Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_LIBPLIST "Enable libplist" ON "APPLE" OFF)
cmake_dependent_option(ENABLE_LIBCJSON "Enable libcjson" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)

option(BUILD_TESTS "Build tests" OFF) # Also create test executables
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
Expand Down Expand Up @@ -338,6 +339,11 @@ if(HAVE_SYSINFO_H)
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_SYSINFO_H)
endif()

CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX_H)
if(HAVE_UTMPX_H)
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX_H)
endif()

function(ff_lib_enable VARNAME)
if(NOT ENABLE_${VARNAME})
return()
Expand Down Expand Up @@ -384,6 +390,7 @@ ff_lib_enable(OSMESA osmesa)
ff_lib_enable(OPENCL OpenCL)
ff_lib_enable(LIBPLIST libplist-2.0)
ff_lib_enable(LIBCJSON libcjson)
ff_lib_enable(FREETYPE freetype2)

if(APPLE)
target_link_libraries(libfastfetch
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following libraries are used if present at runtime:
* [`librpm`](http://rpm.org/): Slower fallback for rpm package count. Needed on openSUSE.
* [`libplist`](https://github.com/libimobiledevice/libplist): Binary `plist` file parser ( macOS ). Needed for iTerm2 Terminal font and WM Theme.
* [`libcJSON`](https://github.com/DaveGamble/cJSON): Needed for Windows Terminal font ( WSL ).
* [`freetype`](https://www.freetype.org/): Needed for Termux font detection ( Android ).

## Support status
All categories not listed here should work without needing a specific implementation.
Expand Down Expand Up @@ -82,7 +83,7 @@ KDE Plasma, Gnome, Cinnamon, Mate, XFCE4, LXQt

##### Terminal fonts
```
Konsole, Gnome Terminal, Tilix, XFCE4 Terminal, Alacritty, LXTerminal, iTerm2, Apple Terminal, TTY, Windows Terminal
Konsole, Gnome Terminal, Tilix, XFCE4 Terminal, Alacritty, LXTerminal, iTerm2, Apple Terminal, TTY, Windows Terminal, Termux
```

## Building
Expand Down
3 changes: 3 additions & 0 deletions completions/bash
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ __fastfetch_completion()
"--opencl-key"
"--opencl-format"
"--opencl-error"
"--users-key"
"--users-format"
"--users-error"
)

local FF_OPTIONS_PATH=(
Expand Down
13 changes: 13 additions & 0 deletions src/common/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ static void defaultConfig(FFinstance* instance)
initModuleArg(&instance->config.vulkan);
initModuleArg(&instance->config.openGL);
initModuleArg(&instance->config.openCL);
initModuleArg(&instance->config.users);

ffStrbufInitA(&instance->config.libPCI, 0);
ffStrbufInitA(&instance->config.libVulkan, 0);
Expand All @@ -219,6 +220,7 @@ static void defaultConfig(FFinstance* instance)
ffStrbufInitA(&instance->config.libOpenCL, 0);
ffStrbufInitA(&instance->config.libplist, 0);
ffStrbufInitA(&instance->config.libcJSON, 0);
ffStrbufInitA(&instance->config.libfreetype, 0);

instance->config.cpuTemp = false;
instance->config.gpuTemp = false;
Expand Down Expand Up @@ -356,6 +358,8 @@ static void exitSignalHandler(int signal)

void ffStart(FFinstance* instance)
{
ffPrepareCPUUsage();

if(instance->config.multithreading)
startDetectionThreads(instance);

Expand Down Expand Up @@ -477,6 +481,15 @@ void ffListFeatures()
#ifdef FF_HAVE_OPENCL
"opencl\n"
#endif
#ifdef FF_HAVE_LIBPLIST
"libplist\n"
#endif
#ifdef FF_HAVE_LIBCJSON
"libcjson\n"
#endif
#ifdef FF_HAVE_FREETYPE
"freetype"
#endif
""
, stdout);
}
4 changes: 4 additions & 0 deletions src/data/config_user.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
#--vulkan-key Vulkan
#--opengl-key OpenGL
#--opencl-key OpenCL
#--users-key Users

# Format options:
# Sets the format string for module values.
Expand Down Expand Up @@ -259,6 +260,7 @@
#--vulkan-format
#--opengl-format
#--opencl-format
#--users-format

# Error options:
# Sets the format string to use if an error occured
Expand Down Expand Up @@ -299,6 +301,7 @@
#--vulkan-error
#--opengl-error
#--opencl-error
#--users-error

# Library options:
# Sets an user specific path to a library to load.
Expand All @@ -325,3 +328,4 @@
#--lib-opencl /usr/lib/libOpenCL.so
#--lib-plist /usr/local/bin/libplist-2.0.dylib
#--lib-cjson /usr/lib/libcjson.so
#--lib-freetype /data/data/com.termux/files/usr/lib
2 changes: 1 addition & 1 deletion src/detection/cpuUsage/cpuUsage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#ifndef FF_INCLUDED_detection_cpu_cpuUsage
#define FF_INCLUDED_detection_cpu_cpuUsage

const char* ffGetCpuUsagePercent(double* result);
const char* ffGetCpuUsageInfo(long* inUseAll, long* totalAll);

#endif
22 changes: 2 additions & 20 deletions src/detection/cpuUsage/cpuUsage_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

#include <mach/processor_info.h>
#include <mach/mach_host.h>
#include <unistd.h>

static const char* getCpuUsageInfo(long* inUseAll, long* totalAll)
const char* ffGetCpuUsageInfo(long* inUseAll, long* totalAll)
{
natural_t numCPUs = 0U;
processor_info_array_t cpuInfo;
mach_msg_type_number_t numCpuInfo;
*inUseAll = *totalAll = 0;

if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numCPUs, &cpuInfo, &numCpuInfo) != KERN_SUCCESS)
return "host_processor_info() failed";
Expand All @@ -26,21 +26,3 @@ static const char* getCpuUsageInfo(long* inUseAll, long* totalAll)
}
return NULL;
}

const char* ffGetCpuUsagePercent(double* result)
{
long inUseAll1 = 0, totalAll1 = 0;
const char* error = getCpuUsageInfo(&inUseAll1, &totalAll1);
if(error)
return error;

sleep(1);

long inUseAll2 = 0, totalAll2 = 0;
error = getCpuUsageInfo(&inUseAll2, &totalAll2);
if(error)
return error;

*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;
return NULL;
}
35 changes: 7 additions & 28 deletions src/detection/cpuUsage/cpuUsage_linux.c
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
#include "fastfetch.h"
#include "cpuUsage.h"

#include <unistd.h>
#include <stdio.h>

static const char* getCpuUsageInfo(FILE* procStat, long* inUseAll, long* totalAll)
const char* ffGetCpuUsageInfo(long* inUseAll, long* totalAll)
{
long user, nice, system, idle, iowait, irq, softirq;

FILE* procStat = fopen("/proc/stat", "r");
if(procStat == NULL)
return "fopen(\"""/proc/stat\", \"r\") == NULL";

if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0)
{
fclose(procStat);
return "fscanf() failed";
}
*inUseAll = user + nice + system;
*totalAll = *inUseAll + idle + iowait + irq + softirq;
return NULL;
}

