File: test-maximize.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 (280 lines) | stat: -rw-r--r-- 7,064 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
--- Tests maximize and fullscreen

local runner = require("_runner")
local awful = require("awful")
local test_client = require("_client")
local lgi = require("lgi")
local gears = require("gears")

local function geo_to_str(g)
    return "pos=" .. g.x .. "," .. g.y ..
        ";size=" .. g.width .. "x" .. g.height
end

local original_geo = nil

local steps = {}

for _, gravity in ipairs { "NORTH_WEST", "NORTH", "NORTH_EAST", "WEST",
    "CENTER", "EAST", "SOUTH_WEST", "SOUTH", "SOUTH_EAST", "STATIC" } do
    gears.table.merge(steps, {
    function(count)
        if count == 1 then
            print("testing gravity " .. gravity)
            test_client(nil,nil,nil,nil,nil,{gravity=lgi.Gdk.Gravity[gravity]})
        else
            local c = client.get()[1]
            if c then
                original_geo = c:geometry()
                return true
            end
        end
    end,

    -- maximize horizontally
    function()
        local c = client.get()[1]
        assert(not c.maximized_horizontal)
        assert(not c.maximized_vertical  )
        assert(not c.maximized           )
        assert(not c.fullscreen          )
        assert(not c.immobilized_horizontal)
        assert(not c.immobilized_vertical)

        c.maximized_horizontal = true
        assert(c.immobilized_horizontal)
        assert(not c.immobilized_vertical)
        return true
    end,
    function()
        local c = client.get()[1]

        --local new_geo = c:geometry()
        --local sgeo = c.screen.workarea

        --assert(new_geo.x-c.border_width==sgeo.x) --FIXME c:geometry({x=1}).x ~= 1

        --assert(new_geo.width+2*c.border_width==sgeo.width) --FIXME off by 4px

        c.maximized_horizontal = false
        assert(not c.immobilized_horizontal)
        return true
    end,

    -- Test restoring client.border_width
    function()
        local c = client.get()[1]

        -- pick an arbitrary border_width distinct from the default one
        local test_width = c.border_width + 1

        c.border_width = test_width

        c.fullscreen = true

        -- Test that the client covers the full screen
        assert(geo_to_str(c:geometry()) == geo_to_str(c.screen.geometry),
            geo_to_str(c:geometry()) .. " == " .. geo_to_str(c.screen.geometry))

        c.fullscreen = false

        assert(c.border_width == test_width)

        -- Restore old border width
        c.border_width = test_width - 1

        return true
    end,

    -- Test restoring a geometry
    function()
        local c = client.get()[1]

        local new_geo = c:geometry()

        assert(geo_to_str(original_geo) == geo_to_str(new_geo),
            geo_to_str(original_geo) .. " == " .. geo_to_str(new_geo))

        c.fullscreen = true

        return true
    end,
    function()
        local c = client.get()[1]

        local new_geo = c:geometry()
        local sgeo    = c.screen.geometry
        local bw      = c.border_width

        assert(c.fullscreen)
        assert(c.immobilized_horizontal)
        assert(c.immobilized_vertical)

        assert(new_geo.x==sgeo.x)
        assert(new_geo.y==sgeo.y)
        assert(new_geo.x+new_geo.width+2*bw==sgeo.x+sgeo.width)
        assert(new_geo.y+new_geo.height+2*bw==sgeo.y+sgeo.height)

        c.fullscreen = false

        return true
    end,
    function()
        local c = client.get()[1]

        local new_geo = c:geometry()

        assert(geo_to_str(original_geo) == geo_to_str(new_geo),
            geo_to_str(original_geo) .. " == " .. geo_to_str(new_geo))

        c.floating  = true

        awful.placement.centered(c)
        original_geo = c:geometry()

        c.maximized = true


        return true
    end,
    function()
        local c = client.get()[1]

        local new_geo = c:geometry()
        local sgeo    = c.screen.workarea

        assert(c.maximized)
        assert(c.floating)
        assert(new_geo.x==sgeo.x)
        assert(new_geo.y==sgeo.y)
        assert(c.immobilized_horizontal)
        assert(c.immobilized_vertical)

        c.maximized = false

        return true
    end,
    function()
        local c = client.get()[1]

        assert(not c.maximized)
        assert(c.floating)

        local new_geo = c:geometry()

        assert(geo_to_str(original_geo) == geo_to_str(new_geo),
            geo_to_str(original_geo) .. " == " .. geo_to_str(new_geo))

        c:kill()

        return true
    end
})
end

local counter = 0

local function geometry_handler(c, context, hints)
    hints = hints or {}
    assert(type(c) == "client")
    assert(type(context) == "string")
    assert(type(hints.toggle) == "boolean")
    assert(type(hints.status) == "boolean")
    counter = counter + 1
end

gears.table.merge(steps, {
    -- Now, start some clients maximized
    function()
        if #client.get() > 0 then return end

        test_client(nil,nil,nil,nil,nil,{maximize_before=true})

        return true
    end,
    function()
        local c = client.get()[1]

        if not c then return end

        assert(not c.maximized_horizontal)
        assert(not c.maximized_vertical)
        assert(c.maximized)
        assert(c.immobilized_horizontal)
        assert(c.immobilized_vertical)

        c:kill()

        return true
    end,
    function()
        if #client.get() > 0 then return end

        test_client(nil,nil,nil,nil,nil,{maximize_after=true})

        return true
    end,
    function()
        local c = client.get()[1]

        if not c then return end

        assert(not c.maximized_horizontal)
        assert(not c.maximized_vertical)

        -- It might happen in the second try
        if not c.maximized then return end

        assert(c.immobilized_horizontal)
        assert(c.immobilized_vertical)

        c:kill()

        return true
    end,
    function()
        if #client.get() > 0 then return end

        -- Test if resizing requests work
        test_client(nil,nil,nil,nil,nil,{resize={width=400, height=400}})

        return true
    end,
    function()
        if #client.get() ~= 1 then return end

        local c = client.get()[1]
        local _, size = c:titlebar_top()

        if c.width ~= 400 or c.height ~= 400+size then return end

        c:kill()

        return true
    end,
    function()
        if #client.get() > 0 then return end

        -- Remove the default handler and replace it with a testing one.
        -- **WARNING**: add tests **BEFORE** this function if you want them
        -- to be relevant.
        client.disconnect_signal("request::geometry", awful.ewmh.geometry)
        client.disconnect_signal("request::geometry", awful.ewmh.merge_maximization)
        client.connect_signal("request::geometry", geometry_handler)

        test_client(nil,nil,nil,nil,nil,{maximize_after=true})

        return true
    end,
    function()
        local c = client.get()[1]

        if not c or counter ~= 2 then return end

        return true
    end
})

runner.run_steps(steps)

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