]> Pileus Git - ~andy/gtk/blobdiff - gdk/x11/gdkevents-x11.c
Fix string offsets.
[~andy/gtk] / gdk / x11 / gdkevents-x11.c
index bc2a38de7bb2f83732751b7504a00b77401e183d..f3445c21c1d905072232a746187ba199d0aa255c 100644 (file)
@@ -24,6 +24,8 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
+
 #include "gdk.h"
 #include "gdkprivate-x11.h"
 #include "gdkinternals.h"
 
 #include "xsettings-client.h"
 
-#if HAVE_CONFIG_H
-#  include <config.h>
-#  if STDC_HEADERS
-#    include <string.h>
-#  endif
-#endif
+#include <string.h>
 
 #include "gdkinputprivate.h"
 
+#include "gdkalias.h"
+
 #ifdef HAVE_XKB
 #include <X11/XKBlib.h>
 #endif
 
+#ifdef HAVE_XSYNC
+#include <X11/extensions/sync.h>
+#endif
+
+#ifdef HAVE_XFIXES
+#include <X11/extensions/Xfixes.h>
+#endif
+
 #include <X11/Xatom.h>
 
 typedef struct _GdkIOClosure GdkIOClosure;
 typedef struct _GdkDisplaySource GdkDisplaySource;
 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
 
-#define DOUBLE_CLICK_TIME      250
-#define TRIPLE_CLICK_TIME      500
-#define DOUBLE_CLICK_DIST      5
-#define TRIPLE_CLICK_DIST      5
-
 struct _GdkIOClosure
 {
   GdkInputFunction function;
@@ -150,6 +152,22 @@ gdk_check_xpending (GdkDisplay *display)
  * Functions for maintaining the event queue *
  *********************************************/
 
+static void
+refcounted_grab_server (Display *xdisplay)
+{
+  GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
+
+  gdk_x11_display_grab (display);
+}
+
+static void
+refcounted_ungrab_server (Display *xdisplay)
+{
+  GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
+  
+  gdk_x11_display_ungrab (display);
+}
+
 void
 _gdk_x11_events_init_screen (GdkScreen *screen)
 {
@@ -163,6 +181,10 @@ _gdk_x11_events_init_screen (GdkScreen *screen)
                                                       gdk_xsettings_notify_cb,
                                                       gdk_xsettings_watch_cb,
                                                       screen);
+  xsettings_client_set_grab_func (screen_x11->xsettings_client,
+                                 refcounted_grab_server);
+  xsettings_client_set_ungrab_func (screen_x11->xsettings_client,
+                                   refcounted_ungrab_server);
   screen_x11->xsettings_in_init = FALSE;
 }
 
@@ -171,8 +193,11 @@ _gdk_x11_events_uninit_screen (GdkScreen *screen)
 {
   GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
 
-  xsettings_client_destroy (screen_x11->xsettings_client);
-  screen_x11->xsettings_client = NULL;
+  if (screen_x11->xsettings_client)
+    {
+      xsettings_client_destroy (screen_x11->xsettings_client);
+      screen_x11->xsettings_client = NULL;
+    }
 }
 
 void 
@@ -199,13 +224,26 @@ _gdk_events_init (GdkDisplay *display)
 
   display_sources = g_list_prepend (display_sources,display_source);
 
-  gdk_display_add_client_message_filter (
-       display,
-       gdk_atom_intern ("WM_PROTOCOLS", FALSE), 
-       gdk_wm_protocols_filter,   
-       NULL);
+  gdk_display_add_client_message_filter (display,
+                                        gdk_atom_intern_static_string ("WM_PROTOCOLS"), 
+                                        gdk_wm_protocols_filter,   
+                                        NULL);
 }
 
