screenlock - Implement StateSuspendPending so exiting CRUST requires 3 clicks

If you don't triple click after exiting deep sleep after 10s, use select() with
timeout to kick back into deep sleep.
master
Miles Alan 5 years ago
parent 0013ea3d73
commit b51644baca
  1. 35
      programs/sxmo_screenlock.c

@ -8,10 +8,11 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
enum State { enum State {
StateNoInput, StateNoInput, // Screen on / input lock
StateNoInputNoScreen, StateNoInputNoScreen, // Screen off / input lock
StateSuspend, StateSuspend, // Deep sleep
StateDead StateSuspendPending, // Suspend 'woken up', must leave state in <10s, or kicks to StateSuspend
StateDead // Exit the appliation
}; };
enum Color { enum Color {
@ -67,12 +68,12 @@ syncstate()
setpineled(Red); setpineled(Red);
configuresuspendsettingsandwakeupsources(); configuresuspendsettingsandwakeupsources();
writefile(powerstatefile, "mem"); writefile(powerstatefile, "mem");
state = StateNoInput; state = StateSuspendPending;
syncstate(); syncstate();
} else if (state == StateNoInput) { } else if (state == StateNoInput) {
setpineled(Blue); setpineled(Blue);
writefile(brightnessfile, oldbrightness); writefile(brightnessfile, oldbrightness);
} else if (state == StateNoInputNoScreen) { } else if (state == StateNoInputNoScreen || state == StateSuspendPending) {
setpineled(Purple); setpineled(Purple);
writefile(brightnessfile, "0"); writefile(brightnessfile, "0");
} else if (state == StateDead) { } else if (state == StateDead) {
@ -123,8 +124,22 @@ readinputloop(Display *dpy, int screen) {
KeySym keysym; KeySym keysym;
XEvent ev; XEvent ev;
char buf[32]; char buf[32];
fd_set fdset;
int xfd;
int selectresult;
struct timeval xeventtimeout = {10, 0};
xfd = ConnectionNumber(dpy);
while (state != StateDead && !XNextEvent(dpy, &ev)) { for (;;) {
FD_ZERO(&fdset);
FD_SET(xfd, &fdset);
if (state == StateSuspendPending)
selectresult = select(FD_SETSIZE, &fdset, NULL, NULL, &xeventtimeout);
else
selectresult = select(FD_SETSIZE, &fdset, NULL, NULL, NULL);
if (FD_ISSET(xfd, &fdset) && XPending(dpy)) {
XNextEvent(dpy, &ev);
if (ev.type == KeyPress) { if (ev.type == KeyPress) {
XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, 0); XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, 0);
if (lastkeysym == keysym) { if (lastkeysym == keysym) {
@ -152,6 +167,12 @@ readinputloop(Display *dpy, int screen) {
} }
syncstate(); syncstate();
} }
} else if (state == StateSuspendPending) {
state = StateSuspend;
syncstate();
}
if (state == StateDead) break;
} }
} }

Loading…
Cancel
Save