shell: Handle unmapped windows correctly

This commit is contained in:
Victoria Brekenfeld 2024-03-21 12:53:52 +01:00 committed by Victoria Brekenfeld
parent aaa40df963
commit 973cfed87b
8 changed files with 175 additions and 51 deletions

View file

@ -22,7 +22,7 @@ use smithay::{
ImportAll, ImportMem, Renderer,
},
},
desktop::{space::SpaceElement, PopupManager, WindowSurface, WindowSurfaceType},
desktop::{space::SpaceElement, PopupManager, WindowSurfaceType},
input::{
keyboard::{KeyboardTarget, KeysymHandle, ModifiersState},
pointer::{

View file

@ -235,18 +235,18 @@ impl CosmicStack {
self.0.force_redraw()
}
pub fn remove_idx(&self, idx: usize) {
self.0.with_program(|p| {
pub fn remove_idx(&self, idx: usize) -> Option<CosmicSurface> {
let window = self.0.with_program(|p| {
let mut windows = p.windows.lock().unwrap();
if windows.len() == 1 {
p.override_alive.store(false, Ordering::SeqCst);
let window = windows.get(0).unwrap();
window.try_force_undecorated(false);
window.set_tiled(false);
return;
return Some(window.clone());
}
if windows.len() <= idx {
return;
return None;
}
if idx == p.active.load(Ordering::SeqCst) {
p.reenter.store(true, Ordering::SeqCst);
@ -256,8 +256,11 @@ impl CosmicStack {
window.set_tiled(false);
p.active.fetch_min(windows.len() - 1, Ordering::SeqCst);
Some(window)
});
self.0.force_redraw()
self.0.force_redraw();
window
}
pub fn len(&self) -> usize {

View file

@ -232,6 +232,10 @@ impl MoveGrabState {
.collect()
}
pub fn element(&self) -> CosmicMapped {
self.window.clone()
}
pub fn window(&self) -> CosmicSurface {
self.window.active_window()
}

View file

@ -29,7 +29,7 @@ use smithay::{
},
wayland_server::{protocol::wl_surface::WlSurface, Client, DisplayHandle},
},
utils::{Logical, Point, Rectangle, Serial, Size, SERIAL_COUNTER},
utils::{IsAlive, Logical, Point, Rectangle, Serial, Size, SERIAL_COUNTER},
wayland::{
compositor::with_states,
seat::WaylandFocus,
@ -262,7 +262,7 @@ impl WorkspaceDelta {
#[derive(Debug)]
pub struct WorkspaceSet {
previously_active: Option<(usize, WorkspaceDelta)>,
active: usize,
pub active: usize,
pub group: WorkspaceGroupHandle,
idx: usize,
tiling_enabled: bool,
@ -1682,6 +1682,9 @@ impl Shell {
.iter()
.for_each(|or| or.refresh());
self.pending_layers.retain(|(s, _, _)| s.alive());
self.pending_windows.retain(|(s, _, _)| s.alive());
self.toplevel_info_state
.refresh(Some(&self.workspace_state));
}
@ -1994,6 +1997,62 @@ impl Shell {
}
}
pub fn unmap_surface<S>(&mut self, surface: &S, seat: &Seat<State>)
where
CosmicSurface: PartialEq<S>,
{
for set in self.workspaces.sets.values_mut() {
let sticky_res = set.sticky_layer.mapped().find_map(|m| {
m.windows()
.position(|(s, _)| &s == surface)
.map(|idx| (idx, m.clone()))
});
let surface = if let Some((idx, mut mapped)) = sticky_res {
if mapped.is_stack() {
mapped.stack_ref_mut().unwrap().remove_idx(idx)
} else {
set.sticky_layer.unmap(&mapped);
Some(mapped.active_window())
}
} else if let Some(idx) = set
.minimized_windows
.iter()
.map(|w| &w.window)
.position(|w| w.windows().any(|(s, _)| &s == surface))
{
if set.minimized_windows.get(idx).unwrap().window.is_stack() {
let window = &mut set.minimized_windows.get_mut(idx).unwrap().window;
let stack = window.stack_ref_mut().unwrap();
let idx = stack.surfaces().position(|s| &s == surface);
idx.and_then(|idx| stack.remove_idx(idx))
} else {
Some(set.minimized_windows.remove(idx).window.active_window())
}
} else if let Some((workspace, mut elem)) = set.workspaces.iter_mut().find_map(|w| {
w.element_for_surface(&surface)
.cloned()
.map(|elem| (w, elem))
}) {
if elem.is_stack() {
let stack = elem.stack_ref_mut().unwrap();
let idx = stack.surfaces().position(|s| &s == surface);
idx.and_then(|idx| stack.remove_idx(idx))
} else {
workspace.unmap(&elem);
Some(elem.active_window())
}
} else {
None
};
if let Some(surface) = surface {
self.toplevel_info_state.remove_toplevel(&surface);
self.pending_windows.push((surface, seat.clone(), None));
return;
}
}
}
pub fn element_under(
&mut self,
location: Point<f64, Global>,