tests: Test the awful.popup

This commit is contained in:
Emmanuel Lepage Vallee 2017-08-10 00:34:09 -04:00
parent 031c773658
commit 6c1f9ec651
7 changed files with 551 additions and 0 deletions

View File

@ -0,0 +1,59 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { --DOC_HIDE --DOC_NO_USAGE
popup = require("awful.popup"), --DOC_HIDE
placement = require("awful.placement"), --DOC_HIDE
widget = {clienticon =require("awful.widget.clienticon"), --DOC_HIDE
tasklist = require("awful.widget.tasklist")} --DOC_HIDE
} --DOC_HIDE
local gears = { shape = require("gears.shape") } --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
local beautiful = require("beautiful") --DOC_HIDE
for _=1, 6 do --DOC_HIDE
local c = client.gen_fake {x = 80, y = 55, width=75, height=50} --DOC_HIDE
c.icon = beautiful.awesome_icon --DOC_HIDE
c.minimized = true --DOC_HIDE
end --DOC_HIDE
local tasklist_buttons = nil --DOC_HIDE
awful.popup {
widget = awful.widget.tasklist {
screen = screen[1],
filter = awful.widget.tasklist.filter.allscreen,
buttons = tasklist_buttons,
style = {
shape = gears.shape.rounded_rect,
},
layout = {
spacing = 5,
forced_num_rows = 2,
layout = wibox.layout.grid.horizontal
},
widget_template = {
{
{
id = "clienticon",
widget = awful.widget.clienticon,
},
margins = 4,
widget = wibox.container.margin,
},
id = "background_role",
forced_width = 48,
forced_height = 48,
widget = wibox.container.background,
create_callback = function(self, c, index, objects) --luacheck: no unused
self:get_children_by_id("clienticon")[1].client = c
end,
},
},
border_color = "#777777",
border_width = 2,
ontop = true,
placement = awful.placement.centered,
shape = gears.shape.rounded_rect
}
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,70 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { --DOC_HIDE --DOC_NO_USAGE
popup = require("awful.popup"), --DOC_HIDE
placement = require("awful.placement"), --DOC_HIDE
widget = {clienticon =require("awful.widget.clienticon"), --DOC_HIDE
tasklist = require("awful.widget.tasklist")} --DOC_HIDE
} --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
screen[1]._resize {width = 320, height = 240} --DOC_HIDE
screen._add_screen {x = 330, y = 0, width = 320, height = 240} --DOC_HIDE
local p = awful.popup { --DOC_HIDE
widget = wibox.widget { --DOC_HIDE
text = "Parent wibox", --DOC_HIDE
forced_width = 100, --DOC_HIDE
forced_height = 50, --DOC_HIDE
widget = wibox.widget.textbox --DOC_HIDE
}, --DOC_HIDE
border_color = "#777777", --DOC_HIDE
border_width = 2, --DOC_HIDE
ontop = true, --DOC_HIDE
screen = screen[1], --DOC_HIDE
placement = awful.placement.top, --DOC_HIDE
} --DOC_HIDE
p:_apply_size_now() --DOC_HIDE
local p2 = awful.popup {
widget = wibox.widget {
text = "A popup",
forced_height = 100,
widget = wibox.widget.textbox
},
border_color = "#777777",
border_width = 2,
preferred_positions = "right",
preferred_anchors = {"front", "back"},
}
p2:move_next_to(p) --DOC_HIDE
local p3 = awful.popup { --DOC_HIDE
widget = wibox.widget { --DOC_HIDE
text = "Parent wibox2", --DOC_HIDE
forced_width = 100, --DOC_HIDE
forced_height = 50, --DOC_HIDE
widget = wibox.widget.textbox --DOC_HIDE
}, --DOC_HIDE
border_color = "#777777", --DOC_HIDE
border_width = 2, --DOC_HIDE
ontop = true, --DOC_HIDE
screen = screen[2], --DOC_HIDE
placement = awful.placement.bottom, --DOC_HIDE
} --DOC_HIDE
p3:_apply_size_now() --DOC_HIDE
local p4 = awful.popup {
widget = wibox.widget {
text = "A popup2",
forced_height = 100,
widget = wibox.widget.textbox
},
border_color = "#777777",
border_width = 2,
preferred_positions = "right",
screen = screen[2], --DOC_HIDE
preferred_anchors = {"front", "back"},
}
p4:move_next_to(p3) --DOC_HIDE
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,38 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { --DOC_HIDE --DOC_NO_USAGE
popup = require("awful.popup"), --DOC_HIDE
placement = require("awful.placement"), --DOC_HIDE
widget = {clienticon =require("awful.widget.clienticon"), --DOC_HIDE
tasklist = require("awful.widget.tasklist")} --DOC_HIDE
} --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
local p = awful.popup { --DOC_HIDE
widget = wibox.widget { --DOC_HIDE
text = "Parent wibox", --DOC_HIDE
forced_width = 100, --DOC_HIDE
forced_height = 100, --DOC_HIDE
widget = wibox.widget.textbox --DOC_HIDE
}, --DOC_HIDE
border_color = "#777777", --DOC_HIDE
border_width = 2, --DOC_HIDE
ontop = true, --DOC_HIDE
placement = awful.placement.centered, --DOC_HIDE
} --DOC_HIDE
p:_apply_size_now() --DOC_HIDE
for _, v in ipairs {"left", "right", "bottom", "top"} do
local p2 = awful.popup {
widget = wibox.widget {
text = "On the "..v,
widget = wibox.widget.textbox
},
border_color = "#777777",
border_width = 2,
preferred_positions = v,
ontop = true,
}
p2:move_next_to(p)
end
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,61 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { --DOC_HIDE --DOC_NO_USAGE
popup = require("awful.popup"), --DOC_HIDE
placement = require("awful.placement"), --DOC_HIDE
widget = {clienticon =require("awful.widget.clienticon"), --DOC_HIDE
tasklist = require("awful.widget.tasklist")} --DOC_HIDE
} --DOC_HIDE
local gears = { shape = require("gears.shape"), timer=require("gears.timer") } --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
local beautiful = require("beautiful") --DOC_HIDE
local p = awful.popup { --DOC_HIDE
widget = wibox.widget { --DOC_HIDE
{ text = "Item", widget = wibox.widget.textbox }, --DOC_HIDE
{ text = "Item", widget = wibox.widget.textbox }, --DOC_HIDE
{ text = "Item", widget = wibox.widget.textbox }, --DOC_HIDE
{ --DOC_HIDE
{ --DOC_HIDE
text = "Selected", --DOC_HIDE
widget = wibox.widget.textbox --DOC_HIDE
}, --DOC_HIDE
bg = beautiful.bg_highlight, --DOC_HIDE
widget = wibox.container.background --DOC_HIDE
}, --DOC_HIDE
{ text = "Item", widget = wibox.widget.textbox }, --DOC_HIDE
{ text = "Item", widget = wibox.widget.textbox }, --DOC_HIDE
forced_width = 100, --DOC_HIDE
widget = wibox.layout.fixed.vertical --DOC_HIDE
}, --DOC_HIDE
border_color = "#ff0000", --DOC_HIDE
border_width = 2, --DOC_HIDE
placement = awful.placement.centered, --DOC_HIDE
} --DOC_HIDE
p:_apply_size_now() --DOC_HIDE
awesome.emit_signal("refresh") --DOC_HIDE
p._drawable._do_redraw() --DOC_HIDE
--DOC_HIDE Necessary as the widgets are drawn later
gears.timer.delayed_call(function() --DOC_HIDE
-- Get the 4th textbox --DOC_HIDE
local list = p:find_widgets(30, 40) --DOC_HIDE
mouse.coords {x= 120, y=125} --DOC_HIDE
mouse.push_history() --DOC_HIDE
local textboxinstance = list[#list] --DOC_HIDE
for _, v in ipairs {"left", "right"} do
local p2 = awful.popup {
widget = wibox.widget {
text = "On the "..v,
forced_height = 100,
widget = wibox.widget.textbox
},
border_color = "#0000ff",
preferred_positions = v,
border_width = 2,
}
p2:move_next_to(textboxinstance, v)
end
end) --DOC_HIDE
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,34 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { --DOC_HIDE --DOC_NO_USAGE
popup = require("awful.popup"), --DOC_HIDE
placement = require("awful.placement"), --DOC_HIDE
widget = {clienticon =require("awful.widget.clienticon"), --DOC_HIDE
tasklist = require("awful.widget.tasklist")} --DOC_HIDE
} --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
local beautiful = require("beautiful") --DOC_HIDE
local previous = nil
for i=1, 5 do
local p2 = awful.popup {
widget = wibox.widget {
text = "Hello world! "..i.." aaaa.",
widget = wibox.widget.textbox
},
border_color = beautiful.border_color,
preferred_positions = "bottom",
border_width = 2,
preferred_anchors = "back",
placement = (not previous) and awful.placement.top or nil,
offset = {
y = 10,
},
}
p2:_apply_size_now() --DOC_HIDE
p2:move_next_to(previous)
previous = p2
previous:_apply_size_now() --DOC_HIDE
end
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,42 @@
--DOC_GEN_IMAGE --DOC_HIDE
local awful = { placement = require("awful.placement"), --DOC_HIDE
popup = require("awful.popup") } --DOC_HIDE --DOC_NO_USAGE
local gears = { shape = require("gears.shape") } --DOC_HIDE
local wibox = require("wibox") --DOC_HIDE
awful.popup {
widget = {
{
{
text = "foobar",
widget = wibox.widget.textbox
},
{
{
text = "foobar",
widget = wibox.widget.textbox
},
bg = "#ff00ff",
clip = true,
shape = gears.shape.rounded_bar,
widget = wibox.widget.background
},
{
value = 0.5,
forced_height = 30,
forced_width = 100,
widget = wibox.widget.progressbar
},
layout = wibox.layout.fixed.vertical,
},
margins = 10,
widget = wibox.container.margin
},
border_color = "#00ff00",
border_width = 5,
placement = awful.placement.top_left,
shape = gears.shape.rounded_rect,
visible = true,
}
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

View File

@ -0,0 +1,247 @@
--DOC_GEN_IMAGE
--DOC_HIDE_ALL
--DOC_NO_USAGE
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful") --DOC_HIDE
screen[1]._resize {width = 640, height = 480}
-- This example is used to show the various type of wibox awesome provides
-- and mimic the default config look
local c = client.gen_fake {hide_first=true}
c:geometry {
x = 50,
y = 350,
height = 100,
width = 150,
}
c._old_geo = {c:geometry()}
c:set_label("A client")
local wb = awful.wibar {
position = "top",
}
-- Create the same number of tags as the default config
awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, screen[1], awful.layout.layouts[1])
-- Only bother with widgets that are visible by default
local mykeyboardlayout = awful.widget.keyboardlayout()
local mytextclock = wibox.widget.textclock()
local mylayoutbox = awful.widget.layoutbox(screen[1])
local mytaglist = awful.widget.taglist(screen[1], awful.widget.taglist.filter.all, {})
local mytasklist = awful.widget.tasklist(screen[1], awful.widget.tasklist.filter.currenttags, {})
wb:setup {
layout = wibox.layout.align.horizontal,
{ -- Left widgets
layout = wibox.layout.fixed.horizontal,
awful.titlebar.widget.iconwidget(c), --looks close enough
mytaglist,
},
mytasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
mykeyboardlayout,
mytextclock,
mylayoutbox,
},
}
-- The popup
awful.popup {
widget = wibox.widget {
--TODO use the layoutlist for this example
awful.widget.taglist {
filter = awful.widget.taglist.filter.all,
screen = 1,
base_layout = wibox.widget {
spacing = 5,
forced_num_cols = 5,
layout = wibox.layout.grid.vertical,
},
widget_template = {
{
--TODO use the layoutlist for this example
-- {
-- id = 'icon_role',
-- forced_height = 22,
-- forced_width = 22,
-- widget = wibox.widget.imagebox,
-- },
{
id = "text_role",
forced_height = 22,
forced_width = 22,
widget = wibox.widget.textbox
},
margins = 4,
widget = wibox.container.margin,
},
id = 'background_role',
forced_width = 24,
forced_height = 24,
shape = gears.shape.rounded_rect,
widget = wibox.container.background,
},
},
margins = 4,
widget = wibox.container.margin,
},
border_color = beautiful.border_color,
border_width = beautiful.border_width,
placement = awful.placement.centered,
ontop = true,
shape = gears.shape.rounded_rect
}
-- poor copy of awful.widget.calendar_widget until I fix its API to be less
-- insane.
local p10 = awful.popup {
widget = {
wibox.widget.calendar.month(os.date('*t')),
top = 30,
margins = 10,
layout = wibox.container.margin
},
preferred_anchors = "middle",
border_width = 2,
border_color = beautiful.border_color,
hide_on_right_click = true,
placement = function(d) return awful.placement.top_right(d, {
honor_workarea = true,
}) end,
shape = gears.shape.infobubble,
}
awesome.emit_signal("refresh")
p10:bind_to_widget(mytextclock)
-- The titlebar
local top_titlebar = awful.titlebar(c, {
height = 20,
bg_normal = "#ff0000",
})
top_titlebar : setup {
{ -- Left
awful.titlebar.widget.iconwidget(c),
layout = wibox.layout.fixed.horizontal
},
{ -- Middle
{ -- Title
align = "center",
widget = awful.titlebar.widget.titlewidget(c)
},
layout = wibox.layout.flex.horizontal
},
{ -- Right
awful.titlebar.widget.floatingbutton (c),
awful.titlebar.widget.maximizedbutton(c),
awful.titlebar.widget.stickybutton (c),
awful.titlebar.widget.ontopbutton (c),
awful.titlebar.widget.closebutton (c),
layout = wibox.layout.fixed.horizontal()
},
layout = wibox.layout.align.horizontal
}
-- Normal wiboxes
wibox {
width = 50,
height = 50,
shape = gears.shape.octogon,
color = "#0000ff",
x = 570,
y = 410,
border_width = 2,
border_color = beautiful.border_color,
}
-- The tooltip
mouse.coords{x=50, y= 100}
mouse.push_history()
local tt = awful.tooltip {
text = "A tooltip!",
visible = true,
}
tt.bg = beautiful.bg_normal
-- Extra information overlay
local overlay_w = wibox {
bg = "#00000000",
visible = true,
ontop = true,
}
awful.placement.maximize(overlay_w)
local canvas = wibox.layout.manual()
canvas.forced_height = 480
canvas.forced_width = 640
overlay_w:set_widget(canvas)
local function create_info(text, x, y, width, height)
canvas:add_at(wibox.widget {
{
{
text = text,
align = "center",
ellipsize = "none",
widget = wibox.widget.textbox
},
margins = 10,
widget = wibox.container.margin
},
forced_width = width,
forced_height = height,
shape = gears.shape.rectangle,
shape_border_width = 1,
shape_border_color = beautiful.border_color,
bg = "#ffff0055",
widget = wibox.container.background
}, {x = x, y = y})
end
local function create_line(x1, y1, x2, y2)
return canvas:add_at(wibox.widget {
fit = function()
return x2-x1+6, y2-y1+6
end,
draw = function(_, _, cr)
cr:set_source_rgb(0,0,0)
cr:set_line_width(1)
cr:arc(1.5, 1.5, 1.5, 0, math.pi*2)
cr:arc(x2-x1+1.5, y2-y1+1.5, 1.5, 0, math.pi*2)
cr:fill()
cr:move_to(1.5,1.5)
cr:line_to(x2-x1+1.5, y2-y1+1.5)
cr:stroke()
end,
layout = wibox.widget.base.make_widget,
}, {x=x1, y=y1})
end
create_info("awful.wibar", 200, 50, 100, 30)
create_info("awful.titlebar", 250, 350, 100, 30)
create_info("awful.tooltip", 30, 130, 100, 30)
create_info("awful.popup", 450, 240, 100, 30)
create_info("Standard `wibox1`", 420, 420, 130, 30)
create_line(250, 10, 250, 55)
create_line(75, 100, 75, 135)
create_line(545, 432, 575, 432)
create_line(500, 165, 500, 245)
create_line(390, 250, 450, 250)
create_line(190, 365, 255, 365)
--DOC_HIDE vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80