jD91mZM2 / xidlehook

GitLab: https://gitlab.com/jD91mZM2/xidlehook
MIT License
382 stars 33 forks source link

Document how to hook xidlehook into systemd #55

Closed ethanpailes closed 3 years ago

ethanpailes commented 3 years ago

Not everyone is comfortable with authoring systemd service files or knows that you can define a user-level service file, so it would be nice to provide an example of how one can make a service file to configure xidlehook.

Here is my attempt at some documentation for this. This could be added as a section to the README (I would have opened a PR, but I don't use emacs).

Configuring via systemd

If you use a distribution that uses systemd for its init system, you may wish to use it to ensure that xidlehook is always started when you log in. You can do this at the level of an individual user by placing the following service file at $XDG_CONFIG_HOME/systemd/user/xidlehook.service (typically $HOME/.config/systemd/user/xidlehook.service):

[Unit]
Description=Automatic Screen Locker

[Service]
Type=simple
Environment=DISPLAY=:0
Environment=XIDLEHOOK_SOCK=%t/xidlehook.socket
ExecStart=/usr/bin/xidlehook --not-when-audio --not-when-fullscreen --socket $XIDLEHOOK_SOCK --timer 900 '/usr/bin/slock' ''

[Install]
WantedBy=multi-user.target

The above service file example locks the screen using the slock program after 15 minutes of inactivity, but you can edit it the xidlehook command to do anything you wish. We need to thread the DISPLAY environment variable down so that xidlehook knows how to open up a connection to the X server.

jD91mZM2 commented 3 years ago

Thanks!

EDIT: Sorry for messing up the Co-authored-by, placing it at the start is apparently incorrect (it gotta be at the end). Hope you're fine with it, I don't really feel like force pushing

ethanpailes commented 3 years ago

@jD91mZM2 no worries, I don't really care about getting co-authorship credit, just glad you accepted the suggestion!

Alpha-404 commented 2 months ago

Mine just crashes whenever i try to enable it:

× xidlehook.service - Automatic Screen Locker
     Loaded: loaded (/usr/lib/systemd/system/xidlehook.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Mon 2024-06-17 06:56:29 BST; 3s ago
   Duration: 6ms
    Process: 401509 ExecStart=/home/rajaa/.cargo/bin/xidlehook --not-when-audio --not-when-fullscreen --socket $XIDLEHOOK_SOCK --timer 600 /usr/bin/i3lock  (code=exited, status=1/FAILURE)
   Main PID: 401509 (code=exited, status=1/FAILURE)
        CPU: 5ms

Jun 17 06:56:29 notagamingpc systemd[1]: Started xidlehook.service - Automatic Screen Locker.
Jun 17 06:56:29 notagamingpc xidlehook[401509]: Authorization required, but no authorization protocol specified
Jun 17 06:56:29 notagamingpc xidlehook[401509]: Error: Connection
Jun 17 06:56:29 notagamingpc systemd[1]: xidlehook.service: Main process exited, code=exited, status=1/FAILURE
Jun 17 06:56:29 notagamingpc systemd[1]: xidlehook.service: Failed with result 'exit-code'.