cosmic-comp/src/wayland/handlers/layer_shell.rs

82 lines
2.4 KiB
Rust
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-only
use crate::{shell::PendingLayer, utils::prelude::*};
use smithay::{
2022-07-04 16:00:29 +02:00
delegate_layer_shell,
desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType},
output::Output,
2022-08-31 13:01:23 +02:00
reexports::wayland_server::protocol::wl_output::WlOutput,
wayland::shell::{
wlr_layer::{
Layer, LayerSurface as WlrLayerSurface, WlrLayerShellHandler, WlrLayerShellState,
},
xdg::PopupSurface,
},
};
impl WlrLayerShellHandler for State {
fn shell_state(&mut self) -> &mut WlrLayerShellState {
2024-04-10 15:49:08 +02:00
&mut self.common.layer_shell_state
}
fn new_layer_surface(
2022-07-04 16:00:29 +02:00
&mut self,
surface: WlrLayerSurface,
wl_output: Option<WlOutput>,
_layer: Layer,
namespace: String,
) {
let mut shell = self.common.shell.write();
2024-04-10 15:49:08 +02:00
let seat = shell.seats.last_active().clone();
let output = wl_output
.as_ref()
.and_then(Output::from_resource)
2022-09-28 12:01:29 +02:00
.unwrap_or_else(|| seat.active_output());
shell.pending_layers.push(PendingLayer {
surface: LayerSurface::new(surface, namespace),
output,
seat,
});
}
2022-07-07 19:45:55 +02:00
2022-08-31 13:01:23 +02:00
fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) {
self.common.shell.read().unconstrain_popup(&popup);
2022-07-07 19:45:55 +02:00
if popup.send_configure().is_ok() {
self.common
.popups
.track_popup(PopupKind::from(popup))
.unwrap();
}
}
fn layer_destroyed(&mut self, surface: WlrLayerSurface) {
let mut shell = self.common.shell.write();
2024-04-10 15:49:08 +02:00
let maybe_output = shell
.outputs()
.find(|o| {
let map = layer_map_for_output(o);
map.layer_for_surface(surface.wl_surface(), WindowSurfaceType::TOPLEVEL)
.is_some()
})
.cloned();
if let Some(output) = maybe_output {
{
let mut map = layer_map_for_output(&output);
let layer = map
.layer_for_surface(surface.wl_surface(), WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
map.unmap_layer(&layer);
}
2024-04-10 15:49:08 +02:00
shell.workspaces.recalculate();
2024-06-10 20:41:29 +02:00
self.backend.schedule_render(&output);
}
}
}
delegate_layer_shell!(State);