From 598b7efa74504efa42cf197b0875397f451bb9b6 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Wed, 3 Jul 2024 17:55:44 -0500 Subject: [PATCH] Invalidate snapshots when swapping windows Hack to make the snapshot location correct --- src/grab/move_grab.rs | 8 ++++++++ src/layout.rs | 1 - src/render/util/snapshot.rs | 15 ++++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/grab/move_grab.rs b/src/grab/move_grab.rs index b21bece..57e65b5 100644 --- a/src/grab/move_grab.rs +++ b/src/grab/move_grab.rs @@ -165,6 +165,14 @@ impl PointerGrab for MoveSurfaceGrab { let output = self.window.output(&state.pinnacle); + // HACK: Snapshots may not be cleared and updated when swapping two windows of the same size; + // this causes new snapshots attempts to fizzle and the currently stored snapshot + // will have the wrong location. We're just gonna invalidate all window snapshots here + // because I'm too lazy to rearchitect stuff to make it more sensible. + for window in state.pinnacle.windows.iter() { + window.with_state_mut(|state| state.snapshot.take()); + } + if let Some(output) = output.as_ref() { state.capture_snapshots_on_output(output, [self.window.clone()]); } diff --git a/src/layout.rs b/src/layout.rs index 4a1f311..ac882fc 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -128,7 +128,6 @@ impl Pinnacle { pending_wins } - /// Swaps two windows in the main window vec and updates all windows. pub fn swap_window_positions(&mut self, win1: &WindowElement, win2: &WindowElement) { let win1_index = self.windows.iter().position(|win| win == win1); let win2_index = self.windows.iter().position(|win| win == win2); diff --git a/src/render/util/snapshot.rs b/src/render/util/snapshot.rs index fa10995..a019e54 100644 --- a/src/render/util/snapshot.rs +++ b/src/render/util/snapshot.rs @@ -132,19 +132,16 @@ impl WindowElement { location: Point, scale: Scale, alpha: f32, - ) -> LayoutSnapshot { + ) -> Option { self.with_state_mut(|state| { if state.snapshot.is_none() || self.is_x11() { let elements = self.texture_render_elements(renderer, location, scale, alpha); - - state.snapshot = Some(RenderSnapshot::new(elements, scale)); + if !elements.is_empty() { + state.snapshot = Some(RenderSnapshot::new(elements, scale)); + } } - let Some(ret) = state.snapshot.clone() else { - unreachable!() - }; - - ret + state.snapshot.clone() }) } } @@ -212,7 +209,7 @@ pub fn capture_snapshots_on_output( 1.0, ); - Some(SnapshotTarget::Snapshot(snapshot)) + snapshot.map(SnapshotTarget::Snapshot) } else { Some(SnapshotTarget::Window(win)) }