Skip to content

Commit

Permalink
Add API_VERSION_MAX constants for use in ProvidesBoundGlobal impls
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldg authored and wash2 committed Oct 31, 2023
1 parent 1500dc8 commit 4c94ed5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
27 changes: 22 additions & 5 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ 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<State>(
globals: &GlobalList,
qh: &QueueHandle<State>,
) -> Result<CompositorState, BindError>
where
State: Dispatch<wl_compositor::WlCompositor, GlobalData, State> + '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 })
}

Expand Down Expand Up @@ -191,7 +197,10 @@ pub struct Surface(wl_surface::WlSurface);

impl Surface {
pub fn new<D>(
compositor: &impl ProvidesBoundGlobal<wl_compositor::WlCompositor, 6>,
compositor: &impl ProvidesBoundGlobal<
wl_compositor::WlCompositor,
{ CompositorState::API_VERSION_MAX },
>,
qh: &QueueHandle<D>,
) -> Result<Self, GlobalError>
where
Expand All @@ -201,7 +210,10 @@ impl Surface {
}

pub fn with_data<D, U>(
compositor: &impl ProvidesBoundGlobal<wl_compositor::WlCompositor, 6>,
compositor: &impl ProvidesBoundGlobal<
wl_compositor::WlCompositor,
{ CompositorState::API_VERSION_MAX },
>,
qh: &QueueHandle<D>,
data: U,
) -> Result<Self, GlobalError>
Expand Down Expand Up @@ -388,7 +400,10 @@ pub struct Region(wl_region::WlRegion);

impl Region {
pub fn new(
compositor: &impl ProvidesBoundGlobal<wl_compositor::WlCompositor, 6>,
compositor: &impl ProvidesBoundGlobal<
wl_compositor::WlCompositor,
{ CompositorState::API_VERSION_MAX },
>,
) -> Result<Region, GlobalError> {
compositor
.bound_global()
Expand Down Expand Up @@ -447,7 +462,9 @@ where
}
}

impl ProvidesBoundGlobal<wl_compositor::WlCompositor, 6> for CompositorState {
impl ProvidesBoundGlobal<wl_compositor::WlCompositor, { CompositorState::API_VERSION_MAX }>
for CompositorState
{
fn bound_global(&self) -> Result<wl_compositor::WlCompositor, GlobalError> {
Ok(self.wl_compositor.clone())
}
Expand Down
16 changes: 11 additions & 5 deletions src/shell/xdg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -54,7 +60,7 @@ impl XdgShell {
+ Dispatch<zxdg_decoration_manager_v1::ZxdgDecorationManagerV1, GlobalData, State>
+ '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 })
}
Expand Down Expand Up @@ -168,7 +174,7 @@ pub struct XdgPositioner(xdg_positioner::XdgPositioner);

impl XdgPositioner {
pub fn new(
wm_base: &impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, 5>,
wm_base: &impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, { XdgShell::API_VERSION_MAX }>,
) -> Result<Self, GlobalError> {
wm_base
.bound_global()
Expand Down Expand Up @@ -240,7 +246,7 @@ impl XdgShellSurface {
/// [`XdgSurface`]: xdg_surface::XdgSurface
/// [`WlSurface`]: wl_surface::WlSurface
pub fn new<U, D>(
wm_base: &impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, 5>,
wm_base: &impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, { XdgShell::API_VERSION_MAX }>,
qh: &QueueHandle<D>,
surface: impl Into<Surface>,
udata: U,
Expand Down Expand Up @@ -310,11 +316,11 @@ impl Drop for XdgShellSurface {
// Version 5 adds the wm_capabilities event, which is a break
impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, 5> for XdgShell {
fn bound_global(&self) -> Result<xdg_wm_base::XdgWmBase, GlobalError> {
Ok(self.xdg_wm_base.clone())
<Self as ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, 6>>::bound_global(self)
}
}

impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, 6> for XdgShell {
impl ProvidesBoundGlobal<xdg_wm_base::XdgWmBase, { XdgShell::API_VERSION_MAX }> for XdgShell {
fn bound_global(&self) -> Result<xdg_wm_base::XdgWmBase, GlobalError> {
Ok(self.xdg_wm_base.clone())
}
Expand Down

0 comments on commit 4c94ed5

Please sign in to comment.