Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.5367.2.30
diff -u -r1.5367.2.30 ChangeLog
--- a/ChangeLog	18 May 2004 18:32:08 -0000	1.5367.2.30
+++ b/ChangeLog	21 May 2004 22:06:23 -0000
@@ -1,3 +1,19 @@
+2004-05-11  Robert Ögren  <gtk@roboros.com>
+
+	* gdk/win32/gdkevents-win32.c (propagate): Don't propagate mouse
+	events to windows that want extended input events. (#142943)
+	(gdk_event_translate): Move check for extended input devices to
+	propagate, new parameter to propagate.
+	(gdk_pointer_grab, gdk_display_pointer_ungrab): Enable calls to
+	_gdk_input_(un)grab_pointer. (#142943)
+
+	* gdk/win32/gdkinput-win32.c (_gdk_input_other_event): Check for
+	input grab, fix missing update of impl in "dijkstra" event
+	propagation loop, don't propagate beyond windows that want
+	normal input events. (#142943)
+	(gdk_input_grab_pointer, gdk_input_ungrab_pointer): Limited
+	implementation of input grab. (#142943)
+
 2004-05-17  Matthias Clasen  <mclasen@redhat.com>
 
 	* gtk/gtkentrycompletion.c (_gtk_entry_completion_resize_popup):
Index: gdk/win32/gdkinput-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkinput-win32.c,v
retrieving revision 1.41.2.1
diff -u -r1.41.2.1 gdkinput-win32.c
--- a/gdk/win32/gdkinput-win32.c	12 May 2004 23:36:11 -0000	1.41.2.1
+++ b/gdk/win32/gdkinput-win32.c	21 May 2004 22:06:23 -0000
@@ -77,6 +77,16 @@
 
 #endif /* HAVE_WINTAB */
 
+#ifdef HAVE_SOME_XINPUT
+
+static GdkWindow *x_grab_window = NULL; /* Window that currently holds
+					 * the extended inputs grab
+					 */
+static GdkEventMask x_grab_mask;
+static gboolean x_grab_owner_events;
+
+#endif /* HAVE_SOME_XINPUT */
+
 #ifdef HAVE_WINTAB
 
 static GdkDevicePrivate *
@@ -695,8 +705,8 @@
   GdkWindow *current_window;
 #endif
   GdkDisplay *display;
-  GdkWindowObject *obj;
-  GdkWindowImplWin32 *impl;
+  GdkWindowObject *obj, *grab_obj;
+  GdkWindowImplWin32 *impl, *grab_impl;
   GdkInputWindow *input_window;
   GdkDevicePrivate *gdkdev = NULL;
   GdkEventMask masktest;
@@ -747,7 +757,7 @@
   switch (msg->message)
     {
     case WT_PACKET:
-      if (window == _gdk_parent_root)
+      if (window == _gdk_parent_root && x_grab_window == NULL)
 	{
 	  GDK_NOTE (EVENTS_OR_INPUT, g_print ("...is root\n"));
 	  return FALSE;
@@ -806,6 +816,28 @@
 	    masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON3_MOTION_MASK;
 	}
 
+      /* See if input is grabbed */
+      /* FIXME: x_grab_owner_events should probably be handled somehow */
+      if (x_grab_window != NULL)
+	{
+	  grab_obj = GDK_WINDOW_OBJECT (x_grab_window);
+	  grab_impl = GDK_WINDOW_IMPL_WIN32 (grab_obj->impl);
+	  if (!grab_impl->extension_events_selected
+	      || !(grab_obj->extension_events & masktest)
+	      || !(x_grab_mask && masktest))
+	    {
+	      GDK_NOTE (EVENTS_OR_INPUT, 
+			g_print ("...grabber doesn't want it\n"));
+	      return FALSE;
+	    }
+	  GDK_NOTE (EVENTS_OR_INPUT, g_print ("...to grabber\n"));
+
+	  g_object_ref(x_grab_window);
+	  g_object_unref(window);
+	  window = x_grab_window;
+	  obj = grab_obj;
+	  impl = grab_impl;
+	}
       /* Now we can check if the window wants the event, and
        * propagate if necessary.
        */
@@ -817,6 +849,15 @@
 
 	  if (obj->parent == GDK_WINDOW_OBJECT (_gdk_parent_root))
 	    return FALSE;
+
+	  /* It is not good to propagate the extended events up to the parent
+	   * if this window wants normal (not extended) motion/button events */
+	  if (obj->event_mask & masktest)
+	    {
+	      GDK_NOTE (EVENTS_OR_INPUT, 
+			g_print ("...wants ordinary event, ignoring this\n"));
+	      return FALSE;
+	    }
 	  
 	  pt.x = x;
 	  pt.y = y;
@@ -824,6 +865,7 @@
 	  g_object_unref (window);
 	  window = (GdkWindow *) obj->parent;
 	  obj = GDK_WINDOW_OBJECT (window);
+	  impl = GDK_WINDOW_IMPL_WIN32 (obj->impl);
 	  g_object_ref (window);
 	  ScreenToClient (GDK_WINDOW_HWND (window), &pt);
 	  x = pt.x;
@@ -1027,6 +1069,11 @@
   if (new_window)
     {
       new_window->grabbed = TRUE;
+      x_grab_window = window;
+      x_grab_mask = event_mask;
+      x_grab_owner_events = owner_events;
+
+      /* FIXME: Do we need to handle confine_to and time? */
       
       tmp_list = _gdk_input_devices;
       while (tmp_list)
@@ -1056,6 +1103,7 @@
     }
   else
     { 
+      x_grab_window = NULL;
       tmp_list = _gdk_input_devices;
       while (tmp_list)
 	{
@@ -1114,6 +1162,7 @@
 	}
     }
 #endif
+  x_grab_window = NULL;
 }
 
 gboolean
Index: gdk/win32/gdkevents-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkevents-win32.c,v
retrieving revision 1.131.2.1
diff -u -r1.131.2.1 gdkevents-win32.c
--- a/gdk/win32/gdkevents-win32.c	12 May 2004 23:36:11 -0000	1.131.2.1
+++ b/gdk/win32/gdkevents-win32.c	21 May 2004 22:06:23 -0000
@@ -533,13 +533,13 @@
     hcursor = NULL;
   else if ((hcursor = CopyCursor (cursor_private->hcursor)) == NULL)
     WIN32_API_FAILED ("CopyCursor");
-#if 0
+
   return_val = _gdk_input_grab_pointer (window,
 					owner_events,
 					event_mask,
 					confine_to,
 					time);
-#endif
+
   if (return_val == GDK_GRAB_SUCCESS)
     {
       if (!GDK_WINDOW_DESTROYED (window))
@@ -615,9 +615,8 @@
   GDK_NOTE (EVENTS, g_print ("%sgdk_display_pointer_ungrab%s",
 			     (debug_indent > 0 ? "\n" : ""),
 			     (debug_indent == 0 ? "\n" : "")));
-#if 0
+
   _gdk_input_ungrab_pointer (time);
-#endif
 
   if (GetCapture () != NULL)
     ReleaseCapture ();
@@ -1557,6 +1556,9 @@
   msg->lParam = MAKELPARAM (pt.x, pt.y);
 }
 
+/* The check_extended flag controls whether to check if the windows want
+ * events from extended input devices and if the message should be skipped
+ * because an extended input device is active */
 static gboolean
 propagate (GdkWindow  **window,
 	   MSG         *msg,
@@ -1564,13 +1566,24 @@
 	   gboolean     grab_owner_events,
 	   gint	        grab_mask,
 	   gboolean   (*doesnt_want_it) (gint mask,
-					 MSG *msg))
+					 MSG *msg),
+	   gboolean    	check_extended)
 {
   gboolean in_propagation = FALSE;
 
   if (grab_window != NULL && !grab_owner_events)
     {
       /* Event source is grabbed with owner_events FALSE */
+
+      /* See if the event should be ignored because an extended input device
+       * is used */
+      if (check_extended &&
+	  ((GdkWindowObject *) grab_window)->extension_events != 0 &&
+	  _gdk_input_ignore_core)
+	{
+	  GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
+	  return FALSE;
+	}
       if ((*doesnt_want_it) (grab_mask, msg))
 	{
 	  GDK_NOTE (EVENTS, g_print (" (grabber doesn't want it)"));
@@ -1585,7 +1598,16 @@
     }
   while (TRUE)
     {
-     if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
+      /* See if the event should be ignored because an extended input device
+       * is used */
+      if (check_extended &&
+	  ((GdkWindowObject *) *window)->extension_events != 0 &&
+	  _gdk_input_ignore_core)
+	{
+	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
+	  return FALSE;
+	}
+      if ((*doesnt_want_it) (((GdkWindowObject *) *window)->event_mask, msg))
 	{
 	  /* Owner doesn't want it, propagate to parent. */
 	  GdkWindow *parent = gdk_window_get_parent (*window);
@@ -1595,6 +1617,16 @@
 	      if (grab_window != NULL)
 		{
 		  /* Event source is grabbed with owner_events TRUE */
+
+		  /* See if the event should be ignored because an extended
+		   * input device is used */
+		  if (check_extended &&
+		      ((GdkWindowObject *) grab_window)->extension_events != 0 &&
+		      _gdk_input_ignore_core)
+		    {
+		      GDK_NOTE (EVENTS, g_print (" (ignored for grabber)"));
+		      return FALSE;
+		    }
 		  if ((*doesnt_want_it) (grab_mask, msg))
 		    {
 		      /* Grabber doesn't want it either */
@@ -2168,16 +2200,9 @@
 
       assign_object (&window, new_window);
 
-      if (((GdkWindowObject *) window)->extension_events != 0 &&
-	  _gdk_input_ignore_core)
-	{
-	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
-	  goto done;
-	}
-
       if (!propagate (&window, msg,
 		      p_grab_window, p_grab_owner_events, p_grab_mask,
-		      doesnt_want_scroll))
+		      doesnt_want_scroll, TRUE))
 	goto done;
 
       if (GDK_WINDOW_DESTROYED (window))
@@ -2319,7 +2344,7 @@
 
       if (!propagate (&window, msg,
 		      k_grab_window, k_grab_owner_events, GDK_ALL_EVENTS_MASK,
-		      doesnt_want_key))
+		      doesnt_want_key, FALSE))
 	break;
 
       if (GDK_WINDOW_DESTROYED (window))
@@ -2401,7 +2426,7 @@
 
       if (!propagate (&window, msg,
 		      k_grab_window, k_grab_owner_events, GDK_ALL_EVENTS_MASK,
-		      doesnt_want_char))
+		      doesnt_want_char, FALSE))
 	break;
 
       if (GDK_WINDOW_DESTROYED (window))
@@ -2479,16 +2504,9 @@
 	    synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
 	}
 
-      if (((GdkWindowObject *) window)->extension_events != 0 &&
-	  _gdk_input_ignore_core)
-	{
-	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
-	  break;
-	}
-
       if (!propagate (&window, msg,
 		      p_grab_window, p_grab_owner_events, p_grab_mask,
-		      doesnt_want_button_press))
+		      doesnt_want_button_press, TRUE))
 	break;
 
       if (GDK_WINDOW_DESTROYED (window))
