diff options
author | ache <ache@ache.one> | 2017-03-13 23:17:19 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2017-03-13 23:17:19 +0100 |
commit | 22d656903563f75678f3634964731ccf93355dfd (patch) | |
tree | e3cb6279d95c9764093072d5e946566ea6533799 /lib/awful/widget/layoutbox.lua |
Init commit
Diffstat (limited to 'lib/awful/widget/layoutbox.lua')
-rw-r--r-- | lib/awful/widget/layoutbox.lua | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/awful/widget/layoutbox.lua b/lib/awful/widget/layoutbox.lua new file mode 100644 index 0000000..c5f8ed3 --- /dev/null +++ b/lib/awful/widget/layoutbox.lua @@ -0,0 +1,73 @@ +--------------------------------------------------------------------------- +--- Layoutbox widget. +-- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2009 Julien Danjou +-- @classmod awful.widget.layoutbox +--------------------------------------------------------------------------- + +local setmetatable = setmetatable +local capi = { screen = screen, tag = tag } +local layout = require("awful.layout") +local tooltip = require("awful.tooltip") +local beautiful = require("beautiful") +local imagebox = require("wibox.widget.imagebox") + +local function get_screen(s) + return s and capi.screen[s] +end + +local layoutbox = { mt = {} } + +local boxes = nil + +local function update(w, screen) + screen = get_screen(screen) + local name = layout.getname(layout.get(screen)) + w._layoutbox_tooltip:set_text(name or "[no name]") + w:set_image(name and beautiful["layout_" .. name]) +end + +local function update_from_tag(t) + local screen = get_screen(t.screen) + local w = boxes[screen] + if w then + update(w, screen) + 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. +-- @return An imagebox widget configured as a layoutbox. +function layoutbox.new(screen) + screen = get_screen(screen or 1) + + -- Do we already have the update callbacks registered? + if boxes == nil then + boxes = setmetatable({}, { __mode = "kv" }) + capi.tag.connect_signal("property::selected", update_from_tag) + capi.tag.connect_signal("property::layout", update_from_tag) + layoutbox.boxes = boxes + end + + -- 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) + boxes[screen] = w + end + + return w +end + +function layoutbox.mt:__call(...) + return layoutbox.new(...) +end + +return setmetatable(layoutbox, layoutbox.mt) + +-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 |