+void
+_gdk_events_uninit (GdkDisplay *display)
+{
+  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
+
+  if (display_x11->event_source)
+    {
+      display_sources = g_list_remove (display_sources,
+                                       display_x11->event_source);
+      g_source_destroy (display_x11->event_source);
+      g_source_unref (display_x11->event_source);
+      display_x11->event_source = NULL;
+    }
+}
 
 /**
  * gdk_events_pending:
@@ -340,8 +378,8 @@ gdk_display_add_client_message_filter (GdkDisplay   *display,
   filter->data = data;
   
   GDK_DISPLAY_X11(display)->client_filters = 
-    g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
-                   filter);
+    g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
+                  filter);
 }
 
 /**
@@ -388,7 +426,7 @@ do_net_wm_state_changes (GdkWindow *window)
     }
   else
     {
-      if (toplevel->have_sticky && toplevel->on_all_desktops)
+      if (toplevel->have_sticky || toplevel->on_all_desktops)
         gdk_synthesize_window_state (window,
                                      0,
                                      GDK_WINDOW_STATE_STICKY);
@@ -438,28 +476,29 @@ gdk_check_wm_desktop_changed (GdkWindow *window)
   gint format;
   gulong nitems;
   gulong bytes_after;
+  guchar *data;
+  gulong *desktop;
 
-  if (toplevel->have_sticky)
-    {
-      gulong *desktop;
-      
-      XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), 
-                         GDK_WINDOW_XID (window),
-                          gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
-                         0, G_MAXLONG, False, XA_CARDINAL, &type, 
-                         &format, &nitems,
-                          &bytes_after, (guchar **)&desktop);
+  type = None;
+  gdk_error_trap_push ();
+  XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), 
+                      GDK_WINDOW_XID (window),
+                      gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
+                      0, G_MAXLONG, False, XA_CARDINAL, &type, 
+                      &format, &nitems,
+                      &bytes_after, &data);
+  gdk_error_trap_pop ();
 
-      if (type != None)
-        {
-          toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
-          XFree (desktop);
-        }
-      else
-       toplevel->on_all_desktops = FALSE;
-      
-      do_net_wm_state_changes (window);
+  if (type != None)
+    {
+      desktop = (gulong *)data;
+      toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
+      XFree (desktop);
     }
+  else
+    toplevel->on_all_desktops = FALSE;
+      
+  do_net_wm_state_changes (window);
 }
 
 static void
@@ -472,6 +511,7 @@ gdk_check_wm_state_changed (GdkWindow *window)
   gint format;
   gulong nitems;
   gulong bytes_after;
+  guchar *data;
   Atom *atoms = NULL;
   gulong i;
 
@@ -482,10 +522,13 @@ gdk_check_wm_state_changed (GdkWindow *window)
   toplevel->have_maxhorz = FALSE;
   toplevel->have_fullscreen = FALSE;
 
+  type = None;
+  gdk_error_trap_push ();
   XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
                      gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
                      0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
-                     &bytes_after, (guchar **)&atoms);
+                     &bytes_after, &data);
+  gdk_error_trap_pop ();
 
   if (type != None)
     {
@@ -494,6 +537,8 @@ gdk_check_wm_state_changed (GdkWindow *window)
       Atom maxhorz_atom        = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
       Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
 
+      atoms = (Atom *)data;
+
       i = 0;
       while (i < nitems)
         {
@@ -538,7 +583,7 @@ generate_focus_event (GdkWindow *window,
   gdk_event_put (&event);
 }
 
-static void
+static gboolean
 set_screen_from_root (GdkDisplay *display,
                      GdkEvent   *event,
                      Window      xrootwin)
@@ -546,9 +591,15 @@ set_screen_from_root (GdkDisplay *display,
   GdkScreen *screen;
 
   screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
-  g_assert (screen);
 
-  gdk_event_set_screen (event, screen);
+  if (screen)
+    {
+      gdk_event_set_screen (event, screen);
+
+      return TRUE;
+    }
+  
+  return FALSE;
 }
 
 static void
@@ -558,7 +609,7 @@ translate_key_event (GdkDisplay *display,
 {
   GdkKeymap *keymap = gdk_keymap_get_for_display (display);
   gunichar c = 0;
-  guchar buf[7];
+  gchar buf[7];
 
   event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
   event->key.time = xevent->xkey.time;
@@ -576,6 +627,9 @@ translate_key_event (GdkDisplay *display,
                                       &event->key.keyval,
                                       NULL, NULL, NULL);
 
+  _gdk_keymap_add_virtual_modifiers (keymap, &event->key.state);
+  event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
+
   /* Fill in event->string crudely, since various programs
    * depend on it.
    */
@@ -651,10 +705,31 @@ translate_key_event (GdkDisplay *display,
   return;
 }
 
