master ohmu/fastfetch-openbsd / src / detection / displayserver / displayserver_haiku.cpp
ohmu  ·  2026-10-15
 1extern "C" {
 2#include "displayserver.h"
 3}
 4
 5#include <math.h>
 6
 7#include <Application.h>
 8#include <Screen.h>
 9
10extern "C" void ffConnectDisplayServerImpl(FFDisplayServerResult* ds);
11
12static void detectDisplays(FFDisplayServerResult* ds) {
13    // We need a valid be_app to query the app_server here.
14    BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
15    BScreen s{}; // default screen is the main one
16    bool main = true;
17
18    do {
19        if (!s.IsValid()) {
20            continue;
21        }
22
23        display_mode mode;
24        if (s.GetMode(&mode) != B_OK) {
25            continue;
26        }
27
28        FF_STRBUF_AUTO_DESTROY name = ffStrbufCreateA(128);
29        monitor_info monitor;
30        // WARNING: This is experimental new Haiku API
31        status_t err = s.GetMonitorInfo(&monitor);
32        if (err == B_OK) {
33            ffStrbufSetF(&name, "%s %s", monitor.vendor, monitor.name);
34            ffStrbufTrimRightSpace(&name);
35        }
36
37        uint32_t width = (uint32_t) s.Frame().Width() + 1;
38        uint32_t height = (uint32_t) (uint32_t) s.Frame().Height() + 1;
39        FFDisplayResult* res = ffdsAppendDisplay(ds,
40            width,
41            height,
42            (double) mode.timing.pixel_clock * 1000 / (mode.timing.v_total * mode.timing.h_total),
43            0,
44            0,
45            0,
46            0,
47            0,
48            &name,
49            FF_DISPLAY_TYPE_UNKNOWN,
50            main,
51            (uint64_t) s.ID().id,
52            0,
53            0,
54            "BScreen");
55        if (err == B_OK) {
56            res->manufactureWeek = monitor.produced.week;
57            res->manufactureYear = monitor.produced.year;
58        }
59        main = false;
60    } while (s.SetToNext() == B_OK);
61
62    return;
63}
64
65void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) {
66    ffStrbufSetStatic(&ds->wmProcessName, "app_server");
67    ffStrbufSetStatic(&ds->wmPrettyName, "Application Server");
68    ffStrbufSetStatic(&ds->dePrettyName, "Application Kit");
69
70    detectDisplays(ds);
71}