mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 10:52:08 +02:00
Brightness: add support for Linux
This commit is contained in:
+1
-1
@@ -310,7 +310,7 @@ if(LINUX)
|
||||
src/detection/battery/battery_linux.c
|
||||
src/detection/bios/bios_linux.c
|
||||
src/detection/board/board_linux.c
|
||||
src/detection/brightness/brightness_nosupport.c
|
||||
src/detection/brightness/brightness_linux.c
|
||||
src/detection/chassis/chassis_linux.c
|
||||
src/detection/cpu/cpu_linux.c
|
||||
src/detection/cpuUsage/cpuUsage_linux.c
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "brightness.h"
|
||||
#include "common/io.h"
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
const char* ffDetectBrightness(FF_UNUSED_PARAM FFlist* result)
|
||||
{
|
||||
//https://www.kernel.org/doc/Documentation/ABI/stable/sysfs-class-backlight
|
||||
const char* backlightDirPath = "/sys/class/backlight/";
|
||||
|
||||
DIR* dirp = opendir(backlightDirPath);
|
||||
if(dirp == NULL)
|
||||
return "Failed to open `/sys/class/backlight/`";
|
||||
|
||||
FFstrbuf backlightDir;
|
||||
ffStrbufInitA(&backlightDir, 64);
|
||||
ffStrbufAppendS(&backlightDir, backlightDirPath);
|
||||
|
||||
uint32_t backlightDirLength = backlightDir.length;
|
||||
|
||||
FFstrbuf buffer;
|
||||
ffStrbufInit(&buffer);
|
||||
|
||||
struct dirent* entry;
|
||||
while((entry = readdir(dirp)) != NULL)
|
||||
{
|
||||
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
ffStrbufAppendS(&backlightDir, entry->d_name);
|
||||
ffStrbufAppendS(&backlightDir, "/actual_brightness");
|
||||
if(ffReadFileBuffer(backlightDir.chars, &buffer))
|
||||
{
|
||||
double actualBrightness = ffStrbufToDouble(&buffer);
|
||||
ffStrbufSubstrBefore(&backlightDir, backlightDirLength);
|
||||
ffStrbufAppendS(&backlightDir, entry->d_name);
|
||||
ffStrbufAppendS(&backlightDir, "/max_brightness");
|
||||
if(ffReadFileBuffer(backlightDir.chars, &buffer))
|
||||
{
|
||||
FFBrightnessResult* display = (FFBrightnessResult*) ffListAdd(result);
|
||||
ffStrbufInitS(&display->name, entry->d_name);
|
||||
double maxBrightness = ffStrbufToDouble(&buffer);
|
||||
display->value = (float) (actualBrightness * 100 / maxBrightness);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dirp);
|
||||
ffStrbufDestroy(&backlightDir);
|
||||
ffStrbufDestroy(&buffer);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user