Added DPMS support
This commit is contained in:
parent
8a3c5c91f4
commit
b30fb7d4fb
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,4 @@
|
|||||||
twilio.*
|
twilio.*
|
||||||
imgur.*
|
imgur.*
|
||||||
|
slock
|
||||||
|
slock.o
|
||||||
|
@ -14,7 +14,7 @@ INCS = -I. -I/usr/include -I${X11INC}
|
|||||||
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
|
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
|
||||||
|
|
||||||
# flags
|
# 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}
|
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||||
LDFLAGS = -s ${LIBS}
|
LDFLAGS = -s ${LIBS}
|
||||||
|
|
||||||
|
23
slock.c
23
slock.c
@ -19,6 +19,7 @@
|
|||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/extensions/dpms.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
|
|
||||||
#if HAVE_BSD_AUTH
|
#if HAVE_BSD_AUTH
|
||||||
@ -28,15 +29,19 @@
|
|||||||
|
|
||||||
#define CMD_LENGTH (500 * sizeof(char))
|
#define CMD_LENGTH (500 * sizeof(char))
|
||||||
|
|
||||||
#define POWEROFF 1
|
#define POWEROFF 0
|
||||||
#define TWILIO_SEND 1
|
#define TWILIO_SEND 0
|
||||||
#define WEBCAM_SHOT 1
|
#define WEBCAM_SHOT 0
|
||||||
#define IMGUR_UPLOAD 0
|
#define IMGUR_UPLOAD 0
|
||||||
#define PLAY_AUDIO 1
|
#define PLAY_AUDIO 0
|
||||||
#define TRANSPARENT 1
|
#define TRANSPARENT 0
|
||||||
|
|
||||||
|
#if IMGUR_UPLOAD
|
||||||
#include "imgur.h"
|
#include "imgur.h"
|
||||||
|
#endif
|
||||||
|
#if TWILIO_SEND
|
||||||
#include "twilio.h"
|
#include "twilio.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *link;
|
char *link;
|
||||||
@ -172,10 +177,8 @@ poweroff(void) {
|
|||||||
// Needs sudo privileges - alter your /etc/sudoers file:
|
// Needs sudo privileges - alter your /etc/sudoers file:
|
||||||
// systemd: [username] [hostname] =NOPASSWD: /usr/bin/systemctl poweroff
|
// systemd: [username] [hostname] =NOPASSWD: /usr/bin/systemctl poweroff
|
||||||
// sysvinit: [username] [hostname] =NOPASSWD: /usr/bin/shutdown -h now
|
// sysvinit: [username] [hostname] =NOPASSWD: /usr/bin/shutdown -h now
|
||||||
char *args[] = { "sudo", "systemctl", "poweroff", NULL };
|
char *args[] = { "sudo", "shutdown", "-h", "now", NULL };
|
||||||
char *args_legacy[] = { "sudo", "shutdown", "-h", "now", NULL };
|
|
||||||
execvp(args[0], args);
|
execvp(args[0], args);
|
||||||
execvp(args_legacy[0], args_legacy);
|
|
||||||
fprintf(stderr, "Error: cannot shutdown. Check your /etc/sudoers file.\n");
|
fprintf(stderr, "Error: cannot shutdown. Check your /etc/sudoers file.\n");
|
||||||
// Needs sudo privileges - alter your /etc/sudoers file:
|
// Needs sudo privileges - alter your /etc/sudoers file:
|
||||||
// [username] [hostname] =NOPASSWD: /usr/bin/tee /proc/sys/kernel/sysrq,/usr/bin/tee /proc/sysrq-trigger
|
// [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
|
* utility. This way the user can easily set a customized DPMS
|
||||||
* timeout. */
|
* timeout. */
|
||||||
while(running && !XNextEvent(dpy, &ev)) {
|
while(running && !XNextEvent(dpy, &ev)) {
|
||||||
|
if(len == 0 && DPMSCapable(dpy)) {
|
||||||
|
DPMSEnable(dpy);
|
||||||
|
DPMSForceLevel(dpy, DPMSModeOff);
|
||||||
|
}
|
||||||
if(ev.type == KeyPress) {
|
if(ev.type == KeyPress) {
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
|
num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user