Skip to content
Snippets Groups Projects
Commit b6d3aa9e authored by Henrik Tjäder's avatar Henrik Tjäder
Browse files

Initial commit for Taggrid

parents
No related branches found
No related tags found
No related merge requests found
# Extension providing a grid layout for Awesomewm 4.3
----------------------------------------------------------------------------
---- @author AfoHT
---- @copyright 2020 AfoHT
---- @license MIT/Apache
---- @module taggrid
------------------------------------------------------------------------------
-- Package envronment
local awful = require("awful")
local gears = require("gears")
-- Widget and layout library
local wibox = require("wibox")
local taggrid = {}
-- Add tags matching the layout below
taggrid.tag_count = 39
taggrid.tag_column_count = 3
taggrid.tag_offset = math.floor(taggrid.tag_count / taggrid.tag_column_count)
-- Provide the tags
taggrid.tags = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "[", "]", "←",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "[", "]", "←",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "[", "]", "←"
}
-- Create a gridlayout for the above tags
taggrid.gridlayout = wibox.widget {
forced_num_cols = taggrid.tag_offset,
forced_num_rows = taggrid.tag_column_count,
--min_rows_size = 10,
homogeneous = true,
expand = true,
layout = wibox.layout.grid
}
-- View the next tag to the left, wrapping on the current row
-- Replacing awful.tag.viewprev
function taggrid.viewprev()
-- If standing on the left edge and shifting one more,
-- wrap around on the current row
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
local tag
if curidx == 1 then
tag = screen.tags[tag_offset]
elseif curidx == tag_offset + 1 then
tag = screen.tags[tag_offset * 2]
elseif curidx == tag_offset * 2 + 1 then
tag = screen.tags[tag_offset * 3]
else
tag = screen.tags[curidx - 1]
end
if tag then
tag:view_only()
end
end
-- View the next tag to the right, wrapping on the current row
-- Replacing awful.tag.viewnext
function taggrid.viewnext()
-- If standing on the right edge and shifting one more,
-- wrap around on the current row
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
local tag
if curidx == tag_offset then
tag = screen.tags[1]
elseif curidx == tag_offset * 2 then
tag = screen.tags[tag_offset + 1]
elseif curidx == tag_offset * 3 then
tag = screen.tags[tag_offset * 2 + 1]
else
tag = screen.tags[curidx + 1]
end
if tag then
tag:view_only()
end
end
-- Jump to the row below in the grid
function taggrid.viewdown()
local tag_offset = taggrid.tag_offset
awful.tag.viewidx(-tag_offset)
end
-- Jump to the row above in the grid
function taggrid.viewup()
local tag_offset = taggrid.tag_offset
awful.tag.viewidx(tag_offset)
end
-- Shift the currently focused client left
function taggrid.shiftleft()
if client.focus then
local tag_offset = taggrid.tag_offset
local t = awful.screen.focused().selected_tag
local curidx = t.index
-- If standing on the right edge and shifting one more,
-- wrap around on the current row
-- Create local tag
local tag
if curidx == 1 then
tag = client.focus.screen.tags[tag_offset]
elseif curidx == tag_offset + 1 then
tag = client.focus.screen.tags[tag_offset * 2]
elseif curidx == tag_offset * 2 + 1 then
tag = client.focus.screen.tags[tag_offset * 3]
else
tag = client.focus.screen.tags[curidx - 1]
end
if tag then
client.focus:move_to_tag(tag)
end
end
end
-- Shift the currently focused client right
function taggrid.shiftright()
if client.focus then
local tag_offset = taggrid.tag_offset
local t = awful.screen.focused().selected_tag
local curidx = t.index
-- If standing on the right left edge and shifting one more,
-- wrap around on the current row
local tag
if curidx == tag_offset then
tag = client.focus.screen.tags[1]
elseif curidx == tag_offset * 2 then
tag = client.focus.screen.tags[tag_offset + 1]
elseif curidx == tag_offset * 3 then
tag = client.focus.screen.tags[tag_offset * 2 + 1]
else
tag = client.focus.screen.tags[curidx + 1]
end
if tag then
client.focus:move_to_tag(tag)
end
end
end
-- Shift the focused tag "downwards" in the grid
function taggrid.shiftdown()
if client.focus then
local tag_offset = taggrid.tag_offset
local t = awful.screen.focused().selected_tag
local curidx = t.index
local tag
if curidx >= tag_offset * 2 + 1 then
tag = client.focus.screen.tags[curidx - tag_offset * 2]
else
tag = client.focus.screen.tags[curidx + tag_offset]
end
if tag then
client.focus:move_to_tag(tag)
end
end
end
-- Shift the focused tag "upwards" in the grid
function taggrid.shiftup()
if client.focus then
local t = awful.screen.focused().selected_tag
local curidx = t.index
local tag
if curidx <= tag_offset then
tag = client.focus.screen.tags[curidx + tag_offset * 2]
else
tag = client.focus.screen.tags[curidx - tag_offset]
end
if tag then
client.focus:move_to_tag(tag)
end
end
end
-- View the tag on the currently selected row based on num-key row input
function taggrid.numviewtag(i)
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
local tag
if curidx <= tag_offset then
tag = screen.tags[i]
elseif curidx <= tag_offset * 2 then
tag = screen.tags[tag_offset + i]
else
tag = screen.tags[tag_offset * 2 + i]
end
if tag then
tag:view_only()
end
end
-- Toggle the tag on the currently selected row based on num-key row input
function taggrid.numviewtoggle(i)
if client.focus then
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
if curidx <= tag_offset then
local tag = screen.tags[i]
if tag then
awful.tag.viewtoggle(tag)
end
elseif curidx <= tag_offset * 2 then
local tag = screen.tags[tag_offset + i]
if tag then
awful.tag.viewtoggle(tag)
end
else
local tag = screen.tags[tag_offset * 2 + i]
if tag then
awful.tag.viewtoggle(tag)
end
end
end
end
-- Shift the tag on the currently selected row based on num-key row input
function taggrid.numshifttag(i)
if client.focus then
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
if curidx <= tag_offset then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
end
elseif curidx <= tag_offset * 2 then
local tag = client.focus.screen.tags[tag_offset + i]
if tag then
client.focus:move_to_tag(tag)
end
else
local tag = client.focus.screen.tags[tag_offset * 2 + i]
if tag then
client.focus:move_to_tag(tag)
end
end
end
end
-- Toggle the tag on the currently selected client on the current row based on num-key row input
function taggrid.numtoggletag(i)
if client.focus then
local tag_offset = taggrid.tag_offset
local screen = awful.screen.focused()
local t = awful.screen.focused().selected_tag
local curidx = t.index
if curidx <= tag_offset then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:toggle_tag(tag)
end
elseif curidx <= tag_offset * 2 then
local tag = client.focus.screen.tags[tag_offset + i]
if tag then
client.focus:toggle_tag(tag)
end
else
local tag = client.focus.screen.tags[tag_offset * 2 + i]
if tag then
client.focus:toggle_tag(tag)
end
end
end
end
return taggrid
----------------------------------------------------------------------------
---- @author AfoHT
---- @copyright 2020 AfoHT
---- @license MIT/Apache
---- @module globalkeys
------------------------------------------------------------------------------
-- Package envronment
local awful = require("awful")
local gears = require("gears")
local taggrid = require("taggrid.taggrid")
local _M = {}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
function _M.get(globalkeys)
-- This should map on the top row of your keyboard, usually 1 to 9.
-- tag_offset from taggrid
for i = 1, taggrid.tag_offset do
globalkeys = gears.table.join(globalkeys,
-- View tag only.
awful.key({ modkey }, "#" .. i + 9,
function ()
taggrid.numviewtag(i)
end,
{description = "view tag #"..i, group = "tag"}),
-- Toggle tag display.
awful.key({ modkey, "Control" }, "#" .. i + 9, taggrid.numviewtoggle(i),
{description = "toggle tag #" .. i, group = "tag"}),
-- Move client to tag.
awful.key({ modkey, "Shift" }, "#" .. i + 9, taggrid.numshifttag(i),
{description = "move focused client to tag #"..i, group = "tag"}),
-- Toggle tag on focused client.
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, taggrid.numtoggletag(i),
{description = "toggle focused client on tag #" .. i, group = "tag"})
)
end
return globalkeys
end
return setmetatable({}, { __call = function(_, ...) return _M.get(...) end })
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment