Add mouse motion event
This commit is contained in:
parent
639810fb13
commit
ea95473090
12
box.go
12
box.go
@ -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)
|
||||
|
48
event.go
48
event.go
@ -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
|
||||
|
Reference in New Issue
Block a user