[Theme] Try to fix importing of theme.
- Fix the two place of resolving into one method. - Do not accept file in CWD. - Prefer file if it exists in same directory as parent file that imported it. fixes: #1889
This commit is contained in:
@@ -2408,6 +2408,10 @@ If a filename is provided, it will try to resolve it in the following order:
|
|||||||
|
|
||||||
.RS
|
.RS
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
|
If path is absolute and file exists, it will pick open the file. This includes expansion of '~' or '~user'
|
||||||
|
.IP \(bu 2
|
||||||
|
On an \fB\fC@import\fR or \fB\fC@theme\fR it looks in the directory of the file that tried to import it.
|
||||||
|
.IP \(bu 2
|
||||||
\fB\fC${XDG_CONFIG_HOME}/rofi/themes/\fR
|
\fB\fC${XDG_CONFIG_HOME}/rofi/themes/\fR
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
\fB\fC${XDG_CONFIG_HOME}/rofi/\fR
|
\fB\fC${XDG_CONFIG_HOME}/rofi/\fR
|
||||||
@@ -2419,7 +2423,7 @@ If a filename is provided, it will try to resolve it in the following order:
|
|||||||
.RE
|
.RE
|
||||||
|
|
||||||
.PP
|
.PP
|
||||||
A name is resolved as a filename by appending the \fB\fC\&.rasi\fR extension.
|
A name is resolved (if it has no valid extension) as a filename by appending the \fB\fC\&.rasi\fR extension.
|
||||||
|
|
||||||
.SH Examples
|
.SH Examples
|
||||||
.PP
|
.PP
|
||||||
|
@@ -1626,12 +1626,14 @@ The specified file can either by *name*, *filename*,*full path*.
|
|||||||
|
|
||||||
If a filename is provided, it will try to resolve it in the following order:
|
If a filename is provided, it will try to resolve it in the following order:
|
||||||
|
|
||||||
|
- If path is absolute and file exists, it will pick open the file. This includes expansion of '~' or '~user'
|
||||||
|
- On an `@import` or `@theme` it looks in the directory of the file that tried to import it.
|
||||||
- `${XDG_CONFIG_HOME}/rofi/themes/`
|
- `${XDG_CONFIG_HOME}/rofi/themes/`
|
||||||
- `${XDG_CONFIG_HOME}/rofi/`
|
- `${XDG_CONFIG_HOME}/rofi/`
|
||||||
- `${XDG_DATA_HOME}/rofi/themes/`
|
- `${XDG_DATA_HOME}/rofi/themes/`
|
||||||
- `${INSTALL PREFIX}/share/rofi/themes/`
|
- `${INSTALL PREFIX}/share/rofi/themes/`
|
||||||
|
|
||||||
A name is resolved as a filename by appending the `.rasi` extension.
|
A name is resolved (if it has no valid extension) as a filename by appending the `.rasi` extension.
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
@@ -397,8 +397,9 @@ char *helper_string_replace_if_exists(char *string, ...);
|
|||||||
*
|
*
|
||||||
* @returns path to theme or copy of filename if not found.
|
* @returns path to theme or copy of filename if not found.
|
||||||
*/
|
*/
|
||||||
char *helper_get_theme_path(const char *file, const char **ext)
|
char *helper_get_theme_path(const char *file, const char **ext,
|
||||||
__attribute__((nonnull));
|
const char *parent_dir)
|
||||||
|
__attribute__((nonnull(1, 2)));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name The name of the element to find.
|
* @param name The name of the element to find.
|
||||||
|
@@ -327,13 +327,12 @@ void rofi_theme_reset(void);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param file File name to prepare.
|
* @param file File name to prepare.
|
||||||
* @param parent_file Filename of parent file.
|
|
||||||
*
|
*
|
||||||
* Tries to find full path relative to parent file.
|
* Tries to find full path relative to parent file.
|
||||||
*
|
*
|
||||||
* @returns full path to file.
|
* @returns full path to file.
|
||||||
*/
|
*/
|
||||||
char *rofi_theme_parse_prepare_file(const char *file, const char *parent_file);
|
char *rofi_theme_parse_prepare_file(const char *file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process conditionals.
|
* Process conditionals.
|
||||||
|
@@ -415,8 +415,8 @@ if ( queue == NULL ) {
|
|||||||
yytext[yyleng-1] = '\0';
|
yytext[yyleng-1] = '\0';
|
||||||
ParseObject *top = g_queue_peek_head ( file_queue );
|
ParseObject *top = g_queue_peek_head ( file_queue );
|
||||||
g_assert ( top != NULL );
|
g_assert ( top != NULL );
|
||||||
char *file2 = helper_get_theme_path ( &yytext[1], rasi_theme_file_extensions );
|
char *file2 = helper_get_theme_path ( &yytext[1], rasi_theme_file_extensions, top->filename );
|
||||||
char *filename = rofi_theme_parse_prepare_file ( file2, top->filename );
|
char *filename = rofi_theme_parse_prepare_file ( file2 );
|
||||||
g_free ( file2 );
|
g_free ( file2 );
|
||||||
FILE *f = fopen ( filename, "rb" );
|
FILE *f = fopen ( filename, "rb" );
|
||||||
if ( f ) {
|
if ( f ) {
|
||||||
@@ -883,8 +883,8 @@ if ( queue == NULL ) {
|
|||||||
|
|
||||||
gboolean rofi_theme_parse_file ( const char *file )
|
gboolean rofi_theme_parse_file ( const char *file )
|
||||||
{
|
{
|
||||||
char *file2 = helper_get_theme_path ( file, rasi_theme_file_extensions );
|
char *file2 = helper_get_theme_path ( file, rasi_theme_file_extensions, NULL );
|
||||||
char *filename = rofi_theme_parse_prepare_file ( file2, NULL );
|
char *filename = rofi_theme_parse_prepare_file ( file2 );
|
||||||
g_free ( file2 );
|
g_free ( file2 );
|
||||||
|
|
||||||
yyin = fopen ( filename, "rb" );
|
yyin = fopen ( filename, "rb" );
|
||||||
|
@@ -1064,13 +1064,8 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
|
|||||||
return helper_execute(wd, args, "", cmd, context);
|
return helper_execute(wd, args, "", cmd, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *helper_get_theme_path(const char *file, const char **ext) {
|
char *helper_get_theme_path(const char *file, const char **ext,
|
||||||
char *filename = rofi_expand_path(file);
|
const char *parent_file) {
|
||||||
g_debug("Opening theme, testing: %s\n", filename);
|
|
||||||
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
|
|
||||||
return filename;
|
|
||||||
}
|
|
||||||
g_free(filename);
|
|
||||||
|
|
||||||
gboolean ext_found = FALSE;
|
gboolean ext_found = FALSE;
|
||||||
for (const char **i = ext; *i != NULL; i++) {
|
for (const char **i = ext; *i != NULL; i++) {
|
||||||
@@ -1079,13 +1074,41 @@ char *helper_get_theme_path(const char *file, const char **ext) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
char *filename = NULL;
|
||||||
if (ext_found) {
|
if (ext_found) {
|
||||||
filename = g_strdup(file);
|
filename = rofi_expand_path(file);
|
||||||
} else {
|
} else {
|
||||||
g_assert_nonnull(ext[0]);
|
g_assert_nonnull(ext[0]);
|
||||||
|
char *temp = rofi_expand_path(file);
|
||||||
// TODO: Pick the first extension. needs fixing.
|
// TODO: Pick the first extension. needs fixing.
|
||||||
filename = g_strconcat(file, ext[0], NULL);
|
filename = g_strconcat(temp, ext[0], NULL);
|
||||||
|
g_free(temp);
|
||||||
}
|
}
|
||||||
|
g_debug("Opening theme, testing: %s\n", filename);
|
||||||
|
if (g_path_is_absolute(filename)) {
|
||||||
|
g_debug("Opening theme, path is absolute: %s", filename);
|
||||||
|
if (g_file_test(filename, G_FILE_TEST_EXISTS)) {
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
g_debug("Opening theme, path is absolute but does not exists: %s",
|
||||||
|
filename);
|
||||||
|
} else {
|
||||||
|
if (parent_file != NULL) {
|
||||||
|
// If no absolute path specified, expand it.
|
||||||
|
char *basedir = g_path_get_dirname(parent_file);
|
||||||
|
char *path = g_build_filename(basedir, filename, NULL);
|
||||||
|
g_free(basedir);
|
||||||
|
g_debug("Opening theme, check in dir where file is included: %s", path);
|
||||||
|
if (g_file_test(path, G_FILE_TEST_EXISTS)) {
|
||||||
|
g_free(filename);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
g_debug("Opening theme, file does not exists in dir where file is "
|
||||||
|
"included: %s\n",
|
||||||
|
filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check config's themes directory.
|
// Check config's themes directory.
|
||||||
const char *cpath = g_get_user_config_dir();
|
const char *cpath = g_get_user_config_dir();
|
||||||
if (cpath) {
|
if (cpath) {
|
||||||
|
@@ -334,7 +334,7 @@ static void rofi_icon_fetcher_worker(thread_state *sdata,
|
|||||||
if (ext) {
|
if (ext) {
|
||||||
const char *exts2[2] = {ext, NULL};
|
const char *exts2[2] = {ext, NULL};
|
||||||
icon_path = icon_path_ =
|
icon_path = icon_path_ =
|
||||||
helper_get_theme_path(sentry->entry->name, exts2);
|
helper_get_theme_path(sentry->entry->name, exts2, NULL);
|
||||||
}
|
}
|
||||||
if (icon_path_ == NULL) {
|
if (icon_path_ == NULL) {
|
||||||
sentry->query_done = TRUE;
|
sentry->query_done = TRUE;
|
||||||
|
@@ -1434,16 +1434,9 @@ void distance_get_linestyle(RofiDistance d, cairo_t *draw) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char *rofi_theme_parse_prepare_file(const char *file, const char *parent_file) {
|
char *rofi_theme_parse_prepare_file(const char *file) {
|
||||||
char *filename = rofi_expand_path(file);
|
char *filename = g_strdup(file);
|
||||||
// If no absolute path specified, expand it.
|
// TODO: Why did I write this code? I think it was to get full path.
|
||||||
if (parent_file != NULL && !g_path_is_absolute(filename)) {
|
|
||||||
char *basedir = g_path_get_dirname(parent_file);
|
|
||||||
char *path = g_build_filename(basedir, filename, NULL);
|
|
||||||
g_free(filename);
|
|
||||||
filename = path;
|
|
||||||
g_free(basedir);
|
|
||||||
}
|
|
||||||
GFile *gf = g_file_new_for_path(filename);
|
GFile *gf = g_file_new_for_path(filename);
|
||||||
parsed_config_files = g_list_append(parsed_config_files, filename);
|
parsed_config_files = g_list_append(parsed_config_files, filename);
|
||||||
filename = g_file_get_path(gf);
|
filename = g_file_get_path(gf);
|
||||||
|
@@ -92,7 +92,8 @@ gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
|
|||||||
}
|
}
|
||||||
char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; }
|
char *rofi_expand_path(G_GNUC_UNUSED const char *path) { return NULL; }
|
||||||
|
|
||||||
char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext) {
|
char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext,
|
||||||
|
G_GNUC_UNUSED const char *parent_file) {
|
||||||
return g_strdup(file);
|
return g_strdup(file);
|
||||||
}
|
}
|
||||||
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
|
void rofi_add_error_message(G_GNUC_UNUSED GString *msg) {}
|
||||||
|
@@ -77,7 +77,8 @@ cairo_surface_t *rofi_icon_fetcher_get(G_GNUC_UNUSED const uint32_t uid) {
|
|||||||
|
|
||||||
int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
|
int monitor_active(G_GNUC_UNUSED workarea *mon) { return 0; }
|
||||||
|
|
||||||
char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext) {
|
char *helper_get_theme_path(const char *file, G_GNUC_UNUSED const char **ext,
|
||||||
|
G_GNUC_UNUSED const char *parent_file) {
|
||||||
return g_strdup(file);
|
return g_strdup(file);
|
||||||
}
|
}
|
||||||
gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
|
gboolean config_parse_set_property(G_GNUC_UNUSED const Property *p,
|
||||||
|
Reference in New Issue
Block a user