-
-
Notifications
You must be signed in to change notification settings - Fork 776
Expand file tree
/
Copy pathbrightness_obsd.c
More file actions
42 lines (33 loc) · 1.13 KB
/
brightness_obsd.c
File metadata and controls
42 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "brightness.h"
#include "common/io/io.h"
#include <dev/wscons/wsconsio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFlist* result)
{
char path[] = "/dev/ttyCX";
for (char i = '0'; i <= '9'; ++i) {
path[strlen("/dev/ttyC")] = i;
FF_AUTO_CLOSE_FD int devfd = open(path, O_RDONLY | O_CLOEXEC);
if (devfd < 0) {
if (errno == EACCES && i == '0')
return "Permission denied when opening tty device";
if (errno == ENOENT)
break;
continue;
}
struct wsdisplay_param param = {
.param = WSDISPLAYIO_PARAM_BRIGHTNESS,
};
if (ioctl(devfd, WSDISPLAYIO_GETPARAM, ¶m) < 0)
continue;
FFBrightnessResult* brightness = (FFBrightnessResult*) ffListAdd(result);
ffStrbufInitF(&brightness->name, "ttyC%c", i);
brightness->max = param.max;
brightness->min = param.min;
brightness->current = param.curval;
brightness->builtin = true;
}
return NULL;
}