Ok it kind of works now

This commit is contained in:
Sasha Koshka 2023-04-10 16:47:03 -04:00
parent da47026d1c
commit 2987331a31
3 changed files with 26 additions and 6 deletions

View File

@ -146,6 +146,8 @@ func (window *window) handleKeyPress (
child.HandleUnfocus()
}
}
} else if key == input.KeyEscape && window.shy {
window.Close()
} else if child, ok := window.child.(tomo.KeyboardTarget); ok {
child.HandleKeyDown(key, modifiers)
}
@ -193,7 +195,14 @@ func (window *window) handleButtonPress (
if window.hasModal { return }
buttonEvent := *event.ButtonPressEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
insideWindow := image.Pt (
int(buttonEvent.EventX),
int(buttonEvent.EventY)).In(window.metrics.bounds)
if !insideWindow && window.shy {
window.Close()
} else if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
if child, ok := window.child.(tomo.ScrollTarget); ok {
sum := scrollSum { }
sum.add(buttonEvent.Detail, window, buttonEvent.State)

View File

@ -30,6 +30,7 @@ type window struct {
modalParent *window
hasModal bool
shy bool
theme tomo.Theme
config tomo.Config
@ -286,10 +287,7 @@ func (window *window) NewMenu (bounds image.Rectangle) (tomo.MenuWindow, error)
window.backend.connection,
menu.xWindow.Id,
window.xWindow.Id)
ewmh.WmStateSet (
window.backend.connection,
menu.xWindow.Id,
[]string { "_NET_WM_STATE_SKIP_TASKBAR" })
menu.setType("POPUP_MENU")
menu.inheritProperties(window)
return menuWindow { window: menu }, err
}
@ -310,7 +308,9 @@ func (window mainWindow) NewPanel (bounds image.Rectangle) (tomo.Window, error)
}
func (window menuWindow) Pin () {
// TODO
// TODO take off override redirect
// TODO turn off shy
// TODO set window type to MENU
}
func (window *window) inheritProperties (parent *window) {

View File

@ -65,6 +65,17 @@ func run () {
})
container.Adopt(errorButton, false)
menuButton := elements.NewButton("menu")
menuButton.OnClick (func () {
menu, err := window.NewMenu (
tomo.Bounds(0, 0, 64, 64).
Add(menuButton.Bounds().Min))
if err != nil { println(err.Error()) }
menu.Adopt(elements.NewLabel("I'm a shy window...", true))
menu.Show()
})
container.Adopt(menuButton, false)
cancelButton := elements.NewButton("No thank you.")
cancelButton.OnClick(tomo.Stop)
container.Adopt(cancelButton, false)