Skip to content

Commit 0b3bf3c

Browse files
Only build display server code on linux
1 parent 7fd9882 commit 0b3bf3c

24 files changed

+88
-63
lines changed

CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,7 @@ set(LIBFASTFETCH_SRC
185185
src/detection/cpu/cpu.c
186186
src/detection/gpu/gpu.c
187187
src/detection/memory/memory.c
188-
src/detection/displayserver/displayServer.c
189-
src/detection/displayserver/wayland.c
190-
src/detection/displayserver/xcb.c
191-
src/detection/displayserver/xlib.c
192-
src/detection/displayserver/wmde.c
188+
src/detection/displayserver/displayserver.c
193189
src/modules/break.c
194190
src/modules/custom.c
195191
src/modules/title.c
@@ -238,6 +234,7 @@ if(APPLE)
238234
src/detection/cpu/cpu_apple.c
239235
src/detection/gpu/gpu_apple.c
240236
src/detection/memory/memory_apple.c
237+
src/detection/displayserver/displayserver_apple.c
241238
)
242239
elseif(ANDROID)
243240
list(APPEND LIBFASTFETCH_SRC
@@ -246,6 +243,7 @@ elseif(ANDROID)
246243
src/detection/cpu/cpu_linux.c
247244
src/detection/gpu/gpu_android.c
248245
src/detection/memory/memory_linux.c
246+
src/detection/displayserver/displayserver_android.c
249247
)
250248
else()
251249
list(APPEND LIBFASTFETCH_SRC
@@ -254,6 +252,11 @@ else()
254252
src/detection/cpu/cpu_linux.c
255253
src/detection/gpu/gpu_linux.c
256254
src/detection/memory/memory_linux.c
255+
src/detection/displayserver/linux/displayserver_linux.c
256+
src/detection/displayserver/linux/wayland.c
257+
src/detection/displayserver/linux/xcb.c
258+
src/detection/displayserver/linux/xlib.c
259+
src/detection/displayserver/linux/wmde.c
257260
)
258261
endif()
259262

@@ -289,7 +292,7 @@ ff_check_lib(VULKAN vulkan)
289292
ff_check_lib(WAYLAND wayland-client)
290293
ff_check_lib(XCB_RANDR xcb-randr)
291294
ff_check_lib(XCB xcb)
292-
ff_check_lib(XRAND xrandr)
295+
ff_check_lib(XRANDR xrandr)
293296
ff_check_lib(X11 x11)
294297
ff_check_lib(GIO gio-2.0)
295298
ff_check_lib(DCONF dconf)

src/common/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "common/parsing.h"
44
#include "detection/qt.h"
55
#include "detection/gtk.h"
6-
#include "detection/displayserver.h"
6+
#include "detection/displayserver/displayserver.h"
77

88
#include <stdlib.h>
99
#include <unistd.h>
@@ -295,7 +295,7 @@ void startDetectionThreads(FFinstance* instance)
295295
//Android needs none of the things that are detected here
296296
//And using gsettings sometimes hangs the program in android for some unknown reason,
297297
//and since we don't need it we just never call it.
298-
#ifdef __ANDROID__
298+
#if defined(__ANDROID__) || defined(__APPLE__)
299299
return;
300300
#endif
301301

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "displayserver.h"
2+
#include "detection/internal.h"
3+
4+
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance);
5+
6+
const FFDisplayServerResult* ffConnectDisplayServer(const FFinstance* instance)
7+
{
8+
FF_DETECTION_INTERNAL_GUARD(FFDisplayServerResult,
9+
ffConnectDisplayServerImpl(&result, instance);
10+
);
11+
}
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "displayserver.h"
2+
3+
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
4+
{
5+
FF_UNUSED(instance);
6+
7+
ffStrbufInitA(&ds->wmProcessName, 0);
8+
ffStrbufInitA(&ds->wmPrettyName, 0);
9+
ffStrbufInitA(&ds->wmProtocolName, 0);
10+
ffStrbufInitA(&ds->deProcessName, 0);
11+
ffStrbufInitA(&ds->dePrettyName, 0);
12+
ffStrbufInitA(&ds->deVersion, 0);
13+
ffListInitA(&ds->resolutions, sizeof(FFResolutionResult), 0);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "displayserver.h"
2+
3+
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
4+
{
5+
FF_UNUSED(instance);
6+
7+
ffStrbufInitA(&ds->wmProcessName, 0);
8+
ffStrbufInitA(&ds->wmPrettyName, 0);
9+
ffStrbufInitA(&ds->wmProtocolName, 0);
10+
ffStrbufInitA(&ds->deProcessName, 0);
11+
ffStrbufInitA(&ds->dePrettyName, 0);
12+
ffStrbufInitA(&ds->deVersion, 0);
13+
ffListInitA(&ds->resolutions, sizeof(FFResolutionResult), 0);
14+
}

src/detection/displayserver/displayServer.c renamed to src/detection/displayserver/linux/displayserver_linux.c

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#include "displayServer.h"
1+
#include "displayserver_linux.h"
22

3-
#include <pthread.h>
43
#include <dirent.h>
54

65
uint32_t ffdsParseRefreshRate(int32_t refreshRate)
@@ -78,56 +77,41 @@ static void parseDRM(FFDisplayServerResult* result)
7877
ffStrbufDestroy(&drmDir);
7978
}
8079

