From be1b4ceb10f690febc9449969d4f6cc3f520d265 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 9 Jun 2023 16:26:13 +0200 Subject: [PATCH] shell: Allow querying current vs pending state --- src/shell/element/mod.rs | 20 ++-- src/shell/element/surface.rs | 132 ++++++++++++++-------- src/shell/element/window.rs | 6 +- src/shell/layout/floating/grabs/resize.rs | 2 +- src/shell/layout/floating/mod.rs | 2 +- src/shell/layout/tiling/mod.rs | 6 +- src/shell/workspace.rs | 6 +- src/wayland/handlers/toplevel_info.rs | 6 +- 8 files changed, 111 insertions(+), 69 deletions(-) diff --git a/src/shell/element/mod.rs b/src/shell/element/mod.rs index dd4d1a72..60ea63c3 100644 --- a/src/shell/element/mod.rs +++ b/src/shell/element/mod.rs @@ -247,14 +247,14 @@ impl CosmicMapped { } } - pub fn is_resizing(&self) -> Option { + pub fn is_resizing(&self, pending: bool) -> Option { let window = match &self.element { CosmicMappedInternal::Stack(s) => s.active(), CosmicMappedInternal::Window(w) => w.surface(), _ => unreachable!(), }; - window.is_resizing() + window.is_resizing(pending) } pub fn set_tiled(&self, tiled: bool) { @@ -268,14 +268,14 @@ impl CosmicMapped { } } - pub fn is_tiled(&self) -> Option { + pub fn is_tiled(&self, pending: bool) -> Option { let window = match &self.element { CosmicMappedInternal::Stack(s) => s.active(), CosmicMappedInternal::Window(w) => w.surface(), _ => unreachable!(), }; - window.is_tiled() + window.is_tiled(pending) } pub fn set_fullscreen(&self, fullscreen: bool) { @@ -290,14 +290,14 @@ impl CosmicMapped { } } - pub fn is_fullscreen(&self) -> bool { + pub fn is_fullscreen(&self, pending: bool) -> bool { let window = match &self.element { CosmicMappedInternal::Stack(s) => s.active(), CosmicMappedInternal::Window(w) => w.surface(), _ => unreachable!(), }; - window.is_fullscreen() + window.is_fullscreen(pending) } pub fn set_maximized(&self, maximized: bool) { @@ -312,14 +312,14 @@ impl CosmicMapped { } } - pub fn is_maximized(&self) -> bool { + pub fn is_maximized(&self, pending: bool) -> bool { let window = match &self.element { CosmicMappedInternal::Stack(s) => s.active(), CosmicMappedInternal::Window(w) => w.surface(), _ => unreachable!(), }; - window.is_maximized() + window.is_maximized(pending) } pub fn set_activated(&self, activated: bool) { @@ -334,14 +334,14 @@ impl CosmicMapped { } } - pub fn is_activated(&self) -> bool { + pub fn is_activated(&self, pending: bool) -> bool { let window = match &self.element { CosmicMappedInternal::Stack(s) => s.active(), CosmicMappedInternal::Window(w) => w.surface(), _ => unreachable!(), }; - window.is_activated() + window.is_activated(pending) } pub fn set_geometry(&self, geo: Rectangle) { diff --git a/src/shell/element/surface.rs b/src/shell/element/surface.rs index d02c4083..6b034837 100644 --- a/src/shell/element/surface.rs +++ b/src/shell/element/surface.rs @@ -129,13 +129,21 @@ impl CosmicSurface { } } - pub fn is_activated(&self) -> bool { + pub fn is_activated(&self, pending: bool) -> bool { match self { - CosmicSurface::Wayland(window) => window - .toplevel() - .current_state() - .states - .contains(ToplevelState::Activated), + CosmicSurface::Wayland(window) => { + if pending { + window.toplevel().with_pending_state(|pending| { + pending.states.contains(ToplevelState::Activated) + }) + } else { + window + .toplevel() + .current_state() + .states + .contains(ToplevelState::Activated) + } + } CosmicSurface::X11(surface) => surface.is_activated(), _ => unreachable!(), } @@ -157,29 +165,46 @@ impl CosmicSurface { } } - pub fn is_decorated(&self) -> bool { + pub fn is_decorated(&self, pending: bool) -> bool { match self { - CosmicSurface::Wayland(window) => window - .toplevel() - .current_state() - .decoration_mode - .map(|mode| mode == DecorationMode::ClientSide) - .unwrap_or(true), + CosmicSurface::Wayland(window) => { + if pending { + window.toplevel().with_pending_state(|pending| { + pending + .decoration_mode + .map(|mode| mode == DecorationMode::ClientSide) + .unwrap_or(true) + }) + } else { + window + .toplevel() + .current_state() + .decoration_mode + .map(|mode| mode == DecorationMode::ClientSide) + .unwrap_or(true) + } + } CosmicSurface::X11(surface) => surface.is_decorated(), _ => unreachable!(), } } - pub fn is_resizing(&self) -> Option { + pub fn is_resizing(&self, pending: bool) -> Option { match self { CosmicSurface::Wayland(window) => { - let xdg = window.toplevel(); - Some( - xdg.current_state().states.contains(ToplevelState::Resizing) - || xdg.with_pending_state(|states| { - states.states.contains(ToplevelState::Resizing) - }), - ) + if pending { + Some(window.toplevel().with_pending_state(|pending| { + pending.states.contains(ToplevelState::Resizing) + })) + } else { + Some( + window + .toplevel() + .current_state() + .states + .contains(ToplevelState::Resizing), + ) + } } _ => None, } @@ -198,15 +223,23 @@ impl CosmicSurface { } } - pub fn is_tiled(&self) -> Option { + pub fn is_tiled(&self, pending: bool) -> Option { match self { - CosmicSurface::Wayland(window) => Some( - window - .toplevel() - .current_state() - .states - .contains(ToplevelState::TiledLeft), - ), + CosmicSurface::Wayland(window) => { + if pending { + Some(window.toplevel().with_pending_state(|pending| { + pending.states.contains(ToplevelState::TiledLeft) + })) + } else { + Some( + window + .toplevel() + .current_state() + .states + .contains(ToplevelState::TiledLeft), + ) + } + } _ => None, } } @@ -230,16 +263,20 @@ impl CosmicSurface { } } - pub fn is_fullscreen(&self) -> bool { + pub fn is_fullscreen(&self, pending: bool) -> bool { match self { CosmicSurface::Wayland(window) => { - let xdg = window.toplevel(); - xdg.current_state() - .states - .contains(ToplevelState::Fullscreen) - || xdg.with_pending_state(|state| { - state.states.contains(ToplevelState::Fullscreen) + if pending { + window.toplevel().with_pending_state(|pending| { + pending.states.contains(ToplevelState::Fullscreen) }) + } else { + window + .toplevel() + .current_state() + .states + .contains(ToplevelState::Fullscreen) + } } CosmicSurface::X11(surface) => surface.is_fullscreen(), _ => unreachable!(), @@ -262,15 +299,20 @@ impl CosmicSurface { } } - pub fn is_maximized(&self) -> bool { + pub fn is_maximized(&self, pending: bool) -> bool { match self { CosmicSurface::Wayland(window) => { - let xdg = window.toplevel(); - xdg.current_state() - .states - .contains(ToplevelState::Maximized) - || xdg - .with_pending_state(|state| state.states.contains(ToplevelState::Maximized)) + if pending { + window.toplevel().with_pending_state(|pending| { + pending.states.contains(ToplevelState::Maximized) + }) + } else { + window + .toplevel() + .current_state() + .states + .contains(ToplevelState::Maximized) + } } CosmicSurface::X11(surface) => surface.is_maximized(), _ => unreachable!(), @@ -311,7 +353,7 @@ impl CosmicSurface { _ => unreachable!(), } .map(|size| { - if self.is_decorated() { + if self.is_decorated(false) { size + (0, SSD_HEIGHT).into() } else { size @@ -337,7 +379,7 @@ impl CosmicSurface { _ => unreachable!(), } .map(|size| { - if self.is_decorated() { + if self.is_decorated(false) { size + (0, SSD_HEIGHT).into() } else { size diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 2047efc8..797f65ad 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -107,7 +107,7 @@ impl CosmicWindowInternal { } pub fn has_ssd(&self) -> bool { - !self.window.is_decorated() + !self.window.is_decorated(false) } } @@ -259,7 +259,7 @@ impl Program for CosmicWindowInternal { } fn background_color(&self) -> Color { - if self.window.is_activated() { + if self.window.is_activated(false) { Color { r: 0.1176, g: 0.1176, @@ -281,7 +281,7 @@ impl Program for CosmicWindowInternal { pixels: &mut tiny_skia::PixmapMut<'_>, damage: &[Rectangle], ) { - if !self.window.is_activated() { + if !self.window.is_activated(false) { let mask = self.mask.lock().unwrap(); let mut paint = tiny_skia::Paint::default(); paint.set_color_rgba8(0, 0, 0, 102); diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index 9654f173..b9acd24b 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -226,7 +226,7 @@ impl ResizeSurfaceGrab { // Finish resizing. if let Some(ResizeState::WaitingForCommit(_)) = *resize_state { - if !window.is_resizing().unwrap_or(false) { + if !window.is_resizing(false).unwrap_or(false) { *resize_state = None; } } diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index 15f7b6c4..e00d6fe7 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -158,7 +158,7 @@ impl FloatingLayout { pub fn unmap(&mut self, window: &CosmicMapped) -> bool { #[allow(irrefutable_let_patterns)] - let is_maximized = window.is_maximized(); + let is_maximized = window.is_maximized(true); if !is_maximized { if let Some(location) = self.space.element_location(window) { diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index fcded726..884d8321 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -1415,7 +1415,7 @@ impl TilingLayout { } }, Data::Mapped { mapped, .. } => { - if !(mapped.is_fullscreen() || mapped.is_maximized()) { + if !(mapped.is_fullscreen(true) || mapped.is_maximized(true)) { mapped.set_tiled(true); let internal_geometry = Rectangle::from_loc_and_size( geo.loc + output.geometry().loc, @@ -1460,7 +1460,7 @@ impl TilingLayout { .unwrap() .filter(|node| node.data().is_mapped(None)) .filter(|node| match node.data() { - Data::Mapped { mapped, .. } => mapped.is_activated(), + Data::Mapped { mapped, .. } => mapped.is_activated(false), _ => unreachable!(), }) .map(|node| match node.data() { @@ -1480,7 +1480,7 @@ impl TilingLayout { .unwrap() .filter(|node| node.data().is_mapped(None)) .filter(|node| match node.data() { - Data::Mapped { mapped, .. } => !mapped.is_activated(), + Data::Mapped { mapped, .. } => !mapped.is_activated(false), _ => unreachable!(), }) .map(|node| match node.data() { diff --git a/src/shell/workspace.rs b/src/shell/workspace.rs index dc54b3d8..e00504f0 100644 --- a/src/shell/workspace.rs +++ b/src/shell/workspace.rs @@ -143,7 +143,7 @@ impl Workspace { assert!(was_floating != was_tiling); } - if mapped.is_maximized() || mapped.is_fullscreen() { + if mapped.is_maximized(true) || mapped.is_fullscreen(true) { self.unmaximize_request(&mapped.active_window()); } @@ -324,7 +324,7 @@ impl Workspace { start_data: PointerGrabStartData, edges: ResizeEdge, ) -> Option { - if mapped.is_fullscreen() || mapped.is_maximized() { + if mapped.is_fullscreen(true) || mapped.is_maximized(true) { return None; } @@ -355,7 +355,7 @@ impl Workspace { let mapped = self.element_for_surface(&window)?.clone(); let mut initial_window_location = self.element_geometry(&mapped).unwrap().loc; - if mapped.is_fullscreen() || mapped.is_maximized() { + if mapped.is_fullscreen(true) || mapped.is_maximized(true) { // If surface is maximized then unmaximize it let new_size = self.unmaximize_request(window); let ratio = pos.x / output.geometry().size.w as f64; diff --git a/src/wayland/handlers/toplevel_info.rs b/src/wayland/handlers/toplevel_info.rs index 40905c66..273fec7b 100644 --- a/src/wayland/handlers/toplevel_info.rs +++ b/src/wayland/handlers/toplevel_info.rs @@ -31,15 +31,15 @@ impl Window for CosmicSurface { } fn is_activated(&self) -> bool { - CosmicSurface::is_activated(self) + CosmicSurface::is_activated(self, false) } fn is_maximized(&self) -> bool { - CosmicSurface::is_maximized(self) + CosmicSurface::is_maximized(self, false) } fn is_fullscreen(&self) -> bool { - CosmicSurface::is_fullscreen(self) + CosmicSurface::is_fullscreen(self, false) } fn is_minimized(&self) -> bool {