gpui/platform/linux/wayland/
layer_shell.rs

1use bitflags::bitflags;
2use thiserror::Error;
3use wayland_protocols_wlr::layer_shell::v1::client::{zwlr_layer_shell_v1, zwlr_layer_surface_v1};
4
5use crate::Pixels;
6
7/// The layer the surface is rendered on. Multiple surfaces can share a layer, and ordering within
8/// a single layer is undefined.
9#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
10pub enum Layer {
11    /// The background layer, typically used for wallpapers.
12    Background,
13
14    /// The bottom layer.
15    Bottom,
16
17    /// The top layer, typically used for fullscreen windows.
18    Top,
19
20    /// The overlay layer, used for surfaces that should always be on top.
21    #[default]
22    Overlay,
23}
24
25impl From<Layer> for zwlr_layer_shell_v1::Layer {
26    fn from(layer: Layer) -> Self {
27        match layer {
28            Layer::Background => Self::Background,
29            Layer::Bottom => Self::Bottom,
30            Layer::Top => Self::Top,
31            Layer::Overlay => Self::Overlay,
32        }
33    }
34}
35
36bitflags! {
37    /// Screen anchor point for layer_shell surfaces. These can be used in any combination, e.g.
38    /// specifying `Anchor::LEFT | Anchor::RIGHT` will stretch the surface across the width of the
39    /// screen.
40    #[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
41    pub struct Anchor: u32 {
42        /// Anchor to the top edge of the screen.
43        const TOP = 1;
44        /// Anchor to the bottom edge of the screen.
45        const BOTTOM = 2;
46        /// Anchor to the left edge of the screen.
47        const LEFT = 4;
48        /// Anchor to the right edge of the screen.
49        const RIGHT = 8;
50    }
51}
52
53impl From<Anchor> for zwlr_layer_surface_v1::Anchor {
54    fn from(anchor: Anchor) -> Self {
55        Self::from_bits_truncate(anchor.bits())
56    }
57}
58
59/// Keyboard interactivity mode for the layer_shell surfaces.
60#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
61pub enum KeyboardInteractivity {
62    /// No keyboard inputs will be delivered to the surface and it won't be able to receive
63    /// keyboard focus.
64    None,
65
66    /// The surface will receive exclusive keyboard focus as long as it is above the shell surface
67    /// layer, and no other layer_shell surfaces are above it.
68    Exclusive,
69
70    /// The surface can be focused similarly to a normal window.
71    #[default]
72    OnDemand,
73}
74
75impl From<KeyboardInteractivity> for zwlr_layer_surface_v1::KeyboardInteractivity {
76    fn from(value: KeyboardInteractivity) -> Self {
77        match value {
78            KeyboardInteractivity::None => Self::None,
79            KeyboardInteractivity::Exclusive => Self::Exclusive,
80            KeyboardInteractivity::OnDemand => Self::OnDemand,
81        }
82    }
83}
84
85/// Options for creating a layer_shell window.
86#[derive(Clone, Debug, Default, PartialEq, Eq)]
87pub struct LayerShellOptions {
88    /// The namespace for the surface, mostly used by compositors to apply rules, can not be
89    /// changed after the surface is created.
90    pub namespace: String,
91    /// The layer the surface is rendered on.
92    pub layer: Layer,
93    /// The anchor point of the surface.
94    pub anchor: Anchor,
95    /// Requests that the compositor avoids occluding an area with other surfaces.
96    pub exclusive_zone: Option<Pixels>,
97    /// The anchor point of the exclusive zone, will be determined using the anchor if left
98    /// unspecified.
99    pub exclusive_edge: Option<Anchor>,
100    /// Margins between the surface and its anchor point(s).
101    /// Specified in CSS order: top, right, bottom, left.
102    pub margin: Option<(Pixels, Pixels, Pixels, Pixels)>,
103    /// How keyboard events should be delivered to the surface.
104    pub keyboard_interactivity: KeyboardInteractivity,
105}
106
107/// An error indicating that an action failed because the compositor doesn't support the required
108/// layer_shell protocol.
109#[derive(Debug, Error)]
110#[error("Compositor doesn't support zwlr_layer_shell_v1")]
111pub struct LayerShellNotSupportedError;