From f6b3d630ce48ebe63c21b4bc4763ac38025d7961 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Fri, 10 Apr 2020 17:01:49 +0200 Subject: [PATCH] rustfmt --- anvil/src/main.rs | 15 +- anvil/src/shell.rs | 66 ++++-- anvil/src/udev.rs | 6 +- anvil/src/window_map.rs | 7 +- anvil/src/winit.rs | 6 +- examples/raw_drm.rs | 15 +- src/backend/drm/egl/mod.rs | 7 +- src/backend/drm/gbm/mod.rs | 9 +- src/backend/drm/gbm/session.rs | 23 +- src/backend/drm/gbm/surface.rs | 10 +- src/backend/drm/legacy/mod.rs | 16 +- src/backend/drm/legacy/session.rs | 5 +- src/backend/drm/legacy/surface.rs | 13 +- src/backend/drm/mod.rs | 7 +- src/backend/libinput.rs | 22 +- src/backend/session/dbus/logind.rs | 2 +- src/backend/udev.rs | 2 +- src/backend/winit.rs | 50 ++--- src/wayland/dmabuf/mod.rs | 95 ++++---- src/wayland/shell/legacy/mod.rs | 9 +- src/wayland/shell/legacy/wl_handlers.rs | 263 ++++++++++++----------- src/wayland/shell/xdg/mod.rs | 18 +- src/wayland/shell/xdg/xdg_handlers.rs | 163 +++++++------- src/wayland/shell/xdg/zxdgv6_handlers.rs | 193 ++++++++--------- src/wayland/shm/mod.rs | 2 +- 25 files changed, 567 insertions(+), 457 deletions(-) diff --git a/anvil/src/main.rs b/anvil/src/main.rs index fb66ada..6b23038 100644 --- a/anvil/src/main.rs +++ b/anvil/src/main.rs @@ -8,7 +8,10 @@ extern crate slog; extern crate smithay; use slog::Drain; -use smithay::reexports::{calloop::{EventLoop, generic::Generic, mio::Interest}, wayland_server::Display}; +use smithay::reexports::{ + calloop::{generic::Generic, mio::Interest, EventLoop}, + wayland_server::Display, +}; #[macro_use] mod shaders; @@ -57,10 +60,12 @@ fn main() { // Glue for event dispatching let mut wayland_event_source = Generic::from_raw_fd(display.get_poll_fd()); wayland_event_source.set_interest(Interest::READABLE); - let _wayland_source = event_loop.handle().insert_source( - wayland_event_source, - |_, state: &mut AnvilState| { state.need_wayland_dispatch = true; } - ); + let _wayland_source = + event_loop + .handle() + .insert_source(wayland_event_source, |_, state: &mut AnvilState| { + state.need_wayland_dispatch = true; + }); let arg = ::std::env::args().nth(1); match arg.as_ref().map(|s| &s[..]) { diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 874bdbd..15a1b83 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -245,7 +245,11 @@ impl PointerGrab for ResizeSurfaceGrab { self.ctoken .with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| { - let mut data = attrs.user_data.get::>().unwrap().borrow_mut(); + let mut data = attrs + .user_data + .get::>() + .unwrap() + .borrow_mut(); if let ResizeState::Resizing(resize_data) = data.resize_state { data.resize_state = ResizeState::WaitingForFinalAck(resize_data, serial); } else { @@ -255,7 +259,11 @@ impl PointerGrab for ResizeSurfaceGrab { } else { self.ctoken .with_surface_data(self.toplevel.get_surface().unwrap(), |attrs| { - let mut data = attrs.user_data.get::>().unwrap().borrow_mut(); + let mut data = attrs + .user_data + .get::>() + .unwrap() + .borrow_mut(); if let ResizeState::Resizing(resize_data) = data.resize_state { data.resize_state = ResizeState::WaitingForCommit(resize_data); } else { @@ -414,12 +422,16 @@ pub fn init_shell( let initial_window_size = (geometry.width, geometry.height); compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| { - attrs.user_data.get::>().unwrap().borrow_mut().resize_state = - ResizeState::Resizing(ResizeData { - edges: edges.into(), - initial_window_location, - initial_window_size, - }); + attrs + .user_data + .get::>() + .unwrap() + .borrow_mut() + .resize_state = ResizeState::Resizing(ResizeData { + edges: edges.into(), + initial_window_location, + initial_window_size, + }); }); let grab = ResizeSurfaceGrab { @@ -453,7 +465,11 @@ pub fn init_shell( if acked { compositor_token.with_surface_data(&surface, |attrs| { - let mut data = attrs.user_data.get::>().unwrap().borrow_mut(); + let mut data = attrs + .user_data + .get::>() + .unwrap() + .borrow_mut(); if let ResizeState::WaitingForFinalAck(resize_data, _) = data.resize_state { data.resize_state = ResizeState::WaitingForCommit(resize_data); } else { @@ -566,12 +582,16 @@ pub fn init_shell( let initial_window_size = (geometry.width, geometry.height); compositor_token.with_surface_data(surface.get_surface().unwrap(), move |attrs| { - attrs.user_data.get::>().unwrap().borrow_mut().resize_state = - ResizeState::Resizing(ResizeData { - edges: edges.into(), - initial_window_location, - initial_window_size, - }); + attrs + .user_data + .get::>() + .unwrap() + .borrow_mut() + .resize_state = ResizeState::Resizing(ResizeData { + edges: edges.into(), + initial_window_location, + initial_window_size, + }); }); let grab = ResizeSurfaceGrab { @@ -698,8 +718,14 @@ fn surface_commit( }); let refresh = token.with_surface_data(surface, |attributes| { - attributes.user_data.insert_if_missing(|| RefCell::new(SurfaceData::default())); - let mut data = attributes.user_data.get::>().unwrap().borrow_mut(); + attributes + .user_data + .insert_if_missing(|| RefCell::new(SurfaceData::default())); + let mut data = attributes + .user_data + .get::>() + .unwrap() + .borrow_mut(); data.geometry = geometry; data.input_region = attributes.input_region.clone(); @@ -739,7 +765,11 @@ fn surface_commit( let Rectangle { width, height, .. } = window_map.geometry(&toplevel).unwrap(); let new_location = token.with_surface_data(surface, |attributes| { - let mut data = attributes.user_data.get::>().unwrap().borrow_mut(); + let mut data = attributes + .user_data + .get::>() + .unwrap() + .borrow_mut(); let mut new_location = None; diff --git a/anvil/src/udev.rs b/anvil/src/udev.rs index 591e19f..987fd49 100644 --- a/anvil/src/udev.rs +++ b/anvil/src/udev.rs @@ -36,7 +36,7 @@ use smithay::{ }, reexports::{ calloop::{ - generic::{SourceFd, Generic}, + generic::{Generic, SourceFd}, EventLoop, LoopHandle, Source, }, drm::control::{ @@ -264,7 +264,9 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop, log running.store(false, Ordering::SeqCst); } else { if state.need_wayland_dispatch { - display.borrow_mut().dispatch(std::time::Duration::from_millis(0), &mut state); + display + .borrow_mut() + .dispatch(std::time::Duration::from_millis(0), &mut state); } display.borrow_mut().flush_clients(&mut state); window_map.borrow_mut().refresh(); diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index 6fb104e..bc0bd74 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -160,7 +160,12 @@ where // It's the set geometry with the full bounding box as the fallback. ctoken .with_surface_data(self.toplevel.get_surface().unwrap(), |attributes| { - attributes.user_data.get::>().unwrap().borrow().geometry + attributes + .user_data + .get::>() + .unwrap() + .borrow() + .geometry }) .unwrap_or(self.bbox) } diff --git a/anvil/src/winit.rs b/anvil/src/winit.rs index 86b71fc..9841f4f 100644 --- a/anvil/src/winit.rs +++ b/anvil/src/winit.rs @@ -29,7 +29,11 @@ use crate::input_handler::AnvilInputHandler; use crate::shell::init_shell; use crate::AnvilState; -pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop, log: Logger) -> Result<(), ()> { +pub fn run_winit( + display: &mut Display, + event_loop: &mut EventLoop, + log: Logger, +) -> Result<(), ()> { let (renderer, mut input) = winit::init(log.clone()).map_err(|_| ())?; #[cfg(feature = "egl")] diff --git a/examples/raw_drm.rs b/examples/raw_drm.rs index ea3f279..08ecdef 100644 --- a/examples/raw_drm.rs +++ b/examples/raw_drm.rs @@ -55,7 +55,12 @@ fn main() { .unwrap(); // Use the first encoder - let encoder = connector_info.encoders().iter().filter_map(|&e| e).next().unwrap(); + let encoder = connector_info + .encoders() + .iter() + .filter_map(|&e| e) + .next() + .unwrap(); let encoder_info = device.get_encoder_info(encoder).unwrap(); // use the connected crtc if any @@ -90,9 +95,13 @@ fn main() { * But they are very slow, this is just for demonstration purposes. */ let (w, h) = mode.size(); - let front_buffer = device.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888).unwrap(); + let front_buffer = device + .create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888) + .unwrap(); let front_framebuffer = device.add_framebuffer(&front_buffer).unwrap(); - let back_buffer = device.create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888).unwrap(); + let back_buffer = device + .create_dumb_buffer((w as u32, h as u32), PixelFormat::XRGB8888) + .unwrap(); let back_framebuffer = device.add_framebuffer(&back_buffer).unwrap(); device.set_handler(DrmHandlerImpl { diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index 3884da3..0c6b77c 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -8,7 +8,7 @@ //! Take a look at `anvil`s source code for an example of this. //! -use drm::control::{crtc, connector, encoder, framebuffer, plane, ResourceHandles}; +use drm::control::{connector, crtc, encoder, framebuffer, plane, ResourceHandles}; use drm::SystemError as DrmError; use nix::libc::dev_t; use std::os::unix::io::{AsRawFd, RawFd}; @@ -183,7 +183,10 @@ where fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result { self.dev.borrow().get_encoder_info(enc) } - fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result { + fn get_framebuffer_info( + &self, + fb: framebuffer::Handle, + ) -> std::result::Result { self.dev.borrow().get_framebuffer_info(fb) } fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result { diff --git a/src/backend/drm/gbm/mod.rs b/src/backend/drm/gbm/mod.rs index 84c6385..91f9eaa 100644 --- a/src/backend/drm/gbm/mod.rs +++ b/src/backend/drm/gbm/mod.rs @@ -11,7 +11,7 @@ use super::{Device, DeviceHandler, RawDevice, ResourceHandles, Surface}; -use drm::control::{crtc, connector, encoder, framebuffer, plane, Device as ControlDevice}; +use drm::control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice}; use drm::SystemError as DrmError; use failure::ResultExt as FailureResultExt; use gbm::{self, BufferObjectFlags, Format as GbmFormat}; @@ -194,7 +194,7 @@ impl Device for GbmDevice { .compat() .chain_err(|| ErrorKind::UnderlyingBackendError) } - + fn get_connector_info(&self, conn: connector::Handle) -> std::result::Result { self.dev.borrow().get_connector_info(conn) } @@ -204,7 +204,10 @@ impl Device for GbmDevice { fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result { self.dev.borrow().get_encoder_info(enc) } - fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result { + fn get_framebuffer_info( + &self, + fb: framebuffer::Handle, + ) -> std::result::Result { self.dev.borrow().get_framebuffer_info(fb) } fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result { diff --git a/src/backend/drm/gbm/session.rs b/src/backend/drm/gbm/session.rs index 6dc8ab6..5da767c 100644 --- a/src/backend/drm/gbm/session.rs +++ b/src/backend/drm/gbm/session.rs @@ -26,8 +26,10 @@ pub struct GbmDeviceObserver< logger: ::slog::Logger, } -impl + 'static> - AsSessionObserver> for GbmDevice +impl< + S: SessionObserver + 'static, + D: RawDevice + ::drm::control::Device + AsSessionObserver + 'static, + > AsSessionObserver> for GbmDevice { fn observer(&mut self) -> GbmDeviceObserver { GbmDeviceObserver { @@ -38,8 +40,10 @@ impl + 'static> - SessionObserver for GbmDeviceObserver +impl< + S: SessionObserver + 'static, + D: RawDevice + ::drm::control::Device + AsSessionObserver + 'static, + > SessionObserver for GbmDeviceObserver { fn pause(&mut self, devnum: Option<(u32, u32)>) { self.observer.pause(devnum); @@ -65,12 +69,11 @@ impl, (u32, u32)) = unsafe { &*backend.cursor.as_ptr() }; - if backend.dev.borrow().set_cursor2( - *crtc, - Some(cursor), - ((*hotspot).0 as i32, (*hotspot).1 as i32), - ) - .is_err() + if backend + .dev + .borrow() + .set_cursor2(*crtc, Some(cursor), ((*hotspot).0 as i32, (*hotspot).1 as i32)) + .is_err() { if let Err(err) = backend.dev.borrow().set_cursor(*crtc, Some(cursor)) { error!(self.logger, "Failed to reset cursor. Error: {}", err); diff --git a/src/backend/drm/gbm/surface.rs b/src/backend/drm/gbm/surface.rs index 05b22f2..db19d8a 100644 --- a/src/backend/drm/gbm/surface.rs +++ b/src/backend/drm/gbm/surface.rs @@ -1,7 +1,7 @@ use super::super::{Device, RawDevice, RawSurface, Surface}; use super::error::*; -use drm::control::{connector, crtc, framebuffer, Mode, Device as ControlDevice}; +use drm::control::{connector, crtc, framebuffer, Device as ControlDevice, Mode}; use gbm::{self, BufferObject, BufferObjectFlags, Format as GbmFormat, SurfaceBufferHandle}; use image::{ImageBuffer, Rgba}; @@ -67,7 +67,9 @@ impl GbmSurfaceInternal { let fb = if let Some(info) = maybe_fb { info } else { - let fb = self.crtc.add_planar_framebuffer(&*next_bo, &[0; 4], 0) + let fb = self + .crtc + .add_planar_framebuffer(&*next_bo, &[0; 4], 0) .map_err(|_| SwapBuffersError::ContextLost)?; next_bo.set_userdata(fb).unwrap(); fb @@ -76,9 +78,7 @@ impl GbmSurfaceInternal { if self.recreated.get() { debug!(self.logger, "Commiting new state"); - self.crtc - .commit(fb) - .map_err(|_| SwapBuffersError::ContextLost)?; + self.crtc.commit(fb).map_err(|_| SwapBuffersError::ContextLost)?; self.recreated.set(false); } diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index 5f81b67..63e088a 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -10,7 +10,9 @@ use super::{DevPath, Device, DeviceHandler, RawDevice}; -use drm::control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, ResourceHandles}; +use drm::control::{ + connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Event, ResourceHandles, +}; use drm::{Device as BasicDevice, SystemError as DrmError}; use failure::ResultExt as FailureResultExt; use nix::libc::dev_t; @@ -187,7 +189,9 @@ impl Device for LegacyDrmDevice { // Try to enumarate the current state to set the initial state variable correctly - let crtc_info = self.get_crtc(crtc).compat() + let crtc_info = self + .get_crtc(crtc) + .compat() .chain_err(|| ErrorKind::DrmDev(format!("Error loading crtc info on {:?}", self.dev_path())))?; let mode = crtc_info.mode(); @@ -265,7 +269,8 @@ impl Device for LegacyDrmDevice { } fn resource_handles(&self) -> Result { - ControlDevice::resource_handles(self).compat() + ControlDevice::resource_handles(self) + .compat() .chain_err(|| ErrorKind::DrmDev(format!("Error loading resource info on {:?}", self.dev_path()))) } @@ -278,7 +283,10 @@ impl Device for LegacyDrmDevice { fn get_encoder_info(&self, enc: encoder::Handle) -> std::result::Result { self.get_encoder(enc) } - fn get_framebuffer_info(&self, fb: framebuffer::Handle) -> std::result::Result { + fn get_framebuffer_info( + &self, + fb: framebuffer::Handle, + ) -> std::result::Result { self.get_framebuffer(fb) } fn get_plane_info(&self, plane: plane::Handle) -> std::result::Result { diff --git a/src/backend/drm/legacy/session.rs b/src/backend/drm/legacy/session.rs index f483673..1f2c2d6 100644 --- a/src/backend/drm/legacy/session.rs +++ b/src/backend/drm/legacy/session.rs @@ -54,7 +54,10 @@ impl SessionObserver for LegacyDrmDeviceObserver { for surface in backends.borrow().values().filter_map(Weak::upgrade) { // other ttys that use no cursor, might not clear it themselves. // This makes sure our cursor won't stay visible. - let _ = (*device).set_cursor(surface.crtc, Option::<&drm::control::dumbbuffer::DumbBuffer>::None); + let _ = (*device).set_cursor( + surface.crtc, + Option::<&drm::control::dumbbuffer::DumbBuffer>::None, + ); } } } diff --git a/src/backend/drm/legacy/surface.rs b/src/backend/drm/legacy/surface.rs index c757fac..af0e93d 100644 --- a/src/backend/drm/legacy/surface.rs +++ b/src/backend/drm/legacy/surface.rs @@ -1,5 +1,8 @@ use drm::buffer::Buffer; -use drm::control::{connector, crtc, dumbbuffer::DumbBuffer, encoder, framebuffer, Device as ControlDevice, Mode, PageFlipFlags}; +use drm::control::{ + connector, crtc, dumbbuffer::DumbBuffer, encoder, framebuffer, Device as ControlDevice, Mode, + PageFlipFlags, +}; use drm::Device as BasicDevice; use failure::ResultExt as FailureResultExt; @@ -54,7 +57,10 @@ impl<'a, A: AsRawFd + 'static> CursorBackend<'a> for LegacyDrmSurfaceInternal { trace!(self.logger, "Setting the new imported cursor"); - if self.set_cursor2(self.crtc, Some(buffer), (hotspot.0 as i32, hotspot.1 as i32)).is_err() { + if self + .set_cursor2(self.crtc, Some(buffer), (hotspot.0 as i32, hotspot.1 as i32)) + .is_err() + { self.set_cursor(self.crtc, Some(buffer)) .compat() .chain_err(|| ErrorKind::DrmDev(format!("Failed to set cursor on {:?}", self.dev_path())))?; @@ -140,7 +146,8 @@ impl Surface for LegacyDrmSurfaceInternal { // check the connectors to see if this mode is supported if let Some(mode) = mode { for connector in &pending.connectors { - if !self.get_connector(*connector) + if !self + .get_connector(*connector) .compat() .chain_err(|| { ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) diff --git a/src/backend/drm/mod.rs b/src/backend/drm/mod.rs index bf7ee7b..b001253 100644 --- a/src/backend/drm/mod.rs +++ b/src/backend/drm/mod.rs @@ -36,9 +36,8 @@ //! use drm::{ - control::{connector, crtc, encoder, plane, framebuffer, Device as ControlDevice, Mode, ResourceHandles}, - Device as BasicDevice, - SystemError as DrmError, + control::{connector, crtc, encoder, framebuffer, plane, Device as ControlDevice, Mode, ResourceHandles}, + Device as BasicDevice, SystemError as DrmError, }; use nix::libc::dev_t; @@ -47,7 +46,7 @@ use std::iter::IntoIterator; use std::os::unix::io::AsRawFd; use std::path::PathBuf; -use calloop::generic::{SourceFd, Generic}; +use calloop::generic::{Generic, SourceFd}; use calloop::mio::Interest; use calloop::InsertError; use calloop::{LoopHandle, Source}; diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 5f198c3..b3c9b47 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -16,7 +16,7 @@ use std::{ }; use calloop::{ - generic::{SourceFd, Generic}, + generic::{Generic, SourceFd}, mio::Interest, InsertError, LoopHandle, Source, }; @@ -315,7 +315,12 @@ impl InputBackend for LibinputInputBackend { }; let device_seat = added.seat(); - info!(self.logger, "New device {:?} on seat {:?}", added.sysname(), device_seat.logical_name()); + info!( + self.logger, + "New device {:?} on seat {:?}", + added.sysname(), + device_seat.logical_name() + ); self.devices.push(added); match self.seats.entry(device_seat.clone()) { @@ -358,7 +363,12 @@ impl InputBackend for LibinputInputBackend { self.devices.retain(|dev| *dev != removed); let device_seat = removed.seat(); - info!(self.logger, "Removed device {:?} on seat {:?}", removed.sysname(), device_seat.logical_name()); + info!( + self.logger, + "Removed device {:?} on seat {:?}", + removed.sysname(), + device_seat.logical_name() + ); // update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`. if let Some(seat) = self.seats.get_mut(&device_seat) { @@ -387,7 +397,11 @@ impl InputBackend for LibinputInputBackend { if !self.devices.iter().any(|x| x.seat() == device_seat) { // it has not, lets destroy it if let Some(seat) = self.seats.remove(&device_seat) { - info!(self.logger, "Removing seat {} which no longer has any device", device_seat.logical_name()); + info!( + self.logger, + "Removing seat {} which no longer has any device", + device_seat.logical_name() + ); if let Some(ref mut handler) = self.handler { trace!(self.logger, "Calling on_seat_destroyed with {:?}", seat); handler.on_seat_destroyed(&seat); diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index 1348ab6..56e86e7 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -53,7 +53,7 @@ use std::{ use systemd::login; use calloop::{ - generic::{Event, SourceRawFd, Generic}, + generic::{Event, Generic, SourceRawFd}, mio::Interest, InsertError, LoopHandle, Source, }; diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 5478499..7319729 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -19,7 +19,7 @@ use std::{ use udev::{Context, Enumerator, EventType, MonitorBuilder, MonitorSocket, Result as UdevResult}; use calloop::{ - generic::{SourceFd, Generic}, + generic::{Generic, SourceFd}, mio::Interest, InsertError, LoopHandle, Source, }; diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 2e61200..9a9751d 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -25,8 +25,8 @@ use wayland_server::Display; use winit::{ dpi::{LogicalPosition, LogicalSize, PhysicalSize}, event::{ - ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton, - MouseScrollDelta, Touch, TouchPhase, WindowEvent + ElementState, Event, KeyboardInput, MouseButton as WinitMouseButton, MouseScrollDelta, Touch, + TouchPhase, WindowEvent, }, event_loop::{ControlFlow, EventLoop}, platform::desktop::EventLoopExtDesktop, @@ -390,7 +390,8 @@ impl BackendEvent for WinitMouseMovedEvent { } } -impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { // TODO: maybe use {Logical, Physical}Position from winit? +impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { + // TODO: maybe use {Logical, Physical}Position from winit? fn x(&self) -> f64 { let wsize = self.size.borrow(); self.logical_position.x * wsize.scale_factor @@ -509,19 +510,13 @@ impl TouchDownEvent for WinitTouchStartedEvent { fn x_transformed(&self, width: u32) -> u32 { let wsize = self.size.borrow(); let w_width = wsize.physical_size.to_logical::(wsize.scale_factor).width; - cmp::min( - self.location.0 as i32 * width as i32 / w_width, - 0, - ) as u32 + cmp::min(self.location.0 as i32 * width as i32 / w_width, 0) as u32 } fn y_transformed(&self, height: u32) -> u32 { let wsize = self.size.borrow(); let w_height = wsize.physical_size.to_logical::(wsize.scale_factor).height; - cmp::min( - self.location.1 as i32 * height as i32 / w_height, - 0, - ) as u32 + cmp::min(self.location.1 as i32 * height as i32 / w_height, 0) as u32 } } @@ -700,17 +695,17 @@ impl InputBackend for WinitInputBackend { let mut events_handler = self.events_handler.as_mut(); let logger = &self.logger; let window_size = &self.size; - - self.events_loop.run_return(move |event, _target, control_flow| { - match event { + + self.events_loop + .run_return(move |event, _target, control_flow| match event { Event::RedrawEventsCleared => { *control_flow = ControlFlow::Exit; - }, + } Event::RedrawRequested(_id) => { if let Some(events_handler) = events_handler.as_mut() { events_handler.refresh(); } - }, + } Event::WindowEvent { event, .. } => { let duration = Instant::now().duration_since(*time); let nanos = duration.subsec_nanos() as u64; @@ -732,14 +727,22 @@ impl InputBackend for WinitInputBackend { (WindowEvent::Focused(focus), _, Some(events_handler)) => { events_handler.focus_changed(focus) } - (WindowEvent::ScaleFactorChanged { scale_factor, new_inner_size: new_psize }, _, events_handler) => { + ( + WindowEvent::ScaleFactorChanged { + scale_factor, + new_inner_size: new_psize, + }, + _, + events_handler, + ) => { let mut wsize = window_size.borrow_mut(); wsize.scale_factor = scale_factor; if let Window::Wayland { ref surface, .. } = **window { surface.resize(new_psize.width as i32, new_psize.height as i32, 0, 0); } if let Some(events_handler) = events_handler { - let psize_f64: (f64, f64) = (new_psize.width.into(), new_psize.height.into()); + let psize_f64: (f64, f64) = + (new_psize.width.into(), new_psize.height.into()); events_handler.resized(psize_f64, wsize.scale_factor); } } @@ -869,13 +872,12 @@ impl InputBackend for WinitInputBackend { (WindowEvent::CloseRequested, _, _) | (WindowEvent::Destroyed, _, _) => { warn!(logger, "Window closed"); *closed_ptr = true; - }, - _ => {}, + } + _ => {} } - }, - _ => {}, - } - }); + } + _ => {} + }); } if closed { diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index 6443104..5f0c729 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -73,7 +73,7 @@ use wayland_protocols::unstable::linux_dmabuf::v1::server::{ }, zwp_linux_dmabuf_v1, }; -use wayland_server::{protocol::wl_buffer, Display, Global, Main, Filter}; +use wayland_server::{protocol::wl_buffer, Display, Filter, Global, Main}; /// Representation of a Dmabuf format, as advertized to the client pub struct Format { @@ -194,45 +194,62 @@ where formats.len() ); - display.create_global(3, Filter::new(move |(dmabuf, version): (Main, u32), _, _| { - let dma_formats = formats.clone(); - let dma_handler = handler.clone(); - let dma_log = log.clone(); - dmabuf.quick_assign( - move |_, req, _| { - if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req { - let mut handler = ParamsHandler { - pending_planes: Vec::new(), - max_planes, - used: false, - formats: dma_formats.clone(), - handler: dma_handler.clone(), - log: dma_log.clone(), - }; - params_id.quick_assign(move |params, req, _| match req { - ParamsRequest::Add { fd, plane_idx, offset, stride, modifier_hi, modifier_lo } => { - handler.add(&*params, fd, plane_idx, offset, stride, modifier_hi, modifier_lo) - }, - ParamsRequest::Create { width, height, format, flags } => { - handler.create(&*params, width, height, format, flags) - }, - ParamsRequest::CreateImmed { buffer_id, width, height, format, flags } => { - handler.create_immed(&*params, buffer_id, width, height, format, flags) - } - _ => {} - }); - } - } - ); + display.create_global( + 3, + Filter::new( + move |(dmabuf, version): (Main, u32), _, _| { + let dma_formats = formats.clone(); + let dma_handler = handler.clone(); + let dma_log = log.clone(); + dmabuf.quick_assign(move |_, req, _| { + if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req { + let mut handler = ParamsHandler { + pending_planes: Vec::new(), + max_planes, + used: false, + formats: dma_formats.clone(), + handler: dma_handler.clone(), + log: dma_log.clone(), + }; + params_id.quick_assign(move |params, req, _| match req { + ParamsRequest::Add { + fd, + plane_idx, + offset, + stride, + modifier_hi, + modifier_lo, + } => { + handler.add(&*params, fd, plane_idx, offset, stride, modifier_hi, modifier_lo) + } + ParamsRequest::Create { + width, + height, + format, + flags, + } => handler.create(&*params, width, height, format, flags), + ParamsRequest::CreateImmed { + buffer_id, + width, + height, + format, + flags, + } => handler.create_immed(&*params, buffer_id, width, height, format, flags), + _ => {} + }); + } + }); - // send the supported formats - for f in &*formats { - dmabuf.format(f.format.as_raw()); - if version >= 3 { - dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32); - } - } - })) + // send the supported formats + for f in &*formats { + dmabuf.format(f.format.as_raw()); + if version >= 3 { + dmabuf.modifier(f.format.as_raw(), (f.modifier >> 32) as u32, f.modifier as u32); + } + } + }, + ), + ) } struct ParamsHandler { diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index 30eebf7..010e93c 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -314,9 +314,12 @@ where })); let state2 = state.clone(); - let global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { - self::wl_handlers::implement_shell(shell, ctoken, implementation.clone(), state2.clone()); - })); + let global = display.create_global( + 1, + Filter::new(move |(shell, _version), _, _data| { + self::wl_handlers::implement_shell(shell, ctoken, implementation.clone(), state2.clone()); + }), + ); (state, global) } diff --git a/src/wayland/shell/legacy/wl_handlers.rs b/src/wayland/shell/legacy/wl_handlers.rs index 92c93a6..29d4ac5 100644 --- a/src/wayland/shell/legacy/wl_handlers.rs +++ b/src/wayland/shell/legacy/wl_handlers.rs @@ -23,36 +23,34 @@ pub(crate) fn implement_shell( R: Role + 'static, Impl: FnMut(ShellRequest) + 'static, { - shell.quick_assign( - move |shell, req, _data| { - let (id, surface) = match req { - wl_shell::Request::GetShellSurface { id, surface } => (id, surface), - _ => unreachable!(), - }; - let role_data = ShellSurfaceRole { - title: "".into(), - class: "".into(), - pending_ping: 0, - }; - if ctoken.give_role_with(&surface, role_data).is_err() { - shell - .as_ref() - .post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into()); - return; - } - let shell_surface = - implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone()); - state - .lock() - .unwrap() - .known_surfaces - .push(make_handle(&shell_surface, ctoken)); - let mut imp = implementation.borrow_mut(); - (&mut *imp)(ShellRequest::NewShellSurface { - surface: make_handle(&shell_surface, ctoken), - }); - }, - ); + shell.quick_assign(move |shell, req, _data| { + let (id, surface) = match req { + wl_shell::Request::GetShellSurface { id, surface } => (id, surface), + _ => unreachable!(), + }; + let role_data = ShellSurfaceRole { + title: "".into(), + class: "".into(), + pending_ping: 0, + }; + if ctoken.give_role_with(&surface, role_data).is_err() { + shell + .as_ref() + .post_error(wl_shell::Error::Role as u32, "Surface already has a role.".into()); + return; + } + let shell_surface = + implement_shell_surface(id, surface, implementation.clone(), ctoken, state.clone()); + state + .lock() + .unwrap() + .known_surfaces + .push(make_handle(&shell_surface, ctoken)); + let mut imp = implementation.borrow_mut(); + (&mut *imp)(ShellRequest::NewShellSurface { + surface: make_handle(&shell_surface, ctoken), + }); + }); } fn make_handle( @@ -91,113 +89,116 @@ where Impl: FnMut(ShellRequest) + 'static, { use self::wl_shell_surface::Request; - shell_surface.quick_assign( - move |shell_surface, req, _data| { - let data = shell_surface - .as_ref() - .user_data() - .get::>() - .unwrap(); - let mut user_impl = implementation.borrow_mut(); - match req { - Request::Pong { serial } => { - let valid = ctoken - .with_role_data(&data.surface, |data| { - if data.pending_ping == serial { - data.pending_ping = 0; - true - } else { - false - } - }) - .expect("wl_shell_surface exists but surface has not the right role?"); - if valid { - (&mut *user_impl)(ShellRequest::Pong { - surface: make_handle(&shell_surface, ctoken), - }); - } - } - Request::Move { seat, serial } => (&mut *user_impl)(ShellRequest::Move { - surface: make_handle(&shell_surface, ctoken), - serial, - seat, - }), - Request::Resize { seat, serial, edges } => (&mut *user_impl)(ShellRequest::Resize { - surface: make_handle(&shell_surface, ctoken), - serial, - seat, - edges, - }), - Request::SetToplevel => (&mut *user_impl)(ShellRequest::SetKind { - surface: make_handle(&shell_surface, ctoken), - kind: ShellSurfaceKind::Toplevel, - }), - Request::SetTransient { parent, x, y, flags } => (&mut *user_impl)(ShellRequest::SetKind { - surface: make_handle(&shell_surface, ctoken), - kind: ShellSurfaceKind::Transient { - parent, - location: (x, y), - inactive: flags.contains(wl_shell_surface::Transient::Inactive), - }, - }), - Request::SetFullscreen { - method, - framerate, - output, - } => (&mut *user_impl)(ShellRequest::SetKind { - surface: make_handle(&shell_surface, ctoken), - kind: ShellSurfaceKind::Fullscreen { - method, - framerate, - output, - }, - }), - Request::SetPopup { - seat, - serial, - parent, - x, - y, - flags, - } => (&mut *user_impl)(ShellRequest::SetKind { - surface: make_handle(&shell_surface, ctoken), - kind: ShellSurfaceKind::Popup { - parent, - serial, - seat, - location: (x, y), - inactive: flags.contains(wl_shell_surface::Transient::Inactive), - }, - }), - Request::SetMaximized { output } => (&mut *user_impl)(ShellRequest::SetKind { - surface: make_handle(&shell_surface, ctoken), - kind: ShellSurfaceKind::Maximized { output }, - }), - Request::SetTitle { title } => { - ctoken - .with_role_data(&data.surface, |data| data.title = title) - .expect("wl_shell_surface exists but surface has not shell_surface role?!"); - } - Request::SetClass { class_ } => { - ctoken - .with_role_data(&data.surface, |data| data.class = class_) - .expect("wl_shell_surface exists but surface has not shell_surface role?!"); - } - _ => unreachable!(), - } - }, - ); - - shell_surface.assign_destructor(Filter::new(|shell_surface: wl_shell_surface::WlShellSurface, _, _data| { + shell_surface.quick_assign(move |shell_surface, req, _data| { let data = shell_surface .as_ref() .user_data() .get::>() .unwrap(); - data.state.lock().unwrap().cleanup_surfaces(); - })); + let mut user_impl = implementation.borrow_mut(); + match req { + Request::Pong { serial } => { + let valid = ctoken + .with_role_data(&data.surface, |data| { + if data.pending_ping == serial { + data.pending_ping = 0; + true + } else { + false + } + }) + .expect("wl_shell_surface exists but surface has not the right role?"); + if valid { + (&mut *user_impl)(ShellRequest::Pong { + surface: make_handle(&shell_surface, ctoken), + }); + } + } + Request::Move { seat, serial } => (&mut *user_impl)(ShellRequest::Move { + surface: make_handle(&shell_surface, ctoken), + serial, + seat, + }), + Request::Resize { seat, serial, edges } => (&mut *user_impl)(ShellRequest::Resize { + surface: make_handle(&shell_surface, ctoken), + serial, + seat, + edges, + }), + Request::SetToplevel => (&mut *user_impl)(ShellRequest::SetKind { + surface: make_handle(&shell_surface, ctoken), + kind: ShellSurfaceKind::Toplevel, + }), + Request::SetTransient { parent, x, y, flags } => (&mut *user_impl)(ShellRequest::SetKind { + surface: make_handle(&shell_surface, ctoken), + kind: ShellSurfaceKind::Transient { + parent, + location: (x, y), + inactive: flags.contains(wl_shell_surface::Transient::Inactive), + }, + }), + Request::SetFullscreen { + method, + framerate, + output, + } => (&mut *user_impl)(ShellRequest::SetKind { + surface: make_handle(&shell_surface, ctoken), + kind: ShellSurfaceKind::Fullscreen { + method, + framerate, + output, + }, + }), + Request::SetPopup { + seat, + serial, + parent, + x, + y, + flags, + } => (&mut *user_impl)(ShellRequest::SetKind { + surface: make_handle(&shell_surface, ctoken), + kind: ShellSurfaceKind::Popup { + parent, + serial, + seat, + location: (x, y), + inactive: flags.contains(wl_shell_surface::Transient::Inactive), + }, + }), + Request::SetMaximized { output } => (&mut *user_impl)(ShellRequest::SetKind { + surface: make_handle(&shell_surface, ctoken), + kind: ShellSurfaceKind::Maximized { output }, + }), + Request::SetTitle { title } => { + ctoken + .with_role_data(&data.surface, |data| data.title = title) + .expect("wl_shell_surface exists but surface has not shell_surface role?!"); + } + Request::SetClass { class_ } => { + ctoken + .with_role_data(&data.surface, |data| data.class = class_) + .expect("wl_shell_surface exists but surface has not shell_surface role?!"); + } + _ => unreachable!(), + } + }); - shell_surface.as_ref().user_data().set_threadsafe(|| ShellSurfaceUserData { surface, state }); + shell_surface.assign_destructor(Filter::new( + |shell_surface: wl_shell_surface::WlShellSurface, _, _data| { + let data = shell_surface + .as_ref() + .user_data() + .get::>() + .unwrap(); + data.state.lock().unwrap().cleanup_surfaces(); + }, + )); + + shell_surface + .as_ref() + .user_data() + .set_threadsafe(|| ShellSurfaceUserData { surface, state }); shell_surface.deref().clone() } diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 99602b7..4b70cf8 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -304,13 +304,19 @@ where let shell_data_z = shell_data.clone(); - let xdg_shell_global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { - self::xdg_handlers::implement_wm_base(shell, &shell_data); - })); + let xdg_shell_global = display.create_global( + 1, + Filter::new(move |(shell, _version), _, _data| { + self::xdg_handlers::implement_wm_base(shell, &shell_data); + }), + ); - let zxdgv6_shell_global = display.create_global(1, Filter::new(move |(shell, _version), _, _data| { - self::zxdgv6_handlers::implement_shell(shell, &shell_data_z); - })); + let zxdgv6_shell_global = display.create_global( + 1, + Filter::new(move |(shell, _version), _, _data| { + self::zxdgv6_handlers::implement_shell(shell, &shell_data_z); + }), + ); (shell_state, xdg_shell_global, zxdgv6_shell_global) } diff --git a/src/wayland/shell/xdg/xdg_handlers.rs b/src/wayland/shell/xdg/xdg_handlers.rs index 87e85a5..dc292a9 100644 --- a/src/wayland/shell/xdg/xdg_handlers.rs +++ b/src/wayland/shell/xdg/xdg_handlers.rs @@ -22,12 +22,10 @@ where R: Role + 'static, { shell.quick_assign(|shell, req, _data| wm_implementation::(req, shell.deref().clone())); - shell.as_ref().user_data().set(|| - ShellUserData { - shell_data: shell_data.clone(), - client_data: Mutex::new(make_shell_client_data()), - }, - ); + shell.as_ref().user_data().set(|| ShellUserData { + shell_data: shell_data.clone(), + client_data: Mutex::new(make_shell_client_data()), + }); let mut user_impl = shell_data.user_impl.borrow_mut(); (&mut *user_impl)(XdgRequest::NewClient { client: make_shell_client(&shell, shell_data.compositor_token), @@ -89,13 +87,11 @@ where xdg_surface_implementation::(req, surface.deref().clone()) }); id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::(surface))); - id.as_ref().user_data().set(|| - XdgSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: surface, - wm_base: shell.clone(), - }, - ); + id.as_ref().user_data().set(|| XdgSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: surface, + wm_base: shell.clone(), + }); } xdg_wm_base::Request::Pong { serial } => { let valid = { @@ -123,61 +119,60 @@ where */ fn implement_positioner(positioner: Main) -> xdg_positioner::XdgPositioner { - positioner.quick_assign( - |positioner, request, _data| { - let mutex = positioner - .as_ref() - .user_data() - .get::>() - .unwrap(); - let mut state = mutex.borrow_mut(); - match request { - xdg_positioner::Request::Destroy => { - // handled by destructor - } - xdg_positioner::Request::SetSize { width, height } => { - if width < 1 || height < 1 { - positioner.as_ref().post_error( - xdg_positioner::Error::InvalidInput as u32, - "Invalid size for positioner.".into(), - ); - } else { - state.rect_size = (width, height); - } - } - xdg_positioner::Request::SetAnchorRect { x, y, width, height } => { - if width < 1 || height < 1 { - positioner.as_ref().post_error( - xdg_positioner::Error::InvalidInput as u32, - "Invalid size for positioner's anchor rectangle.".into(), - ); - } else { - state.anchor_rect = Rectangle { x, y, width, height }; - } - } - xdg_positioner::Request::SetAnchor { anchor } => { - state.anchor_edges = anchor; - } - xdg_positioner::Request::SetGravity { gravity } => { - state.gravity = gravity; - } - xdg_positioner::Request::SetConstraintAdjustment { - constraint_adjustment, - } => { - let constraint_adjustment = - xdg_positioner::ConstraintAdjustment::from_bits_truncate(constraint_adjustment); - state.constraint_adjustment = constraint_adjustment; - } - xdg_positioner::Request::SetOffset { x, y } => { - state.offset = (x, y); - } - _ => unreachable!(), + positioner.quick_assign(|positioner, request, _data| { + let mutex = positioner + .as_ref() + .user_data() + .get::>() + .unwrap(); + let mut state = mutex.borrow_mut(); + match request { + xdg_positioner::Request::Destroy => { + // handled by destructor } - }, - ); - positioner.as_ref().user_data().set(|| - RefCell::new(PositionerState::new()), - ); + xdg_positioner::Request::SetSize { width, height } => { + if width < 1 || height < 1 { + positioner.as_ref().post_error( + xdg_positioner::Error::InvalidInput as u32, + "Invalid size for positioner.".into(), + ); + } else { + state.rect_size = (width, height); + } + } + xdg_positioner::Request::SetAnchorRect { x, y, width, height } => { + if width < 1 || height < 1 { + positioner.as_ref().post_error( + xdg_positioner::Error::InvalidInput as u32, + "Invalid size for positioner's anchor rectangle.".into(), + ); + } else { + state.anchor_rect = Rectangle { x, y, width, height }; + } + } + xdg_positioner::Request::SetAnchor { anchor } => { + state.anchor_edges = anchor; + } + xdg_positioner::Request::SetGravity { gravity } => { + state.gravity = gravity; + } + xdg_positioner::Request::SetConstraintAdjustment { + constraint_adjustment, + } => { + let constraint_adjustment = + xdg_positioner::ConstraintAdjustment::from_bits_truncate(constraint_adjustment); + state.constraint_adjustment = constraint_adjustment; + } + xdg_positioner::Request::SetOffset { x, y } => { + state.offset = (x, y); + } + _ => unreachable!(), + } + }); + positioner + .as_ref() + .user_data() + .set(|| RefCell::new(PositionerState::new())); positioner.deref().clone() } @@ -248,18 +243,16 @@ where }); }) .expect("xdg_surface exists but surface has not shell_surface role?!"); - id.quick_assign( - |toplevel, req, _data| toplevel_implementation::(req, toplevel.deref().clone()), - ); + id.quick_assign(|toplevel, req, _data| { + toplevel_implementation::(req, toplevel.deref().clone()) + }); id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::(toplevel))); - id.as_ref().user_data().set(|| - ShellSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: data.wl_surface.clone(), - xdg_surface: xdg_surface.clone(), - wm_base: data.wm_base.clone(), - }, - ); + id.as_ref().user_data().set(|| ShellSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: data.wl_surface.clone(), + xdg_surface: xdg_surface.clone(), + wm_base: data.wm_base.clone(), + }); data.shell_data .shell_state @@ -302,14 +295,12 @@ where .expect("xdg_surface exists but surface has not shell_surface role?!"); id.quick_assign(|popup, req, _data| xg_popup_implementation::(req, popup.deref().clone())); id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::(popup))); - id.as_ref().user_data().set(|| - ShellSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: data.wl_surface.clone(), - xdg_surface: xdg_surface.clone(), - wm_base: data.wm_base.clone(), - }, - ); + id.as_ref().user_data().set(|| ShellSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: data.wl_surface.clone(), + xdg_surface: xdg_surface.clone(), + wm_base: data.wm_base.clone(), + }); data.shell_data .shell_state diff --git a/src/wayland/shell/xdg/zxdgv6_handlers.rs b/src/wayland/shell/xdg/zxdgv6_handlers.rs index 15c2a94..05cfe34 100644 --- a/src/wayland/shell/xdg/zxdgv6_handlers.rs +++ b/src/wayland/shell/xdg/zxdgv6_handlers.rs @@ -25,12 +25,10 @@ where R: Role + 'static, { shell.quick_assign(|shell, req, _data| shell_implementation::(req, shell.deref().clone())); - shell.as_ref().user_data().set(|| - ShellUserData { - shell_data: shell_data.clone(), - client_data: Mutex::new(make_shell_client_data()), - }, - ); + shell.as_ref().user_data().set(|| ShellUserData { + shell_data: shell_data.clone(), + client_data: Mutex::new(make_shell_client_data()), + }); let mut user_impl = shell_data.user_impl.borrow_mut(); (&mut *user_impl)(XdgRequest::NewClient { client: make_shell_client(&shell, shell_data.compositor_token), @@ -88,15 +86,15 @@ where ); return; } - id.quick_assign(|surface, req, _data| xdg_surface_implementation::(req, surface.deref().clone())); + id.quick_assign(|surface, req, _data| { + xdg_surface_implementation::(req, surface.deref().clone()) + }); id.assign_destructor(Filter::new(|surface, _, _data| destroy_surface::(surface))); - id.as_ref().user_data().set(|| - XdgSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: surface, - shell: shell.clone(), - }, - ); + id.as_ref().user_data().set(|| XdgSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: surface, + shell: shell.clone(), + }); } zxdg_shell_v6::Request::Pong { serial } => { let valid = { @@ -126,75 +124,74 @@ where fn implement_positioner( positioner: Main, ) -> zxdg_positioner_v6::ZxdgPositionerV6 { - positioner.quick_assign( - |positioner, request, _data| { - let mutex = positioner - .as_ref() - .user_data() - .get::>() - .unwrap(); - let mut state = mutex.borrow_mut(); - match request { - zxdg_positioner_v6::Request::Destroy => { - // handled by destructor - } - zxdg_positioner_v6::Request::SetSize { width, height } => { - if width < 1 || height < 1 { - positioner.as_ref().post_error( - zxdg_positioner_v6::Error::InvalidInput as u32, - "Invalid size for positioner.".into(), - ); - } else { - state.rect_size = (width, height); - } - } - zxdg_positioner_v6::Request::SetAnchorRect { x, y, width, height } => { - if width < 1 || height < 1 { - positioner.as_ref().post_error( - zxdg_positioner_v6::Error::InvalidInput as u32, - "Invalid size for positioner's anchor rectangle.".into(), - ); - } else { - state.anchor_rect = Rectangle { x, y, width, height }; - } - } - zxdg_positioner_v6::Request::SetAnchor { anchor } => { - if let Some(anchor) = zxdg_anchor_to_xdg(anchor) { - state.anchor_edges = anchor; - } else { - positioner.as_ref().post_error( - zxdg_positioner_v6::Error::InvalidInput as u32, - "Invalid anchor for positioner.".into(), - ); - } - } - zxdg_positioner_v6::Request::SetGravity { gravity } => { - if let Some(gravity) = zxdg_gravity_to_xdg(gravity) { - state.gravity = gravity; - } else { - positioner.as_ref().post_error( - zxdg_positioner_v6::Error::InvalidInput as u32, - "Invalid gravity for positioner.".into(), - ); - } - } - zxdg_positioner_v6::Request::SetConstraintAdjustment { - constraint_adjustment, - } => { - let constraint_adjustment = - zxdg_positioner_v6::ConstraintAdjustment::from_bits_truncate(constraint_adjustment); - state.constraint_adjustment = zxdg_constraints_adg_to_xdg(constraint_adjustment); - } - zxdg_positioner_v6::Request::SetOffset { x, y } => { - state.offset = (x, y); - } - _ => unreachable!(), + positioner.quick_assign(|positioner, request, _data| { + let mutex = positioner + .as_ref() + .user_data() + .get::>() + .unwrap(); + let mut state = mutex.borrow_mut(); + match request { + zxdg_positioner_v6::Request::Destroy => { + // handled by destructor } - }, - ); - positioner.as_ref().user_data().set(|| - RefCell::new(PositionerState::new()), - ); + zxdg_positioner_v6::Request::SetSize { width, height } => { + if width < 1 || height < 1 { + positioner.as_ref().post_error( + zxdg_positioner_v6::Error::InvalidInput as u32, + "Invalid size for positioner.".into(), + ); + } else { + state.rect_size = (width, height); + } + } + zxdg_positioner_v6::Request::SetAnchorRect { x, y, width, height } => { + if width < 1 || height < 1 { + positioner.as_ref().post_error( + zxdg_positioner_v6::Error::InvalidInput as u32, + "Invalid size for positioner's anchor rectangle.".into(), + ); + } else { + state.anchor_rect = Rectangle { x, y, width, height }; + } + } + zxdg_positioner_v6::Request::SetAnchor { anchor } => { + if let Some(anchor) = zxdg_anchor_to_xdg(anchor) { + state.anchor_edges = anchor; + } else { + positioner.as_ref().post_error( + zxdg_positioner_v6::Error::InvalidInput as u32, + "Invalid anchor for positioner.".into(), + ); + } + } + zxdg_positioner_v6::Request::SetGravity { gravity } => { + if let Some(gravity) = zxdg_gravity_to_xdg(gravity) { + state.gravity = gravity; + } else { + positioner.as_ref().post_error( + zxdg_positioner_v6::Error::InvalidInput as u32, + "Invalid gravity for positioner.".into(), + ); + } + } + zxdg_positioner_v6::Request::SetConstraintAdjustment { + constraint_adjustment, + } => { + let constraint_adjustment = + zxdg_positioner_v6::ConstraintAdjustment::from_bits_truncate(constraint_adjustment); + state.constraint_adjustment = zxdg_constraints_adg_to_xdg(constraint_adjustment); + } + zxdg_positioner_v6::Request::SetOffset { x, y } => { + state.offset = (x, y); + } + _ => unreachable!(), + } + }); + positioner + .as_ref() + .user_data() + .set(|| RefCell::new(PositionerState::new())); positioner.deref().clone() } @@ -267,16 +264,16 @@ fn xdg_surface_implementation( }); }) .expect("xdg_surface exists but surface has not shell_surface role?!"); - id.quick_assign(|toplevel, req, _data| toplevel_implementation::(req, toplevel.deref().clone())); + id.quick_assign(|toplevel, req, _data| { + toplevel_implementation::(req, toplevel.deref().clone()) + }); id.assign_destructor(Filter::new(|toplevel, _, _data| destroy_toplevel::(toplevel))); - id.as_ref().user_data().set(|| - ShellSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: data.wl_surface.clone(), - shell: data.shell.clone(), - xdg_surface: xdg_surface.clone(), - }, - ); + id.as_ref().user_data().set(|| ShellSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: data.wl_surface.clone(), + shell: data.shell.clone(), + xdg_surface: xdg_surface.clone(), + }); data.shell_data .shell_state @@ -316,14 +313,12 @@ fn xdg_surface_implementation( .expect("xdg_surface exists but surface has not shell_surface role?!"); id.quick_assign(|popup, req, _data| popup_implementation::(req, popup.deref().clone())); id.assign_destructor(Filter::new(|popup, _, _data| destroy_popup::(popup))); - id.as_ref().user_data().set(|| - ShellSurfaceUserData { - shell_data: data.shell_data.clone(), - wl_surface: data.wl_surface.clone(), - shell: data.shell.clone(), - xdg_surface: xdg_surface.clone(), - }, - ); + id.as_ref().user_data().set(|| ShellSurfaceUserData { + shell_data: data.shell_data.clone(), + wl_surface: data.wl_surface.clone(), + shell: data.shell.clone(), + xdg_surface: xdg_surface.clone(), + }); data.shell_data .shell_state diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index a6393d1..8a3aea1 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -266,7 +266,7 @@ impl ShmGlobalData { format, }, }; - buffer.quick_assign(|_,_,_| {}); + buffer.quick_assign(|_, _, _| {}); buffer.as_ref().user_data().set(|| data); } Request::Resize { size } => match arc_pool.resize(size) {