From 0811292de6ecdb15f71408b1c6b5369e5759dcd4 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 29 Oct 2026 09:59:19 -0700 Subject: [PATCH] fix(resize): lay windows out in place for the commands that resize them The pictures that stand for windows while they are moved by an animation are dimmer and softer than the windows: text in the main terminal of a recording of resize commands has its brightest pixels at 180 where the window has 215, and half as many pixels brighter than 140 while the picture is up. Every resize command lays out the windows that it makes bigger or smaller, and repeating them puts a picture over each of them every time, so it is the commands that show it. Windows are put where they go at once while the commands that resize them are handled, as they are with animations off, and one that is on its way somewhere is stopped where it is first. Dragging the edge of a window to resize it is not one of them, and has the pictures that cover the windows that follow it, as it did. Animations of other commands are as they were. --- komorebi/src/live_resize.rs | 62 +++++++++++++++++++++++++++++++++ komorebi/src/process_command.rs | 4 +++ komorebi/src/window.rs | 11 ++++++ 3 files changed, 77 insertions(+) diff --git a/komorebi/src/live_resize.rs b/komorebi/src/live_resize.rs index 013a3b3e..05b9f9ae 100644 --- a/komorebi/src/live_resize.rs +++ b/komorebi/src/live_resize.rs @@ -84,6 +84,46 @@ impl Drop for Snapping { } } +thread_local! { + static IN_PLACE: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// Puts the windows that the thread lays out while it is alive where they go at once, and +/// not by an animation, and not under a picture of them: the commands that resize a window +/// are many and quick, and the picture of a window that is made as big or as small as another +/// is a little dimmer and softer than the window, which is more to be seen of a layout that is +/// animated for every one of them than of a drag, which has its pictures, for what it does to +/// the windows that follow its edge, whichever the animations are. +pub struct InPlace { + previous: bool, +} + +impl InPlace { + #[must_use] + pub fn new() -> Self { + Self { + previous: IN_PLACE.with(|in_place| in_place.replace(true)), + } + } +} + +impl Default for InPlace { + fn default() -> Self { + Self::new() + } +} + +impl Drop for InPlace { + fn drop(&mut self) { + IN_PLACE.with(|in_place| in_place.set(self.previous)); + } +} + +/// Whether the thread is laying windows out in place, for a command that resizes them +pub fn is_in_place() -> bool { + IN_PLACE.with(std::cell::Cell::get) +} + /// How long a window is given to get to where it was sent before it is sent /// somewhere else anyway const IN_FLIGHT: Duration = Duration::from_millis(100); @@ -996,4 +1036,26 @@ mod tests { assert_eq!(drag_origin(&started_from, &now, None), started_from); } + + #[test] + fn windows_are_laid_out_in_place_for_as_long_as_the_guard_lives_on_its_thread_alone() { + assert!(!is_in_place()); + + { + let _outer = InPlace::new(); + assert!(is_in_place()); + + { + let _inner = InPlace::new(); + assert!(is_in_place()); + } + assert!(is_in_place(), "the outer guard is still alive"); + + std::thread::spawn(|| assert!(!is_in_place())) + .join() + .unwrap(); + } + + assert!(!is_in_place()); + } } diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 74486b17..bc839b83 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -73,6 +73,7 @@ use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::current_virtual_desktop; +use crate::live_resize; use crate::monitor::MonitorInformation; use crate::notify_subscribers; use crate::stackbar_manager; @@ -1484,9 +1485,12 @@ impl WindowManager { reply.write_all(response.as_bytes())?; } SocketMessage::ResizeWindowEdge(direction, sizing) => { + let _in_place = live_resize::InPlace::new(); self.resize_window(direction, sizing, self.resize_delta, true)?; } SocketMessage::ResizeWindowAxis(axis, sizing) => { + let _in_place = live_resize::InPlace::new(); + // If the user has a custom layout, allow for the resizing of the primary column // with this signal let workspace = self.focused_workspace_mut()?; diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index fe993223..2f9009a6 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -436,6 +436,17 @@ impl Window { return WindowsApi::position_window(self.hwnd, layout, top, true); } + // a command that resizes windows puts them where they go at once: one that is on its + // way somewhere is stopped where it is, first + if live_resize::is_in_place() { + let key = new_animation_key(GhostDispatcher::PREFIX, self.hwnd.to_string()); + if ANIMATION_MANAGER.lock().in_progress(&key) { + AnimationEngine::cancel(&key); + } + + return WindowsApi::position_window(self.hwnd, layout, top, true); + } + let animation_enabled = ANIMATION_ENABLED_PER_ANIMATION.lock(); let move_enabled = animation_enabled.get(&GhostDispatcher::PREFIX);