all repos — tint2 @ 2299132cd340e23ff1fad291cf131bee73ed9ef6

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

tint2conf: Add background labels
o9000 mrovi9000@gmail.com
commit

2299132cd340e23ff1fad291cf131bee73ed9ef6

parent

005e5a49c03c0e05bebcbf84bb351bc62dd407a6

3 files changed, 114 insertions(+), 21 deletions(-)

jump to
M src/tint2conf/properties.csrc/tint2conf/properties.c

@@ -141,6 +141,7 @@ void background_delete(GtkWidget *widget, gpointer data);

void background_update_image(int index); void background_update(GtkWidget *widget, gpointer data); void current_background_changed(GtkWidget *widget, gpointer data); +void background_combo_changed(GtkWidget *widget, gpointer data); void create_panel(GtkWidget *parent); void create_panel_items(GtkWidget *parent); void create_launcher(GtkWidget *parent);

@@ -151,6 +152,7 @@ void create_taskbar(GtkWidget *parent);

void create_task(GtkWidget *parent); void create_task_status(GtkWidget *notebook, char *name, + char *text, GtkWidget **task_status_color, GtkWidget **task_status_color_set, GtkWidget **task_status_icon_opacity,

@@ -167,6 +169,11 @@ void panel_add_item(GtkWidget *widget, gpointer data);

void panel_remove_item(GtkWidget *widget, gpointer data); void panel_move_item_down(GtkWidget *widget, gpointer data); void panel_move_item_up(GtkWidget *widget, gpointer data); + +static gint compare_strings(gconstpointer a, gconstpointer b) +{ + return strnatcasecmp((const char*)a, (const char*)b); +} void applyClicked(GtkWidget *widget, gpointer data) {

@@ -337,15 +344,94 @@ gtk_box_pack_start(GTK_BOX(widget), hbox, FALSE, FALSE, 0);

gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); } -GtkWidget *create_background_combo() +GtkWidget *create_background_combo(const char *label) { GtkWidget *combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(backgrounds)); GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "pixbuf", 0, NULL); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "pixbuf", bgColPixbuf, NULL); + renderer = gtk_cell_renderer_text_new(); + g_object_set(renderer, "wrap-mode", PANGO_WRAP_WORD, NULL); + g_object_set(renderer, "wrap-width", 300, NULL); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "text", bgColText, NULL); + g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(background_combo_changed), (void*)label); return combo; } +void background_combo_changed(GtkWidget *widget, gpointer data) +{ + gchar *combo_text = (gchar*)data; + if (!combo_text || g_str_equal(combo_text, "")) + return; + int selected_index = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); + + int index; + for (index = 0; ; index++) { + GtkTreePath *path; + GtkTreeIter iter; + + path = gtk_tree_path_new_from_indices(index, -1); + gboolean found = gtk_tree_model_get_iter(GTK_TREE_MODEL(backgrounds), &iter, path); + gtk_tree_path_free(path); + + if (!found) { + break; + } + + gchar *text; + gtk_tree_model_get(GTK_TREE_MODEL(backgrounds), &iter, + bgColText, &text, + -1); + gchar **parts = g_strsplit(text, ", ", -1); + int ifound; + for (ifound = 0; parts[ifound]; ifound++) { + if (g_str_equal(parts[ifound], combo_text)) + break; + } + if (parts[ifound] && index != selected_index) { + for (; parts[ifound+1]; ifound++) { + gchar *tmp = parts[ifound]; + parts[ifound] = parts[ifound+1]; + parts[ifound+1] = tmp; + } + g_free(parts[ifound]); + parts[ifound] = NULL; + text = g_strjoinv(", ", parts); + g_strfreev(parts); + gtk_list_store_set(backgrounds, &iter, + bgColText, text, + -1); + g_free(text); + } else if (!parts[ifound] && index == selected_index) { + if (!ifound) { + text = g_strdup(combo_text); + } else { + for (ifound = 0; parts[ifound]; ifound++) { + if (compare_strings(combo_text, parts[ifound]) < 0) + break; + } + if (parts[ifound]) { + gchar *tmp = parts[ifound]; + parts[ifound] = g_strconcat(combo_text, ", ", tmp, NULL); + g_free(tmp); + } else { + ifound--; + gchar *tmp = parts[ifound]; + parts[ifound] = g_strconcat(tmp, ", ", combo_text, NULL); + g_free(tmp); + } + text = g_strjoinv(", ", parts); + g_strfreev(parts); + } + gtk_list_store_set(backgrounds, &iter, + bgColText, text, + -1); + g_free(text); + } + } +} + void gdkColor2CairoColor(GdkColor color, double *red, double *green, double *blue) { *red = color.red / (double)0xffff;

@@ -370,7 +456,8 @@ GTK_TYPE_INT,

GDK_TYPE_COLOR, GTK_TYPE_INT, GTK_TYPE_INT, - GTK_TYPE_INT); + GTK_TYPE_INT, + GTK_TYPE_STRING); GtkWidget *table, *label, *button; int row, col;

