style(compositor): apply rustfmt formatting

This commit is contained in:
Marco Allegretti 2026-03-10 21:24:23 +01:00
parent e981044c43
commit fcd4a3bacd
4 changed files with 52 additions and 72 deletions

View file

@ -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::<WeftCompositorState>::new()?;
let mut display = smithay::reexports::wayland_server::Display::<WeftCompositorState>::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, |_| {})?;

View file

@ -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::<WeftCompositorState>::new()?;
let mut display = smithay::reexports::wayland_server::Display::<WeftCompositorState>::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(),

View file

@ -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<B: InputBackend>(
state: &mut WeftCompositorState,
event: InputEvent<B>,
) {
pub fn process_input_event<B: InputBackend>(state: &mut WeftCompositorState, event: InputEvent<B>) {
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<B: InputBackend>(
}
}
fn handle_keyboard<B: InputBackend>(
state: &mut WeftCompositorState,
event: B::KeyboardKeyEvent,
) {
fn handle_keyboard<B: InputBackend>(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<B: InputBackend>(
) {
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<B: InputBackend>(
}
}
fn handle_touch_down<B: InputBackend>(
state: &mut WeftCompositorState,
event: B::TouchDownEvent,
) {
fn handle_touch_down<B: InputBackend>(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<B: InputBackend>(
}
}
fn handle_touch_up<B: InputBackend>(
state: &mut WeftCompositorState,
event: B::TouchUpEvent,
) {
fn handle_touch_up<B: InputBackend>(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<B: InputBackend>(
pub fn surface_under(
state: &WeftCompositorState,
point: Point<f64, Logical>,
) -> Option<(smithay::reexports::wayland_server::protocol::wl_surface::WlSurface, Point<f64, Logical>)> {
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<f64, Logical>,
)> {
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) {

View file

@ -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::<Self>(&display_handle);
let shm_state = ShmState::new::<Self>(&display_handle, vec![]);
let dmabuf_state = DmabufState::new();
let output_manager_state =
OutputManagerState::new_with_xdg_output::<Self>(&display_handle);
let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle);
// Clock ID 1 = CLOCK_MONOTONIC
let presentation_state = PresentationState::new::<Self>(&display_handle, 1);
let text_input_state = TextInputManagerState::new::<Self>(&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);