[hackers] [slstatus][PATCH] backlight: implemented openbsd support

From: Tobias Tschinkowitz <he4d_AT_posteo.de>
Date: Wed, 23 May 2018 20:41:17 +0200

implemented openbsd support for the backlight function.
this only works when running slstatus as superuser.

---
Hi Guys,
i have implemented basic support for the backlight function on OpenBSD.
The problem here is that /dev/ttyC0 permission is 600 (root:wheel) so a
user cannot read from the device without changing the permission or
running slstatus as root.
Anyway, this is just an proposal. Hopefully there is 
another solution to solve this. I know that we could also do this by
linking against xcb-xrandr (like xbacklight does) but i think we should
not do this for now.
Greetings,
Tobias
 components/backlight.c | 26 ++++++++++++++++++++++++++
 config.def.h           |  1 +
 2 files changed, 27 insertions(+)
diff --git a/components/backlight.c b/components/backlight.c
index f9c4096..21e06a1 100644
--- a/components/backlight.c
+++ b/components/backlight.c
_AT_@ -29,4 +29,30 @@
 
 		return bprintf("%d", cur * 100 / max);
 	}
+
+#elif defined(__OpenBSD__)
+	#include <fcntl.h>
+	#include <sys/ioctl.h>
+	#include <sys/time.h>
+	#include <dev/wscons/wsconsio.h>
+
+	const char *
+	backlight_perc(const char *unused)
+	{
+		int fd, err;
+		struct wsdisplay_param wsd_param = {
+			.param = WSDISPLAYIO_PARAM_BRIGHTNESS
+		};
+
+		if ((fd = open("/dev/ttyC0", O_RDONLY)) < 0) {
+			warn("could not open /dev/ttyC0");
+			return NULL;
+		}
+		if ((err = ioctl(fd, WSDISPLAYIO_GETPARAM, &wsd_param)) < 0) {
+			warn("ioctl 'WSDISPLAYIO_GETPARAM' failed");
+			return NULL;
+		}
+		return bprintf("%d", wsd_param.curval * 100 / wsd_param.max);
+	}
+
 #endif
diff --git a/config.def.h b/config.def.h
index 75debe5..3a0f838 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -14,6 +14,7 @@ static const char unknown_str[] = "n/a";
  *
  * backlight_perc       backlight percentage            device name
  *                                                      (intel_backlight)
+ *                                                      NULL on OpenBSD
  * battery_perc         battery percentage              battery name (BAT0)
  *                                                      NULL on OpenBSD
  * battery_state        battery charging state          battery name (BAT0)
-- 
2.16.2
Received on Wed May 23 2018 - 20:41:17 CEST

This archive was generated by hypermail 2.3.0 : Wed May 23 2018 - 20:48:24 CEST