From ca777201a7bc831476f098e50dc9a970ad7470c8 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 18 May 2009 16:32:05 +0200 Subject: [PATCH] awful.widget.layoutbox: import Signed-off-by: Julien Danjou --- awesomerc.lua.in | 9 +----- lib/awful/widget/init.lua.in | 1 + lib/awful/widget/layoutbox.lua.in | 49 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 lib/awful/widget/layoutbox.lua.in diff --git a/awesomerc.lua.in b/awesomerc.lua.in index e39b2b1c8..4783c2fbb 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -155,7 +155,7 @@ for s = 1, screen.count() do mypromptbox[s] = awful.widget.prompt({ align = "left" }) -- Create an imagebox widget which will contains an icon indicating which layout we're using. -- We need one layoutbox per screen. - mylayoutbox[s] = widget({ type = "imagebox", align = "right" }) + mylayoutbox[s] = awful.widget.layoutbox(s, { align = "right" }) mylayoutbox[s]:buttons(awful.util.table.join( awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end), awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end), @@ -408,13 +408,6 @@ end) -- Hook function to execute when switching tag selection. awful.hooks.tags.register(function (screen, tag, view) - local layout = awful.layout.getname(awful.layout.get(screen)) - if layout and beautiful["layout_" ..layout] then - mylayoutbox[screen].image = image(beautiful["layout_" .. layout]) - else - mylayoutbox[screen].image = nil - end - -- Give focus to the latest client in history if no window has focus -- or if the current window is a desktop or a dock one. if not client.focus or not client.focus:isvisible() then diff --git a/lib/awful/widget/init.lua.in b/lib/awful/widget/init.lua.in index b1dfe1e9e..6d4b51cfe 100644 --- a/lib/awful/widget/init.lua.in +++ b/lib/awful/widget/init.lua.in @@ -11,6 +11,7 @@ require("awful.widget.launcher") require("awful.widget.prompt") require("awful.widget.progressbar") require("awful.widget.graph") +require("awful.widget.layoutbox") --- Widget module for awful module("awful.widget") diff --git a/lib/awful/widget/layoutbox.lua.in b/lib/awful/widget/layoutbox.lua.in new file mode 100644 index 000000000..6fa083509 --- /dev/null +++ b/lib/awful/widget/layoutbox.lua.in @@ -0,0 +1,49 @@ +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @release @AWESOME_VERSION@ +--------------------------------------------------------------------------- + +local setmetatable = setmetatable +local button = require("awful.button") +local layout = require("awful.layout") +local beautiful = require("beautiful") +local hooks = require("awful.hooks") +local capi = { image = image, + widget = widget } + +--- Layoutbox widget. +module("awful.widget.layoutbox") + +local function update(w, screen) + local layout = layout.getname(layout.get(screen)) + if layout and beautiful["layout_" ..layout] then + w.image = capi.image(beautiful["layout_" ..layout]) + else + w.image = nil + end +end + +--- Create a layoutbox widget. It draws a picture with the current layout +-- symbol of the current tag. +-- @param screen The screen number that the layout will be represented for. +-- @param args Standard arguments for an imagebox widget. +-- @return An imagebox widget configured as a layoutbox. +function new(screen, args) + local screen = screen or 1 + local args = args or {} + args.type = "imagebox" + local w = capi.widget(args) + update(w, screen) + hooks.tags.register(function (s, t, view) + if s == screen then return update(w, s) end + end) + hooks.layout.register(function (t, layout) + if t.screen == screen then return update(w, t.screen) end + end) + return w +end + +setmetatable(_M, { __call = function(_, ...) return new(...) end }) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80