Merge pull request #135 from undefinedDarkness/fixes

[3/3] Fixes to titlebar indicator and tasklist tabbed indicator
This commit is contained in:
contribuewwt 2021-11-16 17:48:28 +05:30 committed by GitHub
commit 0da8b7b7f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 175 additions and 140 deletions

View File

@ -80,6 +80,19 @@ 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_border_width = 3 -- The border width of the widget
theme.task_preview_widget_margin = 0 -- The margin 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
}
-- window switcher widget -- window switcher widget
theme.window_switcher_widget_bg = "#000000" -- The bg color of the widget theme.window_switcher_widget_bg = "#000000" -- The bg color of the widget
theme.window_switcher_widget_border_width = 3 -- The border width of the widget theme.window_switcher_widget_border_width = 3 -- The border width of the widget

View File

@ -16,11 +16,14 @@ To use the task list indicator:
```lua ```lua
bling.widget.tabbed_misc.titlebar_indicator(client, { bling.widget.tabbed_misc.titlebar_indicator(client, {
layout_spacing = dpi(5), -- Set spacing in between items layout = wibox.layout.fixed.vertical,
icon_size = dpi(24), -- Set icon size layout_spacing = dpi(5), -- Set spacing in between items
icon_margin = 0, -- Set icon margin icon_size = dpi(24), -- Set icon size
bg_color_focus = "#282828", -- Color for the focused items icon_margin = 0, -- Set icon margin
bg_color = "#1d2021", -- Color for normal / unfocused items 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, icon_shape = gears.shape.circle -- Set icon shape,
}) })
``` ```
@ -35,7 +38,12 @@ bling.widget.tabbed_misc.titlebar_indicator(client, {
}, },
widget = wibox.container.margin, widget = wibox.container.margin,
margins = 2, 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
end
end
} }
}) })
``` ```

View File

