Git Product home page Git Product logo

autosleep's Introduction

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.

autosleep's People

Contributors

perweij avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.