| 
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 | 
 
  | 
@@ -140,6 +141,45 @@ def verify_window_geometry(test_interface, size, maximize, pos, monitor):  | 
140 | 141 |         assert actual_frame_rect == target_rect_unmaximized  | 
141 | 142 | 
 
  | 
142 | 143 | 
 
  | 
 | 144 | +@dataclasses.dataclass  | 
 | 145 | +class WindowSize:  | 
 | 146 | +    width: float  | 
 | 147 | +    height: float  | 
 | 148 | +    position: WindowPosition  | 
 | 149 | + | 
 | 150 | +    _HORIZONTAL_SIZE_POSITIONS = [WindowPosition.TOP, WindowPosition.BOTTOM]  | 
 | 151 | + | 
 | 152 | +    def get_primary_size(self) -> float:  | 
 | 153 | +        return self.width if self.position in self._HORIZONTAL_SIZE_POSITIONS else self.height  | 
 | 154 | + | 
 | 155 | +    @classmethod  | 
 | 156 | +    def get_primary_size_setting(cls, position: WindowPosition) -> str:  | 
 | 157 | +        return "window-hsize" if position in cls._HORIZONTAL_SIZE_POSITIONS else "window-vsize"  | 
 | 158 | + | 
 | 159 | +    @classmethod  | 
 | 160 | +    def get_maximized_size_from_position(  | 
 | 161 | +                                        cls,  | 
 | 162 | +                                        primary_size: float,  | 
 | 163 | +                                        position: WindowPosition) -> "WindowSize":  | 
 | 164 | +        """  | 
 | 165 | +        Get window horizontal/vertical size based on the given position.  | 
 | 166 | +
  | 
 | 167 | +        On top/bottom positions, primary size is horizontal.  | 
 | 168 | +        On left/right positions, primary size is vertical.  | 
 | 169 | +
  | 
 | 170 | +        This is a simplified helper to get a secondary size set to 100% for now, until tests  | 
 | 171 | +        are updated/added to support secondary size as well.  | 
 | 172 | +        """  | 
 | 173 | +        if position in cls._HORIZONTAL_SIZE_POSITIONS:  | 
 | 174 | +            height = primary_size  | 
 | 175 | +            width = 1.0  | 
 | 176 | +        else:  | 
 | 177 | +            height = 1.0  | 
 | 178 | +            width = primary_size  | 
 | 179 | + | 
 | 180 | +        return WindowSize(width=width, height=height, position=position)  | 
 | 181 | + | 
 | 182 | + | 
143 | 183 | @contextlib.contextmanager  | 
144 | 184 | def wait_move_resize(  | 
145 | 185 |     test_interface,  | 
@@ -510,7 +550,10 @@ def test_show(self, test_api, monitor_config, window_pos, window_size, window_ma  | 
510 | 550 |         window_monitor = test_api.layout.resolve_monitor(monitor_config)  | 
511 | 551 |         prev_maximize = test_api.settings.get('window-maximize')  | 
512 | 552 | 
 
  | 
513 |  | -        test_api.settings.set_double('window-size', window_size)  | 
 | 553 | +        window_size_object = WindowSize.get_maximized_size_from_position(window_size, window_pos)  | 
 | 554 | +        test_api.settings.set_double('window-hsize', window_size_object.width)  | 
 | 555 | +        test_api.settings.set_double('window-vsize', window_size_object.height)  | 
 | 556 | + | 
514 | 557 |         test_api.settings.set_string('window-position', window_pos)  | 
515 | 558 |         test_api.settings.set_string('window-monitor', monitor_config.setting)  | 
516 | 559 |         test_api.settings.set_boolean(  | 
@@ -622,8 +665,9 @@ def test_mouse_resize(  | 
622 | 665 |             test_api.mouse_sim.button(False)  | 
623 | 666 | 
 
  | 
624 | 667 |         with glib_util.SignalWait(test_api.dbus, 'g-signal') as wait3:  | 
 | 668 | +            window_size_setting = WindowSize.get_primary_size_setting(window_pos)  | 
625 | 669 |             while compute_target_rect(  | 
626 |  | -                size=test_api.settings.get('window-size'),  | 
 | 670 | +                size=test_api.settings.get(window_size_setting),  | 
627 | 671 |                 pos=window_pos,  | 
628 | 672 |                 monitor=monitor  | 
629 | 673 |             ) != target_frame_rect:  | 
@@ -708,7 +752,8 @@ def test_unmaximize_correct_size(  | 
708 | 752 |             window_pos,  | 
709 | 753 |             monitor,  | 
710 | 754 |         ) as wait1:  | 
711 |  | -            test_api.settings.set_double('window-size', window_size2)  | 
 | 755 | +            window_size_setting = WindowSize.get_primary_size_setting(window_pos)  | 
 | 756 | +            test_api.settings.set_double(window_size_setting, window_size2)  | 
712 | 757 |             wait1()  | 
713 | 758 | 
 
  | 
714 | 759 |         with wait_move_resize(  | 
@@ -756,7 +801,8 @@ def test_unmaximize_on_size_change(  | 
756 | 801 |             window_pos,  | 
757 | 802 |             monitor,  | 
758 | 803 |         ) as wait:  | 
759 |  | -            test_api.settings.set_double('window-size', window_size2)  | 
 | 804 | +            window_size_setting = WindowSize.get_primary_size_setting(window_pos)  | 
 | 805 | +            test_api.settings.set_double(window_size_setting, window_size2)  | 
760 | 806 |             wait()  | 
761 | 807 | 
 
  | 
762 | 808 |     PARAM_TYPES = {  | 
@@ -820,7 +866,8 @@ def test_dark_mode(self, test_api, container, shell_dbus_api, x11_display):  | 
820 | 866 | 
 
  | 
821 | 867 |         glib_util.flush_main_loop()  | 
822 | 868 | 
 
  | 
823 |  | -        test_api.settings.set_double('window-size', 1)  | 
 | 869 | +        test_api.settings.set_double('window-hsize', 1)  | 
 | 870 | +        test_api.settings.set_double('window-vsize', 1)  | 
824 | 871 |         test_api.settings.set_string('window-position', WindowPosition.TOP)  | 
825 | 872 |         test_api.settings.set_string('window-monitor', MonitorSetting.PRIMARY)  | 
826 | 873 |         test_api.settings.set_boolean('window-maximize', True)  | 
 | 
0 commit comments