From e2150fa08275fa7d3416ca1a9cde3621e1104102 Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 26 May 2024 22:10:12 +0100 Subject: [PATCH] Simplify menu overlay code and support multiple menus appearing --- internal/x11/wm/desk.go | 16 ++++++---------- internal/x11/wm/events.go | 10 +++++----- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/internal/x11/wm/desk.go b/internal/x11/wm/desk.go index 87e19059..676b0992 100644 --- a/internal/x11/wm/desk.go +++ b/internal/x11/wm/desk.go @@ -56,13 +56,12 @@ type x11WM struct { currentBindings []*fynedesk.Shortcut - died bool - rootID, menuID xproto.Window - menuSize fyne.Size - menuPos fyne.Position - menuWin fyne.Window - transientMap map[xproto.Window][]xproto.Window - oldRoot *xgraphics.Image + died bool + rootID xproto.Window + menuSize fyne.Size + menuPos fyne.Position + transientMap map[xproto.Window][]xproto.Window + oldRoot *xgraphics.Image } type moveResizeType uint32 @@ -247,7 +246,6 @@ func (x *x11WM) ShowOverlay(w fyne.Window, s fyne.Size, p fyne.Position) { w.Show() x.menuSize = s x.menuPos = p - x.menuWin = w } func (x *x11WM) ShowMenuOverlay(m *fyne.Menu, s fyne.Size, p fyne.Position) { @@ -289,7 +287,6 @@ func (x *x11WM) ShowModal(w fyne.Window, s fyne.Size) { p := fyne.NewPos((float32(root.Width)/scale-s.Width)/2, (float32(root.Height)/scale-s.Height)/2) x.menuPos = p - x.menuWin = w } func (x *x11WM) X() *xgbutil.XUtil { @@ -743,7 +740,6 @@ func (x *x11WM) showWindow(win xproto.Window, parent xproto.Window) { if name == windowNameMenu { x11.WindowExtendedHintsAdd(x.x, win, "_NET_WM_STATE_SKIP_TASKBAR") x11.WindowExtendedHintsAdd(x.x, win, "_NET_WM_STATE_SKIP_PAGER") - x.menuID = win xproto.ChangeWindowAttributes(x.Conn(), win, xproto.CwEventMask, []uint32{xproto.EventMaskLeaveWindow}) screen := fynedesk.Instance().Screens().Primary() diff --git a/internal/x11/wm/events.go b/internal/x11/wm/events.go index 9ee5c7ad..346f0528 100644 --- a/internal/x11/wm/events.go +++ b/internal/x11/wm/events.go @@ -232,11 +232,11 @@ func (x *x11WM) handleMouseEnter(ev xproto.EnterNotifyEvent) { } func (x *x11WM) handleMouseLeave(ev xproto.LeaveNotifyEvent) { - if ev.Event == x.menuID { // dismiss overlay menus on mouse out - x.menuID = 0 - if x.menuWin != nil { - x.menuWin.Close() - x.menuWin = nil + win := x.clientForWin(ev.Event) + if win == nil { + // dismiss overlay menus on mouse out + if x11.WindowName(x.X(), ev.Event) == windowNameMenu { + xproto.UnmapWindow(x.x.Conn(), ev.Event) } }