bitflags::bitflags! {
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct ShellCaps: u32 {
const HW_UPSCALE = 1 << 0;
const ASPECT_HINT_HONORED = 1 << 1;
const POINTER_WARP = 1 << 2;
const POINTER_LOCK = 1 << 3;
const POINTER_CONFINE = 1 << 4;
const RAW_POINTER_MOTION = 1 << 5;
const TEXT_IME = 1 << 6;
const CLIPBOARD = 1 << 7;
const DRAG_DROP = 1 << 8;
const MULTI_WINDOW = 1 << 9;
const WINDOW_POSITION = 1 << 10;
const SERVER_DECORATIONS = 1 << 11;
const FRACTIONAL_SCALE = 1 << 12;
const EVENT_WAIT = 1 << 13;
const TOUCH = 1 << 14;
const PANEL = 1 << 15;
const PANEL_RESERVE = 1 << 16;
const POPUP = 1 << 17;
const TRANSPARENT = 1 << 18;
const POPUP_REPOSITION = 1 << 19;
}
}
impl ShellCaps {
pub const DESKTOP: Self = Self::all();
#[inline]
#[must_use]
pub const fn has_pointer_capture(self) -> bool {
self.intersects(Self::POINTER_LOCK.union(Self::POINTER_CONFINE))
}
#[inline]
#[must_use]
pub const fn has_mouselook(self) -> bool {
self.contains(Self::POINTER_LOCK.union(Self::RAW_POINTER_MOTION))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn mouselook_needs_both_halves() {
assert!(ShellCaps::DESKTOP.has_mouselook());
assert!(!ShellCaps::POINTER_LOCK.has_mouselook());
assert!(!ShellCaps::RAW_POINTER_MOTION.has_mouselook());
assert!((ShellCaps::POINTER_LOCK | ShellCaps::RAW_POINTER_MOTION).has_mouselook());
}
#[test]
fn pointer_capture_is_either_form() {
assert!(ShellCaps::POINTER_LOCK.has_pointer_capture());
assert!(ShellCaps::POINTER_CONFINE.has_pointer_capture());
assert!(!ShellCaps::POINTER_WARP.has_pointer_capture());
assert!(!ShellCaps::empty().has_pointer_capture());
}
#[test]
fn a_wayland_shaped_cap_set_is_expressible() {
let wayland = ShellCaps::HW_UPSCALE
| ShellCaps::POINTER_LOCK
| ShellCaps::POINTER_CONFINE
| ShellCaps::RAW_POINTER_MOTION
| ShellCaps::TEXT_IME
| ShellCaps::CLIPBOARD
| ShellCaps::DRAG_DROP
| ShellCaps::MULTI_WINDOW
| ShellCaps::SERVER_DECORATIONS
| ShellCaps::FRACTIONAL_SCALE
| ShellCaps::EVENT_WAIT;
assert!(wayland.has_mouselook());
assert!(!wayland.contains(ShellCaps::POINTER_WARP));
assert!(!wayland.contains(ShellCaps::ASPECT_HINT_HONORED));
assert!(!wayland.contains(ShellCaps::WINDOW_POSITION));
assert!(!wayland.contains(ShellCaps::TOUCH));
assert!(ShellCaps::DESKTOP.contains(wayland));
assert_eq!(ShellCaps::default(), ShellCaps::empty());
}
}