LINUX.ORG.RU

История изменений

Исправление dissident, (текущая версия) :

@mord0d:

Потому что это относительное смещение. То есть он смещает на i клиентов. Естественно 0 у тебя никуда не ведёт. Вторым аргументом awful.client.next() жрёт клиент, относительно которого смещать (по умолчанию — текущий клиент в фокусе).

А вот оказывается awful.client.next(0) как раз и возвращает текущего сфокусированного. Другие способы у меня не заработали (может не умею готовить их).

А если тебе нужно получить клиент в фокусе из всех, то нужно проходиться по всем клиентам:

Ну вот оказывается не нужно.

Может ещё что добавлю, когда окончательно проснусь.

Только добавь plz к тому, что ниже, бо оно работает. Вобщем я кончил.

Мне только не нравится функция selected_tag_number_of_clients, наверняка это можно сделать короче и без copy paste из функции client_taskbar_idx, но как я так и не понял.

Да и awful.widget.tasklist.filter.currenttags(c, screen) в принципе лишнее, так как все это фильтруется и так при вызове awful.client.iterate, но это как раз неплохо, больше проверок - лучше.

Конечно если бы это было на работе или там в какой-то проект я бы такого не закомитил (из-за selected_tag_number_of_clients), а так - работает и ладно. Но любые упрощения mile widzane!

-- {{{ 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, screen)
        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") and 
            (screen == nil or awful.widget.tasklist.filter.currenttags(c, screen)
        ) then
            return true
        end
        return false
    end

    -- Returns client index in the taskbar (first on the left will have index = 1)
    local function client_taskbar_idx(client)
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1
        local client_screen = client.screen

        local client_taskbar_idx = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) do
            if fixed_indexing_filter(c, client_screen) then
                client_taskbar_idx = client_taskbar_idx + 1
                if (c == client) then
                    return client_taskbar_idx
                end
            end
        end

        return nil
    end
    -- }}}
    
    -- Returns total number of clients in the currently selected tag
    local function selected_tag_number_of_clients()
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1

        local number_of_clients = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) 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 cllients 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
     
        local focused_client = awful.client.next(0) -- does not work

        if focused_client ~= nil then
            local focused_client_taskbar_idx = client_taskbar_idx(focused_client)
            if focused_client_taskbar_idx ~= nil then
                local relative_idx = taskbar_idx - focused_client_taskbar_idx
                awful.client.focus.byidx(relative_idx)
            end
        end
    end
    --- }}}

-- }}}

-- {{{ Key bindings
globalkeys = gears.table.join(

--- skip ---

    -- {{{ Mine: added/changes navigation for clients

--- skip ---

        -- {{{ 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"}
        ),
        -- }}}

    -- }}}

Исправление dissident, :

@mord0d:

Потому что это относительное смещение. То есть он смещает на i клиентов. Естественно 0 у тебя никуда не ведёт. Вторым аргументом awful.client.next() жрёт клиент, относительно которого смещать (по умолчанию — текущий клиент в фокусе).

А вот оказывается awful.client.next(0) как раз и возвращает текущего сфокусированного. Другие способы у меня не заработали (может не умею готовить их).

А если тебе нужно получить клиент в фокусе из всех, то нужно проходиться по всем клиентам:

Ну вот оказывается не нужно.

Может ещё что добавлю, когда окончательно проснусь.

Только добавь plz к тому, что ниже, бо оно работает. Вобщем я кончил.

Мне только не нравится функция selected_tag_number_of_clients, наверняка это можно сделать короче и без copy paste из функции client_taskbar_idx, но как я так и не понял.

Да и awful.widget.tasklist.filter.currenttags(c, screen) в принципе лишнее, так как все это фильтруется и так при вызове awful.client.iterate, но это как раз неплохо, больше проверок - лучше.

Конечно если бы это было на работе или там в какой-то проект я бы такого не закомитил (из-за selected_tag_number_of_clients), а так - работает и ладно. Но любые упрощения mile widzane!

-- {{{ 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, screen)
        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") and 
            (screen == nil or awful.widget.tasklist.filter.currenttags(c, screen)
        ) then
            return true
        end
        return false
    end

    -- Returns client index in the taskbar (first on the left will have index = 1)
    local function client_taskbar_idx(client)
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1
        local client_screen = client.screen

        local client_taskbar_idx = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) do
            if fixed_indexing_filter(c, client_screen) then
                client_taskbar_idx = client_taskbar_idx + 1
                if (c == client) then
                    return client_taskbar_idx
                end
            end
        end

        return nil
    end
    -- }}}
    
    -- Returns total number of clients in the currently selected tag
    local function selected_tag_number_of_clients()
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1

        local number_of_clients = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) 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 cllients 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
     
        local focused_client = awful.client.next(0) -- does not work

        if focused_client ~= nil then
            local focused_client_taskbar_idx = client_taskbar_idx(focused_client)
            if focused_client_taskbar_idx ~= nil then
                local relative_idx = taskbar_idx - focused_client_taskbar_idx
                awful.client.focus.byidx(relative_idx)
            end
        end
    end
    --- }}}

