summaryrefslogtreecommitdiff
path: root/sensors-applet
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-05-02 19:36:57 +0200
committerStefano Karapetsas <[email protected]>2014-05-02 19:36:57 +0200
commit71dfbd694341aa2d9758297fc1fd8ccde910a662 (patch)
tree3f8083cea02ba73e8fbb088c4cf9515435699d5a /sensors-applet
parent310181bbdddc2e8bdb43d54a6321a1f36649423f (diff)
downloadmate-sensors-applet-71dfbd694341aa2d9758297fc1fd8ccde910a662.tar.bz2
mate-sensors-applet-71dfbd694341aa2d9758297fc1fd8ccde910a662.tar.xz
Add GTK3 support
Diffstat (limited to 'sensors-applet')
-rw-r--r--sensors-applet/active-sensor.c187
-rw-r--r--sensors-applet/prefs-dialog.c44
-rw-r--r--sensors-applet/sensor-config-dialog.c4
-rw-r--r--sensors-applet/sensors-applet.c4
4 files changed, 121 insertions, 118 deletions
diff --git a/sensors-applet/active-sensor.c b/sensors-applet/active-sensor.c
index 94cc707..5a5782c 100644
--- a/sensors-applet/active-sensor.c
+++ b/sensors-applet/active-sensor.c
@@ -253,115 +253,92 @@ static void active_sensor_update_icon(ActiveSensor *active_sensor,
}
-static void active_sensor_update_graph(ActiveSensor *as) {
+static void active_sensor_update_graph(ActiveSensor *as, cairo_t *cr) {
+ GtkAllocation allocation;
gdouble line_height;
gdouble width, height;
gdouble x, y;
- cairo_t *cr;
cairo_pattern_t *pattern;
gint i;
- GdkPixmap *pixmap;
-
- width = as->graph->allocation.width;
- height = as->graph->allocation.height;
-
- /* only do if drawable - will not be drawable if not currently
- * displayed on screen */
- if (GDK_IS_DRAWABLE(as->graph->window)) {
- /* use pixmap, draw to it, then use gdk to draw the
- * pixmap onto the drawable surface of the graph to
- * stop flickering */
- pixmap = gdk_pixmap_new(as->graph->window,
- width, height, -1);
-
- cr = gdk_cairo_create(pixmap);
-
- /* so we can set a clipping area, as well as fill the
- * back of the graph black */
- cairo_rectangle(cr,
- 0, 0,
- width,
- height);
- /* clip to rectangle and keep it as a path so can be
- * filled below */
- cairo_clip_preserve(cr);
-
- /* use black for bg color of graphs */
- cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
- cairo_fill(cr);
-
- /* determine height to scale line at for each value -
- * only do as many as will fit or the number of
- * samples that we have */
- for (i = 0; i < MIN(as->num_samples, width); i++) {
- /* need to remove one more to make it line up
- * properly when drawing */
- x = width - i - 1;
- y = height;
-
- line_height = sensor_value_range_normalised(as->sensor_values[i],
- as->sensor_low_value,
- as->sensor_high_value) * height;
-
-
-
- if (line_height > 0) {
- cairo_move_to(cr,
- x,
- y);
- cairo_line_to(cr, x,
- y - line_height);
- }
+ gtk_widget_get_allocation (as->graph, &allocation);
+ width = allocation.width;
+ height = allocation.height;
+
+ /* so we can set a clipping area, as well as fill the
+ * back of the graph black */
+ cairo_rectangle(cr,
+ 0, 0,
+ width,
+ height);
+ /* clip to rectangle and keep it as a path so can be
+ * filled below */
+ cairo_clip_preserve(cr);
+
+ /* use black for bg color of graphs */
+ cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+ cairo_fill(cr);
+
+ /* determine height to scale line at for each value -
+ * only do as many as will fit or the number of
+ * samples that we have */
+ for (i = 0; i < MIN(as->num_samples, width); i++) {
+ /* need to remove one more to make it line up
+ * properly when drawing */
+ x = width - i - 1;
+ y = height;
+
+ line_height = sensor_value_range_normalised(as->sensor_values[i],
+ as->sensor_low_value,
+ as->sensor_high_value) * height;
+
+
+
+ if (line_height > 0) {
+ cairo_move_to(cr,
+ x,
+ y);
+ cairo_line_to(cr, x,
+ y - line_height);
}
- /* make lines a gradient from slightly darker than
- * chosen color at bottom of graph, to slightly
- * lighter than chosen color at top of graph */
- pattern = cairo_pattern_create_linear(x, y,
- x, 0);
- cairo_pattern_add_color_stop_rgb(pattern,
- 0,
- as->graph_color.red / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT,
- as->graph_color.green / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT,
- as->graph_color.blue / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT);
-
- cairo_pattern_add_color_stop_rgb(pattern,
- height,
- as->graph_color.red / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT,
- as->graph_color.green / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT,
- as->graph_color.blue / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT);
-
- cairo_set_source(cr, pattern);
- cairo_stroke(cr);
- cairo_pattern_destroy(pattern);
- cairo_destroy(cr);
-
- /* now draw pixmap onto drawable surface */
- gdk_draw_drawable(as->graph->window,
- as->graph->style->fg_gc[GTK_WIDGET_STATE(as->graph)],
- pixmap,
- 0, 0,
- 0, 0,
- -1, -1);
- /* don't need pixmap anymore */
- g_object_unref(pixmap);
+
}
+ /* make lines a gradient from slightly darker than
+ * chosen color at bottom of graph, to slightly
+ * lighter than chosen color at top of graph */
+ pattern = cairo_pattern_create_linear(x, y,
+ x, 0);
+ cairo_pattern_add_color_stop_rgb(pattern,
+ 0,
+ as->graph_color.red / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT,
+ as->graph_color.green / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT,
+ as->graph_color.blue / 65535.0 - CAIRO_GRAPH_COLOR_GRADIENT);
+
+ cairo_pattern_add_color_stop_rgb(pattern,
+ height,
+ as->graph_color.red / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT,
+ as->graph_color.green / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT,
+ as->graph_color.blue / 65535.0 + CAIRO_GRAPH_COLOR_GRADIENT);
+
+ cairo_set_source(cr, pattern);
+ cairo_stroke(cr);
+ cairo_pattern_destroy(pattern);
}
void active_sensor_destroy(ActiveSensor *active_sensor) {
g_debug("-- destroying active sensor label...");
- gtk_object_destroy(GTK_OBJECT(active_sensor->label));
+ gtk_widget_destroy(active_sensor->label);
g_debug("-- destroying active sensor icon..");
- gtk_object_destroy(GTK_OBJECT(active_sensor->icon));
+ gtk_widget_destroy(active_sensor->icon);
g_debug("-- destroying active sensor value...");
- gtk_object_destroy(GTK_OBJECT(active_sensor->value));
+ gtk_widget_destroy(active_sensor->value);
g_debug("-- destroying active sensor graph and frame...");
- gtk_object_destroy(GTK_OBJECT(active_sensor->graph));
- gtk_object_destroy(GTK_OBJECT(active_sensor->graph_frame));
+ gtk_widget_destroy(active_sensor->graph);
+ gtk_widget_destroy(active_sensor->graph_frame);
g_debug("-- destroying active sensor values...");
g_free(active_sensor->sensor_values);
@@ -371,16 +348,33 @@ void active_sensor_destroy(ActiveSensor *active_sensor) {
g_free(active_sensor);
}
-
+#if GTK_CHECK_VERSION (3, 0, 0)
+gboolean graph_draw_cb(GtkWidget *graph,
+ cairo_t *cr,
+ gpointer data) {
+#else
gboolean graph_expose_event_cb(GtkWidget *graph,
GdkEventExpose *event,
gpointer data) {
+#endif
ActiveSensor *as;
as = (ActiveSensor *)data;
- active_sensor_update_graph(as);
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr;
+ cr = gdk_cairo_create (event->window);
+ gdk_cairo_region (cr, event->region);
+ cairo_clip (cr);
+#endif
+
+ active_sensor_update_graph(as, cr);
/* propagate event onwards */
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ cairo_destroy (cr);
+#endif
+
return FALSE;
}
@@ -425,7 +419,7 @@ static void active_sensor_set_graph_dimensions(ActiveSensor *as,
void active_sensor_update_graph_dimensions(ActiveSensor *as,
gint sizes[2]) {
active_sensor_set_graph_dimensions(as, sizes[0], sizes[1]);
- active_sensor_update_graph(as);
+ gtk_widget_queue_draw (as->graph);
}
ActiveSensor *active_sensor_new(SensorsApplet *sensors_applet,
@@ -475,8 +469,13 @@ ActiveSensor *active_sensor_new(SensorsApplet *sensors_applet,
(horizontal ? sensors_applet->size : graph_size));
g_signal_connect(G_OBJECT(active_sensor->graph),
+#if GTK_CHECK_VERSION (3, 0, 0)
+ "draw",
+ G_CALLBACK(graph_draw_cb),
+#else
"expose_event",
G_CALLBACK(graph_expose_event_cb),
+#endif
active_sensor);
active_sensor->updated = FALSE;
@@ -684,7 +683,7 @@ void active_sensor_update(ActiveSensor *active_sensor,
gdk_color_parse(graph_color,
&(active_sensor->graph_color));
- active_sensor_update_graph(active_sensor);
+ gtk_widget_queue_draw (active_sensor->graph);
gtk_widget_set_tooltip_text(active_sensor->graph,
tooltip);
diff --git a/sensors-applet/prefs-dialog.c b/sensors-applet/prefs-dialog.c
index 89e4b49..769ec99 100644
--- a/sensors-applet/prefs-dialog.c
+++ b/sensors-applet/prefs-dialog.c
@@ -408,7 +408,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
prefs_dialog->dialog = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Sensors Applet Preferences"),
NULL,
- GTK_DIALOG_NO_SEPARATOR,
+ GTK_DIALOG_MODAL,
GTK_STOCK_HELP,
GTK_RESPONSE_HELP,
GTK_STOCK_CLOSE,
@@ -420,9 +420,9 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
"default-height", 350,
NULL);
- gtk_box_set_homogeneous(GTK_BOX(prefs_dialog->dialog->vbox), FALSE);
+ gtk_box_set_homogeneous(GTK_BOX(gtk_dialog_get_content_area (prefs_dialog->dialog)), FALSE);
- gtk_box_set_spacing(GTK_BOX(prefs_dialog->dialog->vbox), 5);
+ gtk_box_set_spacing(GTK_BOX(gtk_dialog_get_content_area (prefs_dialog->dialog)), 5);
g_signal_connect(prefs_dialog->dialog,
@@ -442,7 +442,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
if (sensors_applet->sensors == NULL) {
GtkWidget *label;
label = gtk_label_new(_("No sensors found!"));
- gtk_box_pack_start_defaults(GTK_BOX(prefs_dialog->dialog->vbox), label);
+ gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area (prefs_dialog->dialog)), label, TRUE, TRUE, 0);
return;
}
@@ -456,14 +456,14 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
NULL);
g_free(header_text);
- prefs_dialog->display_mode_combo_box = GTK_COMBO_BOX(gtk_combo_box_new_text());
+ prefs_dialog->display_mode_combo_box = GTK_COMBO_BOX(gtk_combo_box_text_new());
- gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("label with value"));
- gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("icon with value"));
- gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("value only"));
- gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("icon only"));
- gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("graph only"));
+ gtk_combo_box_text_append_text(prefs_dialog->display_mode_combo_box, _("label with value"));
+ gtk_combo_box_text_append_text(prefs_dialog->display_mode_combo_box, _("icon with value"));
+ gtk_combo_box_text_append_text(prefs_dialog->display_mode_combo_box, _("value only"));
+ gtk_combo_box_text_append_text(prefs_dialog->display_mode_combo_box, _("icon only"));
+ gtk_combo_box_text_append_text(prefs_dialog->display_mode_combo_box, _("graph only"));
display_mode = g_settings_get_int(sensors_applet->settings, DISPLAY_MODE);
@@ -487,15 +487,15 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
- prefs_dialog->layout_mode_combo_box = GTK_COMBO_BOX(gtk_combo_box_new_text());
+ prefs_dialog->layout_mode_combo_box = GTK_COMBO_BOX(gtk_combo_box_text_new());
gtk_widget_set_sensitive(GTK_WIDGET(prefs_dialog->layout_mode_combo_box),
(display_mode != DISPLAY_ICON) &&
(display_mode != DISPLAY_VALUE) &&
(display_mode != DISPLAY_GRAPH));
- gtk_combo_box_append_text(prefs_dialog->layout_mode_combo_box, _("beside labels / icons"));
- gtk_combo_box_append_text(prefs_dialog->layout_mode_combo_box, _("below labels / icons"));
+ gtk_combo_box_text_append_text(prefs_dialog->layout_mode_combo_box, _("beside labels / icons"));
+ gtk_combo_box_text_append_text(prefs_dialog->layout_mode_combo_box, _("below labels / icons"));
gtk_combo_box_set_active(prefs_dialog->layout_mode_combo_box, g_settings_get_int(sensors_applet->settings, LAYOUT_MODE));
@@ -516,11 +516,11 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
(display_mode != DISPLAY_VALUE) &&
(display_mode != DISPLAY_GRAPH));
- prefs_dialog->temperature_scale_combo_box = GTK_COMBO_BOX(gtk_combo_box_new_text());
+ prefs_dialog->temperature_scale_combo_box = GTK_COMBO_BOX(gtk_combo_box_text_new());
- gtk_combo_box_append_text(prefs_dialog->temperature_scale_combo_box, _("Kelvin"));
- gtk_combo_box_append_text(prefs_dialog->temperature_scale_combo_box, _("Celsius"));
- gtk_combo_box_append_text(prefs_dialog->temperature_scale_combo_box, _("Fahrenheit"));
+ gtk_combo_box_text_append_text(prefs_dialog->temperature_scale_combo_box, _("Kelvin"));
+ gtk_combo_box_text_append_text(prefs_dialog->temperature_scale_combo_box, _("Celsius"));
+ gtk_combo_box_text_append_text(prefs_dialog->temperature_scale_combo_box, _("Fahrenheit"));
gtk_combo_box_set_active(prefs_dialog->temperature_scale_combo_box, g_settings_get_int(sensors_applet->settings, TEMPERATURE_SCALE));
@@ -624,9 +624,9 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
"use-underline", TRUE,
"label", _("Display _notifications"),
NULL);
- gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(prefs_dialog->display_notifications),
- g_settings_get_boolean(sensors_applet->settings,
- DISPLAY_NOTIFICATIONS));
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(prefs_dialog->display_notifications),
+ g_settings_get_boolean(sensors_applet->settings,
+ DISPLAY_NOTIFICATIONS));
g_signal_connect(prefs_dialog->display_notifications,
"toggled",
G_CALLBACK(prefs_dialog_display_notifications_toggled),
@@ -990,8 +990,8 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) {
gtk_label_new(_("Sensors")));
/* pack notebook into prefs_dialog */
- gtk_box_pack_start_defaults(GTK_BOX(prefs_dialog->dialog->vbox),
- GTK_WIDGET(prefs_dialog->notebook));
+ gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area (prefs_dialog->dialog)),
+ GTK_WIDGET(prefs_dialog->notebook), TRUE, TRUE, 0);
gtk_widget_show_all(GTK_WIDGET(prefs_dialog->dialog));
diff --git a/sensors-applet/sensor-config-dialog.c b/sensors-applet/sensor-config-dialog.c
index dd9f3c7..fa05c9f 100644
--- a/sensors-applet/sensor-config-dialog.c
+++ b/sensors-applet/sensor-config-dialog.c
@@ -395,7 +395,7 @@ void sensor_config_dialog_create(SensorsApplet *sensors_applet) {
config_dialog->dialog = gtk_dialog_new_with_buttons(header_text,
GTK_WINDOW(sensors_applet->prefs_dialog->dialog),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_HELP,
GTK_RESPONSE_HELP,
GTK_STOCK_CLOSE,
@@ -912,7 +912,7 @@ void sensor_config_dialog_create(SensorsApplet *sensors_applet) {
2, 3,
14, 15);
- gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(config_dialog->dialog)->vbox), GTK_WIDGET(config_dialog->table));
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(config_dialog->dialog))), GTK_WIDGET(config_dialog->table), TRUE, TRUE, 0);
gtk_widget_show_all(config_dialog->dialog);
}
diff --git a/sensors-applet/sensors-applet.c b/sensors-applet/sensors-applet.c
index ae5616d..7236591 100644
--- a/sensors-applet/sensors-applet.c
+++ b/sensors-applet/sensors-applet.c
@@ -123,6 +123,7 @@ static void destroy_cb(GtkWidget *widget, gpointer data) {
return;
}
+#if !GTK_CHECK_VERSION (3, 0, 0)
static void change_background_cb(MatePanelApplet *applet,
MatePanelAppletBackgroundType type,
GdkColor *color,
@@ -161,6 +162,7 @@ static void change_background_cb(MatePanelApplet *applet,
break;
}
}
+#endif
static void change_orient_cb (MatePanelApplet *applet,
MatePanelAppletOrient orient,
@@ -1397,9 +1399,11 @@ void sensors_applet_init(SensorsApplet *sensors_applet) {
G_CALLBACK(style_set_cb),
sensors_applet);
+#if !GTK_CHECK_VERSION (3, 0, 0)
g_signal_connect(sensors_applet->applet, "change_background",
G_CALLBACK(change_background_cb),
sensors_applet);
+#endif
g_signal_connect(G_OBJECT(sensors_applet->applet), "change_orient",
G_CALLBACK(change_orient_cb),