mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
WM: add flag --wm-detect-plugin
This commit is contained in:
@@ -421,6 +421,7 @@ if(LINUX)
|
||||
src/detection/users/users_linux.c
|
||||
src/detection/wallpaper/wallpaper_linux.c
|
||||
src/detection/wifi/wifi_linux.c
|
||||
src/detection/wmde/wmde_linux.c
|
||||
src/detection/wmtheme/wmtheme_linux.c
|
||||
src/util/platform/FFPlatform_unix.c
|
||||
)
|
||||
@@ -528,6 +529,7 @@ elseif(BSD)
|
||||
src/detection/users/users_linux.c
|
||||
src/detection/wallpaper/wallpaper_linux.c
|
||||
src/detection/wifi/wifi_bsd.c
|
||||
src/detection/wmde/wmde_linux.c
|
||||
src/detection/wmtheme/wmtheme_linux.c
|
||||
src/util/platform/FFPlatform_unix.c
|
||||
)
|
||||
@@ -578,6 +580,7 @@ elseif(APPLE)
|
||||
src/detection/users/users_linux.c
|
||||
src/detection/wallpaper/wallpaper_apple.c
|
||||
src/detection/wifi/wifi_apple.m
|
||||
src/detection/wmde/wmde_apple.c
|
||||
src/detection/wmtheme/wmtheme_apple.m
|
||||
src/util/apple/cf_helpers.c
|
||||
src/util/apple/osascript.m
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
#include "displayserver.h"
|
||||
#include "common/sysctl.h"
|
||||
#include "util/apple/cf_helpers.h"
|
||||
#include "util/mallocHelper.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <CoreGraphics/CGDirectDisplay.h>
|
||||
@@ -70,35 +67,6 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
}
|
||||
}
|
||||
|
||||
static void detectWMPlugin(FFstrbuf* name)
|
||||
{
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
u_int requestLength = sizeof(request) / sizeof(*request);
|
||||
|
||||
size_t length = 0;
|
||||
FF_AUTO_FREE struct kinfo_proc* processes = ffSysctlGetData(request, requestLength, &length);
|
||||
if(processes == NULL)
|
||||
return;
|
||||
|
||||
for(size_t i = 0; i < length / sizeof(struct kinfo_proc); i++)
|
||||
{
|
||||
const char* comm = processes[i].kp_proc.p_comm;
|
||||
|
||||
if(
|
||||
strcasecmp(comm, "spectacle") != 0 &&
|
||||
strcasecmp(comm, "amethyst") != 0 &&
|
||||
strcasecmp(comm, "kwm") != 0 &&
|
||||
strcasecmp(comm, "chunkwm") != 0 &&
|
||||
strcasecmp(comm, "yabai") != 0 &&
|
||||
strcasecmp(comm, "rectangle") != 0
|
||||
) continue;
|
||||
|
||||
ffStrbufAppendS(name, comm);
|
||||
name->chars[0] = (char) toupper(name->chars[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
|
||||
{
|
||||
{
|
||||
@@ -116,15 +84,6 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
|
||||
}
|
||||
ffStrbufInit(&ds->wmProtocolName);
|
||||
|
||||
if(instance.config.general.allowSlowOperations)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY name;
|
||||
ffStrbufInit(&name);
|
||||
detectWMPlugin(&name);
|
||||
if(name.length)
|
||||
ffStrbufAppendF(&ds->wmPrettyName, " (with %s)", name.chars);
|
||||
}
|
||||
|
||||
ffStrbufInit(&ds->deProcessName);
|
||||
ffStrbufInitStatic(&ds->dePrettyName, "Aqua");
|
||||
ffStrbufInit(&ds->deVersion);
|
||||
|
||||
@@ -143,15 +143,17 @@ static void detectDisplays(FFDisplayServerResult* ds)
|
||||
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
|
||||
{
|
||||
BOOL enabled;
|
||||
if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled == TRUE)
|
||||
if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
|
||||
{
|
||||
ffStrbufInitStatic(&ds->wmProcessName, "dwm.exe");
|
||||
ffStrbufInitStatic(&ds->wmPrettyName, "Desktop Window Manager");
|
||||
}
|
||||
else
|
||||
{
|
||||
// `explorer.exe` only provides a subset of WM functions, as well as the taskbar and desktop icons.
|
||||
// While a window itself is drawn by kernel (GDI). Killing `explorer.exe` won't affect how windows are displayed generally.
|
||||
ffStrbufInitStatic(&ds->wmProcessName, "explorer.exe");
|
||||
ffStrbufInitStatic(&ds->wmPrettyName, "Windows Explorer");
|
||||
ffStrbufInitStatic(&ds->wmPrettyName, "Internal");
|
||||
}
|
||||
ffStrbufInit(&ds->wmProtocolName);
|
||||
ffStrbufInit(&ds->deProcessName);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
const char* ffDetectWMPlugin(FFstrbuf* pluginName);
|
||||
const char* ffDetectDEVersion();
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "wmde.h"
|
||||
|
||||
#include "common/sysctl.h"
|
||||
#include "util/mallocHelper.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
const char* ffDetectWMPlugin(FFstrbuf* pluginName)
|
||||
{
|
||||
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
|
||||
u_int requestLength = sizeof(request) / sizeof(*request);
|
||||
|
||||
size_t length = 0;
|
||||
FF_AUTO_FREE struct kinfo_proc* processes = ffSysctlGetData(request, requestLength, &length);
|
||||
if(processes == NULL)
|
||||
return "sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL) failed";
|
||||
|
||||
for(size_t i = 0; i < length / sizeof(struct kinfo_proc); i++)
|
||||
{
|
||||
const char* comm = processes[i].kp_proc.p_comm;
|
||||
|
||||
if(
|
||||
strcasecmp(comm, "spectacle") != 0 &&
|
||||
strcasecmp(comm, "amethyst") != 0 &&
|
||||
strcasecmp(comm, "kwm") != 0 &&
|
||||
strcasecmp(comm, "chunkwm") != 0 &&
|
||||
strcasecmp(comm, "yabai") != 0 &&
|
||||
strcasecmp(comm, "rectangle") != 0
|
||||
) continue;
|
||||
|
||||
ffStrbufAppendS(pluginName, comm);
|
||||
pluginName->chars[0] = (char) toupper(pluginName->chars[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* ffDetectDEVersion()
|
||||
{
|
||||
return "No support";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "wmde.h"
|
||||
|
||||
const char* ffDetectWMPlugin(FFstrbuf* pluginName)
|
||||
{
|
||||
return "No support";
|
||||
}
|
||||
|
||||
const char* ffDetectDEVersion()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#include "wmde.h"
|
||||
|
||||
const char* ffDetectWMPlugin(FFstrbuf* pluginName)
|
||||
{
|
||||
return "No support";
|
||||
}
|
||||
|
||||
const char* ffDetectDEVersion()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,4 +8,6 @@ typedef struct FFWMOptions
|
||||
{
|
||||
FFModuleBaseInfo moduleInfo;
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
bool detectPlugin;
|
||||
} FFWMOptions;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "common/printing.h"
|
||||
#include "common/jsonconfig.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "detection/wmde/wmde.h"
|
||||
#include "modules/wm/wm.h"
|
||||
#include "util/stringUtils.h"
|
||||
|
||||
@@ -16,6 +17,10 @@ void ffPrintWM(FFWMOptions* options)
|
||||
return;
|
||||
}
|
||||
|
||||
FF_STRBUF_AUTO_DESTROY pluginName = ffStrbufCreate();
|
||||
if(options->detectPlugin)
|
||||
ffDetectWMPlugin(&pluginName);
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
||||
@@ -29,6 +34,13 @@ void ffPrintWM(FFWMOptions* options)
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
if(pluginName.length > 0)
|
||||
{
|
||||
fputs(" (with ", stdout);
|
||||
ffStrbufWriteTo(&pluginName, stdout);
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
@@ -48,6 +60,12 @@ bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char*
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
if (ffStrEqualsIgnCase(subKey, "detect-plugin"))
|
||||
{
|
||||
options->detectPlugin = ffOptionParseBoolean(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -64,6 +82,12 @@ void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module)
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
||||
continue;
|
||||
|
||||
if (ffStrEqualsIgnCase(key, "detectPlugin"))
|
||||
{
|
||||
options->detectPlugin = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
|
||||
ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
@@ -74,6 +98,9 @@ void ffGenerateWMJsonConfig(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mu
|
||||
ffInitWMOptions(&defaultOptions);
|
||||
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
|
||||
|
||||
if (options->detectPlugin != defaultOptions.detectPlugin)
|
||||
yyjson_mut_obj_add_bool(doc, module, "detectPlugin", options->detectPlugin);
|
||||
}
|
||||
|
||||
void ffGenerateWMJsonResult(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
|
||||
Reference in New Issue
Block a user