FIX: macOS popups dismissed by external AXRaise, swallowing the click - #11783
Open
crash0verride11 wants to merge 1 commit into
Open
FIX: macOS popups dismissed by external AXRaise, swallowing the click#11783crash0verride11 wants to merge 1 commit into
crash0verride11 wants to merge 1 commit into
Conversation
Any process holding macOS accessibility permission can raise another
application's windows via the AXRaise action. While a popup is open this
makes the raised window key, the popup resigns key, and
wxPopupFocusHandler dismisses it:
AXRaise (another process, over Mach IPC)
-> -[NSWindow makeKeyAndOrderFront:]
-> -[NSWindow makeKeyWindow]
-> -[NSWindow resignKeyWindow]
-> wxWidgetCocoaImpl::DoNotifyFocusEvent
-> wxPopupFocusHandler::OnKillFocus
When the raise arrives on mouse-down the popup is gone before the click
is delivered, so the click is lost. The popup's NSWindow is also left on
screen at NSPopUpMenuWindowLevel, and since DropDown sets
wxBG_STYLE_PAINT its background is never auto-erased, so it renders as a
blank rectangle above every other application.
Everything deriving from PopupWindow is affected: DropDown, AmsMapingPopup,
ColorPickerPopup. Dropdowns with submenus appear to work because with two
popups open the click dismisses one and still reaches the other.
wxWidgets is correct to dismiss a transient popup that lost focus; the
problem is that the focus loss was not caused by the user. Push a guard
ahead of wxPopupFocusHandler that swallows wxEVT_KILL_FOCUS while the
pointer is still inside the popup, and lets it through otherwise.
Two details are load-bearing:
- The guard must be installed on m_focus, not on the focus argument. On
macOS wxPopupTransientWindow::Popup() reassigns m_focus = FindFocus()
before pushing its own handler, and the two are different windows.
- wxFocusEvent::GetWindow() cannot be used to detect this: it is null for
a key-window change, which is not a first-responder change. Hence the
pointer-location test.
Clicking outside (wxPopupWindowHandler, EVT_LEFT_DOWN on m_child) and
leaving the application are handled elsewhere and still dismiss normally.
macOS-only; no behaviour change on Windows or Linux.
Diagnosed by instrumenting PopupWindow to capture event ordering and a
backtrace at the point of dismissal; instrumentation removed before commit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On macOS, dropdowns and popups can stop registering clicks entirely. The popup opens, but clicking causes the dropdown or popup to dismiss without selection, and a in some cases a blank grey rectangle is left on screen floating above every
application — including when Bambu Studio is not frontmost. Keyboard navigation still works, so some selections become only reachable via the keyboard and some not at all.
My case that led to this patch the trigger was a mouse utility whose click-through feature raises the window under the cursor on mouse-down, so the raise arrived on every click. However, any accessibility client that raises windows can cause it — window managers, automation tools, assistive software. Difficult to disposes because the symptom looks like a Bambu Studio or wxWidgets bug, though it is an app conflict, and reproduces on no clean machine.
Diagnosis and fix
Any process holding macOS accessibility permission can raise another application's windows via the AXRaise action. While a popup is open this makes the raised window key, the popup resigns key, and wxPopupFocusHandler dismisses it:
AXRaise (another process, over Mach IPC)
-> -[NSWindow makeKeyAndOrderFront:]
-> -[NSWindow makeKeyWindow]
-> -[NSWindow resignKeyWindow]
-> wxWidgetCocoaImpl::DoNotifyFocusEvent
-> wxPopupFocusHandler::OnKillFocus
When the raise arrives on mouse-down the popup is gone before the click is delivered, so the click is lost. The popup's NSWindow is also left on screen at NSPopUpMenuWindowLevel, and since DropDown sets wxBG_STYLE_PAINT its background is never auto-erased, so it renders as a blank rectangle above every other application.
Everything deriving from PopupWindow is affected: DropDown, AmsMapingPopup, ColorPickerPopup. Dropdowns with submenus that are clicked sequentially appear to work because with two popups open the click dismisses one and still reaches the other.
wxWidgets is correct to dismiss a transient popup that lost focus; the problem is that the focus loss was not caused by the user. Push a guard ahead of wxPopupFocusHandler that swallows wxEVT_KILL_FOCUS while the pointer is still inside the popup, and lets it through otherwise.
Two key details:
Clicking outside (wxPopupWindowHandler, EVT_LEFT_DOWN on m_child) and leaving the application are handled elsewhere and still dismiss normally.
macOS-only; no behaviour change on Windows or Linux.
Testing
macOS 26.5.2, Apple Silicon:
CGWindowListCopyWindowInfo: 0 onscreenwindows at popup level, against 3 before the change)
Verified by instrumenting
PopupWindowand reading the actual event order and thebacktrace at the point of dismissal.
Related issues
Likely fixes #7443 — The recording added to the issue mirrors some of the issues covered here. "Print preset selection dropdown in the Prepare tab is non-functional" and "Filament color selection dropdown in the Device tab cannot be changed" are two cases reproduced and fixed here.
Possibly related: #10140 (filament colour dropdown fails to apply, intermittent), if the jumps are the window being dismissed this sounds like the issue reproduced here.