diff --git a/examples/helpers/glium.rs b/examples/helpers/glium.rs index 23a8278..d407b46 100644 --- a/examples/helpers/glium.rs +++ b/examples/helpers/glium.rs @@ -19,7 +19,6 @@ pub struct GliumDrawer<'a, F: 'a> { impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> { pub fn new(display: &'a F) -> GliumDrawer<'a, F> { - // building the vertex buffer, which contains all the vertices that we will draw let vertex_buffer = glium::VertexBuffer::new( display, @@ -87,7 +86,6 @@ impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> { pub fn draw(&self, target: &mut glium::Frame, contents: &[u8], surface_dimensions: (u32, u32), surface_location: (i32, i32), screen_size: (u32, u32)) { - let image = glium::texture::RawImage2d { data: contents.into(), width: surface_dimensions.0, @@ -102,8 +100,7 @@ impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> { let x = 2.0 * (surface_location.0 as f32) / (screen_size.0 as f32) - 1.0; let y = 1.0 - 2.0 * (surface_location.1 as f32) / (screen_size.1 as f32); - let uniforms = - uniform! { + let uniforms = uniform! { matrix: [ [xscale, 0.0 , 0.0, 0.0], [ 0.0 , yscale , 0.0, 0.0], @@ -122,6 +119,5 @@ impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> { &Default::default(), ) .unwrap(); - } } diff --git a/examples/helpers/shell.rs b/examples/helpers/shell.rs index e640b0d..e3d9b14 100644 --- a/examples/helpers/shell.rs +++ b/examples/helpers/shell.rs @@ -44,20 +44,14 @@ impl Init for WlShellStubHandler { impl GlobalHandler for WlShellStubHandler where U: Send + 'static, - R: RoleType - + Role - + Send - + 'static, - H: CompositorHandler - + Send - + 'static, + R: RoleType + Role + Send + 'static, + H: CompositorHandler + Send + 'static, { fn bind(&mut self, evqh: &mut EventLoopHandle, client: &Client, global: wl_shell::WlShell) { evqh.register::<_, Self>( &global, - self.my_id.expect( - "WlShellStubHandler was not properly initialized.", - ), + self.my_id + .expect("WlShellStubHandler was not properly initialized."), ); } } @@ -65,10 +59,7 @@ where impl wl_shell::Handler for WlShellStubHandler where U: Send + 'static, - R: RoleType - + Role - + Send - + 'static, + R: RoleType + Role + Send + 'static, H: CompositorHandler + Send + 'static, { fn get_shell_surface(&mut self, evqh: &mut EventLoopHandle, client: &Client, @@ -95,9 +86,7 @@ server_declare_handler!(WlShellStubHandler wl_shell_surface::Handler for WlShellStubHandler where U: Send + 'static, - H: CompositorHandler - + Send - + 'static, + H: CompositorHandler + Send + 'static, { } diff --git a/examples/simple.rs b/examples/simple.rs index ea8723a..8635357 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,9 +1,9 @@ -#[macro_use(server_declare_handler)] -extern crate wayland_server; -#[macro_use(define_roles)] -extern crate smithay; #[macro_use] extern crate glium; +#[macro_use(define_roles)] +extern crate smithay; +#[macro_use(server_declare_handler)] +extern crate wayland_server; #[macro_use] extern crate slog; @@ -59,7 +59,6 @@ impl compositor::Handler for SurfaceHandler { attributes.user_data.buffer = Some((new_vec, (data.width as u32, data.height as u32))); }); - } Some(None) => { // erase the contents @@ -104,7 +103,9 @@ fn main() { * Initialize the compositor global */ let compositor_handler_id = event_loop.add_handler_with_init(MyCompositorHandler::new( - SurfaceHandler { shm_token: shm_token.clone() }, + SurfaceHandler { + shm_token: shm_token.clone(), + }, log.clone(), )); // register it to handle wl_compositor and wl_subcompositor @@ -151,32 +152,32 @@ fn main() { { let screen_dimensions = context.get_framebuffer_dimensions(); let state = event_loop.state(); - for &(_, ref surface) in - state - .get_handler::>(shell_handler_id) - .surfaces() + for &(_, ref surface) in state + .get_handler::>(shell_handler_id) + .surfaces() { if surface.status() != Liveness::Alive { continue; } // this surface is a root of a subsurface tree that needs to be drawn - compositor_token.with_surface_tree(surface, (100, 100), |surface, - attributes, - role, - &(mut x, mut y)| { - if let Some((ref contents, (w, h))) = attributes.user_data.buffer { - // there is actually something to draw ! - if let Ok(subdata) = Role::::data(role) { - x += subdata.x; - y += subdata.y; + compositor_token.with_surface_tree( + surface, + (100, 100), + |surface, attributes, role, &(mut x, mut y)| { + if let Some((ref contents, (w, h))) = attributes.user_data.buffer { + // there is actually something to draw ! + if let Ok(subdata) = Role::::data(role) { + x += subdata.x; + y += subdata.y; + } + drawer.draw(&mut frame, contents, (w, h), (x, y), screen_dimensions); + TraversalAction::DoChildren((x, y)) + } else { + // we are not display, so our children are neither + TraversalAction::SkipChildren } - drawer.draw(&mut frame, contents, (w, h), (x, y), screen_dimensions); - TraversalAction::DoChildren((x, y)) - } else { - // we are not display, so our children are neither - TraversalAction::SkipChildren - } - }); + }, + ); } } frame.finish().unwrap(); diff --git a/src/backend/graphics/egl.rs b/src/backend/graphics/egl.rs index bfd33ad..b6c5e51 100644 --- a/src/backend/graphics/egl.rs +++ b/src/backend/graphics/egl.rs @@ -116,11 +116,11 @@ impl error::Error for CreationError { CreationError::OsError(ref text) => text, CreationError::OpenGlVersionNotSupported => { "The requested OpenGL version is not \ - supported." + supported." } CreationError::NoAvailablePixelFormat => { "Couldn't find any pixel format that matches \ - the criterias." + the criterias." } CreationError::NonMatchingSurfaceType => "Surface type does not match the context type.", CreationError::NotSupported => "Context creation is not supported on the current window system", @@ -244,31 +244,36 @@ impl EGLContext { let display = match native { NativeDisplay::X11(display) - if has_dp_extension("EGL_KHR_platform_x11") && egl.GetPlatformDisplay.is_loaded() => { + if has_dp_extension("EGL_KHR_platform_x11") && egl.GetPlatformDisplay.is_loaded() => + { trace!(log, "EGL Display Initialization via EGL_KHR_platform_x11"); egl.GetPlatformDisplay(ffi::egl::PLATFORM_X11_KHR, display as *mut _, ptr::null()) } NativeDisplay::X11(display) - if has_dp_extension("EGL_EXT_platform_x11") && egl.GetPlatformDisplayEXT.is_loaded() => { + if has_dp_extension("EGL_EXT_platform_x11") && egl.GetPlatformDisplayEXT.is_loaded() => + { trace!(log, "EGL Display Initialization via EGL_EXT_platform_x11"); egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_X11_EXT, display as *mut _, ptr::null()) } NativeDisplay::Gbm(display) - if has_dp_extension("EGL_KHR_platform_gbm") && egl.GetPlatformDisplay.is_loaded() => { + if has_dp_extension("EGL_KHR_platform_gbm") && egl.GetPlatformDisplay.is_loaded() => + { trace!(log, "EGL Display Initialization via EGL_KHR_platform_gbm"); egl.GetPlatformDisplay(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null()) } NativeDisplay::Gbm(display) - if has_dp_extension("EGL_MESA_platform_gbm") && egl.GetPlatformDisplayEXT.is_loaded() => { + if has_dp_extension("EGL_MESA_platform_gbm") && egl.GetPlatformDisplayEXT.is_loaded() => + { trace!(log, "EGL Display Initialization via EGL_MESA_platform_gbm"); egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null()) } NativeDisplay::Wayland(display) - if has_dp_extension("EGL_KHR_platform_wayland") && egl.GetPlatformDisplay.is_loaded() => { + if has_dp_extension("EGL_KHR_platform_wayland") && egl.GetPlatformDisplay.is_loaded() => + { trace!( log, "EGL Display Initialization via EGL_KHR_platform_wayland" @@ -281,7 +286,8 @@ impl EGLContext { } NativeDisplay::Wayland(display) - if has_dp_extension("EGL_EXT_platform_wayland") && egl.GetPlatformDisplayEXT.is_loaded() => { + if has_dp_extension("EGL_EXT_platform_wayland") && egl.GetPlatformDisplayEXT.is_loaded() => + { trace!( log, "EGL Display Initialization via EGL_EXT_platform_wayland" @@ -293,9 +299,7 @@ impl EGLContext { ) } - NativeDisplay::X11(display) | - NativeDisplay::Gbm(display) | - NativeDisplay::Wayland(display) => { + NativeDisplay::X11(display) | NativeDisplay::Gbm(display) | NativeDisplay::Wayland(display) => { trace!(log, "Default EGL Display Initialization via GetDisplay"); egl.GetDisplay(display as *mut _) } @@ -522,7 +526,6 @@ impl EGLContext { context_attributes.push(ffi::egl::CONTEXT_FLAGS_KHR as i32); context_attributes.push(0); - } else if egl_version >= (1, 3) { trace!(log, "Setting CONTEXT_CLIENT_VERSION to {}", version.0); context_attributes.push(ffi::egl::CONTEXT_CLIENT_VERSION as i32); @@ -602,14 +605,12 @@ impl EGLContext { let surface = match (native, self.backend_type) { (NativeSurface::X11(window), NativeType::X11) | (NativeSurface::Wayland(window), NativeType::Wayland) | - (NativeSurface::Gbm(window), NativeType::Gbm) => { - self.egl.CreateWindowSurface( - self.display, - self.config_id, - window, - self.surface_attributes.as_ptr(), - ) - } + (NativeSurface::Gbm(window), NativeType::Gbm) => self.egl.CreateWindowSurface( + self.display, + self.config_id, + window, + self.surface_attributes.as_ptr(), + ), _ => return Err(CreationError::NonMatchingSurfaceType), }; @@ -654,10 +655,9 @@ impl<'a> EGLSurface<'a> { /// Swaps buffers at the end of a frame. pub fn swap_buffers(&self) -> Result<(), SwapBuffersError> { let ret = unsafe { - self.context.egl.SwapBuffers( - self.context.display as *const _, - self.surface as *const _, - ) + self.context + .egl + .SwapBuffers(self.context.display as *const _, self.surface as *const _) }; if ret == 0 { @@ -705,10 +705,8 @@ impl Drop for EGLContext { unsafe { // we don't call MakeCurrent(0, 0) because we are not sure that the context // is still the current one - self.egl.DestroyContext( - self.display as *const _, - self.context as *const _, - ); + self.egl + .DestroyContext(self.display as *const _, self.context as *const _); self.egl.Terminate(self.display as *const _); } } @@ -717,10 +715,9 @@ impl Drop for EGLContext { impl<'a> Drop for EGLSurface<'a> { fn drop(&mut self) { unsafe { - self.context.egl.DestroySurface( - self.context.display as *const _, - self.surface as *const _, - ); + self.context + .egl + .DestroySurface(self.context.display as *const _, self.surface as *const _); } } } diff --git a/src/backend/libinput.rs b/src/backend/libinput.rs index 65ceb4e..4cbad35 100644 --- a/src/backend/libinput.rs +++ b/src/backend/libinput.rs @@ -87,10 +87,10 @@ impl<'a> backend::PointerAxisEvent for PointerAxisEvent { fn amount(&self) -> f64 { match self.source() { - backend::AxisSource::Finger | - backend::AxisSource::Continuous => self.event.axis_value(self.axis), - backend::AxisSource::Wheel | - backend::AxisSource::WheelTilt => self.event.axis_value_discrete(self.axis).unwrap(), + backend::AxisSource::Finger | backend::AxisSource::Continuous => self.event.axis_value(self.axis), + backend::AxisSource::Wheel | backend::AxisSource::WheelTilt => { + self.event.axis_value_discrete(self.axis).unwrap() + } } } } @@ -271,9 +271,9 @@ impl backend::InputBackend for LibinputInputBackend { } fn get_handler(&mut self) -> Option<&mut backend::InputHandler> { - self.handler.as_mut().map(|handler| { - handler as &mut backend::InputHandler - }) + self.handler + .as_mut() + .map(|handler| handler as &mut backend::InputHandler) } fn clear_handler(&mut self) { @@ -349,21 +349,18 @@ impl backend::InputBackend for LibinputInputBackend { // update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`. if let Some(seat) = self.seats.get_mut(&device_seat) { let caps = seat.capabilities_mut(); - caps.pointer = - self.devices - .iter() - .filter(|x| x.seat() == device_seat) - .any(|x| x.has_capability(libinput::DeviceCapability::Pointer)); - caps.keyboard = - self.devices - .iter() - .filter(|x| x.seat() == device_seat) - .any(|x| x.has_capability(libinput::DeviceCapability::Keyboard)); - caps.touch = - self.devices - .iter() - .filter(|x| x.seat() == device_seat) - .any(|x| x.has_capability(libinput::DeviceCapability::Touch)); + caps.pointer = self.devices + .iter() + .filter(|x| x.seat() == device_seat) + .any(|x| x.has_capability(libinput::DeviceCapability::Pointer)); + caps.keyboard = self.devices + .iter() + .filter(|x| x.seat() == device_seat) + .any(|x| x.has_capability(libinput::DeviceCapability::Keyboard)); + caps.touch = self.devices + .iter() + .filter(|x| x.seat() == device_seat) + .any(|x| x.has_capability(libinput::DeviceCapability::Touch)); } else { panic!("Seat changed that was never created") } @@ -395,9 +392,9 @@ impl backend::InputBackend for LibinputInputBackend { use input::event::touch::*; if let Some(ref mut handler) = self.handler { let device_seat = touch_event.device().seat(); - let seat = &self.seats.get(&device_seat).expect( - "Recieved touch event of non existing Seat", - ); + let seat = &self.seats + .get(&device_seat) + .expect("Recieved touch event of non existing Seat"); match touch_event { TouchEvent::Down(down_event) => { trace!(self.logger, "Calling on_touch_down with {:?}", down_event); @@ -433,25 +430,23 @@ impl backend::InputBackend for LibinputInputBackend { libinput::Event::Keyboard(keyboard_event) => { use input::event::keyboard::*; match keyboard_event { - KeyboardEvent::Key(key_event) => { - if let Some(ref mut handler) = self.handler { - let device_seat = key_event.device().seat(); - let seat = &self.seats.get(&device_seat).expect( - "Recieved key event of non existing Seat", - ); - trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event); - handler.on_keyboard_key(seat, key_event); - } - } + KeyboardEvent::Key(key_event) => if let Some(ref mut handler) = self.handler { + let device_seat = key_event.device().seat(); + let seat = &self.seats + .get(&device_seat) + .expect("Recieved key event of non existing Seat"); + trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event); + handler.on_keyboard_key(seat, key_event); + }, } } libinput::Event::Pointer(pointer_event) => { use input::event::pointer::*; if let Some(ref mut handler) = self.handler { let device_seat = pointer_event.device().seat(); - let seat = &self.seats.get(&device_seat).expect( - "Recieved pointer event of non existing Seat", - ); + let seat = &self.seats + .get(&device_seat) + .expect("Recieved pointer event of non existing Seat"); match pointer_event { PointerEvent::Motion(motion_event) => { trace!( diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 5fdb921..3cf23d2 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -214,9 +214,9 @@ impl EGLGraphicsBackend for WinitGraphicsBackend { } fn get_framebuffer_dimensions(&self) -> (u32, u32) { - self.window.get_inner_size_pixels().expect( - "Window does not exist anymore", - ) + self.window + .get_inner_size_pixels() + .expect("Window does not exist anymore") } fn is_current(&self) -> bool { @@ -310,14 +310,16 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent { fn x_transformed(&self, width: u32) -> u32 { cmp::min( - (self.x * width as f64 / self.window.get_inner_size_points().unwrap_or((width, 0)).0 as f64) as u32, + (self.x * width as f64 / self.window.get_inner_size_points().unwrap_or((width, 0)).0 as f64) as + u32, 0, ) } fn y_transformed(&self, height: u32) -> u32 { cmp::min( - (self.y * height as f64 / self.window.get_inner_size_points().unwrap_or((0, height)).1 as f64) as u32, + (self.y * height as f64 / self.window.get_inner_size_points().unwrap_or((0, height)).1 as f64) as + u32, 0, ) } @@ -529,9 +531,9 @@ impl InputBackend for WinitInputBackend { } fn get_handler(&mut self) -> Option<&mut InputHandler> { - self.handler.as_mut().map(|handler| { - handler as &mut InputHandler - }) + self.handler + .as_mut() + .map(|handler| handler as &mut InputHandler) } fn clear_handler(&mut self) { @@ -590,10 +592,15 @@ impl InputBackend for WinitInputBackend { wl_egl_surface.resize(x as i32, y as i32, 0, 0); } } - (WindowEvent::KeyboardInput { - input: KeyboardInput { scancode, state, .. }, .. - }, - Some(handler)) => { + ( + WindowEvent::KeyboardInput { + input: KeyboardInput { + scancode, state, .. + }, + .. + }, + Some(handler), + ) => { match state { ElementState::Pressed => *key_counter += 1, ElementState::Released => { @@ -615,7 +622,12 @@ impl InputBackend for WinitInputBackend { }, ) } - (WindowEvent::MouseMoved { position: (x, y), .. }, Some(handler)) => { + ( + WindowEvent::MouseMoved { + position: (x, y), .. + }, + Some(handler), + ) => { trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y)); handler.on_pointer_move_absolute( seat, @@ -627,39 +639,36 @@ impl InputBackend for WinitInputBackend { }, ) } - (WindowEvent::MouseWheel { delta, .. }, Some(handler)) => { - match delta { - MouseScrollDelta::LineDelta(x, y) | - MouseScrollDelta::PixelDelta(x, y) => { - if x != 0.0 { - let event = WinitMouseWheelEvent { - axis: Axis::Horizontal, - time: *time_counter, - delta: delta, - }; - trace!( - logger, - "Calling on_pointer_axis for Axis::Horizontal with {:?}", - x - ); - handler.on_pointer_axis(seat, event); - } - if y != 0.0 { - let event = WinitMouseWheelEvent { - axis: Axis::Vertical, - time: *time_counter, - delta: delta, - }; - trace!( - logger, - "Calling on_pointer_axis for Axis::Vertical with {:?}", - y - ); - handler.on_pointer_axis(seat, event); - } + (WindowEvent::MouseWheel { delta, .. }, Some(handler)) => match delta { + MouseScrollDelta::LineDelta(x, y) | MouseScrollDelta::PixelDelta(x, y) => { + if x != 0.0 { + let event = WinitMouseWheelEvent { + axis: Axis::Horizontal, + time: *time_counter, + delta: delta, + }; + trace!( + logger, + "Calling on_pointer_axis for Axis::Horizontal with {:?}", + x + ); + handler.on_pointer_axis(seat, event); + } + if y != 0.0 { + let event = WinitMouseWheelEvent { + axis: Axis::Vertical, + time: *time_counter, + delta: delta, + }; + trace!( + logger, + "Calling on_pointer_axis for Axis::Vertical with {:?}", + y + ); + handler.on_pointer_axis(seat, event); } } - } + }, (WindowEvent::MouseInput { state, button, .. }, Some(handler)) => { trace!( logger, @@ -675,13 +684,15 @@ impl InputBackend for WinitInputBackend { }, ) } - (WindowEvent::Touch(Touch { - phase: TouchPhase::Started, - location: (x, y), - id, - .. - }), - Some(handler)) => { + ( + WindowEvent::Touch(Touch { + phase: TouchPhase::Started, + location: (x, y), + id, + .. + }), + Some(handler), + ) => { trace!(logger, "Calling on_touch_down at {:?}", (x, y)); handler.on_touch_down( seat, @@ -693,13 +704,15 @@ impl InputBackend for WinitInputBackend { }, ) } - (WindowEvent::Touch(Touch { - phase: TouchPhase::Moved, - location: (x, y), - id, - .. - }), - Some(handler)) => { + ( + WindowEvent::Touch(Touch { + phase: TouchPhase::Moved, + location: (x, y), + id, + .. + }), + Some(handler), + ) => { trace!(logger, "Calling on_touch_motion at {:?}", (x, y)); handler.on_touch_motion( seat, @@ -711,13 +724,15 @@ impl InputBackend for WinitInputBackend { }, ) } - (WindowEvent::Touch(Touch { - phase: TouchPhase::Ended, - location: (x, y), - id, - .. - }), - Some(handler)) => { + ( + WindowEvent::Touch(Touch { + phase: TouchPhase::Ended, + location: (x, y), + id, + .. + }), + Some(handler), + ) => { trace!(logger, "Calling on_touch_motion at {:?}", (x, y)); handler.on_touch_motion( seat, @@ -737,12 +752,14 @@ impl InputBackend for WinitInputBackend { }, ); } - (WindowEvent::Touch(Touch { - phase: TouchPhase::Cancelled, - id, - .. - }), - Some(handler)) => { + ( + WindowEvent::Touch(Touch { + phase: TouchPhase::Cancelled, + id, + .. + }), + Some(handler), + ) => { trace!(logger, "Calling on_touch_cancel"); handler.on_touch_cancel( seat, diff --git a/src/compositor/global.rs b/src/compositor/global.rs index 80609e2..db03be3 100644 --- a/src/compositor/global.rs +++ b/src/compositor/global.rs @@ -5,15 +5,9 @@ use wayland_server::protocol::{wl_compositor, wl_subcompositor}; impl GlobalHandler for CompositorHandler where - U: Default - + Send - + 'static, - R: Default - + Send - + 'static, - H: UserHandler - + Send - + 'static, + U: Default + Send + 'static, + R: Default + Send + 'static, + H: UserHandler + Send + 'static, { fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) { debug!(self.log, "New compositor global binded."); diff --git a/src/compositor/handlers.rs b/src/compositor/handlers.rs index 9a4add9..b8acb67 100644 --- a/src/compositor/handlers.rs +++ b/src/compositor/handlers.rs @@ -193,10 +193,7 @@ impl Destroy for CompositorDestructor { impl wl_subcompositor::Handler for CompositorHandler where U: Send + 'static, - R: RoleType - + Role - + Send - + 'static, + R: RoleType + Role + Send + 'static, H: Send + 'static, { fn get_subsurface(&mut self, evqh: &mut EventLoopHandle, _: &Client, @@ -210,9 +207,9 @@ where ); return; } - id.set_user_data(Box::into_raw( - Box::new(unsafe { surface.clone_unchecked() }), - ) as *mut _); + id.set_user_data( + Box::into_raw(Box::new(unsafe { surface.clone_unchecked() })) as *mut _, + ); evqh.register_with_destructor::<_, CompositorHandler, CompositorDestructor>( &id, self.my_id, @@ -259,7 +256,10 @@ where let ptr = subsurface.get_user_data(); let surface = &*(ptr as *mut wl_surface::WlSurface); if let Err(()) = SurfaceData::::reorder(surface, Location::After, sibling) { - subsurface.post_error(wl_subsurface::Error::BadSurface as u32, "Provided surface is not a sibling or parent.".into()); + subsurface.post_error( + wl_subsurface::Error::BadSurface as u32, + "Provided surface is not a sibling or parent.".into(), + ); } } } @@ -270,7 +270,10 @@ where let ptr = subsurface.get_user_data(); let surface = &*(ptr as *mut wl_surface::WlSurface); if let Err(()) = SurfaceData::::reorder(surface, Location::Before, sibling) { - subsurface.post_error(wl_subsurface::Error::BadSurface as u32, "Provided surface is not a sibling or parent.".into()); + subsurface.post_error( + wl_subsurface::Error::BadSurface as u32, + "Provided surface is not a sibling or parent.".into(), + ); } } } @@ -291,7 +294,8 @@ where server_declare_handler!(CompositorHandler], H: []>, wl_subsurface::Handler, wl_subsurface::WlSubsurface); impl Destroy for CompositorDestructor - where R: RoleType + Role +where + R: RoleType + Role, { fn destroy(subsurface: &wl_subsurface::WlSubsurface) { let ptr = subsurface.get_user_data(); diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index f9fdb0c..af9582b 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -107,7 +107,7 @@ use self::region::RegionData; use self::roles::{Role, RoleType, WrongRole}; use self::tree::SurfaceData; pub use self::tree::TraversalAction; -use wayland_server::{Client, EventLoopHandle, Init, resource_is_registered}; +use wayland_server::{resource_is_registered, Client, EventLoopHandle, Init}; use wayland_server::protocol::{wl_buffer, wl_callback, wl_output, wl_region, wl_surface}; @@ -321,14 +321,11 @@ where /// - a custom value that is passer in a fold-like maneer, but only from the output of a parent /// to its children. See `TraversalAction` for details. /// - /// If the surface is not managed by the CompositorGlobal that provided this token, this + /// If the surface not managed by the CompositorGlobal that provided this token, this /// will panic (having more than one compositor is not supported). pub fn with_surface_tree(&self, surface: &wl_surface::WlSurface, initial: T, f: F) -> Result<(), ()> where - F: FnMut(&wl_surface::WlSurface, - &mut SurfaceAttributes, - &mut R, - &T) + F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, { assert!( @@ -440,10 +437,11 @@ impl + Send + /// /// If the surface is not managed by the CompositorGlobal that provided this token, this /// will panic (having more than one compositor is not supported). - pub fn with_role_data(&self, surface: &wl_surface::WlSurface, f: F) -> Result + pub fn with_role_data(&self, surface: &wl_surface::WlSurface, f: F) + -> Result where R: Role, - F: FnOnce(&mut RoleData) -> T + F: FnOnce(&mut RoleData) -> T, { assert!( resource_is_registered::<_, CompositorHandler>(surface, self.hid), diff --git a/src/compositor/region.rs b/src/compositor/region.rs index 7f56d1c..d6a7a22 100644 --- a/src/compositor/region.rs +++ b/src/compositor/region.rs @@ -13,9 +13,9 @@ pub struct RegionData { impl RegionData { /// Initialize the user_data of a region, must be called right when the surface is created pub unsafe fn init(region: &wl_region::WlRegion) { - region.set_user_data(Box::into_raw( - Box::new(Mutex::new(RegionData::default())), - ) as *mut _) + region.set_user_data( + Box::into_raw(Box::new(Mutex::new(RegionData::default()))) as *mut _, + ) } /// Cleans the user_data of that surface, must be called when it is destroyed diff --git a/src/compositor/tree.rs b/src/compositor/tree.rs index c3c1e9b..ccd0de4 100644 --- a/src/compositor/tree.rs +++ b/src/compositor/tree.rs @@ -58,9 +58,9 @@ impl SurfaceData { /// Initialize the user_data of a surface, must be called right when the surface is created pub unsafe fn init(surface: &wl_surface::WlSurface) { - surface.set_user_data(Box::into_raw( - Box::new(Mutex::new(SurfaceData::::new())), - ) as *mut _) + surface.set_user_data( + Box::into_raw(Box::new(Mutex::new(SurfaceData::::new()))) as *mut _, + ) } } @@ -315,21 +315,15 @@ impl SurfaceData { /// false will cause an early-stopping. pub unsafe fn map_tree(root: &wl_surface::WlSurface, initial: T, mut f: F) where - F: FnMut(&wl_surface::WlSurface, - &mut SurfaceAttributes, - &mut R, - &T) + F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, { // helper function for recursion - unsafe fn map(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, initial: &T, - f: &mut F) + unsafe fn map(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, + initial: &T, f: &mut F) -> bool where - F: FnMut(&wl_surface::WlSurface, - &mut SurfaceAttributes, - &mut R, - &T) + F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes, &mut R, &T) -> TraversalAction, { // stop if we met the root, so to not deadlock/inifinte loop diff --git a/src/keyboard/mod.rs b/src/keyboard/mod.rs index cf957a9..0b444de 100644 --- a/src/keyboard/mod.rs +++ b/src/keyboard/mod.rs @@ -29,7 +29,7 @@ use wayland_server::protocol::{wl_keyboard, wl_surface}; use xkbcommon::xkb; -pub use xkbcommon::xkb::{Keysym, keysyms}; +pub use xkbcommon::xkb::{keysyms, Keysym}; /// Represents the current state of the keyboard modifiers /// @@ -178,19 +178,18 @@ where "rules" => rules, "model" => model, "layout" => layout, "variant" => variant, "options" => &options ); - let internal = KbdInternal::new(rules, model, layout, variant, options) - .map_err(|_| { - debug!(log, "Loading keymap failed"); - Error::BadKeymap - })?; + let internal = KbdInternal::new(rules, model, layout, variant, options).map_err(|_| { + debug!(log, "Loading keymap failed"); + Error::BadKeymap + })?; // prepare a tempfile with the keymap, to send it to clients let mut keymap_file = tempfile().map_err(Error::IoError)?; let keymap_data = internal.keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1); - keymap_file.write_all(keymap_data.as_bytes()).map_err( - Error::IoError, - )?; + keymap_file + .write_all(keymap_data.as_bytes()) + .map_err(Error::IoError)?; keymap_file.flush().map_err(Error::IoError)?; trace!(log, "Keymap loaded and copied to tempfile."; diff --git a/src/shm/mod.rs b/src/shm/mod.rs index 9dba511..d3dd27b 100644 --- a/src/shm/mod.rs +++ b/src/shm/mod.rs @@ -67,7 +67,7 @@ use self::pool::{Pool, ResizeError}; use std::os::unix::io::RawFd; use std::sync::Arc; -use wayland_server::{Client, Destroy, EventLoopHandle, GlobalHandler, Init, Resource, resource_is_registered}; +use wayland_server::{resource_is_registered, Client, Destroy, EventLoopHandle, GlobalHandler, Init, Resource}; use wayland_server::protocol::{wl_buffer, wl_shm, wl_shm_pool}; mod pool; @@ -111,7 +111,9 @@ impl ShmGlobal { /// /// This is needed to retrieve the contents of the shm pools and buffers. pub fn get_token(&self) -> ShmToken { - ShmToken { hid: self.handler_id.expect("ShmGlobal was not initialized.") } + ShmToken { + hid: self.handler_id.expect("ShmGlobal was not initialized."), + } } } @@ -218,8 +220,11 @@ impl wl_shm::Handler for ShmHandler { let mmap_pool = match Pool::new(fd, size as usize, self.log.clone()) { Ok(p) => p, Err(()) => { - shm.post_error(wl_shm::Error::InvalidFd as u32, format!("Failed mmap of fd {}.", fd)); - return + shm.post_error( + wl_shm::Error::InvalidFd as u32, + format!("Failed mmap of fd {}.", fd), + ); + return; } }; let arc_pool = Box::new(Arc::new(mmap_pool)); diff --git a/src/shm/pool.rs b/src/shm/pool.rs index 4a814f0..227f669 100644 --- a/src/shm/pool.rs +++ b/src/shm/pool.rs @@ -6,7 +6,7 @@ use nix::sys::signal::{self, SigAction, SigHandler, Signal}; use std::cell::Cell; use std::os::unix::io::RawFd; use std::ptr; -use std::sync::{ONCE_INIT, Once, RwLock}; +use std::sync::{Once, RwLock, ONCE_INIT}; thread_local!(static SIGBUS_GUARD: Cell<(*const MemMap, bool)> = Cell::new((ptr::null_mut(), false)));