@@ -390,7 +477,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - current_background = create_background_combo(); + current_background = create_background_combo(NULL); gtk_widget_show(current_background); gtk_table_attach(GTK_TABLE(table), current_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -528,6 +615,7 @@ bgColBorderColor, &borderColor,

bgColBorderOpacity, borderOpacity, bgColBorderWidth, b, bgColCornerRadius, r, + bgColText, "", -1); background_update_image(index);

@@ -574,6 +662,7 @@ bgColBorderColor, borderColor,

bgColBorderOpacity, borderOpacity, bgColBorderWidth, b, bgColCornerRadius, r, + bgColText, "" -1); g_boxed_free(GDK_TYPE_COLOR, fillColor); g_boxed_free(GDK_TYPE_COLOR, borderColor);

@@ -958,7 +1047,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - panel_background = create_background_combo(); + panel_background = create_background_combo(_("Panel")); gtk_widget_show(panel_background); gtk_table_attach(GTK_TABLE(table), panel_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -1810,11 +1899,6 @@ entry->icon = strdup("");

*entries = g_list_append(*entries, entry); } -static gint compare_strings(gconstpointer a, gconstpointer b) -{ - return strnatcasecmp((const char*)a, (const char*)b); -} - void load_desktop_entries(const char *path, GList **entries) { GList *subdirs = NULL;

@@ -2109,7 +2193,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - launcher_background = create_background_combo(); + launcher_background = create_background_combo(_("Launcher")); gtk_widget_show(launcher_background); gtk_table_attach(GTK_TABLE(table), launcher_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -2485,7 +2569,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - taskbar_active_background = create_background_combo(); + taskbar_active_background = create_background_combo(_("Active taskbar")); gtk_widget_show(taskbar_active_background); gtk_table_attach(GTK_TABLE(table), taskbar_active_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -2499,7 +2583,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - taskbar_inactive_background = create_background_combo(); + taskbar_inactive_background = create_background_combo(_("Inactive taskbar")); gtk_widget_show(taskbar_inactive_background); gtk_table_attach(GTK_TABLE(table), taskbar_inactive_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -2619,7 +2703,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - taskbar_name_active_background = create_background_combo(); + taskbar_name_active_background = create_background_combo(_("Active desktop name")); gtk_widget_show(taskbar_name_active_background); gtk_table_attach(GTK_TABLE(table), taskbar_name_active_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -2634,7 +2718,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - taskbar_name_inactive_background = create_background_combo(); + taskbar_name_inactive_background = create_background_combo(_("Inactive desktop name")); gtk_widget_show(taskbar_name_inactive_background); gtk_table_attach(GTK_TABLE(table), taskbar_name_inactive_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -2998,6 +3082,7 @@ gtk_box_pack_start(GTK_BOX(parent), notebook, TRUE, TRUE, 0);

create_task_status(notebook, _("Default style"), + _("Default task"), &task_default_color, &task_default_color_set, &task_default_icon_opacity,

@@ -3007,6 +3092,7 @@ &task_default_icon_brightness,

&task_default_background, &task_default_background_set); create_task_status(notebook, + _("Normal task"), _("Normal task"), &task_normal_color, &task_normal_color_set,

@@ -3018,6 +3104,7 @@ &task_normal_background,

&task_normal_background_set); create_task_status(notebook, _("Active task"), + _("Active task"), &task_active_color, &task_active_color_set, &task_active_icon_opacity,

@@ -3027,6 +3114,7 @@ &task_active_icon_brightness,

&task_active_background, &task_active_background_set); create_task_status(notebook, + _("Urgent task"), _("Urgent task"), &task_urgent_color, &task_urgent_color_set,

@@ -3038,6 +3126,7 @@ &task_urgent_background,

&task_urgent_background_set); create_task_status(notebook, _("Iconified task"), + _("Iconified task"), &task_iconified_color, &task_iconified_color_set, &task_iconified_icon_opacity,

@@ -3113,6 +3202,7 @@ }

void create_task_status(GtkWidget *notebook, char *name, + char *text, GtkWidget **task_status_color, GtkWidget **task_status_color_set, GtkWidget **task_status_icon_opacity,

@@ -3200,7 +3290,7 @@ gtk_misc_set_alignment(GTK_MISC(label), 0, 0);

gtk_widget_show(label); gtk_table_attach(GTK_TABLE(table), label, 1, 2, 4, 5, GTK_FILL, 0, 0, 0); - *task_status_background = create_background_combo(); + *task_status_background = create_background_combo(text); gtk_widget_show(*task_status_background); gtk_table_attach(GTK_TABLE(table), *task_status_background, 2, 3, 4, 5, GTK_FILL, 0, 0, 0); gtk_tooltips_set_tip(tooltips, *task_status_background, _("Selects the background used to display the task. "

@@ -3422,7 +3512,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - clock_background = create_background_combo(); + clock_background = create_background_combo(_("Clock")); gtk_widget_show(clock_background); gtk_table_attach(GTK_TABLE(table), clock_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -3631,7 +3721,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - systray_background = create_background_combo(); + systray_background = create_background_combo(_("Systray")); gtk_widget_show(systray_background); gtk_table_attach(GTK_TABLE(table), systray_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -3984,7 +4074,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - battery_background = create_background_combo(); + battery_background = create_background_combo(_("Battery")); gtk_widget_show(battery_background); gtk_table_attach(GTK_TABLE(table), battery_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;

@@ -4142,7 +4232,7 @@ gtk_widget_show(label);

gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++; - tooltip_background = create_background_combo(); + tooltip_background = create_background_combo(_("Tooltip")); gtk_widget_show(tooltip_background); gtk_table_attach(GTK_TABLE(table), tooltip_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); col++;
M src/tint2conf/properties.hsrc/tint2conf/properties.h

@@ -146,6 +146,7 @@ bgColBorderColor,

bgColBorderOpacity, bgColBorderWidth, bgColCornerRadius, + bgColText, bgNumCols };
M src/tint2conf/properties_rw.csrc/tint2conf/properties_rw.c

@@ -110,6 +110,7 @@ GdkColor *fillColor;

int fillOpacity; GdkColor *borderColor; int borderOpacity; + gchar *text; gtk_tree_model_get(GTK_TREE_MODEL(backgrounds), &iter, bgColFillColor, &fillColor,

@@ -118,8 +119,9 @@ bgColBorderColor, &borderColor,

bgColBorderOpacity, &borderOpacity, bgColBorderWidth, &b, bgColCornerRadius, &r, + bgColText, &text, -1); - fprintf(fp, "# Background %d\n", index); + fprintf(fp, "# Background %d: %s\n", index, text ? text : ""); fprintf(fp, "rounded = %d\n", r); fprintf(fp, "border_width = %d\n", b); config_write_color(fp, "background_color", *fillColor, fillOpacity);