diff options
author | Runxi Yu <me@runxiyu.org> | 2024-08-30 08:00:00 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-08-30 08:00:00 +0800 |
commit | aecc86c67e1c757d277b91a6be4e247e5f984d87 (patch) | |
tree | 2efa0b49a0ca67e9654a49679552d29571b6222a | |
parent | Use promptmenu (diff) | |
download | rxmenus-master.tar.gz rxmenus-master.zip |
-rwxr-xr-x | rxmenu | 1 | ||||
-rwxr-xr-x | rxmenu-backlight | 9 | ||||
-rw-r--r-- | setbkl.c | 38 |
3 files changed, 48 insertions, 0 deletions
@@ -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; +} |