From d3016f142c182edf7dd529fe9be7314f6cabd87a Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 19 Dec 2024 16:49:22 +0100 Subject: [PATCH] WIP: Fix visible_output for dnd_icocons --- src/shell/mod.rs | 56 ++++++++++++++++++++++-- src/wayland/handlers/fractional_scale.rs | 1 - src/wayland/handlers/xdg_shell/mod.rs | 4 +- src/xwayland.rs | 1 - 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/shell/mod.rs b/src/shell/mod.rs index e9022c67..2f10579c 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -10,7 +10,10 @@ use std::{ }; use wayland_backend::server::ClientId; -use crate::wayland::{handlers::data_device, protocols::workspace::WorkspaceCapabilities}; +use crate::wayland::{ + handlers::data_device::{self, get_dnd_icon}, + protocols::workspace::WorkspaceCapabilities, +}; use cosmic_comp_config::{ workspace::{WorkspaceLayout, WorkspaceMode}, TileBehavior, @@ -1579,13 +1582,59 @@ impl Shell { .refresh(xdg_activation_state) } - pub fn visible_output_for_surface(&self, surface: &WlSurface) -> Option<&Output> { + pub fn visible_output_for_surface(&self, surface: &WlSurface) -> Option { if let Some(session_lock) = &self.session_lock { return session_lock .surfaces .iter() .find(|(_, v)| v.wl_surface() == surface) - .map(|(k, _)| k); + .map(|(k, _)| k.clone()); + } + + if let Some(output) = self.seats.iter().find_map(|seat| { + let cursor_status = seat + .user_data() + .get::>() + .map(|lock| { + let mut cursor_status = lock.lock().unwrap(); + if let CursorImageStatus::Surface(ref surface) = *cursor_status { + if !surface.alive() { + *cursor_status = CursorImageStatus::default_named(); + } + } + cursor_status.clone() + }) + .unwrap_or(CursorImageStatus::default_named()); + + // cursor + if let CursorImageStatus::Surface(wl_surface) = cursor_status { + if &wl_surface == surface { + return Some(seat.active_output()); + } + } + + //dnd + if let Some(dnd_icon) = get_dnd_icon(seat) { + if &dnd_icon.surface == surface { + return Some(seat.active_output()); + } + } + + // grabs + if let Some(move_grab) = seat.user_data().get::() { + if let Some(grab_state) = move_grab.lock().unwrap().as_ref() { + if grab_state + .element() + .has_surface(surface, WindowSurfaceType::ALL) + { + return Some(seat.active_output()); + } + } + } + + None + }) { + return Some(output); } self.outputs() @@ -1639,6 +1688,7 @@ impl Shell { .any(|e| e.has_surface(surface, WindowSurfaceType::ALL)) }) }) + .cloned() } pub fn workspace_for_surface(&self, surface: &WlSurface) -> Option<(WorkspaceHandle, Output)> { diff --git a/src/wayland/handlers/fractional_scale.rs b/src/wayland/handlers/fractional_scale.rs index b2cf0a08..7d71f731 100644 --- a/src/wayland/handlers/fractional_scale.rs +++ b/src/wayland/handlers/fractional_scale.rs @@ -44,7 +44,6 @@ impl FractionalScaleHandler for State { .read() .unwrap() .visible_output_for_surface(&surface) - .cloned() }) }) .unwrap_or_else(|| { diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index f3a4e5fe..3701dede 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -389,9 +389,7 @@ impl XdgShellHandler for State { &mut self.common.toplevel_info_state, ); - let output = shell - .visible_output_for_surface(surface.wl_surface()) - .cloned(); + let output = shell.visible_output_for_surface(surface.wl_surface()); if let Some(output) = output.as_ref() { shell.refresh_active_space(output, &self.common.xdg_activation_state); } diff --git a/src/xwayland.rs b/src/xwayland.rs index bec87771..d2556afd 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -420,7 +420,6 @@ impl XwmHandler for State { shell .visible_output_for_surface(&wl_surface) .into_iter() - .cloned() .collect::>() } else { shell.outputs().cloned().collect::>()