diff options
author | raveit65 <[email protected]> | 2016-07-31 23:56:30 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2016-08-31 15:29:57 +0200 |
commit | 9684cbb449ce68a11ea9ccf4d040e9b49b189eee (patch) | |
tree | 135f5a95aeaa88f49482c4164a8ada3e87a8143a /multiload | |
parent | af8334ea1159d64330d1c295000b78ed0daa9f63 (diff) | |
download | mate-applets-9684cbb449ce68a11ea9ccf4d040e9b49b189eee.tar.bz2 mate-applets-9684cbb449ce68a11ea9ccf4d040e9b49b189eee.tar.xz |
GTK+-3 multiload: port to GtkColorChooser and GdkRGBA
Diffstat (limited to 'multiload')
-rw-r--r-- | multiload/global.h | 4 | ||||
-rw-r--r-- | multiload/load-graph.c | 24 | ||||
-rw-r--r-- | multiload/properties.c | 36 |
3 files changed, 61 insertions, 3 deletions
diff --git a/multiload/global.h b/multiload/global.h index 52e25db6..8971df2c 100644 --- a/multiload/global.h +++ b/multiload/global.h @@ -30,7 +30,11 @@ struct _LoadGraph { guint allocated; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA *colors; +#else GdkColor *colors; +#endif gint **data; guint data_size; guint *pos; diff --git a/multiload/load-graph.c b/multiload/load-graph.c index b8d648a6..c0403e85 100644 --- a/multiload/load-graph.c +++ b/multiload/load-graph.c @@ -73,7 +73,11 @@ load_graph_draw (LoadGraph *g) for (j = 0; j < g->n; j++) { +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_cairo_set_source_rgba (cr, &(g->colors [j])); +#else gdk_cairo_set_source_color (cr, &(g->colors [j])); +#endif for (i = 0; i < g->draw_width; i++) { if (g->data [i][j] != 0) { @@ -260,21 +264,39 @@ load_graph_leave_cb(GtkWidget *widget, GdkEventCrossing *event, gpointer data) static void load_graph_load_config (LoadGraph *g) { - +#if GTK_CHECK_VERSION (3, 0, 0) + gchar *name, *temp; +#else gchar name [BUFSIZ], *temp; +#endif guint i; if (!g->colors) +#if GTK_CHECK_VERSION (3, 0, 0) + g->colors = g_new0(GdkRGBA, g->n); +#else g->colors = g_new0(GdkColor, g->n); +#endif for (i = 0; i < g->n; i++) { +#if GTK_CHECK_VERSION (3, 0, 0) + name = g_strdup_printf ("%s-color%u", g->name, i); +#else g_snprintf(name, sizeof(name), "%s-color%u", g->name, i); +#endif temp = g_settings_get_string(g->multiload->settings, name); if (!temp) temp = g_strdup ("#000000"); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_rgba_parse(&(g->colors[i]), temp); +#else gdk_color_parse(temp, &(g->colors[i])); +#endif g_free(temp); +#if GTK_CHECK_VERSION (3, 0, 0) + g_free(name); +#endif } } diff --git a/multiload/properties.c b/multiload/properties.c index 31cd28b0..b00635d8 100644 --- a/multiload/properties.c +++ b/multiload/properties.c @@ -217,11 +217,21 @@ add_page(GtkWidget *notebook, gchar *label) /* save the selected color to gsettings and apply it on the applet */ static void +#if GTK_CHECK_VERSION (3, 0, 0) +color_picker_set_cb(GtkColorChooser *color_picker, gchar *key) +#else color_picker_set_cb(GtkColorButton *color_picker, gchar *key) +#endif { +#if GTK_CHECK_VERSION (3, 0, 0) + gchar *color_string; + guint8 prop_type; + GdkRGBA color; +#else gchar color_string[8]; guint8 prop_type; GdkColor color; +#endif MultiloadApplet *ma; ma = g_object_get_data (G_OBJECT (color_picker), "MultiloadApplet"); @@ -240,15 +250,25 @@ color_picker_set_cb(GtkColorButton *color_picker, gchar *key) prop_type = PROP_DISK; else g_assert_not_reached(); - + +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_chooser_get_rgba(color_picker, &color); + + color_string = gdk_rgba_to_string (&color); + g_settings_set_string(ma->settings, key, color_string); + + gdk_rgba_parse(&(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]), + color_string); +#else gtk_color_button_get_color(color_picker, &color); snprintf(color_string, 8, "#%02X%02X%02X", color.red / 256, color.green / 256, color.blue / 256); g_settings_set_string(ma->settings, key, color_string); - + gdk_color_parse(color_string, &(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]) ); +#endif #if !GTK_CHECK_VERSION (3, 0, 0) ma->graphs[prop_type]->colors_allocated = FALSE; @@ -264,18 +284,26 @@ add_color_selector(GtkWidget *page, gchar *name, gchar *key, MultiloadApplet *ma GtkWidget *vbox; GtkWidget *label; GtkWidget *color_picker; +#if GTK_CHECK_VERSION (3, 0, 0) + GdkRGBA color; +#else GdkColor color; +#endif gchar *color_string; color_string = g_settings_get_string (ma->settings, key); if (!color_string) color_string = g_strdup ("#000000"); +#if GTK_CHECK_VERSION (3, 0, 0) + gdk_rgba_parse (&color, color_string); +#else color.red = (g_ascii_xdigit_value(color_string[1]) * 16 + g_ascii_xdigit_value(color_string[2])) * 256; color.green = (g_ascii_xdigit_value(color_string[3]) * 16 + g_ascii_xdigit_value(color_string[4])) * 256; color.blue = (g_ascii_xdigit_value(color_string[5]) * 16 + g_ascii_xdigit_value(color_string[6])) * 256; +#endif g_free (color_string); vbox = gtk_vbox_new (FALSE, 6); @@ -290,7 +318,11 @@ add_color_selector(GtkWidget *page, gchar *name, gchar *key, MultiloadApplet *ma g_object_set_data (G_OBJECT (color_picker), "MultiloadApplet", ma); +#if GTK_CHECK_VERSION (3, 0, 0) + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color_picker), &color); +#else gtk_color_button_set_color(GTK_COLOR_BUTTON(color_picker), &color); +#endif g_signal_connect(G_OBJECT(color_picker), "color_set", G_CALLBACK(color_picker_set_cb), key); |