Guest User

Untitled

a guest
Mar 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. //Compile with: gcc -o switchOff switchOff.c -lXss -lX11
  2. #include <X11/extensions/scrnsaver.h>
  3. #include <stdio.h>
  4.  
  5. int main(void) {
  6.  
  7. Display *dpy = NULL;
  8. while(!dpy) {
  9. dpy = XOpenDisplay(":0");
  10. usleep(1000 * 1000);
  11. }
  12.  
  13. int on = 1;
  14. while(1) {
  15. XScreenSaverInfo *info = XScreenSaverAllocInfo();
  16. XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
  17.  
  18. //Disable after 5 minutes
  19. if(info->idle >= 5 * 60 * 1000) {
  20. if(on) {
  21. printf("Off\n");
  22. system("/usr/bin/vcgencmd display_power 0");
  23. on = 0;
  24. }
  25. } else {
  26. if(!on) {
  27. printf("On\n");
  28. system("/usr/bin/vcgencmd display_power 1");
  29. on = 1;
  30. }
  31. }
  32.  
  33. usleep(100 * 1000);
  34. }
  35.  
  36. return(0);
  37. }
Add Comment
Please, Sign In to add comment