Skip to content

Commit

Permalink
[Theme] Fix resolving of 'rasinc' extension when no extension is given.
Browse files Browse the repository at this point in the history
Was an unresolved TODO in code.

Fixes: #2069
  • Loading branch information
DaveDavenport committed Jan 2, 2025
1 parent d8e9a19 commit 25c1adb
Showing 1 changed file with 49 additions and 34 deletions.
83 changes: 49 additions & 34 deletions source/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1065,37 +1065,14 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
return helper_execute(wd, args, "", cmd, context);
}

char *helper_get_theme_path(const char *file, const char **ext,
const char *parent_file) {
static char *helper_get_theme_path_check_file(const char *filename,
const char *parent_file) {

char *filename = rofi_expand_path(file);
g_debug("Opening theme, testing: %s\n", filename);
// Check if absolute path.
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;
}
}
gboolean ext_found = FALSE;
for (const char **i = ext; *i != NULL; i++) {
if (g_str_has_suffix(file, *i)) {
ext_found = TRUE;
break;
}
}
if (ext_found) {
filename = rofi_expand_path(file);
} else {
g_assert_nonnull(ext[0]);
char *temp = filename;
// TODO: Pick the first extension. needs fixing.
filename = g_strconcat(temp, ext[0], NULL);
g_free(temp);
}
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;
return g_strdup(filename);
}
g_debug("Opening theme, path is absolute but does not exists: %s",
filename);
Expand All @@ -1107,22 +1084,19 @@ char *helper_get_theme_path(const char *file, const char **ext,
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.
const char *cpath = g_get_user_config_dir();
if (cpath) {
char *themep = g_build_filename(cpath, "rofi", "themes", filename, NULL);
g_debug("Opening theme, testing: %s", themep);
if (themep && g_file_test(themep, G_FILE_TEST_EXISTS)) {
g_free(filename);
return themep;
}
g_free(themep);
Expand All @@ -1132,7 +1106,6 @@ char *helper_get_theme_path(const char *file, const char **ext,
char *themep = g_build_filename(cpath, "rofi", filename, NULL);
g_debug("Opening theme, testing: %s", themep);
if (g_file_test(themep, G_FILE_TEST_EXISTS)) {
g_free(filename);
return themep;
}
g_free(themep);
Expand All @@ -1144,7 +1117,6 @@ char *helper_get_theme_path(const char *file, const char **ext,
if (theme_path) {
g_debug("Opening theme, testing: %s", theme_path);
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
g_free(filename);
return theme_path;
}
g_free(theme_path);
Expand All @@ -1161,7 +1133,6 @@ char *helper_get_theme_path(const char *file, const char **ext,
if (theme_path) {
g_debug("Opening theme, testing: %s", theme_path);
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
g_free(filename);
return theme_path;
}
g_free(theme_path);
Expand All @@ -1173,11 +1144,55 @@ char *helper_get_theme_path(const char *file, const char **ext,
if (theme_path) {
g_debug("Opening theme, testing: %s", theme_path);
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
g_free(filename);
return theme_path;
}
g_free(theme_path);
}
return NULL;
}

char *helper_get_theme_path(const char *file, const char **ext,
const char *parent_file) {

char *filename = rofi_expand_path(file);
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;
}
}
gboolean ext_found = FALSE;
for (const char **i = ext; *i != NULL; i++) {
if (g_str_has_suffix(file, *i)) {
ext_found = TRUE;
break;
}
}
if (ext_found) {
filename = rofi_expand_path(file);

char *retv = helper_get_theme_path_check_file(filename, parent_file);
if (retv) {
g_free(filename);
return retv;
}
} else {
g_assert_nonnull(ext[0]);
// Iterate through extensions.
char *temp = filename;
for (const char **i = ext; *i != NULL; i++) {
filename = g_strconcat(temp, *i, NULL);
char *retv = helper_get_theme_path_check_file(filename, parent_file);
if (retv) {
g_free(filename);
g_free(temp);
return retv;
}
}
g_free(temp);
}

return filename;
}

Expand Down

0 comments on commit 25c1adb

Please sign in to comment.