1
0
Fork 0
forked from wry/wry

autocommit 2022-02-05 18:25:58 CET

This commit is contained in:
Julian Orth 2022-02-05 18:25:58 +01:00
parent 3a4ae99b9a
commit 5eb9186c54
16 changed files with 90 additions and 184 deletions

View file

@ -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<WlCompositorError>),
#[error("An error occurred in a `wl_shm` global")]
WlShmError(#[source] Box<WlShmError>),
#[error("An error occurred in a `wl_subcompositor` global")]
WlSubcompositorError(#[source] Box<WlSubcompositorError>),
#[error("An error occurred in a `xdg_wm_base` global")]
XdgWmBaseError(#[source] Box<XdgWmBaseError>),
#[error("An error occurred in a `wl_output` global")]
WlOutputError(#[source] Box<WlOutputError>),
#[error("An error occurred in a `wl_seat` global")]
WlSeatError(#[source] Box<WlSeatError>),
#[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<WlDataDeviceManagerError>),
#[error("An error occurred in a `zwp_linux_dmabuf_v1` global")]
ZwpLinuxDmabufV1Error(#[source] Box<ZwpLinuxDmabufV1Error>),
#[error("An error occurred in a `wl_drm` global")]
WlDrmError(#[source] Box<WlDrmError>),
#[error("An error occurred in a `zxdg_decoration_manager_v1` global")]
ZxdgDecorationManagerV1Error(#[source] Box<ZxdgDecorationManagerV1Error>),
#[error("An error occurred in a `org_kde_kwin_server_decoration_manager` global")]
OrgKdeKwinServerDecorationManagerError(#[source] Box<OrgKdeKwinServerDecorationManagerError>),
#[error("An error occurred in a `zwp_primary_selection_device_manager_v1` global")]
ZwpPrimarySelectionDeviceManagerV1Error(#[source] Box<ZwpPrimarySelectionDeviceManagerV1Error>),
#[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<dyn Error>,
}
#[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<Self>,
client: &'a Rc<Client>,
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) {}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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<Self>,
client: &'a std::rc::Rc<crate::client::Client>,
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<Self>, 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);
}
}
};

View file

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