cargo fmt

This commit is contained in:
Victor Berger 2017-09-05 19:51:05 +02:00
parent 00c9a0c695
commit 88773cf1b3
14 changed files with 235 additions and 246 deletions

View File

@ -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();
}
}

View File

@ -44,20 +44,14 @@ impl<U, R, H> Init for WlShellStubHandler<U, R, H> {
impl<U, R, H> GlobalHandler<wl_shell::WlShell> for WlShellStubHandler<U, R, H>
where
U: Send + 'static,
R: RoleType
+ Role<ShellSurfaceRole>
+ Send
+ 'static,
H: CompositorHandler<U, R>
+ Send
+ 'static,
R: RoleType + Role<ShellSurfaceRole> + Send + 'static,
H: CompositorHandler<U, R> + 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<U, R, H> wl_shell::Handler for WlShellStubHandler<U, R, H>
where
U: Send + 'static,
R: RoleType
+ Role<ShellSurfaceRole>
+ Send
+ 'static,
R: RoleType + Role<ShellSurfaceRole> + Send + 'static,
H: CompositorHandler<U, R> + Send + 'static,
{
fn get_shell_surface(&mut self, evqh: &mut EventLoopHandle, client: &Client,
@ -95,9 +86,7 @@ server_declare_handler!(WlShellStubHandler<U: [Send], R: [RoleType, Role<ShellSu
impl<U, R, H> wl_shell_surface::Handler for WlShellStubHandler<U, R, H>
where
U: Send + 'static,
H: CompositorHandler<U, R>
+ Send
+ 'static,
H: CompositorHandler<U, R> + Send + 'static,
{
}

View File

@ -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<SurfaceData, Roles> 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,8 +152,7 @@ fn main() {
{
let screen_dimensions = context.get_framebuffer_dimensions();
let state = event_loop.state();
for &(_, ref surface) in
state
for &(_, ref surface) in state
.get_handler::<WlShellStubHandler<SurfaceData, Roles, SurfaceHandler>>(shell_handler_id)
.surfaces()
{
@ -160,10 +160,10 @@ fn main() {
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)| {
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::<SubsurfaceRole>::data(role) {
@ -176,7 +176,8 @@ fn main() {
// we are not display, so our children are neither
TraversalAction::SkipChildren
}
});
},
);
}
}
frame.finish().unwrap();

View File

@ -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(
(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 _);
}
}
}

View File

@ -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>> {
self.handler.as_mut().map(|handler| {
handler as &mut backend::InputHandler<Self>
})
self.handler
.as_mut()
.map(|handler| handler as &mut backend::InputHandler<Self>)
}
fn clear_handler(&mut self) {
@ -349,18 +349,15 @@ 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
caps.pointer = self.devices
.iter()
.filter(|x| x.seat() == device_seat)
.any(|x| x.has_capability(libinput::DeviceCapability::Pointer));
caps.keyboard =
self.devices
caps.keyboard = self.devices
.iter()
.filter(|x| x.seat() == device_seat)
.any(|x| x.has_capability(libinput::DeviceCapability::Keyboard));
caps.touch =
self.devices
caps.touch = self.devices
.iter()
.filter(|x| x.seat() == device_seat)
.any(|x| x.has_capability(libinput::DeviceCapability::Touch));
@ -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 {
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",
);
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!(

View File

@ -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>> {
self.handler.as_mut().map(|handler| {
handler as &mut InputHandler<Self>
})
self.handler
.as_mut()
.map(|handler| handler as &mut InputHandler<Self>)
}
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, .. }, ..
(
WindowEvent::KeyboardInput {
input: KeyboardInput {
scancode, state, ..
},
Some(handler)) => {
..
},
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,10 +639,8 @@ impl InputBackend for WinitInputBackend {
},
)
}
(WindowEvent::MouseWheel { delta, .. }, Some(handler)) => {
match delta {
MouseScrollDelta::LineDelta(x, y) |
MouseScrollDelta::PixelDelta(x, y) => {
(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,
@ -658,8 +668,7 @@ impl InputBackend for WinitInputBackend {
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 {
(
WindowEvent::Touch(Touch {
phase: TouchPhase::Started,
location: (x, y),
id,
..
}),
Some(handler)) => {
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 {
(
WindowEvent::Touch(Touch {
phase: TouchPhase::Moved,
location: (x, y),
id,
..
}),
Some(handler)) => {
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 {
(
WindowEvent::Touch(Touch {
phase: TouchPhase::Ended,
location: (x, y),
id,
..
}),
Some(handler)) => {
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 {
(
WindowEvent::Touch(Touch {
phase: TouchPhase::Cancelled,
id,
..
}),
Some(handler)) => {
Some(handler),
) => {
trace!(logger, "Calling on_touch_cancel");
handler.on_touch_cancel(
seat,

View File

@ -5,15 +5,9 @@ use wayland_server::protocol::{wl_compositor, wl_subcompositor};
impl<U, R, H> GlobalHandler<wl_compositor::WlCompositor> for CompositorHandler<U, R, H>
where
U: Default
+ Send
+ 'static,
R: Default
+ Send
+ 'static,
H: UserHandler<U, R>
+ Send
+ 'static,
U: Default + Send + 'static,
R: Default + Send + 'static,
H: UserHandler<U, R> + Send + 'static,
{
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) {
debug!(self.log, "New compositor global binded.");

View File

@ -193,10 +193,7 @@ impl<U, R> Destroy<wl_region::WlRegion> for CompositorDestructor<U, R> {
impl<U, R, H> wl_subcompositor::Handler for CompositorHandler<U, R, H>
where
U: Send + 'static,
R: RoleType
+ Role<SubsurfaceRole>
+ Send
+ 'static,
R: RoleType + Role<SubsurfaceRole> + 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<U, R, H>, CompositorDestructor<U, R>>(
&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::<U, R>::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::<U, R>::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<U: [], R: [RoleType, Role<SubsurfaceRole>], H: []>, wl_subsurface::Handler, wl_subsurface::WlSubsurface);
impl<U, R> Destroy<wl_subsurface::WlSubsurface> for CompositorDestructor<U, R>
where R: RoleType + Role<SubsurfaceRole>
where
R: RoleType + Role<SubsurfaceRole>,
{
fn destroy(subsurface: &wl_subsurface::WlSubsurface) {
let ptr = subsurface.get_user_data();

View File

@ -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<F, T>(&self, surface: &wl_surface::WlSurface, initial: T, f: F) -> Result<(), ()>
where
F: FnMut(&wl_surface::WlSurface,
&mut SurfaceAttributes<U>,
&mut R,
&T)
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
-> TraversalAction<T>,
{
assert!(
@ -440,10 +437,11 @@ impl<U: Send + 'static, R: Send + RoleType + 'static, H: Handler<U, R> + 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<RoleData, F, T>(&self, surface: &wl_surface::WlSurface, f: F) -> Result<T, WrongRole>
pub fn with_role_data<RoleData, F, T>(&self, surface: &wl_surface::WlSurface, f: F)
-> Result<T, WrongRole>
where
R: Role<RoleData>,
F: FnOnce(&mut RoleData) -> T
F: FnOnce(&mut RoleData) -> T,
{
assert!(
resource_is_registered::<_, CompositorHandler<U, R, H>>(surface, self.hid),

View File

@ -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

View File

@ -58,9 +58,9 @@ impl<U: Default, R: Default> SurfaceData<U, R> {
/// 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::<U, R>::new())),
) as *mut _)
surface.set_user_data(
Box::into_raw(Box::new(Mutex::new(SurfaceData::<U, R>::new()))) as *mut _,
)
}
}
@ -315,21 +315,15 @@ impl<U, R> SurfaceData<U, R> {
/// false will cause an early-stopping.
pub unsafe fn map_tree<F, T>(root: &wl_surface::WlSurface, initial: T, mut f: F)
where
F: FnMut(&wl_surface::WlSurface,
&mut SurfaceAttributes<U>,
&mut R,
&T)
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
-> TraversalAction<T>,
{
// helper function for recursion
unsafe fn map<U, R, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, initial: &T,
f: &mut F)
unsafe fn map<U, R, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface,
initial: &T, f: &mut F)
-> bool
where
F: FnMut(&wl_surface::WlSurface,
&mut SurfaceAttributes<U>,
&mut R,
&T)
F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
-> TraversalAction<T>,
{
// stop if we met the root, so to not deadlock/inifinte loop

View File

@ -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,8 +178,7 @@ where
"rules" => rules, "model" => model, "layout" => layout, "variant" => variant,
"options" => &options
);
let internal = KbdInternal::new(rules, model, layout, variant, options)
.map_err(|_| {
let internal = KbdInternal::new(rules, model, layout, variant, options).map_err(|_| {
debug!(log, "Loading keymap failed");
Error::BadKeymap
})?;
@ -188,9 +187,9 @@ where
// 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.";

View File

@ -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));

View File

@ -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)));