+/**
+ * gdk_x11_register_standard_event_type:
+ * @display: a #GdkDisplay
+ * @event_base: first event type code to register
+ * @n_events: number of event type codes to register
+ * 
+ * Registers interest in receiving extension events with type codes
+ * between @event_base and <literal>event_base + n_events - 1</literal>.
+ * The registered events must have the window field in the same place
+ * as core X events (this is not the case for e.g. XKB extension events).
+ *
+ * If an event type is registered, events of this type will go through
+ * global and window-specific filters (see gdk_window_add_filter()). 
+ * Unregistered events will only go through global filters.
+ * GDK may register the events of some X extensions on its own.
+ * 
+ * This function should only be needed in unusual circumstances, e.g.
+ * when filtering XInput extension events on the root window.
+ *
+ * Since: 2.4
+ **/
 void
-_gdk_x11_register_event_type (GdkDisplay          *display,
-                             gint                 event_base,
-                             gint                 n_events)
+gdk_x11_register_standard_event_type (GdkDisplay          *display,
+                                     gint                 event_base,
+                                     gint                 n_events)
 {
   GdkEventTypeX11 *event_type;
   GdkDisplayX11 *display_x11;
@@ -750,14 +825,14 @@ get_real_window (GdkDisplay *display,
 }
 
 #ifdef G_ENABLE_DEBUG
-static const char notify_modes[][18] = {
+static const char notify_modes[][19] = {
   "NotifyNormal",
   "NotifyGrab",
   "NotifyUngrab",
   "NotifyWhileGrabbed"
 };
 
-static const char notify_details[][22] = {
+static const char notify_details[][23] = {
   "NotifyAncestor",
   "NotifyVirtual",
   "NotifyInferior",
@@ -769,6 +844,23 @@ static const char notify_details[][22] = {
 };
 #endif
 
+static void
+set_user_time (GdkWindow *window,
+              GdkEvent  *event)
+{
+  g_return_if_fail (event != NULL);
+
+  window = gdk_window_get_toplevel (event->client.window);
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  /* If an event doesn't have a valid timestamp, we shouldn't use it
+   * to update the latest user interaction time.
+   */
+  if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
+    gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
+                                  gdk_event_get_time (event));
+}
+
 static gboolean
 gdk_event_translate (GdkDisplay *display,
                     GdkEvent   *event,
@@ -962,6 +1054,7 @@ gdk_event_translate (GdkDisplay *display,
           break;
         }
       translate_key_event (display, event, xevent);
+      set_user_time (window, event);
       break;
 
     case KeyRelease:
@@ -1036,8 +1129,12 @@ gdk_event_translate (GdkDisplay *display,
          event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
          event->scroll.state = (GdkModifierType) xevent->xbutton.state;
          event->scroll.device = display->core_pointer;
-
-         set_screen_from_root (display, event, xevent->xbutton.root);
+         
+         if (!set_screen_from_root (display, event, xevent->xbutton.root))
+           {
+             return_val = FALSE;
+             break;
+           }
          
           break;
           
@@ -1054,12 +1151,19 @@ gdk_event_translate (GdkDisplay *display,
          event->button.button = xevent->xbutton.button;
          event->button.device = display->core_pointer;
          
-         set_screen_from_root (display, event, xevent->xbutton.root);
+         if (!set_screen_from_root (display, event, xevent->xbutton.root))
+           {
+             return_val = FALSE;
+             break;
+           }
 
          _gdk_event_button_generate (display, event);
           break;
        }
 
+      set_user_time (window, event);
+
+      _gdk_xgrab_check_button_event (window, xevent);
       break;
       
     case ButtonRelease:
@@ -1097,8 +1201,13 @@ gdk_event_translate (GdkDisplay *display,
       event->button.button = xevent->xbutton.button;
       event->button.device = display->core_pointer;
 
-      set_screen_from_root (display, event, xevent->xbutton.root);
-      
+      if (!set_screen_from_root (display, event, xevent->xbutton.root))
+       {
+         return_val = FALSE;
+         break;
+       }
+
+      _gdk_xgrab_check_button_event (window, xevent);
       break;
       
     case MotionNotify:
@@ -1115,7 +1224,7 @@ gdk_event_translate (GdkDisplay *display,
          return_val = FALSE;
          break;
        }
-      
+
       event->motion.type = GDK_MOTION_NOTIFY;
       event->motion.window = window;
       event->motion.time = xevent->xmotion.time;
@@ -1128,8 +1237,12 @@ gdk_event_translate (GdkDisplay *display,
       event->motion.is_hint = xevent->xmotion.is_hint;
       event->motion.device = display->core_pointer;
       
-      set_screen_from_root (display, event, xevent->xmotion.root);
-      
+      if (!set_screen_from_root (display, event, xevent->xbutton.root))
+       {
+         return_val = FALSE;
+         break;
+       }
+            
       break;
       
     case EnterNotify:
@@ -1145,17 +1258,26 @@ gdk_event_translate (GdkDisplay *display,
           break;
         }
       
+      if (!set_screen_from_root (display, event, xevent->xbutton.root))
+       {
+         return_val = FALSE;
+         break;
+       }
+      
       /* Handle focusing (in the case where no window manager is running */
-      if (toplevel &&
-         xevent->xcrossing.detail != NotifyInferior &&
-         xevent->xcrossing.focus && !toplevel->has_focus_window)
+      if (toplevel && xevent->xcrossing.detail != NotifyInferior)
        {
-         gboolean had_focus = HAS_FOCUS (toplevel);
-
-         toplevel->has_pointer_focus = TRUE;
+         toplevel->has_pointer = TRUE;
 
-         if (HAS_FOCUS (toplevel) != had_focus)
-           generate_focus_event (window, TRUE);
+         if (xevent->xcrossing.focus && !toplevel->has_focus_window)
+           {
+             gboolean had_focus = HAS_FOCUS (toplevel);
+             
+             toplevel->has_pointer_focus = TRUE;
+             
+             if (HAS_FOCUS (toplevel) != had_focus)
+               generate_focus_event (window, TRUE);
+           }
        }
 
       /* Tell XInput stuff about it if appropriate */
@@ -1181,8 +1303,6 @@ gdk_event_translate (GdkDisplay *display,
       event->crossing.x_root = xevent->xcrossing.x_root;
       event->crossing.y_root = xevent->xcrossing.y_root;
       
-      set_screen_from_root (display, event, xevent->xcrossing.root);
-      
       /* Translate the crossing mode into Gdk terms.
        */
       switch (xevent->xcrossing.mode)
@@ -1238,18 +1358,27 @@ gdk_event_translate (GdkDisplay *display,
           return_val = FALSE;
           break;
         }
-      
+
+      if (!set_screen_from_root (display, event, xevent->xbutton.root))
+       {
+         return_val = FALSE;
+         break;
+       }
+                  
       /* Handle focusing (in the case where no window manager is running */
-      if (toplevel &&
-         xevent->xcrossing.detail != NotifyInferior &&
-         xevent->xcrossing.focus && !toplevel->has_focus_window)
+      if (toplevel && xevent->xcrossing.detail != NotifyInferior)
        {
-         gboolean had_focus = HAS_FOCUS (toplevel);
-         
-         toplevel->has_pointer_focus = FALSE;
-         
-         if (HAS_FOCUS (toplevel) != had_focus)
-           generate_focus_event (window, FALSE);
+         toplevel->has_pointer = FALSE;
+
+         if (xevent->xcrossing.focus && !toplevel->has_focus_window)
+           {
+             gboolean had_focus = HAS_FOCUS (toplevel);
+             
+             toplevel->has_pointer_focus = FALSE;
+             
+             if (HAS_FOCUS (toplevel) != had_focus)
+               generate_focus_event (window, FALSE);
+           }
        }
 
       event->crossing.type = GDK_LEAVE_NOTIFY;
@@ -1269,8 +1398,6 @@ gdk_event_translate (GdkDisplay *display,
       event->crossing.x_root = xevent->xcrossing.x_root;
       event->crossing.y_root = xevent->xcrossing.y_root;
       
-      set_screen_from_root (display, event, xevent->xcrossing.root);
-      
       /* Translate the crossing mode into Gdk terms.
        */
       switch (xevent->xcrossing.mode)
@@ -1332,10 +1459,25 @@ gdk_event_translate (GdkDisplay *display,
          switch (xevent->xfocus.detail)
            {
            case NotifyAncestor:
-           case NotifyNonlinear:
            case NotifyVirtual:
+             /* When the focus moves from an ancestor of the window to
+              * the window or a descendent of the window, *and* the
+              * pointer is inside the window, then we were previously
+              * receiving keystroke events in the has_pointer_focus
+              * case and are now receiving them in the
+              * has_focus_window case.
+              */
+             if (toplevel->has_pointer &&
+                 xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
+               toplevel->has_pointer_focus = FALSE;
+             
+             /* fall through */
+           case NotifyNonlinear:
            case NotifyNonlinearVirtual:
-             toplevel->has_focus_window = TRUE;
+             if (xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
+               toplevel->has_focus_window = TRUE;
              /* We pretend that the focus moves to the grab
               * window, so we pay attention to NotifyGrab
               * NotifyUngrab, and ignore NotifyWhileGrabbed
@@ -1348,7 +1490,8 @@ gdk_event_translate (GdkDisplay *display,
               * but the pointer focus is ignored while a
               * grab is in effect
               */
-             if (xevent->xfocus.mode != NotifyGrab)
+             if (xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
                toplevel->has_pointer_focus = TRUE;
              break;
            case NotifyInferior:
@@ -1375,15 +1518,31 @@ gdk_event_translate (GdkDisplay *display,
          switch (xevent->xfocus.detail)
            {
            case NotifyAncestor:
-           case NotifyNonlinear:
            case NotifyVirtual:
+             /* When the focus moves from the window or a descendent
+              * of the window to an ancestor of the window, *and* the
+              * pointer is inside the window, then we were previously
+              * receiving keystroke events in the has_focus_window
+              * case and are now receiving them in the
+              * has_pointer_focus case.
+              */
+             if (toplevel->has_pointer &&
+                 xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
+               toplevel->has_pointer_focus = TRUE;
+
+             /* fall through */
+           case NotifyNonlinear:
            case NotifyNonlinearVirtual:
-             toplevel->has_focus_window = FALSE;
+             if (xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
+               toplevel->has_focus_window = FALSE;
              if (xevent->xfocus.mode != NotifyWhileGrabbed)
                toplevel->has_focus = FALSE;
              break;
            case NotifyPointer:
-             if (xevent->xfocus.mode != NotifyUngrab)
+             if (xevent->xfocus.mode != NotifyGrab &&
+                 xevent->xfocus.mode != NotifyUngrab)
                toplevel->has_pointer_focus = FALSE;
            break;
            case NotifyInferior:
@@ -1667,8 +1826,16 @@ gdk_event_translate (GdkDisplay *display,
          !GDK_WINDOW_DESTROYED (window) &&
          (window_private->extension_events != 0))
        _gdk_input_configure_event (&xevent->xconfigure, window);
+      
+#ifdef HAVE_XSYNC
+      if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
+       {
+         toplevel->current_counter_value = toplevel->pending_counter_value;
+         XSyncIntToValue (&toplevel->pending_counter_value, 0);
+       }
+#endif
 
-      if (!window ||
+    if (!window ||
          xevent->xconfigure.event != xevent->xconfigure.window ||
           GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
           GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
@@ -1710,6 +1877,9 @@ gdk_event_translate (GdkDisplay *display,
          window_private->y = event->configure.y;
          window_impl->width = xevent->xconfigure.width;
          window_impl->height = xevent->xconfigure.height;
+         
+         _gdk_x11_drawable_update_size (window_private->impl);
+         
          if (window_private->resize_count >= 1)
            {
              window_private->resize_count -= 1;
@@ -1831,13 +2001,14 @@ gdk_event_translate (GdkDisplay *display,
        while (tmp_list)
          {
            GdkClientFilter *filter = tmp_list->data;
+           tmp_list = tmp_list->next;
+           
            if (filter->type == message_type)
              {
                result = (*filter->function) (xevent, event, filter->data);
-               break;
+               if (result != GDK_FILTER_CONTINUE)
+                 break;
              }
-           
-           tmp_list = tmp_list->next;
          }
 
        switch (result)
@@ -1896,11 +2067,29 @@ gdk_event_translate (GdkDisplay *display,
              break;
              
            case XkbStateNotify:
-             _gdk_keymap_state_changed (display);
+             _gdk_keymap_state_changed (display, xevent);
              break;
            }
        }
       else
+#endif
+#ifdef HAVE_XFIXES
+      if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
+       {
+         XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
+         event->owner_change.type = GDK_OWNER_CHANGE;
+         event->owner_change.window = window;
+         event->owner_change.owner = selection_notify->owner;
+         event->owner_change.reason = selection_notify->subtype;
+         event->owner_change.selection = 
+           gdk_x11_xatom_to_atom_for_display (display, 
+                                              selection_notify->selection);
+         event->owner_change.time = selection_notify->timestamp;
+         event->owner_change.selection_time = selection_notify->selection_timestamp;
+
+         return_val = TRUE;
+       }
+      else
 #endif
        {
          /* something else - (e.g., a Xinput event) */
@@ -1946,9 +2135,16 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
 {
   XEvent *xevent = (XEvent *)xev;
   GdkWindow *win = event->any.window;
-  GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
+  GdkDisplay *display;
+  Atom atom;
+
+  if (!win)
+      return GDK_FILTER_REMOVE;    
+
+  display = GDK_WINDOW_DISPLAY (win);
+  atom = (Atom)xevent->xclient.data.l[0];
 
-  if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
+  if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
     {
   /* The delete window request specifies a window
    *  to delete. We don't actually destroy the
@@ -1964,9 +2160,11 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
       
       event->any.type = GDK_DELETE;
 
+      gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
+
       return GDK_FILTER_TRANSLATE;
     }
-  else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
+  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
     {
       GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
       GdkWindowObject *private = (GdkWindowObject *)win;
@@ -1978,8 +2176,10 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
        _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
                                       RevertToParent,
                                       xevent->xclient.data.l[1]);
+
+      return GDK_FILTER_REMOVE;
     }
-  else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
+  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
           !_gdk_x11_display_is_root_window (display,
                                             xevent->xclient.window))
     {
@@ -1990,9 +2190,25 @@ gdk_wm_protocols_filter (GdkXEvent *xev,
                  xev.xclient.window,
                  False, 
                  SubstructureRedirectMask | SubstructureNotifyMask, &xev);
-    }
 
-  return GDK_FILTER_REMOVE;
+      return GDK_FILTER_REMOVE;
+    }
+  else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
+          GDK_DISPLAY_X11 (display)->use_sync)
+    {
+      GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
+      if (toplevel)
+       {
+#ifdef HAVE_XSYNC
+         XSyncIntsToValue (&toplevel->pending_counter_value, 
+                           xevent->xclient.data.l[2], 
+                           xevent->xclient.data.l[3]);
+#endif
+       }
+      return GDK_FILTER_REMOVE;
+    }
+  
+  return GDK_FILTER_CONTINUE;
 }
 
 void
@@ -2143,7 +2359,7 @@ gdk_event_send_client_message_for_display (GdkDisplay     *display,
 
 
 /* Sends a ClientMessage to all toplevel client windows */
-gboolean
+static gboolean
 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
                                              XEvent     *xev, 
                                              guint32     xid,
@@ -2342,6 +2558,7 @@ fetch_net_wm_check_window (GdkScreen *screen)
   gint format;
   gulong n_items;
   gulong bytes_after;
+  guchar *data;
   Window *xwindow;
   
   /* This function is very slow on every call if you are not running a
@@ -2358,27 +2575,38 @@ fetch_net_wm_check_window (GdkScreen *screen)
   if (screen_x11->wmspec_check_window != None)
     return; /* already have it */
   
+  data = NULL;
   XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
                      gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
                      0, G_MAXLONG, False, XA_WINDOW, &type, &format, 
-                     &n_items, &bytes_after, (guchar **) & xwindow);
+                     &n_items, &bytes_after, &data);
   
   if (type != XA_WINDOW)
-    return;
+    {
+      if (data)
+        XFree (data);
+      return;
+    }
+
+  xwindow = (Window *)data;
 
   gdk_error_trap_push ();
   
   /* Find out if this WM goes away, so we can reset everything. */
   XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
+  gdk_display_sync (display);
 
-  screen_x11->wmspec_check_window = *xwindow;
-  XFree (xwindow);
+  if (gdk_error_trap_pop () == Success)
+    {
+      screen_x11->wmspec_check_window = *xwindow;
+      screen_x11->need_refetch_net_supported = TRUE;
+      screen_x11->need_refetch_wm_name = TRUE;
+      
+      /* Careful, reentrancy */
+      _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
+    }
 
-  screen_x11->need_refetch_net_supported = TRUE;
-  screen_x11->need_refetch_wm_name = TRUE;
-  
-  /* Careful, reentrancy */
-  _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
+  XFree (xwindow);    
 }
 
 /**
@@ -2416,9 +2644,11 @@ gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
           gint format;
           gulong n_items;
           gulong bytes_after;
-          guchar *name;
+          gchar *name;
           
           name = NULL;
+
+         gdk_error_trap_push ();
           
           XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
                               screen_x11->wmspec_check_window,
@@ -2564,26 +2794,83 @@ gdk_net_wm_supports (GdkAtom property)
   return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
 }
 
-static struct
+static const char settings_names[] = 
+  "Net/DoubleClickTime\0"     "gtk-double-click-time\0"
+  "Net/DoubleClickDistance\0" "gtk-double-click-distance\0"
+  "Net/DndDragThreshold\0"    "gtk-dnd-drag-threshold\0"
+  "Net/CursorBlink\0"         "gtk-cursor-blink\0"
+  "Net/CursorBlinkTime\0"     "gtk-cursor-blink-time\0"
+  "Net/ThemeName\0"           "gtk-theme-name\0" 
+  "Net/IconThemeName\0"       "gtk-icon-theme-name\0"
+  "Gtk/CanChangeAccels\0"     "gtk-can-change-accels\0"
+  "Gtk/ColorPalette\0"        "gtk-color-palette\0"
+  "Gtk/FontName\0"            "gtk-font-name\0"
+  "Gtk/IconSizes\0"           "gtk-icon-sizes\0"
+  "Gtk/KeyThemeName\0"        "gtk-key-theme-name\0"
+  "Gtk/ToolbarStyle\0"        "gtk-toolbar-style\0"
+  "Gtk/ToolbarIconSize\0"     "gtk-toolbar-icon-size\0"
+  "Gtk/IMPreeditStyle\0"      "gtk-im-preedit-style\0"
+  "Gtk/IMStatusStyle\0"       "gtk-im-status-style\0"
+  "Gtk/Modules\0"             "gtk-modules\0"
+  "Gtk/FileChooserBackend\0"  "gtk-file-chooser-backend\0"
+  "Gtk/ButtonImages\0"        "gtk-button-images\0"
+  "Gtk/MenuImages\0"          "gtk-menu-images\0"
+  "Gtk/MenuBarAccel\0"        "gtk-menu-bar-accel\0"
+  "Gtk/CursorThemeName\0"     "gtk-cursor-theme-name\0"
+  "Gtk/CursorThemeSize\0"     "gtk-cursor-theme-size\0"
+  "Gtk/ShowInputMethodMenu\0" "gtk-show-input-method-menu\0"
+  "Gtk/ShowUnicodeMenu\0"     "gtk-show-unicode-menu\0"
+  "Gtk/TimeoutInitial\0"      "gtk-timeout-initial\0"
+  "Gtk/TimeoutRepeat\0"       "gtk-timeout-repeat\0"
+  "Gtk/ColorScheme\0"         "gtk-color-scheme\0"
+  "Gtk/EnableAnimations\0"    "gtk-enable-animations\0"
+  "Xft/Antialias\0"           "gtk-xft-antialias\0"
+  "Xft/Hinting\0"             "gtk-xft-hinting\0"
+  "Xft/HintStyle\0"           "gtk-xft-hintstyle\0"
+  "Xft/RGBA\0"                "gtk-xft-rgba\0"
+  "Xft/DPI\0"                 "gtk-xft-dpi\0"
+  "Net/FallbackIconTheme\0"   "gtk-fallback-icon-theme\0";
+
+static const struct
 {
-  const char *xsettings_name;
-  const char *gdk_name;
+  gint xsettings_offset;
+  gint gdk_offset;
 } settings_map[] = {
-  { "Net/DoubleClickTime", "gtk-double-click-time" },
-  { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
-  { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
-  { "Gtk/ColorPalette", "gtk-color-palette" },
-  { "Gtk/FontName", "gtk-font-name" },
-  { "Gtk/IconSizes", "gtk-icon-sizes" },
-  { "Gtk/KeyThemeName", "gtk-key-theme-name" },
-  { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
-  { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
-  { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
-  { "Gtk/IMStatusStyle", "gtk-im-status-style" },
-  { "Net/CursorBlink", "gtk-cursor-blink" },
-  { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
-  { "Net/ThemeName", "gtk-theme-name" },
-  { "Net/IconThemeName", "gtk-icon-theme-name" },
+  {    0,   20 },
+  {   42,   66 },
+  {   92,  113 },
+  {  136,  152 },
+  {  169,  189 },
+  {  211,  225 },
+  {  240,  258 },
+  {  278,  298 },
+  {  320,  337 },
+  {  355,  368 },
+  {  382,  396 },
+  {  411,  428 },
+  {  447,  464 },
+  {  482,  502 },
+  {  524,  543 },
+  {  564,  582 },
+  {  602,  614 },
+  {  626,  649 },
+  {  674,  691 },
+  {  709,  724 },
+  {  740,  757 },
+  {  776,  796 },
+  {  818,  838 },
+  {  860,  884 },
+  {  911,  931 },
+  {  953,  972 },
+  {  992, 1010 },
+  { 1029, 1045 },
+  { 1062, 1083 },
+  { 1105, 1119 },
+  { 1137, 1149 },
+  { 1165, 1179 },
+  { 1197, 1206 },
+  { 1219, 1227 },
+  { 1239, 1261 }
 };
 
 static void
@@ -2606,12 +2893,11 @@ gdk_xsettings_notify_cb (const char       *name,
   new_event.setting.name = NULL;
 
   for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
-    if (strcmp (settings_map[i].xsettings_name, name) == 0)
+    if (strcmp (settings_names + settings_map[i].xsettings_offset, name) == 0)
       {
-       new_event.setting.name = (char *)settings_map[i].gdk_name;
+       new_event.setting.name = (char *)settings_names + settings_map[i].gdk_offset;
        break;
       }
-
   
   if (!new_event.setting.name)
     return;
@@ -2639,7 +2925,7 @@ check_transform (const gchar *xsettings_name,
 {
   if (!g_value_type_transformable (src_type, dest_type))
     {
-      g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
+      g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
                 xsettings_name,
                 g_type_name (src_type),
                 g_type_name (dest_type));
@@ -2674,7 +2960,7 @@ gdk_screen_get_setting (GdkScreen   *screen,
 
   const char *xsettings_name = NULL;
   XSettingsResult result;
-  XSettingsSetting *setting;
+  XSettingsSetting *setting = NULL;
   GdkScreenX11 *screen_x11;
   gboolean success = FALSE;
   gint i;
@@ -2685,19 +2971,19 @@ gdk_screen_get_setting (GdkScreen   *screen,
   screen_x11 = GDK_SCREEN_X11 (screen);
 
   for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
-    if (strcmp (settings_map[i].gdk_name, name) == 0)
+    if (strcmp (settings_names + settings_map[i].gdk_offset, name) == 0)
       {
-       xsettings_name = settings_map[i].xsettings_name;
+       xsettings_name = settings_names + settings_map[i].xsettings_offset;
        break;
       }
 
   if (!xsettings_name)
-    return FALSE;
+    goto out;
 
   result = xsettings_client_get_setting (screen_x11->xsettings_client, 
                                         xsettings_name, &setting);
   if (result != XSETTINGS_SUCCESS)
-    return FALSE;
+    goto out;
 
   switch (setting->type)
     {
@@ -2744,9 +3030,14 @@ gdk_screen_get_setting (GdkScreen   *screen,
   
   g_value_unset (&tmp_val);
 
-  xsettings_setting_free (setting);
+ out:
+  if (setting)
+    xsettings_setting_free (setting);
 
-  return success;
+  if (success)
+    return TRUE;
+  else
+    return _gdk_x11_get_xft_setting (screen, name, value);
 }
 
 static GdkFilterReturn 
@@ -2789,3 +3080,6 @@ gdk_xsettings_watch_cb (Window   window,
       g_object_unref (gdkwin);
     }
 }
+
+#define __GDK_EVENTS_X11_C__
+#include "gdkaliasdef.c"