File: test-awful-widget-button.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 (146 lines) | stat: -rw-r--r-- 3,006 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
local runner    = require( "_runner"   )
local wibox     = require( "wibox"     )
local awful     = require( "awful"     )
local beautiful = require( "beautiful" )
local gtable    = require("gears.table")

local steps = {}

local w
local img
local button

-- Also check recursive signals from events
local layout
local got_called = false

-- create a wibox.
table.insert(steps, function()

    w = wibox {
        ontop   = true,
        width   = 250,
        height  = 250,
        visible = true,
    }

    button = awful.widget.button {
        image = beautiful.awesome_icon
    }

    w : setup {
        {
            {
                text   = "foo",
                widget = wibox.widget.textbox,
            },
            bg     = "#ff0000",
            widget = wibox.container.background
        },
        {
            {
                widget = button,
            },
            bg     = "#ff00ff",
            widget = wibox.container.background
        },
        {
            {
                text   = "foo",
                widget = wibox.widget.textbox,
            },
            bg     = "#0000ff",
            widget = wibox.container.background
        },
        layout = wibox.layout.flex.vertical
    }

    awful.placement.centered(w)

    img = button._private.image
    assert(img)

    -- Test the click
    layout = w.widget
    assert(layout)

    button:buttons(gtable.join(
        button:buttons(),
        awful.button({}, 1, nil, function ()
            button:emit_signal_recursive("test::recursive")
        end)
))

    layout:connect_signal("test::recursive", function()
        got_called = true
    end)

    return true
end)

-- Test a button press
table.insert(steps, function()
    awful.placement.centered(mouse)

    root.fake_input("button_press", 1)
    awesome.sync()

    return true
end)

table.insert(steps, function()
    assert(button._private.image ~= img)

    return true
end)

-- Test a button release
table.insert(steps, function()
    assert(button._private.image ~= img)

    root.fake_input("button_release", 1)
    awesome.sync()

    return true
end)

-- Test a button press/release outside of the widget
table.insert(steps, function()
    assert(button._private.image == img)

    root.fake_input("button_press", 1)
    awesome.sync()

    return true
end)

table.insert(steps, function()
assert(button._private.image ~= img)

return true
end)

table.insert(steps, function()
-- just make sure the button is not released for nothing
assert(button._private.image ~= img)

-- test if the button is released when the mouse move out
awful.placement.right(mouse--[[, {parent = w}]])
root.fake_input("button_release", 1)
awesome.sync()

return true
end)

table.insert(steps, function()
assert(button._private.image == img)

-- The button had plenty of clicks by now. Make sure everything worked
assert(got_called)

return true
end)

runner.run_steps(steps)

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