milkyway/src/handlers/wlr_layer_shell.rs

56 lines
1.9 KiB
Rust
Raw Normal View History

use smithay::{
desktop::{layer_map_for_output, LayerSurface},
output::Output,
2026-07-30 14:01:16 -07:00
utils::SERIAL_COUNTER,
wayland::shell::wlr_layer::{KeyboardInteractivity, Layer, WlrLayerShellHandler},
};
use wayland_server::protocol::wl_output::WlOutput;
use crate::State;
impl WlrLayerShellHandler for State {
fn shell_state(&mut self) -> &mut smithay::wayland::shell::wlr_layer::WlrLayerShellState {
&mut self.wlr_layer_shell_state
}
fn new_layer_surface(
&mut self,
surface: smithay::wayland::shell::wlr_layer::LayerSurface,
output: Option<WlOutput>,
layer: smithay::wayland::shell::wlr_layer::Layer,
namespace: String,
) {
let output = output
.as_ref()
.and_then(Output::from_resource)
.unwrap_or_else(|| self.space.outputs().next().unwrap().clone());
let mut map = layer_map_for_output(&output);
2026-07-30 14:01:16 -07:00
let layer_surface = LayerSurface::new(surface.clone(), namespace);
map.map_layer(&layer_surface).unwrap();
surface.send_configure();
2026-07-30 14:01:16 -07:00
let state = layer_surface.cached_state();
if layer_surface.can_receive_keyboard_focus() {
let keyboard = self.seat.get_keyboard().unwrap();
keyboard.set_focus(
self,
Some(surface.wl_surface().clone()),
SERIAL_COUNTER.next_serial(),
);
}
}
fn layer_destroyed(&mut self, surface: smithay::wayland::shell::wlr_layer::LayerSurface) {
if let Some((mut map, layer)) = self.space.outputs().find_map(|o| {
let map = layer_map_for_output(o);
let layer = map
.layers()
.find(|&layer| layer.layer_surface() == &surface)
.cloned();
layer.map(|layer| (map, layer))
}) {
map.unmap_layer(&layer);
}
}
}