mirror of
https://github.com/davatorium/rofi.git
synced 2025-03-10 17:06:37 -04:00
[Theme] Fix resolving of 'rasinc' extension when no extension is given.
Was an unresolved TODO in code. Fixes: #2069
This commit is contained in:
parent
d8e9a1981f
commit
25c1adbb2a
1 changed files with 102 additions and 87 deletions
189
source/helper.c
189
source/helper.c
|
@ -1065,6 +1065,92 @@ gboolean helper_execute_command(const char *wd, const char *cmd,
|
||||||
return helper_execute(wd, args, "", cmd, context);
|
return helper_execute(wd, args, "", cmd, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *helper_get_theme_path_check_file(const char *filename,
|
||||||
|
const char *parent_file) {
|
||||||
|
|
||||||
|
// 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 g_strdup(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)) {
|
||||||
|
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)) {
|
||||||
|
return themep;
|
||||||
|
}
|
||||||
|
g_free(themep);
|
||||||
|
}
|
||||||
|
// Check config directory.
|
||||||
|
if (cpath) {
|
||||||
|
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)) {
|
||||||
|
return themep;
|
||||||
|
}
|
||||||
|
g_free(themep);
|
||||||
|
}
|
||||||
|
const char *datadir = g_get_user_data_dir();
|
||||||
|
if (datadir) {
|
||||||
|
char *theme_path =
|
||||||
|
g_build_filename(datadir, "rofi", "themes", filename, NULL);
|
||||||
|
if (theme_path) {
|
||||||
|
g_debug("Opening theme, testing: %s", theme_path);
|
||||||
|
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
|
||||||
|
return theme_path;
|
||||||
|
}
|
||||||
|
g_free(theme_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const gchar *const *system_data_dirs = g_get_system_data_dirs();
|
||||||
|
if (system_data_dirs) {
|
||||||
|
for (uint_fast32_t i = 0; system_data_dirs[i] != NULL; i++) {
|
||||||
|
const char *const sdatadir = system_data_dirs[i];
|
||||||
|
g_debug("Opening theme directory: %s", sdatadir);
|
||||||
|
char *theme_path =
|
||||||
|
g_build_filename(sdatadir, "rofi", "themes", filename, NULL);
|
||||||
|
if (theme_path) {
|
||||||
|
g_debug("Opening theme, testing: %s", theme_path);
|
||||||
|
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
|
||||||
|
return theme_path;
|
||||||
|
}
|
||||||
|
g_free(theme_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *theme_path = g_build_filename(THEME_DIR, filename, NULL);
|
||||||
|
if (theme_path) {
|
||||||
|
g_debug("Opening theme, testing: %s", theme_path);
|
||||||
|
if (g_file_test(theme_path, G_FILE_TEST_EXISTS)) {
|
||||||
|
return theme_path;
|
||||||
|
}
|
||||||
|
g_free(theme_path);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char *helper_get_theme_path(const char *file, const char **ext,
|
char *helper_get_theme_path(const char *file, const char **ext,
|
||||||
const char *parent_file) {
|
const char *parent_file) {
|
||||||
|
|
||||||
|
@ -1085,99 +1171,28 @@ char *helper_get_theme_path(const char *file, const char **ext,
|
||||||
}
|
}
|
||||||
if (ext_found) {
|
if (ext_found) {
|
||||||
filename = rofi_expand_path(file);
|
filename = rofi_expand_path(file);
|
||||||
|
|
||||||
|
char *retv = helper_get_theme_path_check_file(filename, parent_file);
|
||||||
|
if (retv) {
|
||||||
|
g_free(filename);
|
||||||
|
return retv;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g_assert_nonnull(ext[0]);
|
g_assert_nonnull(ext[0]);
|
||||||
|
// Iterate through extensions.
|
||||||
char *temp = filename;
|
char *temp = filename;
|
||||||
// TODO: Pick the first extension. needs fixing.
|
for (const char **i = ext; *i != NULL; i++) {
|
||||||
filename = g_strconcat(temp, ext[0], NULL);
|
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);
|
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;
|
|
||||||
}
|
|
||||||
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.
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
// Check config directory.
|
|
||||||
if (cpath) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
const char *datadir = g_get_user_data_dir();
|
|
||||||
if (datadir) {
|
|
||||||
char *theme_path =
|
|
||||||
g_build_filename(datadir, "rofi", "themes", filename, NULL);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const gchar *const *system_data_dirs = g_get_system_data_dirs();
|
|
||||||
if (system_data_dirs) {
|
|
||||||
for (uint_fast32_t i = 0; system_data_dirs[i] != NULL; i++) {
|
|
||||||
const char *const sdatadir = system_data_dirs[i];
|
|
||||||
g_debug("Opening theme directory: %s", sdatadir);
|
|
||||||
char *theme_path =
|
|
||||||
g_build_filename(sdatadir, "rofi", "themes", filename, NULL);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *theme_path = g_build_filename(THEME_DIR, filename, NULL);
|
|
||||||
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 filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue