Skip to content

Instantly share code, notes, and snippets.

@bencollerson
Created March 1, 2016 04:48
Show Gist options
  • Save bencollerson/8ab8dd89abacc6a69fd1 to your computer and use it in GitHub Desktop.
Save bencollerson/8ab8dd89abacc6a69fd1 to your computer and use it in GitHub Desktop.
---------------------------------------------------------------------------
-- A text-only layout box widget for the awesome window manager.
--
-- Usage:
--
-- 1. Put this file in ~/.config/awesome/widgets
--
-- 2. Put something like this in your theme.lua file:
--
-- theme.layout_text_tile = "[t]"
-- theme.layout_text_tileleft = "[l]"
-- theme.layout_text_tilebottom = "[b]"
-- theme.layout_text_tiletop = "[T]"
-- theme.layout_text_fairv = "[f]"
-- theme.layout_text_fairh = "[h]"
-- theme.layout_text_spiral = "[s]"
-- theme.layout_text_dwindle = "[d]"
-- theme.layout_text_max = "[m]"
-- theme.layout_text_fullscreen = "[F]"
-- theme.layout_text_magnifier = "[g]"
-- theme.layout_text_floating = "[*]"
--
-- 3. Put something like this in your rc.lua file:
--
-- local textlayoutbox = require("widget.textlayoutbox")
-- ...
-- mytextlayoutbox = {}
-- ...
-- for s = 1, screen.count() do
-- ...
-- mytextlayoutbox[s] = textlayoutbox(s)
-- ...
-- right_layout:add(mytextlayoutbox[s])
-- ...
-- end
--
-- This widget should be compatible with awesome v3.5.6
--
-- @author Ben Collerson <benc@benc.cc>
-- @copyright 2016 Ben Collerson
-- @release v0.1
---------------------------------------------------------------------------
local setmetatable = setmetatable
local ipairs = ipairs
local layout = require("awful.layout")
local tag = require("awful.tag")
local beautiful = require("beautiful")
local textbox = require("wibox.widget.textbox")
--- the textlayoutbox widget.
local textlayoutbox = { mt = {} }
-- update the text for the textlayoutbox
local function update(w, screen)
local layout = layout.getname(layout.get(screen))
-- set the textbox text with the appropriate text from the theme data for
-- the current layout type.
w:set_markup((layout and beautiful["layout_text_" .. layout]) or '')
end
-- create a textlayoutbox widget.
--
-- a textbox containing some text representing the current layout of the current tag.
--
-- @param screen The screen number that the layout will be represented for.
-- @return An textbox widget configured as a textlayoutbox.
function textlayoutbox.new(screen)
local screen = screen or 1
local w = textbox()
update(w, screen)
local function update_on_tag_selection(t)
return update(w, tag.getscreen(t))
end
tag.attached_connect_signal(screen, "property::selected", update_on_tag_selection)
tag.attached_connect_signal(screen, "property::layout", update_on_tag_selection)
return w
end
function textlayoutbox.mt:__call(...)
return textlayoutbox.new(...)
end
return setmetatable(textlayoutbox, textlayoutbox.mt)
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment