handy: register GNOME dictation keybindings via tracked script
GNOME holds the dictation hotkeys because an application cannot grab a global shortcut under Wayland, so they live in dconf where stow cannot reach them. The script re-registers them on a new machine. Co-Authored-By: claude-opus-5
This commit is contained in:
1 parent
503cb95132
commit
f3a16fa2e7
2 files changed
+94
No files matched your search
@@ -19,3 +19,14 @@ paru -S google-java-format java-language-server-git
|
|||||||
```
|
```
|
||||||
sudo systemctl start reflector
|
sudo systemctl start reflector
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## GNOME keybindings
|
||||||
|
|
||||||
|
Shortcuts registered with GNOME live in dconf rather than in a file, so `stow`
|
||||||
|
cannot link them. Run this once per machine to register Handy's dictation
|
||||||
|
shortcuts (<kbd>Ctrl</kbd>+<kbd>Super</kbd>+<kbd>Space</kbd> to toggle,
|
||||||
|
<kbd>Ctrl</kbd>+<kbd>Super</kbd>+<kbd>Backspace</kbd> to cancel):
|
||||||
|
|
||||||
|
```
|
||||||
|
handy-sync-keybindings
|
||||||
|
```
|
||||||
Executable
+83
@@ -0,0 +1,83 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Registers Handy's dictation shortcuts as GNOME custom keybindings.
|
||||||
|
#
|
||||||
|
# Under Wayland an application cannot grab a global hotkey, so Handy's own
|
||||||
|
# shortcut setting never fires. GNOME holds the keys instead and runs Handy's
|
||||||
|
# CLI, which signals the already-running instance.
|
||||||
|
#
|
||||||
|
# Entries are matched by name, so re-running updates them in place. Slots are
|
||||||
|
# allocated around everything already present in dconf, including entries other
|
||||||
|
# applications have orphaned by dropping them from the list but leaving their
|
||||||
|
# keys behind.
|
||||||
|
|
||||||
|
set -u
|
||||||
|
|
||||||
|
schema=org.gnome.settings-daemon.plugins.media-keys
|
||||||
|
entry_schema=$schema.custom-keybinding
|
||||||
|
dconf_dir=/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings
|
||||||
|
|
||||||
|
# name|command|binding
|
||||||
|
shortcuts=(
|
||||||
|
'Handy: toggle dictation|/usr/bin/handy --toggle-transcription|<Control><Super>space'
|
||||||
|
'Handy: cancel dictation|/usr/bin/handy --cancel|<Control><Super>BackSpace'
|
||||||
|
)
|
||||||
|
|
||||||
|
if ! command -v gsettings >/dev/null; then
|
||||||
|
printf >&2 '%s\n' 'gsettings not found; these shortcuts require GNOME.'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Strips the single quotes GVariant wraps around string values.
|
||||||
|
unquote() {
|
||||||
|
local value=$1
|
||||||
|
value=${value#\'}
|
||||||
|
value=${value%\'}
|
||||||
|
printf '%s' "$value"
|
||||||
|
}
|
||||||
|
|
||||||
|
readarray -t paths < <(gsettings get "$schema" custom-keybindings | grep -o "'[^']*'" | tr -d "'")
|
||||||
|
occupied=$(dconf list "$dconf_dir/" 2>/dev/null)
|
||||||
|
|
||||||
|
next_free_slot() {
|
||||||
|
local index=0 candidate
|
||||||
|
while true; do
|
||||||
|
candidate="$dconf_dir/custom$index/"
|
||||||
|
if [[ " ${paths[*]} " != *" $candidate "* ]] && ! grep -qx "custom$index/" <<<"$occupied"; then
|
||||||
|
printf '%s' "$candidate"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
((index++))
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
listed=false
|
||||||
|
|
||||||
|
for shortcut in "${shortcuts[@]}"; do
|
||||||
|
IFS='|' read -r name command binding <<<"$shortcut"
|
||||||
|
|
||||||
|
path=
|
||||||
|
for candidate in "${paths[@]}"; do
|
||||||
|
if [[ $(unquote "$(gsettings get "$entry_schema:$candidate" name)") == "$name" ]]; then
|
||||||
|
path=$candidate
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -z $path ]]; then
|
||||||
|
path=$(next_free_slot)
|
||||||
|
paths+=("$path")
|
||||||
|
listed=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
gsettings set "$entry_schema:$path" name "$name"
|
||||||
|
gsettings set "$entry_schema:$path" command "$command"
|
||||||
|
gsettings set "$entry_schema:$path" binding "$binding"
|
||||||
|
|
||||||
|
printf '%s -> %s (%s)\n' "$binding" "$command" "${path%/}"
|
||||||
|
done
|
||||||
|
|
||||||
|
if "$listed"; then
|
||||||
|
list=$(printf "'%s'," "${paths[@]}")
|
||||||
|
gsettings set "$schema" custom-keybindings "[${list%,}]"
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user