app: enhance mouse button support for X11

- Added support for additional mouse buttons (ButtonQuaternary to ButtonNonary) in the X11 event handler.
- Updated the button state handling to accommodate new button events.
- Changed the Buttons type from uint8 to uint16 to support the expanded button range.

This change improves the application's ability to handle various mouse inputs, particularly for devices with more than three buttons.
This commit is contained in:
2025-10-20 06:50:17 +01:00
parent fd470a7f7a
commit 58bbb86ab3
3 changed files with 31 additions and 9 deletions

View File

@@ -598,6 +598,7 @@ func (h *x11EventHandler) handleEvents() bool {
case C.Button3:
btn = pointer.ButtonSecondary
case C.Button4:
btn = pointer.ButtonQuaternary
ev.Kind = pointer.Scroll
// scroll up or left (if shift is pressed).
if ev.Modifiers == key.ModShift {
@@ -606,6 +607,7 @@ func (h *x11EventHandler) handleEvents() bool {
ev.Scroll.Y = -scrollScale
}
case C.Button5:
btn = pointer.ButtonQuinary
// scroll down or right (if shift is pressed).
ev.Kind = pointer.Scroll
if ev.Modifiers == key.ModShift {
@@ -614,17 +616,24 @@ func (h *x11EventHandler) handleEvents() bool {
ev.Scroll.Y = +scrollScale
}
case 6:
btn = pointer.ButtonSenary
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
// scroll left.
ev.Kind = pointer.Scroll
ev.Scroll.X = -scrollScale * 2
case 7:
btn = pointer.ButtonSeptenary
// scroll right
ev.Kind = pointer.Scroll
ev.Scroll.X = +scrollScale * 2
case 8:
btn = pointer.ButtonOctonary
case 9:
btn = pointer.ButtonNonary
default:
continue
}
// Update button state for all button events (including scroll events)
switch _type {
case C.ButtonPress:
w.pointerBtns |= btn

View File

@@ -15,7 +15,6 @@ import (
"github.com/mleku/fromage/op"
"github.com/mleku/fromage/op/clip"
"github.com/mleku/fromage/op/paint"
"github.com/mleku/fromage/unit"
"github.com/mleku/fromage/widget/material"
)
@@ -78,13 +77,7 @@ func (h *InputHandler) Layout(gtx layout.Context, th *material.Theme) {
return layout.Dimensions{Size: gtx.Constraints.Max}
})
// Add some text at the top
label := layout.Rigid(func(gtx layout.Context) layout.Dimensions {
return material.Label(th, unit.Sp(16),
"Input Logger - Move mouse and press keys to see events logged").Layout(gtx)
})
flex.Layout(gtx, label, box)
flex.Layout(gtx, box)
// Handle events after layout
h.handleEvents(gtx)

View File

@@ -92,7 +92,7 @@ type Priority uint8
type Source uint8
// Buttons is a set of mouse buttons
type Buttons uint8
type Buttons uint16
// Cursor denotes a pre-defined cursor shape. Its Add method adds an
// operation that sets the cursor shape for the current clip area.
@@ -225,6 +225,14 @@ const (
// ButtonQuinary is the fifth button, usually used for browser
// navigation (forward)
ButtonQuinary
// ButtonSenary is the sixth button, usually used for scroll left
ButtonSenary
// ButtonSeptenary is the seventh button, usually used for scroll right
ButtonSeptenary
// ButtonOctonary is the eighth button, usually browser back navigation
ButtonOctonary
// ButtonNonary is the ninth button, usually browser forward navigation
ButtonNonary
)
func (s ScrollRange) Union(s2 ScrollRange) ScrollRange {
@@ -338,6 +346,18 @@ func (b Buttons) String() string {
if b.Contain(ButtonQuinary) {
strs = append(strs, "ButtonQuinary")
}
if b.Contain(ButtonSenary) {
strs = append(strs, "ButtonSenary")
}
if b.Contain(ButtonSeptenary) {
strs = append(strs, "ButtonSeptenary")
}
if b.Contain(ButtonOctonary) {
strs = append(strs, "ButtonOctonary")
}
if b.Contain(ButtonNonary) {
strs = append(strs, "ButtonNonary")
}
return strings.Join(strs, "|")
}