diff --git a/Makefile.am b/Makefile.am
index ae1feb52..c3ced0d8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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)\
diff --git a/include/theme.h b/include/theme.h
index 13894c41..e5cb0e83 100644
--- a/include/theme.h
+++ b/include/theme.h
@@ -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
diff --git a/lexer/theme-lexer.l b/lexer/theme-lexer.l
index 68380410..09a50b5d 100644
--- a/lexer/theme-lexer.l
+++ b/lexer/theme-lexer.l
@@ -574,11 +574,14 @@ 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: %s\nError: %s",
- filename, strerror ( errno ) );
+ filename, strerror ( errno ) );
rofi_add_error_message ( g_string_new ( str ) );
g_free ( str );
g_free ( filename );
diff --git a/source/helper.c b/source/helper.c
index 94929330..42c52eb9 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -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;
+}