[gtk+] plug/socket: Warn if used outside X11



commit aa3bf0ac143c8c53ac31a414fc7461330c3f1199
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 28 12:48:02 2015 -0400

    plug/socket: Warn if used outside X11
    
    Give a clear warning when either of these are realized on a non-X11
    screen.

 gtk/gtkplug.c   |   15 +++++++++------
 gtk/gtksocket.c |   13 ++++++++-----
 2 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkplug.c b/gtk/gtkplug.c
index 56c37f2..b65dacb 100644
--- a/gtk/gtkplug.c
+++ b/gtk/gtkplug.c
@@ -58,16 +58,14 @@
  *
  * The communication between a #GtkSocket and a #GtkPlug follows the
  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
- * This protocol has also been implemented in other toolkits,
- * e.g. Qt, allowing the same level of
- * integration when embedding a Qt widget
+ * This protocol has also been implemented in other toolkits, e.g. Qt,
+ * allowing the same level of integration when embedding a Qt widget
  * in GTK+ or vice versa.
  *
  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
  * They can only be used on a #GdkX11Display. To use #GtkPlug and
- * #GtkSocket, you need to include the `gtk/gtkx.h`
- * header.
+ * #GtkSocket, you need to include the `gtk/gtkx.h` header.
  */
 
 struct _GtkPlugPrivate
@@ -1029,9 +1027,14 @@ gtk_plug_realize (GtkWidget *widget)
   const gchar *title;
   gchar *wmclass_name, *wmclass_class;
   gint attributes_mask;
+  GdkScreen *screen;
 
   gtk_widget_set_realized (widget, TRUE);
 
+  screen = gtk_widget_get_screen (widget);
+  if (!GDK_IS_X11_SCREEN (screen))
+    g_warning ("GtkPlug only works under X11");
+
   title = gtk_window_get_title (window);
   _gtk_window_get_wmclass (window, &wmclass_name, &wmclass_class);
   gtk_widget_get_allocation (widget, &allocation);
@@ -1064,7 +1067,7 @@ gtk_plug_realize (GtkWidget *widget)
       GdkWindow *root_window;
       attributes.window_type = GDK_WINDOW_TOPLEVEL;
 
-      root_window = gdk_screen_get_root_window (gtk_widget_get_screen (widget));
+      root_window = gdk_screen_get_root_window (screen);
 
       gdk_error_trap_push ();
       if (priv->socket_window)
diff --git a/gtk/gtksocket.c b/gtk/gtksocket.c
index 579a1f6..6213ceb 100644
--- a/gtk/gtksocket.c
+++ b/gtk/gtksocket.c
@@ -101,16 +101,14 @@
  *
  * The communication between a #GtkSocket and a #GtkPlug follows the
  * [XEmbed Protocol](http://www.freedesktop.org/Standards/xembed-spec).
- * This protocol has also been implemented in other toolkits,
- * e.g. Qt, allowing the same level of
- * integration when embedding a Qt widget
+ * This protocol has also been implemented in other toolkits, e.g. Qt,
+ * allowing the same level of integration when embedding a Qt widget
  * in GTK or vice versa.
  *
  * The #GtkPlug and #GtkSocket widgets are only available when GTK+
  * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
  * They can only be used on a #GdkX11Display. To use #GtkPlug and
- * #GtkSocket, you need to include the `gtk/gtkx.h`
- * header.
+ * #GtkSocket, you need to include the `gtk/gtkx.h` header.
  */
 
 /* Forward declararations */
@@ -391,9 +389,14 @@ gtk_socket_realize (GtkWidget *widget)
   GdkWindowAttr attributes;
   XWindowAttributes xattrs;
   gint attributes_mask;
+  GdkScreen *screen;
 
   gtk_widget_set_realized (widget, TRUE);
 
+  screen = gtk_widget_get_screen (widget);
+  if (!GDK_IS_X11_SCREEN (screen))
+    g_warning ("GtkSocket: only works under X11");
+
   gtk_widget_get_allocation (widget, &allocation);
 
   attributes.window_type = GDK_WINDOW_CHILD;


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