Skip to content

A small C program providing the means to suspend GNU/Linux after a given time of user inactivity.

License

Notifications You must be signed in to change notification settings

perweij/autosleep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

autosleep

Status:Works
Location:https://github.com/perweij/autosleep

1 Description

This is a program that will execute a command after the user has been idle past a given time limit. The main purpose is to execute an OS suspend command, although any command can be supplied. Autosleep continues after each suspend cycle, making it suitable for starting just once in your ~/.xinitrc.

User activity is picked up from X11 and include mouse movement and keyboard activity. In contrast to other techniques, it does not depend on XScreenSaver.

Bigger desktop session packages provide this functionality, but for minimal setups with only X11 and dwm/evilwm/…, I haven’t found anything similar. A design goal is not to depend on runtimes that pull in loads of dependencies, and just be a simple C program.

I have only tried this on my laptops, running GNU/Linux Debian Jessie x86_64 and i686 - I have no idea if it needs tweaking for other OS versions. This probably only works in GNU/Linux.

2 Usage

autosleep timeout_seconds keyboard_input_nr suspend_cmd...

- timeout_seconds   - the number of seconds that defines inactivity
- keyboard_input_nr - your keyboard id number (check with xinput -list)
- suspend_cmd...    - the suspend command and arguments. Full path required, including to sudo.

I use this with the s2ram suspend command. I recommend adding the following to a new file in /etc/sudoers.d/ (and chmod 440), to make it executable without sudo password input:

yourusername ALL=(ALL) NOPASSWD: /usr/sbin/s2ram

2.1 Examples

Suspend the computer after one hour of inactivity on keyboard ID 9:

autosleep 3600 9 /usr/bin/sudo /usr/sbin/s2ram

3 Install

  • autoreconf --install
  • ./configure (--prefix...)
  • make all (install)

4 Todo

Right now it monitors the keyboard and the mouse movements. Monitoring mouse clicks as well would be a natural continuation.

5 Acknowledgements

For reading the mouse position, I found this useful: https://ubuntuforums.org/showthread.php?t=562087 (user: cwcentral).

For setting up event listening in X11, I found this useful: https://anonscm.debian.org/cgit/pkg-xorg/app/xinput.git/tree/src/test.c (Frederic Lepied, France. <[email protected]>).

6 History

6.1 2016-11-06: Version 0.1

A rough first version.

About

A small C program providing the means to suspend GNU/Linux after a given time of user inactivity.

Resources

License

Stars

Watchers

Forks

Packages

No packages published