From 4c94ed550e874532a9b46dae3b40865f2e6866e8 Mon Sep 17 00:00:00 2001 From: Daniel De Graaf Date: Wed, 18 Oct 2023 20:48:12 -0400 Subject: [PATCH] Add API_VERSION_MAX constants for use in ProvidesBoundGlobal impls --- src/compositor.rs | 27 ++++++++++++++++++++++----- src/shell/xdg/mod.rs | 16 +++++++++++----- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/compositor.rs b/src/compositor.rs index 441fd5d1f..7218fd656 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -75,6 +75,12 @@ pub struct CompositorState { } impl CompositorState { + /// The maximum API version for WlCompositor that this object will bind. + // Note: if bumping this version number, check if the changes to the wayland XML cause an API + // break in the rust interfaces. If it does, be sure to remove other ProvidesBoundGlobal + // impls; if it does not, consider adding one for the previous (compatible) version. + pub const API_VERSION_MAX: u32 = 6; + pub fn bind( globals: &GlobalList, qh: &QueueHandle, @@ -82,7 +88,7 @@ impl CompositorState { where State: Dispatch + 'static, { - let wl_compositor = globals.bind(qh, 1..=6, GlobalData)?; + let wl_compositor = globals.bind(qh, 1..=Self::API_VERSION_MAX, GlobalData)?; Ok(CompositorState { wl_compositor }) } @@ -191,7 +197,10 @@ pub struct Surface(wl_surface::WlSurface); impl Surface { pub fn new( - compositor: &impl ProvidesBoundGlobal, + compositor: &impl ProvidesBoundGlobal< + wl_compositor::WlCompositor, + { CompositorState::API_VERSION_MAX }, + >, qh: &QueueHandle, ) -> Result where @@ -201,7 +210,10 @@ impl Surface { } pub fn with_data( - compositor: &impl ProvidesBoundGlobal, + compositor: &impl ProvidesBoundGlobal< + wl_compositor::WlCompositor, + { CompositorState::API_VERSION_MAX }, + >, qh: &QueueHandle, data: U, ) -> Result @@ -388,7 +400,10 @@ pub struct Region(wl_region::WlRegion); impl Region { pub fn new( - compositor: &impl ProvidesBoundGlobal, + compositor: &impl ProvidesBoundGlobal< + wl_compositor::WlCompositor, + { CompositorState::API_VERSION_MAX }, + >, ) -> Result { compositor .bound_global() @@ -447,7 +462,9 @@ where } } -impl ProvidesBoundGlobal for CompositorState { +impl ProvidesBoundGlobal + for CompositorState +{ fn bound_global(&self) -> Result { Ok(self.wl_compositor.clone()) } diff --git a/src/shell/xdg/mod.rs b/src/shell/xdg/mod.rs index 45e4a8221..5e5a07703 100644 --- a/src/shell/xdg/mod.rs +++ b/src/shell/xdg/mod.rs @@ -40,6 +40,12 @@ pub struct XdgShell { } impl XdgShell { + /// The maximum API version for XdgWmBase that this object will bind. + // Note: if bumping this version number, check if the changes to the wayland XML cause an API + // break in the rust interfaces. If it does, be sure to remove other ProvidesBoundGlobal + // impls; if it does not, consider adding one for the previous (compatible) version. + pub const API_VERSION_MAX: u32 = 6; + /// Binds the xdg shell global, `xdg_wm_base`. /// /// If available, the `zxdg_decoration_manager_v1` global will be bound to allow server side decorations @@ -54,7 +60,7 @@ impl XdgShell { + Dispatch + 'static, { - let xdg_wm_base = globals.bind(qh, 1..=6, GlobalData)?; + let xdg_wm_base = globals.bind(qh, 1..=Self::API_VERSION_MAX, GlobalData)?; let xdg_decoration_manager = GlobalProxy::from(globals.bind(qh, 1..=1, GlobalData)); Ok(Self { xdg_wm_base, xdg_decoration_manager }) } @@ -168,7 +174,7 @@ pub struct XdgPositioner(xdg_positioner::XdgPositioner); impl XdgPositioner { pub fn new( - wm_base: &impl ProvidesBoundGlobal, + wm_base: &impl ProvidesBoundGlobal, ) -> Result { wm_base .bound_global() @@ -240,7 +246,7 @@ impl XdgShellSurface { /// [`XdgSurface`]: xdg_surface::XdgSurface /// [`WlSurface`]: wl_surface::WlSurface pub fn new( - wm_base: &impl ProvidesBoundGlobal, + wm_base: &impl ProvidesBoundGlobal, qh: &QueueHandle, surface: impl Into, udata: U, @@ -310,11 +316,11 @@ impl Drop for XdgShellSurface { // Version 5 adds the wm_capabilities event, which is a break impl ProvidesBoundGlobal for XdgShell { fn bound_global(&self) -> Result { - Ok(self.xdg_wm_base.clone()) + >::bound_global(self) } } -impl ProvidesBoundGlobal for XdgShell { +impl ProvidesBoundGlobal for XdgShell { fn bound_global(&self) -> Result { Ok(self.xdg_wm_base.clone()) }