Silence example warnings.

This commit is contained in:
Victor Berger 2017-09-06 16:33:35 +02:00
parent 3171160cff
commit eeb6373ded
2 changed files with 62 additions and 57 deletions

View File

@ -8,7 +8,6 @@ extern crate slog_term;
#[macro_use(define_roles)] #[macro_use(define_roles)]
extern crate smithay; extern crate smithay;
extern crate wayland_protocols; extern crate wayland_protocols;
#[macro_use(server_declare_handler)]
extern crate wayland_server; extern crate wayland_server;
mod helpers; mod helpers;
@ -25,11 +24,11 @@ use smithay::compositor::{self, CompositorHandler, CompositorToken, SubsurfaceRo
use smithay::compositor::roles::Role; use smithay::compositor::roles::Role;
use smithay::shell::{self, PopupConfigure, PopupSurface, ShellClient, ShellHandler, ShellSurfaceRole, use smithay::shell::{self, PopupConfigure, PopupSurface, ShellClient, ShellHandler, ShellSurfaceRole,
ToplevelConfigure, ToplevelSurface}; ToplevelConfigure, ToplevelSurface};
use smithay::shm::{BufferData, ShmGlobal, ShmToken}; use smithay::shm::{ShmGlobal, ShmToken};
use wayland_protocols::unstable::xdg_shell::server::{zxdg_shell_v6, zxdg_toplevel_v6}; use wayland_protocols::unstable::xdg_shell::server::{zxdg_shell_v6, zxdg_toplevel_v6};
use wayland_server::{Client, EventLoopHandle, Liveness, Resource}; use wayland_server::{Client, EventLoopHandle};
use wayland_server::protocol::{wl_compositor, wl_output, wl_seat, wl_shell, wl_shm, wl_subcompositor, use wayland_server::protocol::{wl_compositor, wl_output, wl_seat, wl_shell, wl_shm, wl_subcompositor,
wl_surface}; wl_surface};
@ -46,13 +45,15 @@ struct SurfaceData {
} }
impl compositor::Handler<SurfaceData, Roles> for SurfaceHandler { impl compositor::Handler<SurfaceData, Roles> for SurfaceHandler {
fn commit(&mut self, evlh: &mut EventLoopHandle, client: &Client, surface: &wl_surface::WlSurface, fn commit(&mut self, _evlh: &mut EventLoopHandle, _client: &Client, surface: &wl_surface::WlSurface,
token: CompositorToken<SurfaceData, Roles, SurfaceHandler>) { token: CompositorToken<SurfaceData, Roles, SurfaceHandler>) {
// we retrieve the contents of the associated buffer and copy it // we retrieve the contents of the associated buffer and copy it
token.with_surface_data(surface, |attributes| { token.with_surface_data(surface, |attributes| {
match attributes.buffer.take() { match attributes.buffer.take() {
Some(Some((buffer, (x, y)))) => { Some(Some((buffer, (_x, _y)))) => {
self.shm_token.with_buffer_contents(&buffer, |slice, data| { // we ignore hotspot coordinates in this simple example
self.shm_token
.with_buffer_contents(&buffer, |slice, data| {
let offset = data.offset as usize; let offset = data.offset as usize;
let stride = data.stride as usize; let stride = data.stride as usize;
let width = data.width as usize; let width = data.width as usize;
@ -65,7 +66,8 @@ 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)));
}); })
.unwrap();
} }
Some(None) => { Some(None) => {
// erase the contents // erase the contents
@ -88,9 +90,9 @@ impl ShellSurfaceHandler {
} }
impl shell::Handler<SurfaceData, Roles, SurfaceHandler, ()> for ShellSurfaceHandler { impl shell::Handler<SurfaceData, Roles, SurfaceHandler, ()> for ShellSurfaceHandler {
fn new_client(&mut self, evlh: &mut EventLoopHandle, client: ShellClient<()>) {} fn new_client(&mut self, _evlh: &mut EventLoopHandle, _client: ShellClient<()>) {}
fn client_pong(&mut self, evlh: &mut EventLoopHandle, client: ShellClient<()>) {} fn client_pong(&mut self, _evlh: &mut EventLoopHandle, _client: ShellClient<()>) {}
fn new_toplevel(&mut self, evlh: &mut EventLoopHandle, fn new_toplevel(&mut self, _evlh: &mut EventLoopHandle,
surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>) surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>)
-> ToplevelConfigure { -> ToplevelConfigure {
let wl_surface = surface.get_surface().unwrap(); let wl_surface = surface.get_surface().unwrap();
@ -109,8 +111,8 @@ impl shell::Handler<SurfaceData, Roles, SurfaceHandler, ()> for ShellSurfaceHand
serial: 42, serial: 42,
} }
} }
fn new_popup(&mut self, evlh: &mut EventLoopHandle, fn new_popup(&mut self, _evlh: &mut EventLoopHandle,
surface: PopupSurface<SurfaceData, Roles, SurfaceHandler, ()>) _surface: PopupSurface<SurfaceData, Roles, SurfaceHandler, ()>)
-> PopupConfigure { -> PopupConfigure {
PopupConfigure { PopupConfigure {
size: (10, 10), size: (10, 10),
@ -118,22 +120,22 @@ impl shell::Handler<SurfaceData, Roles, SurfaceHandler, ()> for ShellSurfaceHand
serial: 42, serial: 42,
} }
} }
fn move_(&mut self, evlh: &mut EventLoopHandle, fn move_(&mut self, _evlh: &mut EventLoopHandle,
surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, seat: &wl_seat::WlSeat, _surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, _seat: &wl_seat::WlSeat,
serial: u32) { _serial: u32) {
} }
fn resize(&mut self, evlh: &mut EventLoopHandle, fn resize(&mut self, _evlh: &mut EventLoopHandle,
surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, seat: &wl_seat::WlSeat, _surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, _seat: &wl_seat::WlSeat,
serial: u32, edges: zxdg_toplevel_v6::ResizeEdge) { _serial: u32, _edges: zxdg_toplevel_v6::ResizeEdge) {
} }
fn grab(&mut self, evlh: &mut EventLoopHandle, fn grab(&mut self, _evlh: &mut EventLoopHandle,
surface: PopupSurface<SurfaceData, Roles, SurfaceHandler, ()>, seat: &wl_seat::WlSeat, _surface: PopupSurface<SurfaceData, Roles, SurfaceHandler, ()>, _seat: &wl_seat::WlSeat,
serial: u32) { _serial: u32) {
} }
fn change_display_state(&mut self, evlh: &mut EventLoopHandle, fn change_display_state(&mut self, _evlh: &mut EventLoopHandle,
surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, _surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>,
maximized: Option<bool>, minimized: Option<bool>, fullscreen: Option<bool>, _maximized: Option<bool>, _minimized: Option<bool>, _fullscreen: Option<bool>,
output: Option<&wl_output::WlOutput>) _output: Option<&wl_output::WlOutput>)
-> ToplevelConfigure { -> ToplevelConfigure {
ToplevelConfigure { ToplevelConfigure {
size: None, size: None,
@ -141,9 +143,9 @@ impl shell::Handler<SurfaceData, Roles, SurfaceHandler, ()> for ShellSurfaceHand
serial: 42, serial: 42,
} }
} }
fn show_window_menu(&mut self, evlh: &mut EventLoopHandle, fn show_window_menu(&mut self, _evlh: &mut EventLoopHandle,
surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>, _surface: ToplevelSurface<SurfaceData, Roles, SurfaceHandler, ()>,
seat: &wl_seat::WlSeat, serial: u32, x: i32, y: i32) { _seat: &wl_seat::WlSeat, _serial: u32, _x: i32, _y: i32) {
} }
} }
@ -240,10 +242,11 @@ fn main() {
// 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
let initial_place = compositor_token let initial_place = compositor_token
.with_surface_data(wl_surface, |data| data.user_data.location.unwrap_or((0, 0))); .with_surface_data(wl_surface, |data| data.user_data.location.unwrap_or((0, 0)));
compositor_token.with_surface_tree( compositor_token
.with_surface_tree(
wl_surface, wl_surface,
initial_place, initial_place,
|surface, attributes, role, &(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) {
@ -257,7 +260,8 @@ fn main() {
TraversalAction::SkipChildren TraversalAction::SkipChildren
} }
}, },
); )
.unwrap();
} }
} }
} }

View File

@ -127,6 +127,7 @@ pub struct ShmToken {
} }
/// Error that can occur when accessing an SHM buffer /// Error that can occur when accessing an SHM buffer
#[derive(Debug)]
pub enum BufferAccessError { pub enum BufferAccessError {
/// This buffer is not managed by the SHM handler /// This buffer is not managed by the SHM handler
NotManaged, NotManaged,