Propagate keyboard events to root if nothing is focused

This makes window-level keybinds possible. Exciting!
This commit is contained in:
Sasha Koshka 2024-07-27 02:20:06 -04:00
parent 6ff5dea308
commit 85b8536925

View File

@ -24,13 +24,19 @@ func (this *Hierarchy) HandleModifiers (modifiers input.Modifiers) {
// HandleModifiers must be called *before* HandleKeyDown.
func (this *Hierarchy) HandleKeyDown (key input.Key, numberPad bool) {
caught := false
this.keyboardTargets(func (target anyBox) bool {
if target.handleKeyDown(key, numberPad) {
caught = true
return false
if this.anyFocused() {
this.keyboardTargets(func (target anyBox) bool {
if target.handleKeyDown(key, numberPad) {
caught = true
return false
}
return true
})
} else {
if this.root != nil {
caught = this.root.handleKeyDown(key, numberPad)
}
return true
})
}
if caught { return }
switch key {
@ -49,12 +55,18 @@ func (this *Hierarchy) HandleKeyDown (key input.Key, numberPad bool) {
// which triggers this comes with modifier key information, HandleModifiers must
// be called *before* HandleKeyUp.
func (this *Hierarchy) HandleKeyUp (key input.Key, numberPad bool) {
this.keyboardTargets(func (target anyBox) bool {
if target.handleKeyUp(key, numberPad) {
return false
if this.anyFocused() {
this.keyboardTargets(func (target anyBox) bool {
if target.handleKeyUp(key, numberPad) {
return false
}
return true
})
} else {
if this.root != nil {
this.root.handleKeyUp(key, numberPad)
}
return true
})
}
}
// HandleMouseDown sends a mouse down event to the Boxes positioned underneath