mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
c7ecc33b64
Improves performance of module Sound and PhysicalMemory
45 lines
1.2 KiB
C
45 lines
1.2 KiB
C
#include "brightness.h"
|
|
#include "common/io.h"
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
#include <sys/ioctl.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
|
|
const char* ffDetectBrightness(FF_A_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 = FF_LIST_ADD(FFBrightnessResult, *result);
|
|
ffStrbufInitF(&brightness->name, "ttyC%c", i);
|
|
|
|
brightness->max = param.max;
|
|
brightness->min = param.min;
|
|
brightness->current = param.curval;
|
|
brightness->builtin = true;
|
|
}
|
|
|
|
return NULL;
|
|
}
|