tint2conf: Add background labels

This commit is contained in:
o9000
2015-09-23 23:56:38 +02:00
parent 005e5a49c0
commit 2299132cd3
3 changed files with 114 additions and 21 deletions

View File

@@ -141,6 +141,7 @@ void background_delete(GtkWidget *widget, gpointer data);
void background_update_image(int index); void background_update_image(int index);
void background_update(GtkWidget *widget, gpointer data); void background_update(GtkWidget *widget, gpointer data);
void current_background_changed(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(GtkWidget *parent);
void create_panel_items(GtkWidget *parent); void create_panel_items(GtkWidget *parent);
void create_launcher(GtkWidget *parent); void create_launcher(GtkWidget *parent);
@@ -151,6 +152,7 @@ void create_taskbar(GtkWidget *parent);
void create_task(GtkWidget *parent); void create_task(GtkWidget *parent);
void create_task_status(GtkWidget *notebook, void create_task_status(GtkWidget *notebook,
char *name, char *name,
char *text,
GtkWidget **task_status_color, GtkWidget **task_status_color,
GtkWidget **task_status_color_set, GtkWidget **task_status_color_set,
GtkWidget **task_status_icon_opacity, GtkWidget **task_status_icon_opacity,
@@ -168,6 +170,11 @@ void panel_remove_item(GtkWidget *widget, gpointer data);
void panel_move_item_down(GtkWidget *widget, gpointer data); void panel_move_item_down(GtkWidget *widget, gpointer data);
void panel_move_item_up(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) void applyClicked(GtkWidget *widget, gpointer data)
{ {
gchar *file = get_current_theme_file_name(); gchar *file = get_current_theme_file_name();
@@ -337,15 +344,94 @@ void change_paragraph(GtkWidget *widget)
gtk_container_set_border_width(GTK_CONTAINER(hbox), 6); 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)); GtkWidget *combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(backgrounds));
GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new(); GtkCellRenderer *renderer = gtk_cell_renderer_pixbuf_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, FALSE); 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; 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) void gdkColor2CairoColor(GdkColor color, double *red, double *green, double *blue)
{ {
*red = color.red / (double)0xffff; *red = color.red / (double)0xffff;
@@ -370,7 +456,8 @@ void create_background(GtkWidget *parent)
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT, GTK_TYPE_INT,
GTK_TYPE_INT); GTK_TYPE_INT,
GTK_TYPE_STRING);
GtkWidget *table, *label, *button; GtkWidget *table, *label, *button;
int row, col; int row, col;
@@ -390,7 +477,7 @@ void create_background(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
current_background = create_background_combo(); current_background = create_background_combo(NULL);
gtk_widget_show(current_background); gtk_widget_show(current_background);
gtk_table_attach(GTK_TABLE(table), current_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), current_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -528,6 +615,7 @@ void background_create_new()
bgColBorderOpacity, borderOpacity, bgColBorderOpacity, borderOpacity,
bgColBorderWidth, b, bgColBorderWidth, b,
bgColCornerRadius, r, bgColCornerRadius, r,
bgColText, "",
-1); -1);
background_update_image(index); background_update_image(index);
@@ -574,6 +662,7 @@ void background_duplicate(GtkWidget *widget, gpointer data)
bgColBorderOpacity, borderOpacity, bgColBorderOpacity, borderOpacity,
bgColBorderWidth, b, bgColBorderWidth, b,
bgColCornerRadius, r, bgColCornerRadius, r,
bgColText, ""
-1); -1);
g_boxed_free(GDK_TYPE_COLOR, fillColor); g_boxed_free(GDK_TYPE_COLOR, fillColor);
g_boxed_free(GDK_TYPE_COLOR, borderColor); g_boxed_free(GDK_TYPE_COLOR, borderColor);
@@ -958,7 +1047,7 @@ void create_panel(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
panel_background = create_background_combo(); panel_background = create_background_combo(_("Panel"));
gtk_widget_show(panel_background); gtk_widget_show(panel_background);
gtk_table_attach(GTK_TABLE(table), panel_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), panel_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -1810,11 +1899,6 @@ void load_desktop_entry(const char *file, GList **entries)
*entries = g_list_append(*entries, entry); *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) void load_desktop_entries(const char *path, GList **entries)
{ {
GList *subdirs = NULL; GList *subdirs = NULL;
@@ -2109,7 +2193,7 @@ void create_launcher(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
launcher_background = create_background_combo(); launcher_background = create_background_combo(_("Launcher"));
gtk_widget_show(launcher_background); gtk_widget_show(launcher_background);
gtk_table_attach(GTK_TABLE(table), launcher_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), launcher_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -2485,7 +2569,7 @@ void create_taskbar(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
taskbar_active_background = create_background_combo(); taskbar_active_background = create_background_combo(_("Active taskbar"));
gtk_widget_show(taskbar_active_background); 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); gtk_table_attach(GTK_TABLE(table), taskbar_active_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -2499,7 +2583,7 @@ void create_taskbar(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
taskbar_inactive_background = create_background_combo(); taskbar_inactive_background = create_background_combo(_("Inactive taskbar"));
gtk_widget_show(taskbar_inactive_background); 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); gtk_table_attach(GTK_TABLE(table), taskbar_inactive_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -2619,7 +2703,7 @@ void create_taskbar(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; 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_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); gtk_table_attach(GTK_TABLE(table), taskbar_name_active_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -2634,7 +2718,7 @@ void create_taskbar(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; 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_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); gtk_table_attach(GTK_TABLE(table), taskbar_name_inactive_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -2998,6 +3082,7 @@ void create_task(GtkWidget *parent)
create_task_status(notebook, create_task_status(notebook,
_("Default style"), _("Default style"),
_("Default task"),
&task_default_color, &task_default_color,
&task_default_color_set, &task_default_color_set,
&task_default_icon_opacity, &task_default_icon_opacity,
@@ -3007,6 +3092,7 @@ void create_task(GtkWidget *parent)
&task_default_background, &task_default_background,
&task_default_background_set); &task_default_background_set);
create_task_status(notebook, create_task_status(notebook,
_("Normal task"),
_("Normal task"), _("Normal task"),
&task_normal_color, &task_normal_color,
&task_normal_color_set, &task_normal_color_set,
@@ -3017,6 +3103,7 @@ void create_task(GtkWidget *parent)
&task_normal_background, &task_normal_background,
&task_normal_background_set); &task_normal_background_set);
create_task_status(notebook, create_task_status(notebook,
_("Active task"),
_("Active task"), _("Active task"),
&task_active_color, &task_active_color,
&task_active_color_set, &task_active_color_set,
@@ -3027,6 +3114,7 @@ void create_task(GtkWidget *parent)
&task_active_background, &task_active_background,
&task_active_background_set); &task_active_background_set);
create_task_status(notebook, create_task_status(notebook,
_("Urgent task"),
_("Urgent task"), _("Urgent task"),
&task_urgent_color, &task_urgent_color,
&task_urgent_color_set, &task_urgent_color_set,
@@ -3037,6 +3125,7 @@ void create_task(GtkWidget *parent)
&task_urgent_background, &task_urgent_background,
&task_urgent_background_set); &task_urgent_background_set);
create_task_status(notebook, create_task_status(notebook,
_("Iconified task"),
_("Iconified task"), _("Iconified task"),
&task_iconified_color, &task_iconified_color,
&task_iconified_color_set, &task_iconified_color_set,
@@ -3113,6 +3202,7 @@ void task_status_toggle_button_callback(GtkWidget *widget, gpointer data)
void create_task_status(GtkWidget *notebook, void create_task_status(GtkWidget *notebook,
char *name, char *name,
char *text,
GtkWidget **task_status_color, GtkWidget **task_status_color,
GtkWidget **task_status_color_set, GtkWidget **task_status_color_set,
GtkWidget **task_status_icon_opacity, GtkWidget **task_status_icon_opacity,
@@ -3200,7 +3290,7 @@ void create_task_status(GtkWidget *notebook,
gtk_widget_show(label); gtk_widget_show(label);
gtk_table_attach(GTK_TABLE(table), label, 1, 2, 4, 5, GTK_FILL, 0, 0, 0); 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_widget_show(*task_status_background);
gtk_table_attach(GTK_TABLE(table), *task_status_background, 2, 3, 4, 5, GTK_FILL, 0, 0, 0); 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. " gtk_tooltips_set_tip(tooltips, *task_status_background, _("Selects the background used to display the task. "
@@ -3422,7 +3512,7 @@ void create_clock(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
clock_background = create_background_combo(); clock_background = create_background_combo(_("Clock"));
gtk_widget_show(clock_background); gtk_widget_show(clock_background);
gtk_table_attach(GTK_TABLE(table), clock_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), clock_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -3631,7 +3721,7 @@ void create_systemtray(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
systray_background = create_background_combo(); systray_background = create_background_combo(_("Systray"));
gtk_widget_show(systray_background); gtk_widget_show(systray_background);
gtk_table_attach(GTK_TABLE(table), systray_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), systray_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -3984,7 +4074,7 @@ void create_battery(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
battery_background = create_background_combo(); battery_background = create_background_combo(_("Battery"));
gtk_widget_show(battery_background); gtk_widget_show(battery_background);
gtk_table_attach(GTK_TABLE(table), battery_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), battery_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
@@ -4142,7 +4232,7 @@ void create_tooltip(GtkWidget *parent)
gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;
tooltip_background = create_background_combo(); tooltip_background = create_background_combo(_("Tooltip"));
gtk_widget_show(tooltip_background); gtk_widget_show(tooltip_background);
gtk_table_attach(GTK_TABLE(table), tooltip_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0); gtk_table_attach(GTK_TABLE(table), tooltip_background, col, col+1, row, row+1, GTK_FILL, 0, 0, 0);
col++; col++;

View File

@@ -146,6 +146,7 @@ enum {
bgColBorderOpacity, bgColBorderOpacity,
bgColBorderWidth, bgColBorderWidth,
bgColCornerRadius, bgColCornerRadius,
bgColText,
bgNumCols bgNumCols
}; };

View File

@@ -110,6 +110,7 @@ void config_write_backgrounds(FILE *fp)
int fillOpacity; int fillOpacity;
GdkColor *borderColor; GdkColor *borderColor;
int borderOpacity; int borderOpacity;
gchar *text;
gtk_tree_model_get(GTK_TREE_MODEL(backgrounds), &iter, gtk_tree_model_get(GTK_TREE_MODEL(backgrounds), &iter,
bgColFillColor, &fillColor, bgColFillColor, &fillColor,
@@ -118,8 +119,9 @@ void config_write_backgrounds(FILE *fp)
bgColBorderOpacity, &borderOpacity, bgColBorderOpacity, &borderOpacity,
bgColBorderWidth, &b, bgColBorderWidth, &b,
bgColCornerRadius, &r, bgColCornerRadius, &r,
bgColText, &text,
-1); -1);
fprintf(fp, "# Background %d\n", index); fprintf(fp, "# Background %d: %s\n", index, text ? text : "");
fprintf(fp, "rounded = %d\n", r); fprintf(fp, "rounded = %d\n", r);
fprintf(fp, "border_width = %d\n", b); fprintf(fp, "border_width = %d\n", b);
config_write_color(fp, "background_color", *fillColor, fillOpacity); config_write_color(fp, "background_color", *fillColor, fillOpacity);