File: test_fakescreen.py

package info (click to toggle)
qtile 0.34.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,004 kB
  • sloc: python: 49,959; ansic: 4,371; xml: 324; sh: 260; makefile: 218
file content (427 lines) | stat: -rw-r--r-- 13,931 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import pytest

import libqtile.config
from libqtile import bar, layout, widget
from libqtile.config import Screen
from libqtile.confreader import Config

LEFT_ALT = "mod1"
WINDOWS = "mod4"
FONTSIZE = 13
CHAM1 = "8AE234"
CHAM3 = "4E9A06"
GRAPH_KW = dict(
    line_width=1, graph_color=CHAM3, fill_color=CHAM3 + ".3", border_width=1, border_color=CHAM3
)

# screens look like this
#     500         300
#  |-------------|-----|
#  |          340|     |380
#  |   A         |  B  |
#  |----------|--|     |
#  |       220|--|-----|
#  |   C      |        |220
#  |----------|   D    |
#     450     |--------|
#                 350
#
# Notice there is a hole in the middle
# also D goes down below the others


class FakeScreenConfig(Config):
    auto_fullscreen = True
    groups = [
        libqtile.config.Group("a"),
        libqtile.config.Group("b"),
        libqtile.config.Group("c"),
        libqtile.config.Group("d"),
    ]
    layouts = [
        layout.Max(),
        layout.RatioTile(),
        layout.Tile(),
    ]
    floating_layout = libqtile.resources.default_config.floating_layout
    keys = []
    mouse = []
    fake_screens = [
        Screen(
            bottom=bar.Bar(
                [
                    widget.GroupBox(
                        this_screen_border=CHAM3,
                        borderwidth=1,
                        fontsize=FONTSIZE,
                        padding=1,
                        margin=1,
                    ),
                    widget.AGroupBox(),
                    widget.Prompt(),
                    widget.Sep(),
                    widget.WindowName(fontsize=FONTSIZE),
                    widget.Sep(),
                    widget.CPUGraph(**GRAPH_KW),
                    widget.MemoryGraph(**GRAPH_KW),
                    widget.SwapGraph(foreground="20C020", **GRAPH_KW),
                    widget.Sep(),
                    widget.Clock(format="%H:%M:%S %d.%manager.%Y", fontsize=FONTSIZE, padding=6),
                ],
                24,
                background="#555555",
            ),
            left=bar.Gap(16),
            right=bar.Gap(20),
            x=0,
            y=0,
            width=500,
            height=340,
        ),
        Screen(
            top=bar.Bar(
                [widget.GroupBox(), widget.WindowName(), widget.Clock()],
                30,
            ),
            bottom=bar.Gap(24),
            left=bar.Gap(12),
            x=500,
            y=0,
            width=300,
            height=380,
        ),
        Screen(
            top=bar.Bar(
                [widget.GroupBox(), widget.WindowName(), widget.Clock()],
                30,
            ),
            bottom=bar.Gap(16),
            right=bar.Gap(40),
            x=0,
            y=340,
            width=450,
            height=220,
        ),
        Screen(
            top=bar.Bar(
                [widget.GroupBox(), widget.WindowName(), widget.Clock()],
                30,
            ),
            left=bar.Gap(20),
            right=bar.Gap(24),
            x=450,
            y=380,
            width=350,
            height=220,
        ),
    ]
    screens = []


fakescreen_config = pytest.mark.parametrize("manager", [FakeScreenConfig], indirect=True)


@fakescreen_config
def test_basic(manager):
    manager.test_window("zero")
    assert manager.c.layout.info()["clients"] == ["zero"]
    assert manager.c.screen.info() == {"y": 0, "x": 0, "index": 0, "width": 500, "height": 340}
    manager.c.to_screen(1)
    manager.test_window("one")
    assert manager.c.layout.info()["clients"] == ["one"]
    assert manager.c.screen.info() == {"y": 0, "x": 500, "index": 1, "width": 300, "height": 380}
    manager.c.to_screen(2)
    manager.test_window("two")
    assert manager.c.screen.info() == {"y": 340, "x": 0, "index": 2, "width": 450, "height": 220}
    manager.c.to_screen(3)
    manager.test_window("one")
    assert manager.c.screen.info() == {
        "y": 380,
        "x": 450,
        "index": 3,
        "width": 350,
        "height": 220,
    }


