add themes XDG support

- fix is_xdg_supported() not being in common.h
- themes are now loaded from $XDG_DATA_HOME, if and only if xdg paths
are being used
This commit is contained in:
altffour 2021-01-06 19:20:09 +03:00
commit dad31bdfde
No known key found for this signature in database
GPG key ID: B4ADFA86EDF5CCE9
4 changed files with 20 additions and 8 deletions

View file

@ -55,9 +55,11 @@ int g_input_add(GIOChannel *source, int condition,
int g_input_add_full(GIOChannel *source, int priority, int condition, int g_input_add_full(GIOChannel *source, int priority, int condition,
GInputFunction function, void *data); GInputFunction function, void *data);
/* return full path for ~/.irssi */ /* return if xdg is being used */
int is_xdg_supported();
/* return full path for irssi folder */
const char *get_irssi_dir(void); const char *get_irssi_dir(void);
/* return full path for ~/.irssi/config */ /* return full path for irssi config */
const char *get_irssi_config(void); const char *get_irssi_config(void);
/* max. size for %d */ /* max. size for %d */

View file

@ -81,7 +81,7 @@ int is_xdg_supported()
const char *get_irssi_dir(void) const char *get_irssi_dir(void)
{ {
return (xdg_support = 1) ? irssi_xdg_dir : irssi_dir; return irssi_dir;
} }
/* return full path for ~/.irssi/config */ /* return full path for ~/.irssi/config */

View file

@ -408,7 +408,7 @@ static void autorun_startup(void)
GString *buf; GString *buf;
gsize tpos; gsize tpos;
/* open ~/.irssi/startup and run all commands in it */ /* open $CONFIG/startup and run all commands in it */
path = g_strdup_printf("%s/startup", get_irssi_dir()); path = g_strdup_printf("%s/startup", get_irssi_dir());
handle = g_io_channel_new_file(path, "r", NULL); handle = g_io_channel_new_file(path, "r", NULL);
g_free(path); g_free(path);

View file

@ -932,6 +932,10 @@ THEME_REC *theme_load(const char *setname)
theme = theme_find(name); theme = theme_find(name);
/* check home dir */ /* check home dir */
if (is_xdg_supported())
fname = g_build_filename(g_get_user_data_dir(), "irssi",
g_strdup_printf("%s.theme", name), NULL);
else
fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name); fname = g_strdup_printf("%s/%s.theme", get_irssi_dir(), name);
if (stat(fname, &statbuf) != 0) { if (stat(fname, &statbuf) != 0) {
/* check global config dir */ /* check global config dir */
@ -1256,7 +1260,10 @@ static void theme_save(THEME_REC *theme, int save_all)
g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data); g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data);
basename = g_path_get_basename(theme->path); basename = g_path_get_basename(theme->path);
/* always save the theme to ~/.irssi/ */ /* always save the theme */
if (is_xdg_supported())
path = g_build_filename(g_get_user_data_dir(), "irssi", basename, NULL);
else
path = g_strdup_printf("%s/%s", get_irssi_dir(), basename); path = g_strdup_printf("%s/%s", get_irssi_dir(), basename);
ok = config_write(config, path, 0660) == 0; ok = config_write(config, path, 0660) == 0;
g_free(basename); g_free(basename);
@ -1413,6 +1420,9 @@ void themes_reload(void)
/* first there's default theme.. */ /* first there's default theme.. */
current_theme = theme_load("default"); current_theme = theme_load("default");
if (current_theme == NULL) { if (current_theme == NULL) {
if (is_xdg_supported())
fname = g_build_filename(g_get_user_data_dir(), "irssi", "default.theme");
else
fname = g_strdup_printf("%s/default.theme", get_irssi_dir()); fname = g_strdup_printf("%s/default.theme", get_irssi_dir());
current_theme = theme_create(fname, "default"); current_theme = theme_create(fname, "default");
current_theme->default_color = -1; current_theme->default_color = -1;