142 lines
2.8 KiB
Lua
Executable File
142 lines
2.8 KiB
Lua
Executable File
-- Tag grid manager
|
|
|
|
local Tagger = {
|
|
screen = nil, rows = 2, cols = 4
|
|
}
|
|
Tagger.__index = Tagger
|
|
|
|
function Tagger:new(screen)
|
|
local t = {}
|
|
setmetatable(t, Tagger)
|
|
t.screen = screen
|
|
|
|
-- Create tags on this Tagger's screen
|
|
for r=1, t.rows do
|
|
for c=1, t.cols do
|
|
awful.tag.add("(" .. tostring(r) .. ", " .. tostring(c) .. ")", {
|
|
layout = layoutmanager:default_layout(),
|
|
screen = t.screen,
|
|
|
|
gap_single_client = false,
|
|
gap = beautiful.useless_gap,
|
|
volatile = false,
|
|
|
|
-- Only select the first tag
|
|
selected = ((r == 1) and (c == 1))
|
|
})
|
|
end
|
|
end
|
|
return t
|
|
end
|
|
|
|
|
|
function Tagger:get_tag()
|
|
return self.screen.selected_tag.index
|
|
end
|
|
|
|
-- Return current column
|
|
function Tagger:get_col()
|
|
return ( (self:get_tag() - 1) % self.cols ) + 1
|
|
end
|
|
|
|
-- Return current row
|
|
function Tagger:get_row()
|
|
return math.floor( (self:get_tag() - self:get_col()) / self.cols ) + 1
|
|
end
|
|
|
|
-- Select a tag by position
|
|
function Tagger:setpos(row, col)
|
|
local target_absolute = (self.cols * (row - 1)) + col
|
|
local target_relative = target_absolute - self.screen.selected_tag.index
|
|
awful.tag.viewidx(target_relative)
|
|
|
|
self:update_widget()
|
|
end
|
|
|
|
-- Update this tagger's screen's tagindicator
|
|
function Tagger:update_widget()
|
|
local clients
|
|
local tgs = self.screen.tags
|
|
|
|
for i=1, #tgs do
|
|
clients = tgs[i]:clients()
|
|
|
|
-- Each tag indicator is a "checkbox" widget.
|
|
-- Make that the currently active tag is checked and that all
|
|
-- others are not.
|
|
if (tgs[i].index == self.screen.selected_tag.index) then
|
|
self.screen.tagindicators[i].checked = true
|
|
else
|
|
self.screen.tagindicators[i].checked = false
|
|
end
|
|
|
|
-- Highlight tags that are not empty
|
|
if (#clients == 0) then
|
|
self.screen.tagindicators[i].border_color = beautiful.color.bar.inactive
|
|
else
|
|
self.screen.tagindicators[i].border_color = beautiful.color.bar.active
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Navigation
|
|
function Tagger:up()
|
|
local row = self:get_row() - 1
|
|
local col = self:get_col()
|
|
|
|
if (row >= 1) then
|
|
self:setpos(row, col)
|
|
end
|
|
end
|
|
|
|
function Tagger:down()
|
|
local row = self:get_row() + 1
|
|
local col = self:get_col()
|
|
|
|
if (row <= self.rows) then
|
|
self:setpos(row, col)
|
|
end
|
|
end
|
|
|
|
function Tagger:right()
|
|
local row = self:get_row()
|
|
local col = self:get_col() + 1
|
|
|
|
if (col <= self.cols) then
|
|
self:setpos(row, col)
|
|
end
|
|
end
|
|
|
|
function Tagger:left()
|
|
local row = self:get_row()
|
|
local col = self:get_col() - 1
|
|
|
|
if (col >= 1) then
|
|
self:setpos(row, col)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
-- Moving clients
|
|
function Tagger:move_client(client, direction)
|
|
if direction == "up" then
|
|
self:up()
|
|
elseif direction == "down" then
|
|
self:down()
|
|
elseif direction == "left" then
|
|
self:left()
|
|
elseif direction == "right" then
|
|
self:right()
|
|
end
|
|
|
|
if client.first_tag.layout == awful.layout.suit.floating then
|
|
client.floating = true
|
|
end
|
|
|
|
client:move_to_tag(self.screen.selected_tag)
|
|
self:update_widget()
|
|
end
|
|
|
|
return Tagger
|