slock-dpms-1.4.diff 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. diff --git a/config.def.h b/config.def.h
  2. index 9855e21..d01bd38 100644
  3. --- a/config.def.h
  4. +++ b/config.def.h
  5. @@ -10,3 +10,6 @@ static const char *colorname[NUMCOLS] = {
  6. /* treat a cleared input like a wrong password (color) */
  7. static const int failonclear = 1;
  8. +
  9. +/* time in seconds before the monitor shuts down */
  10. +static const int monitortime = 5;
  11. diff --git a/slock.c b/slock.c
  12. index d2f0886..f65a43b 100644
  13. --- a/slock.c
  14. +++ b/slock.c
  15. @@ -15,6 +15,7 @@
  16. #include <unistd.h>
  17. #include <sys/types.h>
  18. #include <X11/extensions/Xrandr.h>
  19. +#include <X11/extensions/dpms.h>
  20. #include <X11/keysym.h>
  21. #include <X11/Xlib.h>
  22. #include <X11/Xutil.h>
  23. @@ -306,6 +307,7 @@ main(int argc, char **argv) {
  24. const char *hash;
  25. Display *dpy;
  26. int s, nlocks, nscreens;
  27. + CARD16 standby, suspend, off;
  28. ARGBEGIN {
  29. case 'v':
  30. @@ -366,6 +368,20 @@ main(int argc, char **argv) {
  31. if (nlocks != nscreens)
  32. return 1;
  33. + /* DPMS magic to disable the monitor */
  34. + if (!DPMSCapable(dpy))
  35. + die("slock: DPMSCapable failed\n");
  36. + if (!DPMSEnable(dpy))
  37. + die("slock: DPMSEnable failed\n");
  38. + if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
  39. + die("slock: DPMSGetTimeouts failed\n");
  40. + if (!standby || !suspend || !off)
  41. + die("slock: at least one DPMS variable is zero\n");
  42. + if (!DPMSSetTimeouts(dpy, monitortime, monitortime, monitortime))
  43. + die("slock: DPMSSetTimeouts failed\n");
  44. +
  45. + XSync(dpy, 0);
  46. +
  47. /* run post-lock command */
  48. if (argc > 0) {
  49. switch (fork()) {
  50. @@ -383,5 +399,9 @@ main(int argc, char **argv) {
  51. /* everything is now blank. Wait for the correct password */
  52. readpw(dpy, &rr, locks, nscreens, hash);
  53. + /* reset DPMS values to inital ones */
  54. + DPMSSetTimeouts(dpy, standby, suspend, off);
  55. + XSync(dpy, 0);
  56. +
  57. return 0;
  58. }