all repos — tint2 @ 7c0df616b98026edda1c745d078509a1ddb321a6

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

Move gradients into backgrounds
o9000 mrovi9000@gmail.com
commit

7c0df616b98026edda1c745d078509a1ddb321a6

parent

f438ef712bbb673d58a448774446f148ebec4d8d

M src/config.csrc/config.c

@@ -313,6 +313,24 @@ bg->border_color_pressed.alpha = (atoi(value2) / 100.0);

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 @@ else if (strcmp(key, "panel_background_id") == 0) {

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)

@@ -642,13 +655,6 @@ 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 percentage_hide = atoi(value);

@@ -669,12 +675,6 @@ Separator *separator = get_or_create_last_separator();

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 @@ Execp *execp = get_or_create_last_execp();

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 @@ } else if (strcmp(key, "clock_background_id") == 0) {

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 @@ id = (id < backgrounds->len && id >= 0) ? id : 0;

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 @@ panel_config.g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, id);

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 @@ 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]; } - } 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 @@ } else if (strcmp(key, "systray_background_id") == 0) {

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 @@ } else if (strcmp(key, "launcher_background_id") == 0) {

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) {
M src/launcher/launcher.csrc/launcher/launcher.c

@@ -492,7 +492,6 @@ launcherIcon->area.resize_needed = 0;

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;
M src/panel.csrc/panel.c

@@ -156,8 +156,10 @@ panels = NULL;

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 @@

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,
M src/taskbar/task.csrc/taskbar/task.c

@@ -611,7 +611,6 @@ Task *task1 = g_ptr_array_index(task_buttons, i);

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))
M src/taskbar/taskbar.csrc/taskbar/taskbar.c

@@ -318,12 +318,10 @@ taskbar->desktop = j;

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); }
M src/taskbar/taskbarname.csrc/taskbar/taskbarname.c

@@ -64,10 +64,8 @@ taskbar->bar_name.area.has_mouse_press_effect = panel_config.mouse_effects;

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
M src/util/area.csrc/util/area.c

@@ -40,6 +40,16 @@ memset(bg, 0, sizeof(Background));

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 @@ a->bg->border.radius - a->bg->border.width / 1.571);

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 @@ if (mouse_over_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 @@ return;

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 @@ {

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 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); }
M src/util/area.hsrc/util/area.h

@@ -140,6 +140,8 @@ // Mask: bitwise OR of BorderMask

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 @@ Color border_color_hover;

// 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 @@ ALIGN_CENTER = 1,

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 @@ // Size, including borders

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 @@ } Area;

// Initializes the Background member to default values. void init_background(Background *bg); +void cleanup_background(Background *bg); // Layout