2009-05-18 16:32:05 +02:00
|
|
|
---------------------------------------------------------------------------
|
2019-11-21 15:43:15 +01:00
|
|
|
--- Display the current client layout (`awful.layout`) icon or name.
|
2018-12-27 03:38:08 +01:00
|
|
|
--
|
2019-12-04 14:08:25 +01:00
|
|
|
-- @DOC_awful_widget_layoutbox_default_EXAMPLE@
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2009-05-18 16:32:05 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
2019-06-06 08:15:53 +02:00
|
|
|
-- @widgetmod awful.widget.layoutbox
|
2021-03-27 20:05:10 +01:00
|
|
|
-- @supermodule wibox.layout.fixed
|
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")
|
2017-06-05 07:05:03 +02:00
|
|
|
local wibox = require("wibox")
|
|
|
|
local surface = require("gears.surface")
|
2018-12-28 08:20:26 +01:00
|
|
|
local gdebug = require("gears.debug")
|
2018-12-27 03:38:08 +01:00
|
|
|
local gtable = require("gears.table")
|
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]")
|
2017-06-05 07:05:03 +02:00
|
|
|
|
|
|
|
local img = surface.load_silently(beautiful["layout_" .. name], false)
|
|
|
|
w.imagebox.image = img
|
|
|
|
w.textbox.text = img and "" or 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.
|
2021-12-13 22:55:50 +01:00
|
|
|
-- @constructorfct awful.widget.layoutbox
|
2018-12-27 03:38:08 +01:00
|
|
|
-- @tparam table args The arguments.
|
|
|
|
-- @tparam screen args.screen The screen number that the layout will be represented for.
|
|
|
|
-- @tparam table args.buttons The `awful.button`s for this layoutbox.
|
|
|
|
-- @return The layoutbox.
|
|
|
|
function layoutbox.new(args)
|
|
|
|
args = args or {}
|
2020-02-23 22:14:06 +01:00
|
|
|
local screen = args.screen
|
2018-12-27 03:38:08 +01:00
|
|
|
|
|
|
|
if type(args) == "number" or type(args) == "screen" or args.fake_remove then
|
|
|
|
screen, args = args, {}
|
2018-12-28 08:20:26 +01:00
|
|
|
|
|
|
|
gdebug.deprecate(
|
|
|
|
"Use awful.widget.layoutbox{screen=s} instead of awful.widget.layoutbox(screen)",
|
|
|
|
{deprecated_in=5}
|
|
|
|
)
|
2018-12-27 03:38:08 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
assert(type(args) == "table")
|
|
|
|
|
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)
|
2017-02-02 22:45:33 +01:00
|
|
|
capi.tag.connect_signal("property::screen", function()
|
|
|
|
for s, w in pairs(boxes) do
|
|
|
|
if s.valid then
|
|
|
|
update(w, s)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
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
|
2017-06-05 07:05:03 +02:00
|
|
|
w = wibox.widget {
|
|
|
|
{
|
|
|
|
id = "imagebox",
|
|
|
|
widget = wibox.widget.imagebox
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id = "textbox",
|
|
|
|
widget = wibox.widget.textbox
|
|
|
|
},
|
|
|
|
layout = wibox.layout.fixed.horizontal
|
|
|
|
}
|
|
|
|
|
2016-05-18 03:00:38 +02:00
|
|
|
w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1}
|
2015-09-27 13:19:12 +02:00
|
|
|
|
2018-12-27 03:38:08 +01:00
|
|
|
-- Apply the buttons, visible, forced_width and so on
|
|
|
|
gtable.crush(w, args)
|
|
|
|
|
2015-09-27 13:19:12 +02:00
|
|
|
update(w, screen)
|
2016-05-18 03:00:38 +02:00
|
|
|
boxes[screen] = 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
|