Skip to content

Commit 218dffa

Browse files
Merge pull request #258 from CarterLi/master
[macOS] support Temps, Font; Host pretty print; other improvements
2 parents 4481d98 + f324794 commit 218dffa

39 files changed

+1080
-194
lines changed

CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ set(LIBFASTFETCH_SRC
193193
src/detection/terminalShell.c
194194
src/detection/vulkan.c
195195
src/detection/datetime.c
196-
src/detection/temps.c
197196
src/detection/title.c
198197
src/detection/host/host.c
199198
src/detection/os/os.c
@@ -243,6 +242,7 @@ set(LIBFASTFETCH_SRC
243242
src/modules/colors.c
244243
src/modules/opengl.c
245244
src/modules/opencl.c
245+
src/modules/users.c
246246
)
247247

248248
if(BSD OR APPLE)
@@ -262,6 +262,8 @@ if(LINUX OR ANDROID OR BSD)
262262
list(APPEND LIBFASTFETCH_SRC
263263
src/detection/cpuUsage/cpuUsage_linux.c
264264
src/detection/disk/disk_linux.c
265+
src/detection/poweradapter/poweradapter_linux.c
266+
src/detection/temps/temps_linux.c
265267
)
266268
endif()
267269

@@ -271,7 +273,6 @@ if(LINUX OR BSD)
271273
src/detection/os/os_linux.c
272274
src/detection/gpu/gpu_linux.c
273275
src/detection/battery/battery_linux.c
274-
src/detection/poweradapter/poweradapter_linux.c
275276
src/detection/displayserver/linux/displayserver_linux.c
276277
src/detection/displayserver/linux/wayland.c
277278
src/detection/displayserver/linux/xcb.c
@@ -280,6 +281,7 @@ if(LINUX OR BSD)
280281
src/detection/terminalfont/terminalfont_linux.c
281282
src/detection/media/media_linux.c
282283
src/detection/wmtheme/wmtheme_linux.c
284+
src/detection/font/font_linux.c
283285
)
284286
endif()
285287

@@ -300,6 +302,8 @@ if(APPLE)
300302
src/detection/media/media_apple.m
301303
src/detection/disk/disk_apple.m
302304
src/detection/wmtheme/wmtheme_apple.c
305+
src/detection/temps/temps_apple.c
306+
src/detection/font/font_apple.m
303307
)
304308
endif()
305309

@@ -320,6 +324,7 @@ if(ANDROID)
320324
src/detection/terminalfont/terminalfont_android.c
321325
src/detection/media/media_android.c
322326
src/detection/wmtheme/wmtheme_android.c
327+
src/detection/font/font_android.c
323328
)
324329
endif()
325330

completions/bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,14 @@ __fastfetch_completion()
177177
"--allow-slow-operations"
178178
"--disable-linewrap"
179179
"--hide-cursor"
180+
"--cpu-temp"
181+
"--gpu-temp"
182+
"--battery-temp"
183+
"--font-inline"
180184
"--localip-show-ipv4"
181185
"--localip-show-ipv6"
182186
"--localip-show-loop"
187+
"--localip-name-prefix"
183188
"--escape-bedrock"
184189
"--pipe"
185190
"--title-fqdn"

presets/all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
--structure Title:Separator:OS:Host:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Song:PublicIP:LocalIP:DateTime:Locale:Vulkan:OpenGL:OpenCL:Break:Colors
1+
--structure Title:Separator:OS:Host:Kernel:Uptime:Processes:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:Battery:PowerAdapter:Player:Song:PublicIP:LocalIP:DateTime:Locale:Vulkan:OpenGL:OpenCL:Users:Break:Colors

presets/verbose

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
--wm-theme-format Name: {}
1212
--theme-format Plasma: {}; Plasma colors: {}; Plasma colors pretty: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
1313
--icons-format Plasma: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {}
14-
--font-format Plasma raw: {}; Plasma name: {}; Plasma size: {}; Plasma styles: {}; Plasma pretty: {}; GTK2 raw: {}; GTK2 name: {}; GTK2 size: {}; GTK2 styles: {}; GTK2 pretty: {}; GTK3 raw: {}; GTK3 name: {}; GTK3 size: {}; GTK3 styles: {}; GTK3 pretty: {}; GTK4 raw: {}; GTK4 name: {}; GTK4 size: {}; GTK4 styles: {}; GTK4 pretty: {}; GTK: {}
14+
--font-format Type: {}; Font: {}
1515
--cursor-format Theme: {}; Size: {}
1616
--terminal-format Process: {}; Path: {}; Exe: {}
1717
--terminal-font-format Pretty: {}; Name: {}; Size: {}; Styles: {}

