From cff95e66be47563f34db1f482e02e91ec014119d Mon Sep 17 00:00:00 2001 From: Carter Li Date: Fri, 23 Jun 2023 06:07:22 +0000 Subject: [PATCH] DisplayServer: dirty hack for #477 --- src/detection/displayserver/linux/wayland.c | 45 +++++++-------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/src/detection/displayserver/linux/wayland.c b/src/detection/displayserver/linux/wayland.c index 019a84ae2..5ab460efd 100644 --- a/src/detection/displayserver/linux/wayland.c +++ b/src/detection/displayserver/linux/wayland.c @@ -10,6 +10,7 @@ #include "common/thread.h" #include #include +#include typedef struct WaylandData { @@ -70,13 +71,11 @@ static void waylandOutputModeListener(void* data, FF_MAYBE_UNUSED struct wl_outp display->refreshRate = refreshRate; } -#ifdef WL_OUTPUT_SCALE_SINCE_VERSION static void waylandOutputScaleListener(void* data, FF_MAYBE_UNUSED struct wl_output* output, int32_t scale) { WaylandDisplay* display = data; display->scale = scale; } -#endif static void waylandOutputGeometryListener(void *data, FF_MAYBE_UNUSED struct wl_output *output, @@ -93,7 +92,6 @@ static void waylandOutputGeometryListener(void *data, display->transform = (enum wl_output_transform) transform; } -#ifdef WL_OUTPUT_NAME_SINCE_VERSION static void waylandOutputNameListener(void *data, FF_MAYBE_UNUSED struct wl_output *output, const char *name) { WaylandDisplay* display = data; @@ -103,7 +101,6 @@ static void waylandOutputNameListener(void *data, FF_MAYBE_UNUSED struct wl_outp display->type = FF_DISPLAY_TYPE_EXTERNAL; ffStrbufAppendS(&display->name, name); } -#endif static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* registry, uint32_t name, uint32_t version) { @@ -121,34 +118,20 @@ static void waylandOutputHandler(WaylandData* wldata, struct wl_registry* regist }; ffStrbufInit(&display.name); - struct wl_output_listener outputListener = { - .mode = waylandOutputModeListener, - .geometry = waylandOutputGeometryListener, - - #ifdef WL_OUTPUT_DONE_SINCE_VERSION - .done = (void*) stubListener, - #else - #warning wl_output_listener::done is not supported - #endif - - #ifdef WL_OUTPUT_SCALE_SINCE_VERSION - .scale = waylandOutputScaleListener, - #else - #warning wl_output_listener::scale is not supported - #endif - - #ifdef WL_OUTPUT_NAME_SINCE_VERSION - .name = waylandOutputNameListener, - #else - #warning wl_output_listener::name is not supported - #endif - - #ifdef WL_OUTPUT_DESCRIPTION_SINCE_VERSION - .description = (void*) stubListener, - #else - #warning wl_output_listener::description is not supported - #endif + // Dirty hack for #477 + // The order of these callbacks MUST follow `struct wl_output_listener` + void* outputListener[] = { + waylandOutputGeometryListener, // geometry + waylandOutputModeListener, // mode + stubListener, // done + waylandOutputScaleListener, // scale + waylandOutputNameListener, // name + stubListener, // description }; + static_assert( + sizeof(outputListener) >= sizeof(struct wl_output_listener), + "sizeof(outputListener) is too small. Please report it to fastfetch github issue" + ); wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, &display); wldata->ffwl_display_roundtrip(wldata->display);