diff --git a/programs/sxmo_screenlock.c b/programs/sxmo_screenlock.c index 048f458..437c9bc 100644 --- a/programs/sxmo_screenlock.c +++ b/programs/sxmo_screenlock.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +111,14 @@ die(const char *err, ...) exit(1); } +void +sigterm() +{ + state = StateDead; + syncstate(); + exit(0); +} + int getoldbrightness() { char * buffer = 0; @@ -289,9 +298,32 @@ writefile(char *filepath, char *str) } } +void usage() { + fprintf(stderr, "Usage: sxmo_screenlock [--screen-off] [--suspend]\n"); +} + int main(int argc, char **argv) { 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)) die("setuid(0) failed\n"); @@ -304,6 +336,14 @@ main(int argc, char **argv) { getoldbrightness(); syncstate(); lockscreen(dpy, screen); + if ((target == StateNoInputNoScreen) || (target == StateSuspend)) { + state = StateNoInputNoScreen; + syncstate(); + } + if (target == StateSuspend) { + state = StateSuspend; + syncstate(); + } readinputloop(dpy, screen); return 0; } diff --git a/scripts/core/sxmo_appmenu.sh b/scripts/core/sxmo_appmenu.sh index c53b140..6c6f36b 100755 --- a/scripts/core/sxmo_appmenu.sh +++ b/scripts/core/sxmo_appmenu.sh @@ -79,9 +79,12 @@ programchoicesinit() { elif echo "$WMCLASS" | grep -i "power"; then # Power menu CHOICES=" - Logout ^ 0 ^ pkill -9 dwm - Reboot ^ 0 ^ st -e sudo reboot - Poweroff ^ 0 ^ st -e sudo halt + 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 + Reboot ^ 0 ^ st -e sudo reboot + Poweroff ^ 0 ^ st -e sudo halt " WINNAME="Power" elif echo "$WMCLASS" | grep -i "mpv"; then diff --git a/scripts/core/sxmo_lock.sh b/scripts/core/sxmo_lock.sh new file mode 100755 index 0000000..4490f1c --- /dev/null +++ b/scripts/core/sxmo_lock.sh @@ -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