From 60558e18fd7a423739efac21c6b9972f89e9633d Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 22 Nov 2024 19:10:58 -0500 Subject: [PATCH] overlay-notify: Implement handler --- src/main.rs | 2 ++ src/state.rs | 5 +++ src/wayland/handlers/mod.rs | 1 + src/wayland/handlers/overlap_notify.rs | 42 +++++++++++++++++++++++++ src/wayland/protocols/overlap_notify.rs | 20 ++++++++++-- 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/wayland/handlers/overlap_notify.rs diff --git a/src/main.rs b/src/main.rs index 4c9c4860..aba0727e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use anyhow::{Context, Result}; use state::State; use std::{env, ffi::OsString, os::unix::process::CommandExt, process, sync::Arc}; use tracing::{error, info, warn}; +use wayland::protocols::overlap_notify::OverlapNotifyState; use crate::wayland::handlers::compositor::client_compositor_state; @@ -131,6 +132,7 @@ fn main() -> Result<()> { } state.common.refresh(); state::Common::refresh_focus(state); + OverlapNotifyState::refresh(state); state.common.update_x11_stacking_order(); { diff --git a/src/state.rs b/src/state.rs index 9d71fbae..fc2ba06e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -18,6 +18,7 @@ use crate::{ image_source::ImageSourceState, output_configuration::OutputConfigurationState, output_power::OutputPowerState, + overlap_notify::OverlapNotifyState, screencopy::ScreencopyState, toplevel_info::ToplevelInfoState, toplevel_management::{ManagementCapabilities, ToplevelManagementState}, @@ -219,6 +220,7 @@ pub struct Common { pub viewporter_state: ViewporterState, pub kde_decoration_state: KdeDecorationState, pub xdg_decoration_state: XdgDecorationState, + pub overlap_notify_state: OverlapNotifyState, // shell-related wayland state pub xdg_shell_state: XdgShellState, @@ -499,6 +501,8 @@ impl State { let output_state = OutputManagerState::new_with_xdg_output::(dh); let output_configuration_state = OutputConfigurationState::new(dh, client_is_privileged); let output_power_state = OutputPowerState::new::(dh, client_is_privileged); + let overlap_notify_state = + OverlapNotifyState::new::(dh, client_has_no_security_context); let presentation_state = PresentationState::new::(dh, clock.id() as u32); let primary_selection_state = PrimarySelectionState::new::(dh); let image_source_state = ImageSourceState::new::(dh, client_is_privileged); @@ -609,6 +613,7 @@ impl State { output_state, output_configuration_state, output_power_state, + overlap_notify_state, presentation_state, primary_selection_state, data_control_state, diff --git a/src/wayland/handlers/mod.rs b/src/wayland/handlers/mod.rs index 52414103..870d74e2 100644 --- a/src/wayland/handlers/mod.rs +++ b/src/wayland/handlers/mod.rs @@ -21,6 +21,7 @@ pub mod layer_shell; pub mod output; pub mod output_configuration; pub mod output_power; +pub mod overlap_notify; pub mod pointer_constraints; pub mod pointer_gestures; pub mod presentation; diff --git a/src/wayland/handlers/overlap_notify.rs b/src/wayland/handlers/overlap_notify.rs new file mode 100644 index 00000000..7b948653 --- /dev/null +++ b/src/wayland/handlers/overlap_notify.rs @@ -0,0 +1,42 @@ +use smithay::{ + desktop::{layer_map_for_output, LayerSurface, WindowSurfaceType}, + output::Output, + reexports::wayland_protocols_wlr::layer_shell::v1::server::zwlr_layer_surface_v1::ZwlrLayerSurfaceV1, +}; + +use crate::{ + state::State, + wayland::protocols::overlap_notify::{ + delegate_overlap_notify, OverlapNotifyHandler, OverlapNotifyState, + }, +}; + +impl OverlapNotifyHandler for State { + fn overlap_notify_state(&mut self) -> &mut OverlapNotifyState { + &mut self.common.overlap_notify_state + } + + fn layer_surface_from_resource(&self, resource: ZwlrLayerSurfaceV1) -> Option { + self.common + .layer_shell_state + .layer_surfaces() + .find(|l| l.shell_surface() == &resource) + .and_then(|l| { + let shell = self.common.shell.read().unwrap(); + let outputs = shell.outputs(); + let ret = outputs.map(|o| layer_map_for_output(o)).find_map(|s| { + s.layer_for_surface(l.wl_surface(), WindowSurfaceType::ALL) + .cloned() + }); + drop(shell); + ret + }) + } + + fn outputs(&self) -> impl Iterator { + let shell = self.common.shell.read().unwrap(); + shell.outputs().cloned().collect::>().into_iter() + } +} + +delegate_overlap_notify!(State); diff --git a/src/wayland/protocols/overlap_notify.rs b/src/wayland/protocols/overlap_notify.rs index 69f3eb43..4298b6ef 100644 --- a/src/wayland/protocols/overlap_notify.rs +++ b/src/wayland/protocols/overlap_notify.rs @@ -36,6 +36,7 @@ use super::toplevel_info::{ ToplevelHandleState, ToplevelInfoGlobalData, ToplevelInfoHandler, ToplevelState, Window, }; +#[derive(Debug)] pub struct OverlapNotifyState { instances: Vec, global: GlobalId, @@ -82,7 +83,7 @@ impl OverlapNotifyState { W: Window + 'static, { for output in state.outputs() { - let map = layer_map_for_output(output); + let map = layer_map_for_output(&output); for layer_surface in map.layers() { if let Some(data) = layer_surface .user_data() @@ -144,7 +145,7 @@ impl OverlapNotifyState { pub trait OverlapNotifyHandler: ToplevelInfoHandler { fn overlap_notify_state(&mut self) -> &mut OverlapNotifyState; fn layer_surface_from_resource(&self, resource: ZwlrLayerSurfaceV1) -> Option; - fn outputs(&self) -> impl Iterator; + fn outputs(&self) -> impl Iterator; } pub struct OverlapNotifyGlobalData { @@ -428,3 +429,18 @@ where } } } + +macro_rules! delegate_overlap_notify { + ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { + smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ + cosmic_protocols::overlap_notify::v1::server::zcosmic_overlap_notify_v1::ZcosmicOverlapNotifyV1: $crate::wayland::protocols::overlap_notify::OverlapNotifyGlobalData + ] => $crate::wayland::protocols::overlap_notify::OverlapNotifyState); + smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ + cosmic_protocols::overlap_notify::v1::server::zcosmic_overlap_notify_v1::ZcosmicOverlapNotifyV1: () + ] => $crate::wayland::protocols::overlap_notify::OverlapNotifyState); + smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ + cosmic_protocols::overlap_notify::v1::server::zcosmic_overlap_notification_v1::ZcosmicOverlapNotificationV1: () + ] => $crate::wayland::protocols::overlap_notify::OverlapNotifyState); + }; +} +pub(crate) use delegate_overlap_notify;