Open the Speed Dial with Space right after a tab switch, without a KWin title bar on Wayland

This commit is contained in:
SoftFever committed 2026-11-14 16:02:39 +08:00
1 parent c143a06dcf
commit 69cd4ff3cd
11 files changed
+193 -16

No files matched your search

+4 -1
View File
@@ -51,7 +51,10 @@ bare printable key in the frame hook would swallow that character in every text
The dialog refuses such chords and `ShortcutRegistry::load()` drops them from the config.
Space counts as typing. The speed dial's default is the one bare Space, and
`MainFrame` leaves it to a focused control that uses Space itself (text fields, buttons,
combo boxes), so it opens the dial from the canvases and the tab strip only.
combo boxes), so it opens the dial from the canvases and the tab strip only. Selecting a page
with a 3D view (Prepare, Preview, the Design tab) gives the view the keyboard: the page's own
`SetFocus()` would hand it to its first focusable control, a sidebar control there, which keeps
Space until the pointer enters the view.
`MainFrame::handle_global_shortcut` skips a chord that `KeyChord::edits_text()` reports
while a text field has the focus (a wx text entry, spin control, web view or ImGui
+3 -1
View File
@@ -3936,7 +3936,9 @@ view type change, and the preview refusals of `set_view`, `tools/mcp/test_set_wi
`set_window` on the main window (sized twice, moved, placed over its display's work area, maximized and
minimized, and restored from both, with a window screenshot of the size on Wayland), on the Plugins
window by its ref and on Preferences by its `{label}` locator (on X11 with the main window kept under it
in the X server's stacking order), `tools/mcp/test_set_view_camera.py`
in the X server's stacking order), `tools/mcp/test_speed_dial_open.py` the 3D view's keyboard focus after
a switch to Prepare, Preview or the Design tab, Space opening the Speed Dial there, and the dial without
KWin's title bar, `tools/mcp/test_set_view_camera.py`
`set_view`'s `look_at` and `zoom` after a queued fit (and its note while no 3D view draws), clamping,
an orbit that keeps `look_at`, the camera Preview shares and the Design tab's own, with `camera_state`
and `get_app_state.camera`, and a fit after the window was sized while no 3D view showed,
+6
View File
@@ -7304,6 +7304,12 @@ void DesignPanel::on_tab_hidden()
update_sidebar_pane();
}
void DesignPanel::focus_viewport()
{
if (m_viewport)
m_viewport->SetFocus();
}
void DesignPanel::on_tab_shown()
{
if (m_viewport)
+1
View File
@@ -69,6 +69,7 @@ public:
explicit DesignPanel(wxWindow* parent);
void on_tab_shown(); // re-sync bed to the active printer when the Design tab is activated
void on_tab_hidden(); // another tab took over: take the viewport status line down with us
void focus_viewport(); // the tab was selected: the viewport, the keyboard's owner in this tab, takes it
// From MainFrame, like the other pages: re-rasterise the icons at the new scale, and on a theme
// switch also move every token colour onto the new theme.
void msw_rescale();
+3 -13
View File
@@ -466,19 +466,9 @@ public:
#endif // !__APPLE__
)
{
// Some desktop environments ignore splash screen typed window properties
// when running the app through Wayland,resulting in the titlebar being shown
// on the splash screen. The code below creates a client-side window decoration
// when running on Wayland and then removes that decoration. This ensures every
// environment correctly targets and removes the titlebar for this screen.
#if defined(__WXGTK__)
if (Slic3r::GUI::is_running_on_wayland()) {
GtkWidget *empty = gtk_fixed_new();
gtk_widget_set_size_request(empty, 0, 0);
gtk_window_set_titlebar(GTK_WINDOW(GetHandle()), empty);
gtk_window_set_decorated(GTK_WINDOW(GetHandle()), false);
}
#endif
#if defined(__WXGTK__)
Slic3r::GUI::remove_wayland_titlebar(this);
#endif
this->SetPosition(pos);
this->CenterOnScreen();
+15
View File
@@ -3,6 +3,8 @@
#if defined(__WXGTK__)
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <wx/window.h>
#ifdef wxHAVE_GDK_X11
#include <gdk/gdkx.h>
@@ -47,6 +49,19 @@ bool is_running_on_x11()
return get_linux_display_backend() == LinuxDisplayBackend::X11;
}
void remove_wayland_titlebar(wxWindow* window)
{
if (!is_running_on_wayland())
return;
// With a title bar of its own, an empty one, GTK tells the compositor that the window draws its decorations
// itself; undecorated, the window then draws none.
GtkWindow* const gtk_window = GTK_WINDOW(window->GetHandle());
GtkWidget* const empty = gtk_fixed_new();
gtk_widget_set_size_request(empty, 0, 0);
gtk_window_set_titlebar(gtk_window, empty);
gtk_window_set_decorated(gtk_window, false);
}
} // namespace GUI
} // namespace Slic3r
+7
View File
@@ -1,5 +1,7 @@
#pragma once
class wxWindow;
namespace Slic3r {
namespace GUI {
#if defined(__WXGTK__)
@@ -14,6 +16,11 @@ LinuxDisplayBackend get_linux_display_backend();
bool is_running_on_wayland();
bool is_running_on_x11();
// Keeps a window made without a border free of a title bar on Wayland, where KWin draws one on a window
// that does not draw its own decorations, borderless or not. Call it before the window is first shown.
// No-op on X11.
void remove_wayland_titlebar(wxWindow* window);
#endif // defined(__WXGTK__)
} // namespace GUI
} // namespace Slic3r
+13 -1
View File
@@ -1610,7 +1610,19 @@ void MainFrame::init_tabpanel() {
DesignPanel::ensure()->update_undo_redo_buttons();
#endif
if (panel)
// A page with a 3D view gives the keyboard to the view. The page's own SetFocus() would give it to
// its first focusable child, a sidebar control, which keeps Space (the Speed Dial) and the view's
// other keys until the pointer enters the view. A view switch posted above focuses the view it
// shows in turn.
if (panel == m_plater) {
if (GLCanvas3D* canvas = m_plater->get_current_canvas3D())
canvas->force_set_focus();
}
#ifdef SLIC3R_CAD
else if (m_design_page != nullptr && panel == m_design_page)
DesignPanel::ensure()->focus_viewport();
#endif
else if (panel)
panel->SetFocus();
});
+2
View File
@@ -4,6 +4,7 @@
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "I18N.hpp"
#include "LinuxDisplayBackend.hpp"
#include "MainFrame.hpp"
#include "MsgDialog.hpp"
#include "NativeCommands.hpp"
@@ -164,6 +165,7 @@ SpeedDialWebDialog::SpeedDialWebDialog(wxWindow* parent)
// wxGTK dialogs default to CENTER_ON_PARENT, which places the window at its first map and then
// keeps that position for every later Show(). position_over_parent() supplies the origin instead.
gtk_window_set_position(GTK_WINDOW(GetHandle()), GTK_WIN_POS_NONE);
remove_wayland_titlebar(this);
#endif
// The dial dismisses itself when the focus leaves it. The hide is deferred by kHideSettleMs and
// re-checked, so a focus bounce shorter than that is not a dismissal. It does not protect against
+7
View File
@@ -480,6 +480,13 @@ Prepare and checks the same for it, with no more web views in `list_widgets` tha
without a target reaching the 3D view, a window screenshot, and an agent's `run_script` finishing
while it is shown; `run_replay` still runs the smoke test and a nested inline replay.
`test_speed_dial_open.py` goes from Home to Prepare, the Design tab (launched with `--cad`) and Preview by
their tabs, and checks that the page's 3D view then holds the keyboard focus and that Space opens the Speed
Dial, which Escape closes. A pointer entering a view also gives it the focus, so the tab switch itself is
proved only where no pointer rests on the view: on a native Wayland display, or a desktop with the pointer
elsewhere. Where KWin runs the display, it also checks through KWin's D-Bus that KWin draws no title bar on
the dial.
`tests/slice_stats.json` slices one cube, then two cubes in two colours, and checks the slice
reply's statistics: layers, max Z, filament changes, and each filament slot's model, flush and
prime tower grams.
+132
View File
@@ -0,0 +1,132 @@
#!/usr/bin/env python3
"""Checks that Space opens the Speed Dial right after a switch to each page with a 3D view, and that KWin draws
no title bar on the dial.
tools/mcp/orca_mcp.py launch [--cad]
tools/mcp/test_speed_dial_open.py
Each page is reached from Home by a click on its tab, as a person switches pages: Prepare first, while the
plater still shows the 3D view it started with, then Design when the Design tab is on, and Preview. The page's
3D view must then hold the keyboard focus, as a focused sidebar control keeps Space for itself, and Space sent
to the focused window must open the dial. The view also takes the focus when the pointer enters it, so these
checks prove the switch itself only where no pointer rests on the view: on a native Wayland display, or on a
desktop with the pointer elsewhere. Where KWin answers on the display's D-Bus (the private one of a
`--headless` launch, else the caller's), the frame KWin reports for the dial must be the dial's own size: a
title bar of KWin's makes the frame taller. Run it on a freshly launched app. Exits 0 when every check passes.
"""
import os
import re
import subprocess
import sys
import time
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import orca_mcp # noqa: E402
def kwin_frames(session):
"""[(caption, width, height)] of the app's windows as KWin frames them, or None when no KWin answers."""
env = dict(os.environ)
bus = (session.get("display_env") or {}).get("DBUS_SESSION_BUS_ADDRESS")
if bus:
env["DBUS_SESSION_BUS_ADDRESS"] = bus
def gdbus(path, method, *args):
try:
r = subprocess.run(["gdbus", "call", "--session", "--dest", "org.kde.KWin", "--object-path", path,
"--method", method, *args], env=env, capture_output=True, text=True, timeout=10)
except (OSError, subprocess.TimeoutExpired):
return None
return r.stdout if r.returncode == 0 else None
# KWin's window runner finds windows by caption or application, the dial (which has no caption) by the latter.
found = gdbus("/WindowsRunner", "org.kde.krunner1.Match", "orca")
if found is None:
return None
frames = []
for uuid in re.findall(r"'0_(\{[^}]+\})'", found):
info = gdbus("/KWin", "org.kde.KWin.getWindowInfo", uuid) or ""
pid = re.search(r"'pid': <(\d+)>", info)
if pid and int(pid.group(1)) == session["pid"]:
caption = re.search(r"'caption': <'(.*?)'>", info)
size = [float(re.search(rf"'{k}': <([\d.]+)>", info).group(1)) for k in ("width", "height")]
frames.append((caption.group(1) if caption else "", *size))
return frames
def main():
client, session = orca_mcp.session_client()
checks = []
def check(name, ok, detail=""):
checks.append((name, bool(ok), detail))
def wait_for(predicate, timeout):
deadline = time.time() + timeout
while time.time() < deadline:
value = predicate()
if value:
return value
time.sleep(0.25)
return predicate()
def tree():
_, texts = client.call_with_text("list_widgets", max_nodes=3000)
return "\n".join(texts)
def switch_to(label, tab):
"""Clicks Home's tab (the first, with no label), then the tab `label`, and waits for get_app_state's tab."""
tabs = tree()
home = re.search(r"\[(w\d+)\] tab \[", tabs)
page = re.search(rf'\[(w\d+)\] tab "{re.escape(label)}"', tabs)
client.call("click", target=home.group(1))
wait_for(lambda: client.call("get_app_state")["tab"] == "home", 10)
client.call("click", target=page.group(1))
return wait_for(lambda: client.call("get_app_state")["tab"] == tab, 10)
def dial():
"""The Speed Dial as list_windows gives it: the shown web dialog with no title."""
return next((w for w in client.call("list_windows")["items"]
if w.get("kind") == "dialog" and w.get("web") and not w.get("title")), None)
pages = [("Prepare", "prepare")]
if client.call("get_app_state").get("design_tab"):
pages.append(("Design", "design"))
pages.append(("Preview", "preview"))
frame_checked = False
for label, tab in pages:
check(f"{label}: the tab is shown", switch_to(label, tab))
focused = [line.strip() for line in tree().splitlines() if "[focused]" in line]
check(f"{label}: its 3D view holds the keyboard focus", focused and "canvas (wxGLCanvas)" in focused[0], focused)
client.call("press_keys", keys="Space")
opened = wait_for(dial, 10)
check(f"{label}: Space opens the Speed Dial", opened)
if not opened:
continue
if not frame_checked:
frame_checked = True
frames = kwin_frames(session)
frame = next((f for f in frames or [] if f[0] == ""), None)
if frames is None:
print("skip KWin's frame of the dial: no KWin answers on the display's D-Bus")
elif frame is None:
# On X11 the dial skips the taskbar, and the runner leaves such windows out.
print("skip KWin's frame of the dial: KWin's window runner does not list it")
else:
# A title bar adds a few dozen pixels; the margin covers rounding at a fractional scale.
check("KWin draws no title bar on the dial", frame[2] <= opened["height"] + 2,
f"KWin's frame {frame}, the dial {opened['width']}x{opened['height']}")
client.call("press_keys", keys="Escape", target=opened["ref"])
check(f"{label}: Escape closes the Speed Dial", wait_for(lambda: dial() is None, 10))
failed = [c for c in checks if not c[1]]
for name, ok, detail in checks:
print(f"{'ok ' if ok else 'FAIL'} {name}" + ("" if ok or not detail else f"\n {detail}"))
print(f"{len(checks) - len(failed)} of {len(checks)} checks passed")
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main())