2022-07-04 15:26:26 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
2025-02-04 14:33:11 +01:00
|
|
|
use crate::{shell::PendingLayer, utils::prelude::*};
|
2022-07-04 15:26:26 +02:00
|
|
|
use smithay::{
|
2022-07-04 16:00:29 +02:00
|
|
|
delegate_layer_shell,
|
2025-10-16 18:53:57 +02:00
|
|
|
desktop::{LayerSurface, PopupKind, WindowSurfaceType, layer_map_for_output},
|
2022-09-09 20:00:00 -07:00
|
|
|
output::Output,
|
2022-08-31 13:01:23 +02:00
|
|
|
reexports::wayland_server::protocol::wl_output::WlOutput,
|
2022-09-09 20:00:00 -07:00
|
|
|
wayland::shell::{
|
|
|
|
|
wlr_layer::{
|
|
|
|
|
Layer, LayerSurface as WlrLayerSurface, WlrLayerShellHandler, WlrLayerShellState,
|
2022-07-04 15:26:26 +02:00
|
|
|
},
|
2022-09-09 20:00:00 -07:00
|
|
|
xdg::PopupSurface,
|
2022-07-04 15:26:26 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
2022-07-04 15:26:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn new_layer_surface(
|
2022-07-04 16:00:29 +02:00
|
|
|
&mut self,
|
|
|
|
|
surface: WlrLayerSurface,
|
|
|
|
|
wl_output: Option<WlOutput>,
|
|
|
|
|
_layer: Layer,
|
|
|
|
|
namespace: String,
|
2022-07-04 15:26:26 +02:00
|
|
|
) {
|
2025-05-20 17:41:27 +02:00
|
|
|
let mut shell = self.common.shell.write();
|
2024-04-10 15:49:08 +02:00
|
|
|
let seat = shell.seats.last_active().clone();
|
2022-07-04 15:26:26 +02:00
|
|
|
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());
|
2025-02-04 14:33:11 +01:00
|
|
|
shell.pending_layers.push(PendingLayer {
|
|
|
|
|
surface: LayerSurface::new(surface, namespace),
|
|
|
|
|
output,
|
|
|
|
|
seat,
|
|
|
|
|
});
|
2022-07-04 15:26:26 +02:00
|
|
|
}
|
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) {
|
2025-05-20 17:41:27 +02:00
|
|
|
self.common.shell.read().unconstrain_popup(&popup);
|
2022-07-07 19:45:55 +02:00
|
|
|
|
2025-07-31 14:10:34 -04:00
|
|
|
if let Err(err) = popup.send_configure() {
|
|
|
|
|
tracing::warn!("Unable to configure popup. {err:?}",);
|
|
|
|
|
} else {
|
2022-07-07 19:45:55 +02:00
|
|
|
self.common
|
|
|
|
|
.popups
|
|
|
|
|
.track_popup(PopupKind::from(popup))
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-08 10:32:53 +01:00
|
|
|
|
|
|
|
|
fn layer_destroyed(&mut self, surface: WlrLayerSurface) {
|
2025-05-20 17:41:27 +02:00
|
|
|
let mut shell = self.common.shell.write();
|
2024-04-10 15:49:08 +02:00
|
|
|
let maybe_output = shell
|
2022-11-08 10:32:53 +01:00
|
|
|
.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 {
|
2022-11-10 12:51:59 +01:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
2022-11-08 10:32:53 +01:00
|
|
|
|
2024-04-10 15:49:08 +02:00
|
|
|
shell.workspaces.recalculate();
|
2023-07-13 17:40:49 +02:00
|
|
|
|
2024-06-10 20:41:29 +02:00
|
|
|
self.backend.schedule_render(&output);
|
2022-11-08 10:32:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-07-04 15:26:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delegate_layer_shell!(State);
|