File: test-tooltip.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 (130 lines) | stat: -rw-r--r-- 2,612 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
local runner = require("_runner")
local place = require("awful.placement")
local wibox = require("wibox")
local beautiful = require("beautiful")
local tooltip = require("awful.tooltip")
local gears = require("gears")

local steps = {}

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

w:setup{
    image  = beautiful.awesome_icon,
    widget = wibox.widget.imagebox
}

-- Center eveything
place.centered(w)
place.centered(mouse)

local tt = nil

table.insert(steps, function()
    tt = tooltip {text = "short", visible = true}
    -- This tests changing the text while the tooltip is visible
    tt:set_text("A long tooltip")

    return true
end)

local align_pos = {
    "top_left", "left", "bottom_left", "right",
    "top_right", "bottom_right", "bottom", "top",
}

-- Test the various alignment code paths
for _, v in ipairs(align_pos) do
    table.insert(steps, function()
        tt.align = v

        return true
    end)
end

-- Set a parent object
table.insert(steps, function()
    tt:add_to_object(w)

    return true
end)

-- Test the other mode
table.insert(steps, function()
    tt.mode = "outside"

    -- This only work when there is a mouse::enter event, create one
    place.top_left(mouse)
    place.centered(mouse)

    return true
end)

--- Reset the wibox content and use a widget geometry.
table.insert(steps, function()
    tt:remove_from_object(w)

    tt.visible = false

    w:setup{
        {
            image  = beautiful.awesome_icon,
            widget = wibox.widget.imagebox,
            id     = "myimagebox"
        },
        top    = 125,
        bottom = 100,
        left   = 205,
        right  = 20 ,
        layout = wibox.container.margin
    }

    local imb = w:get_children_by_id("myimagebox")[1]
    assert(imb)

    tt:add_to_object(imb)

    -- Move the mouse over the widget
    place.top_left(mouse)
    mouse.coords {
        x = w.x + w.width - 20 - 12.5,
        y = w.y + 125 + 12.5,
    }
    return true
end)

-- Test that the above move had the intended effect
table.insert(steps, function()
    assert(tt.current_position == "top", tt.current_position)

    return true
end)

-- Try the preferred positions
table.insert(steps, function()
    tt.visible = false

    tt.preferred_positions = {"right"}

    tt.visible = true

    assert(tt.current_position == "right")

    return true
end)

-- Add a shape.
table.insert(steps, function()
    tt.shape = gears.shape.octogon

    return true
end)

runner.run_steps(steps)

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