@fakescreen_config
def test_gaps(manager):
    g = manager.c.get_screens()[0]["gaps"]
    assert g["bottom"] == (0, 316, 500, 24)
    assert g["left"] == (0, 0, 16, 316)
    assert g["right"] == (480, 0, 20, 316)
    g = manager.c.get_screens()[1]["gaps"]
    assert g["top"] == (500, 0, 300, 30)
    assert g["bottom"] == (500, 356, 300, 24)
    assert g["left"] == (500, 30, 12, 326)
    g = manager.c.get_screens()[2]["gaps"]
    assert g["top"] == (0, 340, 450, 30)
    assert g["bottom"] == (0, 544, 450, 16)
    assert g["right"] == (410, 370, 40, 174)
    g = manager.c.get_screens()[3]["gaps"]
    assert g["top"] == (450, 380, 350, 30)
    assert g["left"] == (450, 410, 20, 190)
    assert g["right"] == (776, 410, 24, 190)


@fakescreen_config
def test_maximize_with_move_to_screen(manager):
    """Ensure that maximize respects bars"""
    manager.test_window("one")
    manager.c.window.toggle_maximize()
    assert manager.c.window.info()["width"] == 464
    assert manager.c.window.info()["height"] == 316
    assert manager.c.window.info()["x"] == 16
    assert manager.c.window.info()["y"] == 0
    assert manager.c.window.info()["group"] == "a"

    # go to second screen
    manager.c.to_screen(1)
    assert manager.c.screen.info() == {"y": 0, "x": 500, "index": 1, "width": 300, "height": 380}
    assert manager.c.group.info()["name"] == "b"
    manager.c.group["a"].toscreen()

    assert manager.c.window.info()["width"] == 288
    assert manager.c.window.info()["height"] == 326
    assert manager.c.window.info()["x"] == 512
    assert manager.c.window.info()["y"] == 30
    assert manager.c.window.info()["group"] == "a"


@fakescreen_config
def test_float_first_on_second_screen(manager):
    manager.c.to_screen(1)
    assert manager.c.screen.info() == {"y": 0, "x": 500, "index": 1, "width": 300, "height": 380}

    manager.test_window("one")
    # I don't know where y=30, x=12 comes from...
    assert manager.c.window.info()["float_info"] == {
        "y": 30,
        "x": 12,
        "width": 100,
        "height": 100,
    }

    manager.c.window.toggle_floating()
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100

    assert manager.c.window.info()["x"] == 512
    assert manager.c.window.info()["y"] == 30
    assert manager.c.window.info()["group"] == "b"
    assert manager.c.window.info()["float_info"] == {
        "y": 30,
        "x": 12,
        "width": 100,
        "height": 100,
    }


@fakescreen_config
def test_float_change_screens(manager):
    # add one tiled and one floating window
    manager.test_window("tiled")
    manager.test_window("float")
    manager.c.window.toggle_floating()
    assert set(manager.c.group.info()["windows"]) == set(("tiled", "float"))
    assert manager.c.group.info()["floating_info"]["clients"] == ["float"]
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    # 16 is given by the left gap width
    assert manager.c.window.info()["x"] == 16
    assert manager.c.window.info()["y"] == 0
    assert manager.c.window.info()["group"] == "a"

    # put on group b
    assert manager.c.screen.info() == {"y": 0, "x": 0, "index": 0, "width": 500, "height": 340}
    assert manager.c.group.info()["name"] == "a"
    manager.c.to_screen(1)
    assert manager.c.group.info()["name"] == "b"
    assert manager.c.screen.info() == {"y": 0, "x": 500, "index": 1, "width": 300, "height": 380}
    manager.c.group["a"].toscreen()
    assert manager.c.group.info()["name"] == "a"
    assert set(manager.c.group.info()["windows"]) == set(("tiled", "float"))
    assert manager.c.window.info()["name"] == "float"
    # width/height unchanged
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    # x is shifted by 500, y is shifted by 0
    assert manager.c.window.info()["x"] == 516
    assert manager.c.window.info()["y"] == 0
    assert manager.c.window.info()["group"] == "a"
    assert manager.c.group.info()["floating_info"]["clients"] == ["float"]

    # move to screen 3
    manager.c.to_screen(2)
    assert manager.c.screen.info() == {"y": 340, "x": 0, "index": 2, "width": 450, "height": 220}
    assert manager.c.group.info()["name"] == "c"
    manager.c.group["a"].toscreen()
    assert manager.c.group.info()["name"] == "a"
    assert set(manager.c.group.info()["windows"]) == set(("tiled", "float"))
    assert manager.c.window.info()["name"] == "float"
    # width/height unchanged
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    # x is shifted by 0, y is shifted by 340
    assert manager.c.window.info()["x"] == 16
    assert manager.c.window.info()["y"] == 340

    # now screen 4 for fun
    manager.c.to_screen(3)
    assert manager.c.screen.info() == {
        "y": 380,
        "x": 450,
        "index": 3,
        "width": 350,
        "height": 220,
    }
    assert manager.c.group.info()["name"] == "d"
    manager.c.group["a"].toscreen()
    assert manager.c.group.info()["name"] == "a"
    assert set(manager.c.group.info()["windows"]) == set(("tiled", "float"))
    assert manager.c.window.info()["name"] == "float"
    # width/height unchanged
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    # x is shifted by 450, y is shifted by 40
    assert manager.c.window.info()["x"] == 466
    assert manager.c.window.info()["y"] == 380

    # and back to one
    manager.c.to_screen(0)
    assert manager.c.screen.info() == {"y": 0, "x": 0, "index": 0, "width": 500, "height": 340}
    assert manager.c.group.info()["name"] == "b"
    manager.c.group["a"].toscreen()
    assert manager.c.group.info()["name"] == "a"
    assert set(manager.c.group.info()["windows"]) == set(("tiled", "float"))
    assert manager.c.window.info()["name"] == "float"
    # back to the original location
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == 16
    assert manager.c.window.info()["y"] == 0


