Skip to content

Commit 1861d55

Browse files
Refactor wayland code
1 parent 3b2a6e4 commit 1861d55

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

src/detection/displayserver/wayland.c

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
typedef struct WaylandData
1515
{
16-
const FFinstance* instance;
1716
FFlist* results;
1817
FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned)
1918
FF_LIBRARY_SYMBOL(wl_proxy_add_listener)
@@ -24,9 +23,6 @@ typedef struct WaylandData
2423

2524
static void waylandDetectWM(int fd, FFDisplayServerResult* result)
2625
{
27-
if(fd < 1)
28-
return;
29-
3026
struct ucred ucred;
3127
socklen_t len = sizeof(struct ucred);
3228
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1)
@@ -41,35 +37,13 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result)
4137
ffStrbufDestroy(&procPath);
4238
}
4339

44-
static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){
45-
FF_UNUSED(data, wl_registry, name);
46-
}
47-
48-
static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform)
49-
{
50-
FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform);
51-
}
52-
53-
static void waylandOutputDoneListener(void* data, struct wl_output* wl_output)
54-
{
55-
FF_UNUSED(data, wl_output);
56-
}
57-
58-
static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor)
59-
{
60-
FF_UNUSED(data, wl_output, factor);
61-
}
62-
6340
static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate)
6441
{
65-
if(!(flags & WL_OUTPUT_MODE_CURRENT))
66-
return;
67-
68-
WaylandData* wldata = (WaylandData*) data;
42+
WaylandData* wldata = data;
6943

7044
wldata->ffwl_proxy_destroy((struct wl_proxy*) output);
7145

72-
if(width <= 0 || height <= 0)
46+
if(!(flags & WL_OUTPUT_MODE_CURRENT) || width <= 0 || height <= 0)
7347
return;
7448

7549
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -90,11 +64,11 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u
9064

9165
if(strcmp(interface, wldata->ffwl_output_interface->name) == 0)
9266
{
93-
struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
67+
struct wl_proxy* output = wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy*) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL);
9468
if(output == NULL)
9569
return;
9670

97-
wldata->ffwl_proxy_add_listener((struct wl_proxy*) output, (void(**)(void)) &wldata->output_listener, data);
71+
wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &wldata->output_listener, data);
9872
}
9973
}
10074

@@ -134,17 +108,15 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result)
134108
return false;
135109
}
136110

137-
data.instance = instance;
138111
data.results = &result->resolutions;
139112

140-
struct wl_registry_listener regestry_listener;
141-
regestry_listener.global = waylandGlobalAddListener;
142-
regestry_listener.global_remove = waylandGlobalRemoveListener;
113+
struct wl_registry_listener regestry_listener = {
114+
.global = waylandGlobalAddListener
115+
};
143116

144-
data.output_listener.geometry = waylandOutputGeometryListener;
145-
data.output_listener.mode = waylandOutputModeListener;
146-
data.output_listener.done = waylandOutputDoneListener;
147-
data.output_listener.scale = waylandOutputScaleListener;
117+
data.output_listener = (struct wl_output_listener) {
118+
.mode = waylandOutputModeListener
119+
};
148120

149121
data.ffwl_proxy_add_listener((struct wl_proxy*) registry, (void(**)(void)) &regestry_listener, &data);
150122
ffwl_display_dispatch(display);

0 commit comments

Comments
 (0)