Modal dialogs lock the window's input until they are closed

This commit is contained in:
Sasha Koshka 2023-03-24 01:31:40 -04:00
parent a2c0ff5f4c
commit bdc1109bcf
2 changed files with 11 additions and 0 deletions

View File

@ -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 {

View File

@ -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)