2008-09-29 16:49:18 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local ipairs = ipairs
|
|
|
|
local pairs = pairs
|
2008-10-19 19:14:55 +02:00
|
|
|
local table = table
|
2008-12-04 20:20:16 +01:00
|
|
|
local otable = otable
|
2008-12-29 18:06:41 +01:00
|
|
|
local type = type
|
2008-09-29 16:49:18 +02:00
|
|
|
local capi =
|
|
|
|
{
|
|
|
|
screen = screen,
|
|
|
|
client = client,
|
|
|
|
button = button,
|
|
|
|
widget = widget,
|
2008-12-03 15:23:10 +01:00
|
|
|
image = image,
|
2008-09-29 16:49:18 +02:00
|
|
|
mouse = mouse
|
|
|
|
}
|
|
|
|
local util = require("awful.util")
|
2008-10-19 19:14:55 +02:00
|
|
|
local hooks = require("awful.hooks")
|
2008-11-13 11:53:41 +01:00
|
|
|
local beautiful = require("beautiful")
|
2008-10-22 14:22:48 +02:00
|
|
|
local menu = require("awful.menu")
|
2008-12-01 16:26:41 +01:00
|
|
|
local client = require("awful.client")
|
2009-01-13 16:04:11 +01:00
|
|
|
local tag = require("awful.tag")
|
2008-09-29 16:49:18 +02:00
|
|
|
|
|
|
|
--- Widget module for awful
|
|
|
|
module("awful.widget")
|
|
|
|
|
|
|
|
-- Various public structures
|
|
|
|
taglist = {}
|
|
|
|
taglist.label = {}
|
|
|
|
tasklist = {}
|
|
|
|
tasklist.label = {}
|
|
|
|
|
2008-12-08 19:56:00 +01:00
|
|
|
-- Private structures
|
|
|
|
local tagwidgets = otable()
|
|
|
|
|
2009-01-13 16:04:11 +01:00
|
|
|
local function list_update(w, buttons, label, data, widgets, objects)
|
2008-12-04 23:06:38 +01:00
|
|
|
-- Hack: if it has been registered as a widget in a wibox,
|
|
|
|
-- it's w.len since __len meta does not work on table until Lua 5.2.
|
|
|
|
-- Otherwise it's standard #w.
|
2009-01-13 16:04:11 +01:00
|
|
|
local len = (w.len or #w) / 2
|
2008-12-04 23:06:38 +01:00
|
|
|
-- Add more widgets
|
2009-01-13 16:04:11 +01:00
|
|
|
if len < #objects then
|
|
|
|
for i = len * 2 + 1, #objects * 2, 2 do
|
|
|
|
w[i] = capi.widget({ type = "imagebox", align = widgets.imagebox.align })
|
|
|
|
w[i + 1] = capi.widget({ type = "textbox", align = widgets.textbox.align })
|
|
|
|
w[i + 1]:margin({ left = widgets.textbox.margin.left, right = widgets.textbox.margin.right })
|
|
|
|
w[i + 1].bg_resize = widgets.textbox.bg_resize or false
|
|
|
|
w[i + 1].bg_align = widgets.textbox.bg_align or ""
|
2008-12-04 23:06:38 +01:00
|
|
|
end
|
|
|
|
-- Remove widgets
|
2009-01-13 16:04:11 +01:00
|
|
|
elseif len > #objects then
|
|
|
|
for i = #objects * 2 + 1, len * 2, 2 do
|
2008-12-04 23:06:38 +01:00
|
|
|
w[i] = nil
|
2009-01-13 16:04:11 +01:00
|
|
|
w[i + 1] = nil
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
2008-12-04 23:06:38 +01:00
|
|
|
end
|
2009-01-13 16:04:11 +01:00
|
|
|
|
|
|
|
-- update widgets text
|
|
|
|
for k = 1, #objects * 2, 2 do
|
|
|
|
local o = objects[(k + 1) / 2]
|
|
|
|
if buttons then
|
|
|
|
if not data[o] then
|
|
|
|
data[o] = { }
|
2009-01-18 17:02:29 +01:00
|
|
|
-- Replace press function by a new one calling with object as
|
2009-01-13 16:04:11 +01:00
|
|
|
-- argument
|
|
|
|
for kb, b in ipairs(buttons) do
|
|
|
|
-- Copy object
|
|
|
|
data[o][kb] = capi.button(b)
|
2009-01-18 17:02:29 +01:00
|
|
|
data[o][kb].press = function () b.press(o) end
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
|
|
|
end
|
2009-01-13 16:04:11 +01:00
|
|
|
w[k]:buttons(data[o])
|
|
|
|
w[k + 1]:buttons(data[o])
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
2009-01-13 16:04:11 +01:00
|
|
|
|
|
|
|
local text, bg, bg_image, icon = label(o)
|
|
|
|
w[k + 1].text, w[k + 1].bg, w[k + 1].bg_image = text, bg, bg_image
|
|
|
|
w[k].bg, w[k].image = bg, icon
|
|
|
|
if not w[k + 1].text then
|
|
|
|
w[k+1].visible = false
|
|
|
|
else
|
|
|
|
w[k+1].visible = true
|
|
|
|
end
|
|
|
|
if not w[k].image then
|
|
|
|
w[k].visible = false
|
|
|
|
else
|
|
|
|
w[k].visible = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function taglist_update (screen, w, label, buttons, data, widgets)
|
|
|
|
local tags = capi.screen[screen]:tags()
|
|
|
|
|
|
|
|
list_update(w, buttons, label, data, widgets, tags)
|
2008-12-04 23:06:38 +01:00
|
|
|
end
|
|
|
|
|
2008-12-08 19:56:00 +01:00
|
|
|
function taglist.gettag(widget)
|
|
|
|
return tagwidgets[widget]
|
|
|
|
end
|
|
|
|
|
2008-12-04 23:06:38 +01:00
|
|
|
--- Create a new taglist widget.
|
|
|
|
-- @param screen The screen to draw tag list for.
|
|
|
|
-- @param label Label function to use.
|
|
|
|
-- @param buttons A table with buttons binding to set.
|
|
|
|
function taglist.new(screen, label, buttons)
|
|
|
|
local w = {}
|
2009-01-13 16:04:11 +01:00
|
|
|
local widgets = { }
|
|
|
|
widgets.imagebox = { }
|
|
|
|
widgets.textbox = { ["margin"] = { ["left"] = 0,
|
|
|
|
["right"] = 0},
|
|
|
|
["bg_resize"] = true
|
|
|
|
}
|
2008-12-04 23:06:38 +01:00
|
|
|
local data = otable()
|
|
|
|
local u = function (s)
|
|
|
|
if s == screen then
|
2009-01-13 16:04:11 +01:00
|
|
|
taglist_update(s, w, label, buttons, data, widgets)
|
2008-12-04 23:06:38 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
local uc = function (c) return u(c.screen) end
|
|
|
|
hooks.focus.register(uc)
|
|
|
|
hooks.unfocus.register(uc)
|
|
|
|
hooks.arrange.register(u)
|
|
|
|
hooks.tags.register(u)
|
|
|
|
hooks.tagged.register(uc)
|
2008-10-19 19:14:55 +02:00
|
|
|
hooks.property.register(function (c, prop)
|
2008-12-04 23:06:38 +01:00
|
|
|
if prop == "urgent" then
|
|
|
|
u(c.screen)
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
|
|
|
end)
|
2008-12-04 23:06:38 +01:00
|
|
|
-- Free data on tag removal
|
|
|
|
hooks.tags.register(function (s, tag, action)
|
|
|
|
if action == "remove" then data[tag] = nil end
|
|
|
|
end)
|
|
|
|
u(screen)
|
2008-10-19 19:14:55 +02:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
--- Return labels for a taglist widget with all tag from screen.
|
|
|
|
-- It returns the tag name and set a special
|
|
|
|
-- foreground and background color for selected tags.
|
|
|
|
-- @param t The tag.
|
|
|
|
-- @param args The arguments table.
|
|
|
|
-- bg_focus The background color for selected tag.
|
|
|
|
-- fg_focus The foreground color for selected tag.
|
|
|
|
-- bg_urgent The background color for urgent tags.
|
|
|
|
-- fg_urgent The foreground color for urgent tags.
|
2008-11-17 20:32:26 +01:00
|
|
|
-- squares_sel Optional: a user provided image for selected squares.
|
|
|
|
-- squares_unsel Optional: a user provided image for unselected squares.
|
|
|
|
-- squares_resize Optional: true or false to resize squares.
|
2008-12-03 15:23:10 +01:00
|
|
|
-- @return A string to print, a background color, a background image and a
|
|
|
|
-- background resize value.
|
2008-09-29 16:49:18 +02:00
|
|
|
function taglist.label.all(t, args)
|
|
|
|
if not args then args = {} end
|
|
|
|
local theme = beautiful.get()
|
|
|
|
local fg_focus = args.fg_focus or theme.taglist_fg_focus or theme.fg_focus
|
|
|
|
local bg_focus = args.bg_focus or theme.taglist_bg_focus or theme.bg_focus
|
|
|
|
local fg_urgent = args.fg_urgent or theme.taglist_fg_urgent or theme.fg_urgent
|
|
|
|
local bg_urgent = args.bg_urgent or theme.taglist_bg_urgent or theme.bg_urgent
|
2008-11-10 11:57:20 +01:00
|
|
|
local taglist_squares_sel = args.squares_sel or theme.taglist_squares_sel
|
|
|
|
local taglist_squares_unsel = args.squares_unsel or theme.taglist_squares_unsel
|
2008-11-15 05:19:51 +01:00
|
|
|
local taglist_squares_resize = theme.taglist_squares_resize or args.squares_resize or "true"
|
2008-11-23 09:15:32 +01:00
|
|
|
local font = args.font or theme.taglist_font or theme.font or ""
|
2009-01-13 16:04:11 +01:00
|
|
|
local text = "<span font_desc='"..font.."'>"
|
2008-09-29 16:49:18 +02:00
|
|
|
local sel = capi.client.focus
|
|
|
|
local bg_color = nil
|
|
|
|
local fg_color = nil
|
2008-12-03 15:23:10 +01:00
|
|
|
local bg_image
|
2009-01-13 16:04:11 +01:00
|
|
|
local icon
|
2008-12-03 15:23:10 +01:00
|
|
|
local bg_resize = false
|
2008-09-29 16:49:18 +02:00
|
|
|
if t.selected then
|
|
|
|
bg_color = bg_focus
|
|
|
|
fg_color = fg_focus
|
|
|
|
end
|
|
|
|
if sel and sel:tags()[t] then
|
2008-11-10 11:57:20 +01:00
|
|
|
if taglist_squares_sel then
|
2008-12-03 15:23:10 +01:00
|
|
|
bg_image = capi.image(taglist_squares_sel)
|
|
|
|
bg_resize = taglist_squares_resize == "true"
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2008-10-23 17:55:38 +02:00
|
|
|
else
|
|
|
|
local cls = t:clients()
|
2008-11-10 11:57:20 +01:00
|
|
|
if #cls > 0 and taglist_squares_unsel then
|
2008-12-03 15:23:10 +01:00
|
|
|
bg_image = capi.image(taglist_squares_unsel)
|
|
|
|
bg_resize = taglist_squares_resize == "true"
|
2008-10-23 17:55:38 +02:00
|
|
|
end
|
|
|
|
for k, c in pairs(cls) do
|
2008-09-29 16:49:18 +02:00
|
|
|
if c.urgent then
|
2008-10-23 17:55:38 +02:00
|
|
|
if bg_urgent then bg_color = bg_urgent end
|
|
|
|
if fg_urgent then fg_color = fg_urgent end
|
2008-09-29 16:49:18 +02:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-01-13 16:04:11 +01:00
|
|
|
local taglist_squares = false
|
|
|
|
if taglist_squares_sel or taglist_squares_unsel then
|
|
|
|
taglist_squares = true
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2009-01-13 16:04:11 +01:00
|
|
|
if t.name then
|
|
|
|
if fg_color then
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_color).."'>"
|
|
|
|
if taglist_squares then
|
|
|
|
text = text .. " "
|
|
|
|
end
|
|
|
|
text = text..util.escape(t.name).." </span>"
|
|
|
|
else
|
|
|
|
if taglist_squares then
|
|
|
|
text = text .. " "
|
|
|
|
end
|
|
|
|
text = text .. util.escape(t.name) .. " "
|
|
|
|
end
|
|
|
|
elseif taglist_squares then
|
|
|
|
text = text .. " "
|
|
|
|
end
|
|
|
|
text = text .. "</span>"
|
|
|
|
if tag.geticon(t) and type(tag.geticon(t)) == "image" then
|
|
|
|
icon = tag.geticon(t)
|
|
|
|
elseif tag.geticon(t) then
|
|
|
|
icon = capi.image(tag.geticon(t))
|
|
|
|
end
|
|
|
|
|
|
|
|
return text, bg_color, bg_image, icon
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Return labels for a taglist widget with all *non empty* tags from screen.
|
|
|
|
-- It returns the tag name and set a special
|
|
|
|
-- foreground and background color for selected tags.
|
|
|
|
-- @param t The tag.
|
|
|
|
-- @param args The arguments table.
|
|
|
|
-- bg_focus The background color for selected tag.
|
|
|
|
-- fg_focus The foreground color for selected tag.
|
|
|
|
-- bg_urgent The background color for urgent tags.
|
|
|
|
-- fg_urgent The foreground color for urgent tags.
|
2008-12-03 15:23:10 +01:00
|
|
|
-- @return A string to print, a background color, a background image and a
|
|
|
|
-- background resize value.
|
2008-09-29 16:49:18 +02:00
|
|
|
function taglist.label.noempty(t, args)
|
|
|
|
if #t:clients() > 0 or t.selected then
|
2008-11-13 10:19:09 +01:00
|
|
|
return taglist.label.all(t, args)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-01-13 16:04:11 +01:00
|
|
|
local function tasklist_update(w, buttons, label, data, widgets)
|
2008-12-04 20:20:16 +01:00
|
|
|
local clients = capi.client.get()
|
|
|
|
local shownclients = {}
|
|
|
|
for k, c in ipairs(clients) do
|
|
|
|
if not (c.skip_taskbar or c.hide
|
|
|
|
or c.type == "splash" or c.type == "dock" or c.type == "desktop") then
|
|
|
|
table.insert(shownclients, c)
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
2008-12-04 20:20:16 +01:00
|
|
|
end
|
|
|
|
clients = shownclients
|
2009-01-13 16:04:11 +01:00
|
|
|
|
|
|
|
list_update(w, buttons, label, data, widgets, clients)
|
2008-12-04 20:20:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new tasklist widget.
|
|
|
|
-- @param label Label function to use.
|
|
|
|
-- @param buttons A table with buttons binding to set.
|
|
|
|
function tasklist.new(label, buttons)
|
|
|
|
local w = {}
|
2009-01-13 16:04:11 +01:00
|
|
|
local widgets = { }
|
|
|
|
widgets.imagebox = { ["align"] = "flex" }
|
|
|
|
widgets.textbox = { ["align"] = "flex",
|
|
|
|
["margin"] = { ["left"] = 2,
|
|
|
|
["right"] = 2 },
|
|
|
|
["bg_resize"] = true,
|
|
|
|
["bg_align"] = "right"
|
|
|
|
}
|
2008-12-04 20:20:16 +01:00
|
|
|
local data = otable()
|
2009-01-13 16:04:11 +01:00
|
|
|
local u = function () tasklist_update(w, buttons, label, data, widgets) end
|
2008-12-04 20:20:16 +01:00
|
|
|
hooks.arrange.register(u)
|
|
|
|
hooks.clients.register(u)
|
|
|
|
hooks.tagged.register(u)
|
|
|
|
hooks.focus.register(u)
|
|
|
|
hooks.unfocus.register(u)
|
2008-10-19 19:14:55 +02:00
|
|
|
hooks.property.register(function (c, prop)
|
|
|
|
if prop == "urgent"
|
|
|
|
or prop == "floating"
|
2008-11-25 11:54:38 +01:00
|
|
|
or prop == "maximized_horizontal"
|
|
|
|
or prop == "maximized_vertical"
|
2008-10-21 15:07:18 +02:00
|
|
|
or prop == "icon"
|
2008-10-21 15:12:55 +02:00
|
|
|
or prop == "name"
|
|
|
|
or prop == "icon_name" then
|
2008-12-04 20:20:16 +01:00
|
|
|
u()
|
2008-10-19 19:14:55 +02:00
|
|
|
end
|
|
|
|
end)
|
2008-12-04 20:20:16 +01:00
|
|
|
u()
|
|
|
|
-- Free data on unmanage
|
|
|
|
hooks.unmanage.register(function (c) data[c] = nil end)
|
2008-10-19 19:14:55 +02:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
local function widget_tasklist_label_common(c, args)
|
|
|
|
if not args then args = {} end
|
|
|
|
local theme = beautiful.get()
|
|
|
|
local fg_focus = args.fg_focus or theme.tasklist_fg_focus or theme.fg_focus
|
|
|
|
local bg_focus = args.bg_focus or theme.tasklist_bg_focus or theme.bg_focus
|
|
|
|
local fg_urgent = args.fg_urgent or theme.tasklist_fg_urgent or theme.fg_urgent
|
|
|
|
local bg_urgent = args.bg_urgent or theme.tasklist_bg_urgent or theme.bg_urgent
|
2008-11-10 11:57:20 +01:00
|
|
|
local floating_icon = args.floating_icon or theme.tasklist_floating_icon
|
2008-11-23 09:15:32 +01:00
|
|
|
local font = args.font or theme.tasklist_font or theme.font or ""
|
2008-10-19 19:14:55 +02:00
|
|
|
local bg = nil
|
2008-12-02 18:14:51 +01:00
|
|
|
local text = "<span font_desc='"..font.."'>"
|
2008-09-29 16:49:18 +02:00
|
|
|
local name
|
2008-12-03 15:23:10 +01:00
|
|
|
local status_image
|
2008-12-01 16:26:41 +01:00
|
|
|
if client.floating.get(c) and floating_icon then
|
2008-12-03 15:23:10 +01:00
|
|
|
status_image = capi.image(floating_icon)
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2008-11-25 11:55:56 +01:00
|
|
|
if c.minimized then
|
2008-09-29 16:49:18 +02:00
|
|
|
name = util.escape(c.icon_name) or ""
|
|
|
|
else
|
|
|
|
name = util.escape(c.name) or ""
|
|
|
|
end
|
|
|
|
if capi.client.focus == c then
|
2008-12-03 11:36:52 +01:00
|
|
|
bg = bg_focus
|
|
|
|
if fg_focus then
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_focus).."'>"..name.."</span>"
|
2008-09-29 16:49:18 +02:00
|
|
|
else
|
2008-10-01 17:03:49 +02:00
|
|
|
text = text .. name
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2008-12-03 11:36:52 +01:00
|
|
|
elseif c.urgent and fg_urgent then
|
2008-12-10 17:36:54 +01:00
|
|
|
bg = bg_urgent
|
2008-12-03 11:36:52 +01:00
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_urgent).."'>"..name.."</span>"
|
2008-09-29 16:49:18 +02:00
|
|
|
else
|
2008-10-01 17:03:49 +02:00
|
|
|
text = text .. name
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
2008-11-23 09:15:32 +01:00
|
|
|
text = text .. "</span>"
|
2009-01-13 16:04:11 +01:00
|
|
|
return text, bg, status_image, c.icon
|
2008-09-29 16:49:18 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Return labels for a tasklist widget with clients from all tags and screen.
|
|
|
|
-- It returns the client name and set a special
|
|
|
|
-- foreground and background color for focused client.
|
|
|
|
-- It also puts a special icon for floating windows.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
|
|
|
-- @param args The arguments table.
|
|
|
|
-- bg_focus The background color for focused client.
|
|
|
|
-- fg_focus The foreground color for focused client.
|
|
|
|
-- bg_urgent The background color for urgent clients.
|
|
|
|
-- fg_urgent The foreground color for urgent clients.
|
2008-12-03 15:23:10 +01:00
|
|
|
-- @return A string to print, a background color and a status image.
|
2008-09-29 16:49:18 +02:00
|
|
|
function tasklist.label.allscreen(c, screen, args)
|
|
|
|
return widget_tasklist_label_common(c, args)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return labels for a tasklist widget with clients from all tags.
|
|
|
|
-- It returns the client name and set a special
|
|
|
|
-- foreground and background color for focused client.
|
|
|
|
-- It also puts a special icon for floating windows.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
|
|
|
-- @param args The arguments table.
|
|
|
|
-- bg_focus The background color for focused client.
|
|
|
|
-- fg_focus The foreground color for focused client.
|
|
|
|
-- bg_urgent The background color for urgent clients.
|
|
|
|
-- fg_urgent The foreground color for urgent clients.
|
2008-12-03 15:23:10 +01:00
|
|
|
-- @return A string to print, a background color and a status image.
|
2008-09-29 16:49:18 +02:00
|
|
|
function tasklist.label.alltags(c, screen, args)
|
|
|
|
-- Only print client on the same screen as this widget
|
|
|
|
if c.screen ~= screen then return end
|
|
|
|
return widget_tasklist_label_common(c, args)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Return labels for a tasklist widget with clients from currently selected tags.
|
|
|
|
-- It returns the client name and set a special
|
|
|
|
-- foreground and background color for focused client.
|
|
|
|
-- It also puts a special icon for floating windows.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
|
|
|
-- @param args The arguments table.
|
|
|
|
-- bg_focus The background color for focused client.
|
|
|
|
-- fg_focus The foreground color for focused client.
|
|
|
|
-- bg_urgent The background color for urgent clients.
|
|
|
|
-- fg_urgent The foreground color for urgent clients.
|
2008-12-03 15:23:10 +01:00
|
|
|
-- @return A string to print, a background color and a status image.
|
2008-09-29 16:49:18 +02:00
|
|
|
function tasklist.label.currenttags(c, screen, args)
|
|
|
|
-- Only print client on the same screen as this widget
|
|
|
|
if c.screen ~= screen then return end
|
|
|
|
for k, t in ipairs(capi.screen[screen]:tags()) do
|
|
|
|
if t.selected and c:tags()[t] then
|
|
|
|
return widget_tasklist_label_common(c, args)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a button widget. When clicked, the image is deplaced to make it like
|
|
|
|
-- a real button.
|
2008-12-29 18:06:41 +01:00
|
|
|
-- @param args Standard widget table arguments, plus image for the image path or
|
|
|
|
-- the image object.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return A textbox widget configured as a button.
|
|
|
|
function button(args)
|
2008-11-10 10:42:19 +01:00
|
|
|
if not args or not args.image then return end
|
2008-12-29 18:06:41 +01:00
|
|
|
local img_release
|
|
|
|
if type(args.image) == "string" then
|
2008-12-29 18:15:09 +01:00
|
|
|
img_release = capi.image(args.image)
|
2008-12-29 18:06:41 +01:00
|
|
|
elseif type(args.image) == "image" then
|
|
|
|
img_release = args.image
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2008-12-03 15:23:10 +01:00
|
|
|
local img_press = img_release:crop(-2, -2, img_release.width, img_release.height)
|
|
|
|
args.type = "imagebox"
|
2008-09-29 16:49:18 +02:00
|
|
|
local w = capi.widget(args)
|
2008-12-03 15:23:10 +01:00
|
|
|
w.image = img_release
|
|
|
|
w:buttons({ capi.button({}, 1, function () w.image = img_press end, function () w.image = img_release end) })
|
|
|
|
function w.mouse_leave(s) w.image = img_release end
|
|
|
|
function w.mouse_enter(s) if capi.mouse.coords().buttons[1] then w.image = img_press end end
|
2008-09-29 16:49:18 +02:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a button widget which will launch a command.
|
|
|
|
-- @param args Standard widget table arguments, plus image for the image path
|
2008-10-22 14:22:48 +02:00
|
|
|
-- and command for the command to run on click, or either menu to create menu.
|
2008-09-29 16:49:18 +02:00
|
|
|
-- @return A launcher widget.
|
|
|
|
function launcher(args)
|
2008-10-22 14:22:48 +02:00
|
|
|
if not args.command and not args.menu then return end
|
2008-09-29 16:49:18 +02:00
|
|
|
local w = button(args)
|
2008-11-10 10:42:19 +01:00
|
|
|
if not w then return end
|
2008-09-29 16:49:18 +02:00
|
|
|
local b = w:buttons()
|
2008-10-22 14:22:48 +02:00
|
|
|
|
|
|
|
if args.command then
|
|
|
|
b[#b + 1] = capi.button({}, 1, nil, function () util.spawn(args.command) end)
|
|
|
|
elseif args.menu then
|
2008-11-07 15:27:35 +01:00
|
|
|
b[#b + 1] = capi.button({}, 1, nil, function () args.menu:toggle() end)
|
2008-10-22 14:22:48 +02:00
|
|
|
end
|
|
|
|
|
2008-09-29 16:49:18 +02:00
|
|
|
w:buttons(b)
|
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|