Add ext-foreign-toplevel-list-v1 protocol

This commit is contained in:
Ian Douglas Scott 2024-08-28 15:04:00 -07:00 committed by Victoria Brekenfeld
parent 59b0e0e74e
commit 1342c000ab
9 changed files with 96 additions and 4 deletions

View file

@ -265,6 +265,7 @@ impl State {
let res = shell.map_window(
&window,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
&mut self.common.workspace_state,
&self.common.event_loop_handle,
);

View file

@ -0,0 +1,68 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::{
shell::{CosmicSurface, Shell},
state::State,
};
use smithay::wayland::foreign_toplevel_list::{
ForeignToplevelHandle, ForeignToplevelListHandler, ForeignToplevelListState,
};
use std::sync::Mutex;
impl ForeignToplevelListHandler for State {
fn foreign_toplevel_list_state(&mut self) -> &mut ForeignToplevelListState {
&mut self.common.foreign_toplevel_list
}
}
pub fn new_foreign_toplevel(
window: &CosmicSurface,
foreign_toplevel_list: &mut ForeignToplevelListState,
) {
let toplevel_handle =
foreign_toplevel_list.new_toplevel::<State>(window.title(), window.app_id());
*window
.user_data()
.get_or_insert::<Mutex<Option<ForeignToplevelHandle>>, _>(Default::default)
.lock()
.unwrap() = Some(toplevel_handle);
}
pub fn remove_foreign_toplevel(
window: &CosmicSurface,
foreign_toplevel_list: &mut ForeignToplevelListState,
) {
if let Some(handle) = window
.user_data()
.get::<Mutex<Option<ForeignToplevelHandle>>>()
{
if let Some(handle) = handle.lock().unwrap().take() {
foreign_toplevel_list.remove_toplevel(&handle);
}
}
}
pub fn refresh_foreign_toplevels(shell: &Shell) {
for (window, _) in shell
.workspaces
.spaces()
.flat_map(|workspace| workspace.mapped())
.flat_map(|mapped| mapped.windows())
{
let foreign_toplevel_handle = window
.user_data()
.get::<Mutex<Option<ForeignToplevelHandle>>>()
.and_then(|handle| handle.lock().unwrap().clone());
if let Some(handle) = foreign_toplevel_handle {
let app_id = window.app_id();
let title = window.title();
if handle.app_id() != app_id || handle.title() != title {
handle.send_app_id(&app_id);
handle.send_title(&title);
handle.send_done();
}
}
}
}
smithay::delegate_foreign_toplevel_list!(State);

View file

@ -9,6 +9,7 @@ pub mod decoration;
pub mod dmabuf;
pub mod drm;
pub mod drm_lease;
pub mod foreign_toplevel_list;
pub mod fractional_scale;
pub mod idle_inhibit;
pub mod idle_notify;

View file

@ -379,6 +379,7 @@ impl XdgShellHandler for State {
surface.wl_surface(),
&seat,
&mut self.common.toplevel_info_state,
&mut self.common.foreign_toplevel_list,
);
let output = shell