From 3d5133eaba160d5d7298bff31a891587c5b37cd1 Mon Sep 17 00:00:00 2001 From: Carter Li Date: Wed, 20 Nov 2024 09:37:32 +0800 Subject: [PATCH] DisplayServer (Linux): remove support of xcb & xlib They don't support multi-monitors. Prefer libdrm. --- CMakeLists.txt | 10 --- src/common/init.c | 6 -- .../displayserver/linux/displayserver_linux.c | 7 -- .../displayserver/linux/displayserver_linux.h | 4 - src/detection/displayserver/linux/xcb.c | 76 ++----------------- src/detection/displayserver/linux/xlib.c | 66 ++-------------- 6 files changed, 12 insertions(+), 157 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a0cca18a..1c6eed1c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,7 @@ include(CMakeDependentOption) cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS" OFF) cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD" OFF) cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_XCB "Enable xcb" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) -cmake_dependent_option(ENABLE_X11 "Enable x11" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) cmake_dependent_option(ENABLE_DRM_AMDGPU "Enable libdrm_amdgpu" ON "LINUX" OFF) cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS" OFF) @@ -1277,18 +1275,10 @@ ff_lib_enable(XCB_RANDR "xcb-randr" "XcbRandr" ) -ff_lib_enable(XCB - "xcb" - "Xcb" -) ff_lib_enable(XRANDR "xrandr" "XRandr" ) -ff_lib_enable(X11 - "x11" - "X11" -) ff_lib_enable(DRM "libdrm" "Libdrm" diff --git a/src/common/init.c b/src/common/init.c index 8f8dfea24..2cdce8df4 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -179,15 +179,9 @@ void ffListFeatures(void) #if FF_HAVE_XCB_RANDR "xcb-randr\n" #endif - #if FF_HAVE_XCB - "xcb\n" - #endif #if FF_HAVE_XRANDR "xrandr\n" #endif - #if FF_HAVE_X11 - "x11\n" - #endif #if FF_HAVE_DRM "drm\n" #endif diff --git a/src/detection/displayserver/linux/displayserver_linux.c b/src/detection/displayserver/linux/displayserver_linux.c index cc4e07b21..84ea36ad6 100644 --- a/src/detection/displayserver/linux/displayserver_linux.c +++ b/src/detection/displayserver/linux/displayserver_linux.c @@ -54,18 +54,11 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds) //Try the x11 libs, from most feature rich to least. //We use the display list to detect if a connection is needed. //They respect wmProtocolName, and only detect display if it is set. - if(ds->displays.length == 0) ffdsConnectXcbRandr(ds); if(ds->displays.length == 0) ffdsConnectXrandr(ds); - - if(ds->displays.length == 0) - ffdsConnectXcb(ds); - - if(ds->displays.length == 0) - ffdsConnectXlib(ds); } //This display detection method is display server independent. diff --git a/src/detection/displayserver/linux/displayserver_linux.h b/src/detection/displayserver/linux/displayserver_linux.h index 5452711e7..19ae4e71f 100644 --- a/src/detection/displayserver/linux/displayserver_linux.h +++ b/src/detection/displayserver/linux/displayserver_linux.h @@ -5,11 +5,7 @@ const char* ffdsConnectWayland(FFDisplayServerResult* result); const char* ffdsConnectXcbRandr(FFDisplayServerResult* result); -const char* ffdsConnectXcb(FFDisplayServerResult* result); - const char* ffdsConnectXrandr(FFDisplayServerResult* result); -const char* ffdsConnectXlib(FFDisplayServerResult* result); - const char* ffdsConnectDrm(FFDisplayServerResult* result); void ffdsDetectWMDE(FFDisplayServerResult* result); diff --git a/src/detection/displayserver/linux/xcb.c b/src/detection/displayserver/linux/xcb.c index a9e4b8d79..47508a242 100644 --- a/src/detection/displayserver/linux/xcb.c +++ b/src/detection/displayserver/linux/xcb.c @@ -1,11 +1,15 @@ #include "displayserver_linux.h" -#include "util/mallocHelper.h" -#include "common/time.h" -#ifdef FF_HAVE_XCB +#ifdef FF_HAVE_XCB_RANDR + #include "common/library.h" +#include "common/time.h" +#include "util/edidHelper.h" +#include "util/mallocHelper.h" + #include #include +#include #include typedef struct XcbPropertyData @@ -82,72 +86,6 @@ static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connect ffStrbufSetS(&result->wmProcessName, wmName); } -const char* ffdsConnectXcb(FFDisplayServerResult* result) -{ - FF_LIBRARY_LOAD(xcb, "dlopen lbxcb failed", "libxcb" FF_LIBRARY_EXTENSION, 2) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcb, xcb_connect) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcb, xcb_get_setup) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcb, xcb_setup_roots_iterator) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcb, xcb_screen_next) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xcb, xcb_disconnect) - - XcbPropertyData propertyData; - bool propertyDataInitialized = xcbInitPropertyData(xcb, &propertyData); - - xcb_connection_t* connection = ffxcb_connect(NULL, NULL); - if(connection == NULL) - return "xcb_connect failed"; - - xcb_screen_iterator_t iterator = ffxcb_setup_roots_iterator(ffxcb_get_setup(connection)); - - if(iterator.rem > 0 && propertyDataInitialized) - xcbDetectWMfromEWMH(&propertyData, connection, iterator.data->root, result); - - while(iterator.rem > 0) - { - xcb_screen_t* screen = iterator.data; - ffdsAppendDisplay(result, - (uint32_t) screen->width_in_pixels, - (uint32_t) screen->height_in_pixels, - 0, - (uint32_t) screen->width_in_pixels, - (uint32_t) screen->height_in_pixels, - 0, - NULL, - FF_DISPLAY_TYPE_UNKNOWN, - false, - 0, - (uint32_t) screen->width_in_millimeters, - (uint32_t) screen->height_in_millimeters, - "xcb" - ); - ffxcb_screen_next(&iterator); - } - - ffxcb_disconnect(connection); - - //If wayland hasn't set this, connection failed for it. So we are running only a X Server, not XWayland. - if(result->wmProtocolName.length == 0) - ffStrbufSetS(&result->wmProtocolName, FF_WM_PROTOCOL_X11); - - return NULL; -} - -#else - -const char* ffdsConnectXcb(FFDisplayServerResult* result) -{ - //Do nothing. There are other implementations coming - FF_UNUSED(result) - return "Fastfetch was compiled without XCB support"; -} - -#endif - -#ifdef FF_HAVE_XCB_RANDR -#include "util/edidHelper.h" -#include - typedef struct XcbRandrData { FF_LIBRARY_SYMBOL(xcb_randr_get_screen_resources_current) diff --git a/src/detection/displayserver/linux/xlib.c b/src/detection/displayserver/linux/xlib.c index 00ef3ce7c..ef190c84a 100644 --- a/src/detection/displayserver/linux/xlib.c +++ b/src/detection/displayserver/linux/xlib.c @@ -1,9 +1,13 @@ #include "displayserver_linux.h" -#ifdef FF_HAVE_X11 +#ifdef FF_HAVE_XRANDR + #include "common/library.h" #include "common/parsing.h" +#include "util/edidHelper.h" #include "util/stringUtils.h" + +#include #include typedef struct X11PropertyData @@ -58,66 +62,6 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl data->ffXFree(wmWindow); } -const char* ffdsConnectXlib(FFDisplayServerResult* result) -{ - FF_LIBRARY_LOAD(x11, "dlopen libX11 failed", "libX11" FF_LIBRARY_EXTENSION, 7, "libX11-xcb" FF_LIBRARY_EXTENSION, 2) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(x11, XOpenDisplay) - FF_LIBRARY_LOAD_SYMBOL_MESSAGE(x11, XCloseDisplay) - - X11PropertyData propertyData; - bool propertyDataInitialized = x11InitPropertyData(x11, &propertyData); - - Display* display = ffXOpenDisplay(x11); - if(display == NULL) - return "XOpenDisplay failed"; - - if(propertyDataInitialized && ScreenCount(display) > 0) - x11DetectWMFromEWMH(&propertyData, display, result); - - for(int i = 0; i < ScreenCount(display); i++) - { - Screen* screen = ScreenOfDisplay(display, i); - ffdsAppendDisplay(result, - (uint32_t) WidthOfScreen(screen), - (uint32_t) HeightOfScreen(screen), - 0, - (uint32_t) WidthOfScreen(screen), - (uint32_t) HeightOfScreen(screen), - 0, - NULL, - FF_DISPLAY_TYPE_UNKNOWN, - false, - 0, - (uint32_t) WidthMMOfScreen(screen), - (uint32_t) HeightMMOfScreen(screen), - "xlib" - ); - } - - ffXCloseDisplay(display); - - //If wayland hasn't set this, connection failed for it. So we are running only a X Server, not XWayland. - if(result->wmProtocolName.length == 0) - ffStrbufSetS(&result->wmProtocolName, FF_WM_PROTOCOL_X11); - - return NULL; -} - -#else - -const char* ffdsConnectXlib(FFDisplayServerResult* result) -{ - //Do nothing. WM / DE detection will use environment vars to detect as much as possible. - FF_UNUSED(result); - return "Fastfetch was compiled without libX11 support"; -} - -#endif //FF_HAVE_X11 - -#ifdef FF_HAVE_XRANDR -#include "util/edidHelper.h" -#include - typedef struct XrandrData { FF_LIBRARY_SYMBOL(XInternAtom)