config: Do not treat invalid task status values as defaults

This commit is contained in:
o9000 2015-04-25 16:37:23 +02:00
parent dff7355f3b
commit 2ecb1c4ef4

View file

@ -123,7 +123,7 @@ int get_task_status(char* status)
return TASK_ICONIFIED; return TASK_ICONIFIED;
if (strcmp(status, "urgent") == 0) if (strcmp(status, "urgent") == 0)
return TASK_URGENT; return TASK_URGENT;
return TASK_NORMAL; return -1;
} }
@ -548,8 +548,9 @@ void add_entry (char *key, char *value)
} }
else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) { else if (g_regex_match_simple("task.*_font_color", key, 0, 0)) {
gchar** split = g_regex_split_simple("_", key, 0, 0); gchar** split = g_regex_split_simple("_", key, 0, 0);
int status = get_task_status(split[1]); int status = g_strv_length(split) == 3 ? TASK_NORMAL : get_task_status(split[1]);
g_strfreev(split); g_strfreev(split);
if (status >= 0) {
extract_values(value, &value1, &value2, &value3); extract_values(value, &value1, &value2, &value3);
float alpha = 1; float alpha = 1;
if (value2) alpha = (atoi (value2) / 100.0); if (value2) alpha = (atoi (value2) / 100.0);
@ -557,26 +558,31 @@ void add_entry (char *key, char *value)
panel_config.g_task.font[status].alpha = alpha; panel_config.g_task.font[status].alpha = alpha;
panel_config.g_task.config_font_mask |= (1<<status); panel_config.g_task.config_font_mask |= (1<<status);
} }
}
else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) { else if (g_regex_match_simple("task.*_icon_asb", key, 0, 0)) {
gchar** split = g_regex_split_simple("_", key, 0, 0); gchar** split = g_regex_split_simple("_", key, 0, 0);
int status = get_task_status(split[1]); int status = g_strv_length(split) == 3 ? TASK_NORMAL : get_task_status(split[1]);
g_strfreev(split); g_strfreev(split);
if (status >= 0) {
extract_values(value, &value1, &value2, &value3); extract_values(value, &value1, &value2, &value3);
panel_config.g_task.alpha[status] = atoi(value1); panel_config.g_task.alpha[status] = atoi(value1);
panel_config.g_task.saturation[status] = atoi(value2); panel_config.g_task.saturation[status] = atoi(value2);
panel_config.g_task.brightness[status] = atoi(value3); panel_config.g_task.brightness[status] = atoi(value3);
panel_config.g_task.config_asb_mask |= (1<<status); panel_config.g_task.config_asb_mask |= (1<<status);
} }
}
else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) { else if (g_regex_match_simple("task.*_background_id", key, 0, 0)) {
gchar** split = g_regex_split_simple("_", key, 0, 0); gchar** split = g_regex_split_simple("_", key, 0, 0);
int status = get_task_status(split[1]); int status = g_strv_length(split) == 3 ? TASK_NORMAL : get_task_status(split[1]);
g_strfreev(split); g_strfreev(split);
if (status >= 0) {
int id = atoi (value); int id = atoi (value);
id = (id < backgrounds->len && id >= 0) ? id : 0; id = (id < backgrounds->len && id >= 0) ? id : 0;
panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id); panel_config.g_task.background[status] = &g_array_index(backgrounds, Background, id);
panel_config.g_task.config_background_mask |= (1<<status); panel_config.g_task.config_background_mask |= (1<<status);
if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL]; if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL];
} }
}
// "tooltip" is deprecated but here for backwards compatibility // "tooltip" is deprecated but here for backwards compatibility
else if (strcmp (key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0) else if (strcmp (key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0)
panel_config.g_task.tooltip_enabled = atoi(value); panel_config.g_task.tooltip_enabled = atoi(value);