Skip to content

Commit

Permalink
fix(wm): maximized floating windows move across monitors without disa…
Browse files Browse the repository at this point in the history
…ppearing

When moving maximized floating windows across monitors they were
magically disappearing! The window would be on the correct place, with
the correct coordinates and size, its styles wouldn't change it would
still have the `VISIBLE` style, however the window was invisible. If we
used the system move to try to move it sometimes we would be able to see
a bar on the top of the monitor and if we moved the window with the
keyboard on the direction of another monitor then the window would start
showing up on that monitor... So it was visible on that monitor but not
on the one we just moved it into. After some investigation I decided to
atribute that behavior to magic, since I couldn't find any other plausible
explanation, if someone knows about this please tell me, I too would like
to learn the ways of this dark mysteries from the deep of the Windows OS.

On a serious note, this commit creates a workaround for this by simply
unmaximazing the window first (it's not restore, it doesn't change the size)
then it moves the window (if animations are enabled it proceeds to wait
for the animation to finish...), then it maximizes the window again.
  • Loading branch information
alex-ds13 authored and LGUG2Z committed Nov 26, 2024
1 parent 1d00196 commit dc411f7
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::fmt::Formatter;
use std::fmt::Write as _;
use std::sync::atomic::AtomicI32;
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;

use crate::core::config_generation::IdWithIdentifier;
Expand Down Expand Up @@ -182,7 +183,34 @@ impl Window {
//TODO: We might need to take into account the differences in DPI for the new_rect, unless
//we can use the xy ratios above to the right/bottom (width/height of window) as well?

self.set_position(&new_rect, true)
let is_maximized = &new_rect == target_area;
if is_maximized {
windows_api::WindowsApi::unmaximize_window(self.hwnd);
if ANIMATION_ENABLED.load(Ordering::SeqCst) {
let anim_count = ANIMATIONS_IN_PROGRESS.load(Ordering::Acquire);
self.set_position(&new_rect, true)?;
let hwnd = self.hwnd;
// Wait for the animation to finish before maximizing the window again, otherwise
// we would be maximizing the window on the current monitor anyway
thread::spawn(move || {
let mut new_anim_count = ANIMATIONS_IN_PROGRESS.load(Ordering::Acquire);
let mut max_wait = 2000; // Max waiting time. No one will be using an animation longer than 2s, right? RIGHT??? WHY?
while new_anim_count > anim_count && max_wait > 0 {
thread::sleep(Duration::from_millis(1));
new_anim_count = ANIMATIONS_IN_PROGRESS.load(Ordering::Acquire);
max_wait -= 1;
}
windows_api::WindowsApi::maximize_window(hwnd);
});
} else {
self.set_position(&new_rect, true)?;
windows_api::WindowsApi::maximize_window(self.hwnd);
}
} else {
self.set_position(&new_rect, true)?;
}

Ok(())
}

pub fn center(&mut self, work_area: &Rect) -> Result<()> {
Expand Down

0 comments on commit dc411f7

Please sign in to comment.