Add mouse motion event

This commit is contained in:
Sasha Koshka 2023-08-05 17:56:15 -04:00
parent 639810fb13
commit ea95473090
3 changed files with 61 additions and 1 deletions

12
box.go
View File

@ -313,6 +313,18 @@ func (this *box) handleFocusLeave () {
this.on.focusLeave.Broadcast()
}
func (this *box) handleMouseEnter () {
this.on.mouseEnter.Broadcast()
}
func (this *box) handleMouseLeave () {
this.on.mouseLeave.Broadcast()
}
func (this *box) handleMouseMove () {
this.on.mouseMove.Broadcast()
}
func (this *box) handleMouseDown (button input.Button) {
if this.focusable {
this.SetFocused(true)

View File

@ -261,6 +261,7 @@ func (window *window) handleButtonPress (
if !insideWindow && window.shy && !scrolling {
window.Close()
} else if scrolling {
// TODO
// underneath := window.scrollTargetChildAt(point)
// if underneath != nil {
// if child, ok := underneath.element.(ability.ScrollTarget); ok {
@ -298,6 +299,27 @@ func (window *window) handleButtonRelease (
}
}
func (window *window) handleMotionNotify (
connection *xgbutil.XUtil,
event xevent.MotionNotifyEvent,
) {
if window.hasModal { return }
motionEvent := window.compressMotionNotify(*event.MotionNotifyEvent)
x := int(motionEvent.EventX)
y := int(motionEvent.EventY)
handled := false
for _, child := range window.drags {
if child == nil { continue }
child.handleMouseMove()
handled = true
}
if !handled {
window.boxUnder(image.Pt(x, y)).handleMouseMove()
}
}
func (window *window) compressExpose (
firstEvent xproto.ExposeEvent,
@ -364,6 +386,32 @@ func (window *window) compressConfigureNotify (
return
}
func (window *window) compressMotionNotify (
firstEvent xproto.MotionNotifyEvent,
) (
lastEvent xproto.MotionNotifyEvent,
) {
window.backend.x.Sync()
xevent.Read(window.backend.x, false)
lastEvent = firstEvent
for index, untypedEvent := range xevent.Peek(window.backend.x) {
if untypedEvent.Err != nil { continue }
typedEvent, ok := untypedEvent.Event.(xproto.MotionNotifyEvent)
if !ok { continue }
if firstEvent.Event == typedEvent.Event {
lastEvent = typedEvent
defer func (index int) {
xevent.DequeueAt(window.backend.x, index)
} (index)
}
}
return
}
func (window *window) updateModifiers (state uint16) {
modifiers := xgbkb.StateToModifiers(state)
window.modifiers.Shift = modifiers.Shift || modifiers.ShiftLock

View File

@ -58,7 +58,7 @@ type anyBox interface {
// handleDndDrop (data.Data)
// handleMouseEnter ()
// handleMouseLeave ()
// handleMouseMove ()
handleMouseMove ()
handleMouseDown (input.Button)
handleMouseUp (input.Button)
// handleScroll (float64, float64)