2021-02-18 22:25:36 +01:00
#pragma once
#ifndef FASTFETCH_INCLUDED
#define FASTFETCH_INCLUDED
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
2021-03-27 15:39:56 +01:00
#include <stdarg.h>
2021-02-18 22:25:36 +01:00
#include <pwd.h>
#include <sys/utsname.h>
#include <sys/sysinfo.h>
2021-04-15 18:59:26 +02:00
#include "fastfetch_config.h"
2021-03-19 20:57:07 +01:00
#include "util/FFstrbuf.h"
2021-04-24 13:05:43 +02:00
#include "util/FFlist.h"
2021-03-19 20:57:07 +01:00
2021-04-09 14:07:05 +02:00
#define UNUSED(...) (void)(__VA_ARGS__)
2021-02-18 22:25:36 +01:00
#define FASTFETCH_TEXT_MODIFIER_BOLT "\033[1m"
2021-02-19 16:23:41 +01:00
#define FASTFETCH_TEXT_MODIFIER_ERROR "\033[1;31m"
2021-02-18 22:25:36 +01:00
#define FASTFETCH_TEXT_MODIFIER_RESET "\033[0m"
2021-02-27 18:30:05 +01:00
typedef struct FFconfig
2021-02-18 22:25:36 +01:00
{
2021-06-13 14:23:35 +02:00
struct
{
char * lines ;
const char * colors [ 9 ]; // colors[0] is used as key color
bool freeable ;
bool allLinesSameLength ; // a performance optimization
} logo ;
uint16_t logoKeySpacing ;
2021-05-15 12:36:25 +02:00
FFstrbuf separator ;
2021-02-25 18:38:00 +01:00
int16_t offsetx ;
2021-03-19 20:57:07 +01:00
FFstrbuf color ;
2021-04-15 18:59:26 +02:00
uint32_t titleLength ;
2021-02-25 18:38:00 +01:00
bool colorLogo ;
2021-02-19 16:23:41 +01:00
bool showErrors ;
2021-02-22 16:52:51 +01:00
bool recache ;
2021-04-22 21:41:42 +02:00
bool cacheSave ;
2021-03-19 21:23:15 +01:00
bool printRemainingLogo ;
2021-05-09 21:41:17 +02:00
bool allowSlowOperations ;
2021-03-03 21:03:12 +01:00
2021-03-19 20:57:07 +01:00
FFstrbuf osFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf osKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf hostFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf hostKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf kernelFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf kernelKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf uptimeFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf uptimeKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf packagesFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf packagesKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf shellFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf shellKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf resolutionFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf resolutionKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf deFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf deKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf wmFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf wmKey ;
2021-04-03 23:10:14 +02:00
FFstrbuf wmThemeFormat ;
FFstrbuf wmThemeKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf themeFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf themeKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf iconsFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf iconsKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf fontFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf fontKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf terminalFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf terminalKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf termFontFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf termFontKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf cpuFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf cpuKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf gpuFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf gpuKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf memoryFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf memoryKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf diskFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf diskKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf batteryFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf batteryKey ;
2021-03-19 20:57:07 +01:00
FFstrbuf localeFormat ;
2021-04-03 11:39:59 +02:00
FFstrbuf localeKey ;
2021-03-27 18:14:19 +01:00
2021-03-19 20:57:07 +01:00
FFstrbuf libPCI ;
FFstrbuf libX11 ;
FFstrbuf libXrandr ;
2021-04-16 16:49:33 +02:00
FFstrbuf libWayland ;
2021-05-02 18:52:42 +02:00
FFstrbuf libGIO ;
2021-04-05 23:42:07 +02:00
FFstrbuf libDConf ;
2021-05-11 20:06:17 +02:00
FFstrbuf libXFConf ;
2021-06-08 20:01:29 +02:00
FFstrbuf libSQLite ;
2021-03-03 21:03:12 +01:00
2021-03-28 15:38:52 +02:00
FFstrbuf diskFolders ;
2021-04-24 13:05:43 +02:00
FFstrbuf batteryDir ;
2021-02-27 18:30:05 +01:00
} FFconfig ;
2021-02-19 16:23:41 +01:00
2021-04-22 21:41:42 +02:00
typedef struct FFOSResult
{
FFstrbuf systemName ;
FFstrbuf name ;
FFstrbuf prettyName ;
FFstrbuf id ;
FFstrbuf idLike ;
FFstrbuf variant ;
FFstrbuf variantID ;
FFstrbuf version ;
FFstrbuf versionID ;
FFstrbuf codename ;
FFstrbuf buildID ;
FFstrbuf architecture ;
FFstrbuf error ;
} FFOSResult ;
typedef struct FFPlasmaResult
{
FFstrbuf widgetStyle ;
FFstrbuf colorScheme ;
FFstrbuf icons ;
FFstrbuf font ;
} FFPlasmaResult ;
typedef struct FFGTKResult
2021-04-16 20:22:38 +02:00
{
FFstrbuf theme ;
FFstrbuf icons ;
FFstrbuf font ;
2021-04-22 21:41:42 +02:00
} FFGTKResult ;
2021-06-14 23:22:14 +02:00
typedef struct FFTerminalShellResult
2021-04-22 21:41:42 +02:00
{
2021-06-14 23:22:14 +02:00
FFstrbuf shellProcessName ;
FFstrbuf shellExe ;
const char * shellExeName ; //pointer to a char in shellExe
FFstrbuf shellVersion ;
FFstrbuf terminalProcessName ;
FFstrbuf terminalExe ;
const char * terminalExeName ; //pointer to a char in terminalExe
FFstrbuf userShellExe ;
const char * userShellExeName ; //pointer to a char in userShellExe
FFstrbuf userShellVersion ;
} FFTerminalShellResult ;
2021-04-22 21:41:42 +02:00
2021-05-01 13:03:30 +02:00
typedef struct FFWMDEResult
2021-04-22 21:41:42 +02:00
{
2021-05-01 13:03:30 +02:00
const char * sessionDesktop ;
FFstrbuf wmProcessName ;
FFstrbuf wmPrettyName ;
FFstrbuf wmProtocolName ;
FFstrbuf deProcessName ;
FFstrbuf dePrettyName ;
FFstrbuf deVersion ;
} FFWMDEResult ;
2021-04-16 20:22:38 +02:00
2021-02-27 18:30:05 +01:00
typedef struct FFstate
{
2021-06-13 14:23:35 +02:00
uint32_t logoWidth ;
2021-02-18 22:25:36 +01:00
struct passwd * passwd ;
struct utsname utsname ;
2021-02-22 16:52:51 +01:00
struct sysinfo sysinfo ;
2021-05-07 14:55:43 +02:00
FFlist configDirs ;
2021-05-08 12:14:55 +02:00
FFstrbuf cacheDir ;
2021-02-18 22:25:36 +01:00
} FFstate ;
2021-02-27 18:30:05 +01:00
typedef struct FFinstance
{
FFconfig config ;
FFstate state ;
} FFinstance ;
2021-03-19 20:57:07 +01:00
typedef enum FFformatargtype
{
2021-04-24 21:42:48 +02:00
FF_FORMAT_ARG_TYPE_NULL = 0 ,
2021-03-19 20:57:07 +01:00
FF_FORMAT_ARG_TYPE_UINT ,
FF_FORMAT_ARG_TYPE_UINT8 ,
FF_FORMAT_ARG_TYPE_INT ,
FF_FORMAT_ARG_TYPE_STRING ,
FF_FORMAT_ARG_TYPE_STRBUF ,
2021-05-23 19:40:34 +02:00
FF_FORMAT_ARG_TYPE_DOUBLE ,
FF_FORMAT_ARG_TYPE_LIST
2021-03-19 20:57:07 +01:00
} FFformatargtype ;
typedef struct FFformatarg
{
FFformatargtype type ;
2021-04-03 11:39:59 +02:00
const void * value ;
2021-03-19 20:57:07 +01:00
} FFformatarg ;
2021-04-15 18:59:26 +02:00
typedef struct FFcache
{
FILE * value ;
FILE * split ;
} FFcache ;
2021-05-05 20:20:41 +02:00
typedef enum FFvarianttype
{
FF_VARIANT_TYPE_STRING ,
FF_VARIANT_TYPE_BOOL
} FFvarianttype ;
2021-05-08 17:56:56 +02:00
typedef union FFvariant
2021-05-05 20:20:41 +02:00
{
2021-05-08 17:56:56 +02:00
const char * strValue ;
2021-05-08 18:58:40 +02:00
struct
{
bool boolValueSet ;
bool boolValue ;
};
2021-05-05 20:20:41 +02:00
} FFvariant ;
2021-05-23 19:40:34 +02:00
typedef struct FFfont
{
FFstrbuf pretty ;
FFstrbuf name ;
FFstrbuf size ;
FFlist styles ;
} FFfont ;
2021-04-09 14:07:05 +02:00
/*************************/
/* Common util functions */
/*************************/
//common/init.c
void ffInitInstance ( FFinstance * instance );
void ffFinish ( FFinstance * instance );
//common/threading.c
2021-04-07 17:36:03 +02:00
void ffStartCalculationThreads ( FFinstance * instance );
2021-04-09 14:07:05 +02:00
//common/io.c
2021-04-15 18:59:26 +02:00
void ffPrintLogoAndKey ( FFinstance * instance , const char * moduleName , uint8_t moduleIndex , const FFstrbuf * customKeyFormat );
void ffPrintError ( FFinstance * instance , const char * moduleName , uint8_t moduleIndex , const FFstrbuf * customKeyFormat , const FFstrbuf * formatString , uint32_t numFormatArgs , const char * message , ...);
void ffPrintFormatString ( FFinstance * instance , const char * moduleName , uint8_t moduleIndex , const FFstrbuf * customKeyFormat , const FFstrbuf * formatString , const FFstrbuf * error , uint32_t numArgs , const FFformatarg * arguments );
2021-04-22 21:41:42 +02:00
void ffGetCacheFilePath ( FFinstance * instance , const char * moduleName , const char * extension , FFstrbuf * buffer );
void ffReadCacheFile ( FFinstance * instance , const char * moduleName , const char * extension , FFstrbuf * buffer );
void ffWriteCacheFile ( FFinstance * instance , const char * moduleName , const char * extension , FFstrbuf * content );
2021-04-15 18:59:26 +02:00
bool ffPrintFromCache ( FFinstance * instance , const char * moduleName , const FFstrbuf * customKeyFormat , const FFstrbuf * formatString , uint32_t numArgs );
void ffPrintAndSaveToCache ( FFinstance * instance , const char * moduleName , const FFstrbuf * customKeyFormat , const FFstrbuf * value , const FFstrbuf * formatString , uint32_t numArgs , const FFformatarg * arguments );
void ffPrintAndAppendToCache ( FFinstance * instance , const char * moduleName , uint8_t moduleIndex , const FFstrbuf * customKeyFormat , FFcache * cache , const FFstrbuf * value , const FFstrbuf * formatString , uint32_t numArgs , const FFformatarg * arguments );
void ffCacheValidate ( FFinstance * instance );
void ffCacheOpenWrite ( FFinstance * instance , const char * moduleName , FFcache * cache );
void ffCacheClose ( FFcache * cache );
2021-04-18 15:19:21 +02:00
void ffAppendFDContent ( int fd , FFstrbuf * buffer );
2021-06-13 14:23:35 +02:00
bool ffAppendFileContent ( const char * fileName , FFstrbuf * buffer ); //returns true if open() succeeds. This is used to differentiate between <file not found> and <empty file>
bool ffGetFileContent ( const char * fileName , FFstrbuf * buffer );
2021-04-25 11:56:01 +02:00
bool ffWriteFDContent ( int fd , const FFstrbuf * content );
2021-04-22 21:41:42 +02:00
void ffWriteFileContent ( const char * fileName , const FFstrbuf * buffer );
2021-04-15 18:59:26 +02:00
2021-05-07 11:02:09 +02:00
// They return true if the file was found, independently if regex was found
2021-05-13 12:27:44 +02:00
bool ffParsePropFile ( const char * file , const char * start , FFstrbuf * buffer );
bool ffParsePropFileHome ( FFinstance * instance , const char * relativeFile , const char * start , FFstrbuf * buffer );
bool ffParsePropFileConfig ( FFinstance * instance , const char * relativeFile , const char * start , FFstrbuf * buffer );
2021-02-27 18:30:05 +01:00
2021-04-18 15:19:21 +02:00
//common/processing.c
2021-05-01 16:54:59 +02:00
void ffProcessAppendStdOut ( FFstrbuf * buffer , char * const argv []);
2021-04-18 15:19:21 +02:00
2021-04-09 14:07:05 +02:00
//common/logo.c
2021-06-13 14:23:35 +02:00
void ffLoadLogoSet ( FFinstance * instance , const char * logo );
2021-04-22 21:41:42 +02:00
void ffLoadLogo ( FFinstance * instance );
2021-02-27 18:30:05 +01:00
void ffPrintLogoLine ( FFinstance * instance );
2021-03-19 21:23:15 +01:00
void ffPrintRemainingLogo ( FFinstance * instance );
2021-02-18 22:25:36 +01:00
2021-02-27 18:30:05 +01:00
#ifndef FLASHFETCH_BUILD_FLASHFATCH
2021-04-09 14:07:05 +02:00
void ffListLogos ();
2021-06-13 14:23:35 +02:00
void ffPrintLogos ( FFinstance * instance );
2021-02-27 18:30:05 +01:00
#endif
2021-02-18 22:25:36 +01:00
2021-04-09 14:07:05 +02:00
//common/format.c
2021-04-16 17:46:50 +02:00
void ffFormatAppendFormatArg ( FFstrbuf * buffer , const FFformatarg * formatarg );
2021-04-15 18:59:26 +02:00
void ffParseFormatString ( FFstrbuf * buffer , const FFstrbuf * formatstr , const FFstrbuf * error , uint32_t numArgs , const FFformatarg * arguments );
2021-04-09 14:07:05 +02:00
//common/parsing.c
2021-04-22 21:41:42 +02:00
void ffGetGtkPretty ( FFstrbuf * buffer , const FFstrbuf * gtk2 , const FFstrbuf * gtk3 , const FFstrbuf * gtk4 );
2021-05-23 19:40:34 +02:00
void ffFontInitQt ( FFfont * font , const char * data );
void ffFontInitPango ( FFfont * font , const char * data );
void ffFontInitCopy ( FFfont * font , const char * name );
void ffFontDestroy ( FFfont * font );
2021-05-13 12:27:44 +02:00
bool ffGetPropValue ( const char * line , const char * start , FFstrbuf * buffer );
2021-05-16 21:02:06 +02:00
bool ffGetPropValueFromLines ( const char * lines , const char * start , FFstrbuf * buffer );
2021-04-05 19:25:34 +02:00
2021-05-04 19:48:23 +02:00
//common/settings.c
2021-05-08 17:56:56 +02:00
FFvariant ffSettingsGetDConf ( FFinstance * instance , const char * key , FFvarianttype type );
2021-05-20 20:06:08 +02:00
FFvariant ffSettingsGetGSettings ( FFinstance * instance , const char * schemaName , const char * path , const char * key , FFvarianttype type );
2021-05-08 17:56:56 +02:00
FFvariant ffSettingsGet ( FFinstance * instance , const char * dconfKey , const char * gsettingsSchemaName , const char * gsettingsPath , const char * gsettingsKey , FFvarianttype type );
2021-05-11 20:06:17 +02:00
FFvariant ffSettingsGetXFConf ( FFinstance * instance , const char * channelName , const char * propertyName , FFvarianttype type );
2021-05-01 16:01:59 +02:00
2021-06-08 20:01:29 +02:00
uint32_t ffSettingsGetSQLiteColumnCount ( FFinstance * instance , const char * fileName , const char * tableName );
2021-04-28 19:53:30 +02:00
//common/detectPlasma.c
const FFPlasmaResult * ffDetectPlasma ( FFinstance * instance );
2021-04-22 21:41:42 +02:00
2021-04-28 19:53:30 +02:00
//common/detectGTK.c
const FFGTKResult * ffDetectGTK2 ( FFinstance * instance );
const FFGTKResult * ffDetectGTK4 ( FFinstance * instance );
const FFGTKResult * ffDetectGTK3 ( FFinstance * instance );
2021-04-09 14:07:05 +02:00
2021-05-01 13:03:30 +02:00
//common/detectWMDE.c
const FFWMDEResult * ffDetectWMDE ( FFinstance * instance );
2021-06-14 23:22:14 +02:00
//common/detectTerminalShell.c
const FFTerminalShellResult * ffDetectTerminalShell ( FFinstance * instance );
2021-04-28 19:53:30 +02:00
/********************/
/* Module functions */
/********************/
2021-04-09 14:07:05 +02:00
2021-04-28 19:53:30 +02:00
//Common
const FFOSResult * ffDetectOS ( FFinstance * instance );
//Printing
2021-03-11 17:21:18 +01:00
2021-02-27 19:22:28 +01:00
void ffPrintCustom ( FFinstance * instance , const char * key , const char * value );
void ffPrintBreak ( FFinstance * instance );
void ffPrintTitle ( FFinstance * instance );
2021-05-15 12:36:25 +02:00
void ffPrintSeparator ( FFinstance * instance );
2021-02-27 19:22:28 +01:00
void ffPrintOS ( FFinstance * instance );
void ffPrintHost ( FFinstance * instance );
void ffPrintKernel ( FFinstance * instance );
void ffPrintUptime ( FFinstance * instance );
void ffPrintPackages ( FFinstance * instance );
void ffPrintShell ( FFinstance * instance );
void ffPrintResolution ( FFinstance * instance );
void ffPrintDesktopEnvironment ( FFinstance * instance );
2021-03-05 21:38:35 +01:00
void ffPrintWM ( FFinstance * instance );
2021-04-03 23:10:14 +02:00
void ffPrintWMTheme ( FFinstance * instance );
2021-02-27 19:22:28 +01:00
void ffPrintTheme ( FFinstance * instance );
void ffPrintIcons ( FFinstance * instance );
void ffPrintFont ( FFinstance * instance );
void ffPrintTerminal ( FFinstance * instance );
2021-03-11 17:21:18 +01:00
void ffPrintTerminalFont ( FFinstance * instance );
2021-02-27 19:22:28 +01:00
void ffPrintCPU ( FFinstance * instance );
void ffPrintGPU ( FFinstance * instance );
void ffPrintMemory ( FFinstance * instance );
void ffPrintDisk ( FFinstance * instance );
void ffPrintBattery ( FFinstance * instance );
void ffPrintLocale ( FFinstance * instance );
void ffPrintColors ( FFinstance * instance );
2021-02-18 22:25:36 +01:00
2021-03-27 18:14:19 +01:00
#endif