X backend conforms to new API

This commit is contained in:
2023-01-15 12:23:13 -05:00
parent 8cfb8eeaef
commit 77ef7554ac
3 changed files with 97 additions and 67 deletions

View File

@@ -27,6 +27,8 @@ func (window *Window) handleConfigureNotify (
connection *xgbutil.XUtil,
event xevent.ConfigureNotifyEvent,
) {
if window.child == nil { return }
configureEvent := *event.ConfigureNotifyEvent
newWidth := int(configureEvent.Width)
@@ -66,33 +68,29 @@ func (window *Window) handleKeyPress (
NumberPad: numberPad,
}
keyDownEvent := tomo.EventKeyDown {
Key: key,
Modifiers: modifiers,
Repeated: false, // FIXME: return correct value here
}
if keyDownEvent.Key == tomo.KeyTab && keyDownEvent.Modifiers.Alt {
if window.child.Selectable() {
direction := 1
if keyDownEvent.Modifiers.Shift {
direction = -1
if key == tomo.KeyTab && modifiers.Alt {
if _, ok := window.child.(tomo.Selectable); ok {
direction := tomo.SelectionDirectionForward
if modifiers.Shift {
direction = tomo.SelectionDirectionBackward
}
window.advanceSelectionInChild(direction)
}
} else {
window.child.Handle(keyDownEvent)
} else if child, ok := window.child.(tomo.KeyboardTarget); ok {
// FIXME: pass correct value for repeated
child.HandleKeyDown(key, modifiers, false)
}
}
func (window *Window) advanceSelectionInChild (direction int) {
if window.child.Selected() {
if !window.child.AdvanceSelection(direction) {
window.child.Handle(tomo.EventDeselect { })
func (window *Window) advanceSelectionInChild (direction tomo.SelectionDirection) {
child := window.child.(tomo.Selectable)
if child.Selected() {
if !child.HandleSelection(direction) {
child.HandleDeselection()
}
} else {
window.child.Handle(tomo.EventSelect { })
child.HandleSelection(tomo.SelectionDirectionNeutral)
}
}
@@ -115,11 +113,10 @@ func (window *Window) handleKeyRelease (
Hyper: (keyEvent.State & window.backend.modifierMasks.hyper) > 0,
NumberPad: numberPad,
}
window.child.Handle (tomo.EventKeyUp {
Key: key,
Modifiers: modifiers,
})
if child, ok := window.child.(tomo.KeyboardTarget); ok {
child.HandleKeyUp(key, modifiers)
}
}
func (window *Window) handleButtonPress (
@@ -128,48 +125,54 @@ func (window *Window) handleButtonPress (
) {
if window.child == nil { return }
buttonEvent := *event.ButtonPressEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
sum := scrollSum { }
sum.add(buttonEvent.Detail)
window.compressScrollSum(buttonEvent, &sum)
window.child.Handle (tomo.EventScroll {
X: int(buttonEvent.EventX),
Y: int(buttonEvent.EventY),
ScrollX: sum.x,
ScrollY: sum.y,
})
} else {
window.child.Handle (tomo.EventMouseDown {
Button: tomo.Button(buttonEvent.Detail),
X: int(buttonEvent.EventX),
Y: int(buttonEvent.EventY),
})
if child, ok := window.child.(tomo.MouseTarget); ok {
buttonEvent := *event.ButtonPressEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 {
sum := scrollSum { }
sum.add(buttonEvent.Detail)
window.compressScrollSum(buttonEvent, &sum)
child.HandleScroll (
int(buttonEvent.EventX),
int(buttonEvent.EventY),
float64(sum.x), float64(sum.y))
} else {
child.HandleMouseDown (
int(buttonEvent.EventX),
int(buttonEvent.EventY),
tomo.Button(buttonEvent.Detail))
}
}
}
func (window *Window) handleButtonRelease (
connection *xgbutil.XUtil,
event xevent.ButtonReleaseEvent,
) {
buttonEvent := *event.ButtonReleaseEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
window.child.Handle (tomo.EventMouseUp {
Button: tomo.Button(buttonEvent.Detail),
X: int(buttonEvent.EventX),
Y: int(buttonEvent.EventY),
})
if window.child == nil { return }
if child, ok := window.child.(tomo.MouseTarget); ok {
buttonEvent := *event.ButtonReleaseEvent
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
child.HandleMouseUp (
int(buttonEvent.EventX),
int(buttonEvent.EventY),
tomo.Button(buttonEvent.Detail))
}
}
func (window *Window) handleMotionNotify (
connection *xgbutil.XUtil,
event xevent.MotionNotifyEvent,
) {
motionEvent := window.compressMotionNotify(*event.MotionNotifyEvent)
window.child.Handle (tomo.EventMouseMove {
X: int(motionEvent.EventX),
Y: int(motionEvent.EventY),
})
if window.child == nil { return }
if child, ok := window.child.(tomo.MouseTarget); ok {
motionEvent := window.compressMotionNotify(*event.MotionNotifyEvent)
child.HandleMouseMove (
int(motionEvent.EventX),
int(motionEvent.EventY))
}
}

View File

@@ -78,7 +78,11 @@ func (backend *Backend) NewWindow (
func (window *Window) Adopt (child tomo.Element) {
if window.child != nil {
child.SetParentHooks (tomo.ParentHooks { })
if child.Selected() { child.Handle(tomo.EventDeselect { }) }
if previousChild, ok := window.child.(tomo.Selectable); ok {
if previousChild.Selected() {
previousChild.HandleDeselection()
}
}
}
window.child = child
if child != nil {
@@ -88,7 +92,6 @@ func (window *Window) Adopt (child tomo.Element) {
SelectionRequest: window.childSelectionRequestCallback,
})
if child.Selectable() { child.Handle(tomo.EventSelect { }) }
window.resizeChildToFit()
}
window.childMinimumSizeChangeCallback(child.MinimumSize())
@@ -199,12 +202,18 @@ func (window *Window) redrawChildEntirely () {
func (window *Window) resizeChildToFit () {
window.skipChildDrawCallback = true
window.child.Handle(tomo.EventResize {
Width: window.metrics.width,
Height: window.metrics.height,
})
if child, ok := window.child.(tomo.Expanding); ok {
minimumHeight := child.MinimumHeightFor(window.metrics.width)
_, minimumWidth := child.MinimumSize()
window.childMinimumSizeChangeCallback (
minimumWidth, minimumHeight)
} else {
window.child.Resize (
window.metrics.width,
window.metrics.height)
window.redrawChildEntirely()
}
window.skipChildDrawCallback = false
window.redrawChildEntirely()
}
func (window *Window) childDrawCallback (region tomo.Canvas) {
@@ -246,7 +255,9 @@ func (window *Window) childMinimumSizeChangeCallback (width, height int) {
}
func (window *Window) childSelectionRequestCallback () (granted bool) {
window.child.Handle(tomo.EventSelect { })
if child, ok := window.child.(tomo.Selectable); ok {
child.HandleSelection(tomo.SelectionDirectionNeutral)
}
return true
}