1
0
mirror of https://github.com/alrayyes/slstatus synced 2023-11-14 15:56:27 +00:00

added backlight_perc

This commit is contained in:
Ryan Kes 2019-03-10 21:28:53 +01:00
parent 68e5b68d3c
commit 69376d77d7
3 changed files with 104 additions and 7 deletions

View File

@ -12,6 +12,7 @@ license=('custom:ISC')
_patches=( _patches=(
"seperator-20180305-f4e35fa.diff" "seperator-20180305-f4e35fa.diff"
"backlight-20180305-85a4a18.diff"
) )
source=("git+https://git.suckless.org/${pkgname%-git}" source=("git+https://git.suckless.org/${pkgname%-git}"
@ -19,8 +20,9 @@ source=("git+https://git.suckless.org/${pkgname%-git}"
"${_patches[@]}") "${_patches[@]}")
md5sums=('SKIP' md5sums=('SKIP'
'b928045f39e259a1fa526e18b1ce8dc1' '9a36cf69d3a7318fffad5535f3e0fed5'
'24ea93ef665decc0315248f62aa65f44') '24ea93ef665decc0315248f62aa65f44'
'58404d0af1893f560926daf605a79919')
pkgver() { pkgver() {
cd "${pkgname%-git}" cd "${pkgname%-git}"

View File

@ -0,0 +1,95 @@
From 85a4a1822108d84c50d383211c4092a2aed7e7b4 Mon Sep 17 00:00:00 2001
From: Ryan Kes <alrayyes@gmail.com>
Date: Sun, 10 Mar 2019 21:12:49 +0100
Subject: [PATCH] Add linux support for backlight
---
Makefile | 1 +
components/backlight.c | 36 ++++++++++++++++++++++++++++++++++++
config.def.h | 1 +
slstatus.h | 3 +++
4 files changed, 41 insertions(+)
create mode 100644 components/backlight.c
diff --git a/Makefile b/Makefile
index 20796b3..c93032f 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ include config.mk
REQ = util
COM =\
+ components/backlight\
components/battery\
components/cpu\
components/datetime\
diff --git a/components/backlight.c b/components/backlight.c
new file mode 100644
index 0000000..fcc062a
--- /dev/null
+++ b/components/backlight.c
@@ -0,0 +1,36 @@
+/* See LICENSE file for copyright and license details. */
+#include <stdio.h>
+#include <string.h>
+
+#include "../util.h"
+
+#if defined(__linux__)
+ #include <limits.h>
+ #include <stdint.h>
+ #include <unistd.h>
+
+ const char *
+ backlight_perc(const char *backlight)
+ {
+ float value;
+ char path[PATH_MAX];
+
+ if (esnprintf(path, sizeof(path),
+ "/sys/class/backlight/%s/actual_brightness", backlight) < 0) {
+ return NULL;
+ }
+ if (pscanf(path, "%f", &value) != 1) {
+ return NULL;
+ }
+
+ return bprintf("%d", (int)(value / 852 * 100));
+ }
+
+#else
+ const char *
+ backlight_perc(const char *backlight)
+ {
+ return NULL;
+ }
+
+#endif
diff --git a/config.def.h b/config.def.h
index af289e5..d2f7045 100644
--- a/config.def.h
+++ b/config.def.h
@@ -12,6 +12,7 @@ static const char unknown_str[] = "n/a";
/*
* function description argument (example)
*
+ * backlight_perc backlight percentage backlight name (intel_backlight)
* battery_perc battery percentage battery name (BAT0)
* NULL on OpenBSD/FreeBSD
* battery_state battery charging state battery name (BAT0)
diff --git a/slstatus.h b/slstatus.h
index 78aef21..a46f276 100644
--- a/slstatus.h
+++ b/slstatus.h
@@ -1,5 +1,8 @@
/* See LICENSE file for copyright and license details. */
+/* backlight */
+const char *backlight_perc(const char *backlight);
+
/* battery */
const char *battery_perc(const char *);
const char *battery_state(const char *);
--
2.21.0

View File

@ -73,13 +73,13 @@ static const struct arg args[] = {
{ battery_perc, "\x0C  %s%%", "BAT0" }, { battery_perc, "\x0C  %s%%", "BAT0" },
{ battery_remaining, " %s ", "BAT0" }, { battery_remaining, " %s ", "BAT0" },
{ seperator, "\x0D", NULL }, { seperator, "\x0D", NULL },
/* { run_command, "\x0E  %s%% ", "/bin/sh -c \"xbacklight -get | xargs printf '%.*f\n' 0 \"" }, */ { backlight_perc, "\x0E  %s%% ", "intel_backlight" },
/* { seperator, "\x0F", NULL }, */ { seperator, "\x0F", NULL },
{ disk_perc, "\x10 / %s%%", "/" }, { disk_perc, "\x10 / %s%%", "/" },
{ disk_perc, "  %s%% ", "/home" }, { disk_perc, "  %s%% ", "/home" },
{ seperator, "\x11", NULL }, //{ seperator, "\x11", NULL },
/* { run_command, "\x12 蓼 %s%% ", "/bin/sh -c \"amixer get Master | tail -n1 | grep -Po '\\[\\K[^%]*' | head -n1\"" }, */ //{ run_command, "\x12 蓼 %s%% ", "/bin/sh -c \"amixer get Master | tail -n1 | grep -Po '\\[\\K[^%]*' | head -n1\"" },
/* { seperator, "\x13", NULL }, */ { seperator, "\x13", NULL },
{ ram_perc, "\x14  %s%% ", NULL }, { ram_perc, "\x14  %s%% ", NULL },
{ seperator, "\x15", NULL }, { seperator, "\x15", NULL },
{ load_avg, "\x16  %s ", NULL }, { load_avg, "\x16  %s ", NULL },