[gtk+/xi2: 1082/1239] GdkWindow: Add gdk_window_set_device_events().



commit 135f250e986ba777bd32428f7fd37c445d62b043
Author: Carlos Garnacho <carlos gnome org>
Date:   Sun Sep 6 21:52:36 2009 +0200

    GdkWindow: Add gdk_window_set_device_events().
    
    This function selects input events for a specific device on window.

 gdk/gdkinternals.h |    1 +
 gdk/gdkwindow.c    |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 82 insertions(+), 3 deletions(-)
---
diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h
index 2fb237d..dcb1a5a 100644
--- a/gdk/gdkinternals.h
+++ b/gdk/gdkinternals.h
@@ -283,6 +283,7 @@ struct _GdkWindowObject
   cairo_surface_t *cairo_surface;
 
   GList *devices_inside;
+  GHashTable *device_events;
 };
 
 
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 6ff17be..b99c114 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -34,6 +34,7 @@
 #include "gdkdrawable.h"
 #include "gdkintl.h"
 #include "gdkscreen.h"
+#include "gdkdeviceprivate.h"
 #include "gdkmarshalers.h"
 #include "gdkalias.h"
 
@@ -1100,12 +1101,20 @@ find_native_sibling_above (GdkWindowObject *parent,
 }
 
 static GdkEventMask
-get_native_event_mask (GdkWindowObject *private)
+get_native_device_event_mask (GdkWindowObject *private,
+                              GdkDevice       *device)
 {
+  GdkEventMask event_mask;
+
+  if (device)
+    event_mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
+  else
+    event_mask = private->event_mask;
+
   if (_gdk_native_windows ||
       private->window_type == GDK_WINDOW_ROOT ||
       private->window_type == GDK_WINDOW_FOREIGN)
-    return private->event_mask;
+    return event_mask;
   else
     {
       return
@@ -1121,7 +1130,7 @@ get_native_event_mask (GdkWindowObject *private)
 	 * may be asking for weird things for native windows,
 	 * but filter out things that override the above
 	 * requests somehow. */
-	(private->event_mask &
+	(event_mask &
 	 ~(GDK_POINTER_MOTION_HINT_MASK |
 	   GDK_BUTTON_MOTION_MASK |
 	   GDK_BUTTON1_MOTION_MASK |
@@ -1130,6 +1139,12 @@ get_native_event_mask (GdkWindowObject *private)
     }
 }
 
+static GdkEventMask
+get_native_event_mask (GdkWindowObject *private)
+{
+  return get_native_device_event_mask (private, NULL);
+}
+
 /* Puts the native window in the right order wrt the other native windows
  * in the hierarchy, given the position it has in the client side data.
  * This is useful if some operation changed the stacking order.
@@ -6582,6 +6597,69 @@ gdk_window_get_events (GdkWindow *window)
   return private->event_mask;
 }
 
+void
+gdk_window_set_device_events (GdkWindow    *window,
+                              GdkDevice    *device,
+                              GdkEventMask  event_mask)
+{
+  GdkWindowObject *private;
+  GdkDisplay *display;
+
+  g_return_if_fail (GDK_IS_WINDOW (window));
+  g_return_if_fail (GDK_IS_DEVICE (device));
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return;
+
+  private = (GdkWindowObject *) window;
+
+  /* If motion hint is disabled, enable motion events again */
+  display = gdk_drawable_get_display (window);
+  if ((private->event_mask & GDK_POINTER_MOTION_HINT_MASK) &&
+      !(event_mask & GDK_POINTER_MOTION_HINT_MASK))
+    _gdk_display_enable_motion_hints (display);
+
+  if (event_mask == 0)
+    {
+      /* FIXME: unsetting events on a master device
+       * would restore private->event_mask
+       */
+      g_hash_table_remove (private->device_events, device);
+    }
+  else
+    g_hash_table_insert (private->device_events, device,
+                         GINT_TO_POINTER (event_mask));
+
+  if (gdk_window_has_impl (private))
+    {
+      GdkEventMask device_mask;
+
+      device_mask = get_native_device_event_mask (private, device);
+      GDK_DEVICE_GET_CLASS (device)->select_window_events (device, window, device_mask);
+    }
+}
+
+GdkEventMask
+gdk_window_get_device_events (GdkWindow *window,
+                              GdkDevice *device)
+{
+  GdkWindowObject *private;
+  GdkEventMask mask;
+
+  g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
+  g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
+
+  if (GDK_WINDOW_DESTROYED (window))
+    return 0;
+
+  private = (GdkWindowObject *) window;
+  mask = GPOINTER_TO_INT (g_hash_table_lookup (private->device_events, device));
+
+  /* FIXME: device could be controlled by private->event_mask */
+
+  return mask;
+}
+
 static void
 gdk_window_move_resize_toplevel (GdkWindow *window,
 				 gboolean   with_move,



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