Daniel Novotny 67c3d3
diff -up emacs-23.1/src/gtkutil.c.scroll emacs-23.1/src/gtkutil.c
Daniel Novotny 67c3d3
--- emacs-23.1/src/gtkutil.c.scroll	2009-06-21 06:38:15.000000000 +0200
Daniel Novotny 67c3d3
+++ emacs-23.1/src/gtkutil.c	2009-12-02 17:10:08.000000000 +0100
Daniel Novotny 67c3d3
@@ -3401,6 +3401,38 @@ xg_set_toolkit_scroll_bar_thumb (bar, po
Daniel Novotny 67c3d3
     }
Daniel Novotny 67c3d3
 }
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
+/* Return non-zero if EVENT is for a scroll bar in frame F.
Daniel Novotny 67c3d3
+   When the same X window is used for several Gtk+ widgets, we cannot
Daniel Novotny 67c3d3
+   say for sure based on the X window alone if an event is for the
Daniel Novotny 67c3d3
+   frame.  This function does additional checks.
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+   Return non-zero if the event is for a scroll bar, zero otherwise.  */
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+int
Daniel Novotny 67c3d3
+xg_event_is_for_scrollbar (f, event)
Daniel Novotny 67c3d3
+     FRAME_PTR f;
Daniel Novotny 67c3d3
+     XEvent *event;
Daniel Novotny 67c3d3
+{
Daniel Novotny 67c3d3
+  int retval = 0;
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+  if (f && event->type == ButtonPress)
Daniel Novotny 67c3d3
+    {
Daniel Novotny 67c3d3
+      /* Check if press occurred outside the edit widget.  */
Daniel Novotny 67c3d3
+      GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
Daniel Novotny 67c3d3
+      retval = gdk_display_get_window_at_pointer (gdpy, NULL, NULL)
Daniel Novotny 67c3d3
+        != f->output_data.x->edit_widget->window;
Daniel Novotny 67c3d3
+    }
Daniel Novotny 67c3d3
+  else if (f && (event->type != ButtonRelease || event->type != MotionNotify))
Daniel Novotny 67c3d3
+    {
Daniel Novotny 67c3d3
+      /* If we are releasing or moving the scroll bar, it has the grab.  */
Daniel Novotny 67c3d3
+      retval = gtk_grab_get_current () != 0
Daniel Novotny 67c3d3
+        && gtk_grab_get_current () != f->output_data.x->edit_widget;
Daniel Novotny 67c3d3
+    }
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+  return retval;
Daniel Novotny 67c3d3
+}
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
 /***********************************************************************
Daniel Novotny 67c3d3
                       Tool bar functions
Daniel Novotny 67c3d3
diff -up emacs-23.1/src/gtkutil.h.scroll emacs-23.1/src/gtkutil.h
Daniel Novotny 67c3d3
--- emacs-23.1/src/gtkutil.h.scroll	2009-06-21 06:38:15.000000000 +0200
Daniel Novotny 67c3d3
+++ emacs-23.1/src/gtkutil.h	2009-12-02 17:10:08.000000000 +0100
Daniel Novotny 67c3d3
@@ -180,6 +180,8 @@ extern void xg_set_toolkit_scroll_bar_th
Daniel Novotny 67c3d3
                                                  int position,
Daniel Novotny 67c3d3
                                                  int whole));
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
+extern int xg_event_is_for_scrollbar P_ ((FRAME_PTR f, XEvent *event));
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
 extern void update_frame_tool_bar P_ ((FRAME_PTR f));
Daniel Novotny 67c3d3
 extern void free_frame_tool_bar P_ ((FRAME_PTR f));
Daniel Novotny 67c3d3
diff -up emacs-23.1/src/xterm.c.scroll emacs-23.1/src/xterm.c
Daniel Novotny 67c3d3
--- emacs-23.1/src/xterm.c.scroll	2009-06-21 06:38:20.000000000 +0200
Daniel Novotny 67c3d3
+++ emacs-23.1/src/xterm.c	2009-12-02 17:13:24.000000000 +0100
Daniel Novotny 67c3d3
@@ -6743,6 +6743,12 @@ handle_one_xevent (dpyinfo, eventp, fini
Daniel Novotny 67c3d3
             clear_mouse_face (dpyinfo);
Daniel Novotny 67c3d3
           }
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
+#ifdef USE_GTK
Daniel Novotny 67c3d3
+        if (f && xg_event_is_for_scrollbar (f, &event))
Daniel Novotny 67c3d3
+          f = 0;
Daniel Novotny 67c3d3
+#endif
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
         if (f)
Daniel Novotny 67c3d3
           {
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
@@ -6899,6 +6905,11 @@ handle_one_xevent (dpyinfo, eventp, fini
Daniel Novotny 67c3d3
         else
Daniel Novotny 67c3d3
           f = x_window_to_frame (dpyinfo, event.xbutton.window);
Daniel Novotny 67c3d3
 
Daniel Novotny 67c3d3
+#ifdef USE_GTK
Daniel Novotny 67c3d3
+        if (f && xg_event_is_for_scrollbar (f, &event))
Daniel Novotny 67c3d3
+          f = 0;
Daniel Novotny 67c3d3
+#endif
Daniel Novotny 67c3d3
+
Daniel Novotny 67c3d3
         if (f)
Daniel Novotny 67c3d3
           {
Daniel Novotny 67c3d3
             /* Is this in the tool-bar?  */