Adding a wrapper around sxmo_screenlock, with lock/unlock hooks. Allow setting a target state for sxmo_screenlock, and cleanup on sigterm. Added lock/suspend options to the power menu.

Should be applied after my prior patches from today.
master
Maarten van Gompel 4 years ago committed by Miles Alan
parent b513949b95
commit 113f756eb1
  1. 40
      programs/sxmo_screenlock.c
  2. 3
      scripts/core/sxmo_appmenu.sh
  3. 10
      scripts/core/sxmo_lock.sh

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/XF86keysym.h> #include <X11/XF86keysym.h>
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
@ -110,6 +111,14 @@ die(const char *err, ...)
exit(1); exit(1);
} }
void
sigterm()
{
state = StateDead;
syncstate();
exit(0);
}
int int
getoldbrightness() { getoldbrightness() {
char * buffer = 0; char * buffer = 0;
@ -289,9 +298,32 @@ writefile(char *filepath, char *str)
} }
} }
void usage() {
fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend]\n");
}
int int
main(int argc, char **argv) { main(int argc, char **argv) {
int screen; int screen;
int i;
enum State target = StateNoInput;
signal(SIGTERM, sigterm);
//parse command line arguments
for (i = 1; i < argc; i++) {
if(!strcmp(argv[i], "-h")) {
usage();
return 0;
} else if(!strcmp(argv[i], "--screen-off")) {
target = StateNoInputNoScreen;
} else if(!strcmp(argv[i], "--suspend")) {
target = StateSuspend;
} else {
fprintf(stderr, "Invalid argument: %s\n", argv[i]);
return 2;
}
}
if (setuid(0)) if (setuid(0))
die("setuid(0) failed\n"); die("setuid(0) failed\n");
@ -304,6 +336,14 @@ main(int argc, char **argv) {
getoldbrightness(); getoldbrightness();
syncstate(); syncstate();
lockscreen(dpy, screen); lockscreen(dpy, screen);
if ((target == StateNoInputNoScreen) || (target == StateSuspend)) {
state = StateNoInputNoScreen;
syncstate();
}
if (target == StateSuspend) {
state = StateSuspend;
syncstate();
}
readinputloop(dpy, screen); readinputloop(dpy, screen);
return 0; return 0;
} }

@ -79,6 +79,9 @@ programchoicesinit() {
elif echo "$WMCLASS" | grep -i "power"; then elif echo "$WMCLASS" | grep -i "power"; then
# Power menu # Power menu
CHOICES=" CHOICES="
Lock ^ 0 ^ sxmo_lock.sh
Lock (Screen off) ^ 0 ^ sxmo_lock.sh --screen-off
Suspend ^ 0 ^ sxmo_lock.sh --suspend
Logout ^ 0 ^ pkill -9 dwm Logout ^ 0 ^ pkill -9 dwm
Reboot ^ 0 ^ st -e sudo reboot Reboot ^ 0 ^ st -e sudo reboot
Poweroff ^ 0 ^ st -e sudo halt Poweroff ^ 0 ^ st -e sudo halt

@ -0,0 +1,10 @@
#!/usr/bin/env sh
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/lock" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/lock"
fi
pkill -9 lisgd
sxmo_screenlock "$@"
lisgd &
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/unlock" ]; then
"$XDG_CONFIG_HOME/sxmo/hooks/unlock"
fi
Loading…
Cancel
Save