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 4 years ago
parent 0013ea3d73
commit b51644baca
  1. 81
      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,35 +124,55 @@ 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 (;;) {
if (ev.type == KeyPress) { FD_ZERO(&fdset);
XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, 0); FD_SET(xfd, &fdset);
if (lastkeysym == keysym) { if (state == StateSuspendPending)
lastkeyn++; selectresult = select(FD_SETSIZE, &fdset, NULL, NULL, &xeventtimeout);
} else { else
lastkeysym = keysym; selectresult = select(FD_SETSIZE, &fdset, NULL, NULL, NULL);
lastkeyn = 1;
} if (FD_ISSET(xfd, &fdset) && XPending(dpy)) {
XNextEvent(dpy, &ev);
if (ev.type == KeyPress) {
XLookupString(&ev.xkey, buf, sizeof(buf), &keysym, 0);
if (lastkeysym == keysym) {
lastkeyn++;
} else {
lastkeysym = keysym;
lastkeyn = 1;
}
if (lastkeyn < 3) if (lastkeyn < 3)
continue; continue;
lastkeyn = 0; lastkeyn = 0;
lastkeysym = NULL; lastkeysym = NULL;
switch (keysym) { switch (keysym) {
case XF86XK_AudioRaiseVolume: case XF86XK_AudioRaiseVolume:
state = StateSuspend; state = StateSuspend;
break; break;
case XF86XK_AudioLowerVolume: case XF86XK_AudioLowerVolume:
state = (state == StateNoInput ? StateNoInputNoScreen : StateNoInput); state = (state == StateNoInput ? StateNoInputNoScreen : StateNoInput);
break; break;
case XF86XK_PowerOff: case XF86XK_PowerOff:
state = StateDead; state = StateDead;
break; break;
}
syncstate();
} }
} else if (state == StateSuspendPending) {
state = StateSuspend;
syncstate(); syncstate();
} }
if (state == StateDead) break;
} }
} }

Loading…
Cancel
Save