]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkdisplay-x11.c
[introspection] add transfer none annotation to gdk_keyval_name return
[~andy/gtk] / gdk / x11 / gdkdisplay-x11.c
index ea4e9914dc5e97693de15d78414e90e70c53b196..2bdfd454020194dc5c4f402a9fe3312eedd4d737 100644 (file)
 
 #include "config.h"
 
-#include <glib/gprintf.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
+#include "gdkdisplay-x11.h"
 
-#include <glib.h>
 #include "gdkx.h"
 #include "gdkasync.h"
 #include "gdkdisplay.h"
-#include "gdkdisplay-x11.h"
 #include "gdkeventsource.h"
 #include "gdkeventtranslator.h"
 #include "gdkscreen.h"
 #include "gdkdevicemanager.h"
 #include "xsettings-client.h"
 
+#include <glib.h>
+#include <glib/gprintf.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
 #include <X11/Xatom.h>
 
 #ifdef HAVE_XKB
@@ -265,7 +266,7 @@ gdk_check_wm_desktop_changed (GdkWindow *window)
                       0, G_MAXLONG, False, XA_CARDINAL, &type,
                       &format, &nitems,
                       &bytes_after, &data);
-  gdk_error_trap_pop ();
+  gdk_error_trap_pop_ignored ();
 
   if (type != None)
     {
@@ -306,7 +307,7 @@ gdk_check_wm_state_changed (GdkWindow *window)
                      gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
                      0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
                      &bytes_after, &data);
-  gdk_error_trap_pop ();
+  gdk_error_trap_pop_ignored ();
 
   if (type != None)
     {
@@ -735,7 +736,7 @@ gdk_display_x11_translate_event (GdkEventTranslator *translator,
                  event->configure.x = tx;
                  event->configure.y = ty;
                }
-             gdk_error_trap_pop ();
+             gdk_error_trap_pop_ignored ();
            }
          else
            {
@@ -1347,7 +1348,6 @@ gdk_display_open (const gchar *display_name)
     XQueryPointer (display_x11->xdisplay, 
                   GDK_SCREEN_X11 (display_x11->default_screen)->xroot_window,
                   &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
-    gdk_flush ();
     if (G_UNLIKELY (gdk_error_trap_pop () == BadWindow)) 
       {
        g_warning ("Connection to display %s appears to be untrusted. Pointer and keyboard grabs and inter-client communication may not work as expected.", gdk_display_get_name (display));
@@ -1911,6 +1911,21 @@ gdk_display_x11_finalize (GObject *object)
 
   XCloseDisplay (display_x11->xdisplay);
 
+  /* error traps */
+  while (display_x11->error_traps != NULL)
+    {
+      GdkErrorTrap *trap = display_x11->error_traps->data;
+
+      display_x11->error_traps =
+        g_slist_delete_link (display_x11->error_traps,
+                             display_x11->error_traps);
+
+      if (trap->end_sequence == 0)
+        g_warning ("Display finalized with an unpopped error trap");
+
+      g_slice_free (GdkErrorTrap, trap);
+    }
+
   G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
 }
 
@@ -1995,45 +2010,15 @@ _gdk_windowing_set_default_display (GdkDisplay *display)
   startup_id = g_getenv ("DESKTOP_STARTUP_ID");
   if (startup_id && *startup_id != '\0')
     {
-      gchar *time_str;
-
       if (!g_utf8_validate (startup_id, -1, NULL))
-       g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
+        g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
       else
-       display_x11->startup_notification_id = g_strdup (startup_id);
-
-      /* Find the launch time from the startup_id, if it's there.  Newer spec
-       * states that the startup_id is of the form <unique>_TIME<timestamp>
-       */
-      time_str = g_strrstr (startup_id, "_TIME");
-      if (time_str != NULL)
-        {
-         gulong retval;
-          gchar *end;
-          errno = 0;
-
-          /* Skip past the "_TIME" part */
-          time_str += 5;
-
-          retval = strtoul (time_str, &end, 0);
-          if (end != time_str && errno == 0)
-            display_x11->user_time = retval;
-        }
+        gdk_x11_display_set_startup_notification_id (display, startup_id);
       
       /* Clear the environment variable so it won't be inherited by
        * child processes and confuse things.  
        */
       g_unsetenv ("DESKTOP_STARTUP_ID");
-
-      /* Set the startup id on the leader window so it
-       * applies to all windows we create on this display
-       */
-      XChangeProperty (display_x11->xdisplay,
-                      display_x11->leader_window,
-                      gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
-                      gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
-                      PropModeReplace,
-                      (guchar *)startup_id, strlen (startup_id));
     }
 }
 
@@ -2398,7 +2383,7 @@ gdk_display_store_clipboard (GdkDisplay    *display,
                         GDK_WINDOW_XID (clipboard_window), time_);
       
     }
