File: test-resize.lua

package info (click to toggle)
awesome 4.3-8.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,468 kB
  • sloc: ansic: 14,508; sh: 526; makefile: 46
file content (528 lines) | stat: -rw-r--r-- 14,635 bytes parent folder | download | duplicates (4)
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
local test_client = require("_client")
local placement = require("awful.placement")
local amouse = require("awful.mouse")
local rounded_rect = require("gears.shape").rounded_rect

local steps = {}

table.insert(steps, function(count)
    if count == 1 then  -- Setup.
        test_client("foobar", "foobar")
    elseif #client.get() > 0 then
        client.get()[1] : geometry {
            x      = 200,
            y      = 200,
            width  = 300,
            height = 300,
        }

        client.get()[1].shape = rounded_rect

        return true
    end
end)

table.insert(steps, function()
-- The mousegrabber expect a button to be pressed.
root.fake_input("button_press",1)
local c = client.get()[1]

-- Just in case there is an accidental delayed geometry callback
assert(c:geometry().x      == 200)
assert(c:geometry().y      == 200)
assert(c:geometry().width  == 300)
assert(c:geometry().height == 300)

mouse.coords {x = 500+2*c.border_width, y= 500+2*c.border_width}

local corner = amouse.client.resize(c)

assert(corner == "bottom_right")

return true
end)

-- The geometry should remain the same, as the cursor is placed at the end of
-- the geometry.
table.insert(steps, function()

    local c = client.get()[1]

    assert(c:geometry().x      == 200)
    assert(c:geometry().y      == 200)
    assert(c:geometry().width  == 300)
    assert(c:geometry().height == 300)

    mouse.coords {x = 600+2*c.border_width, y= 600+2*c.border_width}

    return true
end)

-- Grow the client by 100px
table.insert(steps, function()

    local c = client.get()[1]

    assert(c:geometry().x      == 200)
    assert(c:geometry().y      == 200)
    assert(c:geometry().width  == 400)
    assert(c:geometry().height == 400)

    mouse.coords {x = 400+2*c.border_width, y= 400+2*c.border_width}

    return true
end)

-- Shirnk the client by 200px
table.insert(steps, function()

    local c = client.get()[1]

    assert(c:geometry().x      == 200)
    assert(c:geometry().y      == 200)
    assert(c:geometry().width  == 200)
    assert(c:geometry().height == 200)

    mouse.coords {x = 100, y= 100}

    return true
end)

-- Grow the client by 100px from the top left
table.insert(steps, function()

    local c = client.get()[1]

    assert(c:geometry().x      == 100)
    assert(c:geometry().y      == 100)
    assert(c:geometry().width  == 300)
    assert(c:geometry().height == 300)

    mouse.coords {x = 300, y= 200}

    return true
end)

-- Shrink the client by 100px from the top right
table.insert(steps, function()

    local c = client.get()[1]

    assert(c:geometry().x == 100)
    assert(c:geometry().y == 200)
    --     assert(c:geometry().width == 200-2*c.border_width) --FIXME off by border width...
    --     assert(c:geometry().height == 200-2*c.border_width) --FIXME off by border width...


    -- Now do a couple check with the "after" mode to make sure it doesn't
    -- regress.
    root.fake_input("button_release",1)

    mousegrabber.stop()

    amouse.resize.set_mode("after")
    c.border_width = 0
    c:geometry {
        x      = 100,
        y      = 200,
        width  = 300,
        height = 200,
    }
    assert(c:geometry().x      == 100)
    assert(c:geometry().y      == 200)
    assert(c:geometry().width  == 300)
    assert(c:geometry().height == 200)

    root.fake_input("button_press",1)
    amouse.client.resize(c)

    mouse.coords {x = 500, y= 500}

    return true
end)

-- Grow the client by 100px from the top left ("after" mode)
table.insert(steps, function()

    -- local c = client.get()[1]

    --     if not mousegrabber.isrunning then --FIXME it should work, but doesn't
    --         return true
    --     end

    --FIXME, the mousegrabber callback says the mouse buttons are not pressed,
    -- theirfor the test is broken
    -- Nothing should have changed until button_release is done
    --assert(c:geometry().x      == 100)
    --assert(c:geometry().y      == 200)
    --assert(c:geometry().width  == 300)
    --assert(c:geometry().height == 200)

    mouse.coords {x = 300, y= 200}

    return true
end)

