2023-01-08 23:03:19 -07:00
|
|
|
package x
|
|
|
|
|
2023-03-07 10:48:29 -07:00
|
|
|
import "image"
|
2023-03-30 21:19:04 -06:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo"
|
2023-02-01 23:47:55 -07:00
|
|
|
import "git.tebibyte.media/sashakoshka/tomo/input"
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
import "github.com/jezek/xgbutil"
|
|
|
|
import "github.com/jezek/xgb/xproto"
|
|
|
|
import "github.com/jezek/xgbutil/xevent"
|
|
|
|
|
|
|
|
type scrollSum struct {
|
|
|
|
x, y int
|
|
|
|
}
|
|
|
|
|
2023-01-20 14:44:07 -07:00
|
|
|
const scrollDistance = 16
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (sum *scrollSum) add (button xproto.Button, window *window, state uint16) {
|
2023-01-20 14:44:07 -07:00
|
|
|
shift :=
|
|
|
|
(state & xproto.ModMaskShift) > 0 ||
|
|
|
|
(state & window.backend.modifierMasks.shiftLock) > 0
|
|
|
|
if shift {
|
|
|
|
switch button {
|
2023-04-14 17:08:14 -06:00
|
|
|
case 4: sum.x -= scrollDistance
|
|
|
|
case 5: sum.x += scrollDistance
|
|
|
|
case 6: sum.y -= scrollDistance
|
|
|
|
case 7: sum.y += scrollDistance
|
2023-01-20 14:44:07 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch button {
|
2023-04-14 17:08:14 -06:00
|
|
|
case 4: sum.y -= scrollDistance
|
|
|
|
case 5: sum.y += scrollDistance
|
|
|
|
case 6: sum.x -= scrollDistance
|
|
|
|
case 7: sum.x += scrollDistance
|
2023-01-20 14:44:07 -07:00
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleExpose (
|
2023-01-26 00:08:07 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.ExposeEvent,
|
|
|
|
) {
|
2023-03-07 10:48:29 -07:00
|
|
|
_, region := window.compressExpose(*event.ExposeEvent)
|
|
|
|
window.pushRegion(region)
|
2023-01-26 00:08:07 -07:00
|
|
|
}
|
|
|
|
|
2023-04-10 00:36:28 -06:00
|
|
|
func (window *window) updateBounds (x, y int16, width, height uint16) {
|
|
|
|
window.metrics.bounds =
|
|
|
|
image.Rect(0, 0, int(width), int(height)).
|
|
|
|
Add(image.Pt(int(x), int(y)))
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleConfigureNotify (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.ConfigureNotifyEvent,
|
|
|
|
) {
|
2023-01-15 10:23:13 -07:00
|
|
|
if window.child == nil { return }
|
|
|
|
|
2023-01-08 23:03:19 -07:00
|
|
|
configureEvent := *event.ConfigureNotifyEvent
|
|
|
|
|
|
|
|
newWidth := int(configureEvent.Width)
|
|
|
|
newHeight := int(configureEvent.Height)
|
|
|
|
sizeChanged :=
|
2023-04-10 00:36:28 -06:00
|
|
|
window.metrics.bounds.Dx() != newWidth ||
|
|
|
|
window.metrics.bounds.Dy() != newHeight
|
|
|
|
window.updateBounds (
|
|
|
|
configureEvent.X, configureEvent.Y,
|
|
|
|
configureEvent.Width, configureEvent.Height)
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
if sizeChanged {
|
|
|
|
configureEvent = window.compressConfigureNotify(configureEvent)
|
2023-04-10 00:36:28 -06:00
|
|
|
window.updateBounds (
|
|
|
|
configureEvent.X, configureEvent.Y,
|
|
|
|
configureEvent.Width, configureEvent.Height)
|
2023-01-08 23:03:19 -07:00
|
|
|
window.reallocateCanvas()
|
|
|
|
window.resizeChildToFit()
|
2023-01-26 00:08:07 -07:00
|
|
|
|
|
|
|
if !window.exposeEventFollows(configureEvent) {
|
2023-04-13 22:25:05 -06:00
|
|
|
window.child.Invalidate()
|
|
|
|
window.child.InvalidateLayout()
|
2023-01-26 00:08:07 -07:00
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) exposeEventFollows (event xproto.ConfigureNotifyEvent) (found bool) {
|
2023-01-26 00:08:07 -07:00
|
|
|
nextEvents := xevent.Peek(window.backend.connection)
|
|
|
|
if len(nextEvents) > 0 {
|
|
|
|
untypedEvent := nextEvents[0]
|
|
|
|
if untypedEvent.Err == nil {
|
|
|
|
typedEvent, ok :=
|
|
|
|
untypedEvent.Event.(xproto.ConfigureNotifyEvent)
|
|
|
|
|
|
|
|
if ok && typedEvent.Window == event.Window {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) modifiersFromState (
|
2023-01-20 15:40:28 -07:00
|
|
|
state uint16,
|
|
|
|
) (
|
2023-02-01 23:47:55 -07:00
|
|
|
modifiers input.Modifiers,
|
2023-01-20 15:40:28 -07:00
|
|
|
) {
|
2023-02-01 23:47:55 -07:00
|
|
|
return input.Modifiers {
|
2023-01-20 15:40:28 -07:00
|
|
|
Shift:
|
|
|
|
(state & xproto.ModMaskShift) > 0 ||
|
|
|
|
(state & window.backend.modifierMasks.shiftLock) > 0,
|
|
|
|
Control: (state & xproto.ModMaskControl) > 0,
|
|
|
|
Alt: (state & window.backend.modifierMasks.alt) > 0,
|
|
|
|
Meta: (state & window.backend.modifierMasks.meta) > 0,
|
|
|
|
Super: (state & window.backend.modifierMasks.super) > 0,
|
|
|
|
Hyper: (state & window.backend.modifierMasks.hyper) > 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleKeyPress (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.KeyPressEvent,
|
|
|
|
) {
|
2023-04-14 21:58:14 -06:00
|
|
|
if window.hasModal { return }
|
2023-01-08 23:03:19 -07:00
|
|
|
|
|
|
|
keyEvent := *event.KeyPressEvent
|
|
|
|
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
|
2023-01-20 15:40:28 -07:00
|
|
|
modifiers := window.modifiersFromState(keyEvent.State)
|
|
|
|
modifiers.NumberPad = numberPad
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-02-01 23:47:55 -07:00
|
|
|
if key == input.KeyTab && modifiers.Alt {
|
2023-04-14 17:08:14 -06:00
|
|
|
if modifiers.Shift {
|
|
|
|
window.system.focusPrevious()
|
|
|
|
} else {
|
|
|
|
window.system.focusNext()
|
|
|
|
}
|
2023-04-10 14:47:03 -06:00
|
|
|
} else if key == input.KeyEscape && window.shy {
|
|
|
|
window.Close()
|
2023-04-14 17:08:14 -06:00
|
|
|
} else if window.focused != nil {
|
|
|
|
focused, ok := window.focused.element.(tomo.KeyboardTarget)
|
|
|
|
if ok { focused.HandleKeyDown(key, modifiers) }
|
2023-01-11 16:32:02 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleKeyRelease (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.KeyReleaseEvent,
|
|
|
|
) {
|
|
|
|
keyEvent := *event.KeyReleaseEvent
|
2023-01-20 15:40:28 -07:00
|
|
|
|
|
|
|
// do not process this event if it was generated from a key repeat
|
|
|
|
nextEvents := xevent.Peek(window.backend.connection)
|
|
|
|
if len(nextEvents) > 0 {
|
|
|
|
untypedEvent := nextEvents[0]
|
|
|
|
if untypedEvent.Err == nil {
|
|
|
|
typedEvent, ok :=
|
2023-02-09 15:26:36 -07:00
|
|
|
untypedEvent.Event.(xproto.KeyPressEvent)
|
2023-01-20 15:40:28 -07:00
|
|
|
|
|
|
|
if ok && typedEvent.Detail == keyEvent.Detail &&
|
|
|
|
typedEvent.Event == keyEvent.Event &&
|
|
|
|
typedEvent.State == keyEvent.State {
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
2023-01-15 10:23:13 -07:00
|
|
|
|
2023-01-20 15:40:28 -07:00
|
|
|
key, numberPad := window.backend.keycodeToKey(keyEvent.Detail, keyEvent.State)
|
|
|
|
modifiers := window.modifiersFromState(keyEvent.State)
|
|
|
|
modifiers.NumberPad = numberPad
|
2023-04-14 21:58:14 -06:00
|
|
|
|
|
|
|
if window.focused != nil {
|
|
|
|
focused, ok := window.focused.element.(tomo.KeyboardTarget)
|
|
|
|
if ok { focused.HandleKeyUp(key, modifiers) }
|
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleButtonPress (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.ButtonPressEvent,
|
|
|
|
) {
|
2023-04-14 17:08:14 -06:00
|
|
|
if window.hasModal { return }
|
2023-04-10 14:47:03 -06:00
|
|
|
|
2023-04-14 17:08:14 -06:00
|
|
|
buttonEvent := *event.ButtonPressEvent
|
|
|
|
point := image.Pt(int(buttonEvent.EventX), int(buttonEvent.EventY))
|
|
|
|
insideWindow := point.In(window.canvas.Bounds())
|
|
|
|
scrolling := buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7
|
2023-04-20 12:44:54 -06:00
|
|
|
modifiers := window.modifiersFromState(buttonEvent.State)
|
2023-04-10 16:07:49 -06:00
|
|
|
|
|
|
|
if !insideWindow && window.shy && !scrolling {
|
2023-04-10 14:47:03 -06:00
|
|
|
window.Close()
|
2023-04-10 16:07:49 -06:00
|
|
|
} else if scrolling {
|
2023-04-16 12:12:55 -06:00
|
|
|
underneath := window.system.scrollTargetChildAt(point)
|
|
|
|
if underneath != nil {
|
|
|
|
if child, ok := underneath.element.(tomo.ScrollTarget); ok {
|
|
|
|
sum := scrollSum { }
|
|
|
|
sum.add(buttonEvent.Detail, window, buttonEvent.State)
|
|
|
|
window.compressScrollSum(buttonEvent, &sum)
|
|
|
|
child.HandleScroll (
|
2023-04-20 12:44:54 -06:00
|
|
|
point, float64(sum.x), float64(sum.y),
|
|
|
|
modifiers)
|
2023-04-16 12:12:55 -06:00
|
|
|
}
|
2023-03-14 16:54:24 -06:00
|
|
|
}
|
|
|
|
} else {
|
2023-04-16 12:12:55 -06:00
|
|
|
underneath := window.system.childAt(point)
|
2023-04-17 00:05:53 -06:00
|
|
|
window.system.drags[buttonEvent.Detail] = underneath
|
2023-04-14 17:08:14 -06:00
|
|
|
if child, ok := underneath.element.(tomo.MouseTarget); ok {
|
2023-01-15 10:23:13 -07:00
|
|
|
child.HandleMouseDown (
|
2023-04-20 12:44:54 -06:00
|
|
|
point, input.Button(buttonEvent.Detail),
|
|
|
|
modifiers)
|
2023-01-15 10:23:13 -07:00
|
|
|
}
|
2023-04-18 00:59:44 -06:00
|
|
|
callback := func (container tomo.MouseTargetContainer, child tomo.Element) {
|
2023-04-17 00:05:53 -06:00
|
|
|
container.HandleChildMouseDown (
|
2023-04-20 12:44:54 -06:00
|
|
|
point, input.Button(buttonEvent.Detail),
|
|
|
|
modifiers, child)
|
2023-04-17 00:05:53 -06:00
|
|
|
}
|
|
|
|
underneath.forMouseTargetContainers(callback)
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleButtonRelease (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.ButtonReleaseEvent,
|
|
|
|
) {
|
2023-04-14 17:08:14 -06:00
|
|
|
buttonEvent := *event.ButtonReleaseEvent
|
|
|
|
if buttonEvent.Detail >= 4 && buttonEvent.Detail <= 7 { return }
|
2023-04-20 12:44:54 -06:00
|
|
|
modifiers := window.modifiersFromState(buttonEvent.State)
|
2023-04-17 00:05:53 -06:00
|
|
|
dragging := window.system.drags[buttonEvent.Detail]
|
2023-04-20 12:44:54 -06:00
|
|
|
|
2023-04-17 00:05:53 -06:00
|
|
|
if dragging != nil {
|
|
|
|
if child, ok := dragging.element.(tomo.MouseTarget); ok {
|
|
|
|
child.HandleMouseUp (
|
2023-04-20 12:44:54 -06:00
|
|
|
image.Pt (
|
|
|
|
int(buttonEvent.EventX),
|
|
|
|
int(buttonEvent.EventY)),
|
|
|
|
input.Button(buttonEvent.Detail),
|
|
|
|
modifiers)
|
2023-04-17 00:05:53 -06:00
|
|
|
}
|
2023-04-18 00:59:44 -06:00
|
|
|
callback := func (container tomo.MouseTargetContainer, child tomo.Element) {
|
2023-04-17 00:05:53 -06:00
|
|
|
container.HandleChildMouseUp (
|
2023-04-20 12:44:54 -06:00
|
|
|
image.Pt (
|
|
|
|
int(buttonEvent.EventX),
|
|
|
|
int(buttonEvent.EventY)),
|
|
|
|
input.Button(buttonEvent.Detail),
|
|
|
|
modifiers, child)
|
2023-04-17 00:05:53 -06:00
|
|
|
}
|
|
|
|
dragging.forMouseTargetContainers(callback)
|
2023-01-15 10:23:13 -07:00
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) handleMotionNotify (
|
2023-01-08 23:03:19 -07:00
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.MotionNotifyEvent,
|
|
|
|
) {
|
2023-04-14 17:08:14 -06:00
|
|
|
motionEvent := window.compressMotionNotify(*event.MotionNotifyEvent)
|
|
|
|
x := int(motionEvent.EventX)
|
|
|
|
y :=int(motionEvent.EventY)
|
|
|
|
|
|
|
|
handled := false
|
|
|
|
for _, child := range window.system.drags {
|
2023-04-17 00:16:27 -06:00
|
|
|
if child == nil { continue }
|
2023-04-17 00:05:53 -06:00
|
|
|
if child, ok := child.element.(tomo.MotionTarget); ok {
|
2023-04-20 12:44:54 -06:00
|
|
|
child.HandleMotion(image.Pt(x, y))
|
2023-04-14 17:08:14 -06:00
|
|
|
handled = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !handled {
|
|
|
|
child := window.system.childAt(image.Pt(x, y))
|
|
|
|
if child, ok := child.element.(tomo.MotionTarget); ok {
|
2023-04-20 12:44:54 -06:00
|
|
|
child.HandleMotion(image.Pt(x, y))
|
2023-04-14 17:08:14 -06:00
|
|
|
}
|
2023-01-15 10:23:13 -07:00
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
}
|
|
|
|
|
2023-03-27 18:44:39 -06:00
|
|
|
func (window *window) handleSelectionNotify (
|
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.SelectionNotifyEvent,
|
|
|
|
) {
|
|
|
|
if window.selectionRequest == nil { return }
|
2023-03-28 22:50:23 -06:00
|
|
|
window.selectionRequest.handleSelectionNotify(connection, event)
|
|
|
|
if !window.selectionRequest.open() { window.selectionRequest = nil }
|
2023-03-27 18:44:39 -06:00
|
|
|
}
|
|
|
|
|
2023-03-29 21:24:42 -06:00
|
|
|
func (window *window) handlePropertyNotify (
|
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.PropertyNotifyEvent,
|
|
|
|
) {
|
|
|
|
if window.selectionRequest == nil { return }
|
|
|
|
window.selectionRequest.handlePropertyNotify(connection, event)
|
|
|
|
if !window.selectionRequest.open() { window.selectionRequest = nil }
|
|
|
|
}
|
|
|
|
|
|
|
|
func (window *window) handleSelectionClear (
|
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.SelectionClearEvent,
|
|
|
|
) {
|
2023-03-30 11:10:58 -06:00
|
|
|
window.selectionClaim = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (window *window) handleSelectionRequest (
|
|
|
|
connection *xgbutil.XUtil,
|
|
|
|
event xevent.SelectionRequestEvent,
|
|
|
|
) {
|
|
|
|
if window.selectionClaim == nil { return }
|
|
|
|
window.selectionClaim.handleSelectionRequest(connection, event)
|
2023-03-29 21:24:42 -06:00
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) compressExpose (
|
2023-01-26 00:08:07 -07:00
|
|
|
firstEvent xproto.ExposeEvent,
|
|
|
|
) (
|
|
|
|
lastEvent xproto.ExposeEvent,
|
2023-03-07 10:48:29 -07:00
|
|
|
region image.Rectangle,
|
2023-01-26 00:08:07 -07:00
|
|
|
) {
|
2023-03-07 10:48:29 -07:00
|
|
|
region = image.Rect (
|
|
|
|
int(firstEvent.X), int(firstEvent.Y),
|
|
|
|
int(firstEvent.X + firstEvent.Width),
|
|
|
|
int(firstEvent.Y + firstEvent.Height))
|
|
|
|
|
2023-01-26 00:08:07 -07:00
|
|
|
window.backend.connection.Sync()
|
|
|
|
xevent.Read(window.backend.connection, false)
|
|
|
|
lastEvent = firstEvent
|
|
|
|
|
|
|
|
for index, untypedEvent := range xevent.Peek(window.backend.connection) {
|
|
|
|
if untypedEvent.Err != nil { continue }
|
|
|
|
|
|
|
|
typedEvent, ok := untypedEvent.Event.(xproto.ExposeEvent)
|
|
|
|
if !ok { continue }
|
|
|
|
|
|
|
|
if firstEvent.Window == typedEvent.Window {
|
2023-03-07 10:48:29 -07:00
|
|
|
region = region.Union (image.Rect (
|
|
|
|
int(typedEvent.X), int(typedEvent.Y),
|
|
|
|
int(typedEvent.X + typedEvent.Width),
|
|
|
|
int(typedEvent.Y + typedEvent.Height)))
|
|
|
|
|
2023-01-26 00:08:07 -07:00
|
|
|
lastEvent = typedEvent
|
|
|
|
defer func (index int) {
|
|
|
|
xevent.DequeueAt(window.backend.connection, index)
|
|
|
|
} (index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-01-08 23:03:19 -07:00
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) compressConfigureNotify (
|
2023-01-08 23:03:19 -07:00
|
|
|
firstEvent xproto.ConfigureNotifyEvent,
|
|
|
|
) (
|
|
|
|
lastEvent xproto.ConfigureNotifyEvent,
|
|
|
|
) {
|
|
|
|
window.backend.connection.Sync()
|
|
|
|
xevent.Read(window.backend.connection, false)
|
|
|
|
lastEvent = firstEvent
|
|
|
|
|
|
|
|
for index, untypedEvent := range xevent.Peek(window.backend.connection) {
|
|
|
|
if untypedEvent.Err != nil { continue }
|
|
|
|
|
|
|
|
typedEvent, ok := untypedEvent.Event.(xproto.ConfigureNotifyEvent)
|
|
|
|
if !ok { continue }
|
|
|
|
|
|
|
|
if firstEvent.Event == typedEvent.Event &&
|
|
|
|
firstEvent.Window == typedEvent.Window {
|
|
|
|
|
|
|
|
lastEvent = typedEvent
|
|
|
|
defer func (index int) {
|
|
|
|
xevent.DequeueAt(window.backend.connection, index)
|
|
|
|
} (index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) compressScrollSum (
|
2023-01-08 23:03:19 -07:00
|
|
|
firstEvent xproto.ButtonPressEvent,
|
|
|
|
sum *scrollSum,
|
|
|
|
) {
|
|
|
|
window.backend.connection.Sync()
|
|
|
|
xevent.Read(window.backend.connection, false)
|
|
|
|
|
|
|
|
for index, untypedEvent := range xevent.Peek(window.backend.connection) {
|
|
|
|
if untypedEvent.Err != nil { continue }
|
|
|
|
|
|
|
|
typedEvent, ok := untypedEvent.Event.(xproto.ButtonPressEvent)
|
|
|
|
if !ok { continue }
|
|
|
|
|
|
|
|
if firstEvent.Event == typedEvent.Event &&
|
|
|
|
typedEvent.Detail >= 4 &&
|
|
|
|
typedEvent.Detail <= 7 {
|
|
|
|
|
2023-01-20 14:44:07 -07:00
|
|
|
sum.add(typedEvent.Detail, window, typedEvent.State)
|
2023-01-08 23:03:19 -07:00
|
|
|
defer func (index int) {
|
|
|
|
xevent.DequeueAt(window.backend.connection, index)
|
|
|
|
} (index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-03-14 16:54:24 -06:00
|
|
|
func (window *window) compressMotionNotify (
|
2023-01-08 23:03:19 -07:00
|
|
|
firstEvent xproto.MotionNotifyEvent,
|
|
|
|
) (
|
|
|
|
lastEvent xproto.MotionNotifyEvent,
|
|
|
|
) {
|
|
|
|
window.backend.connection.Sync()
|
|
|
|
xevent.Read(window.backend.connection, false)
|
|
|
|
lastEvent = firstEvent
|
|
|
|
|
|
|
|
for index, untypedEvent := range xevent.Peek(window.backend.connection) {
|
|
|
|
if untypedEvent.Err != nil { continue }
|
|
|
|
|
|
|
|
typedEvent, ok := untypedEvent.Event.(xproto.MotionNotifyEvent)
|
|
|
|
if !ok { continue }
|
|
|
|
|
2023-01-20 23:24:24 -07:00
|
|
|
if firstEvent.Event == typedEvent.Event {
|
2023-01-08 23:03:19 -07:00
|
|
|
lastEvent = typedEvent
|
|
|
|
defer func (index int) {
|
|
|
|
xevent.DequeueAt(window.backend.connection, index)
|
|
|
|
} (index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|