Mouse wheel scrolls windows: forward scroll to Wayland clients
The wheel used to reach only the Interface Explorer dialog; clients never got wl_pointer.axis, and the login-session (KMS/libinput) backend dropped scroll events. - libinput axis events (wheel, touchpad, trackpoint) are queued as EV_AXIS and surface as InputEvent::Scroll(axis, value, discrete) in both the native and wasm (moonplasma:host/display seat-event.scroll) backends. - The nested backend keeps horizontal scroll and the host's axis_discrete notches. - The compositor sends axis_source(wheel) + axis_discrete/axis_value120 + axis + frame to the popup or window under the pointer; the explorer still takes the wheel while inspect mode is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hjdz1uQ1y3GgazdKrR
This commit is contained in:
12 files changed
+200
-44
No files matched your search
@@ -1067,10 +1067,49 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
_ => self.leave_pointer()
|
||||
}
|
||||
}
|
||||
Scroll(v) => {
|
||||
// ~10 units per wheel notch -> 3 lines.
|
||||
let lines = if v > 0.0 { (v / 10.0).to_int() + 1 } else { (v / 10.0).to_int() - 1 }
|
||||
ignore(self.shell.scroll_inspector(lines))
|
||||
Scroll(axis, v, discrete) => {
|
||||
if v == 0.0 && discrete == 0 {
|
||||
return
|
||||
}
|
||||
let xi = self.ptr_x.to_int()
|
||||
let yi = self.ptr_y.to_int()
|
||||
match self.popup_at(xi, yi) {
|
||||
Some(p) => {
|
||||
self.pointer_into_popup(p, time_ms, false)
|
||||
self.server.pointer_axis(p.id, time_ms, axis, v, discrete)
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if axis == 0U && self.shell.inspecting() {
|
||||
// ~10 units per wheel notch -> 3 lines.
|
||||
let lines = if v > 0.0 { (v / 10.0).to_int() + 1 } else { (v / 10.0).to_int() - 1 }
|
||||
ignore(self.shell.scroll_inspector(lines))
|
||||
return
|
||||
}
|
||||
if self.wm.drag is Some(_) || self.split_drag is Some(_) {
|
||||
return
|
||||
}
|
||||
// The wheel scrolls the window under the pointer (focused or not), like Plasma.
|
||||
match self.window_at(xi, yi) {
|
||||
Some((wid, true)) =>
|
||||
match self.windows.get(wid) {
|
||||
Some(win) => {
|
||||
if self.ptr_win != Some(wid) {
|
||||
self.leave_pointer()
|
||||
self.ptr_win = Some(wid)
|
||||
self.server.pointer_enter(
|
||||
wid,
|
||||
self.ptr_x - win.geometry.x.to_double(),
|
||||
self.ptr_y - win.geometry.y.to_double(),
|
||||
)
|
||||
}
|
||||
self.server.pointer_axis(wid, time_ms, axis, v, discrete)
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
PointerButton(button, pressed) => {
|
||||
let xi = self.ptr_x.to_int()
|
||||
|
||||
@@ -115,6 +115,18 @@ test "host input reaches the focused client and the launcher popup opens" {
|
||||
assert_true(has_msg(msgs, ptr_id, 3U)) // button
|
||||
assert_true(has_msg(msgs, kbd_id, 3U)) // wl_keyboard.key
|
||||
|
||||
// The mouse wheel over the window scrolls it: axis_source + axis_discrete + axis.
|
||||
comp.handle_input(@nested.InputEvent::Scroll(0U, 15.0, 1), 14U)
|
||||
let wheel = drain_msgs(c)
|
||||
assert_true(has_msg(wheel, ptr_id, 6U)) // wl_pointer.axis_source
|
||||
assert_true(has_msg(wheel, ptr_id, 8U)) // wl_pointer.axis_discrete
|
||||
assert_true(has_msg(wheel, ptr_id, 4U)) // wl_pointer.axis
|
||||
// A touchpad (no notches) sends only the continuous axis.
|
||||
comp.handle_input(@nested.InputEvent::Scroll(1U, -3.5, 0), 15U)
|
||||
let pad = drain_msgs(c)
|
||||
assert_true(has_msg(pad, ptr_id, 4U))
|
||||
assert_false(has_msg(pad, ptr_id, 8U))
|
||||
|
||||
// Cursor: a client that asks for a text cursor gets it inside its window...
|
||||
let shape_mgr = bind_global(c, reg_id, "wp_cursor_shape_manager_v1", 1U)
|
||||
let shape_dev = c.alloc_id()
|
||||
|
||||
@@ -108,6 +108,14 @@ pub fn Kms::take_input(_self : Kms) -> Array[@nested.InputEvent] {
|
||||
c_arg(4).reinterpret_as_uint(),
|
||||
),
|
||||
)
|
||||
5 =>
|
||||
out.push(
|
||||
Scroll(
|
||||
a.reinterpret_as_uint(),
|
||||
b.to_double() / 256.0,
|
||||
c_arg(3),
|
||||
),
|
||||
)
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +297,23 @@ static void handle_li_event(struct libinput_event *ev) {
|
||||
libinput_event_pointer_get_button_state(p) == LIBINPUT_BUTTON_STATE_PRESSED, 0, 0);
|
||||
break;
|
||||
}
|
||||
case LIBINPUT_EVENT_POINTER_AXIS: {
|
||||
/* Legacy axis event: still emitted alongside the libinput >= 1.19 scroll events, so one
|
||||
* handler covers wheels, touchpads and trackpoints on every libinput version. Value is in
|
||||
* pointer-motion units (~15 per wheel notch), sent as 24.8 fixed point. */
|
||||
struct libinput_event_pointer *p = libinput_event_get_pointer_event(ev);
|
||||
int wheel = libinput_event_pointer_get_axis_source(p) == LIBINPUT_POINTER_AXIS_SOURCE_WHEEL;
|
||||
static const enum libinput_pointer_axis axes[2] = {
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL };
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (!libinput_event_pointer_has_axis(p, axes[i])) continue;
|
||||
double v = libinput_event_pointer_get_axis_value(p, axes[i]);
|
||||
int steps = wheel ? (int)libinput_event_pointer_get_axis_value_discrete(p, axes[i]) : 0;
|
||||
if (v == 0.0 && steps == 0) continue; /* scroll stop */
|
||||
q_push(EV_AXIS, i, (int32_t)(v * 256.0), steps, 0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ pub fn Kms::take_input(_self : Kms) -> Array[@nested.InputEvent] {
|
||||
PointerButton(k) => out.push(PointerButton(k.code, k.pressed))
|
||||
Key(k) => out.push(Key(k.code, k.pressed))
|
||||
Modifiers(m) => out.push(Modifiers(m.depressed, m.latched, m.locked, m.group))
|
||||
Scroll(d) => out.push(Scroll(d.axis, d.value, d.discrete))
|
||||
}
|
||||
}
|
||||
out
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
pub(all) enum InputEvent {
|
||||
PointerMove(Double, Double)
|
||||
PointerButton(UInt, Bool)
|
||||
/// Vertical wheel scroll in wl_fixed units / 256 (positive = down).
|
||||
Scroll(Double)
|
||||
/// Wheel/touchpad scroll: axis (0 vertical, 1 horizontal), distance in surface pixels
|
||||
/// (positive = down/right) and wheel notches (0 when not from a wheel, e.g. a touchpad).
|
||||
Scroll(UInt, Double, Int)
|
||||
Key(UInt, Bool)
|
||||
Modifiers(UInt, UInt, UInt, UInt)
|
||||
}
|
||||
@@ -36,6 +37,9 @@ pub(all) struct NestedWindow {
|
||||
mut xdg_surf_id : UInt
|
||||
mut toplevel_id : UInt
|
||||
mut pointer_id : UInt
|
||||
/// wl_pointer.axis_discrete steps waiting for their axis event (vertical, horizontal).
|
||||
mut discrete_v : Int
|
||||
mut discrete_h : Int
|
||||
mut sync_cb : UInt
|
||||
mut sync_done : Bool
|
||||
mut frame_cb : UInt
|
||||
@@ -248,7 +252,21 @@ fn NestedWindow::dispatch(
|
||||
let axis = r.u32()
|
||||
let value = r.i32().to_double() / 256.0
|
||||
if axis == 0U {
|
||||
self.input.push(Scroll(value))
|
||||
self.input.push(Scroll(0U, value, self.discrete_v))
|
||||
self.discrete_v = 0
|
||||
} else if axis == 1U {
|
||||
self.input.push(Scroll(1U, value, self.discrete_h))
|
||||
self.discrete_h = 0
|
||||
}
|
||||
}
|
||||
8U => {
|
||||
// axis_discrete (seat v5+): sent before the axis event of the same frame.
|
||||
let axis = r.u32()
|
||||
let steps = r.i32()
|
||||
if axis == 0U {
|
||||
self.discrete_v = steps
|
||||
} else if axis == 1U {
|
||||
self.discrete_h = steps
|
||||
}
|
||||
}
|
||||
_ => ()
|
||||
@@ -321,6 +339,8 @@ pub fn NestedWindow::open(
|
||||
xdg_surf_id: 0U,
|
||||
toplevel_id: 0U,
|
||||
pointer_id: 0U,
|
||||
discrete_v: 0,
|
||||
discrete_h: 0,
|
||||
sync_cb: 0U,
|
||||
sync_done: false,
|
||||
frame_cb: 0U,
|
||||
|
||||
@@ -1300,6 +1300,45 @@ pub fn WaylandServer::pointer_button(self : WaylandServer, win_id : UInt64, time
|
||||
}
|
||||
}
|
||||
|
||||
///| Scroll: `axis` 0 vertical / 1 horizontal, `value` in surface pixels (positive = down/right),
|
||||
/// `discrete` wheel notches (0 for continuous sources such as touchpads).
|
||||
pub fn WaylandServer::pointer_axis(
|
||||
self : WaylandServer,
|
||||
win_id : UInt64,
|
||||
time_ms : UInt,
|
||||
axis : UInt,
|
||||
value : Double,
|
||||
discrete : Int,
|
||||
) -> Unit {
|
||||
match self.win_client(win_id) {
|
||||
None => ()
|
||||
Some((c, _)) =>
|
||||
for pid in c.pointer_ids {
|
||||
if c.seat_ver >= 5U && discrete != 0 {
|
||||
// axis_source(wheel), then the notch count, both before the axis event.
|
||||
let ws = WireWriter::new()
|
||||
ws.u32(0U)
|
||||
c.send_msg(ws.finish_msg(pid, 6U))
|
||||
let wd = WireWriter::new()
|
||||
wd.u32(axis)
|
||||
if c.seat_ver >= 8U {
|
||||
wd.i32(discrete * 120)
|
||||
c.send_msg(wd.finish_msg(pid, 9U)) // axis_value120
|
||||
} else {
|
||||
wd.i32(discrete)
|
||||
c.send_msg(wd.finish_msg(pid, 8U)) // axis_discrete
|
||||
}
|
||||
}
|
||||
let w = WireWriter::new()
|
||||
w.u32(time_ms)
|
||||
w.u32(axis)
|
||||
w.i32(fixed(value))
|
||||
c.send_msg(w.finish_msg(pid, 4U))
|
||||
self.pointer_frame(c, pid)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn WaylandServer::pointer_frame(_self : WaylandServer, c : ClientConn, pid : UInt) -> Unit {
|
||||
if c.seat_ver >= 5U {
|
||||
|
||||
Reference in new issue
Block a user