1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Add some theme name resolving functions.

This commit is contained in:
Dave Davenport 2017-04-17 17:46:01 +02:00
parent 7c14468697
commit 97fe894f43
4 changed files with 50 additions and 3 deletions

View file

@ -123,7 +123,8 @@ rofi_CFLAGS=\
-Werror=missing-prototypes\
-DSYSCONFDIR=\"$(sysconfdir)\"\
-DTHEME_CONVERTER\
-DPLUGIN_PATH=\"${libdir}/rofi\"
-DPLUGIN_PATH=\"${libdir}/rofi\"\
-DTHEME_DIR=\"${prefix}/share/rofi/themes/\"
rofi_LDADD=\
$(glib_LIBS)\

View file

@ -443,5 +443,12 @@ gboolean rofi_theme_is_empty ( void );
* Convert old theme colors into default one.
*/
void rofi_theme_convert_old ( void );
/**
* @param filename File name passed to option.
*
* @returns path to theme or copy of filename if not found.
*/
char *helper_get_theme_path ( const char *filename );
#endif
#endif

View file

@ -574,7 +574,10 @@ static char * rofi_theme_parse_prepare_file ( const char *file, const char *pare
}
gboolean rofi_theme_parse_file ( const char *file )
{
char *filename = rofi_theme_parse_prepare_file ( file, NULL );
char *file2 = helper_get_theme_path ( file );
char *filename = rofi_theme_parse_prepare_file ( file2, NULL );
g_free ( file2 );
yyin = fopen ( filename, "rb" );
if ( yyin == NULL ) {
char *str = g_markup_printf_escaped ( "Failed to open theme: <i>%s</i>\nError: <b>%s</b>",

View file

@ -964,3 +964,39 @@ int helper_execute_command ( const char *wd, const char *cmd, int run_in_term )
g_strfreev ( args );
return retv;
}
char *helper_get_theme_path ( const char *file )
{
char *filename = rofi_expand_path ( file );
if ( g_file_test ( filename, G_FILE_TEST_EXISTS ) ) {
return filename;
}
g_free ( filename );
if ( g_str_has_suffix ( file, ".rasi" ) ) {
filename = g_strdup ( file );
} else {
filename = g_strconcat ( file, ".rasi", NULL );
}
// Check config directory.
const char *cpath = g_get_user_config_dir ();
if ( cpath ) {
char *themep = g_build_filename ( cpath, "rofi", filename, NULL );
if ( g_file_test ( themep, G_FILE_TEST_EXISTS ) ) {
g_free ( filename );
return themep;
}
g_free ( themep );
}
char *theme_path = g_build_filename ( THEME_DIR, filename, NULL );
if ( theme_path ) {
if ( g_file_test ( theme_path, G_FILE_TEST_EXISTS ) ) {
g_free ( filename );
return theme_path;
}
g_free ( theme_path );
}
return filename;
}