Blame SOURCES/0017-Fix-gtk2-build.patch

4ab194
From bc4be9139c60541659fae1fd961d9eb770820b08 Mon Sep 17 00:00:00 2001
4ab194
From: Jonathon Jongsma <jjongsma@redhat.com>
4ab194
Date: Mon, 31 Mar 2014 17:12:16 -0500
4ab194
Subject: [PATCH] Fix gtk2 build
4ab194
4ab194
Previous commit accidentally broke gtk2 build by using
4ab194
gtk_widget_get_preferred_size().  We can't simply use gtk_widget_size_request()
4ab194
for the gtk2 build since this will generally return 50x50 whenever we're not in
4ab194
the middle of a resize, so we need to add a compatibility function.
4ab194
---
4ab194
 src/virt-viewer-display-spice.c |  2 +-
4ab194
 src/virt-viewer-display.c       | 41 ++++++++++++++++++++++++++++-------------
4ab194
 src/virt-viewer-display.h       |  1 +
4ab194
 3 files changed, 30 insertions(+), 14 deletions(-)
4ab194
4ab194
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
4ab194
index c400f51..0450b5b 100644
4ab194
--- a/src/virt-viewer-display-spice.c
4ab194
+++ b/src/virt-viewer-display-spice.c
4ab194
@@ -204,7 +204,7 @@ virt_viewer_display_spice_size_allocate(VirtViewerDisplaySpice *self,
4ab194
          * resizes the window to the size it already wants to be (based on desktop
4ab194
          * size and zoom level), just return early
4ab194
          */
4ab194
-        gtk_widget_get_preferred_size(GTK_WIDGET(self), NULL, &preferred);
4ab194
+        virt_viewer_display_get_preferred_size(VIRT_VIEWER_DISPLAY(self), &preferred);
4ab194
         if (preferred.width == allocation->width
4ab194
             && preferred.height == allocation->height) {
4ab194
             return;
4ab194
diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
4ab194
index 6c078a5..f298bb0 100644
4ab194
--- a/src/virt-viewer-display.c
4ab194
+++ b/src/virt-viewer-display.c
4ab194
@@ -377,6 +377,31 @@ virt_viewer_display_grab_focus(GtkWidget *widget)
4ab194
     gtk_widget_grab_focus(gtk_bin_get_child(bin));
4ab194
 }
4ab194
 
4ab194
+/* Compatibility function to allow gtk2 to emulate gtk3 behavior. We can't use
4ab194
+ * the size request since it simply returns the minimum size whenever dirty is
4ab194
+ * false */
4ab194
+void virt_viewer_display_get_preferred_size(VirtViewerDisplay *self,
4ab194
+                                            GtkRequisition *requisition)
4ab194
+{
4ab194
+#if GTK_CHECK_VERSION(3, 0, 0)
4ab194
+    gtk_widget_get_preferred_size(GTK_WIDGET(self), NULL, requisition);
4ab194
+#else
4ab194
+    VirtViewerDisplayPrivate *priv = self->priv;
4ab194
+    int border_width = gtk_container_get_border_width(GTK_CONTAINER(self));
4ab194
+
4ab194
+    requisition->width = border_width * 2;
4ab194
+    requisition->height = border_width * 2;
4ab194
+
4ab194
+    if (priv->zoom) {
4ab194
+        requisition->width += round(priv->desktopWidth * priv->zoom_level / 100.0);
4ab194
+        requisition->height += round(priv->desktopHeight * priv->zoom_level / 100.0);
4ab194
+    } else {
4ab194
+        requisition->width += priv->desktopWidth;
4ab194
+        requisition->height += priv->desktopHeight;
4ab194
+    }
4ab194
+#endif
4ab194
+}
4ab194
+
4ab194
 
4ab194
 #if !GTK_CHECK_VERSION(3, 0, 0)
4ab194
 static gboolean
4ab194
@@ -396,22 +421,12 @@ virt_viewer_display_size_request(GtkWidget *widget,
4ab194
 {
4ab194
     VirtViewerDisplay *display = VIRT_VIEWER_DISPLAY(widget);
4ab194
     VirtViewerDisplayPrivate *priv = display->priv;
4ab194
-    int border_width = gtk_container_get_border_width(GTK_CONTAINER(widget));
4ab194
-
4ab194
-    requisition->width = border_width * 2;
4ab194
-    requisition->height = border_width * 2;
4ab194
 
4ab194
     if (priv->dirty) {
4ab194
-        if (priv->zoom) {
4ab194
-            requisition->width += round(priv->desktopWidth * priv->zoom_level / 100.0);
4ab194
-            requisition->height += round(priv->desktopHeight * priv->zoom_level / 100.0);
4ab194
-        } else {
4ab194
-            requisition->width += priv->desktopWidth;
4ab194
-            requisition->height += priv->desktopHeight;
4ab194
-        }
4ab194
+        virt_viewer_display_get_preferred_size(display, requisition);
4ab194
     } else {
4ab194
-        requisition->width += 50;
4ab194
-        requisition->height += 50;
4ab194
+        requisition->width = 50;
4ab194
+        requisition->height = 50;
4ab194
     }
4ab194
 
4ab194
     DEBUG_LOG("Display size request %dx%d (desktop %dx%d)",
4ab194
diff --git a/src/virt-viewer-display.h b/src/virt-viewer-display.h
4ab194
index fe88d98..70ce772 100644
4ab194
--- a/src/virt-viewer-display.h
4ab194
+++ b/src/virt-viewer-display.h
4ab194
@@ -126,6 +126,7 @@ gboolean virt_viewer_display_get_enabled(VirtViewerDisplay *display);
4ab194
 gboolean virt_viewer_display_get_selectable(VirtViewerDisplay *display);
4ab194
 void virt_viewer_display_queue_resize(VirtViewerDisplay *display);
4ab194
 void virt_viewer_display_get_preferred_monitor_geometry(VirtViewerDisplay *self, GdkRectangle* preferred);
4ab194
+void virt_viewer_display_get_preferred_size(VirtViewerDisplay *self, GtkRequisition* requisistion);
4ab194
 
4ab194
 G_END_DECLS
4ab194