smithay_client_toolkit/shell/wlr_layer/
dispatch.rs

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