awful.widget.layoutbox: import

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-05-18 16:32:05 +02:00
parent e59f28a556
commit ca777201a7
3 changed files with 51 additions and 8 deletions

View file

@ -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

View file

@ -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")

View file

@ -0,0 +1,49 @@
---------------------------------------------------------------------------
-- @author Julien Danjou &lt;julien@danjou.info&gt;
-- @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