Files
OrcaSlicer/tests/slic3rutils/test_speed_dial_dismiss.cpp
Lam Wei LunandHanif Koh bd3e9aeb96 fix: stop the Speed Dial dismissing itself on the first open (#17245)
* fix: stop the Speed Dial dismissing itself on the first open

Opening the dial with Space and not touching anything closed it again a
moment later, on GNOME and KDE, X11 and Wayland, and only on the first open.

The dial hides on wxEVT_ACTIVATE(false), but wxGTK does not deliver that
event to the window that lost the focus: gtk_frame_focus_out_callback sends
it to g_activeFrame, the toplevel that was activated last (wx
src/gtk/toplevel.cpp:192-205). A deactivation that belongs to another
window, or the same one arriving while the dial is still taking the focus,
therefore read as "the user dismissed the dial". The first open is the only
one that maps the window, moves it, resizes it to its content and grabs
focus into a web view that has never held it, so it is the only open
exposed to that ordering.

Validate the dismissal instead of trusting the event: arm a 150 ms one-shot,
cancelled by any activation, and hide only if the dial is still shown and
its window is no longer active. On GTK ask the window with
gtk_window_is_active(), because wxTopLevelWindow::IsActive() resolves
through wx focus tracking, which does not follow the focus that WebKit's
native widget takes. Also skip the pre-map focus grab on the first open: at
that point wxGTK has not mapped the window yet, so the grab cannot land.

speed_dial_should_hide() is a free function, so the rule is covered by
tests/slic3rutils/test_speed_dial_dismiss.cpp without a GUI.

* docs(wxwidgets-skill): document the validated Speed Dial deactivation

Section 10 described the dial's old handler, which hid on every
wxEVT_ACTIVATE(false). The skill is the review ground truth, so it has to
match the code: the deactivation is now validated after a settle interval
against the window's real active state, because wxGTK sends that event to
the last activated toplevel whatever window lost the focus.

* Ignore Page Changes of Inner Books in the Main Tab Handler

The main frame's tab-panel handler receives the page-changed event of
any book inside a page, because wxBookCtrlEvent propagates and the
Calibration page's Tabbook has no handler of its own. It then treated
the inner page switch as a main tab change: it reset the selected tab,
toggled the undo/redo buttons and called SetFocus() on the current page.

On wxGTK, SetFocus() on a child of a visible but inactive top-level
window presents that window. While the Calibration page is built in the
background after start-up, this re-activated the main window and the
Speed Dial, which hides when it loses the focus, closed by itself a
moment after its first open on Linux.

Only act on events whose object is the main tab panel.

* Include wx/timer.h Where the Speed Dial Binds Its Timer

* Describe the Real Cause of the Speed Dial's First-Open Close

The deferred, re-checked hide absorbs a focus bounce shorter than its
delay. It did not stop the first-open close, which was the main frame
activating itself from its tab handler; say so in the comments, the
test and the skill reference instead of describing a misdelivered
deactivation.

---------

Co-authored-by: Hanif Koh <hanifkoh@outlook.com>
2026-11-05 11:34:33 +08:00

38 lines
1.5 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include "slic3r/GUI/SpeedDialDialog.hpp"
using namespace Slic3r::GUI;
// The dial hides only after a settle delay, and only if it is still shown and really lost the focus,
// so a focus bounce shorter than the delay does not dismiss it.
TEST_CASE("Speed dial stays shown while it still holds the focus", "[SpeedDialDismiss][SpeedDial]")
{
// A focus bounce: a deactivation arrived, but the dial is active again when the timer fires.
REQUIRE_FALSE(speed_dial_should_hide(true, true));
}
TEST_CASE("Speed dial hides once the focus has really left it", "[SpeedDialDismiss][SpeedDial]")
{
// The user clicked into the application behind the dial, or switched to another application.
REQUIRE(speed_dial_should_hide(true, false));
}
TEST_CASE("Hidden speed dial never hides again", "[SpeedDialDismiss][SpeedDial]")
{
// Already hidden: a second hide would restart the delay and re-trigger any dismissal side effects.
REQUIRE_FALSE(speed_dial_should_hide(false, true));
REQUIRE_FALSE(speed_dial_should_hide(false, false));
}
TEST_CASE("Speed dial dismiss decision follows the shown and active truth table", "[SpeedDialDismiss][SpeedDial]")
{
// The rule in full, so a refactor cannot go back to hiding on the raw deactivation event.
// shown && !active is the only combination that hides.
REQUIRE_FALSE(speed_dial_should_hide(true, true));
REQUIRE(speed_dial_should_hide(true, false));
REQUIRE_FALSE(speed_dial_should_hide(false, true));
REQUIRE_FALSE(speed_dial_should_hide(false, false));
}