From 7b0687e13651e590bcc697c63d0a4288d0c44c9c Mon Sep 17 00:00:00 2001 From: Cyrax Date: Thu, 5 Nov 2020 12:14:57 +1000 Subject: [PATCH 1/2] widget: Added widget_template argument to layoutbox --- lib/awful/widget/layoutbox.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/awful/widget/layoutbox.lua b/lib/awful/widget/layoutbox.lua index ca1a07196b..b4775704ab 100644 --- a/lib/awful/widget/layoutbox.lua +++ b/lib/awful/widget/layoutbox.lua @@ -32,8 +32,8 @@ local function update(w, screen) w._layoutbox_tooltip:set_text(name or "[no name]") local img = surface.load_silently(beautiful["layout_" .. name], false) - w.imagebox.image = img - w.textbox.text = img and "" or name + w:get_children_by_id("imagebox")[1].image = img + w:get_children_by_id("textbox")[1].text = img and "" or name end local function update_from_tag(t) @@ -85,7 +85,7 @@ function layoutbox.new(args) -- Do we already have a layoutbox for this screen? local w = boxes[screen] if not w then - w = wibox.widget { + local template = args.widget_template or { { id = "imagebox", widget = wibox.widget.imagebox @@ -97,6 +97,8 @@ function layoutbox.new(args) layout = wibox.layout.fixed.horizontal } + w = wibox.widget(template) + w._layoutbox_tooltip = tooltip {objects = {w}, delay_show = 1} -- Apply the buttons, visible, forced_width and so on From 9b94b8a0554a78689afd89b245e251c8096fec7a Mon Sep 17 00:00:00 2001 From: Cyrax Date: Sat, 7 Nov 2020 00:16:03 +1000 Subject: [PATCH 2/2] widget: Added update_function argument to layoutbox --- lib/awful/widget/layoutbox.lua | 44 +++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/awful/widget/layoutbox.lua b/lib/awful/widget/layoutbox.lua index b4775704ab..1a6519ba85 100644 --- a/lib/awful/widget/layoutbox.lua +++ b/lib/awful/widget/layoutbox.lua @@ -26,29 +26,17 @@ 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]") - - local img = surface.load_silently(beautiful["layout_" .. name], false) - w:get_children_by_id("imagebox")[1].image = img - w:get_children_by_id("textbox")[1].text = img and "" or 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. +-- symbol of the current tag. The last two arguments (widget_template and +-- update_function) serve to customize the layout of the layoutbox. +-- By default your widget_template should contain textbox with id 'textbox' +-- and imagebox with id 'imagebox'. If that is not enough you can pass your +-- own update_function to manipulate your custom template the way you want. -- @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. +-- @tparam table args.widget_template A custom widget to be used for each layout +-- @tparam function args.update_function Function to create a layout widget on each update. -- @return The layoutbox. function layoutbox.new(args) args = args or {} @@ -67,6 +55,24 @@ function layoutbox.new(args) screen = get_screen(screen or 1) + local update = args.update_function or function(w, screen) + screen = get_screen(screen) + local name = layout.getname(layout.get(screen)) + w._layoutbox_tooltip:set_text(name or "[no name]") + + local img = surface.load_silently(beautiful["layout_" .. name], false) + w:get_children_by_id("imagebox")[1].image = img + w:get_children_by_id("textbox")[1].text = img and "" or 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 + -- Do we already have the update callbacks registered? if boxes == nil then boxes = setmetatable({}, { __mode = "kv" })