src/common/init.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ static void defaultConfig(FFinstance* instance)
220220
ffStrbufInitA(&instance->config.libplist, 0);
221221
ffStrbufInitA(&instance->config.libcJSON, 0);
222222

223+
instance->config.cpuTemp = false;
224+
instance->config.gpuTemp = false;
225+
instance->config.batteryTemp = false;
226+
223227
instance->config.titleFQDN = false;
224228

225229
ffStrbufInitA(&instance->config.diskFolders, 0);
@@ -229,9 +233,12 @@ static void defaultConfig(FFinstance* instance)
229233

230234
ffStrbufInitA(&instance->config.separatorString, 0);
231235

236+
instance->config.fontInline = true;
237+
232238
instance->config.localIpShowIpV4 = true;
233239
instance->config.localIpShowIpV6 = false;
234240
instance->config.localIpShowLoop = false;
241+
ffStrbufInit(&instance->config.localIpNamePrefix);
235242

236243
instance->config.publicIpTimeout = 0;
237244

src/data/help.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,14 @@ Module specific options:
9494
--disk-folders <folders>: A colon separated list of folder paths for the disk output. Default is "/:/home"
9595
--disk-removable <?value>: Sets if removable volume should be printed. Default is false
9696
--battery-dir <folder>: The directory where the battery folders are. Standard: /sys/class/power_supply/
97+
--cpu-temp <?value>: Detect and display CPU temperature if supported. Default is false
98+
--gpu-temp <?value>: Detect and display GPU temperature if supported. Default is false
99+
--battery-temp <?value>: Detect and display Battery temperature if supported. Default is false
100+
--font-inline <?value>: Display fonts of different DE in one line
97101
--localip-show-ipv4 <?value>: Show ipv4 addresses in local ip module. Default is true
98102
--localip-show-ipv6 <?value>: Show ipv6 addresses in local ip module. Default is false
99103
--localip-show-loop <?value>: Show loop back addresses (127.0.0.1) in local ip module. Default is false
104+
--localip-name-prefix <str>: Show ips with given name prefix only. Default is empty
100105
--public-ip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
101106
--player-name: The name of the player to use
102107
--gl <value>: Sets the opengl context creation library to use. Must be auto, egl, glx or osmesa. Default is auto

src/detection/battery/battery.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55

66
#include "fastfetch.h"
77

8+
#define FF_BATTERY_TEMP_UNSET (0/0.0)
9+
810
typedef struct BatteryResult
911
{
1012
FFstrbuf manufacturer;
1113
FFstrbuf modelName;
1214
FFstrbuf technology;
1315
FFstrbuf capacity;
1416
FFstrbuf status;
17+
double temperature;
1518
} BatteryResult;
1619

1720
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results);

src/detection/battery/battery_apple.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
#include "fastfetch.h"
22
#include "battery.h"
33
#include "util/apple/cf_helpers.h"
4+
#include "detection/temps/temps_apple.h"
45

56
#include <IOKit/IOKitLib.h>
67

8+
static double detectBatteryTemp()
9+
{
10+
FFlist temps;
11+
ffListInit(&temps, sizeof(FFTempValue));
12+
13+
ffDetectCoreTemps(FF_TEMP_BATTERY, &temps);
14+
15+
if(temps.length == 0)
16+
return FF_BATTERY_TEMP_UNSET;
17+
18+
double result = 0;
19+
for(uint32_t i = 0; i < temps.length; ++i)
20+
{
21+
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
22+
result += tempValue->value;
23+
//TODO: do we really need this?
24+
ffStrbufDestroy(&tempValue->name);
25+
ffStrbufDestroy(&tempValue->deviceClass);
26+
}
27+
result /= temps.length;
28+
ffListDestroy(&temps);
29+
return result;
30+
}
31+
732
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
833
{
934
FF_UNUSED(instance);
@@ -69,6 +94,11 @@ const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results)
6994
else
7095
ffStrbufAppendS(&battery->status, "");
7196

