Add 0th tag and move to first empty workspace

This commit is contained in:
Thomas Avé 2023-06-05 15:46:55 +02:00
parent ab90eaa114
commit e7d2525d84
2 changed files with 45 additions and 29 deletions

View File

@ -17,8 +17,6 @@ local naughty = require("naughty")
local beautiful = require("beautiful")
local volume_widget = require("widgets.volume-widget.volume")
local dpi = beautiful.xresources.apply_dpi
local mouse_utils = require("mouse_utils")
local modkey = "Mod4"
@ -27,6 +25,20 @@ local keys = {}
-- AwesomeWM Vim Tmux Navigator
local function get_first_nonempty_tag()
local screen = awful.screen.focused()
local tags = screen.tags
local first_empty = nil
for _, t in ipairs(tags) do
if #t:clients() > 0 then
first_empty = nil
elseif first_empty == nil then
first_empty = t
end
end
return first_empty
end
local focus_bydirection = function(direction)
awful.client.focus.global_bydirection(direction)
if client.focus then
@ -409,19 +421,9 @@ keys.globalkeys = gears.table.join(
end,
{description = "Switch to next tag", group = "client"}
),
-- Focus client by index (cycle through clients)
awful.key({modkey}, "t",
function()
local screen = awful.screen.focused()
local tags = screen.tags
local first_empty = nil
for _, t in ipairs(tags) do
if #t:clients() > 0 then
first_empty = nil
elseif first_empty == nil then
first_empty = t
end
end
local first_empty = get_first_nonempty_tag()
if first_empty ~= nil then
first_empty:view_only()
end
@ -429,6 +431,17 @@ keys.globalkeys = gears.table.join(
{description = "Switch to next tag", group = "client"}
),
awful.key({modkey, "Shift"}, "t",
function()
local first_empty = get_first_nonempty_tag()
if first_empty ~= nil then
client.focus:move_to_tag(first_empty)
first_empty:view_only()
end
end,
{description = "Switch to next tag", group = "client"}
),
-- =========================================
-- SCREEN FOCUSING
-- =========================================
@ -640,34 +653,38 @@ keys.clientkeys = gears.table.join(
)
)
-- Bind all key numbers to tags
for i = 1, 9 do
local function register_tag(tag)
keys.globalkeys = gears.table.join(keys.globalkeys,
-- Switch to tag
awful.key({modkey}, "#" .. i + 9,
awful.key({modkey}, "#" .. tag + 9,
function()
local screen = awful.screen.focused()
local tag = screen.tags[i]
if tag then
tag:view_only()
local t = screen.tags[tag]
if t then
t:view_only()
end
end,
{description = "view tag #"..i, group = "tag"}
{description = "view tag #"..tag, group = "tag"}
),
-- Move client to tag
awful.key({modkey, "Shift"}, "#" .. i + 9,
awful.key({modkey, "Shift"}, "#" .. tag + 9,
function()
if client.focus then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
tag:view_only()
local t= client.focus.screen.tags[tag]
if t then
client.focus:move_to_tag(t)
t:view_only()
end
end
end,
{description = "move focused client to tag #"..i, group = "tag"}
{description = "move focused client to tag #"..tag, group = "tag"}
)
)
end
-- Bind all key numbers to tags
for i = 1, 10 do
register_tag(i)
end
return keys

View File

@ -32,15 +32,14 @@ pastel.initialize = function()
-- Set up each screen (add tags & panels)
awful.screen.connect_for_each_screen(function(s)
for i = 1, 9, 1
for i = 1, 10, 1
do
awful.tag.add(tostring(i), {
awful.tag.add(tostring(i % 10), {
layout = grid,
screen = s,
selected = i == 1
})
end
s.quake = quake
-- Only add the top panel on the primary screen