Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Compile with: gcc -o switchOff switchOff.c -lXss -lX11
- #include <X11/extensions/scrnsaver.h>
- #include <stdio.h>
- int main(void) {
- Display *dpy = NULL;
- while(!dpy) {
- dpy = XOpenDisplay(":0");
- usleep(1000 * 1000);
- }
- int on = 1;
- while(1) {
- XScreenSaverInfo *info = XScreenSaverAllocInfo();
- XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
- //Disable after 5 minutes
- if(info->idle >= 5 * 60 * 1000) {
- if(on) {
- printf("Off\n");
- system("/usr/bin/vcgencmd display_power 0");
- on = 0;
- }
- } else {
- if(!on) {
- printf("On\n");
- system("/usr/bin/vcgencmd display_power 1");
- on = 1;
- }
- }
- usleep(100 * 1000);
- }
- return(0);
- }
Add Comment
Please, Sign In to add comment