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. 9
      scripts/core/sxmo_appmenu.sh
  3. 10
      scripts/core/sxmo_lock.sh

@ -4,6 +4,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
#include <X11/XKBlib.h>
@ -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;
}

@ -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

@ -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