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

-- To use special sortingm for hotkey modifiers, add the following line
-- your rc.lua file, after `local hotkeys_popup = require("awful.hotkeys_popup")`:
--
-- hotkeys_popup.widget.use_special_hotkey_mod_sort = true
--
-- And optionally, to customize the order, add, for example:
--
-- hotkeys_popup.widget.special_hotkey_mod_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.


--- Use special order for hotkey modifier sorting
-- @tfield boolean use_special_hotkey_mod_sort
-- @param boolean
widget.use_special_hotkey_mod_sort = false

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

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



local function special_hotkey_join_plus_sort(modifiers)
if #modifiers<1 then return "none" end
table.sort(modifiers, function(a,b)
return widget.special_hotkey_mod_order[a] < widget.special_hotkey_mod_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 @@ -316,6 +365,9 @@ function widget.new(args)
merge_duplicates = (
args.merge_duplicates == nil
) and widget.merge_duplicates or args.merge_duplicates,
use_special_hotkey_mod_sort = (
args.use_special_hotkey_mod_sort == nil
) and widget.use_special_hotkey_mod_sort or args.use_special_hotkey_mod_sort,
group_rules = args.group_rules or gtable.clone(widget.group_rules),
-- For every key in every `awful.key` binding, the first non-nil result
-- in this lists is chosen as a human-readable name:
Expand All @@ -326,6 +378,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,
special_mod_order = args.special_hotkey_mod_order or widget.special_hotkey_mod_order,
_additional_hotkeys = {},
_cached_wiboxes = {},
_cached_awful_keys = {},
Expand Down Expand Up @@ -394,7 +447,13 @@ 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 = {}

if widget.use_special_hotkey_mod_sort then
joined_mods = special_hotkey_join_plus_sort(readable_mods)
else
joined_mods = join_plus_sort(readable_mods)
end

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