Skip to content

Commit

Permalink
WIP: Fix visible_output for dnd_icocons
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Dec 19, 2024
1 parent 29ea548 commit d3016f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 8 deletions.
56 changes: 53 additions & 3 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Output> {
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::<Mutex<CursorImageStatus>>()
.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::<SeatMoveGrabState>() {
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()
Expand Down Expand Up @@ -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)> {
Expand Down
1 change: 0 additions & 1 deletion src/wayland/handlers/fractional_scale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ impl FractionalScaleHandler for State {
.read()
.unwrap()
.visible_output_for_surface(&surface)
.cloned()
})
})
.unwrap_or_else(|| {
Expand Down
4 changes: 1 addition & 3 deletions src/wayland/handlers/xdg_shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 0 additions & 1 deletion src/xwayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ impl XwmHandler for State {
shell
.visible_output_for_surface(&wl_surface)
.into_iter()
.cloned()
.collect::<Vec<_>>()
} else {
shell.outputs().cloned().collect::<Vec<_>>()
Expand Down

0 comments on commit d3016f1

Please sign in to comment.