g_return_val_if_fail(name != NULL, NULL);
rec = g_new0(THEME_REC, 1);
+ rec->refcount = 1;
rec->path = g_strdup(path);
rec->name = g_strdup(name);
rec->abstracts = g_hash_table_new((GHashFunc) g_str_hash,
g_free(rec);
}
-void theme_destroy(THEME_REC *rec)
+static void theme_real_destroy(THEME_REC *rec)
{
- themes = g_slist_remove(themes, rec);
-
- signal_emit("theme destroyed", 1, rec);
-
g_hash_table_foreach(rec->abstracts, (GHFunc) theme_abstract_destroy, NULL);
g_hash_table_destroy(rec->abstracts);
g_hash_table_foreach(rec->modules, (GHFunc) theme_module_destroy, NULL);
g_free(rec);
}
+static void theme_unref(THEME_REC *rec)
+{
+ if (--rec->refcount == 0)
+ theme_real_destroy(rec);
+}
+
+void theme_destroy(THEME_REC *rec)
+{
+ themes = g_slist_remove(themes, rec);
+ signal_emit("theme destroyed", 1, rec);
+
+ theme_unref(rec);
+}
+
static char *theme_replace_expand(THEME_REC *theme, int index,
char default_fg, char default_bg,
char *last_fg, char *last_bg,
{
/* since we don't know the real argument list, assume there's always
an argument in them */
- char *arglist[] = {
+ static char *arglist[] = {
"x", "x", "x", "x", "x", "x","x", "x", "x", "x",
NULL
};
+ SERVER_REC *server;
const char *p;
char *ret;
int free_ret, empty;
/* variable - check if it's empty */
p++;
- ret = parse_special((char **) &p,
- active_win == NULL ? NULL : active_win->active_server,
+
+ server = active_win == NULL ? NULL :
+ active_win->active_server != NULL ?
+ active_win->active_server : active_win->connect_server;
+
+ ret = parse_special((char **) &p, server,
active_win == NULL ? NULL : active_win->active,
arglist, &free_ret, NULL, 0);
p++;
return FALSE;
}
+/* return "data" from {abstract data} string */
+char *theme_format_expand_get(THEME_REC *theme, const char **format)
+{
+ GString *str;
+ char *ret, dummy;
+ int braces = 1; /* we start with one brace opened */
+
+ str = g_string_new(NULL);
+ while ((**format != '\0') && (braces)) {
+ if (**format == '{')
+ braces++;
+ else if (**format == '}')
+ braces--;
+ else if ((braces > 1) && (**format == ' ')) {
+ g_string_append(str, "\\x20");
+ (*format)++;
+ continue;
+ } else {
+ theme_format_append_next(theme, str, format,
+ 'n', 'n',
+ &dummy, &dummy, 0);
+ continue;
+ }
+
+ if (!braces) {
+ (*format)++;
+ break;
+ }
+
+ g_string_append_c(str, **format);
+ (*format)++;
+ }
+
+ ret = str->str;
+ g_string_free(str, FALSE);
+ return ret;
+}
+
/* expand a single {abstract ...data... } */
static char *theme_format_expand_abstract(THEME_REC *theme,
const char **formatp,
char default_fg, char default_bg,
int flags)
{
+ GString *str;
const char *p, *format;
char *abstract, *data, *ret;
int len;
abstract = g_strdup(data);
/* we'll need to get the data part. it may contain
- more abstracts, they are automatically expanded. */
- data = theme_format_expand_data(theme, formatp, default_fg, default_bg,
- NULL, NULL, flags);
+ more abstracts, they are _NOT_ expanded. */
+ data = theme_format_expand_get(theme, formatp);
len = strlen(data);
if (len > 1 && i_isdigit(data[len-1]) && data[len-2] == '$') {
PARSE_FLAG_ONLY_ARGS);
g_free(abstract);
g_free(data);
- abstract = ret;
+ str = g_string_new(NULL);
+ p = ret;
+ while (*p != '\0') {
+ if (*p == '\\') {
+ int chr;
+ p++;
+ chr = expand_escape(&p);
+ g_string_append_c(str, chr != -1 ? chr : *p);
+ } else
+ g_string_append_c(str, *p);
+ p++;
+ }
+ g_free(ret);
+ abstract = str->str;
+ g_string_free(str, FALSE);
/* abstract may itself contain abstracts or replaces */
p = abstract;
static void themes_read(void)
{
+ GSList *refs;
char *fname;
- while (themes != NULL)
- theme_destroy(themes->data);
+ /* increase every theme's refcount, and destroy them. this way if
+ we want to use the theme before it's reloaded we don't crash. */
+ refs = NULL;
+ while (themes != NULL) {
+ THEME_REC *theme = themes->data;
+
+ refs = g_slist_prepend(refs, theme);
+
+ theme->refcount++;
+ theme_destroy(theme);
+ }
/* first there's default theme.. */
current_theme = theme_load("default");
}
window_themes_update();
- change_theme(settings_get_str("theme"), FALSE);
+ change_theme(settings_get_str("theme"), FALSE);
+
+ while (refs != NULL) {
+ theme_unref(refs->data);
+ refs = g_slist_remove(refs, refs->data);
+ }
}
void themes_init(void)