From b30fb7d4fb18f4fbfd31868c1453796469f03927 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 27 Oct 2015 15:56:45 -0400 Subject: [PATCH] Added DPMS support --- .gitignore | 2 ++ config.mk | 2 +- slock.c | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 295c11b..a5609d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ twilio.* imgur.* +slock +slock.o diff --git a/config.mk b/config.mk index e566abe..46d2f74 100644 --- a/config.mk +++ b/config.mk @@ -14,7 +14,7 @@ INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DCOLOR1=\"black\" -DCOLOR2=\"\#005577\" +CPPFLAGS = -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H -DCOLOR1=\"black\" -DCOLOR2=\"\#555555\" CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS} LDFLAGS = -s ${LIBS} diff --git a/slock.c b/slock.c index a25c592..f335b88 100644 --- a/slock.c +++ b/slock.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #if HAVE_BSD_AUTH @@ -28,15 +29,19 @@ #define CMD_LENGTH (500 * sizeof(char)) -#define POWEROFF 1 -#define TWILIO_SEND 1 -#define WEBCAM_SHOT 1 +#define POWEROFF 0 +#define TWILIO_SEND 0 +#define WEBCAM_SHOT 0 #define IMGUR_UPLOAD 0 -#define PLAY_AUDIO 1 -#define TRANSPARENT 1 +#define PLAY_AUDIO 0 +#define TRANSPARENT 0 +#if IMGUR_UPLOAD #include "imgur.h" +#endif +#if TWILIO_SEND #include "twilio.h" +#endif typedef struct { char *link; @@ -172,10 +177,8 @@ poweroff(void) { // Needs sudo privileges - alter your /etc/sudoers file: // systemd: [username] [hostname] =NOPASSWD: /usr/bin/systemctl poweroff // sysvinit: [username] [hostname] =NOPASSWD: /usr/bin/shutdown -h now - char *args[] = { "sudo", "systemctl", "poweroff", NULL }; - char *args_legacy[] = { "sudo", "shutdown", "-h", "now", NULL }; + char *args[] = { "sudo", "shutdown", "-h", "now", NULL }; execvp(args[0], args); - execvp(args_legacy[0], args_legacy); fprintf(stderr, "Error: cannot shutdown. Check your /etc/sudoers file.\n"); // Needs sudo privileges - alter your /etc/sudoers file: // [username] [hostname] =NOPASSWD: /usr/bin/tee /proc/sys/kernel/sysrq,/usr/bin/tee /proc/sysrq-trigger @@ -418,6 +421,10 @@ readpw(Display *dpy, const char *pws) * utility. This way the user can easily set a customized DPMS * timeout. */ while(running && !XNextEvent(dpy, &ev)) { + if(len == 0 && DPMSCapable(dpy)) { + DPMSEnable(dpy); + DPMSForceLevel(dpy, DPMSModeOff); + } if(ev.type == KeyPress) { buf[0] = 0; num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);