-  gdk_error_trap_pop ();
+  gdk_error_trap_pop_ignored ();
 
 }
 
@@ -2472,6 +2457,69 @@ gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
   return GDK_DISPLAY_X11 (display)->startup_notification_id;
 }
 
+/**
+ * gdk_x11_display_set_startup_notification_id:
+ * @display: a #GdkDisplay
+ * @startup_id: the startup notification ID (must be valid utf8)
+ *
+ * Sets the startup notification ID for a display.
+ *
+ * This is usually taken from the value of the DESKTOP_STARTUP_ID
+ * environment variable, but in some cases (such as the application not
+ * being launched using exec()) it can come from other sources.
+ *
+ * If the ID contains the string "_TIME" then the portion following that
+ * string is taken to be the X11 timestamp of the event that triggered
+ * the application to be launched and the GDK current event time is set
+ * accordingly.
+ *
+ * The startup ID is also what is used to signal that the startup is
+ * complete (for example, when opening a window or when calling
+ * gdk_notify_startup_complete()).
+ *
+ * Since: 3.0
+ **/
+void
+gdk_x11_display_set_startup_notification_id (GdkDisplay  *display,
+                                             const gchar *startup_id)
+{
+  GdkDisplayX11 *display_x11;
+  gchar *time_str;
+
+  display_x11 = GDK_DISPLAY_X11 (display);
+
+  g_free (display_x11->startup_notification_id);
+  display_x11->startup_notification_id = g_strdup (startup_id);
+
+  /* Find the launch time from the startup_id, if it's there.  Newer spec
+   * states that the startup_id is of the form <unique>_TIME<timestamp>
+   */
+  time_str = g_strrstr (startup_id, "_TIME");
+  if (time_str != NULL)
+    {
+      gulong retval;
+      gchar *end;
+      errno = 0;
+
+      /* Skip past the "_TIME" part */
+      time_str += 5;
+
+      retval = strtoul (time_str, &end, 0);
+      if (end != time_str && errno == 0)
+        display_x11->user_time = retval;
+    }
+
+  /* Set the startup id on the leader window so it
+   * applies to all windows we create on this display
+   */
+  XChangeProperty (display_x11->xdisplay,
+                   display_x11->leader_window,
+                   gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
+                   gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
+                   PropModeReplace,
+                   (guchar *)startup_id, strlen (startup_id));
+}
+
 /**
  * gdk_display_supports_composite:
  * @display: a #GdkDisplay
@@ -2706,6 +2754,7 @@ _gdk_x11_display_error_event (GdkDisplay  *display,
         {
           ignore = TRUE;
           trap->error_code = error->error_code;
+          break; /* only innermost trap gets the error code */
         }
     }
 
@@ -2736,7 +2785,7 @@ _gdk_x11_display_error_event (GdkDisplay  *display,
 #ifdef G_ENABLE_DEBUG
       g_error ("%s", msg);
 #else /* !G_ENABLE_DEBUG */
-      g_fprintf (stderr, "%s\n", msg);
+      g_warning ("%s\n", msg);
 
       exit (1);
 #endif /* G_ENABLE_DEBUG */
@@ -2757,7 +2806,7 @@ delete_outdated_error_traps (GdkDisplayX11 *display_x11)
       GdkErrorTrap *trap = tmp_list->data;
 
       if (trap->end_sequence != 0 &&
-          SEQUENCE_COMPARE (trap->end_sequence, <, processed_sequence))
+          SEQUENCE_COMPARE (trap->end_sequence, <=, processed_sequence))
         {
           GSList *free_me = tmp_list;
 
@@ -2775,10 +2824,13 @@ delete_outdated_error_traps (GdkDisplayX11 *display_x11)
 
 /**
  * gdk_x11_display_error_trap_push:
+ * @display: a #GdkDisplay
  *
- * Begins a range of X requests for which X error events will be
- * ignored. Unignored errors (when no trap is pushed) will abort the
- * application.
+ * Begins a range of X requests on @display for which X error events
+ * will be ignored. Unignored errors (when no trap is pushed) will abort
+ * the application. Use gdk_x11_display_error_trap_pop() or
+ * gdk_x11_display_error_trap_pop_ignored()to lift a trap pushed
+ * with this function.
  *
  * See also gdk_error_trap_push() to push a trap on all displays.
  *