diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/callbacks.cpp | 10 | ||||
-rw-r--r-- | src/gsm_color_button.c | 140 | ||||
-rw-r--r-- | src/gsm_color_button.h | 12 | ||||
-rw-r--r-- | src/load-graph.cpp | 28 | ||||
-rw-r--r-- | src/load-graph.h | 4 | ||||
-rw-r--r-- | src/procman.cpp | 40 | ||||
-rw-r--r-- | src/procman.h | 10 |
7 files changed, 242 insertions, 2 deletions
diff --git a/src/callbacks.cpp b/src/callbacks.cpp index 4540dba..bb18e8b 100644 --- a/src/callbacks.cpp +++ b/src/callbacks.cpp @@ -250,12 +250,22 @@ cb_end_process_button_pressed (GtkButton *button, gpointer data) static void change_settings_color(GSettings *settings, const char *key, GSMColorButton *cp) { +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA c; + char *color; + + gsm_color_button_get_color(cp, &c); + color = gdk_rgba_to_string (&c); + g_settings_set_string (settings, key, color); + g_free (color); +#else GdkColor c; char color[24]; /* color should be 1 + 3*4 + 1 = 15 chars -> 24 */ gsm_color_button_get_color(cp, &c); g_snprintf(color, sizeof color, "#%04x%04x%04x", c.red, c.green, c.blue); g_settings_set_string (settings, key, color); +#endif } diff --git a/src/gsm_color_button.c b/src/gsm_color_button.c index 19e249b..b3744ea 100644 --- a/src/gsm_color_button.c +++ b/src/gsm_color_button.c @@ -31,6 +31,9 @@ #include <gdk/gdkkeysyms.h> #include <math.h> #include <cairo.h> +#if GTK_CHECK_VERSION(3,0,0) +#include <librsvg/rsvg.h> +#endif #include "gsm_color_button.h" @@ -38,11 +41,19 @@ struct _GSMColorButtonPrivate { +#if GTK_CHECK_VERSION(3,0,0) + GtkWidget *cc_dialog; /* Color chooser dialog */ + + gchar *title; /* Title for the color selection window */ + + GdkRGBA color; +#else GtkWidget *cs_dialog; /* Color selection dialog */ gchar *title; /* Title for the color selection window */ GdkColor color; +#endif gdouble fraction; /* Only used by GSMCP_TYPE_PIE */ guint type; @@ -219,7 +230,11 @@ gsm_color_button_class_init (GSMColorButtonClass * klass) g_param_spec_boxed ("color", _("Current Color"), _("The selected color"), +#if GTK_CHECK_VERSION(3,0,0) + GDK_TYPE_RGBA, +#else GDK_TYPE_COLOR, +#endif G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, @@ -276,6 +291,36 @@ static void render (GtkWidget * widget) { GSMColorButton *color_button = GSM_COLOR_BUTTON (widget); +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA *color; + GdkRGBA tmp_color = color_button->priv->color; + color = &tmp_color; + cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); + cairo_path_t *path = NULL; + gint width, height; + gdouble radius, arc_start, arc_end; + gdouble highlight_factor; + + if (color_button->priv->highlight > 0) { + highlight_factor = 0.125 * color_button->priv->highlight; + + if (color->red + highlight_factor > 1.0) + color->red = 1.0; + else + color->red = color->red + highlight_factor; + + if (color->blue + highlight_factor > 1.0) + color->blue = 1.0; + else + color->blue = color->blue + highlight_factor; + + if (color->green + highlight_factor > 1.0) + color->green = 1.0; + else + color->green = color->green + highlight_factor; + } + gdk_cairo_set_source_rgba (cr, color); +#else GdkColor *color, tmp_color = color_button->priv->color; color = &tmp_color; cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget)); @@ -303,6 +348,7 @@ render (GtkWidget * widget) color->green = color->green + highlight_factor; } gdk_cairo_set_source_color (cr, color); +#endif width = gdk_window_get_width(gtk_widget_get_window(widget)); height = gdk_window_get_height(gtk_widget_get_window(widget)); @@ -581,15 +627,25 @@ gsm_color_button_drag_data_received (GtkWidget * widget, static void +#if GTK_CHECK_VERSION(3,0,0) +set_color_icon (GdkDragContext * context, GdkRGBA * color) +#else set_color_icon (GdkDragContext * context, GdkColor * color) +#endif { GdkPixbuf *pixbuf; guint32 pixel; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 48, 32); +#if GTK_CHECK_VERSION(3,0,0) + pixel = ((guint32)(color->red * 0xff) << 24) | + ((guint32)(color->green * 0xff) << 16) | + ((guint32)(color->blue * 0xff) << 8); +#else pixel = ((color->red & 0xff00) << 16) | ((color->green & 0xff00) << 8) | (color->blue & 0xff00); +#endif gdk_pixbuf_fill (pixbuf, pixel); @@ -673,9 +729,15 @@ gsm_color_button_finalize (GObject * object) { GSMColorButton *color_button = GSM_COLOR_BUTTON (object); +#if GTK_CHECK_VERSION(3,0,0) + if (color_button->priv->cc_dialog != NULL) + gtk_widget_destroy (color_button->priv->cc_dialog); + color_button->priv->cc_dialog = NULL; +#else if (color_button->priv->cs_dialog != NULL) gtk_widget_destroy (color_button->priv->cs_dialog); color_button->priv->cs_dialog = NULL; +#endif g_free (color_button->priv->title); color_button->priv->title = NULL; @@ -687,7 +749,11 @@ gsm_color_button_finalize (GObject * object) } GtkWidget * +#if GTK_CHECK_VERSION(3,0,0) +gsm_color_button_new (const GdkRGBA * color, guint type) +#else gsm_color_button_new (const GdkColor * color, guint type) +#endif { return g_object_new (GSM_TYPE_COLOR_BUTTON, "color", color, "type", type, NULL); @@ -697,6 +763,16 @@ static void dialog_response (GtkWidget * widget, GtkResponseType response, gpointer data) { GSMColorButton *color_button = GSM_COLOR_BUTTON (data); +#if GTK_CHECK_VERSION(3,0,0) + GtkColorChooser *color_chooser; + + if (response == GTK_RESPONSE_OK) { + color_chooser = GTK_COLOR_CHOOSER (color_button->priv->cc_dialog); + + gtk_color_chooser_get_rgba (color_chooser, &color_button->priv->color); + + gtk_widget_hide (color_button->priv->cc_dialog); +#else GtkColorSelection *color_selection; if (response == GTK_RESPONSE_OK) { @@ -708,6 +784,7 @@ dialog_response (GtkWidget * widget, GtkResponseType response, gpointer data) &color_button->priv->color); gtk_widget_hide (color_button->priv->cs_dialog); +#endif gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget)); @@ -718,7 +795,11 @@ dialog_response (GtkWidget * widget, GtkResponseType response, gpointer data) g_object_thaw_notify (G_OBJECT (color_button)); } else /* (response == GTK_RESPONSE_CANCEL) */ +#if GTK_CHECK_VERSION(3,0,0) + gtk_widget_hide (color_button->priv->cc_dialog); +#else gtk_widget_hide (color_button->priv->cs_dialog); +#endif } static gboolean @@ -726,7 +807,11 @@ dialog_destroy (GtkWidget * widget, gpointer data) { GSMColorButton *color_button = GSM_COLOR_BUTTON (data); +#if GTK_CHECK_VERSION(3,0,0) + color_button->priv->cc_dialog = NULL; +#else color_button->priv->cs_dialog = NULL; +#endif return FALSE; } @@ -735,6 +820,37 @@ static gint gsm_color_button_clicked (GtkWidget * widget, GdkEventButton * event) { GSMColorButton *color_button = GSM_COLOR_BUTTON (widget); +#if GTK_CHECK_VERSION(3,0,0) + + /* if dialog already exists, make sure it's shown and raised */ + if (!color_button->priv->cc_dialog) + { + /* Create the dialog and connects its buttons */ + GtkWidget *cc_dialog; + GtkWidget *parent; + + parent = gtk_widget_get_toplevel (GTK_WIDGET (color_button)); + if (!gtk_widget_is_toplevel (parent)) + parent = NULL; + + cc_dialog = gtk_color_chooser_dialog_new (color_button->priv->title, GTK_WINDOW (parent)); + + gtk_window_set_modal (GTK_WINDOW (cc_dialog), TRUE); + + g_signal_connect (cc_dialog, "response", + G_CALLBACK (dialog_response), color_button); + + g_signal_connect (cc_dialog, "destroy", + G_CALLBACK (dialog_destroy), color_button); + + color_button->priv->cc_dialog = cc_dialog; + } + + gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (color_button->priv->cc_dialog), + &color_button->priv->color); + + gtk_window_present (GTK_WINDOW (color_button->priv->cc_dialog)); +#else GtkColorSelectionDialog *color_dialog; /* if dialog already exists, make sure it's shown and raised */ @@ -780,6 +896,7 @@ gsm_color_button_clicked (GtkWidget * widget, GdkEventButton * event) &color_button->priv->color); gtk_window_present (GTK_WINDOW (color_button->priv->cs_dialog)); +#endif return 0; } @@ -867,18 +984,29 @@ gsm_color_button_set_fraction (GSMColorButton * color_button, } void +#if GTK_CHECK_VERSION(3,0,0) +gsm_color_button_get_color (GSMColorButton * color_button, GdkRGBA * color) +#else gsm_color_button_get_color (GSMColorButton * color_button, GdkColor * color) +#endif { g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button)); color->red = color_button->priv->color.red; color->green = color_button->priv->color.green; color->blue = color_button->priv->color.blue; +#if GTK_CHECK_VERSION(3,0,0) + color->alpha = color_button->priv->color.alpha; +#endif } void gsm_color_button_set_color (GSMColorButton * color_button, +#if GTK_CHECK_VERSION(3,0,0) + const GdkRGBA * color) +#else const GdkColor * color) +#endif { g_return_if_fail (GSM_IS_COLOR_BUTTON (color_button)); g_return_if_fail (color != NULL); @@ -886,6 +1014,9 @@ gsm_color_button_set_color (GSMColorButton * color_button, color_button->priv->color.red = color->red; color_button->priv->color.green = color->green; color_button->priv->color.blue = color->blue; +#if GTK_CHECK_VERSION(3,0,0) + color_button->priv->color.alpha = color->alpha; +#endif gtk_widget_queue_draw (GTK_WIDGET (&color_button->widget)); //->priv->draw_area); @@ -904,8 +1035,13 @@ gsm_color_button_set_title (GSMColorButton * color_button, color_button->priv->title = g_strdup (title); g_free (old_title); +#if GTK_CHECK_VERSION(3,0,0) + if (color_button->priv->cc_dialog) + gtk_window_set_title (GTK_WINDOW (color_button->priv->cc_dialog), +#else if (color_button->priv->cs_dialog) gtk_window_set_title (GTK_WINDOW (color_button->priv->cs_dialog), +#endif color_button->priv->title); g_object_notify (G_OBJECT (color_button), "title"); @@ -952,7 +1088,11 @@ gsm_color_button_get_property (GObject * object, GValue * value, GParamSpec * pspec) { GSMColorButton *color_button = GSM_COLOR_BUTTON (object); +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA color; +#else GdkColor color; +#endif switch (param_id) { diff --git a/src/gsm_color_button.h b/src/gsm_color_button.h index bb885bc..bb54f72 100644 --- a/src/gsm_color_button.h +++ b/src/gsm_color_button.h @@ -25,10 +25,9 @@ #include <glib.h> #include <gdk/gdk.h> #include <gtk/gtk.h> +#if !GTK_CHECK_VERSION(3,0,0) #include <cairo.h> #include <librsvg/rsvg.h> -#ifndef RSVG_CAIRO_H -#include <librsvg/rsvg-cairo.h> #endif G_BEGIN_DECLS @@ -80,11 +79,20 @@ struct _GSMColorButtonClass }; GType gsm_color_button_get_type (void) G_GNUC_CONST; +#if GTK_CHECK_VERSION(3,0,0) +GtkWidget *gsm_color_button_new (const GdkRGBA * color, guint type); +void gsm_color_button_set_color (GSMColorButton * color_button, const GdkRGBA * color); +#else GtkWidget *gsm_color_button_new (const GdkColor * color, guint type); void gsm_color_button_set_color (GSMColorButton * color_button, const GdkColor * color); +#endif void gsm_color_button_set_fraction (GSMColorButton * color_button, const gdouble fraction); void gsm_color_button_set_cbtype (GSMColorButton * color_button, guint type); +#if GTK_CHECK_VERSION(3,0,0) +void gsm_color_button_get_color (GSMColorButton * color_button, GdkRGBA * color); +#else void gsm_color_button_get_color (GSMColorButton * color_button, GdkColor * color); +#endif gdouble gsm_color_button_get_fraction (GSMColorButton * color_button); guint gsm_color_button_get_cbtype (GSMColorButton * color_button); void gsm_color_button_set_title (GSMColorButton * color_button, const gchar * title); diff --git a/src/load-graph.cpp b/src/load-graph.cpp index a556292..c621f35 100644 --- a/src/load-graph.cpp +++ b/src/load-graph.cpp @@ -80,6 +80,9 @@ static void draw_background(LoadGraph *graph) { PangoLayout* layout; PangoFontDescription* font_desc; PangoRectangle extents; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA fg, bg; +#endif num_bars = graph->num_bars(); graph->graph_dely = (graph->draw_height - 15) / num_bars; /* round to int to avoid AA blur */ @@ -96,13 +99,26 @@ static void draw_background(LoadGraph *graph) { cr = gdk_cairo_create (graph->background); #endif +#if GTK_CHECK_VERSION(3,0,0) + GtkStyleContext *context = gtk_widget_get_style_context (ProcData::get_instance()->notebook); + gtk_style_context_get_background_color (context, GTK_STATE_FLAG_NORMAL, &bg); + gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &fg); + + // set the background colour + gdk_cairo_set_source_rgba (cr, &bg); +#else // set the background colour GtkStyle *style = gtk_widget_get_style (ProcData::get_instance()->notebook); gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); +#endif cairo_paint (cr); layout = pango_cairo_create_layout (cr); +#if GTK_CHECK_VERSION(3,0,0) + font_desc = pango_font_description_copy (gtk_style_context_get_font (context, GTK_STATE_FLAG_NORMAL)); +#else font_desc = pango_font_description_copy (style->font_desc); +#endif pango_font_description_set_size (font_desc, 0.8 * graph->fontsize * PANGO_SCALE); pango_layout_set_font_description (layout, font_desc); pango_font_description_free (font_desc); @@ -129,7 +145,11 @@ static void draw_background(LoadGraph *graph) { else y = i * graph->graph_dely + graph->fontsize / 2.0; +#if GTK_CHECK_VERSION(3,0,0) + gdk_cairo_set_source_rgba (cr, &fg); +#else gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]); +#endif if (graph->type == LOAD_GRAPH_NET) { // operation orders matters so it's 0 if i == num_bars guint64 rate = graph->net.max - (i * graph->net.max / num_bars); @@ -174,7 +194,11 @@ static void draw_background(LoadGraph *graph) { pango_layout_set_text (layout, caption, -1); pango_layout_get_extents (layout, NULL, &extents); cairo_move_to (cr, ((ceil(x) + 0.5) + graph->rmargin + graph->indent) - (1.0 * extents.width / PANGO_SCALE/2), graph->draw_height - 1.0 * extents.height / PANGO_SCALE); +#if GTK_CHECK_VERSION(3,0,0) + gdk_cairo_set_source_rgba (cr, &fg); +#else gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]); +#endif pango_cairo_show_layout (cr, layout); g_free (caption); } @@ -259,7 +283,11 @@ static gboolean load_graph_expose (GtkWidget *widget, GdkEventExpose *event, gpo for (j = 0; j < graph->n; ++j) { cairo_move_to (cr, x_offset, (1.0f - graph->data[0][j]) * graph->real_draw_height); +#if GTK_CHECK_VERSION(3,0,0) + gdk_cairo_set_source_rgba (cr, &(graph->colors [j])); +#else gdk_cairo_set_source_color (cr, &(graph->colors [j])); +#endif for (i = 1; i < LoadGraph::NUM_POINTS; ++i) { if (graph->data[i][j] == -1.0f) diff --git a/src/load-graph.h b/src/load-graph.h index 2a212fb..b4b3cdd 100644 --- a/src/load-graph.h +++ b/src/load-graph.h @@ -58,7 +58,11 @@ struct LoadGraph { double graph_delx; guint graph_buffer_offset; +#if GTK_CHECK_VERSION(3,0,0) + std::vector<GdkRGBA> colors; +#else std::vector<GdkColor> colors; +#endif std::vector<float> data_block; gfloat* data[NUM_POINTS]; diff --git a/src/procman.cpp b/src/procman.cpp index 0491df9..abfbf69 100644 --- a/src/procman.cpp +++ b/src/procman.cpp @@ -195,26 +195,46 @@ color_changed_cb (GSettings *settings, const gchar *key, gpointer data) for (int i = 0; i < procdata->config.num_cpus; i++) { string cpu_key = make_string(g_strdup_printf("cpu-color%d", i)); if (cpu_key == key) { +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&procdata->config.cpu_color[i], color); +#else gdk_color_parse (color, &procdata->config.cpu_color[i]); +#endif procdata->cpu_graph->colors.at(i) = procdata->config.cpu_color[i]; break; } } } else if (g_str_equal (key, "mem-color")) { +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&procdata->config.mem_color, color); +#else gdk_color_parse (color, &procdata->config.mem_color); +#endif procdata->mem_graph->colors.at(0) = procdata->config.mem_color; } else if (g_str_equal (key, "swap-color")) { +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&procdata->config.swap_color, color); +#else gdk_color_parse (color, &procdata->config.swap_color); +#endif procdata->mem_graph->colors.at(1) = procdata->config.swap_color; } else if (g_str_equal (key, "net-in-color")) { +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&procdata->config.net_in_color, color); +#else gdk_color_parse (color, &procdata->config.net_in_color); +#endif procdata->net_graph->colors.at(0) = procdata->config.net_in_color; } else if (g_str_equal (key, "net-out-color")) { +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&procdata->config.net_out_color, color); +#else gdk_color_parse (color, &procdata->config.net_out_color); +#endif procdata->net_graph->colors.at(1) = procdata->config.net_out_color; } else { @@ -309,7 +329,11 @@ procman_data_new (GSettings *settings) detail_string = std::string("changed::") + std::string(key); g_signal_connect (G_OBJECT(settings), detail_string.c_str(), G_CALLBACK(color_changed_cb), pd); +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&pd->config.cpu_color[i], color); +#else gdk_color_parse(color, &pd->config.cpu_color[i]); +#endif g_free (color); g_free (key); } @@ -319,7 +343,11 @@ procman_data_new (GSettings *settings) color = g_strdup ("#000000ff0082"); g_signal_connect (G_OBJECT(settings), "changed::mem-color", G_CALLBACK(color_changed_cb), pd); +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&pd->config.mem_color, color); +#else gdk_color_parse(color, &pd->config.mem_color); +#endif g_free (color); @@ -328,7 +356,11 @@ procman_data_new (GSettings *settings) color = g_strdup ("#00b6000000ff"); g_signal_connect (G_OBJECT(settings), "changed::swap-color", G_CALLBACK(color_changed_cb), pd); +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&pd->config.swap_color, color); +#else gdk_color_parse(color, &pd->config.swap_color); +#endif g_free (color); color = g_settings_get_string (settings, "net-in-color"); @@ -336,7 +368,11 @@ procman_data_new (GSettings *settings) color = g_strdup ("#000000f200f2"); g_signal_connect (G_OBJECT(settings), "changed::net-in-color", G_CALLBACK(color_changed_cb), pd); +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&pd->config.net_in_color, color); +#else gdk_color_parse(color, &pd->config.net_in_color); +#endif g_free (color); color = g_settings_get_string (settings, "net-out-color"); @@ -344,7 +380,11 @@ procman_data_new (GSettings *settings) color = g_strdup ("#00f2000000c1"); g_signal_connect (G_OBJECT(settings), "changed::net-out-color", G_CALLBACK(color_changed_cb), pd); +#if GTK_CHECK_VERSION(3,0,0) + gdk_rgba_parse (&pd->config.net_out_color, color); +#else gdk_color_parse(color, &pd->config.net_out_color); +#endif g_free (color); /* Sanity checks */ diff --git a/src/procman.h b/src/procman.h index 55fea88..46c93a9 100644 --- a/src/procman.h +++ b/src/procman.h @@ -96,6 +96,15 @@ struct ProcConfig int disks_update_interval; gint whose_process; gint current_tab; +#if GTK_CHECK_VERSION(3,0,0) + GdkRGBA cpu_color[GLIBTOP_NCPU]; + GdkRGBA mem_color; + GdkRGBA swap_color; + GdkRGBA net_in_color; + GdkRGBA net_out_color; + GdkRGBA bg_color; + GdkRGBA frame_color; +#else GdkColor cpu_color[GLIBTOP_NCPU]; GdkColor mem_color; GdkColor swap_color; @@ -103,6 +112,7 @@ struct ProcConfig GdkColor net_out_color; GdkColor bg_color; GdkColor frame_color; +#endif gint num_cpus; bool solaris_mode; bool network_in_bits; |