File: test-wibox-shape.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 (123 lines) | stat: -rw-r--r-- 2,435 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
-- A quick-and-dirty test of wibox shapes ("Does it error out?")

local runner = require("_runner")
local wibox = require("wibox")
local shape = require("gears.shape")

local was_drawn
local widget = wibox.widget.base.make_widget()
function widget.draw()
    was_drawn = true
end

local wb = wibox {
    shape = shape.powerline,
    widget = widget,
    border_width = 42,
}
wb:geometry(screen[1].geometry)
wb.visible = true

local count = 0

local steps = {
    function()
        assert(wb.shape == shape.powerline)
        assert(wb.shape_bounding) -- This is a memory leak! Don't copy!
        if was_drawn then
            return true
        end
    end,
    -- Remove the shape and test the input
    function()
        wb.shape = nil
        wb.input_passthrough = false
        wb:connect_signal("button::press", function()
            count = count + 1
        end)

        wb:geometry {
            x      = 0,
            y      = 100,
            width  = 101,
            height = 101,
        }
        wb.border_width = 0

        return true
    end
}

-- Emulate a click.
-- Each pair of the `...` corresponds to a point.
local function click(...)
    local args = {...}
    table.insert(steps, function()
        for i = 0, math.floor(#args/2)-1 do
            local x, y = args[i*2+1], args[i*2+2]
            mouse.coords{x=x, y=y}
            assert(mouse.coords().x == x and mouse.coords().y == y)
            root.fake_input("button_release", 1)
            root.fake_input("button_press", 1)
        end

        awesome.sync()

        return true
    end)
end

local function check_count(cnt)
    table.insert(steps, function()
        return cnt == count
    end)
end

-- Check each corner
click(0 , 100,
      99, 100,
      99, 199,
      0 , 199
)

check_count(4)

table.insert(steps, function()
    wb.input_passthrough = true
    count = 0
    return true
end)

-- Do it again
click(0 , 100,
      99, 100,
      99, 199,
      0 , 199
)

-- It's passthrough, so there should be no recorded clicks.
check_count(0)

table.insert(steps, function()
    wb.input_passthrough = false
    count = 0
    return true
end)

table.insert(steps, function()
    awesome.sync()
    count = 0
    return true
end)

-- One last time
click(0 , 100,
      99, 100,
      99, 199,
      0 , 199
)
check_count(4)

runner.run_steps(steps)

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