81-
const FFDisplayServerResult* ffConnectDisplayServer(const FFinstance* instance)
80+
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds, const FFinstance* instance)
8281
{
83-
static FFDisplayServerResult result;
84-
85-
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
86-
static bool init = false;
87-
pthread_mutex_lock(&mutex);
88-
if(init)
89-
{
90-
pthread_mutex_unlock(&mutex);
91-
return &result;
92-
}
93-
init = true;
94-
95-
ffStrbufInit(&result.wmProcessName);
96-
ffStrbufInit(&result.wmPrettyName);
97-
ffStrbufInit(&result.wmProtocolName);
98-
ffStrbufInit(&result.deProcessName);
99-
ffStrbufInit(&result.dePrettyName);
100-
ffStrbufInit(&result.deVersion);
101-
ffListInitA(&result.resolutions, sizeof(FFResolutionResult), 4);
82+
ffStrbufInit(&ds->wmProcessName);
83+
ffStrbufInit(&ds->wmPrettyName);
84+
ffStrbufInit(&ds->wmProtocolName);
85+
ffStrbufInit(&ds->deProcessName);
86+
ffStrbufInit(&ds->dePrettyName);
87+
ffStrbufInit(&ds->deVersion);
88+
ffListInitA(&ds->resolutions, sizeof(FFResolutionResult), 4);
10289

10390
//We try wayland as our prefered display server, as it supports the most features.
10491
//This method can't detect the name of our WM / DE
105-
ffdsConnectWayland(instance, &result);
92+
ffdsConnectWayland(instance, ds);
10693

10794
//Try the x11 libs, from most feature rich to least.
10895
//We use the resolution list to detect if a connection is needed.
10996
//They respect wmProtocolName, and only detect resolution if it is set.
11097

111-
if(result.resolutions.length == 0)
112-
ffdsConnectXcbRandr(instance, &result);
98+
if(ds->resolutions.length == 0)
99+
ffdsConnectXcbRandr(instance, ds);
113100

114-
if(result.resolutions.length == 0)
115-
ffdsConnectXrandr(instance, &result);
101+
if(ds->resolutions.length == 0)
102+
ffdsConnectXrandr(instance, ds);
116103

117-
if(result.resolutions.length == 0)
118-
ffdsConnectXcb(instance, &result);
104+
if(ds->resolutions.length == 0)
105+
ffdsConnectXcb(instance, ds);
119106

120-
if(result.resolutions.length == 0)
121-
ffdsConnectXlib(instance, &result);
107+
if(ds->resolutions.length == 0)
108+
ffdsConnectXlib(instance, ds);
122109

123110
//This resolution detection method is display server independent.
124111
//Use it if all connections failed
125-
if(result.resolutions.length == 0)
126-
parseDRM(&result);
112+
if(ds->resolutions.length == 0)
113+
parseDRM(ds);
127114

128115
//This fills in missing information about WM / DE by using env vars and iterating processes
129-
ffdsDetectWMDE(instance, &result);
130-
131-
pthread_mutex_unlock(&mutex);
132-
return &result;
116+
ffdsDetectWMDE(instance, ds);
133117
}

src/detection/displayserver/displayServer.h renamed to src/detection/displayserver/linux/displayserver_linux.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
#ifndef FASTFETCH_INCLUDED_DISPLAYSERVER
44
#define FASTFETCH_INCLUDED_DISPLAYSERVER
55

6-
#include "fastfetch.h"
7-
#include "detection/displayserver.h"
6+
#include "detection/displayserver/displayserver.h"
87

98
#define FF_DISPLAYSERVER_PROTOCOL_WAYLAND "Wayland"
109
#define FF_DISPLAYSERVER_PROTOCOL_X11 "X11"

src/detection/displayserver/wayland.c renamed to src/detection/displayserver/linux/wayland.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define _GNU_SOURCE //required for struct ucred
22

3-
#include "displayServer.h"
3+
#include "displayserver_linux.h"
44

55
#include <stdlib.h>
66
#include <string.h>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "displayServer.h"
1+
#include "displayserver_linux.h"
22
#include "common/io.h"
33
#include "common/properties.h"
44
#include "common/parsing.h"

0 commit comments

Comments
 (0)