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()
|
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) {
|
func (this *box) handleMouseDown (button input.Button) {
|
||||||
if this.focusable {
|
if this.focusable {
|
||||||
this.SetFocused(true)
|
this.SetFocused(true)
|
||||||
|
48
event.go
48
event.go
@ -261,6 +261,7 @@ func (window *window) handleButtonPress (
|
|||||||
if !insideWindow && window.shy && !scrolling {
|
if !insideWindow && window.shy && !scrolling {
|
||||||
window.Close()
|
window.Close()
|
||||||
} else if scrolling {
|
} else if scrolling {
|
||||||
|
// TODO
|
||||||
// underneath := window.scrollTargetChildAt(point)
|
// underneath := window.scrollTargetChildAt(point)
|
||||||
// if underneath != nil {
|
// if underneath != nil {
|
||||||
// if child, ok := underneath.element.(ability.ScrollTarget); ok {
|
// 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 (
|
func (window *window) compressExpose (
|
||||||
firstEvent xproto.ExposeEvent,
|
firstEvent xproto.ExposeEvent,
|
||||||
@ -364,6 +386,32 @@ func (window *window) compressConfigureNotify (
|
|||||||
return
|
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) {
|
func (window *window) updateModifiers (state uint16) {
|
||||||
modifiers := xgbkb.StateToModifiers(state)
|
modifiers := xgbkb.StateToModifiers(state)
|
||||||
window.modifiers.Shift = modifiers.Shift || modifiers.ShiftLock
|
window.modifiers.Shift = modifiers.Shift || modifiers.ShiftLock
|
||||||
|
@ -58,7 +58,7 @@ type anyBox interface {
|
|||||||
// handleDndDrop (data.Data)
|
// handleDndDrop (data.Data)
|
||||||
// handleMouseEnter ()
|
// handleMouseEnter ()
|
||||||
// handleMouseLeave ()
|
// handleMouseLeave ()
|
||||||
// handleMouseMove ()
|
handleMouseMove ()
|
||||||
handleMouseDown (input.Button)
|
handleMouseDown (input.Button)
|
||||||
handleMouseUp (input.Button)
|
handleMouseUp (input.Button)
|
||||||
// handleScroll (float64, float64)
|
// handleScroll (float64, float64)
|
||||||
|
Reference in New Issue
Block a user