forge
Explore
Log in

Don't you dare go Hollow

Add rustfmt.toml and reformat

Browse files at this commit

c6838b08e2f65285f1391cec93f918cadb804117Ivan MolodetskikhParent: ad3c3f8
rustfmt.tomladded+4 -0
@@ -0,0 +1,4 @@
1+imports_granularity = "Module"
2+group_imports = "StdExternalCrate"
3+wrap_comments = true
4+comment_width = 100
src/grabs/move_grab.rsmodified+8 -9
@@ -1,13 +1,12 @@
1-use crate::Smallvil;
2-use smithay::{
3- desktop::Window,
4- input::pointer::{
5- AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
6- PointerInnerHandle, RelativeMotionEvent,
7- },
8- reexports::wayland_server::protocol::wl_surface::WlSurface,
9- utils::{Logical, Point},
1+use smithay::desktop::Window;
2+use smithay::input::pointer::{
3+ AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
4+ PointerInnerHandle, RelativeMotionEvent,
105 };
6+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
7+use smithay::utils::{Logical, Point};
8+
9+use crate::Smallvil;
1110
1211 pub struct MoveSurfaceGrab {
1312 pub start_data: PointerGrabStartData<Smallvil>,
src/grabs/resize_grab.rsmodified+30 -20
@@ -1,18 +1,18 @@
1-use crate::Smallvil;
2-use smithay::{
3- desktop::{Space, Window},
4- input::pointer::{
5- AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
6- PointerInnerHandle, RelativeMotionEvent,
7- },
8- reexports::{
9- wayland_protocols::xdg::shell::server::xdg_toplevel, wayland_server::protocol::wl_surface::WlSurface,
10- },
11- utils::{Logical, Point, Rectangle, Size},
12- wayland::{compositor, shell::xdg::SurfaceCachedState},
13-};
141 use std::cell::RefCell;
152
3+use smithay::desktop::{Space, Window};
4+use smithay::input::pointer::{
5+ AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
6+ PointerInnerHandle, RelativeMotionEvent,
7+};
8+use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
9+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
10+use smithay::utils::{Logical, Point, Rectangle, Size};
11+use smithay::wayland::compositor;
12+use smithay::wayland::shell::xdg::SurfaceCachedState;
13+
14+use crate::Smallvil;
15+
1616 bitflags::bitflags! {
1717 #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
1818 pub struct ResizeEdge: u32 {
@@ -56,7 +56,10 @@ impl ResizeSurfaceGrab {
5656 let initial_rect = initial_window_rect;
5757
5858 ResizeSurfaceState::with(window.toplevel().wl_surface(), |state| {
59- *state = ResizeSurfaceState::Resizing { edges, initial_rect };
59+ *state = ResizeSurfaceState::Resizing {
60+ edges,
61+ initial_rect,
62+ };
6063 });
6164
6265 Self {
@@ -101,10 +104,11 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
101104 new_window_height = (self.initial_rect.size.h as f64 + delta.y) as i32;
102105 }
103106
104- let (min_size, max_size) = compositor::with_states(self.window.toplevel().wl_surface(), |states| {
105- let data = states.cached_state.current::<SurfaceCachedState>();
106- (data.min_size, data.max_size)
107- });
107+ let (min_size, max_size) =
108+ compositor::with_states(self.window.toplevel().wl_surface(), |states| {
109+ let data = states.cached_state.current::<SurfaceCachedState>();
110+ (data.min_size, data.max_size)
111+ });
108112
109113 let min_width = min_size.w.max(1);
110114 let min_height = min_size.h.max(1);
@@ -219,8 +223,14 @@ impl ResizeSurfaceState {
219223
220224 fn commit(&mut self) -> Option<(ResizeEdge, Rectangle<i32, Logical>)> {
221225 match *self {
222- Self::Resizing { edges, initial_rect } => Some((edges, initial_rect)),
223- Self::WaitingForLastCommit { edges, initial_rect } => {
226+ Self::Resizing {
227+ edges,
228+ initial_rect,
229+ } => Some((edges, initial_rect)),
230+ Self::WaitingForLastCommit {
231+ edges,
232+ initial_rect,
233+ } => {
224234 // The resize is done, let's go back to idle
225235 *self = Self::Idle;
226236
src/handlers/compositor.rsmodified+17 -16
@@ -1,21 +1,18 @@
1-use crate::{grabs::resize_grab, state::ClientState, Smallvil};
2-use smithay::{
3- backend::renderer::utils::on_commit_buffer_handler,
4- delegate_compositor, delegate_shm,
5- reexports::wayland_server::{
6- protocol::{wl_buffer, wl_surface::WlSurface},
7- Client,
8- },
9- wayland::{
10- buffer::BufferHandler,
11- compositor::{
12- get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
13- },
14- shm::{ShmHandler, ShmState},
15- },
1+use smithay::backend::renderer::utils::on_commit_buffer_handler;
2+use smithay::reexports::wayland_server::protocol::wl_buffer;
3+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
4+use smithay::reexports::wayland_server::Client;
5+use smithay::wayland::buffer::BufferHandler;
6+use smithay::wayland::compositor::{
7+ get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
168 };
9+use smithay::wayland::shm::{ShmHandler, ShmState};
10+use smithay::{delegate_compositor, delegate_shm};
1711
1812 use super::xdg_shell;
13+use crate::grabs::resize_grab;
14+use crate::state::ClientState;
15+use crate::Smallvil;
1916
2017 impl CompositorHandler for Smallvil {
2118 fn compositor_state(&mut self) -> &mut CompositorState {
@@ -33,7 +30,11 @@ impl CompositorHandler for Smallvil {
3330 while let Some(parent) = get_parent(&root) {
3431 root = parent;
3532 }
36- if let Some(window) = self.space.elements().find(|w| w.toplevel().wl_surface() == &root) {
33+ if let Some(window) = self
34+ .space
35+ .elements()
36+ .find(|w| w.toplevel().wl_surface() == &root)
37+ {
3738 window.on_commit();
3839 }
3940 };
src/handlers/mod.rsmodified+5 -5
@@ -1,17 +1,17 @@
11 mod compositor;
22 mod xdg_shell;
33
4-use crate::Smallvil;
5-
64 //
75 // Wl Seat
8-//
9-
106 use smithay::input::{SeatHandler, SeatState};
117 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
12-use smithay::wayland::data_device::{ClientDndGrabHandler, DataDeviceHandler, ServerDndGrabHandler};
8+use smithay::wayland::data_device::{
9+ ClientDndGrabHandler, DataDeviceHandler, ServerDndGrabHandler,
10+};
1311 use smithay::{delegate_data_device, delegate_output, delegate_seat};
1412
13+use crate::Smallvil;
14+
1515 impl SeatHandler for Smallvil {
1616 type KeyboardFocus = WlSurface;
1717 type PointerFocus = WlSurface;
src/handlers/xdg_shell.rsmodified+15 -26
@@ -1,31 +1,20 @@
1-use smithay::{
2- delegate_xdg_shell,
3- desktop::{Space, Window},
4- input::{
5- pointer::{Focus, GrabStartData as PointerGrabStartData},
6- Seat,
7- },
8- reexports::{
9- wayland_protocols::xdg::shell::server::xdg_toplevel,
10- wayland_server::{
11- protocol::{wl_seat, wl_surface::WlSurface},
12- Resource,
13- },
14- },
15- utils::{Rectangle, Serial},
16- wayland::{
17- compositor::with_states,
18- shell::xdg::{
19- PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
20- XdgToplevelSurfaceData,
21- },
22- },
1+use smithay::delegate_xdg_shell;
2+use smithay::desktop::{Space, Window};
3+use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};
4+use smithay::input::Seat;
5+use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
6+use smithay::reexports::wayland_server::protocol::wl_seat;
7+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
8+use smithay::reexports::wayland_server::Resource;
9+use smithay::utils::{Rectangle, Serial};
10+use smithay::wayland::compositor::with_states;
11+use smithay::wayland::shell::xdg::{
12+ PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
13+ XdgToplevelSurfaceData,
2314 };
2415
25-use crate::{
26- grabs::{MoveSurfaceGrab, ResizeSurfaceGrab},
27- Smallvil,
28-};
16+use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};
17+use crate::Smallvil;
2918
3019 impl XdgShellHandler for Smallvil {
3120 fn xdg_shell_state(&mut self) -> &mut XdgShellState {
src/input.rsmodified+12 -12
@@ -1,15 +1,11 @@
1-use smithay::{
2- backend::input::{
3- AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
4- KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
5- },
6- input::{
7- keyboard::FilterResult,
8- pointer::{AxisFrame, ButtonEvent, MotionEvent},
9- },
10- reexports::wayland_server::protocol::wl_surface::WlSurface,
11- utils::SERIAL_COUNTER,
1+use smithay::backend::input::{
2+ AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
3+ KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
124 };
5+use smithay::input::keyboard::FilterResult;
6+use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent};
7+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
8+use smithay::utils::SERIAL_COUNTER;
139
1410 use crate::state::Smallvil;
1511
@@ -70,7 +66,11 @@ impl Smallvil {
7066 .map(|(w, l)| (w.clone(), l))
7167 {
7268 self.space.raise_element(&window, true);
73- keyboard.set_focus(self, Some(window.toplevel().wl_surface().clone()), serial);
69+ keyboard.set_focus(
70+ self,
71+ Some(window.toplevel().wl_surface().clone()),
72+ serial,
73+ );
7474 self.space.elements().for_each(|window| {
7575 window.toplevel().send_pending_configure();
7676 });
src/main.rsmodified+2 -1
@@ -7,7 +7,8 @@ mod input;
77 mod state;
88 mod winit;
99
10-use smithay::reexports::{calloop::EventLoop, wayland_server::Display};
10+use smithay::reexports::calloop::EventLoop;
11+use smithay::reexports::wayland_server::Display;
1112 pub use state::Smallvil;
1213
1314 pub struct CalloopData {
src/state.rsmodified+33 -32
@@ -1,26 +1,22 @@
1-use std::{ffi::OsString, os::unix::io::AsRawFd, sync::Arc};
2-
3-use smithay::{
4- desktop::{Space, Window, WindowSurfaceType},
5- input::{pointer::PointerHandle, Seat, SeatState},
6- reexports::{
7- calloop::{generic::Generic, EventLoop, Interest, LoopSignal, Mode, PostAction},
8- wayland_server::{
9- backend::{ClientData, ClientId, DisconnectReason},
10- protocol::wl_surface::WlSurface,
11- Display,
12- },
13- },
14- utils::{Logical, Point},
15- wayland::{
16- compositor::{CompositorClientState, CompositorState},
17- data_device::DataDeviceState,
18- output::OutputManagerState,
19- shell::xdg::XdgShellState,
20- shm::ShmState,
21- socket::ListeningSocketSource,
22- },
23-};
1+use std::ffi::OsString;
2+use std::os::unix::io::AsRawFd;
3+use std::sync::Arc;
4+
5+use smithay::desktop::{Space, Window, WindowSurfaceType};
6+use smithay::input::pointer::PointerHandle;
7+use smithay::input::{Seat, SeatState};
8+use smithay::reexports::calloop::generic::Generic;
9+use smithay::reexports::calloop::{EventLoop, Interest, LoopSignal, Mode, PostAction};
10+use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
11+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
12+use smithay::reexports::wayland_server::Display;
13+use smithay::utils::{Logical, Point};
14+use smithay::wayland::compositor::{CompositorClientState, CompositorState};
15+use smithay::wayland::data_device::DataDeviceState;
16+use smithay::wayland::output::OutputManagerState;
17+use smithay::wayland::shell::xdg::XdgShellState;
18+use smithay::wayland::shm::ShmState;
19+use smithay::wayland::socket::ListeningSocketSource;
2420
2521 use crate::CalloopData;
2622
@@ -59,8 +55,9 @@ impl Smallvil {
5955 // A seat typically has a pointer and maintains a keyboard focus and a pointer focus.
6056 let mut seat: Seat<Self> = seat_state.new_wl_seat(&dh, "winit");
6157
62- // Notify clients that we have a keyboard, for the sake of the example we assume that keyboard is always present.
63- // You may want to track keyboard hot-plug in real compositor.
58+ // Notify clients that we have a keyboard, for the sake of the example we assume that
59+ // keyboard is always present. You may want to track keyboard hot-plug in real
60+ // compositor.
6461 seat.add_keyboard(Default::default(), 200, 200).unwrap();
6562
6663 // Notify clients that we have a pointer (mouse)
@@ -99,7 +96,8 @@ impl Smallvil {
9996 display: &mut Display<Smallvil>,
10097 event_loop: &mut EventLoop<CalloopData>,
10198 ) -> OsString {
102- // Creates a new listening socket, automatically choosing the next available `wayland` socket name.
99+ // Creates a new listening socket, automatically choosing the next available `wayland`
100+ // socket name.
103101 let listening_socket = ListeningSocketSource::new_auto().unwrap();
104102
105103 // Get the name of the listening socket.
@@ -122,7 +120,8 @@ impl Smallvil {
122120 })
123121 .expect("Failed to init the wayland event source.");
124122
125- // You also need to add the display itself to the event loop, so that client events will be processed by wayland-server.
123+ // You also need to add the display itself to the event loop, so that client events will be
124+ // processed by wayland-server.
126125 handle
127126 .insert_source(
128127 Generic::new(
@@ -145,11 +144,13 @@ impl Smallvil {
145144 pointer: &PointerHandle<Self>,
146145 ) -> Option<(WlSurface, Point<i32, Logical>)> {
147146 let pos = pointer.current_location();
148- self.space.element_under(pos).and_then(|(window, location)| {
149- window
150- .surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
151- .map(|(s, p)| (s, p + location))
152- })
147+ self.space
148+ .element_under(pos)
149+ .and_then(|(window, location)| {
150+ window
151+ .surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
152+ .map(|(s, p)| (s, p + location))
153+ })
153154 }
154155 }
155156
src/winit.rsmodified+28 -27
@@ -1,19 +1,13 @@
11 use std::time::Duration;
22
3-use smithay::{
4- backend::{
5- renderer::{
6- damage::OutputDamageTracker, element::surface::WaylandSurfaceRenderElement, gles::GlesRenderer,
7- },
8- winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend},
9- },
10- output::{Mode, Output, PhysicalProperties, Subpixel},
11- reexports::calloop::{
12- timer::{TimeoutAction, Timer},
13- EventLoop,
14- },
15- utils::{Rectangle, Transform},
16-};
3+use smithay::backend::renderer::damage::OutputDamageTracker;
4+use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
5+use smithay::backend::renderer::gles::GlesRenderer;
6+use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend};
7+use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
8+use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
9+use smithay::reexports::calloop::EventLoop;
10+use smithay::utils::{Rectangle, Transform};
1711
1812 use crate::{CalloopData, Smallvil};
1913
@@ -41,7 +35,12 @@ pub fn init_winit(
4135 },
4236 );
4337 let _global = output.create_global::<Smallvil>(&display.handle());
44- output.change_current_state(Some(mode), Some(Transform::Flipped180), None, Some((0, 0).into()));
38+ output.change_current_state(
39+ Some(mode),
40+ Some(Transform::Flipped180),
41+ None,
42+ Some((0, 0).into()),
43+ );
4544 output.set_preferred(mode);
4645
4746 state.space.map_output(&output, (0, 0));
@@ -53,18 +52,20 @@ pub fn init_winit(
5352 let mut full_redraw = 0u8;
5453
5554 let timer = Timer::immediate();
56- event_loop.handle().insert_source(timer, move |_, _, data| {
57- winit_dispatch(
58- &mut backend,
59- &mut winit,
60- data,
61- &output,
62- &mut damage_tracker,
63- &mut full_redraw,
64- )
65- .unwrap();
66- TimeoutAction::ToDuration(Duration::from_millis(16))
67- })?;
55+ event_loop
56+ .handle()
57+ .insert_source(timer, move |_, _, data| {
58+ winit_dispatch(
59+ &mut backend,
60+ &mut winit,
61+ data,
62+ &output,
63+ &mut damage_tracker,
64+ &mut full_redraw,
65+ )
66+ .unwrap();
67+ TimeoutAction::ToDuration(Duration::from_millis(16))
68+ })?;
6869
6970 Ok(())
7071 }