Skip to content

Commit c62efad

Browse files
committed
WindowStateSaver: validate saved window position before placing
1 parent 099cd69 commit c62efad

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/WindowStateSaver.vala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
public class Gala.WindowStateSaver : GLib.Object {
7+
private const double REQUIRED_AREA_PERCENTAGE_IN_BOUNDS = 5.0;
8+
79
[DBus (name = "org.freedesktop.login1.Manager")]
810
private interface LoginManager : Object {
911
public signal void prepare_for_sleep (bool about_to_suspend);
@@ -125,7 +127,10 @@ public class Gala.WindowStateSaver : GLib.Object {
125127
}
126128
}
127129

128-
window.move_resize_frame (false, last_x, last_y, last_width, last_height);
130+
if (validate_last_window_position (window.display, { last_x, last_y, last_width, last_height })) {
131+
window.move_resize_frame (true, last_x, last_y, last_width, last_height);
132+
}
133+
129134
track_window (window, app_id);
130135
return;
131136
}
@@ -159,6 +164,22 @@ public class Gala.WindowStateSaver : GLib.Object {
159164
save_all_windows_state ();
160165
}
161166

167+
private static bool validate_last_window_position (Meta.Display display, Mtk.Rectangle position) {
168+
var area_in_bounds = 0;
169+
170+
var n_monitors = display.get_n_monitors ();
171+
for (var i = 0; i < n_monitors; i++) {
172+
var monitor_rect = display.get_monitor_geometry (i);
173+
174+
Mtk.Rectangle intersection;
175+
monitor_rect.intersect (position, out intersection);
176+
177+
area_in_bounds += intersection.area ();
178+
}
179+
180+
return (double) area_in_bounds / position.area () * 100.0 >= REQUIRED_AREA_PERCENTAGE_IN_BOUNDS;
181+
}
182+
162183
private static void track_window (Meta.Window window, string app_id) {
163184
window.unmanaging.connect (save_window_state);
164185
}

0 commit comments

Comments
 (0)