From fcd4a3bacd115f62d77fb07554123fa9b5d20d14 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Tue, 10 Mar 2026 21:24:23 +0100 Subject: [PATCH] style(compositor): apply rustfmt formatting --- crates/weft-compositor/src/backend/drm.rs | 19 +++---- crates/weft-compositor/src/backend/winit.rs | 9 ++- crates/weft-compositor/src/input.rs | 62 ++++++++------------- crates/weft-compositor/src/state.rs | 34 +++++------ 4 files changed, 52 insertions(+), 72 deletions(-) diff --git a/crates/weft-compositor/src/backend/drm.rs b/crates/weft-compositor/src/backend/drm.rs index f38d3bb..5357263 100644 --- a/crates/weft-compositor/src/backend/drm.rs +++ b/crates/weft-compositor/src/backend/drm.rs @@ -13,17 +13,16 @@ pub fn run() -> anyhow::Result<()> { use smithay::{ backend::{ - session::{libseat::LibSeatSession, Session}, + session::{Session, libseat::LibSeatSession}, udev::{UdevBackend, UdevEvent}, }, - reexports::calloop::{generic::Generic, EventLoop, Interest, Mode, PostAction}, + reexports::calloop::{EventLoop, Interest, Mode, PostAction, generic::Generic}, wayland::socket::ListeningSocketSource, }; use crate::state::{WeftClientState, WeftCompositorState}; - let mut display = - smithay::reexports::wayland_server::Display::::new()?; + let mut display = smithay::reexports::wayland_server::Display::::new()?; let display_handle = display.handle(); let mut event_loop: EventLoop<'static, WeftCompositorState> = EventLoop::try_new()?; @@ -31,8 +30,8 @@ pub fn run() -> anyhow::Result<()> { let loop_signal = event_loop.get_signal(); // Gain DRM device access without root via libseat. - let (session, _notifier) = LibSeatSession::new() - .map_err(|e| anyhow::anyhow!("libseat session failed: {e}"))?; + let (session, _notifier) = + LibSeatSession::new().map_err(|e| anyhow::anyhow!("libseat session failed: {e}"))?; let listening_socket = ListeningSocketSource::new_auto() .map_err(|e| anyhow::anyhow!("Wayland socket creation failed: {e}"))?; @@ -79,12 +78,8 @@ pub fn run() -> anyhow::Result<()> { }) .map_err(|e| anyhow::anyhow!("udev source insertion failed: {e}"))?; - let mut state = WeftCompositorState::new( - display_handle, - loop_signal, - loop_handle, - session.seat(), - ); + let mut state = + WeftCompositorState::new(display_handle, loop_signal, loop_handle, session.seat()); tracing::info!("DRM/KMS backend initialised; entering event loop"); event_loop.run(None, &mut state, |_| {})?; diff --git a/crates/weft-compositor/src/backend/winit.rs b/crates/weft-compositor/src/backend/winit.rs index d14e517..0a44d04 100644 --- a/crates/weft-compositor/src/backend/winit.rs +++ b/crates/weft-compositor/src/backend/winit.rs @@ -9,7 +9,7 @@ use smithay::{ winit::{self, WinitEvent}, }, output::{Mode as OutputMode, Output, PhysicalProperties, Subpixel}, - reexports::calloop::{generic::Generic, EventLoop, Interest, Mode, PostAction}, + reexports::calloop::{EventLoop, Interest, Mode, PostAction, generic::Generic}, utils::{Rectangle, Transform}, wayland::socket::ListeningSocketSource, }; @@ -20,16 +20,15 @@ use crate::{ }; pub fn run() -> anyhow::Result<()> { - let mut display = - smithay::reexports::wayland_server::Display::::new()?; + let mut display = smithay::reexports::wayland_server::Display::::new()?; let display_handle = display.handle(); let mut event_loop: EventLoop<'static, WeftCompositorState> = EventLoop::try_new()?; let loop_handle = event_loop.handle(); let loop_signal = event_loop.get_signal(); - let (mut backend, winit) = winit::init() - .map_err(|e| anyhow::anyhow!("winit init failed: {e}"))?; + let (mut backend, winit) = + winit::init().map_err(|e| anyhow::anyhow!("winit init failed: {e}"))?; let mode = OutputMode { size: backend.window_size(), diff --git a/crates/weft-compositor/src/input.rs b/crates/weft-compositor/src/input.rs index 507ae8f..26412c0 100644 --- a/crates/weft-compositor/src/input.rs +++ b/crates/weft-compositor/src/input.rs @@ -1,31 +1,26 @@ use smithay::{ backend::input::{ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, GestureHoldBeginEvent, - GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, - GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, - GestureSwipeUpdateEvent, InputBackend, InputEvent, KeyState, KeyboardKeyEvent, - PointerAxisEvent, PointerButtonEvent, PointerMotionAbsoluteEvent, PointerMotionEvent, - TouchCancelEvent, TouchDownEvent, TouchFrameEvent, TouchMotionEvent, TouchUpEvent, + GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, + GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, InputBackend, + InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, + PointerMotionAbsoluteEvent, PointerMotionEvent, TouchCancelEvent, TouchDownEvent, + TouchFrameEvent, TouchMotionEvent, TouchUpEvent, }, input::{ keyboard::FilterResult, pointer::{AxisFrame, ButtonEvent, MotionEvent}, }, - utils::{Logical, Point, Serial, SERIAL_COUNTER}, + utils::{Logical, Point, SERIAL_COUNTER, Serial}, }; use crate::state::WeftCompositorState; -pub fn process_input_event( - state: &mut WeftCompositorState, - event: InputEvent, -) { +pub fn process_input_event(state: &mut WeftCompositorState, event: InputEvent) { match event { InputEvent::Keyboard { event } => handle_keyboard(state, event), InputEvent::PointerMotion { event } => handle_pointer_motion(state, event), - InputEvent::PointerMotionAbsolute { event } => { - handle_pointer_motion_absolute(state, event) - } + InputEvent::PointerMotionAbsolute { event } => handle_pointer_motion_absolute(state, event), InputEvent::PointerButton { event } => handle_pointer_button(state, event), InputEvent::PointerAxis { event } => handle_pointer_axis(state, event), InputEvent::TouchDown { event } => handle_touch_down(state, event), @@ -47,10 +42,7 @@ pub fn process_input_event( } } -fn handle_keyboard( - state: &mut WeftCompositorState, - event: B::KeyboardKeyEvent, -) { +fn handle_keyboard(state: &mut WeftCompositorState, event: B::KeyboardKeyEvent) { let serial = SERIAL_COUNTER.next_serial(); let time = event.time_msec(); let key_state = event.state(); @@ -99,10 +91,7 @@ fn handle_pointer_motion_absolute( ) { let output = state.space.outputs().next().cloned(); if let Some(output) = output { - let output_geo = state - .space - .output_geometry(&output) - .unwrap_or_default(); + let output_geo = state.space.output_geometry(&output).unwrap_or_default(); let pos = event.position_transformed(output_geo.size); state.pointer_location = output_geo.loc.to_f64() + pos; } @@ -203,10 +192,7 @@ fn handle_pointer_axis( } } -fn handle_touch_down( - state: &mut WeftCompositorState, - event: B::TouchDownEvent, -) { +fn handle_touch_down(state: &mut WeftCompositorState, event: B::TouchDownEvent) { let serial = SERIAL_COUNTER.next_serial(); let output = state.space.outputs().next().cloned(); if let Some(output) = output { @@ -230,10 +216,7 @@ fn handle_touch_down( } } -fn handle_touch_up( - state: &mut WeftCompositorState, - event: B::TouchUpEvent, -) { +fn handle_touch_up(state: &mut WeftCompositorState, event: B::TouchUpEvent) { let serial = SERIAL_COUNTER.next_serial(); if let Some(touch) = state.seat.get_touch() { touch.up( @@ -428,15 +411,18 @@ fn handle_gesture_hold_end( pub fn surface_under( state: &WeftCompositorState, point: Point, -) -> Option<(smithay::reexports::wayland_server::protocol::wl_surface::WlSurface, Point)> { - state - .space - .element_under(point) - .and_then(|(window, loc)| { - window - .surface_under(point - loc.to_f64(), smithay::desktop::WindowSurfaceType::ALL) - .map(|(surface, surface_loc)| (surface, (loc.to_f64() + surface_loc.to_f64()))) - }) +) -> Option<( + smithay::reexports::wayland_server::protocol::wl_surface::WlSurface, + Point, +)> { + state.space.element_under(point).and_then(|(window, loc)| { + window + .surface_under( + point - loc.to_f64(), + smithay::desktop::WindowSurfaceType::ALL, + ) + .map(|(surface, surface_loc)| (surface, (loc.to_f64() + surface_loc.to_f64()))) + }) } fn clamp_pointer_to_output_space(state: &mut WeftCompositorState) { diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index 566ed3d..6c0f4a0 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -2,33 +2,27 @@ use smithay::{ backend::{input::TabletToolDescriptor, renderer::utils::on_commit_buffer_handler}, delegate_compositor, delegate_cursor_shape, delegate_dmabuf, delegate_input_method_manager, delegate_layer_shell, delegate_output, delegate_pointer_constraints, delegate_presentation, - delegate_seat, delegate_shm, delegate_text_input_manager, - delegate_xdg_shell, - desktop::{ - layer_map_for_output, PopupKind, PopupManager, Space, Window, WindowSurfaceType, - }, - input::{ - keyboard::XkbConfig, - pointer::CursorImageStatus, - Seat, SeatHandler, SeatState, - }, + delegate_seat, delegate_shm, delegate_text_input_manager, delegate_xdg_shell, + desktop::{PopupKind, PopupManager, Space, Window, WindowSurfaceType, layer_map_for_output}, + input::{Seat, SeatHandler, SeatState, keyboard::XkbConfig, pointer::CursorImageStatus}, output::Output, reexports::{ calloop::{LoopHandle, LoopSignal}, wayland_server::{ + Client, DisplayHandle, backend::{ClientData, ClientId, DisconnectReason}, protocol::{wl_buffer::WlBuffer, wl_output::WlOutput, wl_surface::WlSurface}, - Client, DisplayHandle, }, }, utils::{Logical, Point, Rectangle}, wayland::{ - compositor::{CompositorClientState, CompositorHandler, CompositorState}, buffer::BufferHandler, + compositor::{CompositorClientState, CompositorHandler, CompositorState}, cursor_shape::CursorShapeManagerState, dmabuf::{DmabufGlobal, DmabufHandler, DmabufState, ImportNotifier}, - input_method::{InputMethodHandler, InputMethodManagerState, PopupSurface as ImPopupSurface}, - tablet_manager::TabletSeatHandler, + input_method::{ + InputMethodHandler, InputMethodManagerState, PopupSurface as ImPopupSurface, + }, output::OutputManagerState, pointer_constraints::{PointerConstraintsHandler, PointerConstraintsState}, presentation::{PresentationHandler, PresentationState}, @@ -38,6 +32,7 @@ use smithay::{ xdg::{PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState}, }, shm::{ShmHandler, ShmState}, + tablet_manager::TabletSeatHandler, text_input::TextInputManagerState, }, }; @@ -100,8 +95,7 @@ impl WeftCompositorState { let layer_shell_state = WlrLayerShellState::new::(&display_handle); let shm_state = ShmState::new::(&display_handle, vec![]); let dmabuf_state = DmabufState::new(); - let output_manager_state = - OutputManagerState::new_with_xdg_output::(&display_handle); + let output_manager_state = OutputManagerState::new_with_xdg_output::(&display_handle); // Clock ID 1 = CLOCK_MONOTONIC let presentation_state = PresentationState::new::(&display_handle, 1); let text_input_state = TextInputManagerState::new::(&display_handle); @@ -223,7 +217,13 @@ impl XdgShellHandler for WeftCompositorState { } } - fn grab(&mut self, _surface: PopupSurface, _seat: smithay::reexports::wayland_server::protocol::wl_seat::WlSeat, _serial: smithay::utils::Serial) {} + fn grab( + &mut self, + _surface: PopupSurface, + _seat: smithay::reexports::wayland_server::protocol::wl_seat::WlSeat, + _serial: smithay::utils::Serial, + ) { + } } delegate_xdg_shell!(WeftCompositorState);