From bdc025fb63c237e5a224c5fdc18fecd6c112545d Mon Sep 17 00:00:00 2001 From: contribuewwt <38278035+undefinedDarkness@users.noreply.github.com> Date: Thu, 19 Aug 2021 00:09:33 +0530 Subject: [PATCH] +titlbar tabbed group indicator +tasklist tabbed group indicator (#88) * +titlbar tabbed group indicator +tasklist tabbed group indicator * fixup! +titlbar tabbed group indicator +tasklist tabbed group indicator * fixup! fixup! +titlbar tabbed group indicator +tasklist tabbed group indicator * fixup! fixup! fixup! +titlbar tabbed group indicator +tasklist tabbed group indicator * Import bling * reeeeeeeeeee * stuff * fixup! stuff * fixup! fixup! stuff * fixup! fixup! fixup! stuff * fixup! fixup! fixup! fixup! stuff * fixup! fixup! fixup! fixup! fixup! stuff * fixup! fixup! fixup! fixup! fixup! fixup! stuff * fixup! fixup! fixup! fixup! fixup! fixup! fixup! stuff Co-authored-by: gokul <33443763+JavaCafe01@users.noreply.github.com> --- AUTHORS.md | 1 + docs/module/tabbed.md | 10 +- docs/widgets/tabbed_misc.md | 106 +++++++++++++++++++++ module/tabbed.lua | 5 +- widget/init.lua | 3 +- widget/tabbed_misc/custom_tasklist.lua | 53 +++++++++++ widget/tabbed_misc/init.lua | 4 + widget/tabbed_misc/titlebar_indicator.lua | 107 ++++++++++++++++++++++ 8 files changed, 286 insertions(+), 3 deletions(-) create mode 100644 docs/widgets/tabbed_misc.md create mode 100644 widget/tabbed_misc/custom_tasklist.lua create mode 100644 widget/tabbed_misc/init.lua create mode 100644 widget/tabbed_misc/titlebar_indicator.lua diff --git a/AUTHORS.md b/AUTHORS.md index c396a26..28daa57 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -5,3 +5,4 @@ The following developers have contributed major code to bling: * [Grumph](https://github.com/Grumph) * [Bysmutheye](https://github.com/Bysmutheye) * [HumblePresent](https://github.com/HumblePresent) + * [undefinedDarkness](https://github.com/undefinedDarkness) diff --git a/docs/module/tabbed.md b/docs/module/tabbed.md index 517863f..985fca3 100644 --- a/docs/module/tabbed.md +++ b/docs/module/tabbed.md @@ -47,8 +47,16 @@ Modern theme: *screenshot by [javacafe](https://github.com/JavaCafe01)* ### Signals -The tabbed module emits 1 signals for the purpose of integrating with your rice, +The tabbed module emits a few signals for the purpose of integration, ```lua -- bling::tabbed::update -- triggered whenever a tabbed object is updated -- tabobj -- the object that caused the update +-- bling::tabbed::client_added -- triggered whenever a new client is added to a tab group +-- tabobj -- the object that the client was added to +-- client -- the client that added +-- bling::tabbed::client_removed -- triggered whenever a client is removed from a tab group +-- tabobj -- the object that the client was removed from +-- client -- the client that was removed +-- bling::tabbed::changed_focus -- triggered whenever a tab group's focus is changed +-- tabobj -- the modified tab group ``` diff --git a/docs/widgets/tabbed_misc.md b/docs/widgets/tabbed_misc.md new file mode 100644 index 0000000..951fb69 --- /dev/null +++ b/docs/widgets/tabbed_misc.md @@ -0,0 +1,106 @@ +## 🧱 Tabbed Miscellaneous + +This comprises a few widgets to better represent tabbed groups (from the tabbed module) in your desktop. +The widgets currently included are: +- Titlebar Indicator +- Tasklist + +![Preview Image](https://i.imgur.com/ZeYSrxY.png) + +## Titlebar Indicator + +### Usage + +To use the task list indicator: +**NOTE:** Options can be set as theme vars under the table `theme.bling_tabbed_misc_titlebar_indicator` + +```lua +bling.widget.tabbed_misc.titlebar_indicator(client, { + layout_spacing = dpi(5), -- Set spacing in between items + icon_size = dpi(24), + icon_margin = 0, + 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, +}) +``` + +a widget_template option is also available: +```lua +bling.widget.tabbed_misc.titlebar_indicator(client, { + widget_template = { + { + widget = awful.widget.clienticon, + id = 'icon_role' + }, + widget = wibox.container.margin, + margins = 2, + id = 'click_role' + } +}) +``` + +### Example Implementation + +You normally embed the widget in your titlebar... +```lua +awful.titlebar(c).widget = { + { -- Left + bling.widget.tabbed_misc.titlebar_indicator(c), + layout = wibox.layout.fixed.horizontal + }, + { -- Middle + { -- Title + align = "center", + widget = awful.titlebar.widget.titlewidget(c) + }, + buttons = buttons, + layout = wibox.layout.flex.horizontal + }, + { -- Right + awful.titlebar.widget.maximizedbutton(c), + awful.titlebar.widget.closebutton (c), + layout = wibox.layout.fixed.horizontal + }, + layout = wibox.layout.align.horizontal + } +``` + +## Tasklist + +### Usage +Similar to the titlebar indicator, it can be used like so: +**NOTE:** Similar to above, options can also be used under as theme vars under the table + +```lua +require('bling.widget.tabbed').custom_tasklist(s, { + icon_margin = dpi(0), -- Item Margin + icon_size = dpi(24), -- Does not apply to tabbed groups + group_row_spacing = dpi(2), -- Spacing between rows in a group indicator + filter = awful.widget.tasklist.filter.currenttags, -- Set awful.widget.titlbar like filter + layout = wibox.layout.fixed.vertical, -- Tasklist layout + -- widget_template = {...} -- Identical to above widget template, used for regular clients, has click & icon roles +}) +``` + +### Implementation +It can be used as follows: +```lua +s.mywibox:setup { + layout = wibox.layout.align.horizontal, + { -- Left widgets + layout = wibox.layout.fixed.horizontal, + mylauncher, + s.mytaglist, + s.mypromptbox, + }, + require('bling.widget.tabbed_misc').custom_tasklist(s), + { -- Right widgets + layout = wibox.layout.fixed.horizontal, + mykeyboardlayout, + wibox.widget.systray(), + mytextclock, + s.mylayoutbox, + }, + } +``` diff --git a/module/tabbed.lua b/module/tabbed.lua index 48eb3f9..5989da5 100644 --- a/module/tabbed.lua +++ b/module/tabbed.lua @@ -41,6 +41,7 @@ tabbed.remove = function(c) awful.titlebar.hide(c, bar.position) end c.bling_tabbed = nil + awesome.emit_signal("bling::tabbed::client_removed", tabobj, c) tabbed.switch_to(tabobj, 1) end @@ -62,7 +63,7 @@ tabbed.add = function(c, tabobj) -- but the new client needs to have the tabobj property -- before a clean switch can happen tabbed.update(tabobj) - awesome.emit_signal("bling::tabbed::client_added", tabobj) + awesome.emit_signal("bling::tabbed::client_added", tabobj, c) tabbed.switch_to(tabobj, #tabobj.clients) end @@ -151,6 +152,7 @@ tabbed.update = function(tabobj) end end + -- Maybe remove if I'm the only one using it? awesome.emit_signal("bling::tabbed::update", tabobj) if not beautiful.tabbar_disable then tabbed.update_tabbar(tabobj) @@ -173,6 +175,7 @@ tabbed.switch_to = function(tabobj, new_idx) helpers.client.sync(c, old_focused_c) end end + awesome.emit_signal("bling::tabbed::changed_focus", tabobj) tabbed.update(tabobj) end diff --git a/widget/init.lua b/widget/init.lua index cad993a..0044a13 100644 --- a/widget/init.lua +++ b/widget/init.lua @@ -1,4 +1,5 @@ return { tag_preview = require(... .. ".tag_preview"), - task_preview = require(... .. ".task_preview") + task_preview = require(... .. ".task_preview"), + tabbed_misc = require(... .. ".tabbed_misc") } diff --git a/widget/tabbed_misc/custom_tasklist.lua b/widget/tabbed_misc/custom_tasklist.lua new file mode 100644 index 0000000..e77e5b5 --- /dev/null +++ b/widget/tabbed_misc/custom_tasklist.lua @@ -0,0 +1,53 @@ +local wibox = require('wibox') +local awful = require('awful') +local gears = require('gears') +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 + + local group = c.bling_tabbed + + -- 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) + }) + + 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 + + self.widget = wrapper + + end +end + +return tabobj_support diff --git a/widget/tabbed_misc/init.lua b/widget/tabbed_misc/init.lua new file mode 100644 index 0000000..f0f1002 --- /dev/null +++ b/widget/tabbed_misc/init.lua @@ -0,0 +1,4 @@ +return { + titlebar_indicator = require(tostring(...):match(".*bling") .. ".widget.tabbed_misc.titlebar_indicator"), + custom_tasklist = require(tostring(...):match(".*bling") .. ".widget.tabbed_misc.custom_tasklist") +} diff --git a/widget/tabbed_misc/titlebar_indicator.lua b/widget/tabbed_misc/titlebar_indicator.lua new file mode 100644 index 0000000..243a722 --- /dev/null +++ b/widget/tabbed_misc/titlebar_indicator.lua @@ -0,0 +1,107 @@ +local wibox = require('wibox') +local awful = require('awful') +local gears = require('gears') +local beautiful = require('beautiful') +local dpi = require("beautiful.xresources").apply_dpi +local tabbed_module = require(tostring(...):match(".*bling") .. ".module.tabbed") + +-- 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 +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)) + + -- Container to store icons + local tabbed_icons = wibox.widget({ + layout = wibox.layout.fixed.horizontal, + 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 + end + + -- Empty list + if removed_c == c then + tabbed_icons:reset() + end + end) + + 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, + }) + + -- 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 +end +