I want to automatically dim keyboards light when its been inactive for some time. How can I detect inactivity time? I use archlinux, btw.

  • 1
    look at the design of a custom screen saver perhaps
    – jsotola
    Oct 29, 2020 at 2:43

3 Answers 3


On Debian-based systems, there's a xprintidle command in the xprintidle package (from https://github.com/g0hl1n/xprintidle/) that prints the idle time in milliseconds on stdout.

$ sleep 2; xprintidle

If you ltrace it, you'll see it uses XScreenSaverQueryExtension(), XScreenSaverQueryInfo() API like in other answers though also adds some workarounds to specific issues in corner cases with some servers.

  • does not work with Wayland unfortunately
    – xinthose
    Jun 21, 2022 at 19:59

Compiling and running this gets idle time in miliseconds

#include <X11/extensions/scrnsaver.h>
#include <stdio.h>

int main(void) {
    Display *dpy = XOpenDisplay(NULL);

    if (!dpy) {

    XScreenSaverInfo *info = XScreenSaverAllocInfo();
    XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
    printf("%u\n", info->idle);


This is also implemented in C (with Makefile) at https://github.com/mjml/xidle.

It will provide hours, minutes, seconds, and milliseconds of idle time for shell scripts, with units/denominations selected by optional switches.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .