alols / xcape

Linux utility to configure modifier keys to act as other keys when pressed and released on their own.
GNU General Public License v3.0
2.1k stars 115 forks source link

Exits when run by systemd #57

Closed michalrus closed 7 years ago

michalrus commented 9 years ago

Because the xmodmap and xcape settings are not kept after suspend and resume, I’ve created a systemd service:

[Unit]
Description=space2ctrl
After=suspend.target

[Service]
User=m
Type=simple
ExecStart=/home/m/space2ctrl

[Install]
WantedBy=suspend.target

This /home/m/space2ctrl is a copy of the script from the README.md with sleep 5 added (even xmodmap wouldn’t work otherwise):

#!/bin/sh
sleep 5
export DISPLAY=":0"

# Kill instances of xcape that might be running.
killall -u m xcape

# Map an unused modifier’s keysym to the spacebar’s keycode and make it a
# control modifier. It needs to be an existing key so that emacs won't
# spazz out when you press it. Hyper_L is a good candidate.
spare_modifier="Hyper_L"
xmodmap -e "keycode 65 = $spare_modifier"
xmodmap -e "remove mod4 = $spare_modifier" # hyper_l is mod4 by default
xmodmap -e "add Control = $spare_modifier"

# Map space to an unused keycode (to keep it around for xcape to
# use).
xmodmap -e "keycode any = space"

# Finally use xcape to cause the space bar to generate a space when tapped.
xcape -e "${spare_modifier}=space"

With this service, after resuming, the xmodmap mods work (Space is Ctrl), but xcape exits immediately and no space can be typed.

When the above script, /home/m/space2ctrl, is run manually in a terminal, everything works as expected.

What could be the case?

etam commented 7 years ago

When using Type=simple, systemd expects the process to remain running in the foreground. So either change the last line of the script to "exec xcape -d ...", or try using Type=forking.

blueyed commented 7 years ago

FWIW: settings are being kept for me across suspend/resume, so there might be another issue.

michalrus commented 7 years ago

I propose we close this. :smiley_cat:

This happened a long time ago and I cannot really replicate settings not being kept across suspend/resume, so…

Edit: on second thought, this was probably related to me using GNOME back then.