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:
Claude authored and V committed 2026-11-25 17:07:33 +00:00
1 parent 63e63c65e0
commit d0d375c071
12 files changed
+197 -41

No files matched your search

+40 -1
View File
@@ -1067,10 +1067,49 @@ pub fn MoonPlasmaCompositor::handle_input(
_ => self.leave_pointer()
}
}
Scroll(v) => {
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()
+12
View File
@@ -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()
+8
View File
@@ -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),
),
)
_ => ()
}
}
+17
View File
@@ -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;
}
+1
View File
@@ -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
+23 -3
View File
@@ -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,
+39
View File
@@ -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 {
+6 -1
View File
@@ -1,7 +1,7 @@
//! The login-session display backend: calls into compositor/kms/kms_stub.c (built by build.rs),
//! the same shim the native compositor uses. One display, one seat, global state.
use crate::moonplasma::host::display::{KeyState, Modifiers, Output, PointerPos, SeatEvent};
use crate::moonplasma::host::display::{KeyState, Modifiers, Output, PointerPos, ScrollDelta, SeatEvent};
extern "C" {
fn mp_kms_open() -> i32;
@@ -80,6 +80,11 @@ pub fn take_input() -> Vec<SeatEvent> {
locked: mp_kms_arg(3) as u32,
group: mp_kms_arg(4) as u32,
})),
5 => out.push(SeatEvent::Scroll(ScrollDelta {
axis: a as u32,
value: b as f64 / 256.0,
discrete: mp_kms_arg(3),
})),
_ => {}
}
}
+19 -19
View File
@@ -25,26 +25,21 @@ fn wasmImportTakeInput(p0 : Int) = "moonplasma:host/display@0.1.0" "take-input"
fn wasmImportClose() = "moonplasma:host/display@0.1.0" "close"
///|
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
///|
extern "wasm" fn mbt_ffi_loadf64(offset : Int) -> Double =
#|(func (param i32) (result f64) local.get 0 f64.load)
///|
#owned(bytes)
extern "wasm" fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int =
#|(func (param i32) (result i32) local.get 0)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
///|
extern "wasm" fn mbt_ffi_loadf64(offset : Int) -> Double =
#|(func (param i32) (result f64) local.get 0 f64.load)
///|
extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#|(func (param i32) (result i32) (local i32)
@@ -53,9 +48,14 @@ extern "wasm" fn mbt_ffi_malloc(size : Int) -> Int =
#| local.get 1)
///|
extern "wasm" fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] =
#|(func (param i32) (param i32) (result i32)
#| local.get 0
#| local.get 1 call $moonbit.init_array8
#| local.get 0)
extern "wasm" fn mbt_ffi_load8_u(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load8_u)
///|
extern "wasm" fn mbt_ffi_load32(offset : Int) -> Int =
#|(func (param i32) (result i32) local.get 0 i32.load)
///|
extern "wasm" fn mbt_ffi_free(position : Int) =
#|(func (param i32) local.get 0 call $moonbit.decref)
@@ -41,7 +41,12 @@ fn wasmImportClose() -> Unit {
}
///|
fn mbt_ffi_load8_u(offset : Int) -> Int {
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
///|
fn mbt_ffi_loadf64(offset : Int) -> Double {
abort("wasm-only")
}
@@ -50,6 +55,16 @@ fn mbt_ffi_bytes2ptr(bytes : FixedArray[Byte]) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load8_u(offset : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_load32(offset : Int) -> Int {
abort("wasm-only")
@@ -59,18 +74,3 @@ fn mbt_ffi_load32(offset : Int) -> Int {
fn mbt_ffi_free(position : Int) -> Unit {
abort("wasm-only")
}
///|
fn mbt_ffi_loadf64(offset : Int) -> Double {
abort("wasm-only")
}
///|
fn mbt_ffi_malloc(size : Int) -> Int {
abort("wasm-only")
}
///|
fn mbt_ffi_ptr2bytes(ptr : Int, len : Int) -> FixedArray[Byte] {
abort("wasm-only")
}
+12 -1
View File
@@ -17,11 +17,18 @@ pub(all) struct Modifiers {
depressed : UInt; latched : UInt; locked : UInt; group : UInt
}
///|
/// Wheel/touchpad scroll: axis (0 vertical, 1 horizontal), distance in pixels (positive =
/// down/right), wheel notches (0 when not from a wheel).
pub(all) struct ScrollDelta {
axis : UInt; value : Double; discrete : Int
}
///|
pub(all) enum SeatEvent {
PointerMove(PointerPos)
PointerButton(KeyState)
Key(KeyState)
Modifiers(Modifiers)
Scroll(ScrollDelta)
}
///|
/// Take over the first connected output and the seat's input. None, with the reason on the
@@ -98,7 +105,7 @@ pub fn take_input() -> Array[SeatEvent] {
let array : Array[SeatEvent] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 24)
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 32)
let lifted = match (mbt_ffi_load8_u((iter_base) + 0)) {
0 => {
@@ -117,6 +124,10 @@ pub fn take_input() -> Array[SeatEvent] {
SeatEvent::Modifiers(Modifiers::{depressed : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), latched : (mbt_ffi_load32((iter_base) + 12)).reinterpret_as_uint(), locked : (mbt_ffi_load32((iter_base) + 16)).reinterpret_as_uint(), group : (mbt_ffi_load32((iter_base) + 20)).reinterpret_as_uint()})
}
4 => {
SeatEvent::Scroll(ScrollDelta::{axis : (mbt_ffi_load32((iter_base) + 8)).reinterpret_as_uint(), value : mbt_ffi_loadf64((iter_base) + 16), discrete : mbt_ffi_load32((iter_base) + 24)})
}
_ => panic()
}
+4
View File
@@ -30,11 +30,15 @@ interface display {
/// A button or key as an evdev code, pressed or released.
record key-state { code: u32, pressed: bool }
record modifiers { depressed: u32, latched: u32, locked: u32, group: u32 }
/// Wheel/touchpad scroll: axis (0 vertical, 1 horizontal), distance in pixels (positive =
/// down/right), wheel notches (0 when not from a wheel).
record scroll-delta { axis: u32, value: f64, discrete: s32 }
variant seat-event {
pointer-move(pointer-pos),
pointer-button(key-state),
key(key-state),
modifiers(modifiers),
scroll(scroll-delta),
}
/// Input queued since the last call.
take-input: func() -> list<seat-event>;