const char* ffGetCpuUsagePercent(double* result)
{
FILE* procStat = fopen("/proc/stat", "r");
if(procStat == NULL)
return "fopen(\"""/proc/stat\", \"r\") == NULL";

const char* error = NULL;
long inUseAll1 = 0, totalAll1 = 0;
error = getCpuUsageInfo(procStat, &inUseAll1, &totalAll1);
if(error)
goto exit;

sleep(1);
rewind(procStat);

long inUseAll2 = 0, totalAll2 = 0;
error = getCpuUsageInfo(procStat, &inUseAll2, &totalAll2);
if(error)
goto exit;

*result = (double)(inUseAll2 - inUseAll1) / (double)(totalAll2 - totalAll1) * 100;

exit:
fclose(procStat);
return error;

return NULL;
}
1 change: 1 addition & 0 deletions src/detection/font/font_android.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "fastfetch.h"
#include "common/font.h"

const char* ffDetectFontImpl(FFinstance* instance, FFlist* result)
Expand Down
69 changes: 68 additions & 1 deletion src/detection/terminalfont/terminalfont_android.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,74 @@
#include "fastfetch.h"
#include "terminalfont.h"
#include "detection/terminalshell.h"
#include "common/io.h"

#include <sys/stat.h>

#ifdef FF_HAVE_FREETYPE
#include "common/library.h"
#include <ft2build.h>
#include FT_FREETYPE_H
#endif

#define FF_TERMUX_FONT_PATH FASTFETCH_TARGET_DIR_HOME "/.termux/font.ttf"