-- }}}

-- {{{ Key bindings
globalkeys = gears.table.join(

--- skip ---

    -- {{{ Mine: added/changes navigation for clients

--- skip ---

        -- {{{ added (browser-tab-like switching of clients):
        --     moving between windows with Mod4-FNN (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"}
        ),
        -- }}}

    -- }}}

Исходная версия dissident, :

@mord0d:

Потому что это относительное смещение. То есть он смещает на i клиентов. Естественно 0 у тебя никуда не ведёт. Вторым аргументом awful.client.next() жрёт клиент, относительно которого смещать (по умолчанию — текущий клиент в фокусе).

А вот оказывается awful.client.next(0) как раз и возвращает текущего сфокусированного. Другие способы у меня не заработали (может не умею готовить их).

А если тебе нужно получить клиент в фокусе из всех, то нужно проходиться по всем клиентам:

Ну вот оказывается не нужно.

Может ещё что добавлю, когда окончательно проснусь.

Только добавь plz к тому, что ниже, бо оно работает. Вобщем я кончил.

Мне только не нравится функция selected_tag_number_of_clients, наверняка это можно сделать короче и без copy paste из функции client_taskbar_idx, но как я так и не понял.

Да и awful.widget.tasklist.filter.currenttags(c, screen) в принципе лишнее, так как все это фильтруется и так при вызове awful.client.iterate, но это как раз неплохо, больше проверок - лучше.

Конечно если бы это было на работе или там в какой-то проект я бы такого не закомитил (из-за selected_tag_number_of_clients, а так - работает и ладно. Но любые упрощения mile widzane!

-- {{{ 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, screen)
        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") and 
            (screen == nil or awful.widget.tasklist.filter.currenttags(c, screen)
        ) then
            return true
        end
        return false
    end

    -- Returns client index in the taskbar (first on the left will have index = 1)
    local function client_taskbar_idx(client)
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1
        local client_screen = client.screen

        local client_taskbar_idx = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) do
            if fixed_indexing_filter(c, client_screen) then
                client_taskbar_idx = client_taskbar_idx + 1
                if (c == client) then
                    return client_taskbar_idx
                end
            end
        end

        return nil
    end
    -- }}}
    
    -- Returns total number of clients in the currently selected tag
    local function selected_tag_number_of_clients()
        local focused_screen = awful.screen.focused()
        local selected_tag = focused_screen.selected_tag
        local selected_tag_filter = function (c) return c.first_tag == selected_tag end
        local first_client_taskbar_idx = 1

        local number_of_clients = 0
        for c in awful.client.iterate(selected_tag_filter, first_client_taskbar_idx, focused_screen) 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 cllients 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
     
        local focused_client = awful.client.next(0) -- does not work

        if focused_client ~= nil then
            local focused_client_taskbar_idx = client_taskbar_idx(focused_client)
            if focused_client_taskbar_idx ~= nil then
                local relative_idx = taskbar_idx - focused_client_taskbar_idx
                awful.client.focus.byidx(relative_idx)
            end
        end
    end
    --- }}}

-- }}}

-- {{{ Key bindings
globalkeys = gears.table.join(

--- skip ---

    -- {{{ Mine: added/changes navigation for clients

--- skip ---

        -- {{{ added (browser-tab-like switching of clients):
        --     moving between windows with Mod4-FNN (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"}
        ),
        -- }}}

    -- }}}