From 0cfcf5ca2d98f611043565e9919edf6791767b96 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 9 Nov 2019 17:57:20 +0100 Subject: [PATCH] app/internal/window: (X11) implement right and middle mouse buttons Updates gio#60 Signed-off-by: Elias Naur --- app/internal/window/os_x11.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go index 90086d31..f82f17d6 100644 --- a/app/internal/window/os_x11.go +++ b/app/internal/window/os_x11.go @@ -76,6 +76,8 @@ type x11Window struct { mu sync.Mutex animating bool + + pointerBtns pointer.Buttons } func (w *x11Window) SetAnimating(anim bool) { @@ -219,7 +221,7 @@ func (h *x11EventHandler) handleEvents() bool { if C.XFilterEvent(xev, C.None) == C.True { continue } - switch (*C.XAnyEvent)(unsafe.Pointer(xev))._type { + switch _type := (*C.XAnyEvent)(unsafe.Pointer(xev))._type; _type { case C.KeyPress: kevt := (*C.XKeyPressedEvent)(unsafe.Pointer(xev)) lookup: @@ -290,10 +292,15 @@ func (h *x11EventHandler) handleEvents() bool { if bevt._type == C.ButtonRelease { ev.Type = pointer.Release } + var btn pointer.Buttons const scrollScale = 10 switch bevt.button { case C.Button1: - // left click by default + btn = pointer.ButtonLeft + case C.Button2: + btn = pointer.ButtonMiddle + case C.Button3: + btn = pointer.ButtonRight case C.Button4: // scroll up ev.Type = pointer.Move @@ -305,12 +312,20 @@ func (h *x11EventHandler) handleEvents() bool { default: continue } + switch _type { + case C.ButtonPress: + w.pointerBtns |= btn + case C.ButtonRelease: + w.pointerBtns &^= btn + } + ev.Buttons = w.pointerBtns w.w.Event(ev) case C.MotionNotify: mevt := (*C.XMotionEvent)(unsafe.Pointer(xev)) w.w.Event(pointer.Event{ - Type: pointer.Move, - Source: pointer.Mouse, + Type: pointer.Move, + Source: pointer.Mouse, + Buttons: w.pointerBtns, Position: f32.Point{ X: float32(mevt.x), Y: float32(mevt.y),