[gtk+/xi2] Factor out find_toplevel_for_mouse_event()
- From: Kristian Rietveld <kristian src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/xi2] Factor out find_toplevel_for_mouse_event()
- Date: Mon, 10 May 2010 20:34:51 +0000 (UTC)
commit 99e73e02f6b8fd6db987a1333d8ac6c590dd0dca
Author: Kristian Rietveld <kris gtk org>
Date: Thu Mar 11 11:22:32 2010 +0100
Factor out find_toplevel_for_mouse_event()
gdk/quartz/gdkevents-quartz.c | 295 +++++++++++++++++++++-------------------
1 files changed, 155 insertions(+), 140 deletions(-)
---
diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c
index 77df4ec..b41fd92 100644
--- a/gdk/quartz/gdkevents-quartz.c
+++ b/gdk/quartz/gdkevents-quartz.c
@@ -565,6 +565,158 @@ find_toplevel_for_keyboard_event (GdkDisplay *display,
return window;
}
+static GdkWindow *
+find_toplevel_for_mouse_event (NSEvent *nsevent,
+ GdkWindow *toplevel,
+ gint *x,
+ gint *y)
+{
+ NSPoint point;
+ NSPoint screen_point;
+ NSEventType event_type;
+ GdkDisplay *display;
+ GdkDeviceGrabInfo *grab;
+ GdkWindowObject *private;
+
+ display = gdk_drawable_get_display (toplevel);
+ private = GDK_WINDOW_OBJECT (toplevel);
+
+ event_type = [nsevent type];
+ point = [nsevent locationInWindow];
+ screen_point = [[nsevent window] convertBaseToScreen:point];
+
+ *x = point.x;
+ *y = private->height - point.y;
+
+ /* From the docs for XGrabPointer:
+ *
+ * If owner_events is True and if a generated pointer event
+ * would normally be reported to this client, it is reported
+ * as usual. Otherwise, the event is reported with respect to
+ * the grab_window and is reported only if selected by
+ * event_mask. For either value of owner_events, unreported
+ * events are discarded.
+ */
+ grab = _gdk_display_get_last_device_grab (display,
+ display->core_pointer);
+ if (grab)
+ {
+ /* Implicit grabs do not go through XGrabPointer and thus the
+ * event mask should not be checked.
+ */
+ if (!grab->implicit
+ && (grab->event_mask & get_event_mask_from_ns_event (nsevent)) == 0)
+ return NULL;
+
+ if (grab->owner_events)
+ {
+ /* For owner events, we need to use the toplevel under the
+ * pointer, not the window from the NSEvent, since that is
+ * reported with respect to the key window, which could be
+ * wrong.
+ */
+ GdkWindow *toplevel_under_pointer;
+ gint x_tmp, y_tmp;
+
+ toplevel_under_pointer = find_toplevel_under_pointer (display,
+ screen_point,
+ &x_tmp, &y_tmp);
+ if (toplevel_under_pointer)
+ {
+ toplevel = toplevel_under_pointer;
+ *x = x_tmp;
+ *y = y_tmp;
+ }
+
+ return toplevel;
+ }
+ else
+ {
+ /* Finally check the grab window. */
+ GdkWindow *grab_toplevel;
+ GdkWindowObject *grab_private;
+ NSWindow *grab_nswindow;
+
+ grab_toplevel = gdk_window_get_toplevel (grab->window);
+ grab_private = (GdkWindowObject *)grab_toplevel;
+
+ grab_nswindow = ((GdkWindowImplQuartz *)grab_private->impl)->toplevel;
+ point = [grab_nswindow convertScreenToBase:screen_point];
+
+ /* Note: x_root and y_root are already right. */
+ *x = point.x;
+ *y = grab_private->height - point.y;
+
+ return grab_toplevel;
+ }
+
+ return NULL;
+ }
+ else
+ {
+ /* The non-grabbed case. */
+ GdkWindow *toplevel_under_pointer;
+ gint x_tmp, y_tmp;
+
+ /* Ignore all events but mouse moved that might be on the title
+ * bar (above the content view). The reason is that otherwise
+ * gdk gets confused about getting e.g. button presses with no
+ * window (the title bar is not known to it).
+ */
+ if (event_type != NSMouseMoved)
+ if (*y < 0)
+ return NULL;
+
+ /* As for owner events, we need to use the toplevel under the
+ * pointer, not the window from the NSEvent.
+ */
+ toplevel_under_pointer = find_toplevel_under_pointer (display,
+ screen_point,
+ &x_tmp, &y_tmp);
+ if (toplevel_under_pointer)
+ {
+ GdkWindowObject *toplevel_private;
+ GdkWindowImplQuartz *toplevel_impl;
+
+ toplevel = toplevel_under_pointer;
+
+ toplevel_private = (GdkWindowObject *)toplevel;
+ toplevel_impl = (GdkWindowImplQuartz *)toplevel_private->impl;
+
+ if ([toplevel_impl->toplevel showsResizeIndicator])
+ {
+ NSRect frame;
+
+ /* If the resize indicator is visible and the event
+ * is in the lower right 15x15 corner, we leave these
+ * events to Cocoa as to be handled as resize events.
+ * Applications may have widgets in this area. These
+ * will most likely be larger than 15x15 and for
+ * scroll bars there are also other means to move
+ * the scroll bar. Since the resize indicator is
+ * the only way of resizing windows on Mac OS, it
+ * is too important to not make functional.
+ */
+ frame = [toplevel_impl->view bounds];
+ if (x_tmp > frame.size.width - GRIP_WIDTH
+ && x_tmp < frame.size.width
+ && y_tmp > frame.size.height - GRIP_HEIGHT
+ && y_tmp < frame.size.height)
+ {
+ return NULL;
+ }
+ }
+
+ *x = x_tmp;
+ *y = y_tmp;
+ }
+
+ return toplevel;
+ }
+
+ return NULL;
+}
+
/* This function finds the correct window to send an event to, taking
* into account grabs, event propagation, and event masks.
*/
@@ -577,24 +729,19 @@ find_window_for_ns_event (NSEvent *nsevent,
{
GdkQuartzView *view;
GdkWindow *toplevel;
- GdkWindowObject *private;
NSPoint point;
NSPoint screen_point;
NSEventType event_type;
view = (GdkQuartzView *)[[nsevent window] contentView];
- toplevel = [view gdkWindow];
- private = GDK_WINDOW_OBJECT (toplevel);
-
point = [nsevent locationInWindow];
screen_point = [[nsevent window] convertBaseToScreen:point];
- *x = point.x;
- *y = private->height - point.y;
-
_gdk_quartz_window_nspoint_to_gdk_xy (screen_point, x_root, y_root);
+ toplevel = [view gdkWindow];
+
event_type = [nsevent type];
switch (event_type)
@@ -610,139 +757,7 @@ find_window_for_ns_event (NSEvent *nsevent,
case NSLeftMouseDragged:
case NSRightMouseDragged:
case NSOtherMouseDragged:
- {
- GdkDisplay *display;
- GdkDeviceGrabInfo *grab;
-
- display = gdk_drawable_get_display (toplevel);
-
- /* From the docs for XGrabPointer:
- *
- * If owner_events is True and if a generated pointer event
- * would normally be reported to this client, it is reported
- * as usual. Otherwise, the event is reported with respect to
- * the grab_window and is reported only if selected by
- * event_mask. For either value of owner_events, unreported
- * events are discarded.
- */
- grab = _gdk_display_get_last_device_grab (display,
- display->core_pointer);
- if (grab)
- {
- /* Implicit grabs do not go through XGrabPointer and thus the
- * event mask should not be checked.
- */
- if (!grab->implicit
- && (grab->event_mask & get_event_mask_from_ns_event (nsevent)) == 0)
- return NULL;
-
- if (grab->owner_events)
- {
- /* For owner events, we need to use the toplevel under the
- * pointer, not the window from the NSEvent, since that is
- * reported with respect to the key window, which could be
- * wrong.
- */
- GdkWindow *toplevel_under_pointer;
- gint x_tmp, y_tmp;
-
- toplevel_under_pointer = find_toplevel_under_pointer (display,
- screen_point,
- &x_tmp, &y_tmp);
- if (toplevel_under_pointer)
- {
- toplevel = toplevel_under_pointer;
- *x = x_tmp;
- *y = y_tmp;
- }
-
- return toplevel;
- }
- else
- {
- /* Finally check the grab window. */
- GdkWindow *grab_toplevel;
- GdkWindowObject *grab_private;
- NSWindow *grab_nswindow;
-
- grab_toplevel = gdk_window_get_toplevel (grab->window);
- grab_private = (GdkWindowObject *)grab_toplevel;
-
- grab_nswindow = ((GdkWindowImplQuartz *)grab_private->impl)->toplevel;
- point = [grab_nswindow convertScreenToBase:screen_point];
-
- /* Note: x_root and y_root are already right. */
- *x = point.x;
- *y = grab_private->height - point.y;
-
- return grab_toplevel;
- }
-
- return NULL;
- }
- else
- {
- /* The non-grabbed case. */
- GdkWindow *toplevel_under_pointer;
- gint x_tmp, y_tmp;
-
- /* Ignore all events but mouse moved that might be on the title
- * bar (above the content view). The reason is that otherwise
- * gdk gets confused about getting e.g. button presses with no
- * window (the title bar is not known to it).
- */
- if (event_type != NSMouseMoved)
- if (*y < 0)
- return NULL;
-
- /* As for owner events, we need to use the toplevel under the
- * pointer, not the window from the NSEvent.
- */
- toplevel_under_pointer = find_toplevel_under_pointer (display,
- screen_point,
- &x_tmp, &y_tmp);
- if (toplevel_under_pointer)
- {
- GdkWindowObject *toplevel_private;
- GdkWindowImplQuartz *toplevel_impl;
-
- toplevel = toplevel_under_pointer;
-
- toplevel_private = (GdkWindowObject *)toplevel;
- toplevel_impl = (GdkWindowImplQuartz *)toplevel_private->impl;
-
- if ([toplevel_impl->toplevel showsResizeIndicator])
- {
- NSRect frame;
-
- /* If the resize indicator is visible and the event
- * is in the lower right 15x15 corner, we leave these
- * events to Cocoa as to be handled as resize events.
- * Applications may have widgets in this area. These
- * will most likely be larger than 15x15 and for
- * scroll bars there are also other means to move
- * the scroll bar. Since the resize indicator is
- * the only way of resizing windows on Mac OS, it
- * is too important to not make functional.
- */
- frame = [toplevel_impl->view bounds];
- if (x_tmp > frame.size.width - GRIP_WIDTH
- && x_tmp < frame.size.width
- && y_tmp > frame.size.height - GRIP_HEIGHT
- && y_tmp < frame.size.height)
- {
- return NULL;
- }
- }
-
- *x = x_tmp;
- *y = y_tmp;
- }
-
- return toplevel;
- }
- }
- break;
+ return find_toplevel_for_mouse_event (nsevent, toplevel, x, y);
case NSMouseEntered:
case NSMouseExited:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]