toplevel-info/mgmt: Update to v2/v3

This commit is contained in:
Victoria Brekenfeld 2024-09-18 16:02:41 +02:00 committed by Victoria Brekenfeld
parent bbda6fb13d
commit 9c7c41c508
11 changed files with 270 additions and 119 deletions

View file

@ -1,6 +1,9 @@
use std::{
borrow::Cow,
sync::atomic::{AtomicBool, Ordering},
sync::{
atomic::{AtomicBool, Ordering},
Mutex,
},
time::Duration,
};
@ -84,6 +87,12 @@ impl PartialEq<X11Surface> for CosmicSurface {
#[derive(Default)]
struct Minimized(AtomicBool);
#[derive(Default)]
struct Sticky(AtomicBool);
#[derive(Default)]
pub struct GlobalGeometry(pub Mutex<Option<Rectangle<i32, Global>>>);
pub const SSD_HEIGHT: i32 = 36;
pub const RESIZE_BORDER: i32 = 10;
@ -130,6 +139,13 @@ impl CosmicSurface {
}
pub fn set_geometry(&self, geo: Rectangle<i32, Global>) {
*self
.0
.user_data()
.get_or_insert_threadsafe(GlobalGeometry::default)
.0
.lock()
.unwrap() = Some(geo);
match self.0.underlying_surface() {
WindowSurface::Wayland(toplevel) => {
toplevel.with_pending_state(|state| state.size = Some(geo.size.as_logical()))
@ -387,6 +403,22 @@ impl CosmicSurface {
}
}
pub fn is_sticky(&self) -> bool {
self.0
.user_data()
.get_or_insert_threadsafe(Sticky::default)
.0
.load(Ordering::SeqCst)
}
pub fn set_sticky(&self, sticky: bool) {
self.0
.user_data()
.get_or_insert_threadsafe(Sticky::default)
.0
.store(sticky, Ordering::SeqCst);
}
pub fn set_suspended(&self, suspended: bool) {
match self.0.underlying_surface() {
WindowSurface::Wayland(window) => window.with_pending_state(|state| {

View file

@ -44,7 +44,6 @@ use smithay::{
utils::{IsAlive, Logical, Point, Rectangle, Serial, Size},
wayland::{
compositor::with_states,
foreign_toplevel_list::ForeignToplevelListState,
seat::WaylandFocus,
session_lock::LockSurface,
shell::wlr_layer::{KeyboardInteractivity, Layer, LayerSurfaceCachedState},
@ -61,11 +60,7 @@ use crate::{
utils::{prelude::*, quirks::WORKSPACE_OVERVIEW_NAMESPACE},
wayland::{
handlers::{
foreign_toplevel_list::{
new_foreign_toplevel, refresh_foreign_toplevels, remove_foreign_toplevel,
},
toplevel_management::minimize_rectangle,
xdg_activation::ActivationContext,
toplevel_management::minimize_rectangle, xdg_activation::ActivationContext,
xdg_shell::popup::get_popup_toplevel,
},
protocols::{
@ -1194,7 +1189,6 @@ impl Common {
);
self.popups.cleanup();
self.toplevel_info_state.refresh(&self.workspace_state);
refresh_foreign_toplevels(&self.shell.read().unwrap());
self.refresh_idle_inhibit();
}
@ -2083,7 +2077,6 @@ impl Shell {
&mut self,
window: &CosmicSurface,
toplevel_info: &mut ToplevelInfoState<State, CosmicSurface>,
foreign_toplevel_list: &mut ForeignToplevelListState,
workspace_state: &mut WorkspaceState<State>,
evlh: &LoopHandle<'static, State>,
) -> Option<KeyboardFocusTarget> {
@ -2166,7 +2159,6 @@ impl Shell {
toplevel_info.new_toplevel(&window, workspace_state);
toplevel_enter_output(&window, &output);
toplevel_enter_workspace(&window, &workspace.handle);
new_foreign_toplevel(&window, foreign_toplevel_list);
let mut workspace_state = workspace_state.update();
@ -2298,7 +2290,6 @@ impl Shell {
surface: &S,
seat: &Seat<State>,
toplevel_info: &mut ToplevelInfoState<State, CosmicSurface>,
foreign_toplevel_list: &mut ForeignToplevelListState,
) where
CosmicSurface: PartialEq<S>,
{
@ -2348,7 +2339,6 @@ impl Shell {
if let Some(surface) = surface {
toplevel_info.remove_toplevel(&surface);
remove_foreign_toplevel(&surface, foreign_toplevel_list);
self.pending_windows.push((surface, seat.clone(), None));
return;
}
@ -3619,6 +3609,7 @@ impl Shell {
let handle = workspace.handle;
for (window, _) in mapped.windows() {
window.set_sticky(true);
toplevel_leave_workspace(&window, &handle);
}
@ -3640,6 +3631,7 @@ impl Shell {
let workspace = &mut set.workspaces[set.active];
for (window, _) in mapped.windows() {
toplevel_enter_workspace(&window, &workspace.handle);
window.set_sticky(false);
}
match mapped