master ohmu/fastfetch-openbsd / src / detection / displayserver / linux / wayland / wayland.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#ifdef FF_HAVE_WAYLAND
 4
 5    #include "common/library.h"
 6    #include "common/strutil.h"
 7
 8    #include <wayland-client.h>
 9
10    #include "../displayserver_linux.h"
11
12static inline uint32_t min(uint32_t a, uint32_t b) {
13    return a < b ? a : b;
14}
15
16typedef enum WaylandProtocolType: uint8_t {
17    FF_WAYLAND_PROTOCOL_TYPE_NONE,
18    FF_WAYLAND_PROTOCOL_TYPE_GLOBAL,
19    FF_WAYLAND_PROTOCOL_TYPE_KDE_DEPRECATED,
20    FF_WAYLAND_PROTOCOL_TYPE_KDE_REGISTRY,
21} WaylandProtocolType;
22
23// In case users have an ancient version of libwayland-client
24int wl_display_dispatch_timeout(struct wl_display *display, const struct timespec *timeout);
25
26typedef struct WaylandData {
27    FFDisplayServerResult* result;
28    FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned)
29    FF_LIBRARY_SYMBOL(wl_proxy_add_listener)
30    FF_LIBRARY_SYMBOL(wl_proxy_destroy)
31    FF_LIBRARY_SYMBOL(wl_display_roundtrip)
32    union {
33        FF_LIBRARY_SYMBOL(wl_display_dispatch)
34        FF_LIBRARY_SYMBOL(wl_display_dispatch_timeout)
35    };
36    struct wl_display* display;
37    WaylandProtocolType protocolType;
38    struct wl_proxy* zxdgOutputManager;
39    struct wl_proxy* wpColorManager;
40} WaylandData;
41
42typedef struct WaylandDisplay {
43    WaylandData* parent;
44    void* internal;
45    int32_t width;
46    int32_t height;
47    int32_t refreshRate;
48    int32_t preferredWidth;
49    int32_t preferredHeight;
50    int32_t preferredRefreshRate;
51    int32_t physicalWidth;
52    int32_t physicalHeight;
53    uint32_t dpi;
54    enum wl_output_transform transform;
55    FFDisplayType type;
56    FFstrbuf name;
57    FFstrbuf description;
58    FFstrbuf edidName;
59    uint64_t id;
60    bool hdrInfoAvailable;
61    bool hdrSupported;
62    bool hdrEnabled;
63    uint16_t myear;
64    uint16_t mweek;
65    FFstrbuf serial;
66    uint8_t bitDepth;
67    bool primary;
68    bool done;
69} WaylandDisplay;
70
71inline static uint64_t ffWaylandGenerateIdFromName(const char* name) {
72    uint64_t id = 0;
73    size_t len = strlen(name);
74    if (len > sizeof(id)) {
75        memcpy(&id, name + (len - sizeof(id)), sizeof(id)); // copy the last 8 bytes
76    } else if (len > 0) {
77        memcpy(&id, name, len);
78    }
79    return id;
80}
81
82void ffWaylandOutputNameListener(void* data, [[maybe_unused]] void* output, const char* name);
83void ffWaylandOutputDescriptionListener(void* data, [[maybe_unused]] void* output, const char* description);
84// Modifies content of display. Don't call this function when calling ffdsAppendDisplay
85uint32_t ffWaylandHandleRotation(WaylandDisplay* display);
86const char* ffWaylandWaitForDone(WaylandDisplay* display);
87
88const char* ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
89const char* ffWaylandHandleKdeOutputRegistry(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
90const char* ffWaylandHandleKdeOutput(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
91const char* ffWaylandHandleKdeOutputOrder(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
92const char* ffWaylandHandleZxdgOutput(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
93const char* ffWaylandHandleWpColor(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version);
94
95#endif