fix some clippy warnings (#147)

This commit removes some clippy warnings (to advance #45) by doing the following:
- replace usage of `mem::uninitialized()` with `MaybeUninit`
- replace usage of `nix::libc::{uint64_t, int32_t}` with `{u64, i32}`
- replace functions inside of `Option::ok_or` with `Option::ok_or_else`
- replace functions inside of `Result::unwrap_or` with `Result::unwrap_or_else`
- replace occurrences of pass-by-reference with pass-by-value when
  appropriate
- replace unused variables in pattern-matching with wildcards
- replace `match` expressions that have only one case with `if let`
  expressions
- replace UpperCamelCase names of consts with SCREAMING_SNAKE_CASE
- remove `clone()` on types that implement Copy
- remove redundant imports
- remove `fn main()` from doctests
- remove let binding for variables that are returned afterwards
This commit is contained in:
nycex 2020-01-01 11:43:16 +01:00 committed by Victor Berger
parent 834f3d2e65
commit 0140de89fb
30 changed files with 118 additions and 135 deletions

View File

@ -1,7 +1,7 @@
use std::env::var; use std::env::var;
fn main() { fn main() {
if !var("CARGO_FEATURE_LOGIND").ok().is_some() { if var("CARGO_FEATURE_LOGIND").ok().is_none() {
println!("cargo:warning=You are compiling anvil without logind support."); println!("cargo:warning=You are compiling anvil without logind support.");
println!("cargo:warning=This means that you'll likely need to run it as root if you want to launch it from a tty."); println!("cargo:warning=This means that you'll likely need to run it as root if you want to launch it from a tty.");
println!("cargo:warning=To enable logind support add `--feature logind` to your cargo invocation:"); println!("cargo:warning=To enable logind support add `--feature logind` to your cargo invocation:");

View File

@ -113,7 +113,7 @@ impl<B: InputBackend> InputHandler<B> for AnvilInputHandler {
"mods" => format!("{:?}", modifiers), "mods" => format!("{:?}", modifiers),
"keysym" => ::xkbcommon::xkb::keysym_get_name(keysym) "keysym" => ::xkbcommon::xkb::keysym_get_name(keysym)
); );
action = process_keyboard_shortcut(modifiers, keysym); action = process_keyboard_shortcut(*modifiers, keysym);
// forward to client only if action == KeyAction::Forward // forward to client only if action == KeyAction::Forward
// both for pressed and released, to avoid inconsistencies // both for pressed and released, to avoid inconsistencies
if let KeyAction::Forward = action { if let KeyAction::Forward = action {
@ -229,13 +229,13 @@ impl<B: InputBackend> InputHandler<B> for AnvilInputHandler {
input::AxisSource::Wheel | input::AxisSource::WheelTilt => wl_pointer::AxisSource::Wheel, input::AxisSource::Wheel | input::AxisSource::WheelTilt => wl_pointer::AxisSource::Wheel,
}; };
let horizontal_amount = evt let horizontal_amount = evt
.amount(&input::Axis::Horizontal) .amount(input::Axis::Horizontal)
.unwrap_or_else(|| evt.amount_discrete(&input::Axis::Horizontal).unwrap() * 3.0); .unwrap_or_else(|| evt.amount_discrete(input::Axis::Horizontal).unwrap() * 3.0);
let vertical_amount = evt let vertical_amount = evt
.amount(&input::Axis::Vertical) .amount(input::Axis::Vertical)
.unwrap_or_else(|| evt.amount_discrete(&input::Axis::Vertical).unwrap() * 3.0); .unwrap_or_else(|| evt.amount_discrete(input::Axis::Vertical).unwrap() * 3.0);
let horizontal_amount_discrete = evt.amount_discrete(&input::Axis::Horizontal); let horizontal_amount_discrete = evt.amount_discrete(input::Axis::Horizontal);
let vertical_amount_discrete = evt.amount_discrete(&input::Axis::Vertical); let vertical_amount_discrete = evt.amount_discrete(input::Axis::Vertical);
{ {
let mut frame = AxisFrame::new(evt.time()).source(source); let mut frame = AxisFrame::new(evt.time()).source(source);
@ -293,7 +293,7 @@ enum KeyAction {
None, None,
} }
fn process_keyboard_shortcut(modifiers: &ModifiersState, keysym: Keysym) -> KeyAction { fn process_keyboard_shortcut(modifiers: ModifiersState, keysym: Keysym) -> KeyAction {
if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_BackSpace if modifiers.ctrl && modifiers.alt && keysym == xkb::KEY_BackSpace
|| modifiers.logo && keysym == xkb::KEY_q || modifiers.logo && keysym == xkb::KEY_q
{ {

View File

@ -22,7 +22,7 @@ mod window_map;
#[cfg(feature = "winit")] #[cfg(feature = "winit")]
mod winit; mod winit;
static POSSIBLE_BACKENDS: &'static [&'static str] = &[ static POSSIBLE_BACKENDS: &[&str] = &[
#[cfg(feature = "winit")] #[cfg(feature = "winit")]
"--winit : Run anvil as a X11 or Wayland client using winit.", "--winit : Run anvil as a X11 or Wayland client using winit.",
#[cfg(feature = "udev")] #[cfg(feature = "udev")]

View File

@ -137,7 +137,7 @@ pub struct SurfaceData {
fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken<Roles>) { fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken<Roles>) {
// 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| {
attributes.user_data.insert_if_missing(|| SurfaceData::default()); attributes.user_data.insert_if_missing(SurfaceData::default);
match attributes.buffer.take() { match attributes.buffer.take() {
Some(Some((buffer, (_x, _y)))) => { Some(Some((buffer, (_x, _y)))) => {
// new contents // new contents

View File

@ -156,7 +156,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger
_ => {} _ => {}
}, },
default_action_chooser, default_action_chooser,
compositor_token.clone(), compositor_token,
log.clone(), log.clone(),
); );
@ -166,7 +166,7 @@ pub fn run_udev(mut display: Display, mut event_loop: EventLoop<()>, log: Logger
let (mut w_seat, _) = Seat::new( let (mut w_seat, _) = Seat::new(
&mut display.borrow_mut(), &mut display.borrow_mut(),
session.seat(), session.seat(),
compositor_token.clone(), compositor_token,
log.clone(), log.clone(),
); );

View File

@ -61,7 +61,7 @@ where
// need to check more carefully // need to check more carefully
let found = RefCell::new(None); let found = RefCell::new(None);
if let Some(wl_surface) = self.toplevel.get_surface() { if let Some(wl_surface) = self.toplevel.get_surface() {
let _ = ctoken.with_surface_tree_downward( ctoken.with_surface_tree_downward(
wl_surface, wl_surface,
self.location, self.location,
|wl_surface, attributes, role, &(mut x, mut y)| { |wl_surface, attributes, role, &(mut x, mut y)| {
@ -102,7 +102,7 @@ where
let (base_x, base_y) = self.location; let (base_x, base_y) = self.location;
let (mut min_x, mut min_y, mut max_x, mut max_y) = (base_x, base_y, base_x, base_y); let (mut min_x, mut min_y, mut max_x, mut max_y) = (base_x, base_y, base_x, base_y);
if let Some(wl_surface) = self.toplevel.get_surface() { if let Some(wl_surface) = self.toplevel.get_surface() {
let _ = ctoken.with_surface_tree_downward( ctoken.with_surface_tree_downward(
wl_surface, wl_surface,
(base_x, base_y), (base_x, base_y),
|_, attributes, role, &(mut x, mut y)| { |_, attributes, role, &(mut x, mut y)| {

View File

@ -75,11 +75,11 @@ pub fn run_winit(display: &mut Display, event_loop: &mut EventLoop<()>, log: Log
_ => {} _ => {}
}, },
default_action_chooser, default_action_chooser,
compositor_token.clone(), compositor_token,
log.clone(), log.clone(),
); );
let (mut seat, _) = Seat::new(display, "winit".into(), compositor_token.clone(), log.clone()); let (mut seat, _) = Seat::new(display, "winit".into(), compositor_token, log.clone());
let cursor_status = Arc::new(Mutex::new(CursorImageStatus::Default)); let cursor_status = Arc::new(Mutex::new(CursorImageStatus::Default));

View File

@ -78,11 +78,11 @@ impl<A: AsRawFd + 'static> Surface for LegacyDrmSurfaceInternal<A> {
} }
fn current_mode(&self) -> Option<Mode> { fn current_mode(&self) -> Option<Mode> {
self.state.read().unwrap().mode.clone() self.state.read().unwrap().mode
} }
fn pending_mode(&self) -> Option<Mode> { fn pending_mode(&self) -> Option<Mode> {
self.pending.read().unwrap().mode.clone() self.pending.read().unwrap().mode
} }
fn add_connector(&self, connector: connector::Handle) -> Result<()> { fn add_connector(&self, connector: connector::Handle) -> Result<()> {
@ -135,13 +135,11 @@ impl<A: AsRawFd + 'static> Surface for LegacyDrmSurfaceInternal<A> {
// check the connectors to see if this mode is supported // check the connectors to see if this mode is supported
if let Some(mode) = mode { if let Some(mode) = mode {
for connector in &pending.connectors { for connector in &pending.connectors {
if !connector::Info::load_from_device(self, *connector) let info = connector::Info::load_from_device(self, *connector).chain_err(|| {
.chain_err(|| {
ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path())) ErrorKind::DrmDev(format!("Error loading connector info on {:?}", self.dev_path()))
})? })?;
.modes()
.contains(&mode) if !info.modes().contains(&mode) {
{
bail!(ErrorKind::ModeNotSuitable(mode)); bail!(ErrorKind::ModeNotSuitable(mode));
} }
} }

View File

@ -8,7 +8,8 @@ use std::{
cell::{Ref, RefCell, RefMut}, cell::{Ref, RefCell, RefMut},
ffi::{CStr, CString}, ffi::{CStr, CString},
marker::PhantomData, marker::PhantomData,
mem, ptr, mem::MaybeUninit,
ptr,
rc::Rc, rc::Rc,
}; };
@ -149,12 +150,14 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLContext<B, N> {
} }
let egl_version = { let egl_version = {
let mut major: ffi::egl::types::EGLint = mem::uninitialized(); let mut major: MaybeUninit<ffi::egl::types::EGLint> = MaybeUninit::uninit();
let mut minor: ffi::egl::types::EGLint = mem::uninitialized(); let mut minor: MaybeUninit<ffi::egl::types::EGLint> = MaybeUninit::uninit();
if ffi::egl::Initialize(display, &mut major, &mut minor) == 0 { if ffi::egl::Initialize(display, major.as_mut_ptr(), minor.as_mut_ptr()) == 0 {
bail!(ErrorKind::InitFailed); bail!(ErrorKind::InitFailed);
} }
let major = major.assume_init();
let minor = minor.assume_init();
info!(log, "EGL Initialized"); info!(log, "EGL Initialized");
info!(log, "EGL Version: {:?}", (major, minor)); info!(log, "EGL Version: {:?}", (major, minor));
@ -294,11 +297,22 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLContext<B, N> {
}; };
// calling `eglChooseConfig` // calling `eglChooseConfig`
let mut config_id = mem::uninitialized(); let mut config_id = MaybeUninit::uninit();
let mut num_configs = mem::uninitialized(); let mut num_configs = MaybeUninit::uninit();
if ffi::egl::ChooseConfig(display, descriptor.as_ptr(), &mut config_id, 1, &mut num_configs) == 0 { if ffi::egl::ChooseConfig(
display,
descriptor.as_ptr(),
config_id.as_mut_ptr(),
1,
num_configs.as_mut_ptr(),
) == 0
{
bail!(ErrorKind::ConfigFailed); bail!(ErrorKind::ConfigFailed);
} }
let config_id = config_id.assume_init();
let num_configs = num_configs.assume_init();
if num_configs == 0 { if num_configs == 0 {
error!(log, "No matching color format found"); error!(log, "No matching color format found");
bail!(ErrorKind::NoAvailablePixelFormat); bail!(ErrorKind::NoAvailablePixelFormat);
@ -307,17 +321,17 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLContext<B, N> {
// analyzing each config // analyzing each config
macro_rules! attrib { macro_rules! attrib {
($display:expr, $config:expr, $attr:expr) => {{ ($display:expr, $config:expr, $attr:expr) => {{
let mut value = mem::uninitialized(); let mut value = MaybeUninit::uninit();
let res = ffi::egl::GetConfigAttrib( let res = ffi::egl::GetConfigAttrib(
$display, $display,
$config, $config,
$attr as ffi::egl::types::EGLint, $attr as ffi::egl::types::EGLint,
&mut value, value.as_mut_ptr(),
); );
if res == 0 { if res == 0 {
bail!(ErrorKind::ConfigFailed); bail!(ErrorKind::ConfigFailed);
} }
value value.assume_init()
}}; }};
}; };

View File

@ -1,11 +1,11 @@
#![allow(missing_docs)] #![allow(missing_docs)]
use nix::libc::{c_long, c_uint, c_void, int32_t, uint64_t}; use nix::libc::{c_long, c_uint, c_void};
pub type khronos_utime_nanoseconds_t = khronos_uint64_t; pub type khronos_utime_nanoseconds_t = khronos_uint64_t;
pub type khronos_uint64_t = uint64_t; pub type khronos_uint64_t = u64;
pub type khronos_ssize_t = c_long; pub type khronos_ssize_t = c_long;
pub type EGLint = int32_t; pub type EGLint = i32;
pub type EGLNativeDisplayType = NativeDisplayType; pub type EGLNativeDisplayType = NativeDisplayType;
pub type EGLNativePixmapType = NativePixmapType; pub type EGLNativePixmapType = NativePixmapType;
pub type EGLNativeWindowType = NativeWindowType; pub type EGLNativeWindowType = NativeWindowType;
@ -162,11 +162,11 @@ pub mod egl {
// Accepted in the <attrib_list> parameter of eglCreateImageKHR: // Accepted in the <attrib_list> parameter of eglCreateImageKHR:
pub const WAYLAND_PLANE_WL: c_uint = 0x31D6; pub const WAYLAND_PLANE_WL: c_uint = 0x31D6;
// Possible values for EGL_TEXTURE_FORMAT: // Possible values for EGL_TEXTURE_FORMAT:
pub const TEXTURE_Y_U_V_WL: int32_t = 0x31D7; pub const TEXTURE_Y_U_V_WL: i32 = 0x31D7;
pub const TEXTURE_Y_UV_WL: int32_t = 0x31D8; pub const TEXTURE_Y_UV_WL: i32 = 0x31D8;
pub const TEXTURE_Y_XUXV_WL: int32_t = 0x31D9; pub const TEXTURE_Y_XUXV_WL: i32 = 0x31D9;
pub const TEXTURE_EXTERNAL_WL: int32_t = 0x31DA; pub const TEXTURE_EXTERNAL_WL: i32 = 0x31DA;
// Accepted in the <attribute> parameter of eglQueryWaylandBufferWL: // Accepted in the <attribute> parameter of eglQueryWaylandBufferWL:
pub const EGL_TEXTURE_FORMAT: int32_t = 0x3080; pub const EGL_TEXTURE_FORMAT: i32 = 0x3080;
pub const WAYLAND_Y_INVERTED_WL: int32_t = 0x31DB; pub const WAYLAND_Y_INVERTED_WL: i32 = 0x31DB;
} }

View File

@ -122,13 +122,13 @@ unsafe impl NativeDisplay<X11> for WinitWindow {
fn ptr(&self) -> Result<ffi::NativeDisplayType> { fn ptr(&self) -> Result<ffi::NativeDisplayType> {
self.get_xlib_display() self.get_xlib_display()
.map(|ptr| ptr as *const _) .map(|ptr| ptr as *const _)
.ok_or(ErrorKind::NonMatchingBackend("X11").into()) .ok_or_else(|| ErrorKind::NonMatchingBackend("X11").into())
} }
fn create_surface(&mut self, _args: ()) -> Result<XlibWindow> { fn create_surface(&mut self, _args: ()) -> Result<XlibWindow> {
self.get_xlib_window() self.get_xlib_window()
.map(XlibWindow) .map(XlibWindow)
.ok_or(ErrorKind::NonMatchingBackend("X11").into()) .ok_or_else(|| ErrorKind::NonMatchingBackend("X11").into())
} }
} }
@ -144,7 +144,7 @@ unsafe impl NativeDisplay<Wayland> for WinitWindow {
fn ptr(&self) -> Result<ffi::NativeDisplayType> { fn ptr(&self) -> Result<ffi::NativeDisplayType> {
self.get_wayland_display() self.get_wayland_display()
.map(|ptr| ptr as *const _) .map(|ptr| ptr as *const _)
.ok_or(ErrorKind::NonMatchingBackend("Wayland").into()) .ok_or_else(|| ErrorKind::NonMatchingBackend("Wayland").into())
} }
fn create_surface(&mut self, _args: ()) -> Result<wegl::WlEglSurface> { fn create_surface(&mut self, _args: ()) -> Result<wegl::WlEglSurface> {

View File

@ -23,7 +23,6 @@ pub enum SwapBuffersError {
impl fmt::Display for SwapBuffersError { impl fmt::Display for SwapBuffersError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
use std::error::Error;
write!(formatter, "{}", self.description()) write!(formatter, "{}", self.description())
} }
} }

View File

@ -215,23 +215,23 @@ pub trait PointerAxisEvent: Event {
/// Amount of scrolling in pixels on the given [`Axis`]. /// Amount of scrolling in pixels on the given [`Axis`].
/// ///
/// Guaranteed to be `Some` when source returns either [`AxisSource::Finger`] or [`AxisSource::Continuous`]. /// Guaranteed to be `Some` when source returns either [`AxisSource::Finger`] or [`AxisSource::Continuous`].
fn amount(&self, axis: &Axis) -> Option<f64>; fn amount(&self, axis: Axis) -> Option<f64>;
/// Amount of scrolling in discrete steps on the given [`Axis`]. /// Amount of scrolling in discrete steps on the given [`Axis`].
/// ///
/// Guaranteed to be `Some` when source returns either [`AxisSource::Wheel`] or [`AxisSource::WheelTilt`]. /// Guaranteed to be `Some` when source returns either [`AxisSource::Wheel`] or [`AxisSource::WheelTilt`].
fn amount_discrete(&self, axis: &Axis) -> Option<f64>; fn amount_discrete(&self, axis: Axis) -> Option<f64>;
/// Source of the scroll event. /// Source of the scroll event.
fn source(&self) -> AxisSource; fn source(&self) -> AxisSource;
} }
impl PointerAxisEvent for UnusedEvent { impl PointerAxisEvent for UnusedEvent {
fn amount(&self, _axis: &Axis) -> Option<f64> { fn amount(&self, _axis: Axis) -> Option<f64> {
match *self {} match *self {}
} }
fn amount_discrete(&self, _axis: &Axis) -> Option<f64> { fn amount_discrete(&self, _axis: Axis) -> Option<f64> {
match *self {} match *self {}
} }

View File

@ -87,12 +87,12 @@ impl<'a> backend::Event for event::pointer::PointerAxisEvent {
} }
impl backend::PointerAxisEvent for event::pointer::PointerAxisEvent { impl backend::PointerAxisEvent for event::pointer::PointerAxisEvent {
fn amount(&self, axis: &Axis) -> Option<f64> { fn amount(&self, axis: Axis) -> Option<f64> {
Some(self.axis_value((*axis).into())) Some(self.axis_value(axis.into()))
} }
fn amount_discrete(&self, axis: &Axis) -> Option<f64> { fn amount_discrete(&self, axis: Axis) -> Option<f64> {
self.axis_value_discrete((*axis).into()) self.axis_value_discrete(axis.into())
} }
fn source(&self) -> backend::AxisSource { fn source(&self) -> backend::AxisSource {
@ -612,8 +612,6 @@ pub fn libinput_bind<Data: 'static>(
source.set_interest(Ready::readable()); source.set_interest(Ready::readable());
handle.insert_source(source, move |evt, _| { handle.insert_source(source, move |evt, _| {
use crate::backend::input::InputBackend;
let mut backend = evt.source.borrow_mut(); let mut backend = evt.source.borrow_mut();
if let Err(error) = backend.0.dispatch_new_events() { if let Err(error) = backend.0.dispatch_new_events() {
warn!(backend.0.logger, "Libinput errored: {}", error); warn!(backend.0.logger, "Libinput errored: {}", error);

View File

@ -19,9 +19,7 @@
//! //!
//! use smithay::backend::session::direct::DirectSession; //! use smithay::backend::session::direct::DirectSession;
//! //!
//! # fn main() {
//! let (session, mut notifier) = DirectSession::new(None, None).unwrap(); //! let (session, mut notifier) = DirectSession::new(None, None).unwrap();
//! # }
//! ``` //! ```
//! //!
//! ### Usage of the session //! ### Usage of the session

View File

@ -183,7 +183,7 @@ pub fn primary_gpu<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Opti
if device if device
.property_value("ID_SEAT") .property_value("ID_SEAT")
.map(|x| x.to_os_string()) .map(|x| x.to_os_string())
.unwrap_or(OsString::from("seat0")) .unwrap_or_else(|| OsString::from("seat0"))
== *seat.as_ref() == *seat.as_ref()
{ {
if let Some(pci) = device.parent_with_subsystem(Path::new("pci"))? { if let Some(pci) = device.parent_with_subsystem(Path::new("pci"))? {
@ -214,7 +214,7 @@ pub fn all_gpus<S: AsRef<str>>(context: &Context, seat: S) -> UdevResult<Vec<Pat
device device
.property_value("ID_SEAT") .property_value("ID_SEAT")
.map(|x| x.to_os_string()) .map(|x| x.to_os_string())
.unwrap_or(OsString::from("seat0")) .unwrap_or_else(|| OsString::from("seat0"))
== *seat.as_ref() == *seat.as_ref()
}) })
.flat_map(|device| device.devnode().map(PathBuf::from)) .flat_map(|device| device.devnode().map(PathBuf::from))

View File

@ -431,18 +431,18 @@ impl PointerAxisEvent for WinitMouseWheelEvent {
} }
} }
fn amount(&self, axis: &Axis) -> Option<f64> { fn amount(&self, axis: Axis) -> Option<f64> {
match (axis, self.delta) { match (axis, self.delta) {
(&Axis::Horizontal, MouseScrollDelta::PixelDelta(delta)) => Some(delta.x), (Axis::Horizontal, MouseScrollDelta::PixelDelta(delta)) => Some(delta.x),
(&Axis::Vertical, MouseScrollDelta::PixelDelta(delta)) => Some(delta.y), (Axis::Vertical, MouseScrollDelta::PixelDelta(delta)) => Some(delta.y),
(_, MouseScrollDelta::LineDelta(_, _)) => None, (_, MouseScrollDelta::LineDelta(_, _)) => None,
} }
} }
fn amount_discrete(&self, axis: &Axis) -> Option<f64> { fn amount_discrete(&self, axis: Axis) -> Option<f64> {
match (axis, self.delta) { match (axis, self.delta) {
(&Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64), (Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64),
(&Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64), (Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64),
(_, MouseScrollDelta::PixelDelta(_)) => None, (_, MouseScrollDelta::PixelDelta(_)) => None,
} }
} }

View File

@ -35,7 +35,6 @@
//! // Declare the roles enum //! // Declare the roles enum
//! define_roles!(MyRoles); //! define_roles!(MyRoles);
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! // Call the init function: //! // Call the init function:
@ -52,7 +51,6 @@
//! // this `token` is what you'll use to access the surface associated data //! // this `token` is what you'll use to access the surface associated data
//! //!
//! // You're now ready to go! //! // You're now ready to go!
//! # }
//! ``` //! ```
//! //!
//! ### Use the surface metadata //! ### Use the surface metadata
@ -260,7 +258,7 @@ impl<R: 'static> CompositorToken<R> {
/// ///
/// 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_surface_data<F, T>(&self, surface: &WlSurface, f: F) -> T pub fn with_surface_data<F, T>(self, surface: &WlSurface, f: F) -> T
where where
F: FnOnce(&mut SurfaceAttributes) -> T, F: FnOnce(&mut SurfaceAttributes) -> T,
{ {
@ -299,7 +297,7 @@ where
/// If the surface 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_upward<F1, F2, F3, T>( pub fn with_surface_tree_upward<F1, F2, F3, T>(
&self, self,
surface: &WlSurface, surface: &WlSurface,
initial: T, initial: T,
filter: F1, filter: F1,
@ -320,7 +318,7 @@ where
/// ///
/// This would typically be used to find out which surface of a subsurface tree has been clicked for example. /// This would typically be used to find out which surface of a subsurface tree has been clicked for example.
pub fn with_surface_tree_downward<F1, F2, F3, T>( pub fn with_surface_tree_downward<F1, F2, F3, T>(
&self, self,
surface: &WlSurface, surface: &WlSurface,
initial: T, initial: T,
filter: F1, filter: F1,
@ -340,7 +338,7 @@ where
/// ///
/// 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 get_parent(&self, surface: &WlSurface) -> Option<WlSurface> { pub fn get_parent(self, surface: &WlSurface) -> Option<WlSurface> {
SurfaceData::<R>::get_parent(surface) SurfaceData::<R>::get_parent(surface)
} }
@ -348,7 +346,7 @@ where
/// ///
/// 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 get_children(&self, surface: &WlSurface) -> Vec<WlSurface> { pub fn get_children(self, surface: &WlSurface) -> Vec<WlSurface> {
SurfaceData::<R>::get_children(surface) SurfaceData::<R>::get_children(surface)
} }
} }
@ -358,7 +356,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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 has_a_role(&self, surface: &WlSurface) -> bool { pub fn has_a_role(self, surface: &WlSurface) -> bool {
SurfaceData::<R>::has_a_role(surface) SurfaceData::<R>::has_a_role(surface)
} }
@ -366,7 +364,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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 has_role<RoleData>(&self, surface: &WlSurface) -> bool pub fn has_role<RoleData>(self, surface: &WlSurface) -> bool
where where
R: Role<RoleData>, R: Role<RoleData>,
{ {
@ -379,7 +377,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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 give_role<RoleData>(&self, surface: &WlSurface) -> Result<(), ()> pub fn give_role<RoleData>(self, surface: &WlSurface) -> Result<(), ()>
where where
R: Role<RoleData>, R: Role<RoleData>,
RoleData: Default, RoleData: Default,
@ -393,7 +391,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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 give_role_with<RoleData>(&self, surface: &WlSurface, data: RoleData) -> Result<(), RoleData> pub fn give_role_with<RoleData>(self, surface: &WlSurface, data: RoleData) -> Result<(), RoleData>
where where
R: Role<RoleData>, R: Role<RoleData>,
{ {
@ -406,7 +404,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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: &WlSurface, f: F) -> Result<T, WrongRole> pub fn with_role_data<RoleData, F, T>(self, 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,
@ -420,7 +418,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// 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 remove_role<RoleData>(&self, surface: &WlSurface) -> Result<RoleData, WrongRole> pub fn remove_role<RoleData>(self, surface: &WlSurface) -> Result<RoleData, WrongRole>
where where
R: Role<RoleData>, R: Role<RoleData>,
{ {
@ -431,7 +429,7 @@ impl<R: RoleType + 'static> CompositorToken<R> {
/// ///
/// If the region is not managed by the `CompositorGlobal` that provided this token, this /// If the region 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 get_region_attributes(&self, region: &wl_region::WlRegion) -> RegionAttributes { pub fn get_region_attributes(self, region: &wl_region::WlRegion) -> RegionAttributes {
match region.as_ref().user_data::<Mutex<RegionAttributes>>() { match region.as_ref().user_data::<Mutex<RegionAttributes>>() {
Some(mutex) => mutex.lock().unwrap().clone(), Some(mutex) => mutex.lock().unwrap().clone(),
None => panic!("Accessing the data of foreign regions is not supported."), None => panic!("Accessing the data of foreign regions is not supported."),

View File

@ -32,9 +32,7 @@
//! type. You can call it like this: //! type. You can call it like this:
//! //!
//! ``` //! ```
//! # #[macro_use] //! # use smithay::define_roles;
//! # extern crate smithay;
//! #
//! // Metadata for a first role //! // Metadata for a first role
//! #[derive(Default)] //! #[derive(Default)]
//! pub struct MyRoleMetadata { //! pub struct MyRoleMetadata {
@ -55,7 +53,6 @@
//! /* ... */ //! /* ... */
//! ); //! );
//! //!
//! # fn main() {}
//! ``` //! ```
//! //!
//! And this will expand to an enum like this: //! And this will expand to an enum like this:

View File

@ -242,7 +242,7 @@ fn implement_dnd_data_offer(
move |req, offer| { move |req, offer| {
let mut data = offer_data.borrow_mut(); let mut data = offer_data.borrow_mut();
match req { match req {
Request::Accept { serial: _, mime_type } => { Request::Accept { mime_type, .. } => {
if let Some(mtype) = mime_type { if let Some(mtype) = mime_type {
if let Err(()) = with_source_metadata(&source, |meta| { if let Err(()) = with_source_metadata(&source, |meta| {
data.accepted = meta.mime_types.contains(&mtype); data.accepted = meta.mime_types.contains(&mtype);
@ -304,8 +304,8 @@ fn implement_dnd_data_offer(
"Invalid preferred action.".into(), "Invalid preferred action.".into(),
); );
} }
let source_actions = let source_actions = with_source_metadata(&source, |meta| meta.dnd_action)
with_source_metadata(&source, |meta| meta.dnd_action).unwrap_or(DndAction::empty()); .unwrap_or_else(|_| DndAction::empty());
let possible_actions = source_actions & DndAction::from_bits_truncate(dnd_actions); let possible_actions = source_actions & DndAction::from_bits_truncate(dnd_actions);
data.chosen_action = data.chosen_action =
(&mut *action_choice.borrow_mut())(possible_actions, preferred_action); (&mut *action_choice.borrow_mut())(possible_actions, preferred_action);

View File

@ -40,7 +40,6 @@
//! // to set a surface as a dnd icon //! // to set a surface as a dnd icon
//! define_roles!(Roles => [DnDIcon, DnDIconRole]); //! define_roles!(Roles => [DnDIcon, DnDIconRole]);
//! //!
//! # fn main(){
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None); //! # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None);
@ -53,7 +52,6 @@
//! compositor_token.clone(), // a compositor token //! compositor_token.clone(), // a compositor token
//! None // insert a logger here //! None // insert a logger here
//! ); //! );
//! # }
//! ``` //! ```
use std::cell::RefCell; use std::cell::RefCell;
@ -179,8 +177,9 @@ impl SeatData {
.create_resource::<wl_data_offer::WlDataOffer>(dd.as_ref().version()) .create_resource::<wl_data_offer::WlDataOffer>(dd.as_ref().version())
.unwrap() .unwrap()
.implement_closure( .implement_closure(
move |req, _offer| match req { move |req, _offer| {
wl_data_offer::Request::Receive { fd, mime_type } => { // selection data offers only care about the `receive` event
if let wl_data_offer::Request::Receive { fd, mime_type } = req {
// check if the source and associated mime type is still valid // check if the source and associated mime type is still valid
let valid = with_source_metadata(&source, |meta| { let valid = with_source_metadata(&source, |meta| {
meta.mime_types.contains(&mime_type) meta.mime_types.contains(&mime_type)
@ -195,7 +194,6 @@ impl SeatData {
} }
let _ = ::nix::unistd::close(fd); let _ = ::nix::unistd::close(fd);
} }
_ => { /* seleciton data offers only care about the `receive` event */ }
}, },
None::<fn(_)>, None::<fn(_)>,
(), (),
@ -230,8 +228,9 @@ impl SeatData {
.create_resource::<wl_data_offer::WlDataOffer>(dd.as_ref().version()) .create_resource::<wl_data_offer::WlDataOffer>(dd.as_ref().version())
.unwrap() .unwrap()
.implement_closure( .implement_closure(
move |req, _offer| match req { move |req, _offer| {
wl_data_offer::Request::Receive { fd, mime_type } => { // selection data offers only care about the `receive` event
if let wl_data_offer::Request::Receive { fd, mime_type } = req {
// check if the associated mime type is valid // check if the associated mime type is valid
if !offer_meta.mime_types.contains(&mime_type) { if !offer_meta.mime_types.contains(&mime_type) {
// deny the receive // deny the receive
@ -244,7 +243,6 @@ impl SeatData {
}); });
} }
} }
_ => { /* seleciton data offers only care about the `receive` event */ }
}, },
None::<fn(_)>, None::<fn(_)>,
(), (),
@ -302,7 +300,7 @@ where
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "data_device_mgr")); let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "data_device_mgr"));
let action_choice = Rc::new(RefCell::new(action_choice)); let action_choice = Rc::new(RefCell::new(action_choice));
let callback = Rc::new(RefCell::new(callback)); let callback = Rc::new(RefCell::new(callback));
let global = display.create_global(3, move |new_ddm, _version| { display.create_global(3, move |new_ddm, _version| {
implement_ddm( implement_ddm(
new_ddm, new_ddm,
callback.clone(), callback.clone(),
@ -310,9 +308,7 @@ where
token, token,
log.clone(), log.clone(),
); );
}); })
global
} }
/// Set the data device focus to a certain client for a given seat /// Set the data device focus to a certain client for a given seat
@ -406,7 +402,7 @@ where
seat.clone(), seat.clone(),
callback.clone(), callback.clone(),
action_choice.clone(), action_choice.clone(),
token.clone(), token,
log.clone(), log.clone(),
); );
seat_data.borrow_mut().known_devices.push(data_device); seat_data.borrow_mut().known_devices.push(data_device);
@ -476,7 +472,7 @@ where
origin, origin,
seat.clone(), seat.clone(),
icon, icon,
token.clone(), token,
callback.clone(), callback.clone(),
), ),
serial, serial,
@ -486,7 +482,7 @@ where
} }
debug!(log, "denying drag from client without implicit grab"); debug!(log, "denying drag from client without implicit grab");
} }
Request::SetSelection { source, serial: _ } => { Request::SetSelection { source, .. } => {
if let Some(keyboard) = seat.get_keyboard() { if let Some(keyboard) = seat.get_keyboard() {
if dd if dd
.as_ref() .as_ref()

View File

@ -236,7 +236,7 @@ where
move |req, offer| { move |req, offer| {
let mut data = offer_data.borrow_mut(); let mut data = offer_data.borrow_mut();
match req { match req {
Request::Accept { serial: _, mime_type } => { Request::Accept { mime_type, .. } => {
if let Some(mtype) = mime_type { if let Some(mtype) = mime_type {
data.accepted = metadata.mime_types.contains(&mtype); data.accepted = metadata.mime_types.contains(&mtype);
} else { } else {

View File

@ -51,7 +51,6 @@
//! //!
//! // Once this is defined, you can in your setup initialize the dmabuf global: //! // Once this is defined, you can in your setup initialize the dmabuf global:
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! // define your supported formats //! // define your supported formats
@ -64,7 +63,6 @@
//! MyDmabufHandler, //! MyDmabufHandler,
//! None // we don't provide a logger in this example //! None // we don't provide a logger in this example
//! ); //! );
//! # }
//! ``` //! ```
use std::{cell::RefCell, os::unix::io::RawFd, rc::Rc}; use std::{cell::RefCell, os::unix::io::RawFd, rc::Rc};
@ -108,11 +106,11 @@ pub struct Plane {
bitflags! { bitflags! {
pub struct BufferFlags: u32 { pub struct BufferFlags: u32 {
/// The buffer content is Y-inverted /// The buffer content is Y-inverted
const YInvert = 1; const Y_INVERT = 1;
/// The buffer content is interlaced /// The buffer content is interlaced
const Interlaced = 2; const INTERLACED = 2;
/// The buffer content if interlaced is bottom-field first /// The buffer content if interlaced is bottom-field first
const BottomFirst = 4; const BOTTOM_FIRST = 4;
} }
} }
@ -200,8 +198,8 @@ where
let dma_handler = handler.clone(); let dma_handler = handler.clone();
let dma_log = log.clone(); let dma_log = log.clone();
let dmabuf: zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1 = new_dmabuf.implement_closure( let dmabuf: zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1 = new_dmabuf.implement_closure(
move |req, _| match req { move |req, _| {
zwp_linux_dmabuf_v1::Request::CreateParams { params_id } => { if let zwp_linux_dmabuf_v1::Request::CreateParams { params_id } = req {
params_id.implement( params_id.implement(
ParamsHandler { ParamsHandler {
pending_planes: Vec::new(), pending_planes: Vec::new(),
@ -215,7 +213,6 @@ where
(), (),
); );
} }
_ => (),
}, },
None::<fn(_)>, None::<fn(_)>,
(), (),

View File

@ -28,7 +28,6 @@
//! use smithay::wayland::explicit_synchronization::*; //! use smithay::wayland::explicit_synchronization::*;
//! # define_roles!(MyRoles); //! # define_roles!(MyRoles);
//! # //! #
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>( //! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>(
@ -41,7 +40,6 @@
//! compositor_token, //! compositor_token,
//! None /* You can insert a logger here */ //! None /* You can insert a logger here */
//! ); //! );
//! # }
//! ``` //! ```
//! //!
//! Then when handling a surface commit, you can retrieve the synchronization information for the surface //! Then when handling a surface commit, you can retrieve the synchronization information for the surface
@ -207,8 +205,12 @@ where
2, 2,
move |new_sync, _version| { move |new_sync, _version| {
new_sync.implement_closure( new_sync.implement_closure(
move |req, explicit_sync| match req { move |req, explicit_sync| {
zwp_linux_explicit_synchronization_v1::Request::GetSynchronization { id, surface } => { if let zwp_linux_explicit_synchronization_v1::Request::GetSynchronization {
id,
surface,
} = req
{
let exists = compositor.with_surface_data(&surface, |attrs| { let exists = compositor.with_surface_data(&surface, |attrs| {
attrs.user_data.insert_if_missing(|| ESUserData { state: None }); attrs.user_data.insert_if_missing(|| ESUserData { state: None });
attrs attrs
@ -236,7 +238,6 @@ where
}); });
}); });
} }
_ => {}
}, },
None::<fn(_)>, None::<fn(_)>,
(), (),

View File

@ -21,7 +21,6 @@
//! use smithay::wayland::output::{Output, PhysicalProperties, Mode}; //! use smithay::wayland::output::{Output, PhysicalProperties, Mode};
//! use wayland_server::protocol::wl_output; //! use wayland_server::protocol::wl_output;
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! // Create the Output with given name and physical properties //! // Create the Output with given name and physical properties
@ -48,7 +47,6 @@
//! // add other supported modes //! // add other supported modes
//! output.add_mode(Mode { width: 800, height: 600, refresh: 60000 }); //! output.add_mode(Mode { width: 800, height: 600, refresh: 60000 });
//! output.add_mode(Mode { width: 1024, height: 768, refresh: 60000 }); //! output.add_mode(Mode { width: 1024, height: 768, refresh: 60000 });
//! # }
//! ``` //! ```
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};

View File

@ -17,7 +17,6 @@
//! // to set a surface as a cursor image //! // to set a surface as a cursor image
//! define_roles!(Roles => [CursorImage, CursorImageRole]); //! define_roles!(Roles => [CursorImage, CursorImageRole]);
//! //!
//! # fn main(){
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None); //! # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None);
@ -28,7 +27,6 @@
//! compositor_token.clone(), // the compositor token //! compositor_token.clone(), // the compositor token
//! None // insert a logger here //! None // insert a logger here
//! ); //! );
//! # }
//! ``` //! ```
//! //!
//! ### Run usage //! ### Run usage
@ -144,7 +142,7 @@ impl Seat {
}); });
let seat = Seat { arc: arc.clone() }; let seat = Seat { arc: arc.clone() };
let global = display.create_global(5, move |new_seat, _version| { let global = display.create_global(5, move |new_seat, _version| {
let seat = implement_seat(new_seat, arc.clone(), token.clone()); let seat = implement_seat(new_seat, arc.clone(), token);
let mut inner = arc.inner.borrow_mut(); let mut inner = arc.inner.borrow_mut();
if seat.as_ref().version() >= 2 { if seat.as_ref().version() >= 2 {
seat.name(arc.name.clone()); seat.name(arc.name.clone());
@ -190,7 +188,6 @@ impl Seat {
/// # /// #
/// # define_roles!(Roles => [CursorImage, CursorImageRole]); /// # define_roles!(Roles => [CursorImage, CursorImageRole]);
/// # /// #
/// # fn main(){
/// # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); /// # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
/// # let mut display = wayland_server::Display::new(event_loop.handle()); /// # let mut display = wayland_server::Display::new(event_loop.handle());
/// # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None); /// # let (compositor_token, _, _) = compositor_init::<Roles, _, _>(&mut display, |_, _, _| {}, None);
@ -204,7 +201,6 @@ impl Seat {
/// compositor_token.clone(), /// compositor_token.clone(),
/// |new_status| { /* a closure handling requests from clients tot change the cursor icon */ } /// |new_status| { /* a closure handling requests from clients tot change the cursor icon */ }
/// ); /// );
/// # }
/// ``` /// ```
pub fn add_pointer<R, F>(&mut self, token: CompositorToken<R>, cb: F) -> PointerHandle pub fn add_pointer<R, F>(&mut self, token: CompositorToken<R>, cb: F) -> PointerHandle
where where
@ -349,7 +345,7 @@ where
let inner = arc.inner.borrow_mut(); let inner = arc.inner.borrow_mut();
match request { match request {
wl_seat::Request::GetPointer { id } => { wl_seat::Request::GetPointer { id } => {
let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref(), token.clone()); let pointer = self::pointer::implement_pointer(id, inner.pointer.as_ref(), token);
if let Some(ref ptr_handle) = inner.pointer { if let Some(ref ptr_handle) = inner.pointer {
ptr_handle.new_pointer(pointer); ptr_handle.new_pointer(pointer);
} else { } else {

View File

@ -545,10 +545,10 @@ where
move |request, pointer: WlPointer| { move |request, pointer: WlPointer| {
match request { match request {
Request::SetCursor { Request::SetCursor {
serial: _,
surface, surface,
hotspot_x, hotspot_x,
hotspot_y, hotspot_y,
..
} => { } => {
if let Some(ref inner) = inner { if let Some(ref inner) = inner {
let mut guard = inner.borrow_mut(); let mut guard = inner.borrow_mut();

View File

@ -42,7 +42,6 @@
//! [ShellSurface, ShellSurfaceRole] //! [ShellSurface, ShellSurfaceRole]
//! ); //! );
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>( //! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>(
@ -60,7 +59,6 @@
//! ); //! );
//! //!
//! // You're now ready to go! //! // You're now ready to go!
//! # }
//! ``` //! ```
use std::{ use std::{

View File

@ -47,7 +47,6 @@
//! /* ... */ //! /* ... */
//! } //! }
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>( //! # let (compositor_token, _, _) = smithay::wayland::compositor::compositor_init::<MyRoles, _, _>(
@ -65,7 +64,6 @@
//! ); //! );
//! //!
//! // You're now ready to go! //! // You're now ready to go!
//! # }
//! ``` //! ```
//! //!
//! ### Access to shell surface and clients data //! ### Access to shell surface and clients data

View File

@ -22,7 +22,6 @@
//! use smithay::wayland::shm::init_shm_global; //! use smithay::wayland::shm::init_shm_global;
//! use wayland_server::protocol::wl_shm::Format; //! use wayland_server::protocol::wl_shm::Format;
//! //!
//! # fn main() {
//! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap(); //! # let mut event_loop = wayland_server::calloop::EventLoop::<()>::new().unwrap();
//! # let mut display = wayland_server::Display::new(event_loop.handle()); //! # let mut display = wayland_server::Display::new(event_loop.handle());
//! // Insert the ShmGlobal into your event loop //! // Insert the ShmGlobal into your event loop
@ -33,7 +32,6 @@
//! vec![Format::Yuyv, Format::C8], //! vec![Format::Yuyv, Format::C8],
//! None // we don't provide a logger here //! None // we don't provide a logger here
//! ); //! );
//! # }
//! ``` //! ```
//! //!
//! Then, when you have a [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer) //! Then, when you have a [`WlBuffer`](wayland_server::protocol::wl_buffer::WlBuffer)
@ -67,7 +65,6 @@
//! } //! }
//! } //! }
//! # } //! # }
//! # fn main() {}
//! ``` //! ```
//! //!
//! **Note** //! **Note**