/* gcc -o getIdleTime getIdleTime.c -lXss */
#include <X11/extensions/scrnsaver.h>
#include <stdio.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if (!dpy) {
return(1);
}
XScreenSaverInfo *info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
printf("%u", info->idle);
return(0);
}
Add idle check:
Example: link to stackoverflow
On Windows, GetLastInputInfo, see this answer
On OS X, NSWorkspaceWillSleepNotification and NSWorkspaceDidWakeNotification, see this answer
On X11, it is the screensaver API: