From 1f8c3bdcd7f79dc3ef4c1a7fb5b039d9597db7e3 Mon Sep 17 00:00:00 2001 From: undefinedDarkness Date: Thu, 4 Nov 2021 21:19:44 +0530 Subject: [PATCH 1/5] add-create-callback to titlebar_indicator --- docs/theme.md | 12 ++++++++++++ docs/widgets/tabbed_misc.md | 7 ++++++- widget/tabbed_misc/titlebar_indicator.lua | 24 ++++++++++++----------- 3 files changed, 31 insertions(+), 12 deletions(-) diff --git a/docs/theme.md b/docs/theme.md index 592d771..916f839 100644 --- a/docs/theme.md +++ b/docs/theme.md @@ -75,4 +75,16 @@ theme.task_preview_widget_border_color = "#ffffff" -- The border color of the theme.task_preview_widget_border_width = 3 -- The border width of the widget theme.task_preview_widget_margin = 0 -- The margin of the widget +-- tabbed misc widget(s) +theme.bling_tabbed_misc_titlebar_indicator = { + layout_spacing = dpi(4), + icon_size = dpi(20), + icon_margin = dpi(4), + bg_color_focus = "#ff0000", + bg_color = "#00000000", + icon_shape = function(cr, w, h) + gears.shape.rounded_rect(cr, w, h, 0) + end, + layout = wibox.layout.fixed.horizontal +} ``` diff --git a/docs/widgets/tabbed_misc.md b/docs/widgets/tabbed_misc.md index 2fbdb48..9ae8df5 100644 --- a/docs/widgets/tabbed_misc.md +++ b/docs/widgets/tabbed_misc.md @@ -35,7 +35,12 @@ bling.widget.tabbed_misc.titlebar_indicator(client, { }, widget = wibox.container.margin, margins = 2, - id = 'click_role' + id = 'click_role', + update_callback = function(self, client, group) + if client == group.clients[group.focused_idx] then + self.margins = 5 + end + end } }) ``` diff --git a/widget/tabbed_misc/titlebar_indicator.lua b/widget/tabbed_misc/titlebar_indicator.lua index af86ad2..2549d83 100644 --- a/widget/tabbed_misc/titlebar_indicator.lua +++ b/widget/tabbed_misc/titlebar_indicator.lua @@ -40,16 +40,11 @@ return function(c, opts) spacing = opts.layout_spacing, }) - awesome.connect_signal( - "bling::tabbed::client_removed", - function(_, removed_c) - -- Remove from list - for idx, icon in ipairs(tabbed_icons.children) do - if - icon:get_children_by_id("icon_role")[1].client == removed_c - then - tabbed_icons:remove(idx) - end + awesome.connect_signal("bling::tabbed::client_removed", function(_, removed_c) + -- Remove from list + for idx, icon in ipairs(tabbed_icons.children) do + if icon._client == removed_c then + tabbed_icons:remove(idx) end -- Empty list @@ -57,7 +52,7 @@ return function(c, opts) tabbed_icons:reset() end end - ) + end) local function recreate(group) if tbl_contains(group.clients, c) then @@ -93,6 +88,13 @@ return function(c, opts) widget = wibox.container.place, }) + widget._client = client + + -- No creation call back since this would be called on creation & every time the widget updated. + if opts.widget_template.update_callback then + opts.widget_template.update_callback(widget, client, group) + end + -- Add icons & etc for _, w in ipairs(widget:get_children_by_id("icon_role")) do -- TODO: Allow fallback icon? From 7261f0ba40b2d86da92cd54fdf3698d6408c11dc Mon Sep 17 00:00:00 2001 From: undefinedDarkness Date: Mon, 27 Sep 2021 11:44:33 +0530 Subject: [PATCH 2/5] Use grid layout in custom_tasklist Export draw_widget from tag_preview --- widget/tabbed_misc/custom_tasklist.lua | 78 +++++++++++------------ widget/tabbed_misc/titlebar_indicator.lua | 76 ++++++++++++++++++++++ widget/tag_preview.lua | 32 ++++------ 3 files changed, 125 insertions(+), 61 deletions(-) diff --git a/widget/tabbed_misc/custom_tasklist.lua b/widget/tabbed_misc/custom_tasklist.lua index 2e105c6..ac22377 100644 --- a/widget/tabbed_misc/custom_tasklist.lua +++ b/widget/tabbed_misc/custom_tasklist.lua @@ -5,51 +5,47 @@ local beautiful = require("beautiful") local dpi = require("beautiful.xresources").apply_dpi local function tabobj_support(self, c, index, clients) - -- Self is the background widget in this context - if not c.bling_tabbed then - return - end + -- Self is the background widget in this context + if not c.bling_tabbed and #c.bling_tabbed.clients > 1 then + return + end - local group = c.bling_tabbed + local group = c.bling_tabbed + + -- TODO: Allow customization here + local layout_v = wibox.widget { + vertical_spacing = dpi(2), + horizontal_spacing = dpi(2), + layout = wibox.layout.grid.horizontal, + forced_num_rows = 2, + forced_num_cols = 2, + homogeneous = true + } - -- Single item tabbed group's dont get special rendering - if #group.clients > 1 then - local wrapper = wibox.widget({ - { - -- This is so dumb... but it works so meh - { - id = "row1", - layout = wibox.layout.flex.horizontal, - }, - { - id = "row2", - layout = wibox.layout.flex.horizontal, - }, - spacing = dpi(2), - layout = wibox.layout.fixed.vertical, - }, - id = "click_role", - widget = wibox.container.margin, - margins = dpi(5), - }) + local wrapper = wibox.widget({ + layout_v, + id = "click_role", + widget = wibox.container.margin, + margins = dpi(5), + }) - for idx, c in ipairs(group.clients) do - if c and c.icon then - -- TODO: Don't do this in a -1iq way - if idx <= 2 then - wrapper - :get_children_by_id("row1")[1] - :add(awful.widget.clienticon(c)) - else - wrapper - :get_children_by_id("row2")[1] - :add(awful.widget.clienticon(c)) - end - end - end + -- To get the ball rolling. + for idx, c in ipairs(group.clients) do + if not (c and c.icon) then goto skip end - self.widget = wrapper - end + -- Add to the last layout + layout_v:add(wibox.widget { + { + widget = awful.widget.clienticon, + client = c + }, + widget = wibox.container.constraint, + width = dpi(24), + height = dpi(24) + }) + ::skip:: + end + self.widget = wrapper end return tabobj_support diff --git a/widget/tabbed_misc/titlebar_indicator.lua b/widget/tabbed_misc/titlebar_indicator.lua index 2549d83..de40216 100644 --- a/widget/tabbed_misc/titlebar_indicator.lua +++ b/widget/tabbed_misc/titlebar_indicator.lua @@ -54,6 +54,7 @@ return function(c, opts) end end) +<<<<<<< HEAD local function recreate(group) if tbl_contains(group.clients, c) then tabbed_icons:reset() @@ -117,4 +118,79 @@ return function(c, opts) awesome.connect_signal("bling::tabbed::changed_focus", recreate) return tabbed_icons +======= + local function recreate(group) + if tbl_contains(group.clients, c) then + tabbed_icons:reset() + local focused = group.clients[group.focused_idx] + + -- Autohide? + if #group.clients == 1 then + return + end + + for idx, client in ipairs(group.clients) do + local widget = wibox.widget( + opts.widget_template or { + { + { + { + id = "icon_role", + forced_width = opts.icon_size, + forced_height = opts.icon_size, + widget = awful.widget.clienticon, + }, + margins = opts.icon_margin, + widget = wibox.container.margin, + }, + shape = opts.icon_shape, + id = "bg_role", + widget = wibox.container.background, + }, + halign = "center", + valign = "center", + widget = wibox.container.place, + }) + + widget._client = client + + -- No creation call back since this would be called on creation & every time the widget updated. + if opts.widget_template and opts.widget_template.update_callback then + opts.widget_template.update_callback(widget, client, group) + end + + -- Add icons & etc + for _, w in ipairs(widget:get_children_by_id("icon_role")) do + -- TODO: Allow fallback icon? + w.image = client.icon + w.client = client + end + + for _, w in ipairs(widget:get_children_by_id("bg_role")) do + w:add_button(awful.button({}, 1, function() + tabbed_module.switch_to(group, idx) + end)) + if client == focused then + w.bg = opts.bg_color_focus + w.fg = opts.fg_color_focus + else + w.bg = opts.bg_color + w.fg = opts.fg_color + end + end + + for _, w in ipairs(widget:get_children_by_id("text_role")) do + w.text = client.name + end + + tabbed_icons:add(widget) + end + end + end + + awesome.connect_signal("bling::tabbed::client_added", recreate) + awesome.connect_signal("bling::tabbed::changed_focus", recreate) + + return tabbed_icons +>>>>>>> 848ddd9 (Use grid layout in custom_tasklist) end diff --git a/widget/tag_preview.lua b/widget/tag_preview.lua index f2ef42b..d73d42a 100644 --- a/widget/tag_preview.lua +++ b/widget/tag_preview.lua @@ -36,7 +36,8 @@ local function draw_widget( local tag_screen = t.screen for i, c in ipairs(t:clients()) do if not c.hidden and not c.minimized then - local img_box = wibox.widget({ + + local img_box = wibox.widget({ image = gears.surface.load(c.icon), resize = true, forced_height = 100 * scale, @@ -182,24 +183,15 @@ local enable = function(opts) tag_preview_box.maximum_width = scale * geo.width + margin * 2 tag_preview_box.maximum_height = scale * geo.height + margin * 2 - tag_preview_box:setup( - draw_widget( - t, - tag_preview_image, - scale, - screen_radius, - client_radius, - client_opacity, - client_bg, - client_border_color, - client_border_width, - widget_bg, - widget_border_color, - widget_border_width, - geo, - margin - ) - ) + + -- TODO: Use a table here + tag_preview_box:setup(draw_widget(t, tag_preview_image, scale, + screen_radius, client_radius, + client_opacity, client_bg, + client_border_color, + client_border_width, widget_bg, + widget_border_color, + widget_border_width, geo, margin)) end) awesome.connect_signal("bling::tag_preview::visibility", function(s, v) @@ -212,4 +204,4 @@ local enable = function(opts) end) end -return { enable = enable } +return {enable = enable, draw_widget = draw_widget} From a525299d4f7f7277503f181130de50085a356ed0 Mon Sep 17 00:00:00 2001 From: undefinedDarkness Date: Mon, 30 Aug 2021 23:53:44 +0530 Subject: [PATCH 3/5] add more options to titlebar indicator --- docs/widgets/tabbed_misc.md | 5 +- widget/tabbed_misc/titlebar_indicator.lua | 143 ++++++---------------- 2 files changed, 44 insertions(+), 104 deletions(-) diff --git a/docs/widgets/tabbed_misc.md b/docs/widgets/tabbed_misc.md index 9ae8df5..2d5f788 100644 --- a/docs/widgets/tabbed_misc.md +++ b/docs/widgets/tabbed_misc.md @@ -16,9 +16,12 @@ To use the task list indicator: ```lua bling.widget.tabbed_misc.titlebar_indicator(client, { + layout = wibox.layout.fixed.vertical, layout_spacing = dpi(5), -- Set spacing in between items icon_size = dpi(24), icon_margin = 0, + fg_color = "#cccccc", -- Normal color for text + fg_color_focus = "#ffffff", -- Color for focused text bg_color_focus = "#282828", -- Color for the focused items bg_color = "#1d2021", -- Color for normal / unfocused items icon_shape = gears.shape.circle -- Set icon shape, @@ -35,7 +38,7 @@ bling.widget.tabbed_misc.titlebar_indicator(client, { }, widget = wibox.container.margin, margins = 2, - id = 'click_role', + id = 'bg_role', update_callback = function(self, client, group) if client == group.clients[group.focused_idx] then self.margins = 5 diff --git a/widget/tabbed_misc/titlebar_indicator.lua b/widget/tabbed_misc/titlebar_indicator.lua index de40216..225f3a1 100644 --- a/widget/tabbed_misc/titlebar_indicator.lua +++ b/widget/tabbed_misc/titlebar_indicator.lua @@ -9,116 +9,54 @@ local tabbed_module = require( -- Just check if a table contains a value. local function tbl_contains(tbl, item) - for _, v in ipairs(tbl) do - if v == item then - return true - end - end - return false + for _, v in ipairs(tbl) do + if v == item then + return true + end + end + return false end -- Needs to be run, every time a new titlbear is created return function(c, opts) - -- Args & Fallback -- Widget templates are in their original loactions - opts = gears.table.crush({ - layout_spacing = dpi(4), - icon_size = dpi(20), - icon_margin = dpi(4), - bg_color_focus = "#ff0000", - bg_color = "#00000000", - icon_shape = function(cr, w, h) - gears.shape.rounded_rect(cr, w, h, 0) - end, - }, gears.table.join( - opts, - beautiful.bling_tabbed_misc_titlebar_indicator - )) + -- Args & Fallback -- Widget templates are in their original loactions + opts = gears.table.crush({ + layout_spacing = dpi(4), + icon_size = dpi(20), + icon_margin = dpi(4), + bg_color_focus = "#ff0000", + bg_color = "#00000000", + fg_color = "#fafafa", + fg_color_focus = "#e0e0e0", + icon_shape = function(cr, w, h) + gears.shape.rounded_rect(cr, w, h, 0) + end, + layout = wibox.layout.fixed.horizontal, + }, gears.table.join( + opts, + beautiful.bling_tabbed_misc_titlebar_indicator + )) - -- Container to store icons - local tabbed_icons = wibox.widget({ - layout = wibox.layout.fixed.horizontal, - spacing = opts.layout_spacing, - }) + -- Container to store icons + local tabbed_icons = wibox.widget({ + layout = opts.layout, + spacing = opts.layout_spacing, + }) - awesome.connect_signal("bling::tabbed::client_removed", function(_, removed_c) - -- Remove from list - for idx, icon in ipairs(tabbed_icons.children) do - if icon._client == removed_c then - tabbed_icons:remove(idx) - end + awesome.connect_signal("bling::tabbed::client_removed", function(_, removed_c) + -- Remove from list + for idx, icon in ipairs(tabbed_icons.children) do + if icon._client == removed_c then + tabbed_icons:remove(idx) + end + end - -- Empty list - if removed_c == c then - tabbed_icons:reset() - end - end + -- Empty list + if removed_c == c then + tabbed_icons:reset() + end end) -<<<<<<< HEAD - local function recreate(group) - if tbl_contains(group.clients, c) then - tabbed_icons:reset() - local focused = group.clients[group.focused_idx] - - -- Autohide? - if #group.clients == 1 then - return - end - - for idx, client in ipairs(group.clients) do - local widget = wibox.widget(opts.widget_template or { - { - { - { - id = "icon_role", - forced_width = opts.icon_size, - forced_height = opts.icon_size, - widget = awful.widget.clienticon, - }, - margins = opts.icon_margin, - widget = wibox.container.margin, - }, - bg = (client == focused) and opts.bg_color_focus - or opts.bg_color, - shape = opts.icon_shape, - id = "click_role", - widget = wibox.container.background, - }, - halign = "center", - valign = "center", - widget = wibox.container.place, - }) - - widget._client = client - - -- No creation call back since this would be called on creation & every time the widget updated. - if opts.widget_template.update_callback then - opts.widget_template.update_callback(widget, client, group) - end - - -- Add icons & etc - for _, w in ipairs(widget:get_children_by_id("icon_role")) do - -- TODO: Allow fallback icon? - w.image = client.icon - w.client = client - end - - for _, w in ipairs(widget:get_children_by_id("click_role")) do - w:add_button(awful.button({}, 1, function() - tabbed_module.switch_to(group, idx) - end)) - end - - tabbed_icons:add(widget) - end - end - end - - awesome.connect_signal("bling::tabbed::client_added", recreate) - awesome.connect_signal("bling::tabbed::changed_focus", recreate) - - return tabbed_icons -======= local function recreate(group) if tbl_contains(group.clients, c) then tabbed_icons:reset() @@ -144,7 +82,7 @@ return function(c, opts) widget = wibox.container.margin, }, shape = opts.icon_shape, - id = "bg_role", + id = "background_role", widget = wibox.container.background, }, halign = "center", @@ -192,5 +130,4 @@ return function(c, opts) awesome.connect_signal("bling::tabbed::changed_focus", recreate) return tabbed_icons ->>>>>>> 848ddd9 (Use grid layout in custom_tasklist) end From b68b95a1cec7e70c79b3372b8d847a3b23d83d31 Mon Sep 17 00:00:00 2001 From: undefinedDarkness Date: Fri, 5 Nov 2021 13:23:25 +0530 Subject: [PATCH 4/5] fixup! add more options to titlebar indicator --- widget/tabbed_misc/titlebar_indicator.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/tabbed_misc/titlebar_indicator.lua b/widget/tabbed_misc/titlebar_indicator.lua index 225f3a1..46959cd 100644 --- a/widget/tabbed_misc/titlebar_indicator.lua +++ b/widget/tabbed_misc/titlebar_indicator.lua @@ -82,7 +82,7 @@ return function(c, opts) widget = wibox.container.margin, }, shape = opts.icon_shape, - id = "background_role", + id = "bg_role", widget = wibox.container.background, }, halign = "center", From f51fbc5e6376ff0a8bb27e5ebce5f1e0374b7d20 Mon Sep 17 00:00:00 2001 From: undefinedDarkness Date: Fri, 5 Nov 2021 21:08:29 +0530 Subject: [PATCH 5/5] export draw_widget from task_preview too --- widget/task_preview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/widget/task_preview.lua b/widget/task_preview.lua index 4712ebd..603e6db 100644 --- a/widget/task_preview.lua +++ b/widget/task_preview.lua @@ -164,4 +164,4 @@ local enable = function(opts) end) end -return { enable = enable } +return { enable = enable, draw_widget = draw_widget }