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,
|
|
|
|
client = client }
|
|
|
|
local ipairs = ipairs
|
2009-04-11 14:15:45 +02:00
|
|
|
local setmetatable = setmetatable
|
2009-02-27 17:22:03 +01:00
|
|
|
local table = table
|
|
|
|
local common = require("awful.widget.common")
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
local client = require("awful.client")
|
|
|
|
local util = require("awful.util")
|
2009-08-18 16:48:19 +02:00
|
|
|
local tag = require("awful.tag")
|
2010-10-06 14:23:36 +02:00
|
|
|
local flex = require("wibox.layout.flex")
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
--- Tasklist widget module for awful
|
2012-06-14 01:08:27 +02:00
|
|
|
-- awful.widget.tasklist
|
|
|
|
local tasklist = { mt = {} }
|
2009-02-27 17:22:03 +01:00
|
|
|
|
|
|
|
-- Public structures
|
2012-06-14 01:08:27 +02:00
|
|
|
tasklist.filter = {}
|
2009-02-27 17:22:03 +01:00
|
|
|
|
2009-10-24 14:53:01 +02:00
|
|
|
local function tasklist_label(c, args)
|
2009-02-27 17:22:03 +01:00
|
|
|
if not args then args = {} end
|
|
|
|
local theme = beautiful.get()
|
2011-10-11 22:24:44 +02:00
|
|
|
local fg_normal = args.fg_normal or theme.tasklist_fg_normal or theme.fg_normal
|
|
|
|
local bg_normal = args.bg_normal or theme.tasklist_bg_normal or theme.bg_normal
|
2009-02-27 17:22:03 +01:00
|
|
|
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 font = args.font or theme.tasklist_font or theme.font or ""
|
|
|
|
local bg = nil
|
|
|
|
local text = "<span font_desc='"..font.."'>"
|
2009-10-03 09:59:27 +02:00
|
|
|
local name = ""
|
2012-01-05 19:31:27 +01:00
|
|
|
|
|
|
|
-- symbol to use to indicate certain client properties
|
2012-01-05 20:24:33 +01:00
|
|
|
local sticky = args.sticky or theme.tasklist_sticky or "▪"
|
2012-01-05 19:31:27 +01:00
|
|
|
local ontop = args.ontop or theme.tasklist_ontop or '⌃'
|
|
|
|
local floating = args.floating or theme.tasklist_floating or '✈'
|
|
|
|
local maximized_horizontal = args.maximized_horizontal or theme.tasklist_maximized_horizontal or '⬌'
|
|
|
|
local maximized_vertical = args.maximized_vertical or theme.tasklist_maximized_vertical or '⬍'
|
|
|
|
|
2012-01-05 20:24:33 +01:00
|
|
|
if c.sticky then name = name .. sticky end
|
2012-01-05 19:31:27 +01:00
|
|
|
if c.ontop then name = name .. ontop end
|
|
|
|
if client.floating.get(c) then name = name .. floating end
|
|
|
|
if c.maximized_horizontal then name = name .. maximized_horizontal end
|
|
|
|
if c.maximized_vertical then name = name .. maximized_vertical end
|
2009-02-27 17:22:03 +01:00
|
|
|
if c.minimized then
|
2010-05-30 12:37:56 +02:00
|
|
|
name = name .. (util.escape(c.icon_name) or util.escape(c.name) or util.escape("<untitled>"))
|
2009-02-27 17:22:03 +01:00
|
|
|
else
|
2010-05-30 12:37:56 +02:00
|
|
|
name = name .. (util.escape(c.name) or util.escape("<untitled>"))
|
2009-02-27 17:22:03 +01:00
|
|
|
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
|
2011-10-11 22:24:44 +02:00
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_normal).."'>"..name.."</span>"
|
2009-02-27 17:22:03 +01:00
|
|
|
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
|
2011-10-11 22:24:44 +02:00
|
|
|
bg = bg_normal
|
|
|
|
text = text .. "<span color='"..util.color_strip_alpha(fg_normal).."'>"..name.."</span>"
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
text = text .. "</span>"
|
2009-10-03 09:59:27 +02:00
|
|
|
return text, bg, nil, c.icon
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
2010-10-06 14:23:36 +02:00
|
|
|
local function tasklist_update(s, w, buttons, filter, data, style)
|
2009-10-24 14:53:01 +02:00
|
|
|
local clients = {}
|
|
|
|
for k, c in ipairs(capi.client.get()) do
|
|
|
|
if not (c.skip_taskbar or c.hidden
|
|
|
|
or c.type == "splash" or c.type == "dock" or c.type == "desktop")
|
|
|
|
and filter(c, s) then
|
|
|
|
table.insert(clients, c)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function label(c) return tasklist_label(c, style) end
|
|
|
|
|
2010-10-06 14:23:36 +02:00
|
|
|
common.list_update(w, buttons, label, data, clients)
|
2009-10-24 14:53:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a new tasklist widget.
|
|
|
|
-- @param screen The screen to draw tasklist for.
|
|
|
|
-- @param filter Filter function to define what clients will be listed.
|
|
|
|
-- @param buttons A table with buttons binding to set.
|
|
|
|
-- @param style The style overrides default theme.
|
2011-10-11 22:24:44 +02:00
|
|
|
-- bg_normal The background color for unfocused client.
|
|
|
|
-- fg_normal The foreground color for unfocused client.
|
2009-02-27 17:22:03 +01:00
|
|
|
-- 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.
|
2009-10-24 14:53:01 +02:00
|
|
|
-- bg_minimize The background color for minimized clients.
|
|
|
|
-- fg_minimize The foreground color for minimized clients.
|
2012-01-05 19:31:27 +01:00
|
|
|
-- floating Symbol to use for floating clients.
|
|
|
|
-- ontop Symbol to use for ontop clients.
|
|
|
|
-- maximized_horizontal Symbol to use for clients that have been horizontally maximized.
|
|
|
|
-- maximized_vertical Symbol to use for clients that have been vertically maximized.
|
2009-10-24 14:53:01 +02:00
|
|
|
-- font The font.
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.new(screen, filter, buttons, style)
|
2010-10-06 14:23:36 +02:00
|
|
|
local w = flex.horizontal()
|
2009-10-24 14:53:01 +02:00
|
|
|
|
2011-10-04 13:55:59 +02:00
|
|
|
local data = setmetatable({}, { __mode = 'k' })
|
2010-10-06 14:23:36 +02:00
|
|
|
local u = function () tasklist_update(screen, w, buttons, filter, data, style) end
|
2009-10-09 20:39:55 +02:00
|
|
|
tag.attached_connect_signal(screen, "property::selected", u)
|
2012-10-20 17:33:32 +02:00
|
|
|
tag.attached_connect_signal(screen, "property::activated", u)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::urgent", u)
|
2012-01-05 20:24:33 +01:00
|
|
|
capi.client.connect_signal("property::sticky", u)
|
2011-03-08 19:28:40 +01:00
|
|
|
capi.client.connect_signal("property::ontop", u)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::floating", u)
|
|
|
|
capi.client.connect_signal("property::maximized_horizontal", u)
|
|
|
|
capi.client.connect_signal("property::maximized_vertical", u)
|
2011-02-19 21:42:39 +01:00
|
|
|
capi.client.connect_signal("property::minimized", u)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::name", u)
|
|
|
|
capi.client.connect_signal("property::icon_name", u)
|
|
|
|
capi.client.connect_signal("property::icon", u)
|
|
|
|
capi.client.connect_signal("property::skip_taskbar", u)
|
2011-07-07 18:50:00 +02:00
|
|
|
capi.client.connect_signal("property::screen", u)
|
2010-08-26 18:31:06 +02:00
|
|
|
capi.client.connect_signal("property::hidden", u)
|
|
|
|
capi.client.connect_signal("tagged", u)
|
|
|
|
capi.client.connect_signal("untagged", u)
|
2009-10-09 20:39:55 +02:00
|
|
|
capi.client.connect_signal("unmanage", u)
|
|
|
|
capi.client.connect_signal("list", u)
|
|
|
|
capi.client.connect_signal("focus", u)
|
|
|
|
capi.client.connect_signal("unfocus", u)
|
2009-10-24 14:53:01 +02:00
|
|
|
u()
|
|
|
|
return w
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
2009-10-24 14:53:01 +02:00
|
|
|
--- Filtering function to include all clients.
|
2009-02-27 17:22:03 +01:00
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
2009-10-24 14:53:01 +02:00
|
|
|
-- @return true
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.filter.allscreen(c, screen)
|
2009-10-24 14:53:01 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Filtering function to include the clients from all tags on the screen.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
|
|
|
-- @return true if c is on screen, false otherwise
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.filter.alltags(c, screen)
|
2009-02-27 17:22:03 +01:00
|
|
|
-- Only print client on the same screen as this widget
|
2012-05-11 17:42:45 +02:00
|
|
|
return c.screen == screen
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
2009-10-24 14:53:01 +02:00
|
|
|
--- Filtering function to include only the clients from currently selected tags.
|
2009-02-27 17:22:03 +01:00
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
2009-10-24 14:53:01 +02:00
|
|
|
-- @return true if c is in a selected tag on screen, false otherwise
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.filter.currenttags(c, screen)
|
2009-02-27 17:22:03 +01:00
|
|
|
-- Only print client on the same screen as this widget
|
2009-10-24 14:53:01 +02:00
|
|
|
if c.screen ~= screen then return false end
|
2009-03-25 14:51:14 +01:00
|
|
|
-- Include sticky client too
|
2009-10-24 14:53:01 +02:00
|
|
|
if c.sticky then return true end
|
2012-10-20 16:34:06 +02:00
|
|
|
local tags = tag.gettags(screen)
|
2009-10-24 14:53:01 +02:00
|
|
|
for k, t in ipairs(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
|
2009-10-24 14:53:01 +02:00
|
|
|
return true
|
2009-03-14 13:47:50 +01:00
|
|
|
end
|
|
|
|
end
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
end
|
2009-10-24 14:53:01 +02:00
|
|
|
return false
|
2009-02-27 17:22:03 +01:00
|
|
|
end
|
|
|
|
|
2010-10-17 15:35:50 +02:00
|
|
|
--- Filtering function to include only the minimized clients from currently selected tags.
|
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
|
|
|
-- @return true if c is in a selected tag on screen and is minimized, false otherwise
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.filter.minimizedcurrenttags(c, screen)
|
2010-10-17 15:35:50 +02:00
|
|
|
-- Only print client on the same screen as this widget
|
|
|
|
if c.screen ~= screen then return false end
|
|
|
|
-- Check client is minimized
|
|
|
|
if not c.minimized then return false end
|
2012-12-13 03:30:37 +01:00
|
|
|
-- Include sticky client
|
|
|
|
if c.sticky then return true end
|
2012-10-20 16:34:06 +02:00
|
|
|
local tags = tag.gettags(screen)
|
2010-10-17 15:35:50 +02:00
|
|
|
for k, t in ipairs(tags) do
|
|
|
|
-- Select only minimized clients
|
|
|
|
if t.selected then
|
|
|
|
local ctags = c:tags()
|
|
|
|
for _, v in ipairs(ctags) do
|
|
|
|
if v == t then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2009-10-24 14:53:01 +02:00
|
|
|
--- Filtering function to include only the currently focused client.
|
2009-08-27 11:21:32 +02:00
|
|
|
-- @param c The client.
|
|
|
|
-- @param screen The screen we are drawing on.
|
2009-10-24 14:53:01 +02:00
|
|
|
-- @return true if c is focused on screen, false otherwise
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.filter.focused(c, screen)
|
2009-08-27 11:21:32 +02:00
|
|
|
-- Only print client on the same screen as this widget
|
2012-05-11 17:42:45 +02:00
|
|
|
return c.screen == screen and capi.client.focus == c
|
2009-08-27 11:21:32 +02:00
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function tasklist.mt:__call(...)
|
|
|
|
return tasklist.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(tasklist, tasklist.mt)
|
2009-05-08 11:59:38 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|