jtroo / kanata

Improve keyboard comfort and usability with advanced customization
GNU Lesser General Public License v3.0
3.18k stars 130 forks source link

Bug: unable to setup Kanata with systemd #1151

Closed ndrew222 closed 2 months ago

ndrew222 commented 4 months ago

Requirements

Describe the bug

kanata fails to run when summoned using systemctl --user start kanata.service, but runs properly when invoked using sudo /usr/bin/sh -c "exec $(which kanata) --cfg $HOME/.config/kanata/config.kbd"

Relevant kanata config

kanata.kbd

(defsrc
  caps
)

(defalias
  escctrl (tap-hold 200 200 esc lctl)
)

(deflayer base
  @escctrl
)

kanata.service

[Unit]
Description=Kanata keyboard remapper
Documentation=https://github.com/jtroo/kanata

[Service]
Environment=PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:${HOME}/.local/bin
Environment=DISPLAY=:0
Type=simple
ExecStart=/usr/bin/sh -c 'exec $(which kanata) --cfg $HOME/.config/kanata/config.kbd'
Restart=no

[Install]
WantedBy=default.target

To Reproduce

  1. mkdir -p ~/.config/systemd/user && cd ~/.config/systemd/user
  2. nvim kanata.service and paste above text
  3. systemctl --user daemon-reload
  4. systemctl --user start kanata.service
  5. systemctl --user status kanata.service
  6. cry because it doesn't work

Expected behavior

kanata should run properly and allow me to tap caps for esc and hold for lctl

Kanata version

kanata 1.6.1

Debug logs

systemctl --user status kanata.service

× kanata.service - Kanata keyboard remapper
     Loaded: loaded (/home/andrew/.config/systemd/user/kanata.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Wed 2024-07-24 08:58:32 +08; 9min ago
   Duration: 4ms
       Docs: https://github.com/jtroo/kanata
   Main PID: 86554 (code=exited, status=127)
        CPU: 4ms

Jul 24 08:58:32 computer systemd[1505]: Started kanata.service - Kanata keyboard remapper.
Jul 24 08:58:32 computer systemd[1505]: kanata.service: Main process exited, code=exited, status=127/n/a
Jul 24 08:58:32 computer systemd[1505]: kanata.service: Failed with result 'exit-code'.

sh -c 'exec $(which kanata) --cfg $HOME/.config/kanata/config.kbd'

2024-07-24T09:10:35.574683995+08:00 [INFO] kanata v1.6.1 starting
2024-07-24T09:10:35.574963978+08:00 [INFO] process unmapped keys: false
2024-07-24T09:10:35.57501947+08:00 [INFO] NOTE: kanata was compiled to never allow cmd
2024-07-24T09:10:35.575241253+08:00 [INFO] config file is valid
2024-07-24T09:10:35.576574827+08:00 [INFO] Created device "/dev/input/event20"
2024-07-24T09:10:35.576688207+08:00 [INFO] Sleeping for 2s. Please release all keys and don't press additional ones. Run kanata with --help to see how understand more and how to disable this sleep.
2024-07-24T09:10:37.576847008+08:00 [INFO] entering the processing loop
2024-07-24T09:10:37.577105028+08:00 [INFO] entering the event loop
2024-07-24T09:10:37.577152033+08:00 [INFO] looking for devices in /dev/input
2024-07-24T09:10:37.577361495+08:00 [INFO] Init: catching only releases and sending immediately
2024-07-24T09:10:37.577726476+08:00 [ERROR] failed to open keyboard device(s): No keyboard devices were found

Press enter to exit
2024-07-24T09:10:38.147566257+08:00 [INFO] Starting kanata proper
2024-07-24T09:10:38.147612502+08:00 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.
2024-07-24T09:10:38.147634912+08:00 [ERROR] channel disconnected

Error: failed to open keyboard device(s): No keyboard devices were found

$ sudo sh -c "exec $(which kanata) --cfg $HOME/.config/kanata/config.kbd"

2024-07-24T09:17:01.703142851+08:00 [INFO] kanata v1.6.1 starting
2024-07-24T09:17:01.703299777+08:00 [INFO] process unmapped keys: false
2024-07-24T09:17:01.703324228+08:00 [INFO] NOTE: kanata was compiled to never allow cmd
2024-07-24T09:17:01.703422298+08:00 [INFO] config file is valid
2024-07-24T09:17:01.704420726+08:00 [INFO] Created device "/dev/input/event20"
2024-07-24T09:17:01.704485215+08:00 [INFO] Sleeping for 2s. Please release all keys and don't press additional ones. Run kanata with --help to see how understand more and how to disable this sleep.
2024-07-24T09:17:03.704670625+08:00 [INFO] entering the processing loop
2024-07-24T09:17:03.704890689+08:00 [INFO] entering the event loop
2024-07-24T09:17:03.704929587+08:00 [INFO] looking for devices in /dev/input
2024-07-24T09:17:03.705197246+08:00 [INFO] Init: catching only releases and sending immediately
2024-07-24T09:17:04.202866038+08:00 [INFO] registering /dev/input/event12: "ELAN0511:00 04F3:3041 Mouse"
2024-07-24T09:17:04.242581509+08:00 [INFO] registering /dev/input/event0: "AT Translated Set 2 keyboard"
2024-07-24T09:17:04.312659007+08:00 [INFO] Starting kanata proper
2024-07-24T09:17:04.312711405+08:00 [INFO] You may forcefully exit kanata by pressing lctl+spc+esc at any time. These keys refer to defsrc input, meaning BEFORE kanata remaps keys.

Operating system

Linux (Debian 12)

Additional context

I have checked the discussion #130 but does not seem to help

DarkKronicle commented 4 months ago

Did you follow the steps here? Specifically adding the udev rule and adding input and uinput to your user's groups? (Also make sure to restart)

ndrew222 commented 2 months ago

fixed it by changing kanata.service to

[Unit]
Description=Kanata keyboard remapper
Documentation=https://github.com/jtroo/kanata

[Service]
Environment=PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:${HOME}/.local/bin
Environment=DISPLAY=:0
Type=simple
ExecStart=/usr/bin/sh -c "exec $HOME/.local/bin/kanata --cfg $HOME/.config/kanata/config.kbd"
Restart=no

[Install]
WantedBy=default.target