Repository navigation
wxGUI: fix orphaned drag image windows when dragging layers in layer tree on macOS - #7725
Merged
petrasovaa merged 3 commits intoJul 17, 2026
Merged
Conversation
…tree on macOS Every layer drag in the Layer Manager tree leaves an orphaned borderless window on screen on macOS (visible in Mission Control), because wx.DragImage renders through wxOverlay whose Cocoa implementation never orders its NSWindow out of screen on Reset() (wxWidgets#26380, still open). Replace the drag image on macOS with a wx.PopupWindow-based ghost that is explicitly destroyed when the drag ends, and add an EVT_MOUSE_CAPTURE_LOST handler to clean up when the capture is stolen mid-drag (e.g. by a Mission Control space switch), in which case EVT_TREE_END_DRAG never fires.
petrasovaa
requested changes
Jul 15, 2026
Add a TODO to remove the _MacSafeDragImage workaround once a wxPython release includes the wxWidgets/wxWidgets#26380 fix. Remove the EVT_MOUSE_CAPTURE_LOST handler: the event is only generated by the MSW, GTK, and Qt ports (wxWindowBase::NotifyCaptureLost callers in wxWidgets 3.2.8 and master), never by the osx port, so the handler could never fire on macOS.
petrasovaa
enabled auto-merge (squash)
July 16, 2026 09:57
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.
Description
Every drag of a layer in the Layer Manager tree (TOC) on macOS leaves an
orphaned borderless window behind. The windows are invisible on the desktop
but pile up in Mission Control/Exposé as untitled "python" windows, one per
drag, and are never released for the lifetime of the session.
Root cause
The bug is not in GRASS code. The chain is:
LayerTreeis based onwx.lib.agw.customtreectrl.CustomTreeCtrl, whoseinternal
OnMousehandler shows the drag animation through awx.DragImage.wx.DragImageis the generic implementation, which draws viawxOverlay.wxOverlayImpl::Reset()releases its borderlessNSWindowwithout ever ordering it out of the screen (there is a
// todo : don't dispose, only hide and reposition on next runcomment atthe exact spot in
src/osx/cocoa/overlay.mm). A visibleNSWindowstaysalive on screen, so every overlay use leaks one phantom window.
This is wxWidgets/wxWidgets#26380, reproducible with the plain wxWidgets
Drawing sample. It affects wxWidgets 3.2.x and 3.3.x including current
nightly and is still open, so upgrading the bundled wxPython does not fix
it — GRASS needs a workaround on its side.
The leak was verified empirically against wxPython 4.2.4 / wxWidgets 3.2.8
(osx-cocoa) by replicating
customtreectrl.OnMouse's exact drag-imagelifecycle and counting the process's on-screen windows via
CGWindowListCopyWindowInfo: 3 drags → 3 leaked windows with stockwx.DragImage, 0 with this patch.Changes
All in
gui/wxpython/lmgr/layertree.py, active on macOS only(
sys.platform == "darwin").