|
1 | 1 | import collections |
2 | 2 | import contextlib |
| 3 | +import dataclasses |
3 | 4 | import enum |
4 | 5 | import functools |
5 | 6 | import logging.handlers |
@@ -90,21 +91,21 @@ def resize_point(frame_rect, window_pos): |
90 | 91 |
|
91 | 92 | def compute_target_rect(size, pos, monitor): |
92 | 93 | x, y, width, height = monitor.workarea |
| 94 | + window_size = WindowSize.get_maximized_size_from_position(size, pos) |
93 | 95 |
|
94 | 96 | round_to = int(monitor.scale) |
95 | 97 |
|
96 | | - if pos in [WindowPosition.TOP, WindowPosition.BOTTOM]: |
97 | | - height *= size |
98 | | - height -= height % round_to |
| 98 | + height *= window_size.height |
| 99 | + height -= height % round_to |
99 | 100 |
|
100 | | - if pos == WindowPosition.BOTTOM: |
101 | | - y += monitor.workarea.height - height |
102 | | - else: |
103 | | - width *= size |
104 | | - width -= width % round_to |
| 101 | + if pos == WindowPosition.BOTTOM: |
| 102 | + y += monitor.workarea.height - height |
105 | 103 |
|
106 | | - if pos == WindowPosition.RIGHT: |
107 | | - x += monitor.workarea.width - width |
| 104 | + width *= window_size.width |
| 105 | + width -= width % round_to |
| 106 | + |
| 107 | + if pos == WindowPosition.RIGHT: |
| 108 | + x += monitor.workarea.width - width |
108 | 109 |
|
109 | 110 | return Rect(x, y, width, height) |
110 | 111 |
|
@@ -139,6 +140,41 @@ def verify_window_geometry(test_interface, size, maximize, pos, monitor): |
139 | 140 | else: |
140 | 141 | assert actual_frame_rect == target_rect_unmaximized |
141 | 142 |
|
| 143 | +@dataclasses.dataclass |
| 144 | +class WindowSize: |
| 145 | + width: float |
| 146 | + height: float |
| 147 | + position: WindowPosition |
| 148 | + |
| 149 | + _HORIZONTAL_SIZE_POSITIONS = [WindowPosition.TOP, WindowPosition.BOTTOM] |
| 150 | + |
| 151 | + def get_primary_size(self) -> float: |
| 152 | + return self.width if self.position in self._HORIZONTAL_SIZE_POSITIONS else self.height |
| 153 | + |
| 154 | + @classmethod |
| 155 | + def get_primary_size_setting(cls, position: WindowPosition) -> str: |
| 156 | + return "window-hsize" if position in cls._HORIZONTAL_SIZE_POSITIONS else "window-vsize" |
| 157 | + |
| 158 | + @classmethod |
| 159 | + def get_maximized_size_from_position(cls, primary_size: float, position: WindowPosition) -> "WindowSize": |
| 160 | + """ |
| 161 | + Get window horizontal/vertical size based on the given position. |
| 162 | +
|
| 163 | + On top/bottom positions, primary size is horizontal. |
| 164 | + On left/right positions, primary size is vertical. |
| 165 | +
|
| 166 | + This is a simplified helper to get a secondary size set to 100% for now, until tests |
| 167 | + are updated/added to support secondary size as well. |
| 168 | + """ |
| 169 | + if position in cls._HORIZONTAL_SIZE_POSITIONS: |
| 170 | + height = primary_size |
| 171 | + width = 1.0 |
| 172 | + else: |
| 173 | + height = 1.0 |
| 174 | + width = primary_size |
| 175 | + |
| 176 | + return WindowSize(width=width, height=height, position=position) |
| 177 | + |
142 | 178 |
|
143 | 179 | @contextlib.contextmanager |
144 | 180 | def wait_move_resize( |
@@ -510,7 +546,10 @@ def test_show(self, test_api, monitor_config, window_pos, window_size, window_ma |
510 | 546 | window_monitor = test_api.layout.resolve_monitor(monitor_config) |
511 | 547 | prev_maximize = test_api.settings.get('window-maximize') |
512 | 548 |
|
513 | | - test_api.settings.set_double('window-size', window_size) |
| 549 | + window_size_object = WindowSize.get_maximized_size_from_position(window_size, window_pos) |
| 550 | + test_api.settings.set_double('window-hsize', window_size_object.width) |
| 551 | + test_api.settings.set_double('window-vsize', window_size_object.height) |
| 552 | + |
514 | 553 | test_api.settings.set_string('window-position', window_pos) |
515 | 554 | test_api.settings.set_string('window-monitor', monitor_config.setting) |
516 | 555 | test_api.settings.set_boolean( |
@@ -622,8 +661,9 @@ def test_mouse_resize( |
622 | 661 | test_api.mouse_sim.button(False) |
623 | 662 |
|
624 | 663 | with glib_util.SignalWait(test_api.dbus, 'g-signal') as wait3: |
| 664 | + window_size_setting = WindowSize.get_primary_size_setting(window_pos) |
625 | 665 | while compute_target_rect( |
626 | | - size=test_api.settings.get('window-size'), |
| 666 | + size=test_api.settings.get(window_size_setting), |
627 | 667 | pos=window_pos, |
628 | 668 | monitor=monitor |
629 | 669 | ) != target_frame_rect: |
@@ -708,7 +748,8 @@ def test_unmaximize_correct_size( |
708 | 748 | window_pos, |
709 | 749 | monitor, |
710 | 750 | ) as wait1: |
711 | | - test_api.settings.set_double('window-size', window_size2) |
| 751 | + window_size_setting = WindowSize.get_primary_size_setting(window_pos) |
| 752 | + test_api.settings.set_double(window_size_setting, window_size2) |
712 | 753 | wait1() |
713 | 754 |
|
714 | 755 | with wait_move_resize( |
@@ -756,7 +797,8 @@ def test_unmaximize_on_size_change( |
756 | 797 | window_pos, |
757 | 798 | monitor, |
758 | 799 | ) as wait: |
759 | | - test_api.settings.set_double('window-size', window_size2) |
| 800 | + window_size_setting = WindowSize.get_primary_size_setting(window_pos) |
| 801 | + test_api.settings.set_double(window_size_setting, window_size2) |
760 | 802 | wait() |
761 | 803 |
|
762 | 804 | PARAM_TYPES = { |
@@ -820,7 +862,8 @@ def test_dark_mode(self, test_api, container, shell_dbus_api, x11_display): |
820 | 862 |
|
821 | 863 | glib_util.flush_main_loop() |
822 | 864 |
|
823 | | - test_api.settings.set_double('window-size', 1) |
| 865 | + test_api.settings.set_double('window-hsize', 1) |
| 866 | + test_api.settings.set_double('window-vsize', 1) |
824 | 867 | test_api.settings.set_string('window-position', WindowPosition.TOP) |
825 | 868 | test_api.settings.set_string('window-monitor', MonitorSetting.PRIMARY) |
826 | 869 | test_api.settings.set_boolean('window-maximize', True) |
|
0 commit comments