From e511451fd3efe787c5be5873376b305140e098ad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Dj=C3=A4rv?= Date: Fri, 6 Nov 2009 08:30:43 +0000 Subject: [PATCH] Fix bug #4870, issues 3 and 4. * gtkutil.c (xg_event_is_for_scrollbar): New function (bug#4870). * gtkutil.h: Declare xg_event_is_for_scrollbar (bug#4870). * xterm.c (handle_one_xevent): Call xg_event_is_for_scrollbar for ButtonPressRelease and MotionNotify (bug#4870). --- src/ChangeLog | 9 +++++++++ src/gtkutil.c | 32 ++++++++++++++++++++++++++++++++ src/gtkutil.h | 2 +- src/xterm.c | 8 ++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2e913ff30b..29387dac5e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2009-11-06 Jan Djärv + + * gtkutil.c (xg_event_is_for_scrollbar): New function (bug#4870). + + * gtkutil.h: Declare xg_event_is_for_scrollbar (bug#4870). + + * xterm.c (handle_one_xevent): Call xg_event_is_for_scrollbar for + ButtonPressRelease and MotionNotify (bug#4870). + 2009-11-06 Dan Nicolaescu * keymap.c (syms_of_keymap): Construct exclude_keys in pure memory. diff --git a/src/gtkutil.c b/src/gtkutil.c index e95601c7fd..543b868448 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -3371,6 +3371,38 @@ xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) } } +/* Return non-zero if EVENT is for a scroll bar in frame F. + When the same X window is used for several Gtk+ widgets, we cannot + say for sure based on the X window alone if an event is for the + frame. This function does additional checks. + + Return non-zero if the event is for a scroll bar, zero otherwise. */ + +int +xg_event_is_for_scrollbar (f, event) + FRAME_PTR f; + XEvent *event; +{ + int retval = 0; + + if (f && event->type == ButtonPress) + { + /* Check if press occurred outside the edit widget. */ + GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); + retval = gdk_display_get_window_at_pointer (gdpy, NULL, NULL) + != f->output_data.x->edit_widget->window; + } + else if (f && (event->type != ButtonRelease || event->type != MotionNotify)) + { + /* If we are releasing or moving the scroll bar, it has the grab. */ + retval = gtk_grab_get_current () != 0 + && gtk_grab_get_current () != f->output_data.x->edit_widget; + } + + return retval; +} + + /*********************************************************************** Tool bar functions diff --git a/src/gtkutil.h b/src/gtkutil.h index faf5395fdb..6d9f6da269 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -179,7 +179,7 @@ extern void xg_set_toolkit_scroll_bar_thumb P_ ((struct scroll_bar *bar, int portion, int position, int whole)); - +extern int xg_event_is_for_scrollbar P_ ((FRAME_PTR f, XEvent *event)); extern void update_frame_tool_bar P_ ((FRAME_PTR f)); extern void free_frame_tool_bar P_ ((FRAME_PTR f)); diff --git a/src/xterm.c b/src/xterm.c index 1ba367c998..545f3a5254 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -6688,6 +6688,10 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) clear_mouse_face (dpyinfo); } +#ifdef USE_GTK + if (f && xg_event_is_for_scrollbar (f, &event)) + f = 0; +#endif if (f) { @@ -6824,6 +6828,10 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) else f = x_window_to_frame (dpyinfo, event.xbutton.window); +#ifdef USE_GTK + if (f && xg_event_is_for_scrollbar (f, &event)) + f = 0; +#endif if (f) { /* Is this in the tool-bar? */ -- 2.20.1