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,
input::pointer::{
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
},
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::{Logical, Point},
use smithay::desktop::Window;
use smithay::input::pointer::{
AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
PointerInnerHandle, RelativeMotionEvent,
};
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::{Logical, Point};
use crate::Smallvil;
pub struct MoveSurfaceGrab {
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 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! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct ResizeEdge: u32 {
@ -56,7 +56,10 @@ impl ResizeSurfaceGrab {
let initial_rect = initial_window_rect;
ResizeSurfaceState::with(window.toplevel().wl_surface(), |state| {
*state = ResizeSurfaceState::Resizing { edges, initial_rect };
*state = ResizeSurfaceState::Resizing {
edges,
initial_rect,
};
});
Self {
@ -101,10 +104,11 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
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 data = states.cached_state.current::<SurfaceCachedState>();
(data.min_size, data.max_size)
});
let (min_size, max_size) =
compositor::with_states(self.window.toplevel().wl_surface(), |states| {
let data = states.cached_state.current::<SurfaceCachedState>();
(data.min_size, data.max_size)
});
let min_width = min_size.w.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>)> {
match *self {
Self::Resizing { edges, initial_rect } => Some((edges, initial_rect)),
Self::WaitingForLastCommit { edges, initial_rect } => {
Self::Resizing {
edges,
initial_rect,
} => Some((edges, initial_rect)),
Self::WaitingForLastCommit {
edges,
initial_rect,
} => {
// The resize is done, let's go back to 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,
delegate_compositor, delegate_shm,
reexports::wayland_server::{
protocol::{wl_buffer, wl_surface::WlSurface},
Client,
},
wayland::{
buffer::BufferHandler,
compositor::{
get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
},
shm::{ShmHandler, ShmState},
},
use smithay::backend::renderer::utils::on_commit_buffer_handler;
use smithay::reexports::wayland_server::protocol::wl_buffer;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Client;
use smithay::wayland::buffer::BufferHandler;
use smithay::wayland::compositor::{
get_parent, is_sync_subsurface, CompositorClientState, CompositorHandler, CompositorState,
};
use smithay::wayland::shm::{ShmHandler, ShmState};
use smithay::{delegate_compositor, delegate_shm};
use super::xdg_shell;
use crate::grabs::resize_grab;
use crate::state::ClientState;
use crate::Smallvil;
impl CompositorHandler for Smallvil {
fn compositor_state(&mut self) -> &mut CompositorState {
@ -33,7 +30,11 @@ impl CompositorHandler for Smallvil {
while let Some(parent) = get_parent(&root) {
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();
}
};

View file

@ -1,17 +1,17 @@
mod compositor;
mod xdg_shell;
use crate::Smallvil;
//
// Wl Seat
//
use smithay::input::{SeatHandler, SeatState};
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 crate::Smallvil;
impl SeatHandler for Smallvil {
type KeyboardFocus = WlSurface;
type PointerFocus = WlSurface;

View file

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

View file

@ -1,15 +1,11 @@
use smithay::{
backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
},
input::{
keyboard::FilterResult,
pointer::{AxisFrame, ButtonEvent, MotionEvent},
},
reexports::wayland_server::protocol::wl_surface::WlSurface,
utils::SERIAL_COUNTER,
use smithay::backend::input::{
AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent,
KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent,
};
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;
@ -70,7 +66,11 @@ impl Smallvil {
.map(|(w, l)| (w.clone(), l))
{
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| {
window.toplevel().send_pending_configure();
});

View file

@ -7,7 +7,8 @@ mod input;
mod state;
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 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::{
desktop::{Space, Window, WindowSurfaceType},
input::{pointer::PointerHandle, Seat, SeatState},
reexports::{
calloop::{generic::Generic, EventLoop, Interest, LoopSignal, Mode, PostAction},
wayland_server::{
backend::{ClientData, ClientId, DisconnectReason},
protocol::wl_surface::WlSurface,
Display,
},
},
utils::{Logical, Point},
wayland::{
compositor::{CompositorClientState, CompositorState},
data_device::DataDeviceState,
output::OutputManagerState,
shell::xdg::XdgShellState,
shm::ShmState,
socket::ListeningSocketSource,
},
};
use smithay::desktop::{Space, Window, WindowSurfaceType};
use smithay::input::pointer::PointerHandle;
use smithay::input::{Seat, SeatState};
use smithay::reexports::calloop::generic::Generic;
use smithay::reexports::calloop::{EventLoop, Interest, LoopSignal, Mode, PostAction};
use smithay::reexports::wayland_server::backend::{ClientData, ClientId, DisconnectReason};
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Display;
use smithay::utils::{Logical, Point};
use smithay::wayland::compositor::{CompositorClientState, CompositorState};
use smithay::wayland::data_device::DataDeviceState;
use smithay::wayland::output::OutputManagerState;
use smithay::wayland::shell::xdg::XdgShellState;
use smithay::wayland::shm::ShmState;
use smithay::wayland::socket::ListeningSocketSource;
use crate::CalloopData;
@ -59,8 +55,9 @@ impl Smallvil {
// 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");
// Notify clients that we have a keyboard, for the sake of the example we assume that keyboard is always present.
// You may want to track keyboard hot-plug in real compositor.
// Notify clients that we have a keyboard, for the sake of the example we assume that
// keyboard is always present. You may want to track keyboard hot-plug in real
// compositor.
seat.add_keyboard(Default::default(), 200, 200).unwrap();
// Notify clients that we have a pointer (mouse)
@ -99,7 +96,8 @@ impl Smallvil {
display: &mut Display<Smallvil>,
event_loop: &mut EventLoop<CalloopData>,
) -> 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();
// Get the name of the listening socket.
@ -122,7 +120,8 @@ impl Smallvil {
})
.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
.insert_source(
Generic::new(
@ -145,11 +144,13 @@ impl Smallvil {
pointer: &PointerHandle<Self>,
) -> Option<(WlSurface, Point<i32, Logical>)> {
let pos = pointer.current_location();
self.space.element_under(pos).and_then(|(window, location)| {
window
.surface_under(pos - location.to_f64(), WindowSurfaceType::ALL)
.map(|(s, p)| (s, p + location))
})
self.space
.element_under(pos)
.and_then(|(window, 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 smithay::{
backend::{
renderer::{
damage::OutputDamageTracker, element::surface::WaylandSurfaceRenderElement, gles::GlesRenderer,
},
winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend},
},
output::{Mode, Output, PhysicalProperties, Subpixel},
reexports::calloop::{
timer::{TimeoutAction, Timer},
EventLoop,
},
utils::{Rectangle, Transform},
};
use smithay::backend::renderer::damage::OutputDamageTracker;
use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
use smithay::backend::renderer::gles::GlesRenderer;
use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend};
use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
use smithay::reexports::calloop::EventLoop;
use smithay::utils::{Rectangle, Transform};
use crate::{CalloopData, Smallvil};
@ -41,7 +35,12 @@ pub fn init_winit(
},
);
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);
state.space.map_output(&output, (0, 0));
@ -53,18 +52,20 @@ pub fn init_winit(
let mut full_redraw = 0u8;
let timer = Timer::immediate();
event_loop.handle().insert_source(timer, move |_, _, data| {
winit_dispatch(
&mut backend,
&mut winit,
data,
&output,
&mut damage_tracker,
&mut full_redraw,
)
.unwrap();
TimeoutAction::ToDuration(Duration::from_millis(16))
})?;
event_loop
.handle()
.insert_source(timer, move |_, _, data| {
winit_dispatch(
&mut backend,
&mut winit,
data,
&output,
&mut damage_tracker,
&mut full_redraw,
)
.unwrap();
TimeoutAction::ToDuration(Duration::from_millis(16))
})?;
Ok(())
}