Skip to content

Commit

Permalink
fix(wm): resize float windows moved across monitors
Browse files Browse the repository at this point in the history
Previously when moving floating windows across monitors we would keep
the size of the window as it was. For most cases this would be ok.

However for users with monitors with completely different sizes this
could result on a window that would fill across monitors when moving
from the bigger monitor to the smaller monitor.

This commit, attempts to resize the windows proportionally to the
monitors' sizes.

There is currently a slight issue with some apps (so far I've only
noticed it on 'Wezterm'...) where if the DPIs across monitors are
different they don't seem to fully get the OS DPI change completely, but
it seems that setting the `Wezterm` compatibility high DPI scaling
override to "System" on the app's executable properties, fixes the
issue.

Since this is only 1 app (so far...) and only when the scales between
monitors are different I decided to commit this anyway.

This will do more good than harm, since in the cases it was misbehaving
with 'Wezterm' the result would be a wrongly resized window that is
still completely visible on the target monitor anyway and the override
fix seems to be good so far.
  • Loading branch information
alex-ds13 authored and LGUG2Z committed Nov 26, 2024
1 parent 449ccac commit 3ad4090
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,18 @@ impl Window {
let corrected_relative_y = (window_relative_y as f32 * y_ratio) as i32;
let window_x = current_area.left + corrected_relative_x;
let window_y = current_area.top + corrected_relative_y;
let left = x_diff + window_x;
let top = y_diff + window_y;

let corrected_width = (current_rect.right as f32 * x_ratio) as i32;
let corrected_height = (current_rect.bottom as f32 * y_ratio) as i32;

let new_rect = Rect {
left: x_diff + window_x,
top: y_diff + window_y,
right: current_rect.right,
bottom: current_rect.bottom,
left,
top,
right: corrected_width,
bottom: corrected_height,
};
//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)
}
Expand Down

0 comments on commit 3ad4090

Please sign in to comment.