-- {{{ Mine
-- {{{ From https://www.reddit.com/r/awesomewm/comments/gd4qxl/get_index_of_client_in_tasklist/ with some modifications
local function fixed_indexing_filter(c)
if not c then
return false
end
if not (c.skip_taskbar or c.hidden or c.type == "splash" or c.type == "dock" or c.type == "desktop") then
return true
end
return false
end
local function focused_screen_current_tag_client_iterator()
local focused_screen = awful.screen.focused()
local selected_tag_filter = function (c) return c.first_tag == focused_screen.selected_tag end
local first_client_taskbar_idx = 1
return awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen)
end
-- Returns client index in the taskbar (first on the left will have index = 1)
local function client_to_taskbar_idx(client)
local client_taskbar_idx = 0
for c in focused_screen_current_tag_client_iterator() do
if fixed_indexing_filter(c) then
client_taskbar_idx = client_taskbar_idx + 1
if (c == client) then
return client_taskbar_idx
end
end
end
-- if no client is focused (e.g. all are minimized) behave as if 1st is focused
return 1
end
-- Returns client which is at taskbar_idx position in the taskbar
function taskbar_idx_to_client(taskbar_idx)
local client_taskbar_idx = 0
for c in focused_screen_current_tag_client_iterator() do
if fixed_indexing_filter(c) then
client_taskbar_idx = client_taskbar_idx + 1
if (client_taskbar_idx == taskbar_idx) then
return c
end
end
end
return nil
end
--
-- }}}
-- Returns total number of clients in the currently selected tag
local function selected_tag_number_of_clients()
local number_of_clients = 0
for c in focused_screen_current_tag_client_iterator() do
if fixed_indexing_filter(c) then
number_of_clients = number_of_clients + 1
end
end
return number_of_clients
end
-- Switches focus to the client of index in the taskbar = taskbar_idx:
-- * client with 1st taskbar item will have index 1
-- * client with 2nd taskbar item will have index 2
-- * etc
local function client_focus_by_taskbar_idx(taskbar_idx)
-- User wants to focus a non-existing client, e.g. there are only 2 opened in
-- focused screen selected tag clients and user wants to focus 3rd one, as there is
-- no 3rd one just do nothing
if taskbar_idx < 1 or taskbar_idx > selected_tag_number_of_clients() then
return
end
-- unminimize clint to focus in case it is minizied (won't harm for not-minimized)
local client_to_focus = taskbar_idx_to_client(taskbar_idx)
client_to_focus:emit_signal( -- client_to_focus cannot be null because of the sanity check above
"request::activate",
"tasklist",
{raise = true}
)
-- now focus to it
local focused_client_taskbar_idx = client_to_taskbar_idx(client.focus)
local relative_idx = taskbar_idx - focused_client_taskbar_idx
awful.client.focus.byidx(relative_idx)
end
-- }}}
-- }}}
-- {{{ Mine: added/changes navigation for clients
-- {{{ changed (was according to stack, now according to taskbar position):
-- moving between windows left/right (as in tasklist)
awful.key({ modkey, }, "j",
function () awful.client.focus.byidx(-1) end,
{description = "next window to the left by index", group = "client"}
),
awful.key({ modkey, }, "k",
function () awful.client.focus.byidx(1) end,
{description = "next window to the right by index", group = "client"}
), -- }}}
-- {{{ added (browser-tab-like switching of clients):
-- moving between windows with Mod4-Fn (as between tags with Mod4-n)
awful.key({ modkey, }, "F1",
function () client_focus_by_taskbar_idx(1) end,
{description = "focus client 1 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F2",
function () client_focus_by_taskbar_idx(2) end,
{description = "focus client 2 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F3",
function () client_focus_by_taskbar_idx(3) end,
{description = "focus client 3 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F4",
function () client_focus_by_taskbar_idx(4) end,
{description = "focus client 4 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F5",
function () client_focus_by_taskbar_idx(5) end,
{description = "focus client 5 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F6",
function () client_focus_by_taskbar_idx(6) end,
{description = "focus client 6 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F7",
function () client_focus_by_taskbar_idx(7) end,
{description = "focus client 7 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F8",
function () client_focus_by_taskbar_idx(8) end,
{description = "focus client 8 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F9",
function () client_focus_by_taskbar_idx(9) end,
{description = "focus client 9 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F10",
function () client_focus_by_taskbar_idx(10) end,
{description = "focus client 10 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F11",
function () client_focus_by_taskbar_idx(11) end,
{description = "focus client 11 in taskbar", group = "client"}
),
awful.key({ modkey, }, "F12",
function () client_focus_by_taskbar_idx(12) end,
{description = "focus client 12 in taskbar", group = "client"}
),
-- }}}
-- }}}