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> { impl<'a, F: glium::backend::Facade + 'a> GliumDrawer<'a, F> {
pub fn new(display: &'a F) -> 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 // building the vertex buffer, which contains all the vertices that we will draw
let vertex_buffer = glium::VertexBuffer::new( let vertex_buffer = glium::VertexBuffer::new(
display, 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), pub fn draw(&self, target: &mut glium::Frame, contents: &[u8], surface_dimensions: (u32, u32),
surface_location: (i32, i32), screen_size: (u32, u32)) { surface_location: (i32, i32), screen_size: (u32, u32)) {
let image = glium::texture::RawImage2d { let image = glium::texture::RawImage2d {
data: contents.into(), data: contents.into(),
width: surface_dimensions.0, 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 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 y = 1.0 - 2.0 * (surface_location.1 as f32) / (screen_size.1 as f32);
let uniforms = let uniforms = uniform! {
uniform! {
matrix: [ matrix: [
[xscale, 0.0 , 0.0, 0.0], [xscale, 0.0 , 0.0, 0.0],
[ 0.0 , yscale , 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(), &Default::default(),
) )
.unwrap(); .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> impl<U, R, H> GlobalHandler<wl_shell::WlShell> for WlShellStubHandler<U, R, H>
where where
U: Send + 'static, U: Send + 'static,
R: RoleType R: RoleType + Role<ShellSurfaceRole> + Send + 'static,
+ Role<ShellSurfaceRole> H: CompositorHandler<U, R> + Send + 'static,
+ Send
+ 'static,
H: CompositorHandler<U, R>
+ Send
+ 'static,
{ {
fn bind(&mut self, evqh: &mut EventLoopHandle, client: &Client, global: wl_shell::WlShell) { fn bind(&mut self, evqh: &mut EventLoopHandle, client: &Client, global: wl_shell::WlShell) {
evqh.register::<_, Self>( evqh.register::<_, Self>(
&global, &global,
self.my_id.expect( self.my_id
"WlShellStubHandler was not properly initialized.", .expect("WlShellStubHandler was not properly initialized."),
),
); );
} }
} }
@ -65,10 +59,7 @@ where
impl<U, R, H> wl_shell::Handler for WlShellStubHandler<U, R, H> impl<U, R, H> wl_shell::Handler for WlShellStubHandler<U, R, H>
where where
U: Send + 'static, U: Send + 'static,
R: RoleType R: RoleType + Role<ShellSurfaceRole> + Send + 'static,
+ Role<ShellSurfaceRole>
+ Send
+ 'static,
H: CompositorHandler<U, R> + Send + 'static, H: CompositorHandler<U, R> + Send + 'static,
{ {
fn get_shell_surface(&mut self, evqh: &mut EventLoopHandle, client: &Client, 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> impl<U, R, H> wl_shell_surface::Handler for WlShellStubHandler<U, R, H>
where where
U: Send + 'static, U: Send + 'static,
H: CompositorHandler<U, R> H: CompositorHandler<U, R> + Send + 'static,
+ 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] #[macro_use]
extern crate glium; extern crate glium;
#[macro_use(define_roles)]
extern crate smithay;
#[macro_use(server_declare_handler)]
extern crate wayland_server;
#[macro_use] #[macro_use]
extern crate slog; extern crate slog;
@ -59,7 +59,6 @@ impl compositor::Handler<SurfaceData, Roles> for SurfaceHandler {
attributes.user_data.buffer = attributes.user_data.buffer =
Some((new_vec, (data.width as u32, data.height as u32))); Some((new_vec, (data.width as u32, data.height as u32)));
}); });
} }
Some(None) => { Some(None) => {
// erase the contents // erase the contents
@ -104,7 +103,9 @@ fn main() {
* Initialize the compositor global * Initialize the compositor global
*/ */
let compositor_handler_id = event_loop.add_handler_with_init(MyCompositorHandler::new( 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(), log.clone(),
)); ));
// register it to handle wl_compositor and wl_subcompositor // register it to handle wl_compositor and wl_subcompositor
@ -151,32 +152,32 @@ fn main() {
{ {
let screen_dimensions = context.get_framebuffer_dimensions(); let screen_dimensions = context.get_framebuffer_dimensions();
let state = event_loop.state(); let state = event_loop.state();
for &(_, ref surface) in for &(_, ref surface) in state
state .get_handler::<WlShellStubHandler<SurfaceData, Roles, SurfaceHandler>>(shell_handler_id)
.get_handler::<WlShellStubHandler<SurfaceData, Roles, SurfaceHandler>>(shell_handler_id) .surfaces()
.surfaces()
{ {
if surface.status() != Liveness::Alive { if surface.status() != Liveness::Alive {
continue; continue;
} }
// this surface is a root of a subsurface tree that needs to be drawn // this surface is a root of a subsurface tree that needs to be drawn
compositor_token.with_surface_tree(surface, (100, 100), |surface, compositor_token.with_surface_tree(
attributes, surface,
role, (100, 100),
&(mut x, mut y)| { |surface, attributes, role, &(mut x, mut y)| {
if let Some((ref contents, (w, h))) = attributes.user_data.buffer { if let Some((ref contents, (w, h))) = attributes.user_data.buffer {
// there is actually something to draw ! // there is actually something to draw !
if let Ok(subdata) = Role::<SubsurfaceRole>::data(role) { if let Ok(subdata) = Role::<SubsurfaceRole>::data(role) {
x += subdata.x; x += subdata.x;
y += subdata.y; 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(); frame.finish().unwrap();

View File

@ -116,11 +116,11 @@ impl error::Error for CreationError {
CreationError::OsError(ref text) => text, CreationError::OsError(ref text) => text,
CreationError::OpenGlVersionNotSupported => { CreationError::OpenGlVersionNotSupported => {
"The requested OpenGL version is not \ "The requested OpenGL version is not \
supported." supported."
} }
CreationError::NoAvailablePixelFormat => { CreationError::NoAvailablePixelFormat => {
"Couldn't find any pixel format that matches \ "Couldn't find any pixel format that matches \
the criterias." the criterias."
} }
CreationError::NonMatchingSurfaceType => "Surface type does not match the context type.", CreationError::NonMatchingSurfaceType => "Surface type does not match the context type.",
CreationError::NotSupported => "Context creation is not supported on the current window system", CreationError::NotSupported => "Context creation is not supported on the current window system",
@ -244,31 +244,36 @@ impl EGLContext {
let display = match native { let display = match native {
NativeDisplay::X11(display) 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"); trace!(log, "EGL Display Initialization via EGL_KHR_platform_x11");
egl.GetPlatformDisplay(ffi::egl::PLATFORM_X11_KHR, display as *mut _, ptr::null()) egl.GetPlatformDisplay(ffi::egl::PLATFORM_X11_KHR, display as *mut _, ptr::null())
} }
NativeDisplay::X11(display) 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"); trace!(log, "EGL Display Initialization via EGL_EXT_platform_x11");
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_X11_EXT, display as *mut _, ptr::null()) egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_X11_EXT, display as *mut _, ptr::null())
} }
NativeDisplay::Gbm(display) 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"); trace!(log, "EGL Display Initialization via EGL_KHR_platform_gbm");
egl.GetPlatformDisplay(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null()) egl.GetPlatformDisplay(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
} }
NativeDisplay::Gbm(display) 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"); trace!(log, "EGL Display Initialization via EGL_MESA_platform_gbm");
egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null()) egl.GetPlatformDisplayEXT(ffi::egl::PLATFORM_GBM_KHR, display as *mut _, ptr::null())
} }
NativeDisplay::Wayland(display) 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!( trace!(
log, log,
"EGL Display Initialization via EGL_KHR_platform_wayland" "EGL Display Initialization via EGL_KHR_platform_wayland"
@ -281,7 +286,8 @@ impl EGLContext {
} }
NativeDisplay::Wayland(display) 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!( trace!(
log, log,
"EGL Display Initialization via EGL_EXT_platform_wayland" "EGL Display Initialization via EGL_EXT_platform_wayland"
@ -293,9 +299,7 @@ impl EGLContext {
) )
} }
NativeDisplay::X11(display) | NativeDisplay::X11(display) | NativeDisplay::Gbm(display) | NativeDisplay::Wayland(display) => {
NativeDisplay::Gbm(display) |
NativeDisplay::Wayland(display) => {
trace!(log, "Default EGL Display Initialization via GetDisplay"); trace!(log, "Default EGL Display Initialization via GetDisplay");
egl.GetDisplay(display as *mut _) egl.GetDisplay(display as *mut _)
} }
@ -522,7 +526,6 @@ impl EGLContext {
context_attributes.push(ffi::egl::CONTEXT_FLAGS_KHR as i32); context_attributes.push(ffi::egl::CONTEXT_FLAGS_KHR as i32);
context_attributes.push(0); context_attributes.push(0);
} else if egl_version >= (1, 3) { } else if egl_version >= (1, 3) {
trace!(log, "Setting CONTEXT_CLIENT_VERSION to {}", version.0); trace!(log, "Setting CONTEXT_CLIENT_VERSION to {}", version.0);
context_attributes.push(ffi::egl::CONTEXT_CLIENT_VERSION as i32); context_attributes.push(ffi::egl::CONTEXT_CLIENT_VERSION as i32);
@ -602,14 +605,12 @@ impl EGLContext {
let surface = match (native, self.backend_type) { let surface = match (native, self.backend_type) {
(NativeSurface::X11(window), NativeType::X11) | (NativeSurface::X11(window), NativeType::X11) |
(NativeSurface::Wayland(window), NativeType::Wayland) | (NativeSurface::Wayland(window), NativeType::Wayland) |
(NativeSurface::Gbm(window), NativeType::Gbm) => { (NativeSurface::Gbm(window), NativeType::Gbm) => self.egl.CreateWindowSurface(
self.egl.CreateWindowSurface( self.display,
self.display, self.config_id,
self.config_id, window,
window, self.surface_attributes.as_ptr(),
self.surface_attributes.as_ptr(), ),
)
}
_ => return Err(CreationError::NonMatchingSurfaceType), _ => return Err(CreationError::NonMatchingSurfaceType),
}; };
@ -654,10 +655,9 @@ impl<'a> EGLSurface<'a> {
/// Swaps buffers at the end of a frame. /// Swaps buffers at the end of a frame.
pub fn swap_buffers(&self) -> Result<(), SwapBuffersError> { pub fn swap_buffers(&self) -> Result<(), SwapBuffersError> {
let ret = unsafe { let ret = unsafe {
self.context.egl.SwapBuffers( self.context
self.context.display as *const _, .egl
self.surface as *const _, .SwapBuffers(self.context.display as *const _, self.surface as *const _)
)
}; };
if ret == 0 { if ret == 0 {
@ -705,10 +705,8 @@ impl Drop for EGLContext {
unsafe { unsafe {
// we don't call MakeCurrent(0, 0) because we are not sure that the context // we don't call MakeCurrent(0, 0) because we are not sure that the context
// is still the current one // is still the current one
self.egl.DestroyContext( self.egl
self.display as *const _, .DestroyContext(self.display as *const _, self.context as *const _);
self.context as *const _,
);
self.egl.Terminate(self.display as *const _); self.egl.Terminate(self.display as *const _);
} }
} }
@ -717,10 +715,9 @@ impl Drop for EGLContext {
impl<'a> Drop for EGLSurface<'a> { impl<'a> Drop for EGLSurface<'a> {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
self.context.egl.DestroySurface( self.context
self.context.display as *const _, .egl
self.surface as *const _, .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 { fn amount(&self) -> f64 {
match self.source() { match self.source() {
backend::AxisSource::Finger | backend::AxisSource::Finger | backend::AxisSource::Continuous => self.event.axis_value(self.axis),
backend::AxisSource::Continuous => self.event.axis_value(self.axis), backend::AxisSource::Wheel | backend::AxisSource::WheelTilt => {
backend::AxisSource::Wheel | self.event.axis_value_discrete(self.axis).unwrap()
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>> { fn get_handler(&mut self) -> Option<&mut backend::InputHandler<Self>> {
self.handler.as_mut().map(|handler| { self.handler
handler as &mut backend::InputHandler<Self> .as_mut()
}) .map(|handler| handler as &mut backend::InputHandler<Self>)
} }
fn clear_handler(&mut self) { 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`. // update capabilities, so they appear correctly on `on_seat_changed` and `on_seat_destroyed`.
if let Some(seat) = self.seats.get_mut(&device_seat) { if let Some(seat) = self.seats.get_mut(&device_seat) {
let caps = seat.capabilities_mut(); let caps = seat.capabilities_mut();
caps.pointer = caps.pointer = self.devices
self.devices .iter()
.iter() .filter(|x| x.seat() == device_seat)
.filter(|x| x.seat() == device_seat) .any(|x| x.has_capability(libinput::DeviceCapability::Pointer));
.any(|x| x.has_capability(libinput::DeviceCapability::Pointer)); caps.keyboard = self.devices
caps.keyboard = .iter()
self.devices .filter(|x| x.seat() == device_seat)
.iter() .any(|x| x.has_capability(libinput::DeviceCapability::Keyboard));
.filter(|x| x.seat() == device_seat) caps.touch = self.devices
.any(|x| x.has_capability(libinput::DeviceCapability::Keyboard)); .iter()
caps.touch = .filter(|x| x.seat() == device_seat)
self.devices .any(|x| x.has_capability(libinput::DeviceCapability::Touch));
.iter()
.filter(|x| x.seat() == device_seat)
.any(|x| x.has_capability(libinput::DeviceCapability::Touch));
} else { } else {
panic!("Seat changed that was never created") panic!("Seat changed that was never created")
} }
@ -395,9 +392,9 @@ impl backend::InputBackend for LibinputInputBackend {
use input::event::touch::*; use input::event::touch::*;
if let Some(ref mut handler) = self.handler { if let Some(ref mut handler) = self.handler {
let device_seat = touch_event.device().seat(); let device_seat = touch_event.device().seat();
let seat = &self.seats.get(&device_seat).expect( let seat = &self.seats
"Recieved touch event of non existing Seat", .get(&device_seat)
); .expect("Recieved touch event of non existing Seat");
match touch_event { match touch_event {
TouchEvent::Down(down_event) => { TouchEvent::Down(down_event) => {
trace!(self.logger, "Calling on_touch_down with {:?}", 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) => { libinput::Event::Keyboard(keyboard_event) => {
use input::event::keyboard::*; use input::event::keyboard::*;
match keyboard_event { match keyboard_event {
KeyboardEvent::Key(key_event) => { KeyboardEvent::Key(key_event) => if let Some(ref mut handler) = self.handler {
if let Some(ref mut handler) = self.handler { let device_seat = key_event.device().seat();
let device_seat = key_event.device().seat(); let seat = &self.seats
let seat = &self.seats.get(&device_seat).expect( .get(&device_seat)
"Recieved key event of non existing Seat", .expect("Recieved key event of non existing Seat");
); trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event);
trace!(self.logger, "Calling on_keyboard_key with {:?}", key_event); handler.on_keyboard_key(seat, key_event);
handler.on_keyboard_key(seat, key_event); },
}
}
} }
} }
libinput::Event::Pointer(pointer_event) => { libinput::Event::Pointer(pointer_event) => {
use input::event::pointer::*; use input::event::pointer::*;
if let Some(ref mut handler) = self.handler { if let Some(ref mut handler) = self.handler {
let device_seat = pointer_event.device().seat(); let device_seat = pointer_event.device().seat();
let seat = &self.seats.get(&device_seat).expect( let seat = &self.seats
"Recieved pointer event of non existing Seat", .get(&device_seat)
); .expect("Recieved pointer event of non existing Seat");
match pointer_event { match pointer_event {
PointerEvent::Motion(motion_event) => { PointerEvent::Motion(motion_event) => {
trace!( trace!(

View File

@ -214,9 +214,9 @@ impl EGLGraphicsBackend for WinitGraphicsBackend {
} }
fn get_framebuffer_dimensions(&self) -> (u32, u32) { fn get_framebuffer_dimensions(&self) -> (u32, u32) {
self.window.get_inner_size_pixels().expect( self.window
"Window does not exist anymore", .get_inner_size_pixels()
) .expect("Window does not exist anymore")
} }
fn is_current(&self) -> bool { fn is_current(&self) -> bool {
@ -310,14 +310,16 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
fn x_transformed(&self, width: u32) -> u32 { fn x_transformed(&self, width: u32) -> u32 {
cmp::min( 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, 0,
) )
} }
fn y_transformed(&self, height: u32) -> u32 { fn y_transformed(&self, height: u32) -> u32 {
cmp::min( 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, 0,
) )
} }
@ -529,9 +531,9 @@ impl InputBackend for WinitInputBackend {
} }
fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> { fn get_handler(&mut self) -> Option<&mut InputHandler<Self>> {
self.handler.as_mut().map(|handler| { self.handler
handler as &mut InputHandler<Self> .as_mut()
}) .map(|handler| handler as &mut InputHandler<Self>)
} }
fn clear_handler(&mut 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); wl_egl_surface.resize(x as i32, y as i32, 0, 0);
} }
} }
(WindowEvent::KeyboardInput { (
input: KeyboardInput { scancode, state, .. }, .. WindowEvent::KeyboardInput {
}, input: KeyboardInput {
Some(handler)) => { scancode, state, ..
},
..
},
Some(handler),
) => {
match state { match state {
ElementState::Pressed => *key_counter += 1, ElementState::Pressed => *key_counter += 1,
ElementState::Released => { 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)); trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y));
handler.on_pointer_move_absolute( handler.on_pointer_move_absolute(
seat, seat,
@ -627,39 +639,36 @@ impl InputBackend for WinitInputBackend {
}, },
) )
} }
(WindowEvent::MouseWheel { delta, .. }, Some(handler)) => { (WindowEvent::MouseWheel { delta, .. }, Some(handler)) => match delta {
match delta { MouseScrollDelta::LineDelta(x, y) | MouseScrollDelta::PixelDelta(x, y) => {
MouseScrollDelta::LineDelta(x, y) | if x != 0.0 {
MouseScrollDelta::PixelDelta(x, y) => { let event = WinitMouseWheelEvent {
if x != 0.0 { axis: Axis::Horizontal,
let event = WinitMouseWheelEvent { time: *time_counter,
axis: Axis::Horizontal, delta: delta,
time: *time_counter, };
delta: delta, trace!(
}; logger,
trace!( "Calling on_pointer_axis for Axis::Horizontal with {:?}",
logger, x
"Calling on_pointer_axis for Axis::Horizontal with {:?}", );
x handler.on_pointer_axis(seat, event);
); }
handler.on_pointer_axis(seat, event); if y != 0.0 {
} let event = WinitMouseWheelEvent {
if y != 0.0 { axis: Axis::Vertical,
let event = WinitMouseWheelEvent { time: *time_counter,
axis: Axis::Vertical, delta: delta,
time: *time_counter, };
delta: delta, trace!(
}; logger,
trace!( "Calling on_pointer_axis for Axis::Vertical with {:?}",
logger, y
"Calling on_pointer_axis for Axis::Vertical with {:?}", );
y handler.on_pointer_axis(seat, event);
);
handler.on_pointer_axis(seat, event);
}
} }
} }
} },
(WindowEvent::MouseInput { state, button, .. }, Some(handler)) => { (WindowEvent::MouseInput { state, button, .. }, Some(handler)) => {
trace!( trace!(
logger, logger,
@ -675,13 +684,15 @@ impl InputBackend for WinitInputBackend {
}, },
) )
} }
(WindowEvent::Touch(Touch { (
phase: TouchPhase::Started, WindowEvent::Touch(Touch {
location: (x, y), phase: TouchPhase::Started,
id, location: (x, y),
.. id,
}), ..
Some(handler)) => { }),
Some(handler),
) => {
trace!(logger, "Calling on_touch_down at {:?}", (x, y)); trace!(logger, "Calling on_touch_down at {:?}", (x, y));
handler.on_touch_down( handler.on_touch_down(
seat, seat,
@ -693,13 +704,15 @@ impl InputBackend for WinitInputBackend {
}, },
) )
} }
(WindowEvent::Touch(Touch { (
phase: TouchPhase::Moved, WindowEvent::Touch(Touch {
location: (x, y), phase: TouchPhase::Moved,
id, location: (x, y),
.. id,
}), ..
Some(handler)) => { }),
Some(handler),
) => {
trace!(logger, "Calling on_touch_motion at {:?}", (x, y)); trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
handler.on_touch_motion( handler.on_touch_motion(
seat, seat,
@ -711,13 +724,15 @@ impl InputBackend for WinitInputBackend {
}, },
) )
} }
(WindowEvent::Touch(Touch { (
phase: TouchPhase::Ended, WindowEvent::Touch(Touch {
location: (x, y), phase: TouchPhase::Ended,
id, location: (x, y),
.. id,
}), ..
Some(handler)) => { }),
Some(handler),
) => {
trace!(logger, "Calling on_touch_motion at {:?}", (x, y)); trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
handler.on_touch_motion( handler.on_touch_motion(
seat, seat,
@ -737,12 +752,14 @@ impl InputBackend for WinitInputBackend {
}, },
); );
} }
(WindowEvent::Touch(Touch { (
phase: TouchPhase::Cancelled, WindowEvent::Touch(Touch {
id, phase: TouchPhase::Cancelled,
.. id,
}), ..
Some(handler)) => { }),
Some(handler),
) => {
trace!(logger, "Calling on_touch_cancel"); trace!(logger, "Calling on_touch_cancel");
handler.on_touch_cancel( handler.on_touch_cancel(
seat, 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> impl<U, R, H> GlobalHandler<wl_compositor::WlCompositor> for CompositorHandler<U, R, H>
where where
U: Default U: Default + Send + 'static,
+ Send R: Default + Send + 'static,
+ 'static, H: UserHandler<U, R> + Send + 'static,
R: Default
+ Send
+ 'static,
H: UserHandler<U, R>
+ Send
+ 'static,
{ {
fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) { fn bind(&mut self, evlh: &mut EventLoopHandle, _: &Client, global: wl_compositor::WlCompositor) {
debug!(self.log, "New compositor global binded."); 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> impl<U, R, H> wl_subcompositor::Handler for CompositorHandler<U, R, H>
where where
U: Send + 'static, U: Send + 'static,
R: RoleType R: RoleType + Role<SubsurfaceRole> + Send + 'static,
+ Role<SubsurfaceRole>
+ Send
+ 'static,
H: Send + 'static, H: Send + 'static,
{ {
fn get_subsurface(&mut self, evqh: &mut EventLoopHandle, _: &Client, fn get_subsurface(&mut self, evqh: &mut EventLoopHandle, _: &Client,
@ -210,9 +207,9 @@ where
); );
return; return;
} }
id.set_user_data(Box::into_raw( id.set_user_data(
Box::new(unsafe { surface.clone_unchecked() }), Box::into_raw(Box::new(unsafe { surface.clone_unchecked() })) as *mut _,
) as *mut _); );
evqh.register_with_destructor::<_, CompositorHandler<U, R, H>, CompositorDestructor<U, R>>( evqh.register_with_destructor::<_, CompositorHandler<U, R, H>, CompositorDestructor<U, R>>(
&id, &id,
self.my_id, self.my_id,
@ -259,7 +256,10 @@ where
let ptr = subsurface.get_user_data(); let ptr = subsurface.get_user_data();
let surface = &*(ptr as *mut wl_surface::WlSurface); let surface = &*(ptr as *mut wl_surface::WlSurface);
if let Err(()) = SurfaceData::<U, R>::reorder(surface, Location::After, sibling) { 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 ptr = subsurface.get_user_data();
let surface = &*(ptr as *mut wl_surface::WlSurface); let surface = &*(ptr as *mut wl_surface::WlSurface);
if let Err(()) = SurfaceData::<U, R>::reorder(surface, Location::Before, sibling) { 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); 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> 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) { fn destroy(subsurface: &wl_subsurface::WlSubsurface) {
let ptr = subsurface.get_user_data(); let ptr = subsurface.get_user_data();

View File

@ -107,7 +107,7 @@ use self::region::RegionData;
use self::roles::{Role, RoleType, WrongRole}; use self::roles::{Role, RoleType, WrongRole};
use self::tree::SurfaceData; use self::tree::SurfaceData;
pub use self::tree::TraversalAction; 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}; 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 /// - 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. /// 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). /// 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<(), ()> pub fn with_surface_tree<F, T>(&self, surface: &wl_surface::WlSurface, initial: T, f: F) -> Result<(), ()>
where where
F: FnMut(&wl_surface::WlSurface, F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
&mut SurfaceAttributes<U>,
&mut R,
&T)
-> TraversalAction<T>, -> TraversalAction<T>,
{ {
assert!( 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 /// If the surface is not managed by the CompositorGlobal that provided this token, this
/// will panic (having more than one compositor is not supported). /// 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 where
R: Role<RoleData>, R: Role<RoleData>,
F: FnOnce(&mut RoleData) -> T F: FnOnce(&mut RoleData) -> T,
{ {
assert!( assert!(
resource_is_registered::<_, CompositorHandler<U, R, H>>(surface, self.hid), resource_is_registered::<_, CompositorHandler<U, R, H>>(surface, self.hid),

View File

@ -13,9 +13,9 @@ pub struct RegionData {
impl RegionData { impl RegionData {
/// Initialize the user_data of a region, must be called right when the surface is created /// Initialize the user_data of a region, must be called right when the surface is created
pub unsafe fn init(region: &wl_region::WlRegion) { pub unsafe fn init(region: &wl_region::WlRegion) {
region.set_user_data(Box::into_raw( region.set_user_data(
Box::new(Mutex::new(RegionData::default())), Box::into_raw(Box::new(Mutex::new(RegionData::default()))) as *mut _,
) as *mut _) )
} }
/// Cleans the user_data of that surface, must be called when it is destroyed /// 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 /// Initialize the user_data of a surface, must be called right when the surface is created
pub unsafe fn init(surface: &wl_surface::WlSurface) { pub unsafe fn init(surface: &wl_surface::WlSurface) {
surface.set_user_data(Box::into_raw( surface.set_user_data(
Box::new(Mutex::new(SurfaceData::<U, R>::new())), Box::into_raw(Box::new(Mutex::new(SurfaceData::<U, R>::new()))) as *mut _,
) as *mut _) )
} }
} }
@ -315,21 +315,15 @@ impl<U, R> SurfaceData<U, R> {
/// false will cause an early-stopping. /// false will cause an early-stopping.
pub unsafe fn map_tree<F, T>(root: &wl_surface::WlSurface, initial: T, mut f: F) pub unsafe fn map_tree<F, T>(root: &wl_surface::WlSurface, initial: T, mut f: F)
where where
F: FnMut(&wl_surface::WlSurface, F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
&mut SurfaceAttributes<U>,
&mut R,
&T)
-> TraversalAction<T>, -> TraversalAction<T>,
{ {
// helper function for recursion // helper function for recursion
unsafe fn map<U, R, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface, initial: &T, unsafe fn map<U, R, F, T>(surface: &wl_surface::WlSurface, root: &wl_surface::WlSurface,
f: &mut F) initial: &T, f: &mut F)
-> bool -> bool
where where
F: FnMut(&wl_surface::WlSurface, F: FnMut(&wl_surface::WlSurface, &mut SurfaceAttributes<U>, &mut R, &T)
&mut SurfaceAttributes<U>,
&mut R,
&T)
-> TraversalAction<T>, -> TraversalAction<T>,
{ {
// stop if we met the root, so to not deadlock/inifinte loop // 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; use xkbcommon::xkb;
pub use xkbcommon::xkb::{Keysym, keysyms}; pub use xkbcommon::xkb::{keysyms, Keysym};
/// Represents the current state of the keyboard modifiers /// Represents the current state of the keyboard modifiers
/// ///
@ -178,19 +178,18 @@ where
"rules" => rules, "model" => model, "layout" => layout, "variant" => variant, "rules" => rules, "model" => model, "layout" => layout, "variant" => variant,
"options" => &options "options" => &options
); );
let internal = KbdInternal::new(rules, model, layout, variant, options) let internal = KbdInternal::new(rules, model, layout, variant, options).map_err(|_| {
.map_err(|_| { debug!(log, "Loading keymap failed");
debug!(log, "Loading keymap failed"); Error::BadKeymap
Error::BadKeymap })?;
})?;
// prepare a tempfile with the keymap, to send it to clients // prepare a tempfile with the keymap, to send it to clients
let mut keymap_file = tempfile().map_err(Error::IoError)?; let mut keymap_file = tempfile().map_err(Error::IoError)?;
let keymap_data = internal.keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1); let keymap_data = internal.keymap.get_as_string(xkb::KEYMAP_FORMAT_TEXT_V1);
keymap_file.write_all(keymap_data.as_bytes()).map_err( keymap_file
Error::IoError, .write_all(keymap_data.as_bytes())
)?; .map_err(Error::IoError)?;
keymap_file.flush().map_err(Error::IoError)?; keymap_file.flush().map_err(Error::IoError)?;
trace!(log, "Keymap loaded and copied to tempfile."; 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::os::unix::io::RawFd;
use std::sync::Arc; 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}; use wayland_server::protocol::{wl_buffer, wl_shm, wl_shm_pool};
mod pool; mod pool;
@ -111,7 +111,9 @@ impl ShmGlobal {
/// ///
/// This is needed to retrieve the contents of the shm pools and buffers. /// This is needed to retrieve the contents of the shm pools and buffers.
pub fn get_token(&self) -> ShmToken { 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()) { let mmap_pool = match Pool::new(fd, size as usize, self.log.clone()) {
Ok(p) => p, Ok(p) => p,
Err(()) => { Err(()) => {
shm.post_error(wl_shm::Error::InvalidFd as u32, format!("Failed mmap of fd {}.", fd)); shm.post_error(
return wl_shm::Error::InvalidFd as u32,
format!("Failed mmap of fd {}.", fd),
);
return;
} }
}; };
let arc_pool = Box::new(Arc::new(mmap_pool)); 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::cell::Cell;
use std::os::unix::io::RawFd; use std::os::unix::io::RawFd;
use std::ptr; 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))); thread_local!(static SIGBUS_GUARD: Cell<(*const MemMap, bool)> = Cell::new((ptr::null_mut(), false)));