diff --git a/.config/eww/eww.yuck b/.config/eww/eww.yuck index 15369ad..93ecbee 100644 --- a/.config/eww/eww.yuck +++ b/.config/eww/eww.yuck @@ -39,6 +39,7 @@ (defpoll brightness_label :interval "1s" "scripts/brightnesslabel") (defpoll battery_level :interval "15s" "scripts/battery") (defpoll currtime :interval "1s" "scripts/currtime") +(defpoll autosus :interval "5s" "scripts/autosus") (defvar songcard_reveal false) (defvar brightness_reveal false) @@ -116,6 +117,7 @@ :valign "center" :space-evenly "false" :spacing 10 + (literal :content {autosus}) (wifi) (bluetooth) (brightness) diff --git a/.config/eww/scripts/Makefile b/.config/eww/scripts/Makefile new file mode 100644 index 0000000..57053bf --- /dev/null +++ b/.config/eww/scripts/Makefile @@ -0,0 +1,2 @@ +susauto: autosus.c + clang -lX11 -lXrandr autosus.c -o autosus diff --git a/.config/eww/scripts/autosus.c b/.config/eww/scripts/autosus.c new file mode 100644 index 0000000..940aaac --- /dev/null +++ b/.config/eww/scripts/autosus.c @@ -0,0 +1,34 @@ +#include +#include +#include + +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; +}