@ -5,51 +5,47 @@ local beautiful = require("beautiful")
local dpi = require("beautiful.xresources").apply_dpi local dpi = require("beautiful.xresources").apply_dpi
local function tabobj_support(self, c, index, clients) local function tabobj_support(self, c, index, clients)
-- Self is the background widget in this context -- Self is the background widget in this context
if not c.bling_tabbed then if not c.bling_tabbed and #c.bling_tabbed.clients > 1 then
return return
end 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 local wrapper = wibox.widget({
if #group.clients > 1 then layout_v,
local wrapper = wibox.widget({ id = "click_role",
{ widget = wibox.container.margin,
-- This is so dumb... but it works so meh margins = dpi(5),
{ })
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 -- To get the ball rolling.
if c and c.icon then for idx, c in ipairs(group.clients) do
-- TODO: Don't do this in a -1iq way if not (c and c.icon) then goto skip end
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 -- Add to the last layout
end 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 end
return tabobj_support return tabobj_support

View File

@ -9,110 +9,125 @@ local tabbed_module = require(
-- Just check if a table contains a value. -- Just check if a table contains a value.
local function tbl_contains(tbl, item) local function tbl_contains(tbl, item)
for _, v in ipairs(tbl) do for _, v in ipairs(tbl) do
if v == item then if v == item then
return true return true
end end
end end
return false return false
end end
-- Needs to be run, every time a new titlbear is created -- Needs to be run, every time a new titlbear is created
return function(c, opts) return function(c, opts)
-- Args & Fallback -- Widget templates are in their original loactions -- Args & Fallback -- Widget templates are in their original loactions
opts = gears.table.crush({ opts = gears.table.crush({
layout_spacing = dpi(4), layout_spacing = dpi(4),
icon_size = dpi(20), icon_size = dpi(20),
icon_margin = dpi(4), icon_margin = dpi(4),
bg_color_focus = "#ff0000", bg_color_focus = "#ff0000",
bg_color = "#00000000", bg_color = "#00000000",
icon_shape = function(cr, w, h) fg_color = "#fafafa",
gears.shape.rounded_rect(cr, w, h, 0) fg_color_focus = "#e0e0e0",
end, icon_shape = function(cr, w, h)
}, gears.table.join( gears.shape.rounded_rect(cr, w, h, 0)
opts, end,
beautiful.bling_tabbed_misc_titlebar_indicator layout = wibox.layout.fixed.horizontal,
)) }, gears.table.join(
opts,
beautiful.bling_tabbed_misc_titlebar_indicator
))
-- Container to store icons -- Container to store icons
local tabbed_icons = wibox.widget({ local tabbed_icons = wibox.widget({
layout = wibox.layout.fixed.horizontal, layout = opts.layout,
spacing = opts.layout_spacing, spacing = opts.layout_spacing,
}) })
awesome.connect_signal( awesome.connect_signal("bling::tabbed::client_removed", function(_, removed_c)
"bling::tabbed::client_removed", -- Remove from list
function(_, removed_c) for idx, icon in ipairs(tabbed_icons.children) do
-- Remove from list if icon._client == removed_c then
for idx, icon in ipairs(tabbed_icons.children) do tabbed_icons:remove(idx)
if end
icon:get_children_by_id("icon_role")[1].client == removed_c end
then
tabbed_icons:remove(idx)
end
end
-- Empty list -- Empty list
if removed_c == c then if removed_c == c then
tabbed_icons:reset() tabbed_icons:reset()
end end
end end)
)
local function recreate(group) local function recreate(group)
if tbl_contains(group.clients, c) then if tbl_contains(group.clients, c) then
tabbed_icons:reset() tabbed_icons:reset()
local focused = group.clients[group.focused_idx] local focused = group.clients[group.focused_idx]
-- Autohide? -- Autohide?
if #group.clients == 1 then if #group.clients == 1 then
return return
end end
for idx, client in ipairs(group.clients) do for idx, client in ipairs(group.clients) do
local widget = wibox.widget(opts.widget_template or { local widget = wibox.widget(
{ opts.widget_template or {
{ {
{ {
id = "icon_role", {
forced_width = opts.icon_size, id = "icon_role",
forced_height = opts.icon_size, forced_width = opts.icon_size,
widget = awful.widget.clienticon, forced_height = opts.icon_size,
}, widget = awful.widget.clienticon,
margins = opts.icon_margin, },
widget = wibox.container.margin, margins = opts.icon_margin,
}, widget = wibox.container.margin,
bg = (client == focused) and opts.bg_color_focus },
or opts.bg_color, shape = opts.icon_shape,
shape = opts.icon_shape, id = "bg_role",
id = "click_role", widget = wibox.container.background,
widget = wibox.container.background, },
}, halign = "center",
halign = "center", valign = "center",
valign = "center", widget = wibox.container.place,
widget = wibox.container.place, })
})
-- Add icons & etc widget._client = client
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 -- No creation call back since this would be called on creation & every time the widget updated.
w:add_button(awful.button({}, 1, function() if opts.widget_template and opts.widget_template.update_callback then
tabbed_module.switch_to(group, idx) opts.widget_template.update_callback(widget, client, group)
end)) end
end
tabbed_icons:add(widget) -- Add icons & etc
end for _, w in ipairs(widget:get_children_by_id("icon_role")) do
end -- TODO: Allow fallback icon?
end w.image = client.icon
w.client = client
end
awesome.connect_signal("bling::tabbed::client_added", recreate) for _, w in ipairs(widget:get_children_by_id("bg_role")) do
awesome.connect_signal("bling::tabbed::changed_focus", recreate) 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
return tabbed_icons 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
end end

View File

@ -38,6 +38,7 @@ local function draw_widget(
for i, c in ipairs(t:clients()) do for i, c in ipairs(t:clients()) do
if not c.hidden and not c.minimized then if not c.hidden and not c.minimized then
local img_box = wibox.widget ({ local img_box = wibox.widget ({
resize = true, resize = true,
forced_height = 100 * scale, forced_height = 100 * scale,
@ -206,6 +207,8 @@ local enable = function(opts)
tag_preview_box.maximum_width = scale * geo.width + margin * 2 tag_preview_box.maximum_width = scale * geo.width + margin * 2
tag_preview_box.maximum_height = scale * geo.height + margin * 2 tag_preview_box.maximum_height = scale * geo.height + margin * 2
tag_preview_box.widget = draw_widget( tag_preview_box.widget = draw_widget(
t, t,
tag_preview_image, tag_preview_image,
@ -240,4 +243,4 @@ local enable = function(opts)
end) end)
end end
return { enable = enable } return {enable = enable, draw_widget = draw_widget}

View File

@ -196,4 +196,4 @@ local enable = function(opts)
end) end)
end end
return { enable = enable } return { enable = enable, draw_widget = draw_widget }