aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-08-30 08:00:00 +0800
committerRunxi Yu <me@runxiyu.org>2024-08-30 08:00:00 +0800
commitaecc86c67e1c757d277b91a6be4e247e5f984d87 (patch)
tree2efa0b49a0ca67e9654a49679552d29571b6222a
parentUse promptmenu (diff)
downloadrxmenus-master.tar.gz
rxmenus-master.zip
Add backlightHEADmaster
-rwxr-xr-xrxmenu1
-rwxr-xr-xrxmenu-backlight9
-rw-r--r--setbkl.c38
3 files changed, 48 insertions, 0 deletions
diff --git a/rxmenu b/rxmenu
index 5a4c51a..fbf5380 100755
--- a/rxmenu
+++ b/rxmenu
@@ -3,6 +3,7 @@
rxmenu-$(promptmenu rxmenu <<EOF
profile
cpufreq
+backlight
telinit
rfkill
EOF
diff --git a/rxmenu-backlight b/rxmenu-backlight
new file mode 100755
index 0000000..5099b89
--- /dev/null
+++ b/rxmenu-backlight
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+t="$(promptmenu backlight << EOF
+EOF
+)"
+
+r="$(setbkl $t 2>&1)"
+
+notify-send "setbkl $t" "$r"
diff --git a/setbkl.c b/setbkl.c
new file mode 100644
index 0000000..05a7ffb
--- /dev/null
+++ b/setbkl.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: BSD-2-Clause
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <glob.h>
+
+int
+main(int argc, char **argv)
+{
+ if (argc != 2) {
+ dprintf(2, "%s: missing brightness argument\n", argv[0]);
+ return 1;
+ }
+
+ int fd = open("/sys/class/backlight/apple-panel-bl/brightness", O_WRONLY);
+ if (fd == -1) {
+ dprintf(2, "%s: can't open\n", argv[0]);
+ return 6;
+ }
+ ssize_t wl = (write(fd, argv[1], strlen(argv[1])));
+ if (wl == -1) {
+ dprintf(2, "%s: can't write\n", argv[0]);
+ return 7;
+ } else if ((size_t)wl == strlen(argv[1])) {
+ } else {
+ dprintf(2, "%s: incomplete write\n", argv[0]);
+ return 8;
+ }
+ if (close(fd) == -1) {
+ dprintf(2, "%s: can't close\n", argv[0]);
+ return 9;
+ }
+
+ return 0;
+}