mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
Display (Linux): show brand of Xserver in WM section (#1888)
* Display: add server vendor string * Display (X11): fetch server vendor string using XCB/Xlib * WM: show server vendor string when not empty * Display (XCB): use proper string helper function * Display (X11): shorten "The X.Org Foundation" to "Xorg"
This commit is contained in:
@@ -61,6 +61,7 @@ const FFDisplayServerResult* ffConnectDisplayServer()
|
||||
ffStrbufInit(&result.wmProtocolName);
|
||||
ffStrbufInit(&result.deProcessName);
|
||||
ffStrbufInit(&result.dePrettyName);
|
||||
ffStrbufInit(&result.serverVendor);
|
||||
ffListInit(&result.displays, sizeof(FFDisplayResult));
|
||||
ffConnectDisplayServerImpl(&result);
|
||||
}
|
||||
|
||||
@@ -91,6 +91,7 @@ typedef struct FFDisplayServerResult
|
||||
FFstrbuf wmProtocolName;
|
||||
FFstrbuf deProcessName;
|
||||
FFstrbuf dePrettyName;
|
||||
FFstrbuf serverVendor;
|
||||
FFlist displays; //List of FFDisplayResult
|
||||
} FFDisplayServerResult;
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "common/time.h"
|
||||
#include "util/edidHelper.h"
|
||||
#include "util/mallocHelper.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -24,6 +25,9 @@ typedef struct XcbPropertyData
|
||||
FF_LIBRARY_SYMBOL(xcb_get_atom_name_name)
|
||||
FF_LIBRARY_SYMBOL(xcb_get_atom_name_name_length)
|
||||
FF_LIBRARY_SYMBOL(xcb_get_atom_name_reply)
|
||||
FF_LIBRARY_SYMBOL(xcb_get_setup)
|
||||
FF_LIBRARY_SYMBOL(xcb_setup_vendor)
|
||||
FF_LIBRARY_SYMBOL(xcb_setup_vendor_length)
|
||||
} XcbPropertyData;
|
||||
|
||||
static bool xcbInitPropertyData(FF_MAYBE_UNUSED void* libraryHandle, XcbPropertyData* propertyData)
|
||||
@@ -38,6 +42,9 @@ static bool xcbInitPropertyData(FF_MAYBE_UNUSED void* libraryHandle, XcbProperty
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_get_atom_name_name, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_get_atom_name_name_length, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_get_atom_name_reply, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_get_setup, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_setup_vendor, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, xcb_setup_vendor_length, false)
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -86,6 +93,21 @@ static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connect
|
||||
ffStrbufSetS(&result->wmProcessName, wmName);
|
||||
}
|
||||
|
||||
static void xcbFetchServerVendor(XcbPropertyData* data, xcb_connection_t* connection, FFDisplayServerResult* result)
|
||||
{
|
||||
const xcb_setup_t* setup = data->ffxcb_get_setup(connection);
|
||||
|
||||
int length = data->ffxcb_setup_vendor_length(setup);
|
||||
if(length <= 0)
|
||||
return;
|
||||
|
||||
ffStrbufSetNS(&result->serverVendor, (uint32_t) length, data->ffxcb_setup_vendor(setup));
|
||||
|
||||
//Shorten Xorg vendor string
|
||||
if (!ffStrbufCompS(&result->serverVendor, "The X.Org Foundation"))
|
||||
ffStrbufSetS(&result->serverVendor, "Xorg");
|
||||
}
|
||||
|
||||
typedef struct XcbRandrData
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(xcb_randr_get_screen_resources_current)
|
||||
@@ -381,8 +403,10 @@ const char* ffdsConnectXcbRandr(FFDisplayServerResult* result)
|
||||
xcb_screen_iterator_t iterator = ffxcb_setup_roots_iterator(ffxcb_get_setup(data.connection));
|
||||
|
||||
|
||||
if(iterator.rem > 0 && propertyDataInitialized)
|
||||
if(iterator.rem > 0 && propertyDataInitialized) {
|
||||
xcbDetectWMfromEWMH(&data.propData, data.connection, iterator.data->root, result);
|
||||
xcbFetchServerVendor(&data.propData, data.connection, result);
|
||||
}
|
||||
|
||||
|
||||
while(iterator.rem > 0)
|
||||
|
||||
@@ -14,6 +14,7 @@ typedef struct X11PropertyData
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(XInternAtom)
|
||||
FF_LIBRARY_SYMBOL(XGetWindowProperty)
|
||||
FF_LIBRARY_SYMBOL(XServerVendor)
|
||||
FF_LIBRARY_SYMBOL(XFree)
|
||||
} X11PropertyData;
|
||||
|
||||
@@ -21,6 +22,7 @@ static bool x11InitPropertyData(FF_MAYBE_UNUSED void* libraryHandle, X11Property
|
||||
{
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XInternAtom, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XGetWindowProperty, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XServerVendor, false)
|
||||
FF_LIBRARY_LOAD_SYMBOL_PTR(libraryHandle, propertyData, XFree, false)
|
||||
|
||||
return true;
|
||||
@@ -62,6 +64,23 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl
|
||||
data->ffXFree(wmWindow);
|
||||
}
|
||||
|
||||
static void x11FetchServerVendor(X11PropertyData* data, Display* display, FFDisplayServerResult* result)
|
||||
{
|
||||
if(result->serverVendor.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_WM_PROTOCOL_WAYLAND) == 0)
|
||||
return;
|
||||
|
||||
const char* serverVendor = data->ffXServerVendor(display);
|
||||
if(ffStrSet(serverVendor)) {
|
||||
ffStrbufSetS(&result->serverVendor, serverVendor);
|
||||
|
||||
//Shorten Xorg vendor string
|
||||
if (!ffStrbufCompS(&result->serverVendor, "The X.Org Foundation"))
|
||||
ffStrbufSetS(&result->serverVendor, "Xorg");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
typedef struct XrandrData
|
||||
{
|
||||
FF_LIBRARY_SYMBOL(XInternAtom)
|
||||
@@ -305,8 +324,10 @@ const char* ffdsConnectXrandr(FFDisplayServerResult* result)
|
||||
if(data.display == NULL)
|
||||
return "XOpenDisplay() failed";
|
||||
|
||||
if(propertyDataInitialized && ScreenCount(data.display) > 0)
|
||||
if(propertyDataInitialized && ScreenCount(data.display) > 0) {
|
||||
x11DetectWMFromEWMH(&propertyData, data.display, result);
|
||||
x11FetchServerVendor(&propertyData, data.display, result);
|
||||
}
|
||||
|
||||
data.result = result;
|
||||
|
||||
|
||||
@@ -42,6 +42,13 @@ void ffPrintWM(FFWMOptions* options)
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
if(result->serverVendor.length > 0)
|
||||
{
|
||||
fputs(" [", stdout);
|
||||
ffStrbufWriteTo(&result->serverVendor, stdout);
|
||||
putchar(']');
|
||||
}
|
||||
|
||||
if(pluginName.length > 0)
|
||||
{
|
||||
fputs(" (with ", stdout);
|
||||
|
||||
Reference in New Issue
Block a user