diff options
| author | srdusr <[email protected]> | 2024-07-31 17:34:00 +0200 |
|---|---|---|
| committer | srdusr <[email protected]> | 2024-07-31 17:34:00 +0200 |
| commit | f166df4d979162ae09b439c87cdc64f2b0981308 (patch) | |
| tree | b337d88dec627ab1e49b91f1f3c91de06a7af692 /crates/wayland/src/winit/events.rs | |
| parent | c180bfc34e4c74ba7cac9e0220e9c172c239fe71 (diff) | |
| download | srdwm-f166df4d979162ae09b439c87cdc64f2b0981308.tar.gz srdwm-f166df4d979162ae09b439c87cdc64f2b0981308.zip | |
Split crates/wayland/src/winit.rs (889 lines) into winit/
Pure reorganization, no behavior change - verified by diffing the
function-name and struct-name sets before/after (both identical) plus
a full cargo test pass. mod.rs keeps the module doc comment, imports,
WaylandPlatform's struct definition, and TARGET_FRAME_TIME, plus mod
declarations. The rest splits by concern:
- connect.rs: connect(), the ~200-line setup/init function.
- run.rs: accept_clients, pump_winit - the small per-poll pair.
- render.rs: render_frame, the per-frame render loop (left as one
intact ~330-line function, same reasoning as udev's render.rs: its
structure is deliberate and already documented inline, not a target
for further decomposition in a pure reorganization pass).
- capture.rs: capture_offscreen, the screencopy path.
- events.rs: handle_winit_event.
- platform.rs: `impl Platform for WaylandPlatform`.
No tests module existed in the original file, so none was split out.
A handful of methods/functions (accept_clients, pump_winit,
render_frame, capture_offscreen, handle_winit_event) went from private
to pub(super): called across what are now sibling submodules, which
Rust's privacy model doesn't let see each other's private items.
Diffstat (limited to 'crates/wayland/src/winit/events.rs')
| -rw-r--r-- | crates/wayland/src/winit/events.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/crates/wayland/src/winit/events.rs b/crates/wayland/src/winit/events.rs new file mode 100644 index 0000000..017b7d0 --- /dev/null +++ b/crates/wayland/src/winit/events.rs @@ -0,0 +1,48 @@ +use super::*; + +pub(super) fn handle_winit_event(state: &mut CompState, output: &Output, event: WinitEvent, closed: &mut bool) { + match event { + WinitEvent::CloseRequested => *closed = true, + WinitEvent::Input(InputEvent::Keyboard { event }) => handle_keyboard_key_event(state, &event), + WinitEvent::Input(InputEvent::PointerMotionAbsolute { event }) => { + let size = output.current_mode().map(|m| m.size).unwrap_or_default().to_logical(1); + let pos = event.position_transformed(size); + handle_pointer_position(state, pos, event.time_msec()); + } + WinitEvent::Input(InputEvent::PointerButton { event }) => { + let pos = last_pointer_pos(state); + let button = event.button_code(); + let pressed = event.state() == BackendButtonState::Pressed; + handle_pointer_button(state, pos, button, pressed, event.time_msec()); + } + // This backend had no scroll handling at all - `InputEvent:: + // PointerAxis` fell into the catch-all below and was silently + // dropped, unconditionally, on every device. Same forwarding as + // `udev.rs`'s equivalent (see its own comment for the `stop()`/ + // `v120()` reasoning); duplicated rather than shared since the two + // backends' `InputEvent` generic parameters differ and there's no + // shared event type to write one function against. + WinitEvent::Input(InputEvent::PointerAxis { event }) => { + if crate::input::handle_workspace_scroll(state, &event) { + return; + } + let Some(pointer) = state.seat.get_pointer() else { return }; + let source = event.source(); + let mut frame = smithay::input::pointer::AxisFrame::new(event.time_msec()).source(source); + for axis in [Axis::Horizontal, Axis::Vertical] { + match event.amount(axis) { + Some(value) => frame = frame.value(axis, value), + None if source == AxisSource::Finger => frame = frame.stop(axis), + None => {} + } + if let Some(v120) = event.amount_v120(axis) { + frame = frame.v120(axis, v120 as i32); + } + } + pointer.axis(state, frame); + pointer.frame(state); + } + WinitEvent::Resized { .. } => {} + _ => {} + } +} |