Skip to content
42 changes: 41 additions & 1 deletion lib/awful/hotkeys_popup/widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,50 @@ local widget = {
group_rules = {},
}

-- To use change the sorting order for hotkey modifiers, add the following line
-- your rc.lua file, after `local hotkeys_popup = require("awful.hotkeys_popup")`:
--
-- hotkeys_popup.widget.modifier_sort_order = {
-- Shift = 1,
-- Ctrl = 2,
-- Super = 3,
-- Alt = 4,
-- }
Copy link
Member

@actionless actionless Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it would be better to have one parameter for this same thing (sorting), instead of two:

  • hotkeys_popup.widget.use_special_hotkey_mod_sort
  • hotkeys_popup.widget.special_hotkey_mod_order

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks much better now 👌😸

--
-- Setting 2 or more modifiers to the same number will cause their relative
-- sorting order to be undefined.

--- Modifier sort order.
-- Defines the order in which modifier keys are displayed.
--
-- @tfield table awful.hotkeys_popup.widget.modifier_sort_order
--
-- @tfield[opt=1] int Alt
-- @tfield[opt=2] int Ctrl
-- @tfield[opt=3] int Shift
-- @tfield[opt=4] int Super
widget.modifier_sort_order = {
Alt = 1,
Ctrl = 2,
Shift = 3,
Super = 4,
}

--- Don't show hotkeys without descriptions.
-- @tfield boolean widget.hide_without_description
-- @param boolean
widget.hide_without_description = true



local function modifier_join_plus_sort(modifiers)
if #modifiers<1 then return "none" end
table.sort(modifiers, function(a,b)
return widget.modifier_sort_order[a] < widget.modifier_sort_order[b]
end)
return table.concat(modifiers, '+')
end

--- Merge hotkey records into one if they have the same modifiers and
-- description. Records with five or more keys will abbreviate them.
--
Expand Down Expand Up @@ -326,6 +365,7 @@ function widget.new(args)
-- be presented to the user as-is. (This is useful for cheatsheets for
-- external programs.)
labels = args.labels or widget.labels,
modifier_order = args.modifier_order or widget.modifier_order,
_additional_hotkeys = {},
_cached_wiboxes = {},
_cached_awful_keys = {},
Expand Down Expand Up @@ -394,7 +434,7 @@ function widget.new(args)
for _, mod in ipairs(data.mod) do
table.insert(readable_mods, self.labels[mod] or mod)
end
local joined_mods = join_plus_sort(readable_mods)
local joined_mods = modifier_join_plus_sort(readable_mods)

local group = data.group or "none"
self._group_list[group] = true
Expand Down
Loading