@@ -2568,16 +2586,18 @@
 	    synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
 	}
 
+#if 0
       if (((GdkWindowObject *) window)->extension_events != 0 &&
 	  _gdk_input_ignore_core)
 	{
 	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
 	  break;
 	}
+#endif
 
       if (!propagate (&window, msg,
 		      p_grab_window, p_grab_owner_events, p_grab_mask,
-		      doesnt_want_button_release))
+		      doesnt_want_button_release, TRUE))
 	{
 	}
       else if (!GDK_WINDOW_DESTROYED (window))
@@ -2640,16 +2660,9 @@
 	    synthesize_crossing_events (window, GDK_CROSSING_NORMAL, msg);
 	}
 
-      if (((GdkWindowObject *) window)->extension_events != 0 &&
-	  _gdk_input_ignore_core)
-	{
-	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
-	  break;
-	}
-
       if (!propagate (&window, msg,
 		      p_grab_window, p_grab_owner_events, p_grab_mask,
-		      doesnt_want_button_motion))
+		      doesnt_want_button_motion, TRUE))
 	break;
 
       if (GDK_WINDOW_DESTROYED (window))
@@ -2747,16 +2760,9 @@
 	  assign_object (&window, new_window);
 	}
 
-      if (((GdkWindowObject *) window)->extension_events != 0 &&
-	  _gdk_input_ignore_core)
-	{
-	  GDK_NOTE (EVENTS, g_print (" (ignored)"));
-	  break;
-	}
-
       if (!propagate (&window, msg,
 		      p_grab_window, p_grab_owner_events, p_grab_mask,
-		      doesnt_want_scroll))
+		      doesnt_want_scroll, TRUE))
 	break;
 
       if (GDK_WINDOW_DESTROYED (window))
