Skip to content

Commit 77b93a9

Browse files
committed
Wallpaper (Windows): add new module
1 parent 7934c16 commit 77b93a9

File tree

10 files changed

+82
-1
lines changed

10 files changed

+82
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Features:
44
* Support display name, type, rotation detection on Wayland (Linux, Display)
55
* Print more useful display name instead of intel_backlight (Linux, Brightness)
66
* Icons module supports Windows (Windows, Icons)
7+
* Add Wallpaper module
78

89
Bugfixes:
910
* Fix Gnome version detection on Fedora

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ set(LIBFASTFETCH_SRC
306306
src/modules/uptime.c
307307
src/modules/users.c
308308
src/modules/vulkan.c
309+
src/modules/wallpaper.c
309310
src/modules/weather.c
310311
src/modules/wifi.c
311312
src/modules/wm.c
@@ -360,6 +361,7 @@ if(LINUX)
360361
src/detection/terminalshell/terminalshell_linux.c
361362
src/detection/uptime/uptime_linux.c
362363
src/detection/users/users_linux.c
364+
src/detection/wallpaper/wallpaper_nosupport.c
363365
src/detection/wifi/wifi_linux.c
364366
src/detection/wmtheme/wmtheme_linux.c
365367
src/util/platform/FFPlatform_unix.c
@@ -400,6 +402,7 @@ elseif(ANDROID)
400402
src/detection/terminalshell/terminalshell_linux.c
401403
src/detection/uptime/uptime_linux.c
402404
src/detection/users/users_linux.c
405+
src/detection/wallpaper/wallpaper_nosupport.c
403406
src/detection/wifi/wifi_android.c
404407
src/detection/wmtheme/wmtheme_nosupport.c
405408
src/util/platform/FFPlatform_unix.c
@@ -448,6 +451,7 @@ elseif(BSD)
448451
src/detection/terminalshell/terminalshell_linux.c
449452
src/detection/uptime/uptime_bsd.c
450453
src/detection/users/users_linux.c
454+
src/detection/wallpaper/wallpaper_nosupport.c
451455
src/detection/wifi/wifi_nosupport.c
452456
src/detection/wmtheme/wmtheme_linux.c
453457
src/util/platform/FFPlatform_unix.c
@@ -490,6 +494,7 @@ elseif(APPLE)
490494
src/detection/terminalshell/terminalshell_linux.c
491495
src/detection/uptime/uptime_bsd.c
492496
src/detection/users/users_linux.c
497+
src/detection/wallpaper/wallpaper_nosupport.c
493498
src/detection/wifi/wifi_apple.m
494499
src/detection/wmtheme/wmtheme_apple.m
495500
src/util/apple/cf_helpers.c
@@ -532,6 +537,7 @@ elseif(WIN32)
532537
src/detection/temps/temps_windows.cpp
533538
src/detection/uptime/uptime_windows.c
534539
src/detection/users/users_windows.c
540+
src/detection/wallpaper/wallpaper_windows.c
535541
src/detection/wifi/wifi_windows.c
536542
src/detection/wmtheme/wmtheme_windows.c
537543
src/util/windows/getline.c

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ All categories not listed here should work without needing a specific implementa
8989

9090
##### Available Modules
9191
```
92-
Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, Locale, LocalIP, Media, Memory, OpenCL, OpenGL, Packages, Player, Power Adapter, Processes, PublicIP, Separator, OS, Shell, Sound, Swap, Terminal, Terminal Font, Theme, Time, Title, Uptime, Vulkan, Wifi, WM, WMTheme
92+
Battery, Bios, Bluetooth, Board, Break, Brightness, Colors, Command, CPU, CPUUsage, Cursor, Custom, Date, DateTime, DE, Disk, Display, Font, Gamepad, GPU, Host, Icons, Kernel, Locale, LocalIP, Media, Memory, OpenCL, OpenGL, Packages, Player, Power Adapter, Processes, PublicIP, Separator, OS, Shell, Sound, Swap, Terminal, Terminal Font, Theme, Time, Title, Uptime, Vulkan, Wallpaper, Wifi, WM, WMTheme
9393
```
9494

9595
##### Builtin logos

src/common/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ static void defaultConfig(FFinstance* instance)
109109
initModuleArg(&instance->config.date);
110110
initModuleArg(&instance->config.time);
111111
initModuleArg(&instance->config.vulkan);
112+
initModuleArg(&instance->config.wallpaper);
112113
initModuleArg(&instance->config.openGL);
113114
initModuleArg(&instance->config.openCL);
114115
initModuleArg(&instance->config.users);
@@ -369,6 +370,7 @@ static void destroyConfig(FFinstance* instance)
369370
destroyModuleArg(&instance->config.locale);
370371
destroyModuleArg(&instance->config.localIP);
371372
destroyModuleArg(&instance->config.publicIP);
373+
destroyModuleArg(&instance->config.wallpaper);
372374
destroyModuleArg(&instance->config.weather);
373375
destroyModuleArg(&instance->config.wifi);
374376
destroyModuleArg(&instance->config.player);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#ifndef FF_INCLUDED_detection_wallpaper
4+
#define FF_INCLUDED_detection_wallpaper
5+
6+
#include "fastfetch.h"
7+
8+
const char* ffDetectWallpaper(const FFinstance* instance, FFstrbuf* result);
9+
10+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "wallpaper.h"
2+
3+
const char* ffDetectWallpaper(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_UNUSED FFstrbuf* result)
4+
{
5+
return "Not supported on this platform";
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "wallpaper.h"
2+
#include "util/windows/registry.h"
3+
4+
const char* ffDetectWallpaper(FF_MAYBE_UNUSED const FFinstance* instance, FFstrbuf* result)
5+
{
6+
FF_HKEY_AUTO_DESTROY hKey = NULL;
7+
if(!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Control Panel\\Desktop", &hKey, NULL))
8+
return "ffRegOpenKeyForRead(Control Panel\\Desktop) failed";
9+
10+
if(!ffRegReadStrbuf(hKey, L"WallPaper", result, NULL))
11+
return "ffRegReadStrbuf(WallPaper) failed";
12+
13+
return NULL;
14+
}

src/fastfetch.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ static inline void printCommandHelp(const char* command)
223223
"Combined icons"
224224
);
225225
}
226+
else if(strcasecmp(command, "wallpaper-format") == 0)
227+
{
228+
constructAndPrintCommandHelpFormat("wallpaper", "{}", 1,
229+
"Wallpaper image file"
230+
);
231+
}
226232
else if(strcasecmp(command, "font-format") == 0)
227233
{
228234
constructAndPrintCommandHelpFormat("font", "{} [QT], {} [GTK2], {} [GTK3], {} [GTK4]", 4,
@@ -1145,6 +1151,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
11451151
else if(optionParseModuleArgs(key, value, "wm-theme", &instance->config.wmTheme)) {}
11461152
else if(optionParseModuleArgs(key, value, "theme", &instance->config.theme)) {}
11471153
else if(optionParseModuleArgs(key, value, "icons", &instance->config.icons)) {}
1154+
else if(optionParseModuleArgs(key, value, "wallpaper", &instance->config.wallpaper)) {}
11481155
else if(optionParseModuleArgs(key, value, "font", &instance->config.font)) {}
11491156
else if(optionParseModuleArgs(key, value, "cursor", &instance->config.cursor)) {}
11501157
else if(optionParseModuleArgs(key, value, "terminal", &instance->config.terminal)) {}
@@ -1450,6 +1457,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
14501457
ffPrintWMTheme(instance);
14511458
else if(strcasecmp(line, "icons") == 0)
14521459
ffPrintIcons(instance);
1460+
else if(strcasecmp(line, "wallpaper") == 0)
1461+
ffPrintWallpaper(instance);
14531462
else if(strcasecmp(line, "font") == 0)
14541463
ffPrintFont(instance);
14551464
else if(strcasecmp(line, "cursor") == 0)

src/fastfetch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ typedef struct FFconfig
130130
FFModuleArgs shell;
131131
FFModuleArgs display;
132132
FFModuleArgs de;
133+
FFModuleArgs wallpaper;
133134
FFModuleArgs wifi;
134135
FFModuleArgs wm;
135136
FFModuleArgs wmTheme;
@@ -318,6 +319,7 @@ void ffPrintWM(FFinstance* instance);
318319
void ffPrintWMTheme(FFinstance* instance);
319320
void ffPrintTheme(FFinstance* instance);
320321
void ffPrintIcons(FFinstance* instance);
322+
void ffPrintWallpaper(FFinstance* instance);
321323
void ffPrintFont(FFinstance* instance);
322324
void ffPrintCursor(FFinstance* instance);
323325
void ffPrintTerminal(FFinstance* instance);

src/modules/wallpaper.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "fastfetch.h"
2+
#include "common/printing.h"
3+
#include "detection/wallpaper/wallpaper.h"
4+
5+
#define FF_WALLPAPER_MODULE_NAME "Wallpaper"
6+
#define FF_WALLPAPER_NUM_FORMAT_ARGS 1
7+
8+
void ffPrintWallpaper(FFinstance* instance)
9+
{
10+
FF_STRBUF_AUTO_DESTROY wallpaper;
11+
ffStrbufInit(&wallpaper);
12+
const char* error = ffDetectWallpaper(instance, &wallpaper);
13+
14+
if(error)
15+
{
16+
ffPrintError(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper, "%s", error);
17+
return;
18+
}
19+
20+
if(instance->config.wallpaper.outputFormat.length == 0)
21+
{
22+
ffPrintLogoAndKey(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper.key);
23+
ffStrbufPutTo(&wallpaper, stdout);
24+
}
25+
else
26+
{
27+
ffPrintFormat(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper, FF_WALLPAPER_NUM_FORMAT_ARGS, (FFformatarg[]){
28+
{FF_FORMAT_ARG_TYPE_STRBUF, &wallpaper}
29+
});
30+
}
31+
}

0 commit comments

Comments
 (0)