Cleaned up tagger code

master
Mark 2022-04-24 12:57:41 -07:00
parent 58b2df6956
commit 9a13f2406d
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
5 changed files with 118 additions and 94 deletions

View File

@ -10,7 +10,6 @@ local desktop = {
textclock = require("desktop.widgets.textclock"), textclock = require("desktop.widgets.textclock"),
layoutbox = require("desktop.widgets.layoutbox"), layoutbox = require("desktop.widgets.layoutbox"),
keymap = require("desktop.widgets.keymap"), keymap = require("desktop.widgets.keymap"),
tagindicator = require("desktop.widgets.tagindicator"),
launcher = require("desktop.widgets.launcher"), launcher = require("desktop.widgets.launcher"),
shortcut = require("desktop.widgets.shortcut"), shortcut = require("desktop.widgets.shortcut"),
--mdadm = require("desktop.widgets.mdadm"), --mdadm = require("desktop.widgets.mdadm"),
@ -88,10 +87,7 @@ awful.screen.connect_for_each_screen(
function(s) function(s)
-- s: the screen this function is being called for -- s: the screen this function is being called for
-- Create tag table -- Create tag table
s.tagger = desktop.Tagger{screen = s}
s.tagger = desktop.Tagger:new(s)
desktop.widgets.tagindicator(s)
-- Create a promptbox for each s -- Create a promptbox for each s
s.mypromptbox = awful.widget.prompt() s.mypromptbox = awful.widget.prompt()
@ -198,7 +194,7 @@ awful.screen.connect_for_each_screen(
desktop.widgets.launcher, desktop.widgets.launcher,
desktop.widgets.space(18), desktop.widgets.space(18),
s.tagindicator, s.tagger.widget.widget,
desktop.widgets.layoutbox(s), desktop.widgets.layoutbox(s),
s.shortcuts, s.shortcuts,

7
desktop/tagger/init.lua Normal file
View File

@ -0,0 +1,7 @@
local P = require("desktop/tagger/tagger")
local F = function(args)
return P:new(args)
end
return F

View File

@ -3,29 +3,39 @@
local Tagger = { local Tagger = {
screen = nil, rows = 2, cols = 4 screen = nil, rows = 2, cols = 4
} }
local Widget = require("desktop.tagger.widget")
Tagger.__index = Tagger Tagger.__index = Tagger
function Tagger:new(screen) function Tagger:new(args)
local t = {} local t = {
setmetatable(t, Tagger) screen = args.screen,
t.screen = screen rows = args.rows or 2,
cols = args.cols or 4,
}
setmetatable(t, self)
-- Create tags on this Tagger's screen -- Create tags on this Tagger's screen
for r=1, t.rows do for r=1, t.rows do
for c=1, t.cols do for c=1, t.cols do
awful.tag.add("(" .. tostring(r) .. ", " .. tostring(c) .. ")", { awful.tag.add(
layout = layoutmanager:default_layout(), "(" .. tostring(r) .. ", " .. tostring(c) .. ")",
screen = t.screen, {
layout = layoutmanager:default_layout(),
screen = t.screen,
gap_single_client = false, gap_single_client = false,
gap = beautiful.useless_gap, gap = beautiful.useless_gap,
volatile = false, volatile = false,
-- Only select the first tag -- Only select the first tag
selected = ((r == 1) and (c == 1)) selected = ((r == 1) and (c == 1))
}) }
)
end end
end end
t.widget = Widget:new(t)
return t return t
end end
@ -36,12 +46,18 @@ end
-- Return current column -- Return current column
function Tagger:get_col() function Tagger:get_col()
return ( (self:get_tag() - 1) % self.cols ) + 1 return (
(self:get_tag() - 1) % self.cols
) + 1
end end
-- Return current row -- Return current row
function Tagger:get_row() function Tagger:get_row()
return math.floor( (self:get_tag() - self:get_col()) / self.cols ) + 1 return math.floor(
(
self:get_tag() - self:get_col()
) / self.cols
) + 1
end end
-- Select a tag by position -- Select a tag by position
@ -65,16 +81,16 @@ function Tagger:update_widget()
-- Make that the currently active tag is checked and that all -- Make that the currently active tag is checked and that all
-- others are not. -- others are not.
if (tgs[i].index == self.screen.selected_tag.index) then if (tgs[i].index == self.screen.selected_tag.index) then
self.screen.tagindicators[i].checked = true self.widget.tagindicators[i].checked = true
else else
self.screen.tagindicators[i].checked = false self.widget.tagindicators[i].checked = false
end end
-- Highlight tags that are not empty -- Highlight tags that are not empty
if (#clients == 0) then if (#clients == 0) then
self.screen.tagindicators[i].border_color = beautiful.color.bar.inactive self.widget.tagindicators[i].border_color = beautiful.color.bar.inactive
else else
self.screen.tagindicators[i].border_color = beautiful.color.bar.active self.widget.tagindicators[i].border_color = beautiful.color.bar.active
end end
end end
end end
@ -117,7 +133,6 @@ function Tagger:left()
end end
-- Moving clients -- Moving clients
function Tagger:move_client(client, direction) function Tagger:move_client(client, direction)
if direction == "up" then if direction == "up" then

74
desktop/tagger/widget.lua Normal file
View File

@ -0,0 +1,74 @@
local P = {}
P.__index = P
function P:new(tagger)
local widget = {}
setmetatable(widget, self)
widget.tagindicator = wibox.widget {
homogeneous = true,
spacing = beautiful.dpi(2),
min_cols_size = 10,
min_rows_size = 10,
layout = wibox.layout.grid
}
-- Calculate checkbox size limit
local cbox_maxsize = beautiful.dpi(conf.bar_height)
cbox_maxsize = cbox_maxsize - (2 * beautiful.dpi(conf.bar_margin))
cbox_maxsize = cbox_maxsize - (tagger.rows - 1)*(beautiful.dpi(widget.tagindicator.spacing))
-- Make each tag's checkmark
widget.tagindicators = {}
for r=1, tagger.rows do
for c=1, tagger.cols do
local t = wibox.widget {
widget = wibox.widget.checkbox,
bg = beautiful.color.transparent,
checked = false,
border_width = beautiful.dpi(2),
paddings = beautiful.dpi(3),
color = beautiful.color.bar.active,
border_color = beautiful.color.bar.inactive,
}
widget.tagindicators[
(c + (tagger.cols * (r - 1)))
] = t
if ((conf.bar_position == "bottom") or (conf.bar_position == "top")) then
cbox_maxsize = cbox_maxsize / tagger.rows
else
cbox_maxsize = cbox_maxsize / tagger.cols
end
widget.tagindicator:add_widget_at(
-- The constraint container is necessary here, without it
-- the checkboxes will fill all the height that is available to them.
wibox.container.constraint(
widget.tagindicators[(c + (tagger.cols * (r - 1)))],
"exact", cbox_maxsize, cbox_maxsize
), r, c)
end
end
-- Wrap everything with a background container
widget.widget = wibox.widget {
widget.tagindicator,
layout = wibox.container.background
}
widget.widget:connect_signal("mouse::enter", function(result)
widget.bg = beautiful.color.bar.hover_bg
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.bg = beautiful.color.transparent
end)
return widget
end
return P

View File

@ -1,68 +0,0 @@
local tagindicator = {}
tagindicator.make = function(screen)
local widget
-- Create tag tagindicators
-- We're using flex.vertical and flex.horizontal layouts because the grid
-- layout doesn't expand things properly.
screen.tagindicators = {}
screen.tagindicator = wibox.widget {
homogeneous = true,
spacing = beautiful.dpi(2),
min_cols_size = 10,
min_rows_size = 10,
layout = wibox.layout.grid
}
local tmp_row
for r=1, screen.tagger.rows do
for c=1, screen.tagger.cols do
screen.tagindicators[(c + (screen.tagger.cols * (r - 1)))] = wibox.widget {
checked = false,
border_width = beautiful.dpi(2),
paddings = beautiful.dpi(3),
color = beautiful.color.bar.active,
border_color = beautiful.color.bar.inactive,
widget = wibox.widget.checkbox
}
-- Calculate checkbox size limit
local cbox_maxsize = beautiful.dpi(conf.bar_height)
cbox_maxsize = cbox_maxsize - (2 * beautiful.dpi(conf.bar_margin))
cbox_maxsize = cbox_maxsize - (screen.tagger.rows - 1)*(beautiful.dpi(screen.tagindicator.spacing))
if ((conf.bar_position == "bottom") or (conf.bar_position == "top")) then
cbox_maxsize = cbox_maxsize / screen.tagger.rows
else
cbox_maxsize = cbox_maxsize / screen.tagger.cols
end
screen.tagindicator:add_widget_at(
-- The constraint container is VERY necessary here!
-- Otherwise, the checkboxes will fill all the height that is available to them.
wibox.container.constraint(
screen.tagindicators[(c + (screen.tagger.cols * (r - 1)))],
"exact", cbox_maxsize, cbox_maxsize
), r, c)
end
end
widget = wibox.widget {
screen.tagindicator,
layout = wibox.container.background
}
-- Change background when mouse is over widget
widget:connect_signal("mouse::enter", function(result)
widget.bg = beautiful.color.bar.hover_bg
end)
widget:connect_signal("mouse::leave", function(result)
widget.bg = beautiful.color.transparent
end)
return widget
end
return tagindicator.make