const char* detectTermux(const FFinstance* instance, FFTerminalFontResult* terminalFont)
{
#ifdef FF_HAVE_FREETYPE

FF_LIBRARY_LOAD(freetype, &instance->config.libfreetype, "dlopen libfreetype"FF_LIBRARY_EXTENSION " failed", "libfreetype"FF_LIBRARY_EXTENSION, 2)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Init_FreeType);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_New_Face);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Done_Face);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(freetype, FT_Done_FreeType);

FT_Library library = NULL;
FT_Face face = NULL;
const char* error = NULL;

if(ffFT_Init_FreeType(&library))
{
error = "FT_Init_FreeType() failed";
goto exit;
}

if(ffFT_New_Face(library, FF_TERMUX_FONT_PATH, 0, &face ))
{
error = "FT_NEW_Face(" FF_TERMUX_FONT_PATH ") failed";
goto exit;
}

ffFontInitCopy(&terminalFont->font, face->family_name);

exit:
if(face) ffFT_Done_Face(face);
if(library) ffFT_Done_FreeType(library);
dlclose(freetype);

return error;

#else

FF_UNUSED(terminalFont);
ffStrbufSetS(&terminalFont->error, "fastfetch is built without freetype2 support");

#endif
}

void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
{
FF_UNUSED(instance, terminalShell, terminalFont);
if(ffStrbufCompS(&terminalShell->terminalProcessName, "Termux") != 0)
{
ffStrbufSetS(&terminalFont->error, "Unsupported terminal");
return;
}

if(!ffFileExists(FF_TERMUX_FONT_PATH, S_IFREG))
{
ffFontInitCopy(&terminalFont->font, "monospace");
return;
}

ffStrbufSetS(&terminalFont->error, detectTermux(instance, terminalFont));
}
8 changes: 8 additions & 0 deletions src/fastfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,12 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.openCL.outputFormat);
else if(strcasecmp(key, "--opencl-error") == 0)
optionParseString(key, value, &instance->config.openCL.errorFormat);
else if(strcasecmp(key, "--users-key") == 0)
optionParseString(key, value, &instance->config.users.key);
else if(strcasecmp(key, "--users-format") == 0)
optionParseString(key, value, &instance->config.users.outputFormat);
else if(strcasecmp(key, "--users-error") == 0)
optionParseString(key, value, &instance->config.users.errorFormat);

///////////////////
//Library options//
Expand All @@ -1208,6 +1214,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
optionParseString(key, value, &instance->config.libPCI);
else if(strcasecmp(key, "--lib-vulkan") == 0)
optionParseString(key, value, &instance->config.libVulkan);
else if(strcasecmp(key, "--lib-freetype") == 0)
optionParseString(key, value, &instance->config.libfreetype);
else if(strcasecmp(key, "--lib-wayland") == 0)
optionParseString(key, value, &instance->config.libWayland);
else if(strcasecmp(key, "--lib-xcb-randr") == 0)
Expand Down
3 changes: 3 additions & 0 deletions src/fastfetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ typedef struct FFconfig
FFModuleArgs vulkan;
FFModuleArgs openGL;
FFModuleArgs openCL;
FFModuleArgs users;

FFstrbuf libPCI;
FFstrbuf libVulkan;
Expand All @@ -151,6 +152,7 @@ typedef struct FFconfig
FFstrbuf libOpenCL;
FFstrbuf libplist;
FFstrbuf libcJSON;
FFstrbuf libfreetype;

bool cpuTemp;
bool gpuTemp;
Expand Down Expand Up @@ -233,6 +235,7 @@ void ffLogoBuiltinListAutocompletion();
//Common

void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs);
void ffPrepareCPUUsage();

//Printing

Expand Down
2 changes: 1 addition & 1 deletion src/flashfetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ int main(int argc, char** argv)
ffPrintTerminal(&instance);
ffPrintTerminalFont(&instance);
ffPrintCPU(&instance);
//ffPrintCPUUsage(&instance);
ffPrintGPU(&instance);
ffPrintMemory(&instance);
//ffPrintSwap(&instance);
Expand All @@ -45,6 +44,7 @@ int main(int argc, char** argv)
//ffPrintSong(&instance);
//ffPrintLocalIp(&instance);
//ffPrintPublicIp(&instance);
//ffPrintCPUUsage(&instance);
ffPrintLocale(&instance);
//ffPrintDateTime(&instance);
//ffPrintDate(&instance);
Expand Down
Loading