2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
2021-04-15 18:59:26 +02:00
#define FF_THEME_MODULE_NAME "Theme"
#define FF_THEME_NUM_FORMAT_ARGS 7
2021-02-27 18:30:05 +01:00
void ffPrintTheme ( FFinstance * instance )
2021-02-18 22:25:36 +01:00
{
2022-01-10 14:41:34 +01:00
#ifdef __ANDROID__
ffPrintError ( instance , FF_THEME_MODULE_NAME , 0 , & instance -> config . themeKey , & instance -> config . themeFormat , FF_THEME_NUM_FORMAT_ARGS , "Theme detection is not supported on Android" );
return ;
#endif
2022-01-02 16:55:26 +01:00
const FFDisplayServerResult * wmde = ffConnectDisplayServer ( instance );
2021-06-27 21:53:50 +02:00
if ( ffStrbufIgnCaseCompS ( & wmde -> wmProtocolName , "TTY" ) == 0 )
{
ffPrintError ( instance , FF_THEME_MODULE_NAME , 0 , & instance -> config . fontKey , & instance -> config . fontFormat , FF_THEME_NUM_FORMAT_ARGS , "Theme isn't supported in TTY" );
return ;
}
2021-04-28 19:53:30 +02:00
const FFPlasmaResult * plasma = ffDetectPlasma ( instance );
const FFstrbuf * gtk2 = & ffDetectGTK2 ( instance ) -> theme ;
const FFstrbuf * gtk3 = & ffDetectGTK3 ( instance ) -> theme ;
const FFstrbuf * gtk4 = & ffDetectGTK4 ( instance ) -> theme ;
2021-03-27 18:14:19 +01:00
2021-04-22 21:41:42 +02:00
if ( plasma -> widgetStyle . length == 0 && plasma -> colorScheme . length == 0 && gtk2 -> length == 0 && gtk3 -> length == 0 && gtk4 -> length == 0 )
2021-04-05 19:25:34 +02:00
{
2021-04-15 18:59:26 +02:00
ffPrintError ( instance , FF_THEME_MODULE_NAME , 0 , & instance -> config . themeKey , & instance -> config . themeFormat , FF_THEME_NUM_FORMAT_ARGS , "No themes found" );
2021-04-05 19:25:34 +02:00
return ;
}
2021-03-19 20:57:07 +01:00
2021-04-09 19:21:56 +02:00
FF_STRBUF_CREATE ( plasmaColorPretty );
2021-04-22 21:41:42 +02:00
if ( ffStrbufStartsWithIgnCase ( & plasma -> colorScheme , & plasma -> widgetStyle ))
ffStrbufAppendNS ( & plasmaColorPretty , plasma -> colorScheme . length - plasma -> widgetStyle . length , & plasma -> colorScheme . chars [ plasma -> widgetStyle . length ]);
2021-04-09 19:21:56 +02:00
else
2021-04-22 21:41:42 +02:00
ffStrbufAppend ( & plasmaColorPretty , & plasma -> colorScheme );
2021-04-09 19:21:56 +02:00
ffStrbufTrim ( & plasmaColorPretty , ' ' );
2021-03-21 16:52:17 +01:00
FF_STRBUF_CREATE ( gtkPretty );
2021-04-22 21:41:42 +02:00
ffGetGtkPretty ( & gtkPretty , gtk2 , gtk3 , gtk4 );
2021-03-19 20:57:07 +01:00
2021-03-23 19:48:52 +01:00
if ( instance -> config . themeFormat . length == 0 )
2021-03-19 20:57:07 +01:00
{
2021-04-15 18:59:26 +02:00
ffPrintLogoAndKey ( instance , FF_THEME_MODULE_NAME , 0 , & instance -> config . themeKey );
2021-03-27 15:39:56 +01:00
2021-04-22 21:41:42 +02:00
if ( plasma -> widgetStyle . length > 0 )
2021-04-09 19:21:56 +02:00
{
2021-04-22 21:41:42 +02:00
ffStrbufWriteTo ( & plasma -> widgetStyle , stdout );
2021-04-09 19:21:56 +02:00
2021-04-22 21:41:42 +02:00
if ( plasma -> colorScheme . length > 0 )
2021-04-09 19:21:56 +02:00
{
fputs ( " (" , stdout );
if ( plasmaColorPretty . length > 0 )
ffStrbufWriteTo ( & plasmaColorPretty , stdout );
else
2021-04-22 21:41:42 +02:00
ffStrbufWriteTo ( & plasma -> colorScheme , stdout );
2021-04-09 19:21:56 +02:00
putchar ( ')' );
}
}
2021-04-22 21:41:42 +02:00
else if ( plasma -> colorScheme . length > 0 )
2021-04-09 19:21:56 +02:00
{
if ( plasmaColorPretty . length > 0 )
ffStrbufWriteTo ( & plasmaColorPretty , stdout );
else
2021-04-22 21:41:42 +02:00
ffStrbufWriteTo ( & plasma -> colorScheme , stdout );
2021-04-09 19:21:56 +02:00
}
2021-04-22 21:41:42 +02:00
if ( plasma -> widgetStyle . length > 0 || plasma -> colorScheme . length > 0 )
2021-04-07 12:55:11 +02:00
{
fputs ( " [Plasma]" , stdout );
if ( gtkPretty . length > 0 )
fputs ( ", " , stdout );
}
2021-03-19 20:57:07 +01:00
2021-03-22 20:02:32 +01:00
ffStrbufPutTo ( & gtkPretty , stdout );
2021-03-19 20:57:07 +01:00
}
2021-02-19 16:23:41 +01:00
else
2021-03-19 20:57:07 +01:00
{
2021-04-15 18:59:26 +02:00
ffPrintFormatString ( instance , FF_THEME_MODULE_NAME , 0 , & instance -> config . themeKey , & instance -> config . themeFormat , NULL , FF_THEME_NUM_FORMAT_ARGS , ( FFformatarg []){
2021-04-22 21:41:42 +02:00
{ FF_FORMAT_ARG_TYPE_STRBUF , & plasma -> widgetStyle },
{ FF_FORMAT_ARG_TYPE_STRBUF , & plasma -> colorScheme },
2021-04-15 18:59:26 +02:00
{ FF_FORMAT_ARG_TYPE_STRBUF , & plasmaColorPretty },
2021-04-22 21:41:42 +02:00
{ FF_FORMAT_ARG_TYPE_STRBUF , gtk2 },
{ FF_FORMAT_ARG_TYPE_STRBUF , gtk3 },
{ FF_FORMAT_ARG_TYPE_STRBUF , gtk4 },
2021-04-15 18:59:26 +02:00
{ FF_FORMAT_ARG_TYPE_STRBUF , & gtkPretty }
});
2021-03-19 20:57:07 +01:00
}
2021-04-09 19:21:56 +02:00
ffStrbufDestroy ( & plasmaColorPretty );
ffStrbufDestroy ( & gtkPretty );
2021-03-27 18:14:19 +01:00
}