@fakescreen_config
def test_float_outside_edges(manager):
    manager.test_window("one")
    manager.c.window.toggle_floating()
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    # 16 is given by the left gap width
    assert manager.c.window.info()["x"] == 16
    assert manager.c.window.info()["y"] == 0
    # empty because window is floating
    assert manager.c.layout.info() == {"clients": [], "current": 0, "group": "a", "name": "max"}

    # move left, but some still on screen 0
    manager.c.window.move_floating(-30, 20)
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == -14
    assert manager.c.window.info()["y"] == 20
    assert manager.c.window.info()["group"] == "a"

    # move up, but some still on screen 0
    manager.c.window.set_position_floating(-10, -20)
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == -10
    assert manager.c.window.info()["y"] == -20
    assert manager.c.window.info()["group"] == "a"

    # move above a
    manager.c.window.set_position_floating(50, -20)
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == 50
    assert manager.c.window.info()["y"] == -20
    assert manager.c.window.info()["group"] == "a"

    # move down so still left, but next to screen c
    manager.c.window.set_position_floating(-10, 360)
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == -10
    assert manager.c.window.info()["y"] == 360
    assert manager.c.window.info()["group"] == "c"

    # move above b
    manager.c.window.set_position_floating(700, -10)
    assert manager.c.window.info()["width"] == 100
    assert manager.c.window.info()["height"] == 100
    assert manager.c.window.info()["x"] == 700
    assert manager.c.window.info()["y"] == -10
    assert manager.c.window.info()["group"] == "b"


@fakescreen_config
def test_hammer_tile(manager):
    # change to tile layout
    manager.c.next_layout()
    manager.c.next_layout()
    for i in range(7):
        manager.test_window("one")
    for i in range(30):
        manager.c.to_screen((i + 1) % 4)
        manager.c.group["a"].toscreen()
    assert manager.c.group["a"].info()["windows"] == [
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
    ]


@fakescreen_config
def test_hammer_ratio_tile(manager):
    # change to ratio tile layout
    manager.c.next_layout()
    for i in range(7):
        manager.test_window("one")
    for i in range(30):
        manager.c.to_screen((i + 1) % 4)
        manager.c.group["a"].toscreen()
    assert manager.c.group["a"].info()["windows"] == [
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
    ]


@fakescreen_config
def test_ratio_to_fourth_screen(manager):
    # change to ratio tile layout
    manager.c.next_layout()
    for i in range(7):
        manager.test_window("one")
    manager.c.to_screen(1)
    manager.c.group["a"].toscreen()
    assert manager.c.group["a"].info()["windows"] == [
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
    ]

    # now move to 4th, fails...
    manager.c.to_screen(3)
    manager.c.group["a"].toscreen()
    assert manager.c.group["a"].info()["windows"] == [
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
        "one",
    ]