ohmu
·
2026-10-15
1extern "C" {
2#include "brightness.h"
3#include "common/strutil.h"
4}
5
6#include <Application.h>
7#include <Screen.h>
8
9const char* ffDetectBrightness([[maybe_unused]] FFBrightnessOptions* options, FFlist* result) {
10 // We need a valid be_app to query the app_server here.
11 BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
12 BScreen screen{}; // default screen is the main one
13
14 do {
15 if (!screen.IsValid()) {
16 continue;
17 }
18
19 float value = 1.0f;
20 status_t status = screen.GetBrightness(&value);
21 if (status != B_OK) {
22 continue;
23 }
24
25 monitor_info monitor;
26 // WARNING: This is experimental new Haiku API
27 status_t err = screen.GetMonitorInfo(&monitor);
28
29 FFBrightnessResult* brightness = FF_LIST_ADD(FFBrightnessResult, *result);
30
31 if (err == B_OK) {
32 ffStrbufInitF(&brightness->name, "%s %s (%d)", monitor.vendor, monitor.name, screen.ID().id);
33 ffStrbufTrimRightSpace(&brightness->name);
34 } else {
35 ffStrbufInitF(&brightness->name, "Screen %d", screen.ID().id);
36 }
37
38 brightness->max = 1.0f;
39 brightness->min = 0.0f;
40 brightness->current = value;
41 brightness->builtin = true;
42
43 } while (screen.SetToNext() == B_OK);
44
45 return nullptr;
46}