Skip to main content

smithay_client_toolkit/shell/wlr_layer/
dispatch.rs

1use wayland_client::{Connection, QueueHandle};
2use wayland_protocols_wlr::layer_shell::v1::client::{zwlr_layer_shell_v1, zwlr_layer_surface_v1};
3
4use crate::{
5    dispatch2::Dispatch2,
6    error::GlobalError,
7    globals::{GlobalData, ProvidesBoundGlobal},
8};
9
10use super::{LayerShell, LayerShellHandler, LayerSurface, LayerSurfaceConfigure, LayerSurfaceData};
11
12// Layer shell has only added requests and enum variants in versions 2-4, so its client-facing API
13// is still compatible.
14impl ProvidesBoundGlobal<zwlr_layer_shell_v1::ZwlrLayerShellV1, 1> for LayerShell {
15    fn bound_global(&self) -> Result<zwlr_layer_shell_v1::ZwlrLayerShellV1, GlobalError> {
16        Ok(self.wlr_layer_shell.clone())
17    }
18}
19
20impl ProvidesBoundGlobal<zwlr_layer_shell_v1::ZwlrLayerShellV1, 2> for LayerShell {
21    fn bound_global(&self) -> Result<zwlr_layer_shell_v1::ZwlrLayerShellV1, GlobalError> {
22        Ok(self.wlr_layer_shell.clone())
23    }
24}
25
26impl ProvidesBoundGlobal<zwlr_layer_shell_v1::ZwlrLayerShellV1, 3> for LayerShell {
27    fn bound_global(&self) -> Result<zwlr_layer_shell_v1::ZwlrLayerShellV1, GlobalError> {
28        Ok(self.wlr_layer_shell.clone())
29    }
30}
31
32impl ProvidesBoundGlobal<zwlr_layer_shell_v1::ZwlrLayerShellV1, 4> for LayerShell {
33    fn bound_global(&self) -> Result<zwlr_layer_shell_v1::ZwlrLayerShellV1, GlobalError> {
34        Ok(self.wlr_layer_shell.clone())
35    }
36}
37
38impl<D> Dispatch2<zwlr_layer_shell_v1::ZwlrLayerShellV1, D> for GlobalData
39where
40    D: LayerShellHandler + 'static,
41{
42    fn event(
43        &self,
44        _: &mut D,
45        _: &zwlr_layer_shell_v1::ZwlrLayerShellV1,
46        _: zwlr_layer_shell_v1::Event,
47        _: &Connection,
48        _: &QueueHandle<D>,
49    ) {
50        unreachable!("zwlr_layer_shell_v1 has no events")
51    }
52}
53
54impl<D> Dispatch2<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, D> for LayerSurfaceData
55where
56    D: LayerShellHandler + 'static,
57{
58    fn event(
59        &self,
60        data: &mut D,
61        surface: &zwlr_layer_surface_v1::ZwlrLayerSurfaceV1,
62        event: zwlr_layer_surface_v1::Event,
63        conn: &Connection,
64        qh: &QueueHandle<D>,
65    ) {
66        if let Some(layer_surface) = LayerSurface::from_wlr_surface(surface) {
67            match event {
68                zwlr_layer_surface_v1::Event::Configure { serial, width, height } => {
69                    surface.ack_configure(serial);
70
71                    let configure = LayerSurfaceConfigure { new_size: (width, height) };
72                    data.configure(conn, qh, &layer_surface, configure, serial);
73                }
74
75                zwlr_layer_surface_v1::Event::Closed => {
76                    data.closed(conn, qh, &layer_surface);
77                }
78
79                _ => unreachable!(),
80            }
81        }
82    }
83}