feat: autosleep from eww under specific conditions optimally
Signed-off-by: Lucas Sta Maria <lucas@priime.dev>
This commit is contained in:
parent
dca1413c4f
commit
91631f15f0
3 changed files with 38 additions and 0 deletions
2
.config/eww/scripts/Makefile
Normal file
2
.config/eww/scripts/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
susauto: autosus.c
|
||||
clang -lX11 -lXrandr autosus.c -o autosus
|
34
.config/eww/scripts/autosus.c
Normal file
34
.config/eww/scripts/autosus.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <X11/Xlibint.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **args) {
|
||||
const char *display_name = ":0";
|
||||
Display *dpy = XOpenDisplay(display_name);
|
||||
Window window = XDefaultRootWindow(dpy);
|
||||
XRRMonitorInfo *monitor = XRRGetMonitors(dpy, window, 1, &dpy->nscreens);
|
||||
|
||||
int is_laptop_screen = monitor->height == 1200 ? 1 : 0;
|
||||
FILE *fp = popen(
|
||||
"cat /proc/acpi/button/lid/LID0/state | grep -i closed | wc -l", "r");
|
||||
if (fp == NULL) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char buf[2];
|
||||
int is_closed = 0;
|
||||
if (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||
is_closed = atoi(buf);
|
||||
pclose(fp);
|
||||
} else {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (is_closed && is_laptop_screen) {
|
||||
system("systemctl suspend");
|
||||
}
|
||||
|
||||
printf("");
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue