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
|
2016-05-08 06:20:51 +02:00
|
|
|
local capi = { screen = screen, tag = tag }
|
2009-05-18 16:32:05 +02:00
|
|
|
local layout = require("awful.layout")
|
2015-07-15 19:00:21 +02:00
|
|
|
local tooltip = require("awful.tooltip")
|
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
|
|
|
|
2016-02-26 19:19:58 +01:00
|
|
|
local function get_screen(s)
|
|
|
|
return s and capi.screen[s]
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
local layoutbox = { mt = {} }
|
2009-05-18 16:32:05 +02:00
|
|
|
|
2015-09-27 13:19:12 +02:00
|
|
|
local boxes = nil
|
|
|
|
|
|
|
|
local function update(w, screen)
|
2016-02-26 19:19:58 +01:00
|
|
|
screen = get_screen(screen)
|
2016-02-27 09:24:19 +01:00
|
|
|
local name = layout.getname(layout.get(screen))
|
2016-02-07 15:12:22 +01:00
|
|
|
w._layoutbox_tooltip:set_text(name or "[no name]")
|
|
|
|
w:set_image(name and beautiful["layout_" .. name])
|
2009-05-18 16:32:05 +02:00
|
|
|
end
|
|
|
|
|
2015-09-27 13:19:12 +02:00
|
|
|
local function update_from_tag(t)
|
2016-04-05 09:02:00 +02:00
|
|
|
local screen = get_screen(t.screen)
|
2015-09-27 13:19:12 +02:00
|
|
|
local w = boxes[screen]
|
|
|
|
if w then
|
|
|
|
update(w, screen)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-05-18 16:32:05 +02:00
|
|
|
--- 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)
|
2016-02-26 19:19:58 +01:00
|
|
|
screen = get_screen(screen or 1)
|
2015-07-15 19:00:21 +02:00
|
|
|
|
2015-09-27 13:19:12 +02:00
|
|
|
-- Do we already have the update callbacks registered?
|
|
|
|
if boxes == nil then
|
2016-04-17 15:37:00 +02:00
|
|
|
boxes = setmetatable({}, { __mode = "kv" })
|
2016-05-08 06:20:51 +02:00
|
|
|
capi.tag.connect_signal("property::selected", update_from_tag)
|
|
|
|
capi.tag.connect_signal("property::layout", update_from_tag)
|
2015-09-27 13:19:12 +02:00
|
|
|
layoutbox.boxes = boxes
|
2009-08-11 11:30:04 +02:00
|
|
|
end
|
|
|
|
|
2015-09-27 13:19:12 +02:00
|
|
|
-- Do we already have a layoutbox for this screen?
|
|
|
|
local w = boxes[screen]
|
|
|
|
if not w then
|
|
|
|
w = imagebox()
|
|
|
|
w._layoutbox_tooltip = tooltip({ objects = {w}, delay_show = 1 })
|
|
|
|
|
|
|
|
update(w, screen)
|
2016-05-08 06:20:51 +02:00
|
|
|
boxes[screen] = setmetatable({}, {__index = w, __newindex = w})
|
2015-09-27 13:19:12 +02:00
|
|
|
end
|
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
|