mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
Brightness: add new module (macOS)
It turns out that merging brightness module into resolution module is a bad idea.
This commit is contained in:
@@ -19,6 +19,8 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg)
|
||||
ffStrbufAppendS(buffer, (const char*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_STRBUF)
|
||||
ffStrbufAppend(buffer, (FFstrbuf*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_FLOAT)
|
||||
ffStrbufAppendF(buffer, "%f", *(float*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_DOUBLE)
|
||||
ffStrbufAppendF(buffer, "%g", *(double*)formatarg->value);
|
||||
else if(formatarg->type == FF_FORMAT_ARG_TYPE_BOOL)
|
||||
|
||||
@@ -12,6 +12,7 @@ typedef enum FFformatargtype
|
||||
FF_FORMAT_ARG_TYPE_INT,
|
||||
FF_FORMAT_ARG_TYPE_STRING,
|
||||
FF_FORMAT_ARG_TYPE_STRBUF,
|
||||
FF_FORMAT_ARG_TYPE_FLOAT,
|
||||
FF_FORMAT_ARG_TYPE_DOUBLE,
|
||||
FF_FORMAT_ARG_TYPE_LIST,
|
||||
FF_FORMAT_ARG_TYPE_BOOL
|
||||
|
||||
@@ -247,6 +247,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.host);
|
||||
initModuleArg(&instance->config.bios);
|
||||
initModuleArg(&instance->config.board);
|
||||
initModuleArg(&instance->config.brightness);
|
||||
initModuleArg(&instance->config.chassis);
|
||||
initModuleArg(&instance->config.kernel);
|
||||
initModuleArg(&instance->config.uptime);
|
||||
|
||||
@@ -230,6 +230,7 @@
|
||||
#--packages-key Packages
|
||||
#--shell-key Shell
|
||||
#--resolution-key Resolution {1}
|
||||
#--brightness-key Brightness ({1})
|
||||
#--de-key DE
|
||||
#--wm-key WM
|
||||
#--wm-theme-key WM Theme
|
||||
@@ -274,6 +275,7 @@
|
||||
#--packages-format
|
||||
#--shell-format
|
||||
#--resolution-format
|
||||
#--brightness-format
|
||||
#--de-format
|
||||
#--wm-format
|
||||
#--wm-theme-format
|
||||
@@ -317,6 +319,7 @@
|
||||
#--packages-error
|
||||
#--shell-error
|
||||
#--resolution-error
|
||||
#--brightness-error
|
||||
#--de-error
|
||||
#--wm-error
|
||||
#--wm-theme-error
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_detection_brightness_brightness
|
||||
#define FF_INCLUDED_detection_brightness_brightness
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "util/FFlist.h"
|
||||
|
||||
typedef struct FFBrightnessResult
|
||||
{
|
||||
FFstrbuf name;
|
||||
float value;
|
||||
} FFBrightnessResult;
|
||||
|
||||
const char* ffDetectBrightness(FFlist* result); // list of FFBrightnessResult
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "brightness.h"
|
||||
|
||||
#include <CoreGraphics/CoreGraphics.h>
|
||||
|
||||
extern int DisplayServicesGetBrightness(CGDirectDisplayID display, float *brightness) __attribute__((weak_import));
|
||||
|
||||
const char* ffDetectBrightness(FFlist* result)
|
||||
{
|
||||
if(DisplayServicesGetBrightness == NULL)
|
||||
return "DisplayServices function DisplayServicesGetBrightness is not available";
|
||||
|
||||
CGDirectDisplayID screens[128];
|
||||
uint32_t screenCount;
|
||||
if(CGGetOnlineDisplayList(sizeof(screens) / sizeof(screens[0]), screens, &screenCount) != kCGErrorSuccess)
|
||||
return "CGGetOnlineDisplayList() failed";
|
||||
|
||||
for(uint32_t i = 0; i < screenCount; i++)
|
||||
{
|
||||
CGDirectDisplayID screen = screens[i];
|
||||
float brightness;
|
||||
if(DisplayServicesGetBrightness(screen, &brightness) != kCGErrorSuccess)
|
||||
continue;
|
||||
|
||||
FFBrightnessResult* display = (FFBrightnessResult*) ffListAdd(result);
|
||||
if(CGDisplayIsBuiltin(screen))
|
||||
ffStrbufInitS(&display->name, "built-in");
|
||||
else
|
||||
ffStrbufInitF(&display->name, "external-%u", (unsigned) screen);
|
||||
display->value = brightness * 100;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "brightness.h"
|
||||
|
||||
const char* ffDetectBrightness(FF_UNUSED_PARAM FFlist* result)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
@@ -1146,6 +1146,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(optionParseModuleArgs(key, value, "packages", &instance->config.packages)) {}
|
||||
else if(optionParseModuleArgs(key, value, "shell", &instance->config.shell)) {}
|
||||
else if(optionParseModuleArgs(key, value, "resolution", &instance->config.resolution)) {}
|
||||
else if(optionParseModuleArgs(key, value, "brightness", &instance->config.brightness)) {}
|
||||
else if(optionParseModuleArgs(key, value, "de", &instance->config.de)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wifi", &instance->config.wifi)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wm", &instance->config.wm)) {}
|
||||
@@ -1362,6 +1363,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintBios(instance);
|
||||
else if(strcasecmp(line, "board") == 0)
|
||||
ffPrintBoard(instance);
|
||||
else if(strcasecmp(line, "brightness") == 0)
|
||||
ffPrintBrightness(instance);
|
||||
else if(strcasecmp(line, "chassis") == 0)
|
||||
ffPrintChassis(instance);
|
||||
else if(strcasecmp(line, "kernel") == 0)
|
||||
|
||||
+3
-1
@@ -106,8 +106,9 @@ typedef struct FFconfig
|
||||
FFModuleArgs os;
|
||||
FFModuleArgs host;
|
||||
FFModuleArgs bios;
|
||||
FFModuleArgs chassis;
|
||||
FFModuleArgs board;
|
||||
FFModuleArgs brightness;
|
||||
FFModuleArgs chassis;
|
||||
FFModuleArgs kernel;
|
||||
FFModuleArgs uptime;
|
||||
FFModuleArgs processes;
|
||||
@@ -273,6 +274,7 @@ void ffPrintProcesses(FFinstance* instance);
|
||||
void ffPrintPackages(FFinstance* instance);
|
||||
void ffPrintShell(FFinstance* instance);
|
||||
void ffPrintResolution(FFinstance* instance);
|
||||
void ffPrintBrightness(FFinstance* instance);
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance);
|
||||
void ffPrintWM(FFinstance* instance);
|
||||
void ffPrintWMTheme(FFinstance* instance);
|
||||
|
||||
@@ -31,6 +31,7 @@ int main(int argc, char** argv)
|
||||
ffPrintPackages(&instance);
|
||||
ffPrintShell(&instance);
|
||||
ffPrintResolution(&instance);
|
||||
// ffPrintBrightness(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintWM(&instance);
|
||||
ffPrintWMTheme(&instance);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/brightness/brightness.h"
|
||||
|
||||
#define FF_BRIGHTNESS_MODULE_NAME "Brightness"
|
||||
#define FF_BRIGHTNESS_NUM_FORMAT_ARGS 2
|
||||
|
||||
void ffPrintBrightness(FFinstance* instance)
|
||||
{
|
||||
FFlist result;
|
||||
ffListInit(&result, sizeof(FFBrightnessResult));
|
||||
const char* error = ffDetectBrightness(&result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &instance->config.brightness, "%s", error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_BRIGHTNESS_MODULE_NAME, 0, &instance->config.brightness, "No result is detected.");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
FFstrbuf key;
|
||||
ffStrbufInit(&key);
|
||||
|
||||
FF_LIST_FOR_EACH(FFBrightnessResult, item, result)
|
||||
{
|
||||
if(instance->config.brightness.key.length == 0)
|
||||
{
|
||||
ffStrbufAppendF(&key, "%s (%s)", FF_BRIGHTNESS_MODULE_NAME, item->name.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffParseFormatString(&key, &instance->config.brightness.key, 1, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &item->name}
|
||||
});
|
||||
}
|
||||
|
||||
if(instance->config.brightness.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
|
||||
printf("%.0f%%\n", item->value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.brightness.outputFormat, FF_BRIGHTNESS_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &item->value},
|
||||
{FF_FORMAT_ARG_TYPE_FLOAT, &item->name}
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&item->name);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&key);
|
||||
|
||||
exit:
|
||||
ffListDestroy(&result);
|
||||
}
|
||||
Reference in New Issue
Block a user