1# Copyright (c) 2021 elParaguayo
2#
3# Permission is hereby granted, free of charge, to any person obtaining a copy
4# of this software and associated documentation files (the "Software"), to deal
5# in the Software without restriction, including without limitation the rights
6# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7# copies of the Software, and to permit persons to whom the Software is
8# furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice shall be included in
11# all copies or substantial portions of the Software.
12#
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19# SOFTWARE.
20
21# Widget specific tests
22
23import pytest
24
25import libqtile.config
26from libqtile import bar, layout, widget
27from libqtile.config import Screen
28from libqtile.confreader import Config
29
30
31class WindowNameConfig(Config):
32    auto_fullscreen = True
33    groups = [
34        libqtile.config.Group("a"),
35        libqtile.config.Group("b")
36    ]
37    layouts = [
38        layout.Max()
39    ]
40    floating_layout = libqtile.resources.default_config.floating_layout
41    keys = []
42    mouse = []
43    fake_screens = [
44        Screen(
45            top=bar.Bar(
46                [
47                    widget.WindowName(),
48                ],
49                24,
50            ),
51            x=0, y=0, width=900, height=480
52        ),
53        Screen(
54            top=bar.Bar(
55                [
56                    widget.WindowName(for_current_screen=True),
57                ],
58                24,
59            ),
60            x=0, y=480, width=900, height=480
61        ),
62
63    ]
64    screens = []
65
66
67windowname_config = pytest.mark.parametrize("manager", [WindowNameConfig], indirect=True)
68
69
70@windowname_config
71def test_window_names(manager):
72
73    def widget_text_on_screen(index):
74        return manager.c.screen[index].bar["top"].info()["widgets"][0]["text"]
75
76    # Screen 1's widget is set up with for_current_screen=True
77    # This means that when screen 0 is active, screen 1's widget should show the same text
78
79    assert widget_text_on_screen(0) == " "
80    assert widget_text_on_screen(0) == widget_text_on_screen(1)
81
82    # Load a window
83    proc = manager.test_window('one')
84    assert widget_text_on_screen(0) == "one"
85    assert widget_text_on_screen(0) == widget_text_on_screen(1)
86
87    # Maximize window
88    manager.c.window.toggle_maximize()
89    assert widget_text_on_screen(0) == "[] one"
90    assert widget_text_on_screen(0) == widget_text_on_screen(1)
91
92    # Minimize window
93    manager.c.window.toggle_minimize()
94    assert widget_text_on_screen(0) == "_ one"
95    assert widget_text_on_screen(0) == widget_text_on_screen(1)
96
97    # Float window
98    manager.c.window.toggle_minimize()
99    manager.c.window.toggle_floating()
100    assert widget_text_on_screen(0) == "V one"
101    assert widget_text_on_screen(0) == widget_text_on_screen(1)
102
103    # Kill the window and check text again
104    manager.kill_window(proc)
105    assert widget_text_on_screen(0) == " "
106    assert widget_text_on_screen(0) == widget_text_on_screen(1)
107
108    # Quick test to check for_current_screen=False works
109    manager.c.to_screen(1)
110    proc = manager.test_window('one')
111    assert widget_text_on_screen(0) == " "
112    assert widget_text_on_screen(1) == "one"
113    manager.kill_window(proc)
114