app/internal/window: (X11) implement right and middle mouse buttons

Updates gio#60

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-09 17:57:20 +01:00
parent dc7f9bab23
commit 0cfcf5ca2d
+19 -4
View File
@@ -76,6 +76,8 @@ type x11Window struct {
mu sync.Mutex mu sync.Mutex
animating bool animating bool
pointerBtns pointer.Buttons
} }
func (w *x11Window) SetAnimating(anim bool) { func (w *x11Window) SetAnimating(anim bool) {
@@ -219,7 +221,7 @@ func (h *x11EventHandler) handleEvents() bool {
if C.XFilterEvent(xev, C.None) == C.True { if C.XFilterEvent(xev, C.None) == C.True {
continue continue
} }
switch (*C.XAnyEvent)(unsafe.Pointer(xev))._type { switch _type := (*C.XAnyEvent)(unsafe.Pointer(xev))._type; _type {
case C.KeyPress: case C.KeyPress:
kevt := (*C.XKeyPressedEvent)(unsafe.Pointer(xev)) kevt := (*C.XKeyPressedEvent)(unsafe.Pointer(xev))
lookup: lookup:
@@ -290,10 +292,15 @@ func (h *x11EventHandler) handleEvents() bool {
if bevt._type == C.ButtonRelease { if bevt._type == C.ButtonRelease {
ev.Type = pointer.Release ev.Type = pointer.Release
} }
var btn pointer.Buttons
const scrollScale = 10 const scrollScale = 10
switch bevt.button { switch bevt.button {
case C.Button1: 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: case C.Button4:
// scroll up // scroll up
ev.Type = pointer.Move ev.Type = pointer.Move
@@ -305,12 +312,20 @@ func (h *x11EventHandler) handleEvents() bool {
default: default:
continue continue
} }
switch _type {
case C.ButtonPress:
w.pointerBtns |= btn
case C.ButtonRelease:
w.pointerBtns &^= btn
}
ev.Buttons = w.pointerBtns
w.w.Event(ev) w.w.Event(ev)
case C.MotionNotify: case C.MotionNotify:
mevt := (*C.XMotionEvent)(unsafe.Pointer(xev)) mevt := (*C.XMotionEvent)(unsafe.Pointer(xev))
w.w.Event(pointer.Event{ w.w.Event(pointer.Event{
Type: pointer.Move, Type: pointer.Move,
Source: pointer.Mouse, Source: pointer.Mouse,
Buttons: w.pointerBtns,
Position: f32.Point{ Position: f32.Point{
X: float32(mevt.x), X: float32(mevt.x),
Y: float32(mevt.y), Y: float32(mevt.y),