diff --git a/src/config.c b/src/config.c index e13cacd..5fe8d30 100644 --- a/src/config.c +++ b/src/config.c @@ -313,6 +313,24 @@ void add_entry(char *key, char *value) else bg->border_color_pressed.alpha = 0.5; read_border_color_press = 1; + } else if (strcmp(key, "gradient_id") == 0) { + Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); + int id = atoi(value); + id = (id < gradients->len && id >= 0) ? id : -1; + if (id >= 0) + bg->gradients[MOUSE_NORMAL] = g_list_append(bg->gradients[MOUSE_NORMAL], &g_array_index(gradients, GradientClass, id)); + } else if (strcmp(key, "hover_gradient_id") == 0) { + Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); + int id = atoi(value); + id = (id < gradients->len && id >= 0) ? id : -1; + if (id >= 0) + bg->gradients[MOUSE_OVER] = g_list_append(bg->gradients[MOUSE_OVER], &g_array_index(gradients, GradientClass, id)); + } else if (strcmp(key, "pressed_gradient_id") == 0) { + Background *bg = &g_array_index(backgrounds, Background, backgrounds->len - 1); + int id = atoi(value); + id = (id < gradients->len && id >= 0) ? id : -1; + if (id >= 0) + bg->gradients[MOUSE_DOWN] = g_list_append(bg->gradients[MOUSE_DOWN], &g_array_index(gradients, GradientClass, id)); } /* Gradients */ @@ -534,11 +552,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.area.bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "panel_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.area.gradients = g_list_append(panel_config.area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "wm_menu") == 0) wm_menu = atoi(value); else if (strcmp(key, "panel_dock") == 0) @@ -641,13 +654,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.battery.area.bg = &g_array_index(backgrounds, Background, id); -#endif - } else if (strcmp(key, "battery_gradient_id") == 0) { -#ifdef ENABLE_BATTERY - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.battery.area.gradients = g_list_append(panel_config.battery.area.gradients, &g_array_index(gradients, GradientClass, id)); #endif } else if (strcmp(key, "battery_hide") == 0) { #ifdef ENABLE_BATTERY @@ -669,12 +675,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; separator->area.bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "separator_gradient_id") == 0) { - Separator *separator = get_or_create_last_separator(); - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - separator->area.gradients = g_list_append(separator->area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "separator_color") == 0) { Separator *separator = get_or_create_last_separator(); extract_values(value, &value1, &value2, &value3); @@ -767,12 +767,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; execp->backend->bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "execp_gradient_id") == 0) { - Execp *execp = get_or_create_last_execp(); - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - execp->area.gradients = g_list_append(execp->area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "execp_centered") == 0) { Execp *execp = get_or_create_last_execp(); execp->backend->centered = atoi(value); @@ -869,11 +863,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.clock.area.bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "clock_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.clock.area.gradients = g_list_append(panel_config.clock.area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "clock_tooltip") == 0) { if (strlen(value) > 0) time_tooltip_format = strdup(value); @@ -918,20 +907,10 @@ void add_entry(char *key, char *value) panel_config.g_taskbar.background[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id); if (panel_config.g_taskbar.background[TASKBAR_ACTIVE] == 0) panel_config.g_taskbar.background[TASKBAR_ACTIVE] = panel_config.g_taskbar.background[TASKBAR_NORMAL]; - } else if (strcmp(key, "taskbar_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.g_taskbar.gradient[TASKBAR_NORMAL] = g_list_append(panel_config.g_taskbar.gradient[TASKBAR_NORMAL], &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "taskbar_active_background_id") == 0) { int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.g_taskbar.background[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "taskbar_active_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.g_taskbar.gradient[TASKBAR_ACTIVE] = g_list_append(panel_config.g_taskbar.gradient[TASKBAR_ACTIVE], &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "taskbar_name") == 0) { taskbarname_enabled = atoi(value); } else if (strcmp(key, "taskbar_name_padding") == 0) { @@ -946,20 +925,10 @@ void add_entry(char *key, char *value) if (panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] == 0) panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = panel_config.g_taskbar.background_name[TASKBAR_NORMAL]; - } else if (strcmp(key, "taskbar_name_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.g_taskbar.gradient_name[TASKBAR_NORMAL] = g_list_append(panel_config.g_taskbar.gradient_name[TASKBAR_NORMAL], &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "taskbar_name_active_background_id") == 0) { int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "taskbar_name_active_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.g_taskbar.gradient_name[TASKBAR_ACTIVE] = g_list_append(panel_config.g_taskbar.gradient_name[TASKBAR_ACTIVE], &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "taskbar_name_font") == 0) { panel_config.taskbarname_font_desc = pango_font_description_from_string(value); panel_config.taskbarname_has_font = TRUE; @@ -1071,17 +1040,6 @@ void add_entry(char *key, char *value) if (status == TASK_NORMAL) panel_config.g_task.area.bg = panel_config.g_task.background[TASK_NORMAL]; } - } else if (g_regex_match_simple("task.*_gradient_id", key, 0, 0)) { - gchar **split = g_regex_split_simple("_", key, 0, 0); - int status = g_strv_length(split) == 3 ? TASK_NORMAL : get_task_status(split[1]); - g_strfreev(split); - if (status >= 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) { - panel_config.g_task.gradient[status] = g_list_append(panel_config.g_task.gradient[status], &g_array_index(gradients, GradientClass, id)); - } - } } // "tooltip" is deprecated but here for backwards compatibility else if (strcmp(key, "task_tooltip") == 0 || strcmp(key, "tooltip") == 0) @@ -1109,11 +1067,6 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; systray.area.bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "systray_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - systray.area.gradients = g_list_append(systray.area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "systray_sort") == 0) { if (strcmp(value, "descending") == 0) systray.sort = SYSTRAY_SORT_DESCENDING; @@ -1146,20 +1099,10 @@ void add_entry(char *key, char *value) int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; panel_config.launcher.area.bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "launcher_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - panel_config.launcher.area.gradients = g_list_append(panel_config.launcher.area.gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "launcher_icon_background_id") == 0) { int id = atoi(value); id = (id < backgrounds->len && id >= 0) ? id : 0; launcher_icon_bg = &g_array_index(backgrounds, Background, id); - } else if (strcmp(key, "launcher_icon_gradient_id") == 0) { - int id = atoi(value); - id = (id < gradients->len && id >= 0) ? id : -1; - if (id >= 0) - launcher_icon_gradients = g_list_append(launcher_icon_gradients, &g_array_index(gradients, GradientClass, id)); } else if (strcmp(key, "launcher_icon_size") == 0) { launcher_max_icon_size = atoi(value); } else if (strcmp(key, "launcher_item_app") == 0) { diff --git a/src/launcher/launcher.c b/src/launcher/launcher.c index 030b8ee..18160be 100644 --- a/src/launcher/launcher.c +++ b/src/launcher/launcher.c @@ -492,7 +492,6 @@ void launcher_load_icons(Launcher *launcher) launcherIcon->area.has_mouse_over_effect = panel_config.mouse_effects; launcherIcon->area.has_mouse_press_effect = launcherIcon->area.has_mouse_over_effect; launcherIcon->area.bg = launcher_icon_bg; - launcherIcon->area.gradients = launcher_icon_gradients; launcherIcon->area.on_screen = TRUE; launcherIcon->area.posx = -1; launcherIcon->area._on_change_layout = launcher_icon_on_change_layout; diff --git a/src/panel.c b/src/panel.c index 91c52ee..f079eac 100644 --- a/src/panel.c +++ b/src/panel.c @@ -156,8 +156,10 @@ void cleanup_panel() free_area(&panel_config.area); - if (backgrounds) - g_array_free(backgrounds, TRUE); + if (backgrounds) { + for (guint i = 0; i < backgrounds->len; i++) + cleanup_background(&g_array_index(backgrounds, Background, i)); + } backgrounds = NULL; if (gradients) { for (guint i = 0; i < gradients->len; i++) @@ -201,7 +203,6 @@ void init_panel() panels = calloc(num_panels, sizeof(Panel)); for (int i = 0; i < num_panels; i++) { memcpy(&panels[i], &panel_config, sizeof(Panel)); - panels[i].area.gradients = g_list_copy(panel_config.area.gradients); } fprintf(stderr, diff --git a/src/taskbar/task.c b/src/taskbar/task.c index e21a86e..97a60e6 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -611,7 +611,6 @@ void set_task_state(Task *task, TaskState state) task1->current_state = state; task1->area.bg = panels[0].g_task.background[state]; free_area_gradient_instances(&task1->area); - task1->area.gradients = g_list_copy(panels[0].g_task.gradient[state]); instantiate_area_gradients(&task1->area); schedule_redraw(&task1->area); if (state == TASK_ACTIVE && g_slist_find(urgent_list, task1)) diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index b1e51fd..a9aa9cb 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -318,12 +318,10 @@ void init_taskbar_panel(void *p) if (j == server.desktop) { taskbar->area.bg = panel->g_taskbar.background[TASKBAR_ACTIVE]; free_area_gradient_instances(&taskbar->area); - taskbar->area.gradients = g_list_copy(panel->g_taskbar.gradient[TASKBAR_ACTIVE]); instantiate_area_gradients(&taskbar->area); } else { taskbar->area.bg = panel->g_taskbar.background[TASKBAR_NORMAL]; free_area_gradient_instances(&taskbar->area); - taskbar->area.gradients = g_list_copy(panel->g_taskbar.gradient[TASKBAR_NORMAL]); instantiate_area_gradients(&taskbar->area); } @@ -514,13 +512,11 @@ void set_taskbar_state(Taskbar *taskbar, TaskbarState state) { taskbar->area.bg = panels[0].g_taskbar.background[state]; free_area_gradient_instances(&taskbar->area); - taskbar->area.gradients = g_list_copy(panels[0].g_taskbar.gradient[state]); instantiate_area_gradients(&taskbar->area); if (taskbarname_enabled) { taskbar->bar_name.area.bg = panels[0].g_taskbar.background_name[state]; free_area_gradient_instances(&taskbar->bar_name.area); - taskbar->bar_name.area.gradients = g_list_copy(panels[0].g_taskbar.gradient_name[state]); instantiate_area_gradients(&taskbar->bar_name.area); } diff --git a/src/taskbar/taskbarname.c b/src/taskbar/taskbarname.c index b7eebf4..3a3da2a 100644 --- a/src/taskbar/taskbarname.c +++ b/src/taskbar/taskbarname.c @@ -64,10 +64,8 @@ void init_taskbarname_panel(void *p) taskbar->bar_name.area._compute_desired_size = taskbarname_compute_desired_size; if (j == server.desktop) { taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_ACTIVE]; - taskbar->bar_name.area.gradients = g_list_copy(panel->g_taskbar.gradient_name[TASKBAR_ACTIVE]); } else { taskbar->bar_name.area.bg = panel->g_taskbar.background_name[TASKBAR_NORMAL]; - taskbar->bar_name.area.gradients = g_list_copy(panel->g_taskbar.gradient_name[TASKBAR_NORMAL]); } // use desktop number if name is missing diff --git a/src/util/area.c b/src/util/area.c index be72f4e..11da1a7 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -40,6 +40,16 @@ void init_background(Background *bg) bg->border.mask = BORDER_TOP | BORDER_BOTTOM | BORDER_LEFT | BORDER_RIGHT; } +void cleanup_background(Background *bg) +{ + if (debug_gradients) + fprintf(stderr, YELLOW "freeing gradient list %p" RESET "\n", (void*)bg->gradients); + for (int i = 0; i < MOUSE_STATE_COUNT; i++) { + g_list_free(bg->gradients[i]); + bg->gradients[i] = NULL; + } +} + void initialize_positions(void *obj, int offset) { Area *a = (Area *)obj; @@ -517,7 +527,7 @@ void draw_background(Area *a, cairo_t *c) cairo_fill(c); } - for (GList *l = a->gradient_instances; l; l = l->next) { + for (GList *l = a->gradient_instances_by_state[a->mouse_state]; l; l = l->next) { GradientInstance *gi = (GradientInstance *)l->data; if (!gi->pattern) update_gradient(gi); @@ -624,10 +634,6 @@ void free_area(Area *a) mouse_over_area = NULL; } free_area_gradient_instances(a); - if (debug_gradients) - fprintf(stderr, YELLOW "freeing gradient list %p" RESET "\n", (void*)a->gradients); - g_list_free(a->gradients); - a->gradients = NULL; } void mouse_over(Area *area, int pressed) @@ -653,8 +659,7 @@ void mouse_over(Area *area, int pressed) mouse_over_area = area; mouse_over_area->mouse_state = new_state; - mouse_over_area->pix = - mouse_over_area->pix_by_state[mouse_over_area->has_mouse_over_effect ? mouse_over_area->mouse_state : 0]; + mouse_over_area->pix = mouse_over_area->pix_by_state[mouse_over_area->mouse_state]; if (!mouse_over_area->pix) mouse_over_area->_redraw_needed = TRUE; panel_refresh = TRUE; @@ -665,8 +670,7 @@ void mouse_out() if (!mouse_over_area) return; mouse_over_area->mouse_state = MOUSE_NORMAL; - mouse_over_area->pix = - mouse_over_area->pix_by_state[mouse_over_area->has_mouse_over_effect ? mouse_over_area->mouse_state : 0]; + mouse_over_area->pix = mouse_over_area->pix_by_state[mouse_over_area->mouse_state]; if (!mouse_over_area->pix) mouse_over_area->_redraw_needed = TRUE; panel_refresh = TRUE; @@ -956,14 +960,16 @@ void free_gradient_instance(GradientInstance *gi) void instantiate_area_gradients(Area *area) { - g_assert_null(area->gradient_instances); if (debug_gradients) fprintf(stderr, "Initializing gradients for area %s\n", area->name); - for (GList *l = area->gradients; l; l = l->next) { - GradientClass *g = (GradientClass *)l->data; - GradientInstance *gi = (GradientInstance *)calloc(1, sizeof(GradientInstance)); - instantiate_gradient(area, g, gi); - area->gradient_instances = g_list_append(area->gradient_instances, gi); + for (int i = 0; i < MOUSE_STATE_COUNT; i++) { + g_assert_null(area->gradient_instances_by_state[i]); + for (GList *l = area->bg->gradients[i]; l; l = l->next) { + GradientClass *g = (GradientClass *)l->data; + GradientInstance *gi = (GradientInstance *)calloc(1, sizeof(GradientInstance)); + instantiate_gradient(area, g, gi); + area->gradient_instances_by_state[i] = g_list_append(area->gradient_instances_by_state[i], gi); + } } } @@ -971,12 +977,14 @@ void free_area_gradient_instances(Area *area) { if (debug_gradients) fprintf(stderr, "Freeing gradients for area %s\n", area->name); - for (GList *l = area->gradient_instances; l; l = l->next) { - GradientInstance *gi = (GradientInstance *)l->data; - free_gradient_instance(gi); + for (int i = 0; i < MOUSE_STATE_COUNT; i++) { + for (GList *l = area->gradient_instances_by_state[i]; l; l = l->next) { + GradientInstance *gi = (GradientInstance *)l->data; + free_gradient_instance(gi); + } + g_list_free_full(area->gradient_instances_by_state[i], free); + area->gradient_instances_by_state[i] = NULL; } - g_list_free_full(area->gradient_instances, free); - area->gradient_instances = NULL; g_assert_null(area->dependent_gradients); } diff --git a/src/util/area.h b/src/util/area.h index 2ef300b..cc1fb75 100644 --- a/src/util/area.h +++ b/src/util/area.h @@ -140,6 +140,8 @@ typedef struct Border { int mask; } Border; +typedef enum MouseState { MOUSE_NORMAL = 0, MOUSE_OVER = 1, MOUSE_DOWN = 2, MOUSE_STATE_COUNT } MouseState; + typedef struct Background { // Normal state Color fill_color; @@ -150,6 +152,8 @@ typedef struct Background { // On mouse press Color fill_color_pressed; Color border_color_pressed; + // Each list element is a pointer to a GradientClass (list can be empty), no ownership + GList *gradients[MOUSE_STATE_COUNT]; } Background; typedef enum Layout { @@ -163,8 +167,6 @@ typedef enum Alignment { ALIGN_RIGHT = 2, } Alignment; -typedef enum MouseState { MOUSE_NORMAL = 0, MOUSE_OVER = 1, MOUSE_DOWN = 2, MOUSE_STATE_COUNT } MouseState; - struct Panel; typedef struct Area { @@ -174,10 +176,8 @@ typedef struct Area { int width, height; int old_width, old_height; Background *bg; - // Each element is a pointer to a GradientClass (list can be empty), no ownership - GList *gradients; // Each element is a GradientInstance attached to this Area (list can be empty) - GList *gradient_instances; + GList *gradient_instances_by_state[MOUSE_STATE_COUNT]; // Each element is a GradientInstance that depends on this Area's geometry (position or size) GList *dependent_gradients; // List of children, each one a pointer to Area @@ -244,6 +244,7 @@ typedef struct Area { // Initializes the Background member to default values. void init_background(Background *bg); +void cleanup_background(Background *bg); // Layout