2009-05-18 16:32:05 +02:00
|
|
|
---------------------------------------------------------------------------
|
2014-05-20 13:02:39 +02:00
|
|
|
--- Layoutbox widget.
|
|
|
|
--
|
2009-05-18 16:32:05 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @classmod awful.widget.layoutbox
|
2009-05-18 16:32:05 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
2009-08-11 15:27:31 +02:00
|
|
|
local ipairs = ipairs
|
2009-05-18 16:32:05 +02:00
|
|
|
local button = require("awful.button")
|
|
|
|
local layout = require("awful.layout")
|
2015-07-15 19:00:21 +02:00
|
|
|
local tooltip = require("awful.tooltip")
|
2009-08-18 16:44:14 +02:00
|
|
|
local tag = require("awful.tag")
|
2009-05-18 16:32:05 +02:00
|
|
|
local beautiful = require("beautiful")
|
2010-10-06 14:30:00 +02:00
|
|
|
local imagebox = require("wibox.widget.imagebox")
|
2009-05-18 16:32:05 +02:00
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
local layoutbox = { mt = {} }
|
2009-05-18 16:32:05 +02:00
|
|
|
|
2015-07-15 19:00:21 +02:00
|
|
|
local function update(w, screen, tooltip)
|
2009-05-18 16:32:05 +02:00
|
|
|
local layout = layout.getname(layout.get(screen))
|
2015-07-15 19:00:21 +02:00
|
|
|
tooltip:set_text(layout or "[no name]")
|
2010-10-06 14:30:00 +02:00
|
|
|
w:set_image(layout and beautiful["layout_" .. layout])
|
2009-05-18 16:32:05 +02:00
|
|
|
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.
|
|
|
|
-- @return An imagebox widget configured as a layoutbox.
|
2012-06-14 01:08:27 +02:00
|
|
|
function layoutbox.new(screen)
|
2009-05-18 16:32:05 +02:00
|
|
|
local screen = screen or 1
|
2010-10-06 14:30:00 +02:00
|
|
|
local w = imagebox()
|
2015-07-15 19:00:21 +02:00
|
|
|
local tooltip = tooltip({ objects = {w}, delay_show = 1 })
|
|
|
|
|
|
|
|
update(w, screen, tooltip)
|
2009-08-11 11:30:04 +02:00
|
|
|
|
2012-10-20 17:33:32 +02:00
|
|
|
local function update_on_tag_selection(t)
|
2015-07-15 19:00:21 +02:00
|
|
|
return update(w, tag.getscreen(t), tooltip)
|
2009-08-11 11:30:04 +02:00
|
|
|
end
|
|
|
|
|
2009-10-09 20:39:55 +02:00
|
|
|
tag.attached_connect_signal(screen, "property::selected", update_on_tag_selection)
|
|
|
|
tag.attached_connect_signal(screen, "property::layout", update_on_tag_selection)
|
2009-08-18 16:44:14 +02:00
|
|
|
|
2009-05-18 16:32:05 +02:00
|
|
|
return w
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function layoutbox.mt:__call(...)
|
|
|
|
return layoutbox.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(layoutbox, layoutbox.mt)
|
2009-05-18 16:32:05 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|