Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions bin/omarchy-menu-keybindings
Original file line number Diff line number Diff line change
Expand Up @@ -243,26 +243,25 @@ LUA
)
}

# Hyprland reports modifiers as a bitmask, so derive the text from the bits
# rather than enumerating combinations. Enumerating only covered SHIFT, CTRL,
# ALT and SUPER, which left Mod2, Mod3 and Mod5 falling through to a raw number
# (a Caps Lock remapped with `caps:hyper` binds on Mod3 and rendered as "32").
modmask_to_text() {
case "$1" in
0) printf '' ;;
1) printf 'SHIFT' ;;
4) printf 'CTRL' ;;
5) printf 'SHIFT CTRL' ;;
8) printf 'ALT' ;;
9) printf 'SHIFT ALT' ;;
12) printf 'CTRL ALT' ;;
13) printf 'SHIFT CTRL ALT' ;;
64) printf 'SUPER' ;;
65) printf 'SUPER SHIFT' ;;
68) printf 'SUPER CTRL' ;;
69) printf 'SUPER SHIFT CTRL' ;;
72) printf 'SUPER ALT' ;;
73) printf 'SUPER SHIFT ALT' ;;
76) printf 'SUPER CTRL ALT' ;;
77) printf 'SUPER SHIFT CTRL ALT' ;;
*) printf '%s' "$1" ;;
esac
local modmask="$1"
local -a parts=()
local modifier bit name

for modifier in '64:SUPER' '1:SHIFT' '2:CAPS' '4:CTRL' '8:ALT' '16:MOD2' '32:MOD3' '128:MOD5'; do
bit="${modifier%%:*}"
name="${modifier#*:}"

if (( modmask & bit )); then
parts+=("$name")
fi
done

printf '%s' "${parts[*]}"
}

# Fetch dynamic keybindings from Hyprland.
Expand Down Expand Up @@ -533,7 +532,7 @@ output_binding_records_uncached() {

keybindings_cache_key() {
{
printf 'v14\n'
printf 'v15\n'
hyprctl devices 2>/dev/null | grep -F 'active keymap:'
hyprctl binds 2>/dev/null
} | sha256sum | awk '{ print $1 }'
Expand Down
24 changes: 24 additions & 0 deletions test/shell.d/keybindings-menu-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,27 @@ keybindings >/dev/null
grep -qP '→ Terminal\texec\tomarchy-launch-terminal$' "$tmpdir"/cache/omarchy/keybindings-*.records ||
fail "picking the terminal bind from the menu launches a terminal" "$(cat "$tmpdir"/cache/omarchy/keybindings-*.records)"
pass "picking the terminal bind from the menu launches a terminal"

# Hyprland can bind any of the eight modifier bits, but the menu used to
# enumerate only SHIFT/CTRL/ALT/SUPER combinations. A Caps Lock remapped with
# `caps:hyper` binds on Mod3, which fell through and rendered as "32 + K".
eval "$(sed -n '/^modmask_to_text()/,/^}/p' "$ROOT/bin/omarchy-menu-keybindings")"

[[ $(modmask_to_text 32) == "MOD3" ]] ||
fail "a Mod3 bind renders its modifier by name" "$(modmask_to_text 32)"
[[ $(modmask_to_text 16) == "MOD2" ]] ||
fail "a Mod2 bind renders its modifier by name" "$(modmask_to_text 16)"
[[ $(modmask_to_text 128) == "MOD5" ]] ||
fail "a Mod5 bind renders its modifier by name" "$(modmask_to_text 128)"
[[ $(modmask_to_text 33) == "SHIFT MOD3" ]] ||
fail "a Mod3 bind combines with other modifiers" "$(modmask_to_text 33)"
[[ $(modmask_to_text 66) == "SUPER CAPS" ]] ||
fail "a Caps bind keeps its modifier rather than rendering as the bare key" "$(modmask_to_text 66)"
Comment on lines +274 to +285

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 New masks lack menu coverage The new assertions check modmask_to_text by itself, but none pass a Mod2, Mod3, Mod5, or Caps bind through the stubbed hyprctl and keybindings --print path already used in this test. A full-menu case for MOD3 + K would catch parsing or record-formatting regressions that these assertions miss.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

pass "every modifier Hyprland can bind renders by name"

# The masks the menu already rendered keep rendering exactly as before.
[[ $(modmask_to_text 0) == "" ]] ||
fail "an unmodified key renders no modifier text" "$(modmask_to_text 0)"
[[ $(modmask_to_text 77) == "SUPER SHIFT CTRL ALT" ]] ||
fail "a fully modified chord keeps its established order" "$(modmask_to_text 77)"
pass "previously rendered modifier masks are unchanged"