-- Stop the resize
table.insert(steps, function()

    local c = client.get()[1]

    root.fake_input("button_release",1)

    assert(c:geometry().x      == 100)
    assert(c:geometry().y      == 200)
    assert(c:geometry().width  == 400)
    assert(c:geometry().height == 300)

    amouse.resize.set_mode("live")

    mousegrabber.stop()

    return true
end)

-- Setup for move testing
table.insert(steps, function()
    assert(not mousegrabber.isrunning())

    local c = client.get()[1]

    c:geometry {
        width  = 200,
        height = 200,
    }

    placement.bottom_right(c)

    mouse.coords {x = c.screen.geometry.width -150,
    y = c.screen.geometry.height-150}


    return true
end)

-- Start the move mouse grabber
table.insert(steps, function()
    local c = client.get()[1]

    -- The resize is over, it should not move the client anymore
    assert(c:geometry().x == c.screen.geometry.width  - 200 - 2*c.border_width)
    assert(c:geometry().y == c.screen.geometry.height - 200 - 2*c.border_width)
    assert(c:geometry().width  == 200)
    assert(c:geometry().height == 200)

    assert(c.valid)

    root.fake_input("button_press",1)

    -- Begin the move
    amouse.client.move(c)

    -- Make sure nothing unwanted happen by accident
    assert(c:geometry().x == c.screen.geometry.width  - 200 - 2*c.border_width)
    assert(c:geometry().y == c.screen.geometry.height - 200 - 2*c.border_width)
    assert(c:geometry().width  == 200)
    assert(c:geometry().height == 200)

    -- The cursor should not have moved
    assert(mouse.coords().x == c.screen.geometry.width  - 150)
    assert(mouse.coords().y == c.screen.geometry.height - 150)
    mouse.coords {x = 50 + 2*c.border_width, y= 50 + 2*c.border_width}

    assert(mousegrabber.isrunning())

    return true
end)

-- The client should now be in the top left
table.insert(steps, function()
    local c = client.get()[1]
    assert(c:geometry().x == 0)
    assert(c:geometry().y == 0)
    assert(c:geometry().width  == 200)
    assert(c:geometry().height == 200)

    -- Move to the bottom left
    mouse.coords {
        x = 50 + 2*c.border_width,
        y = c.screen.geometry.height - 200
    }

    return true
end)

