From 112f0863dc8ed9a5d3c08f5ef393e3f064554bae Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 29 Jul 2008 11:21:47 +0200 Subject: [PATCH] awful: add several label function for tasklist Signed-off-by: Julien Danjou --- awesomerc.lua.in | 15 +----------- lib/awful.lua | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 0c8da008e..18322d516 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -91,20 +91,7 @@ mytasklist = widget({ type = "tasklist", name = "mytasklist" }) mytasklist:mouse_add(mouse({ }, 1, function (object, c) c:focus_set(); c:raise() end)) mytasklist:mouse_add(mouse({ }, 4, function () awful.client.focus(1) end)) mytasklist:mouse_add(mouse({ }, 5, function () awful.client.focus(-1) end)) -function mytasklist.label(c, scr) - -- Only print client on the same screen as this widget - if c.screen ~= scr then return end - local text = "" - if c.floating then - text = "" - end - if client.focus_get() == c then - text = text .. " "..awful.escape(c.name).." " - else - text = text .. " "..awful.escape(c.name).." " - end - return text -end +function mytasklist.label(c, screen) return awful.widget.tasklist.label.currenttags(c, screen, bg_focus, fg_focus) end -- Create a textbox widget mytextbox = widget({ type = "textbox", name = "mytextbox", align = "right" }) diff --git a/lib/awful.lua b/lib/awful.lua index 0c9a5b204..ce997fd9c 100644 --- a/lib/awful.lua +++ b/lib/awful.lua @@ -45,6 +45,8 @@ P.client = {} P.tag = {} P.widget = {} P.widget.taglist = {} +P.widget.tasklist = {} +P.widget.tasklist.label = {} --- Create a new userhook (for external libs). -- @param name Hook name. @@ -773,4 +775,64 @@ function P.widget.taglist.label(t, bg_focus, fg_focus) return text end +local function widget_tasklist_label_common(c, bg_focus, fg_focus) + local text = "" + if c.floating then + text = "" + end + if client.focus_get() == c then + text = text .. " "..P.escape(c.name).." " + else + text = text .. " "..P.escape(c.name).." " + end + return text +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 bg_focus The background color for focused client. +-- @param fg_focus The foreground color for focused client. +-- @return A string to pring. +function P.widget.tasklist.label.allscreen(c, screen, bg_focus, fg_focus) + return widget_tasklist_label_common(c, bg_focus, fg_focus) +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 bg_focus The background color for focused client. +-- @param fg_focus The foreground color for focused client. +-- @return A string to pring. +function P.widget.tasklist.label.alltags(c, screen, bg_focus, fg_focus) + -- Only print client on the same screen as this widget + if c.screen ~= screen then return end + return widget_tasklist_label_common(c, bg_focus, fg_focus) +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 bg_focus The background color for focused client. +-- @param fg_focus The foreground color for focused client. +-- @return A string to pring. +function P.widget.tasklist.label.currenttags(c, screen, bg_focus, fg_focus) + -- Only print client on the same screen as this widget + if c.screen ~= screen then return end + for k, t in pairs(tag.get(screen)) do + if t.selected and c:istagged(t) then + return widget_tasklist_label_common(c, bg_focus, fg_focus) + end + end +end + return P