From 3ad4090df87bf5fb621b9b5eafc11fe5a5139d27 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:23:46 +0000 Subject: [PATCH] fix(wm): resize float windows moved across monitors 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. --- komorebi/src/window.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 7e95c1e7c..c6b5437b9 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -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) }