97+
if(instance->config.batteryTemp)
98+
battery->temperature = detectBatteryTemp();
99+
else
100+
battery->temperature = FF_BATTERY_TEMP_UNSET;
101+
72102
CFRelease(properties);
73103
IOObjectRelease(registryEntry);
74104
}

src/detection/battery/battery_linux.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static void parseBattery(FFstrbuf* dir, FFlist* results)
7070
ffStrbufAppendS(dir, "/status");
7171
ffReadFileBuffer(dir->chars, &result->status);
7272
ffStrbufSubstrBefore(dir, dirLength);
73+
74+
result->temperature = FF_BATTERY_TEMP_UNSET;
7375
}
7476

7577
const char* ffDetectBatteryImpl(FFinstance* instance, FFlist* results) {

src/detection/cpu/cpu_apple.c

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cpu.h"
22
#include "common/sysctl.h"
3+
#include "detection/temps/temps_apple.h"
34

45
static double getFrequency(const char* propName)
56
{
@@ -12,33 +13,64 @@ static double getFrequency(const char* propName)
1213
return herz / 1000.0; //to GHz
1314
}
1415

16+
static double detectCpuTemp(const FFstrbuf* cpuName)
17+
{
18+
FFlist temps;
19+
ffListInit(&temps, sizeof(FFTempValue));
20+
21+
if(ffStrbufStartsWithS(cpuName, "Apple M1"))
22+
ffDetectCoreTemps(FF_TEMP_CPU_M1X, &temps);
23+
else if(ffStrbufStartsWithS(cpuName, "Apple M2"))
24+
ffDetectCoreTemps(FF_TEMP_CPU_M2X, &temps);
25+
else //TODO: PPC?
26+
ffDetectCoreTemps(FF_TEMP_CPU_X64, &temps);
27+
28+
if(temps.length == 0)
29+
return FF_CPU_TEMP_UNSET;
30+
31+
double result = 0;
32+
for(uint32_t i = 0; i < temps.length; ++i)
33+
{
34+
FFTempValue* tempValue = (FFTempValue*)ffListGet(&temps, i);
35+
result += tempValue->value;
36+
//TODO: do we really need this?
37+
ffStrbufDestroy(&tempValue->name);
38+
ffStrbufDestroy(&tempValue->deviceClass);
39+
}
40+
result /= temps.length;
41+
ffListDestroy(&temps);
42+
return result;
43+
}
44+
1545
void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
1646
{
1747
FF_UNUSED(instance);
1848

19-
//TODO find a way to detect this
20-
cpu->temperature = FF_CPU_TEMP_UNSET;
21-
22-
if(cached)
23-
return;
49+
if(!cached)
50+
{
51+
ffSysctlGetString("machdep.cpu.brand_string", &cpu->name);
52+
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
2453

25-
ffSysctlGetString("machdep.cpu.brand_string", &cpu->name);
26-
ffSysctlGetString("machdep.cpu.vendor", &cpu->vendor);
54+
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
55+
if(cpu->coresPhysical == 1)
56+
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
2757

28-
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu_max", 1);
29-
if(cpu->coresPhysical == 1)
30-
cpu->coresPhysical = (uint16_t) ffSysctlGetInt("hw.physicalcpu", 1);
58+
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
59+
if(cpu->coresLogical == 1)
60+
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
3161

32-
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.logicalcpu_max", 1);
33-
if(cpu->coresLogical == 1)
34-
cpu->coresLogical = (uint16_t) ffSysctlGetInt("hw.ncpu", 1);
62+
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
63+
if(cpu->coresOnline == 1)
64+
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
3565

36-
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.logicalcpu", 1);
37-
if(cpu->coresOnline == 1)
38-
cpu->coresOnline = (uint16_t) ffSysctlGetInt("hw.activecpu", 1);
66+
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
67+
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
68+
if(cpu->frequencyMax == 0.0)
69+
cpu->frequencyMax = getFrequency("hw.cpufrequency");
70+
}
3971

40-
cpu->frequencyMin = getFrequency("hw.cpufrequency_min");
41-
cpu->frequencyMax = getFrequency("hw.cpufrequency_max");
42-
if(cpu->frequencyMax == 0.0)
43-
cpu->frequencyMax = getFrequency("hw.cpufrequency");
72+
if (instance->config.cpuTemp)
73+
cpu->temperature = detectCpuTemp(&cpu->name);
74+
else
75+
cpu->temperature = FF_CPU_TEMP_UNSET;
4476
}

0 commit comments

Comments
 (0)