toplevel-info/mgmt: Update to v2/v3
This commit is contained in:
parent
bbda6fb13d
commit
9c7c41c508
11 changed files with 270 additions and 119 deletions
|
|
@ -265,7 +265,6 @@ 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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,67 +1,13 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use crate::{
|
||||
shell::{CosmicSurface, Shell},
|
||||
state::State,
|
||||
};
|
||||
use crate::{state::State, wayland::protocols::toplevel_info::ToplevelInfoHandler};
|
||||
use smithay::wayland::foreign_toplevel_list::{
|
||||
ForeignToplevelHandle, ForeignToplevelListHandler, ForeignToplevelListState,
|
||||
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();
|
||||
}
|
||||
}
|
||||
&mut self.toplevel_info_state_mut().foreign_toplevel_list
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use smithay::utils::user_data::UserDataMap;
|
||||
use smithay::utils::{user_data::UserDataMap, Rectangle};
|
||||
|
||||
use crate::{
|
||||
shell::CosmicSurface,
|
||||
shell::{element::surface::GlobalGeometry, CosmicSurface},
|
||||
state::State,
|
||||
utils::prelude::Global,
|
||||
wayland::protocols::toplevel_info::{
|
||||
delegate_toplevel_info, ToplevelInfoHandler, ToplevelInfoState, Window,
|
||||
},
|
||||
|
|
@ -46,6 +47,20 @@ impl Window for CosmicSurface {
|
|||
CosmicSurface::is_minimized(self)
|
||||
}
|
||||
|
||||
fn is_sticky(&self) -> bool {
|
||||
CosmicSurface::is_sticky(&self)
|
||||
}
|
||||
|
||||
fn global_geometry(&self) -> Option<Rectangle<i32, Global>> {
|
||||
self.user_data()
|
||||
.get_or_insert(GlobalGeometry::default)
|
||||
.0
|
||||
.lock()
|
||||
.unwrap()
|
||||
.clone()
|
||||
.filter(|_| !self.is_minimized())
|
||||
}
|
||||
|
||||
fn user_data(&self) -> &UserDataMap {
|
||||
CosmicSurface::user_data(self)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -228,6 +228,34 @@ impl ToplevelManagementHandler for State {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn set_sticky(&mut self, _dh: &DisplayHandle, window: &<Self as ToplevelInfoHandler>::Window) {
|
||||
if window.is_sticky() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut shell = self.common.shell.write().unwrap();
|
||||
if let Some(mapped) = shell.element_for_surface(window).cloned() {
|
||||
let seat = shell.seats.last_active().clone();
|
||||
shell.toggle_sticky(&seat, &mapped);
|
||||
}
|
||||
}
|
||||
|
||||
fn unset_sticky(
|
||||
&mut self,
|
||||
_dh: &DisplayHandle,
|
||||
window: &<Self as ToplevelInfoHandler>::Window,
|
||||
) {
|
||||
if !window.is_sticky() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut shell = self.common.shell.write().unwrap();
|
||||
if let Some(mapped) = shell.element_for_surface(window).cloned() {
|
||||
let seat = shell.seats.last_active().clone();
|
||||
shell.toggle_sticky(&seat, &mapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ManagementWindow for CosmicSurface {
|
||||
|
|
|
|||
|
|
@ -387,7 +387,6 @@ impl XdgShellHandler for State {
|
|||
surface.wl_surface(),
|
||||
&seat,
|
||||
&mut self.common.toplevel_info_state,
|
||||
&mut self.common.foreign_toplevel_list,
|
||||
);
|
||||
|
||||
let output = shell
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue