Files
fastfetch/src/detection/brightness/brightness_haiku.cpp
T

47 lines
1.3 KiB
C++
Raw Normal View History

2026-05-30 17:01:45 +02:00
extern "C" {
#include "brightness.h"
#include "common/strutil.h"
}
#include <Application.h>
#include <Screen.h>
const char* ffDetectBrightness([[maybe_unused]] FFBrightnessOptions* options, FFlist* result) {
2026-05-30 17:01:45 +02:00
// We need a valid be_app to query the app_server here.
BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
BScreen screen{}; // default screen is the main one
do {
if (!screen.IsValid()) {
continue;
}
float value = 1.0f;
status_t status = screen.GetBrightness(&value);
if (status != B_OK) {
continue;
}
monitor_info monitor;
// WARNING: This is experimental new Haiku API
status_t err = screen.GetMonitorInfo(&monitor);
FFBrightnessResult* brightness = FF_LIST_ADD(FFBrightnessResult, *result);
if (err == B_OK) {
2026-05-31 23:55:18 +08:00
ffStrbufInitF(&brightness->name, "%s %s (%d)", monitor.vendor, monitor.name, screen.ID().id);
2026-05-30 17:01:45 +02:00
ffStrbufTrimRightSpace(&brightness->name);
} else {
2026-05-31 23:55:18 +08:00
ffStrbufInitF(&brightness->name, "Screen %d", screen.ID().id);
2026-05-30 17:01:45 +02:00
}
brightness->max = 1.0f;
brightness->min = 0.0f;
brightness->current = value;
brightness->builtin = true;
} while (screen.SetToNext() == B_OK);
2026-07-10 18:08:04 +08:00
return nullptr;
2026-05-30 17:01:45 +02:00
}