|
4 | 4 | */ |
5 | 5 |
|
6 | 6 | public class Gala.WindowStateSaver : GLib.Object { |
| 7 | + private const double REQUIRED_AREA_PERCENTAGE_IN_BOUNDS = 5.0; |
| 8 | + |
7 | 9 | [DBus (name = "org.freedesktop.login1.Manager")] |
8 | 10 | private interface LoginManager : Object { |
9 | 11 | public signal void prepare_for_sleep (bool about_to_suspend); |
@@ -125,7 +127,10 @@ public class Gala.WindowStateSaver : GLib.Object { |
125 | 127 | } |
126 | 128 | } |
127 | 129 |
|
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 | + |
129 | 134 | track_window (window, app_id); |
130 | 135 | return; |
131 | 136 | } |
@@ -159,6 +164,22 @@ public class Gala.WindowStateSaver : GLib.Object { |
159 | 164 | save_all_windows_state (); |
160 | 165 | } |
161 | 166 |
|
| 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 | + |
162 | 183 | private static void track_window (Meta.Window window, string app_id) { |
163 | 184 | window.unmanaging.connect (save_window_state); |
164 | 185 | } |
|
0 commit comments