From bdc1109bcfe13cc4860b389763406d6231dc02a7 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Fri, 24 Mar 2023 01:31:40 -0400 Subject: [PATCH] Modal dialogs lock the window's input until they are closed --- backends/x/event.go | 2 ++ backends/x/window.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/backends/x/event.go b/backends/x/event.go index d5da4ad..ad05e97 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -119,6 +119,7 @@ func (window *window) handleKeyPress ( event xevent.KeyPressEvent, ) { if window.child == nil { return } + if window.hasModal { return } keyEvent := *event.KeyPressEvent key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State) @@ -180,6 +181,7 @@ func (window *window) handleButtonPress ( event xevent.ButtonPressEvent, ) { if window.child == nil { return } + if window.hasModal { return } buttonEvent := *event.ButtonPressEvent if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { diff --git a/backends/x/window.go b/backends/x/window.go index a851568..7fb34b0 100644 --- a/backends/x/window.go +++ b/backends/x/window.go @@ -24,6 +24,9 @@ type window struct { onClose func () skipChildDrawCallback bool + modalParent *window + hasModal bool + theme theme.Theme config config.Config @@ -217,6 +220,8 @@ func (window *window) NewModal (width, height int) (elements.Window, error) { window.backend.connection, modal.xWindow.Id, []string { "_NET_WM_STATE_MODAL" }) + modal.modalParent = window + window.hasModal = true return modal, err } @@ -249,6 +254,10 @@ func (window *window) Hide () { func (window *window) Close () { if window.onClose != nil { window.onClose() } + if window.modalParent != nil { + // we are a modal dialog, so unlock the parent + window.modalParent.hasModal = false + } window.Hide() window.Adopt(nil) delete(window.backend.windows, window.xWindow.Id)