Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state: send send_frames/primary_output/dmabuf_feedback for dnd surfaces #1080

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
99 changes: 87 additions & 12 deletions src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ use crate::{
input::{gestures::GestureState, PointerFocusState},
shell::{grabs::SeatMoveGrabState, CosmicSurface, SeatExt, Shell},
utils::prelude::OutputExt,
wayland::handlers::screencopy::SessionHolder,
wayland::protocols::{
atspi::AtspiState,
drm::WlDrmState,
image_source::ImageSourceState,
output_configuration::OutputConfigurationState,
output_power::OutputPowerState,
overlap_notify::OverlapNotifyState,
screencopy::ScreencopyState,
toplevel_info::ToplevelInfoState,
toplevel_management::{ManagementCapabilities, ToplevelManagementState},
workspace::{WorkspaceClientState, WorkspaceState, WorkspaceUpdateGuard},
wayland::{
handlers::{data_device::get_dnd_icon, screencopy::SessionHolder},
protocols::{
atspi::AtspiState,
drm::WlDrmState,
image_source::ImageSourceState,
output_configuration::OutputConfigurationState,
output_power::OutputPowerState,
overlap_notify::OverlapNotifyState,
screencopy::ScreencopyState,
toplevel_info::ToplevelInfoState,
toplevel_management::{ManagementCapabilities, ToplevelManagementState},
workspace::{WorkspaceClientState, WorkspaceState, WorkspaceUpdateGuard},
},
},
xwayland::XWaylandState,
};
Expand Down Expand Up @@ -722,6 +724,11 @@ impl Common {
with_surfaces_surface_tree(&wl_surface, processor);
}

//dnd
if let Some(dnd_icon) = get_dnd_icon(seat) {
with_surfaces_surface_tree(&dnd_icon.surface, processor);
}

// grabs
if let Some(move_grab) = seat.user_data().get::<SeatMoveGrabState>() {
if let Some(grab_state) = move_grab.lock().unwrap().as_ref() {
Expand Down Expand Up @@ -807,6 +814,64 @@ impl Common {
.iter()
.filter(|seat| &seat.active_output() == output)
{
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 let Some(feedback) =
advertised_node_for_surface(&wl_surface, &self.display_handle)
.and_then(|source| dmabuf_feedback(source))
{
send_dmabuf_feedback_surface_tree(
&wl_surface,
output,
surface_primary_scanout_output,
|surface, _| {
select_dmabuf_feedback(
surface,
render_element_states,
&feedback.render_feedback,
&feedback.scanout_feedback,
)
},
);
}
}

//dnd
if let Some(dnd_icon) = get_dnd_icon(seat) {
if let Some(feedback) =
advertised_node_for_surface(&dnd_icon.surface, &self.display_handle)
.and_then(|source| dmabuf_feedback(source))
{
send_dmabuf_feedback_surface_tree(
&dnd_icon.surface,
output,
surface_primary_scanout_output,
|surface, _| {
select_dmabuf_feedback(
surface,
render_element_states,
&feedback.render_feedback,
&feedback.scanout_feedback,
)
},
)
}
}

if let Some(move_grab) = seat.user_data().get::<SeatMoveGrabState>() {
if let Some(grab_state) = move_grab.lock().unwrap().as_ref() {
for (window, _) in grab_state.element().windows() {
Expand Down Expand Up @@ -1012,6 +1077,16 @@ impl Common {
)
}

if let Some(dnd_icon) = get_dnd_icon(seat) {
send_frames_surface_tree(
&dnd_icon.surface,
output,
time,
Some(Duration::ZERO),
should_send,
)
}

if let Some(move_grab) = seat.user_data().get::<SeatMoveGrabState>() {
if let Some(grab_state) = move_grab.lock().unwrap().as_ref() {
for (window, _) in grab_state.element().windows() {
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
Loading