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
|
@ -39,6 +39,7 @@
|
||||||
(defpoll brightness_label :interval "1s" "scripts/brightnesslabel")
|
(defpoll brightness_label :interval "1s" "scripts/brightnesslabel")
|
||||||
(defpoll battery_level :interval "15s" "scripts/battery")
|
(defpoll battery_level :interval "15s" "scripts/battery")
|
||||||
(defpoll currtime :interval "1s" "scripts/currtime")
|
(defpoll currtime :interval "1s" "scripts/currtime")
|
||||||
|
(defpoll autosus :interval "5s" "scripts/autosus")
|
||||||
|
|
||||||
(defvar songcard_reveal false)
|
(defvar songcard_reveal false)
|
||||||
(defvar brightness_reveal false)
|
(defvar brightness_reveal false)
|
||||||
|
@ -116,6 +117,7 @@
|
||||||
:valign "center"
|
:valign "center"
|
||||||
:space-evenly "false"
|
:space-evenly "false"
|
||||||
:spacing 10
|
:spacing 10
|
||||||
|
(literal :content {autosus})
|
||||||
(wifi)
|
(wifi)
|
||||||
(bluetooth)
|
(bluetooth)
|
||||||
(brightness)
|
(brightness)
|
||||||
|
|
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