[gtk-vnc] Refactor drawing code to allow compatibility with Gtk3



commit d0d619741512d95f1f8636d641efc7075459a3c2
Author: Daniel P. Berrange <berrange redhat com>
Date:   Wed Oct 27 21:53:58 2010 +0100

    Refactor drawing code to allow compatibility with Gtk3
    
    In Gtk3, the expose_event is replaced with a 'draw' callback.
    This is provided with a 'cairo_t' context that is already
    configured with the clip region.
    
    Split the current expose_event into two parts, the first
    which creates a cairo_t based on the GdkEventExpose data,
    and the second method which draws to that cairo_t. The
    expose_event is conditionally disabled for Gtk3 builds,
    just leaving the draw method which works on Gtk2 and Gtk3
    
    * src/vncdisplay.c: Pull drawing code out of expose_event
      method and disable expose_event on Gtk3

 src/vncdisplay.c |   65 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 48 insertions(+), 17 deletions(-)
---
diff --git a/src/vncdisplay.c b/src/vncdisplay.c
index d0a04dc..bdf26da 100644
--- a/src/vncdisplay.c
+++ b/src/vncdisplay.c
@@ -128,6 +128,26 @@ typedef enum
 	LAST_SIGNAL
 } vnc_display_signals;
 
+
+/* Some compatibility defines to let us build on both Gtk2 and Gtk3 */
+#if GTK_CHECK_VERSION (2, 91, 0)
+
+static inline void gdk_drawable_get_size(GdkWindow *w, gint *ww, gint *wh)
+{
+	*ww = gdk_window_get_width(w);
+	*wh = gdk_window_get_height(w);
+}
+
+#define gdk_drawable_get_display(w) gdk_window_get_display(w)
+#define gdk_drawable_get_screen(w) gdk_window_get_screen(w)
+#define gdk_drawable_get_visual(w) gdk_window_get_visual(w)
+
+#define GtkObject GtkWidget
+#define GtkObjectClass GtkWidgetClass
+#define GTK_OBJECT_CLASS(c) GTK_WIDGET_CLASS(c)
+
+#endif
+
 static guint signals[LAST_SIGNAL] = { 0, 0, 0, 0,
 				      0, 0, 0, 0,
 				      0, 0, 0, 0, 0,};
@@ -262,13 +282,12 @@ static GdkCursor *create_null_cursor(void)
 	return cursor;
 }
 
-static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
+static gboolean draw_event(GtkWidget *widget, cairo_t *cr)
 {
 	VncDisplay *obj = VNC_DISPLAY(widget);
 	VncDisplayPrivate *priv = obj->priv;
 	int ww, wh;
 	int mx = 0, my = 0;
-	cairo_t *cr;
 	int fbw = 0, fbh = 0;
 
 	if (priv->fb) {
@@ -276,12 +295,6 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
 		fbh = vnc_framebuffer_get_height(VNC_FRAMEBUFFER(priv->fb));
 	}
 
-	VNC_DEBUG("Expose area %dx%d at location %d,%d",
-		   expose->area.width,
-		   expose->area.height,
-		   expose->area.x,
-		   expose->area.y);
-
 	gdk_drawable_get_size(gtk_widget_get_window(widget), &ww, &wh);
 
 	if (ww > fbw)
@@ -289,14 +302,6 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
 	if (wh > fbh)
 		my = (wh - fbh) / 2;
 
-	cr = gdk_cairo_create(gtk_widget_get_window(GTK_WIDGET(obj)));
-	cairo_rectangle(cr,
-			expose->area.x-1,
-			expose->area.y-1,
-			expose->area.width + 2,
-			expose->area.height + 2);
-	cairo_clip(cr);
-
 	/* If we don't have a pixmap, or we're not scaling, then
 	   we need to fill with background color */
 	if (!priv->fb ||
@@ -334,10 +339,32 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
 		cairo_paint(cr);
 	}
 
+	return TRUE;
+}
+
+
+#if !GTK_CHECK_VERSION (2, 91, 0)
+static gboolean expose_event(GtkWidget *widget, GdkEventExpose *expose)
+{
+	VncDisplay *obj = VNC_DISPLAY(widget);
+	cairo_t *cr;
+	gboolean ret;
+
+	cr = gdk_cairo_create(gtk_widget_get_window(GTK_WIDGET(obj)));
+	cairo_rectangle(cr,
+			expose->area.x-1,
+			expose->area.y-1,
+			expose->area.width + 2,
+			expose->area.height + 2);
+	cairo_clip(cr);
+
+	ret = draw_event(widget, cr);
+
 	cairo_destroy(cr);
 
-	return TRUE;
+	return ret;
 }
+#endif
 
 static void do_keyboard_grab(VncDisplay *obj, gboolean quiet)
 {
@@ -1486,7 +1513,11 @@ static void vnc_display_class_init(VncDisplayClass *klass)
 	GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
 	GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
+#if GTK_CHECK_VERSION (2, 91, 0)
+	gtkwidget_class->draw = draw_event;
+#else
 	gtkwidget_class->expose_event = expose_event;
+#endif
 	gtkwidget_class->motion_notify_event = motion_event;
 	gtkwidget_class->button_press_event = button_event;
 	gtkwidget_class->button_release_event = button_event;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]