2009-02-27 17:22:03 +01:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2008-2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- Grab environment we need
|
|
|
|
local capi = { screen = screen,
|
|
|
|
image = image,
|
|
|
|
client = client }
|
|
|
|
local ipairs = ipairs
|
2009-05-18 16:42:03 +02:00
|
|
|
local type = type
|
2009-04-11 14:15:45 +02:00
|
|
|
local setmetatable = setmetatable
|
2009-02-27 17:22:03 +01:00
|
|
|
local table = table
|
|
|
|
local hooks = require("awful.hooks")
|
|
|
|
local common = require("awful.widget.common")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local client = require("awful.client")
|
|
|
|
local util = require("awful.util")
|
|
|
|
|
|
|
|
--- Tasklist widget module for awful
|
|
|
|
module("awful.widget.tasklist")
|
|
|
|
|
|
|
|
-- Public structures
|
|
|
|
label = {}
|
|
|
|
|
|
|
|
local function tasklist_update(w, buttons, label, data, widgets)
|
|
|
|
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)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
clients = shownclients
|
|
|
|
|
|
|
|
common.list_update(w, buttons, label, data, widgets, clients)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new tasklist widget.
|
|
|
|
-- @param label Label function to use.
|
|
|
|
-- @param buttons A table with buttons binding to set.
|
|
|
|
function new(label, buttons)
|
|
|
|
local w = {}
|
|
|
|
local widgets = { }
|
|
|
|
widgets.imagebox = { align = "flex" }
|
|
|
|
widgets.textbox = { align = "flex",
|
|
|
|
margin = { left = 2,
|
|
|
|
right = 2 },
|
|
|
|
bg_resize = true,
|
|
|
|
bg_align = "right"
|
|
|
|
}
|
2009-04-11 14:15:45 +02:00
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
2009-02-27 17:22:03 +01:00
|
|
|
local u = function () tasklist_update(w, buttons, label, data, widgets) end
|
2009-05-18 17:14:43 +02:00
|
|
|
hooks.tags.register(u)
|
2009-02-27 17:22:03 +01:00
|
|
|
hooks.clients.register(u)
|
|
|
|
hooks.tagged.register(u)
|
|
|
|
hooks.focus.register(u)
|
|
|
|
hooks.unfocus.register(u)
|
|
|
|
hooks.property.register(function (c, prop)
|
2009-05-18 16:42:03 +02:00
|
|
|
if type(c) ~= "client" then return end
|
2009-02-27 17:22:03 +01:00
|
|
|
if prop == "urgent"
|
|
|
|
or prop == "floating"
|
|
|
|
or prop == "maximized_horizontal"
|
|
|
|
or prop == "maximized_vertical"
|
|
|
|
or prop == "icon"
|
|
|
|
or prop == "name"
|
2009-05-28 07:37:17 +02:00
|
|
|
or prop == "icon_name"
|
|
|
|
or prop == "skip_taskbar" then
|
2009-02-27 17:22:03 +01:00
|
|
|
u()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
u()
|
2009-05-08 14:36:39 +02:00
|
|
|
-- Free data on unmanage.
|
|
|
|
-- You may thing we do not need to clear data[] on unmanage because it's a
|
|
|
|
-- weak-keyed table. But in fact we need, because it's a loop reference
|
|
|
|
-- between data[client] and data[client][i] = button(reference a client in
|
|
|
|
-- the Lua registry) and since the registry and the button() are totally
|
|
|
|
-- unconnected, Lua does not free anything.
|
|
|
|
hooks.unmanage.register(function (c) data[c] = nil end)
|
2009-02-27 17:22:03 +01:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
local fg_minimize = args.fg_minimize or theme.tasklist_fg_minimize or theme.fg_minimize
|
|
|
|
local bg_minimize = args.bg_minimize or theme.tasklist_bg_minimize or theme.bg_minimize
|
|
|
|
local floating_icon = args.floating_icon or theme.tasklist_floating_icon
|
|
|
|
local font = args.font or theme.tasklist_font or theme.font or ""
|
|
|
|
local bg = nil
|
|
|
|
local text = "<span font_desc='"..font.."'>"
|
|
|
|
local name
|
|
|
|
local status_image
|
|
|
|
if client.floating.get(c) and floating_icon then
|
|
|
|
status_image = capi.image(floating_icon)
|
|
|
|
end
|
|
|
|
if c.minimized then
|
2009-03-24 14:09:43 +01:00
|
|
|
name = util.escape(c.icon_name) or util.escape(c.name) or util.escape("<untitled>")
|
2009-02-27 17:22:03 +01:00
|
|
|
else
|
|
|
|
name = util.escape(c.name) or util.escape("<untitled>")
|
|
|
|
end
|
|
|
|
if capi.client.focus == c then
|
|
|
|
bg = bg_focus
|
|
|
|
if fg_focus then
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_focus).."'>"..name.."</span>"
|
|
|
|
else
|
|
|
|
text = text .. name
|
|
|
|
end
|
|
|
|
elseif c.urgent and fg_urgent then
|
|
|
|
bg = bg_urgent
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_urgent).."'>"..name.."</span>"
|
|
|
|
elseif c.minimized and fg_minimize and bg_minimize then
|
|
|
|
bg = bg_minimize
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_minimize).."'>"..name.."</span>"
|
|
|
|
else
|
|
|
|
text = text .. name
|
|
|
|
end
|
|
|
|
text = text .. "</span>"
|
|
|
|
return text, bg, status_image, c.icon
|
|
|
|
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.
|
|
|
|
-- @return A string to print, a background color and a status image.
|
|
|
|
function 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.
|
|
|
|
-- @return A string to print, a background color and a status image.
|
|
|
|
function 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.
|
|
|
|
-- @return A string to print, a background color and a status image.
|
|
|
|
function label.currenttags(c, screen, args)
|
|
|
|
-- Only print client on the same screen as this widget
|
|
|
|
if c.screen ~= screen then return end
|
2009-03-25 14:51:14 +01:00
|
|
|
-- Include sticky client too
|
|
|
|
if c.sticky then return widget_tasklist_label_common(c, args) end
|
2009-02-27 17:22:03 +01:00
|
|
|
for k, t in ipairs(capi.screen[screen]:tags()) do
|
2009-03-14 13:47:50 +01:00
|
|
|
if t.selected then
|
|
|
|
local ctags = c:tags()
|
|
|
|
for _, v in ipairs(ctags) do
|
|
|
|
if v == t then
|
|
|
|
return widget_tasklist_label_common(c, args)
|
|
|
|
end
|
|
|
|
end
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-25 11:14:08 +02:00
|
|
|
setmetatable(_M, { __call = function(_, ...) return new(...) end })
|
2009-05-08 11:59:38 +02:00
|
|
|
|
2009-02-27 17:22:03 +01:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|