Add rustfmt.toml and reformat

This commit is contained in:
Ivan Molodetskikh 2023-08-07 19:45:55 +04:00
parent ad3c3f8cef
commit c6838b08e2
10 changed files with 153 additions and 147 deletions

4
rustfmt.toml Normal file
View file

@ -0,0 +1,4 @@
imports_granularity = "Module"
group_imports = "StdExternalCrate"
wrap_comments = true
comment_width = 100

View file

@ -1,13 +1,12 @@
use crate::Smallvil; use smithay::desktop::Window;
use smithay::{ use smithay::input::pointer::{
desktop::Window, AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
input::pointer::{ PointerInnerHandle, RelativeMotionEvent,
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
},
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{Logical, Point},
}; };
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::{Logical, Point};
use crate::Smallvil;
pub struct MoveSurfaceGrab { pub struct MoveSurfaceGrab {
pub start_data: PointerGrabStartData<Smallvil>, pub start_data: PointerGrabStartData<Smallvil>,

View file

@ -1,18 +1,18 @@
use crate::Smallvil;
use smithay::{
desktop::{Space, Window},
input::pointer::{
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
},
reexports::{
wayland_protocols::xdg::shell::server::xdg_toplevel, wayland_server::protocol::wl_surface::WlSurface,
},
utils::{Logical, Point, Rectangle, Size},
wayland::{compositor, shell::xdg::SurfaceCachedState},
};
use std::cell::RefCell; use std::cell::RefCell;
use smithay::desktop::{Space, Window};
use smithay::input::pointer::{
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
};
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::{Logical, Point, Rectangle, Size};
use smithay::wayland::compositor;
use smithay::wayland::shell::xdg::SurfaceCachedState;
use crate::Smallvil;
bitflags::bitflags! { bitflags::bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ResizeEdge: u32 { pub struct ResizeEdge: u32 {
@ -56,7 +56,10 @@ impl ResizeSurfaceGrab {
let initial_rect = initial_window_rect; let initial_rect = initial_window_rect;
ResizeSurfaceState::with(window.toplevel().wl_surface(), |state| { ResizeSurfaceState::with(window.toplevel().wl_surface(), |state| {
*state = ResizeSurfaceState::Resizing { edges, initial_rect }; *state = ResizeSurfaceState::Resizing {
edges,
initial_rect,
};
}); });
Self { Self {
@ -101,10 +104,11 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
new_window_height = (self.initial_rect.size.h as f64 + delta.y) as i32; new_window_height = (self.initial_rect.size.h as f64 + delta.y) as i32;
} }
let (min_size, max_size) = compositor::with_states(self.window.toplevel().wl_surface(), |states| { let (min_size, max_size) =
let data = states.cached_state.current::<SurfaceCachedState>(); compositor::with_states(self.window.toplevel().wl_surface(), |states| {
(data.min_size, data.max_size) let data = states.cached_state.current::<SurfaceCachedState>();
}); (data.min_size, data.max_size)
});
let min_width = min_size.w.max(1); let min_width = min_size.w.max(1);
let min_height = min_size.h.max(1); let min_height = min_size.h.max(1);
@ -219,8 +223,14 @@ impl ResizeSurfaceState {
fn commit(&mut self) -> Option<(ResizeEdge, Rectangle<i32, Logical>)> { fn commit(&mut self) -> Option<(ResizeEdge, Rectangle<i32, Logical>)> {
match *self { match *self {
Self::Resizing { edges, initial_rect } => Some((edges, initial_rect)), Self::Resizing {
Self::WaitingForLastCommit { edges, initial_rect } => { edges,
initial_rect,
} => Some((edges, initial_rect)),
Self::WaitingForLastCommit {
edges,
initial_rect,
} => {
// The resize is done, let's go back to idle // The resize is done, let's go back to idle
*self = Self::Idle; *self = Self::Idle;

View file

@ -1,21 +1,18 @@
use crate::{grabs::resize_grab, state::ClientState, Smallvil}; use smithay::backend::renderer::utils::on_commit_buffer_handler;
use smithay::{ use smithay::reexports::wayland_server::protocol::wl_buffer;
backend::renderer::utils::on_commit_buffer_handler, use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
delegate_compositor, delegate_shm, use smithay::reexports::wayland_server::Client;
reexports::wayland_server::{ use smithay::wayland::buffer::BufferHandler;
protocol::{wl_buffer, wl_surface::WlSurface}, use smithay::wayland::compositor::{
Client, get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
},
wayland::{
buffer::BufferHandler,
compositor::{
get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
},
shm::{ShmHandler, ShmState},
},
}; };
use smithay::wayland::shm::{ShmHandler, ShmState};
use smithay::{delegate_compositor, delegate_shm};
use super::xdg_shell; use super::xdg_shell;
use crate::grabs::resize_grab;
use crate::state::ClientState;
use crate::Smallvil;
impl CompositorHandler for Smallvil { impl CompositorHandler for Smallvil {
fn compositor_state(&mut self) -> &mut CompositorState { fn compositor_state(&mut self) -> &mut CompositorState {
@ -33,7 +30,11 @@ impl CompositorHandler for Smallvil {
while let Some(parent) = get_parent(&root) { while let Some(parent) = get_parent(&root) {
root = parent; root = parent;
} }
if let Some(window) = self.space.elements().find(|w| w.toplevel().wl_surface() == &root) { if let Some(window) = self
.space
.elements()
.find(|w| w.toplevel().wl_surface() == &root)
{
window.on_commit(); window.on_commit();
} }
}; };

View file

@ -1,17 +1,17 @@
mod compositor; mod compositor;
mod xdg_shell; mod xdg_shell;
use crate::Smallvil;
// //
// Wl Seat // Wl Seat
//
use smithay::input::{SeatHandler, SeatState}; use smithay::input::{SeatHandler, SeatState};
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::wayland::data_device::{ClientDndGrabHandler, DataDeviceHandler, ServerDndGrabHandler}; use smithay::wayland::data_device::{
ClientDndGrabHandler, DataDeviceHandler, ServerDndGrabHandler,
};
use smithay::{delegate_data_device, delegate_output, delegate_seat}; use smithay::{delegate_data_device, delegate_output, delegate_seat};
use crate::Smallvil;
impl SeatHandler for Smallvil { impl SeatHandler for Smallvil {
type KeyboardFocus = WlSurface; type KeyboardFocus = WlSurface;
type PointerFocus = WlSurface; type PointerFocus = WlSurface;

View file

@ -1,31 +1,20 @@
use smithay::{ use smithay::delegate_xdg_shell;
delegate_xdg_shell, use smithay::desktop::{Space, Window};
desktop::{Space, Window}, use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};
input::{ use smithay::input::Seat;
pointer::{Focus, GrabStartData as PointerGrabStartData}, use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
Seat, use smithay::reexports::wayland_server::protocol::wl_seat;
}, use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
reexports::{ use smithay::reexports::wayland_server::Resource;
wayland_protocols::xdg::shell::server::xdg_toplevel, use smithay::utils::{Rectangle, Serial};
wayland_server::{ use smithay::wayland::compositor::with_states;
protocol::{wl_seat, wl_surface::WlSurface}, use smithay::wayland::shell::xdg::{
Resource, PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
}, XdgToplevelSurfaceData,
},
utils::{Rectangle, Serial},
wayland::{
compositor::with_states,
shell::xdg::{
PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
XdgToplevelSurfaceData,
},
},
}; };
use crate::{ use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};
grabs::{MoveSurfaceGrab, ResizeSurfaceGrab}, use crate::Smallvil;
Smallvil,
};
impl XdgShellHandler for Smallvil { impl XdgShellHandler for Smallvil {
fn xdg_shell_state(&mut self) -> &mut XdgShellState { fn xdg_shell_state(&mut self) -> &mut XdgShellState {

View file

@ -1,15 +1,11 @@
use smithay::{ use smithay::backend::input::{
backend::input::{ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent, KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
},
input::{
keyboard::FilterResult,
pointer::{AxisFrame, ButtonEvent, MotionEvent},
},
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::SERIAL_COUNTER,
}; };
use smithay::input::keyboard::FilterResult;
use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent};
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::SERIAL_COUNTER;
use crate::state::Smallvil; use crate::state::Smallvil;
@ -70,7 +66,11 @@ impl Smallvil {
.map(|(w, l)| (w.clone(), l)) .map(|(w, l)| (w.clone(), l))
{ {
self.space.raise_element(&window, true); self.space.raise_element(&window, true);
keyboard.set_focus(self, Some(window.toplevel().wl_surface().clone()), serial); keyboard.set_focus(
self,
Some(window.toplevel().wl_surface().clone()),
serial,
);
self.space.elements().for_each(|window| { self.space.elements().for_each(|window| {
window.toplevel().send_pending_configure(); window.toplevel().send_pending_configure();
}); });

View file

@ -7,7 +7,8 @@ mod input;
mod state; mod state;
mod winit; mod winit;
use smithay::reexports::{calloop::EventLoop, wayland_server::Display}; use smithay::reexports::calloop::EventLoop;
use smithay::reexports::wayland_server::Display;
pub use state::Smallvil; pub use state::Smallvil;
pub struct CalloopData { pub struct CalloopData {

View file

@ -1,26 +1,22 @@
use std::{ffi::OsString, os::unix::io::AsRawFd, sync::Arc}; use std::ffi::OsString;
use std::os::unix::io::AsRawFd;
use std::sync::Arc;
use smithay::{ use smithay::desktop::{Space, Window, WindowSurfaceType};
desktop::{Space, Window, WindowSurfaceType}, use smithay::input::pointer::PointerHandle;
input::{pointer::PointerHandle, Seat, SeatState}, use smithay::input::{Seat, SeatState};
reexports::{ use smithay::reexports::calloop::generic::Generic;
calloop::{generic::Generic, EventLoop, Interest, LoopSignal, Mode, PostAction}, use smithay::reexports::calloop::{EventLoop, Interest, LoopSignal, Mode, PostAction};
wayland_server::{ use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
backend::{ClientData, ClientId, DisconnectReason}, use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
protocol::wl_surface::WlSurface, use smithay::reexports::wayland_server::Display;
Display, use smithay::utils::{Logical, Point};
}, use smithay::wayland::compositor::{CompositorClientState, CompositorState};
}, use smithay::wayland::data_device::DataDeviceState;
utils::{Logical, Point}, use smithay::wayland::output::OutputManagerState;
wayland::{ use smithay::wayland::shell::xdg::XdgShellState;
compositor::{CompositorClientState, CompositorState}, use smithay::wayland::shm::ShmState;
data_device::DataDeviceState, use smithay::wayland::socket::ListeningSocketSource;
output::OutputManagerState,
shell::xdg::XdgShellState,
shm::ShmState,
socket::ListeningSocketSource,
},
};
use crate::CalloopData; use crate::CalloopData;
@ -59,8 +55,9 @@ impl Smallvil {
// A seat typically has a pointer and maintains a keyboard focus and a pointer focus. // A seat typically has a pointer and maintains a keyboard focus and a pointer focus.
let mut seat: Seat<Self> = seat_state.new_wl_seat(&dh, "winit"); let mut seat: Seat<Self> = seat_state.new_wl_seat(&dh, "winit");
// Notify clients that we have a keyboard, for the sake of the example we assume that keyboard is always present. // Notify clients that we have a keyboard, for the sake of the example we assume that
// You may want to track keyboard hot-plug in real compositor. // keyboard is always present. You may want to track keyboard hot-plug in real
// compositor.
seat.add_keyboard(Default::default(), 200, 200).unwrap(); seat.add_keyboard(Default::default(), 200, 200).unwrap();
// Notify clients that we have a pointer (mouse) // Notify clients that we have a pointer (mouse)
@ -99,7 +96,8 @@ impl Smallvil {
display: &mut Display<Smallvil>, display: &mut Display<Smallvil>,
event_loop: &mut EventLoop<CalloopData>, event_loop: &mut EventLoop<CalloopData>,
) -> OsString { ) -> OsString {
// Creates a new listening socket, automatically choosing the next available `wayland` socket name. // Creates a new listening socket, automatically choosing the next available `wayland`
// socket name.
let listening_socket = ListeningSocketSource::new_auto().unwrap(); let listening_socket = ListeningSocketSource::new_auto().unwrap();
// Get the name of the listening socket. // Get the name of the listening socket.
@ -122,7 +120,8 @@ impl Smallvil {
}) })
.expect("Failed to init the wayland event source."); .expect("Failed to init the wayland event source.");
// You also need to add the display itself to the event loop, so that client events will be processed by wayland-server. // You also need to add the display itself to the event loop, so that client events will be
// processed by wayland-server.
handle handle
.insert_source( .insert_source(
Generic::new( Generic::new(
@ -145,11 +144,13 @@ impl Smallvil {
pointer: &PointerHandle<Self>, pointer: &PointerHandle<Self>,
) -> Option<(WlSurface, Point<i32, Logical>)> { ) -> Option<(WlSurface, Point<i32, Logical>)> {
let pos = pointer.current_location(); let pos = pointer.current_location();
self.space.element_under(pos).and_then(|(window, location)| { self.space
window .element_under(pos)
.surface_under(pos - location.to_f64(), WindowSurfaceType::ALL) .and_then(|(window, location)| {
.map(|(s, p)| (s, p + location)) window
}) .surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
.map(|(s, p)| (s, p + location))
})
} }
} }

View file

@ -1,19 +1,13 @@
use std::time::Duration; use std::time::Duration;
use smithay::{ use smithay::backend::renderer::damage::OutputDamageTracker;
backend::{ use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
renderer::{ use smithay::backend::renderer::gles::GlesRenderer;
damage::OutputDamageTracker, element::surface::WaylandSurfaceRenderElement, gles::GlesRenderer, use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend};
}, use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend}, use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
}, use smithay::reexports::calloop::EventLoop;
output::{Mode, Output, PhysicalProperties, Subpixel}, use smithay::utils::{Rectangle, Transform};
reexports::calloop::{
timer::{TimeoutAction, Timer},
EventLoop,
},
utils::{Rectangle, Transform},
};
use crate::{CalloopData, Smallvil}; use crate::{CalloopData, Smallvil};
@ -41,7 +35,12 @@ pub fn init_winit(
}, },
); );
let _global = output.create_global::<Smallvil>(&display.handle()); let _global = output.create_global::<Smallvil>(&display.handle());
output.change_current_state(Some(mode), Some(Transform::Flipped180), None, Some((0, 0).into())); output.change_current_state(
Some(mode),
Some(Transform::Flipped180),
None,
Some((0, 0).into()),
);
output.set_preferred(mode); output.set_preferred(mode);
state.space.map_output(&output, (0, 0)); state.space.map_output(&output, (0, 0));
@ -53,18 +52,20 @@ pub fn init_winit(
let mut full_redraw = 0u8; let mut full_redraw = 0u8;
let timer = Timer::immediate(); let timer = Timer::immediate();
event_loop.handle().insert_source(timer, move |_, _, data| { event_loop
winit_dispatch( .handle()
&mut backend, .insert_source(timer, move |_, _, data| {
&mut winit, winit_dispatch(
data, &mut backend,
&output, &mut winit,
&mut damage_tracker, data,
&mut full_redraw, &output,
) &mut damage_tracker,
.unwrap(); &mut full_redraw,
TimeoutAction::ToDuration(Duration::from_millis(16)) )
})?; .unwrap();
TimeoutAction::ToDuration(Duration::from_millis(16))
})?;
Ok(()) Ok(())
} }