filter tiled toplevel states if not supported
This commit is contained in:
parent
b36cfbb392
commit
477f737b95
|
@ -125,6 +125,9 @@ pub const ZXDG_TOPLEVEL_ROLE: &str = "zxdg_toplevel";
|
||||||
/// [xdg_popup]: self::XDG_POPUP_ROLE
|
/// [xdg_popup]: self::XDG_POPUP_ROLE
|
||||||
pub const ZXDG_POPUP_ROLE: &str = "zxdg_popup";
|
pub const ZXDG_POPUP_ROLE: &str = "zxdg_popup";
|
||||||
|
|
||||||
|
/// Constant for toplevel state version checking
|
||||||
|
const XDG_TOPLEVEL_STATE_TILED_SINCE: u32 = 2;
|
||||||
|
|
||||||
macro_rules! xdg_role {
|
macro_rules! xdg_role {
|
||||||
($configure:ty,
|
($configure:ty,
|
||||||
$(#[$attr:meta])* $element:ident {$($(#[$field_attr:meta])* $vis:vis$field:ident:$type:ty),*},
|
$(#[$attr:meta])* $element:ident {$($(#[$field_attr:meta])* $vis:vis$field:ident:$type:ty),*},
|
||||||
|
@ -615,6 +618,39 @@ impl ToplevelStateSet {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Filter the states according to the provided version
|
||||||
|
/// of the [`XdgToplevel`]
|
||||||
|
pub(crate) fn into_filtered_states(self, version: u32) -> Vec<xdg_toplevel::State> {
|
||||||
|
// If the client version supports the tiled states
|
||||||
|
// we can directly return the states which will save
|
||||||
|
// us from allocating another vector
|
||||||
|
if version >= XDG_TOPLEVEL_STATE_TILED_SINCE {
|
||||||
|
return self.states;
|
||||||
|
}
|
||||||
|
|
||||||
|
let is_tiled = |state: &xdg_toplevel::State| {
|
||||||
|
matches!(
|
||||||
|
state,
|
||||||
|
xdg_toplevel::State::TiledTop
|
||||||
|
| xdg_toplevel::State::TiledBottom
|
||||||
|
| xdg_toplevel::State::TiledLeft
|
||||||
|
| xdg_toplevel::State::TiledRight
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
let contains_tiled = self.states.iter().any(|state| is_tiled(state));
|
||||||
|
|
||||||
|
// If the states do not contain a tiled state
|
||||||
|
// we can directly return the states which will save
|
||||||
|
// us from allocating another vector
|
||||||
|
if !contains_tiled {
|
||||||
|
return self.states;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We need to filter out the unsupported states
|
||||||
|
self.states.into_iter().filter(|state| !is_tiled(state)).collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ToplevelStateSet {
|
impl Default for ToplevelStateSet {
|
||||||
|
|
|
@ -519,7 +519,10 @@ pub fn send_toplevel_configure(resource: &xdg_toplevel::XdgToplevel, configure:
|
||||||
let (width, height) = configure.state.size.unwrap_or_default().into();
|
let (width, height) = configure.state.size.unwrap_or_default().into();
|
||||||
// convert the Vec<State> (which is really a Vec<u32>) into Vec<u8>
|
// convert the Vec<State> (which is really a Vec<u32>) into Vec<u8>
|
||||||
let states = {
|
let states = {
|
||||||
let mut states: Vec<xdg_toplevel::State> = configure.state.states.into();
|
let mut states: Vec<xdg_toplevel::State> = configure
|
||||||
|
.state
|
||||||
|
.states
|
||||||
|
.into_filtered_states(resource.as_ref().version());
|
||||||
let ptr = states.as_mut_ptr();
|
let ptr = states.as_mut_ptr();
|
||||||
let len = states.len();
|
let len = states.len();
|
||||||
let cap = states.capacity();
|
let cap = states.capacity();
|
||||||
|
|
|
@ -522,7 +522,10 @@ pub fn send_toplevel_configure(resource: &zxdg_toplevel_v6::ZxdgToplevelV6, conf
|
||||||
let (width, height) = configure.state.size.unwrap_or_default().into();
|
let (width, height) = configure.state.size.unwrap_or_default().into();
|
||||||
// convert the Vec<State> (which is really a Vec<u32>) into Vec<u8>
|
// convert the Vec<State> (which is really a Vec<u32>) into Vec<u8>
|
||||||
let states = {
|
let states = {
|
||||||
let mut states: Vec<xdg_toplevel::State> = configure.state.states.into();
|
let mut states: Vec<xdg_toplevel::State> = configure
|
||||||
|
.state
|
||||||
|
.states
|
||||||
|
.into_filtered_states(resource.as_ref().version());
|
||||||
let ptr = states.as_mut_ptr();
|
let ptr = states.as_mut_ptr();
|
||||||
let len = states.len();
|
let len = states.len();
|
||||||
let cap = states.capacity();
|
let cap = states.capacity();
|
||||||
|
|
Loading…
Reference in New Issue