Skip to content

Commit d00c772

Browse files
committed
keyboard: improve Toshy Kanata device recovery
1 parent 7f76b8e commit d00c772

9 files changed

Lines changed: 39 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ result
2727
!/packages/
2828
!/packages/**
2929
/packages/**/.DS_Store
30+
**/__pycache__/
31+
**/*.py[cod]
3032
node_modules/
3133
**/node_modules/
3234

ansible/files/scripts/host/keyboard/kanata.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ LockPersonality=true
2424
MemoryDenyWriteExecute=true
2525
NoNewPrivileges=true
2626
PrivateNetwork=true
27-
PrivateUsers=true
2827
ProcSubset=pid
2928
ProtectClock=true
3029
ProtectControlGroups=true

ansible/files/scripts/host/keyboard/toshy-kanata-chain.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config_path=$(run_host_user_bash "printf \"%s\n\" \"\${XDG_CONFIG_HOME:-\$HOME/.
2424
require_file "$toshy_automation"
2525
require_file "$toshy_slice_merger"
2626
require_file "$toshy_slice_dir/keymapper_api.py"
27+
require_file "$toshy_slice_dir/kbtype_override.py"
2728
require_file "$toshy_slice_dir/barebones_user_cfg.py"
2829

2930
ensure_dir "$toshy_root"

ansible/files/scripts/host/keyboard/toshy-kanata-check.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ fi
6060
check_system_service_active kanata-main.service
6161
check_user_service_active toshy-config.service
6262

63+
if systemctl cat kanata-main.service 2>/dev/null |
64+
grep -Fq 'PrivateUsers=true'; then
65+
fail "kanata-main.service uses PrivateUsers=true, which can hide input/uinput supplemental groups"
66+
else
67+
ok "kanata-main.service does not isolate host input/uinput groups with PrivateUsers"
68+
fi
69+
6370
if [[ -f $repo_kanata_config && -f $host_kanata_config ]]; then
6471
if cmp -s "$repo_kanata_config" "$host_kanata_config"; then
6572
ok "$host_kanata_config matches the dotfiles Kanata config"
@@ -87,8 +94,10 @@ fi
8794
toshy_config="${XDG_CONFIG_HOME:-$HOME/.config}/toshy/toshy_config.py"
8895
if [[ -f $toshy_config ]]; then
8996
if grep -Fq 'SLICE_MARK_START: keymapper_api' "$toshy_config" &&
97+
grep -Fq 'SLICE_MARK_START: kbtype_override' "$toshy_config" &&
9098
grep -Fq 'DOTFILES_TOSHY_ONLY_DEVICES' "$toshy_config" &&
91-
grep -Fq '/run/kanata-main/main' "$toshy_config"; then
99+
grep -Fq '/run/kanata-main/main' "$toshy_config" &&
100+
grep -Fq 'dotfiles-kanata-main' "$toshy_config"; then
92101
ok "Toshy config includes dotfiles Kanata device slice"
93102
else
94103
fail "Toshy config does not include the dotfiles Kanata device slice"
@@ -118,12 +127,23 @@ else
118127
fi
119128

120129
if systemctl --user cat toshy-kanata-device.path 2>/dev/null |
121-
grep -Fxq 'PathChanged=/run/kanata-main'; then
130+
grep -Fxq 'PathChanged=/run/kanata-main/main'; then
122131
ok "toshy-kanata-device.path watches the Kanata virtual device"
123132
else
124133
fail "toshy-kanata-device.path is missing the Kanata virtual device watch"
125134
fi
126135

136+
if systemctl --user cat toshy-kanata-device.service 2>/dev/null |
137+
grep -Fq 'reset-failed toshy-config.service' &&
138+
systemctl --user cat toshy-kanata-device.service 2>/dev/null |
139+
grep -Fq '[ -e /run/kanata-main/main ]' &&
140+
systemctl --user cat toshy-kanata-device.service 2>/dev/null |
141+
grep -Fq 'restart toshy-config.service'; then
142+
ok "toshy-kanata-device.service can recover a failed Toshy service"
143+
else
144+
fail "toshy-kanata-device.service does not recover failed Toshy starts"
145+
fi
146+
127147
if systemctl cat input-remapper.service >/dev/null 2>&1; then
128148
if [[ ${DOTFILES_KEEP_INPUT_REMAPPER:-0} == 1 ]]; then
129149
warn "input-remapper.service exists and keep flag is set; skipping conflict check"

ansible/files/scripts/host/keyboard/toshy-kanata-device.path

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Description=Watch Kanata virtual keyboard for Toshy
33
Documentation=https://github.com/RedBearAK/Toshy https://github.com/jtroo/kanata
44

55
[Path]
6-
PathChanged=/run/kanata-main
6+
PathChanged=/run/kanata-main/main
77
Unit=toshy-kanata-device.service
88

99
[Install]

ansible/files/scripts/host/keyboard/toshy-kanata-device.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Documentation=https://github.com/RedBearAK/Toshy https://github.com/jtroo/kanata
44

55
[Service]
66
Type=oneshot
7-
ExecStart=/bin/sh -c 'systemctl --user is-active --quiet toshy-config.service && systemctl --user restart toshy-config.service || true'
7+
ExecStart=/bin/sh -c 'systemctl --user reset-failed toshy-config.service || true; [ -e /run/kanata-main/main ] || exit 0; if systemctl --user is-active --quiet toshy-config.service || systemctl --user is-enabled --quiet toshy-config.service; then systemctl --user restart toshy-config.service; fi'

ansible/files/scripts/host/keyboard/toshy-merge.host.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ if [[ ! -d $slice_dir ]]; then
2020
printf "%s\n" "toshy-kanata-chain: Toshy slice directory was not found at $slice_dir" >&2
2121
exit 1
2222
fi
23+
if [[ ! -f $dropin_source ]]; then
24+
printf "%s\n" "toshy-kanata-chain: Toshy Kanata drop-in was not found at $dropin_source" >&2
25+
exit 1
26+
fi
2327
if [[ ! -f $path_unit_source ]]; then
2428
printf "%s\n" "toshy-kanata-chain: Toshy Kanata path unit was not found at $path_unit_source" >&2
2529
exit 1
@@ -35,8 +39,10 @@ service_dropin_dir="${XDG_CONFIG_HOME:-$HOME/.config}/systemd/user/toshy-config.
3539

3640
ensure_dirs "$config_dir" "$service_dir" "$service_dropin_dir"
3741
python3 "$slice_merger" "$config_path" "$slice_dir"
42+
python3 -m py_compile "$config_path"
3843
install_file_if_changed "$dropin_source" "$service_dropin_dir/10-dotfiles.conf"
3944
install_file_if_changed "$path_unit_source" "$service_dir/toshy-kanata-device.path"
4045
install_file_if_changed "$refresh_unit_source" "$service_dir/toshy-kanata-device.service"
4146
systemctl --user daemon-reload || true
4247
systemctl --user enable --now toshy-kanata-device.path || true
48+
systemctl --user start toshy-kanata-device.service || true

dotfiles/dot_config/kanata/kanata.kbd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(defcfg
22
process-unmapped-keys yes
33
log-layer-changes yes
4+
linux-output-device-name "dotfiles-kanata-main"
45
linux-dev-names-include (
56
"ITE Tech. Inc. ITE Device(8910) Keyboard"
67
"LIFT Mouse"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
keyboards_UserCustom_dct = {
2+
"kanata": "Windows",
3+
"kanata output": "Windows",
4+
"dotfiles-kanata-main": "Windows",
5+
}

0 commit comments

Comments
 (0)