From 5eb9186c54ef66159e6676b081b9885d216730a1 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Sat, 5 Feb 2022 18:25:58 +0100 Subject: [PATCH] autocommit 2022-02-05 18:25:58 CET --- src/globals.rs | 75 +++++-------------- .../mod.rs | 16 ++-- src/ifs/wl_compositor/mod.rs | 12 +-- src/ifs/wl_data_device_manager/mod.rs | 16 ++-- src/ifs/wl_drm/mod.rs | 12 +-- src/ifs/wl_output/mod.rs | 12 +-- src/ifs/wl_registry/types.rs | 2 +- src/ifs/wl_seat/mod.rs | 12 +-- src/ifs/wl_shm/mod.rs | 12 +-- src/ifs/wl_subcompositor/mod.rs | 12 +-- src/ifs/xdg_wm_base/mod.rs | 12 +-- src/ifs/zwp_linux_dmabuf_v1/mod.rs | 16 ++-- .../mod.rs | 16 ++-- src/ifs/zxdg_decoration_manager_v1/mod.rs | 16 ++-- src/macros.rs | 31 ++++++-- src/state.rs | 2 +- 16 files changed, 90 insertions(+), 184 deletions(-) diff --git a/src/globals.rs b/src/globals.rs index b17e7404..bb975bee 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -1,21 +1,10 @@ use crate::client::{Client, DynEventFormatter}; -use crate::ifs::org_kde_kwin_server_decoration_manager::{ - OrgKdeKwinServerDecorationManagerError, OrgKdeKwinServerDecorationManagerGlobal, -}; -use crate::ifs::wl_compositor::WlCompositorError; -use crate::ifs::wl_data_device_manager::WlDataDeviceManagerError; -use crate::ifs::wl_drm::{WlDrmError, WlDrmGlobal}; -use crate::ifs::wl_output::{WlOutputError, WlOutputGlobal}; +use crate::ifs::org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerGlobal; +use crate::ifs::wl_drm::WlDrmGlobal; +use crate::ifs::wl_output::WlOutputGlobal; use crate::ifs::wl_registry::WlRegistry; -use crate::ifs::wl_seat::{WlSeatError, WlSeatGlobal}; -use crate::ifs::wl_shm::WlShmError; -use crate::ifs::wl_subcompositor::WlSubcompositorError; -use crate::ifs::xdg_wm_base::XdgWmBaseError; -use crate::ifs::zwp_linux_dmabuf_v1::ZwpLinuxDmabufV1Error; -use crate::ifs::zwp_primary_selection_device_manager_v1::{ - ZwpPrimarySelectionDeviceManagerV1Error, ZwpPrimarySelectionDeviceManagerV1Global, -}; -use crate::ifs::zxdg_decoration_manager_v1::ZxdgDecorationManagerV1Error; +use crate::ifs::wl_seat::WlSeatGlobal; +use crate::ifs::zwp_primary_selection_device_manager_v1::ZwpPrimarySelectionDeviceManagerV1Global; use crate::object::{Interface, ObjectId}; use crate::utils::copyhashmap::CopyHashMap; use crate::{ @@ -24,6 +13,7 @@ use crate::{ }; use ahash::AHashMap; use std::cell::RefMut; +use std::error::Error; use std::fmt::{Display, Formatter}; use std::rc::Rc; use thiserror::Error; @@ -32,46 +22,19 @@ use thiserror::Error; pub enum GlobalsError { #[error("The requested global {0} does not exist")] GlobalDoesNotExist(GlobalName), - #[error("An error occurred in a `wl_compositor` global")] - WlCompositorError(#[source] Box), - #[error("An error occurred in a `wl_shm` global")] - WlShmError(#[source] Box), - #[error("An error occurred in a `wl_subcompositor` global")] - WlSubcompositorError(#[source] Box), - #[error("An error occurred in a `xdg_wm_base` global")] - XdgWmBaseError(#[source] Box), - #[error("An error occurred in a `wl_output` global")] - WlOutputError(#[source] Box), - #[error("An error occurred in a `wl_seat` global")] - WlSeatError(#[source] Box), #[error("The output with id {0} does not exist")] OutputDoesNotExist(GlobalName), - #[error("An error occurred in a `wl_data_device_manager` global")] - WlDataDeviceManagerError(#[source] Box), - #[error("An error occurred in a `zwp_linux_dmabuf_v1` global")] - ZwpLinuxDmabufV1Error(#[source] Box), - #[error("An error occurred in a `wl_drm` global")] - WlDrmError(#[source] Box), - #[error("An error occurred in a `zxdg_decoration_manager_v1` global")] - ZxdgDecorationManagerV1Error(#[source] Box), - #[error("An error occurred in a `org_kde_kwin_server_decoration_manager` global")] - OrgKdeKwinServerDecorationManagerError(#[source] Box), - #[error("An error occurred in a `zwp_primary_selection_device_manager_v1` global")] - ZwpPrimarySelectionDeviceManagerV1Error(#[source] Box), + #[error(transparent)] + GlobalError(GlobalError), } -efrom!(GlobalsError, WlCompositorError); -efrom!(GlobalsError, WlShmError); -efrom!(GlobalsError, WlSubcompositorError); -efrom!(GlobalsError, XdgWmBaseError); -efrom!(GlobalsError, WlOutputError); -efrom!(GlobalsError, WlSeatError); -efrom!(GlobalsError, ZwpLinuxDmabufV1Error); -efrom!(GlobalsError, WlDrmError); -efrom!(GlobalsError, WlDataDeviceManagerError); -efrom!(GlobalsError, ZxdgDecorationManagerV1Error); -efrom!(GlobalsError, OrgKdeKwinServerDecorationManagerError); -efrom!(GlobalsError, ZwpPrimarySelectionDeviceManagerV1Error); +#[derive(Debug, Error)] +#[error("An error occurred in a `{}` global", .interface.name())] +pub struct GlobalError { + pub interface: Interface, + #[source] + pub error: Box, +} #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] pub struct GlobalName(u32); @@ -92,19 +55,19 @@ impl Display for GlobalName { } } -pub trait GlobalBind { +pub trait GlobalBase { + fn name(&self) -> GlobalName; fn bind<'a>( self: Rc, client: &'a Rc, id: ObjectId, version: u32, ) -> Result<(), GlobalsError>; + fn interface(&self) -> Interface; } -pub trait Global: GlobalBind { - fn name(&self) -> GlobalName; +pub trait Global: GlobalBase { fn singleton(&self) -> bool; - fn interface(&self) -> Interface; fn version(&self) -> u32; fn break_loops(&self) {} } diff --git a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs b/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs index aa3329cf..311bfe88 100644 --- a/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs +++ b/src/ifs/org_kde_kwin_server_decoration_manager/mod.rs @@ -1,7 +1,7 @@ use crate::client::{Client, DynEventFormatter}; use crate::globals::{Global, GlobalName}; use crate::ifs::org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -45,21 +45,17 @@ impl OrgKdeKwinServerDecorationManagerGlobal { } } -bind!(OrgKdeKwinServerDecorationManagerGlobal); +global_base!( + OrgKdeKwinServerDecorationManagerGlobal, + OrgKdeKwinServerDecorationManager, + OrgKdeKwinServerDecorationManagerError +); impl Global for OrgKdeKwinServerDecorationManagerGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::OrgKdeKwinServerDecorationManager - } - fn version(&self) -> u32 { 1 } diff --git a/src/ifs/wl_compositor/mod.rs b/src/ifs/wl_compositor/mod.rs index 2f94b1ab..830d78fc 100644 --- a/src/ifs/wl_compositor/mod.rs +++ b/src/ifs/wl_compositor/mod.rs @@ -4,7 +4,7 @@ use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::wl_region::WlRegion; use crate::ifs::wl_surface::WlSurface; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -61,21 +61,13 @@ impl WlCompositor { } } -bind!(WlCompositorGlobal); +global_base!(WlCompositorGlobal, WlCompositor, WlCompositorError); impl Global for WlCompositorGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::WlCompositor - } - fn version(&self) -> u32 { 4 } diff --git a/src/ifs/wl_data_device_manager/mod.rs b/src/ifs/wl_data_device_manager/mod.rs index fd914b27..e27cffc4 100644 --- a/src/ifs/wl_data_device_manager/mod.rs +++ b/src/ifs/wl_data_device_manager/mod.rs @@ -4,7 +4,7 @@ use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::wl_data_device::WlDataDevice; use crate::ifs::wl_data_source::WlDataSource; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -75,21 +75,17 @@ impl WlDataDeviceManager { } } -bind!(WlDataDeviceManagerGlobal); +global_base!( + WlDataDeviceManagerGlobal, + WlDataDeviceManager, + WlDataDeviceManagerError +); impl Global for WlDataDeviceManagerGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::WlDataDeviceManager - } - fn version(&self) -> u32 { 3 } diff --git a/src/ifs/wl_drm/mod.rs b/src/ifs/wl_drm/mod.rs index 54235ccd..da7bba46 100644 --- a/src/ifs/wl_drm/mod.rs +++ b/src/ifs/wl_drm/mod.rs @@ -1,6 +1,6 @@ use crate::client::{Client, DynEventFormatter}; use crate::globals::{Global, GlobalName}; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::ffi::CString; use std::rc::Rc; @@ -50,21 +50,13 @@ impl WlDrmGlobal { } } -bind!(WlDrmGlobal); +global_base!(WlDrmGlobal, WlDrm, WlDrmError); impl Global for WlDrmGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::WlDrm - } - fn version(&self) -> u32 { 1 } diff --git a/src/ifs/wl_output/mod.rs b/src/ifs/wl_output/mod.rs index 9d42854f..24a03432 100644 --- a/src/ifs/wl_output/mod.rs +++ b/src/ifs/wl_output/mod.rs @@ -3,7 +3,7 @@ mod types; use crate::backend::Output; use crate::client::{Client, ClientId, DynEventFormatter, WlEvent}; use crate::globals::{Global, GlobalName}; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use ahash::AHashMap; use std::cell::{Cell, RefCell}; @@ -136,21 +136,13 @@ impl WlOutputGlobal { } } -bind!(WlOutputGlobal); +global_base!(WlOutputGlobal, WlOutput, WlOutputError); impl Global for WlOutputGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { false } - fn interface(&self) -> Interface { - Interface::WlOutput - } - fn version(&self) -> u32 { 3 } diff --git a/src/ifs/wl_registry/types.rs b/src/ifs/wl_registry/types.rs index 9ba0df61..75a12c92 100644 --- a/src/ifs/wl_registry/types.rs +++ b/src/ifs/wl_registry/types.rs @@ -1,5 +1,5 @@ use crate::client::{EventFormatter, RequestParser}; -use crate::globals::{Global, GlobalsError, GlobalName}; +use crate::globals::{Global, GlobalName, GlobalsError}; use crate::ifs::wl_registry::{WlRegistry, GLOBAL, GLOBAL_REMOVE}; use crate::object::{Interface, Object, ObjectId}; use crate::utils::buffd::{MsgFormatter, MsgParser, MsgParserError}; diff --git a/src/ifs/wl_seat/mod.rs b/src/ifs/wl_seat/mod.rs index d01b31a4..d40ca1cc 100644 --- a/src/ifs/wl_seat/mod.rs +++ b/src/ifs/wl_seat/mod.rs @@ -23,7 +23,7 @@ use crate::ifs::zwp_primary_selection_offer_v1::ZwpPrimarySelectionOfferV1Id; use crate::ifs::zwp_primary_selection_source_v1::{ ZwpPrimarySelectionSourceV1, ZwpPrimarySelectionSourceV1Error, }; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::tree::{FloatNode, FoundNode, Node}; use crate::utils::asyncevent::AsyncEvent; use crate::utils::buffd::MsgParser; @@ -287,21 +287,13 @@ impl WlSeatGlobal { } } -bind!(WlSeatGlobal); +global_base!(WlSeatGlobal, WlSeat, WlSeatError); impl Global for WlSeatGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { false } - fn interface(&self) -> Interface { - Interface::WlSeat - } - fn version(&self) -> u32 { 7 } diff --git a/src/ifs/wl_shm/mod.rs b/src/ifs/wl_shm/mod.rs index f04c4bbe..cbe913c2 100644 --- a/src/ifs/wl_shm/mod.rs +++ b/src/ifs/wl_shm/mod.rs @@ -4,7 +4,7 @@ use crate::client::Client; use crate::format::FORMATS; use crate::globals::{Global, GlobalName}; use crate::ifs::wl_shm_pool::WlShmPool; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -69,21 +69,13 @@ impl WlShm { } } -bind!(WlShmGlobal); +global_base!(WlShmGlobal, WlShm, WlShmError); impl Global for WlShmGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::WlShm - } - fn version(&self) -> u32 { 1 } diff --git a/src/ifs/wl_subcompositor/mod.rs b/src/ifs/wl_subcompositor/mod.rs index ac2d1328..6ae4b167 100644 --- a/src/ifs/wl_subcompositor/mod.rs +++ b/src/ifs/wl_subcompositor/mod.rs @@ -3,7 +3,7 @@ mod types; use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::wl_surface::wl_subsurface::WlSubsurface; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -63,21 +63,13 @@ impl WlSubcompositor { } } -bind!(WlSubcompositorGlobal); +global_base!(WlSubcompositorGlobal, WlSubcompositor, WlSubcompositorError); impl Global for WlSubcompositorGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::WlSubcompositor - } - fn version(&self) -> u32 { 1 } diff --git a/src/ifs/xdg_wm_base/mod.rs b/src/ifs/xdg_wm_base/mod.rs index 9ec410a2..5a9d6bd8 100644 --- a/src/ifs/xdg_wm_base/mod.rs +++ b/src/ifs/xdg_wm_base/mod.rs @@ -4,7 +4,7 @@ use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::wl_surface::xdg_surface::{XdgSurface, XdgSurfaceId}; use crate::ifs::xdg_positioner::XdgPositioner; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use crate::utils::copyhashmap::CopyHashMap; use std::rc::Rc; @@ -111,21 +111,13 @@ impl XdgWmBase { } } -bind!(XdgWmBaseGlobal); +global_base!(XdgWmBaseGlobal, XdgWmBase, XdgWmBaseError); impl Global for XdgWmBaseGlobal { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::XdgWmBase - } - fn version(&self) -> u32 { 3 } diff --git a/src/ifs/zwp_linux_dmabuf_v1/mod.rs b/src/ifs/zwp_linux_dmabuf_v1/mod.rs index ae974ce4..27ace15d 100644 --- a/src/ifs/zwp_linux_dmabuf_v1/mod.rs +++ b/src/ifs/zwp_linux_dmabuf_v1/mod.rs @@ -2,7 +2,7 @@ use crate::client::{Client, DynEventFormatter}; use crate::drm::INVALID_MODIFIER; use crate::globals::{Global, GlobalName}; use crate::ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -53,21 +53,17 @@ impl ZwpLinuxDmabufV1Global { const MODIFIERS_SINCE_VERSION: u32 = 3; -bind!(ZwpLinuxDmabufV1Global); +global_base!( + ZwpLinuxDmabufV1Global, + ZwpLinuxDmabufV1, + ZwpLinuxDmabufV1Error +); impl Global for ZwpLinuxDmabufV1Global { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::ZwpLinuxDmabufV1 - } - fn version(&self) -> u32 { 3 } diff --git a/src/ifs/zwp_primary_selection_device_manager_v1/mod.rs b/src/ifs/zwp_primary_selection_device_manager_v1/mod.rs index 36752253..83e12e5b 100644 --- a/src/ifs/zwp_primary_selection_device_manager_v1/mod.rs +++ b/src/ifs/zwp_primary_selection_device_manager_v1/mod.rs @@ -4,7 +4,7 @@ use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1; use crate::ifs::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -70,21 +70,17 @@ impl ZwpPrimarySelectionDeviceManagerV1 { } } -bind!(ZwpPrimarySelectionDeviceManagerV1Global); +global_base!( + ZwpPrimarySelectionDeviceManagerV1Global, + ZwpPrimarySelectionDeviceManagerV1, + ZwpPrimarySelectionDeviceManagerV1Error +); impl Global for ZwpPrimarySelectionDeviceManagerV1Global { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::ZwpPrimarySelectionDeviceManagerV1 - } - fn version(&self) -> u32 { 1 } diff --git a/src/ifs/zxdg_decoration_manager_v1/mod.rs b/src/ifs/zxdg_decoration_manager_v1/mod.rs index 91fd4b59..f86d4299 100644 --- a/src/ifs/zxdg_decoration_manager_v1/mod.rs +++ b/src/ifs/zxdg_decoration_manager_v1/mod.rs @@ -1,7 +1,7 @@ use crate::client::Client; use crate::globals::{Global, GlobalName}; use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1; -use crate::object::{Interface, Object}; +use crate::object::Object; use crate::utils::buffd::MsgParser; use std::rc::Rc; pub use types::*; @@ -37,21 +37,17 @@ impl ZxdgDecorationManagerV1Global { } } -bind!(ZxdgDecorationManagerV1Global); +global_base!( + ZxdgDecorationManagerV1Global, + ZxdgDecorationManagerV1, + ZxdgDecorationManagerV1Error +); impl Global for ZxdgDecorationManagerV1Global { - fn name(&self) -> GlobalName { - self.name - } - fn singleton(&self) -> bool { true } - fn interface(&self) -> Interface { - Interface::ZxdgDecorationManagerV1 - } - fn version(&self) -> u32 { 1 } diff --git a/src/macros.rs b/src/macros.rs index 2edbead6..54f98e3c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -59,18 +59,37 @@ macro_rules! object_base { }; } -macro_rules! bind { - ($oname:ty) => { - impl crate::globals::GlobalBind for $oname { +macro_rules! global_base { + ($oname:ty, $ifname:ident, $ename:ty) => { + impl crate::globals::GlobalBase for $oname { + fn name(&self) -> crate::globals::GlobalName { + self.name + } + fn bind<'a>( self: std::rc::Rc, client: &'a std::rc::Rc, id: crate::object::ObjectId, version: u32, ) -> Result<(), crate::globals::GlobalsError> { - self.bind_(id.into(), client, version)?; + if let Err(e) = self.bind_(id.into(), client, version) { + return Err(crate::globals::GlobalsError::GlobalError(e.into())); + } Ok(()) } + + fn interface(&self) -> crate::object::Interface { + crate::object::Interface::$ifname + } + } + + impl From<$ename> for crate::globals::GlobalError { + fn from(e: $ename) -> Self { + Self { + interface: crate::object::Interface::$ifname, + error: Box::new(e), + } + } } }; } @@ -282,10 +301,10 @@ macro_rules! dedicated_add_global { ($oname:ident, $field:ident) => { impl crate::globals::WaylandGlobal for $oname { fn add(self: Rc, globals: &crate::globals::Globals) { - globals.$field.set(self.name(), self); + globals.$field.set(self.name, self); } fn remove(&self, globals: &crate::globals::Globals) { - globals.$field.remove(&self.name()); + globals.$field.remove(&self.name); } } }; diff --git a/src/state.rs b/src/state.rs index 257816fb..f921ac11 100644 --- a/src/state.rs +++ b/src/state.rs @@ -3,7 +3,7 @@ use crate::backend::{BackendEvent, OutputId, OutputIds, SeatId, SeatIds}; use crate::client::{Client, Clients}; use crate::cursor::ServerCursors; use crate::event_loop::EventLoop; -use crate::globals::{GlobalsError, Globals, WaylandGlobal}; +use crate::globals::{Globals, GlobalsError, WaylandGlobal}; use crate::ifs::wl_output::WlOutputGlobal; use crate::ifs::wl_seat::WlSeatGlobal; use crate::ifs::wl_surface::NoneSurfaceExt;