-- Ensure the move was correct, the snap to the top part of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x == 0)
    assert(c:geometry().y == c.screen.geometry.height - 250 - 2*c.border_width)
    assert(c:geometry().width  == 200)
    assert(c:geometry().height == 200)

    -- Should trigger the top snap
    mouse.coords {x = 600, y= 0}

    -- The snap is only applied on release
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the top half of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x       == c.screen.workarea.x                                     )
    assert(c:geometry().y       == c.screen.workarea.y                                     )
    assert(c:geometry().width   == c.screen.workarea.width - 2*c.border_width              )
    assert(c:geometry().height  == math.ceil(c.screen.workarea.height/2 - 2*c.border_width))

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.top_right(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the top right corner of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x       == math.ceil(c.screen.workarea.x+c.screen.workarea.width/2))
    assert(c:geometry().y       == c.screen.workarea.y                                     )
    assert(c:geometry().width   == math.ceil(c.screen.workarea.width/2 - 2*c.border_width) )
    assert(c:geometry().height  == math.ceil(c.screen.workarea.height/2 - 2*c.border_width))

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.right(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the top right half of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x       == math.ceil(c.screen.workarea.x+c.screen.workarea.width/2))
    assert(c:geometry().y       == c.screen.workarea.y                                    )
    assert(c:geometry().width   == math.ceil(c.screen.workarea.width/2 - 2*c.border_width))
    assert(c:geometry().height  == c.screen.workarea.height - 2*c.border_width            )

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.bottom(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the bottom half of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x      == c.screen.workarea.x                                     )
    assert(c:geometry().y      == math.ceil(c.screen.workarea.y+c.screen.workarea.height/2))
    assert(c:geometry().width  == c.screen.workarea.width - 2*c.border_width              )
    assert(c:geometry().height == math.ceil(c.screen.workarea.height/2 - 2*c.border_width))

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.bottom_left(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the bottom left corner of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x       == c.screen.workarea.x                                     )
    assert(c:geometry().y       == math.ceil(c.screen.workarea.y+c.screen.workarea.height/2))
    assert(c:geometry().width   == math.ceil(c.screen.workarea.width/2 - 2*c.border_width) )
    assert(c:geometry().height  == math.ceil(c.screen.workarea.height/2 - 2*c.border_width))

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.left(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The client should now fill the left half of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x      == c.screen.workarea.x                                     )
    assert(c:geometry().y      == c.screen.workarea.y                                     )
    assert(c:geometry().width  == math.ceil(c.screen.workarea.width/2 - 2*c.border_width) )
    assert(c:geometry().height == c.screen.workarea.height - 2*c.border_width             )

    -- Snap to the top right
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.top_left(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

local cur_tag = nil

-- The client should now fill the top left corner of the screen
table.insert(steps, function()
    local c = client.get()[1]

    assert(c:geometry().x       == c.screen.workarea.x                                     )
    assert(c:geometry().y       == c.screen.workarea.y                                     )
    assert(c:geometry().width   == math.ceil(c.screen.workarea.width/2 - 2*c.border_width) )
    assert(c:geometry().height  == math.ceil(c.screen.workarea.height/2 - 2*c.border_width))

    -- Change the mode to test drag_to_tag
    amouse.drag_to_tag.enabled = true
    amouse.snap.edge_enabled   = false

    cur_tag = c.first_tag

    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.right(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The tag should have changed
table.insert(steps, function()
    local c = client.get()[1]

    assert(c.first_tag       ~= cur_tag          )
    assert(c.first_tag.index == cur_tag.index + 1)

    -- Move it back
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.left(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The tag should now be the same as before
table.insert(steps, function()
    local c = client.get()[1]

    assert(c.first_tag == cur_tag)
    assert(c.first_tag.index == 1)

    -- Wrap
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.left(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The tag should now be the last
table.insert(steps, function()
    local c = client.get()[1]

    assert(c.first_tag.index == #c.screen.tags)

    -- Wrap back
    root.fake_input("button_press",1)
    amouse.client.move(c)
    placement.right(mouse, {honor_workarea=false})
    root.fake_input("button_release",1)

    return true
end)

-- The tag should now original one again
table.insert(steps, function()
    local c = client.get()[1]

    assert(c.first_tag == cur_tag)

    c:geometry {
        x      = 99,
        y      = 99,
        width  = 99,
        height = 99,
    }

    return true
end)

-- Test that odd number sized clients don't move by accident
for _=1, 15 do
    table.insert(steps, function()
        local c = client.get()[1]

        root.fake_input("button_press",1)
        amouse.client.move(c)
        root.fake_input("button_release",1)


        return true
    end)
end

table.insert(steps, function()
    local c = client.get()[1]
    root.fake_input("button_release",1)

    assert(c.x      == 99)
    assert(c.y      == 99)
    assert(c.width  == 99)
    assert(c.height == 99)

    return true
end)

table.insert(steps, function()
    for _, c in pairs(client.get()) do
        c:kill()
    end
    if #client.get() == 0 then
        test_client(nil, nil, nil, nil, true)
        return true
    end
end)

table.insert(steps, function()
    if #client.get() ~= 1 then
        return
    end

    local c = client.get()[1]
    local geo = c:geometry()
    local hints = c.size_hints
    assert(hints.height_inc == 200)
    assert(hints.width_inc == 200)
    assert(c:apply_size_hints(1, 1) == 0)

    c:geometry { width = 1, height = 50 }

    -- The above should be rejected, because it would make us resize the
    -- window size 0x0.
    assert(c:geometry().width == geo.width)
    assert(c:geometry().height == geo.height)
    return true
end)

require("_runner").run_steps(steps)

-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80