summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-01-20 09:58:30 +0100
committerStefano Karapetsas <[email protected]>2014-01-20 09:58:30 +0100
commit7ca1965de675c694a0a811c6d075b67a114edd3a (patch)
tree68c72937ff42d5bf24dd90465330cb861ba65e48
parent7779705809b61a180aeb2371afcf8d0cba9ba0e3 (diff)
downloadmate-applets-7ca1965de675c694a0a811c6d075b67a114edd3a.tar.bz2
mate-applets-7ca1965de675c694a0a811c6d075b67a114edd3a.tar.xz
multiload: Add GTK3 support
-rw-r--r--configure.ac2
-rw-r--r--multiload/global.h6
-rw-r--r--multiload/load-graph.c69
-rw-r--r--multiload/main.c11
-rw-r--r--multiload/properties.c4
5 files changed, 86 insertions, 6 deletions
diff --git a/configure.ac b/configure.ac
index 40aefdfe..dd3b7299 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ GIO_REQUIRED=2.15.3
LIBPANEL4_REQUIRED=1.7.0
LIBGTOP_REQUIRED=2.11.92
LIBXKLAVIER_REQUIRED=4.0
-LIBMATE_DESKTOP_REQUIRED=1.7.0
+LIBMATE_DESKTOP_REQUIRED=1.7.3
LIBNOTIFY_REQUIRED=0.7.0
HAL_REQUIRED=0.5.3
UPOWER_REQUIRED=0.9.4
diff --git a/multiload/global.h b/multiload/global.h
index 613adb5d..a480f11c 100644
--- a/multiload/global.h
+++ b/multiload/global.h
@@ -35,11 +35,17 @@ struct _LoadGraph {
guint data_size;
guint *pos;
+#if !GTK_CHECK_VERSION (3, 0, 0)
gint colors_allocated;
+#endif
GtkWidget *main_widget;
GtkWidget *frame, *box, *disp;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_surface_t *surface;
+#else
GdkPixmap *pixmap;
GdkGC *gc;
+#endif
int timer_index;
gint show_frame;
diff --git a/multiload/load-graph.c b/multiload/load-graph.c
index a17d604a..ec14156e 100644
--- a/multiload/load-graph.c
+++ b/multiload/load-graph.c
@@ -50,18 +50,33 @@ load_graph_draw (LoadGraph *g)
{
GtkStyle *style;
guint i, j;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr;
+#endif
/* we might get called before the configure event so that
* g->disp->allocation may not have the correct size
* (after the user resized the applet in the prop dialog). */
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (!g->surface)
+ g->surface = gdk_window_create_similar_surface (gtk_widget_get_window (g->disp),
+ CAIRO_CONTENT_COLOR,
+ g->draw_width, g->draw_height);
+#else
if (!g->pixmap)
g->pixmap = gdk_pixmap_new (gtk_widget_get_window (g->disp),
g->draw_width, g->draw_height,
gtk_widget_get_visual (g->disp)->depth);
-
+#endif
+
style = gtk_widget_get_style (g->disp);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cr = cairo_create (g->surface);
+ cairo_set_line_width (cr, 1.0);
+ cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+#else
/* Create GC if necessary. */
if (!g->gc)
{
@@ -89,27 +104,43 @@ load_graph_draw (LoadGraph *g)
TRUE, 0, 0,
g->draw_width,
g->draw_height);
+#endif
for (i = 0; i < g->draw_width; i++)
g->pos [i] = g->draw_height - 1;
for (j = 0; j < g->n; j++)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gdk_cairo_set_source_color (cr, &(g->colors [j]));
+#else
gdk_gc_set_foreground (g->gc, &(g->colors [j]));
+#endif
for (i = 0; i < g->draw_width; i++) {
if (g->data [i][j] != 0) {
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_move_to (cr, g->draw_width - i - 0.5, g->pos[i] + 0.5);
+ cairo_line_to (cr, g->draw_width - i - 0.5, g->pos[i] - (g->data [i][j] - 0.5));
+#else
gdk_draw_line (g->pixmap, g->gc,
g->draw_width - i - 1,
g->pos[i],
g->draw_width - i - 1,
g->pos[i] - (g->data [i][j] - 1));
+#endif
g->pos [i] -= g->data [i][j];
}
}
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_stroke (cr);
+#endif
}
-
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_queue_draw (g->disp);
+#else
gdk_draw_drawable (gtk_widget_get_window (g->disp),
style->fg_gc [gtk_widget_get_state (g->disp)],
g->pixmap,
@@ -117,6 +148,7 @@ load_graph_draw (LoadGraph *g)
0, 0,
g->draw_width,
g->draw_height);
+#endif
}
/* Updates the load graph when the timeout expires */
@@ -159,6 +191,12 @@ load_graph_unalloc (LoadGraph *g)
g->size = g_settings_get_int(g->multiload->settings, "size");
g->size = MAX (g->size, 10);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (g->surface) {
+ cairo_surface_destroy (g->surface);
+ g->surface = NULL;
+ }
+#else
if (g->pixmap) {
g_object_unref (g->pixmap);
g->pixmap = NULL;
@@ -168,6 +206,7 @@ load_graph_unalloc (LoadGraph *g)
g_object_unref (g->gc);
g->gc = NULL;
}
+#endif
g->allocated = FALSE;
}
@@ -209,7 +248,14 @@ load_graph_configure (GtkWidget *widget, GdkEventConfigure *event,
c->draw_height = MAX (c->draw_height, 1);
load_graph_alloc (c);
-
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+ if (!c->surface)
+ c->surface = gdk_window_create_similar_surface (gtk_widget_get_window (c->disp),
+ CAIRO_CONTENT_COLOR,
+ c->draw_width, c->draw_height);
+ gtk_widget_queue_draw (widget);
+#else
if (!c->pixmap)
c->pixmap = gdk_pixmap_new (gtk_widget_get_window (c->disp),
c->draw_width,
@@ -228,22 +274,33 @@ load_graph_configure (GtkWidget *widget, GdkEventConfigure *event,
0, 0,
c->draw_width,
c->draw_height);
+#endif
return TRUE;
}
static gint
-load_graph_expose (GtkWidget *widget, GdkEventExpose *event,
+load_graph_expose (GtkWidget *widget,
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_t *cr,
+#else
+ GdkEventExpose *event,
+#endif
gpointer data_ptr)
{
LoadGraph *g = (LoadGraph *) data_ptr;
+#if GTK_CHECK_VERSION (3, 0, 0)
+ cairo_set_source_surface (cr, g->surface, 0, 0);
+ cairo_paint (cr);
+#else
gdk_draw_drawable (gtk_widget_get_window (widget),
(gtk_widget_get_style (widget))->fg_gc [gtk_widget_get_state (widget)],
g->pixmap,
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
+#endif
return FALSE;
}
@@ -387,7 +444,11 @@ load_graph_new (MultiloadApplet *ma, guint n, const gchar *label,
GDK_LEAVE_NOTIFY_MASK |
GDK_BUTTON_PRESS_MASK);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ g_signal_connect (G_OBJECT (g->disp), "draw",
+#else
g_signal_connect (G_OBJECT (g->disp), "expose_event",
+#endif
G_CALLBACK (load_graph_expose), g);
g_signal_connect (G_OBJECT(g->disp), "configure_event",
G_CALLBACK (load_graph_configure), g);
diff --git a/multiload/main.c b/multiload/main.c
index 16075895..db94fdaf 100644
--- a/multiload/main.c
+++ b/multiload/main.c
@@ -19,14 +19,23 @@
#include <time.h>
#include <glibtop.h>
-#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
+#if GTK_CHECK_VERSION (3, 0, 0)
+#include <gdk/gdkkeysyms-compat.h>
+#endif
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <mate-panel-applet.h>
#include <mate-panel-applet-gsettings.h>
+#if GTK_CHECK_VERSION (3, 0, 0)
+#define MATE_DESKTOP_USE_UNSTABLE_API
+#include <libmate-desktop/mate-desktop-utils.h>
+#define gdk_spawn_command_line_on_screen mate_gdk_spawn_command_line_on_screen
+#endif
+
#include "global.h"
static void
diff --git a/multiload/properties.c b/multiload/properties.c
index 97d750c5..9dd3cf6a 100644
--- a/multiload/properties.c
+++ b/multiload/properties.c
@@ -244,7 +244,9 @@ color_picker_set_cb(GtkColorButton *color_picker, gchar *key)
gdk_color_parse(color_string,
&(ma->graphs[prop_type]->colors[g_ascii_digit_value(key[strlen(key) - 1]) ]) );
+#if !GTK_CHECK_VERSION (3, 0, 0)
ma->graphs[prop_type]->colors_allocated = FALSE;
+#endif
return;
}
@@ -635,7 +637,9 @@ multiload_properties_cb (GtkAction *action,
gtk_widget_get_screen (GTK_WIDGET (ma->applet)));
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
+#endif
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2);