#include "gdkkeysyms.h"
#include "gdkprivate-quartz.h"
-/* This is the window the mouse is currently over */
-static GdkWindow *current_mouse_window;
-
/* This is the window corresponding to the key window */
static GdkWindow *current_keyboard_window;
-/* This is the pointer grab window */
-GdkWindow *_gdk_quartz_pointer_grab_window;
-static gboolean pointer_grab_owner_events;
-static GdkEventMask pointer_grab_event_mask;
-
-/* This is the keyboard grab window */
-GdkWindow * _gdk_quartz_keyboard_grab_window;
-static gboolean keyboard_grab_owner_events;
-
/* This is the event mask and button state from the last event */
static GdkEventMask current_event_mask;
static int current_button_state;
-static void get_child_coordinates_from_ancestor (GdkWindow *ancestor_window,
- gint ancestor_x,
- gint ancestor_y,
- GdkWindow *child_window,
- gint *child_x,
- gint *child_y);
-static void get_ancestor_coordinates_from_child (GdkWindow *child_window,
- gint child_x,
- gint child_y,
- GdkWindow *ancestor_window,
- gint *ancestor_x,
- gint *ancestor_y);
-static void get_converted_window_coordinates (GdkWindow *in_window,
- gint in_x,
- gint in_y,
- GdkWindow *out_window,
- gint *out_x,
- gint *out_y);
static void append_event (GdkEvent *event);
-static const gchar *
-which_window_is_this (GdkWindow *window)
-{
- static gchar buf[256];
- const gchar *name = NULL;
- gpointer widget;
-
- /* Get rid of compiler warning. */
- if (0) which_window_is_this (window);
-
- if (window == _gdk_root)
- name = "root";
- else if (window == NULL)
- name = "null";
-
- if (window)
- {
- gdk_window_get_user_data (window, &widget);
- if (widget)
- name = G_OBJECT_TYPE_NAME (widget);
- }
-
- if (!name)
- name = "unknown";
-
- snprintf (buf, 256, "<%s (%p)%s>",
- name, window,
- window == current_mouse_window ? ", is mouse" : "");
-
- return buf;
-}
-
NSEvent *
gdk_quartz_event_get_nsevent (GdkEvent *event)
{
{
_gdk_quartz_event_loop_init ();
- current_mouse_window = g_object_ref (_gdk_root);
current_keyboard_window = g_object_ref (_gdk_root);
}
return NULL;
}
-static void
-generate_grab_broken_event (GdkWindow *window,
- gboolean keyboard,
- GdkWindow *grab_window)
-{
- if (!GDK_WINDOW_DESTROYED (window))
- {
- GdkEvent *event = gdk_event_new (GDK_GRAB_BROKEN);
-
- event->grab_broken.window = window;
- event->grab_broken.send_event = 0;
- event->grab_broken.keyboard = keyboard;
- event->grab_broken.implicit = FALSE;
- event->grab_broken.grab_window = grab_window;
-
- append_event (event);
- }
-}
-
GdkGrabStatus
gdk_keyboard_grab (GdkWindow *window,
gint owner_events,
guint32 time)
{
+ GdkDisplay *display;
+ GdkWindow *toplevel;
+
g_return_val_if_fail (window != NULL, 0);
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
- if (_gdk_quartz_keyboard_grab_window)
- {
- if (_gdk_quartz_keyboard_grab_window != window)
- generate_grab_broken_event (_gdk_quartz_keyboard_grab_window,
- TRUE, window);
-
- g_object_unref (_gdk_quartz_keyboard_grab_window);
- }
+ display = gdk_drawable_get_display (window);
+ toplevel = gdk_window_get_toplevel (window);
- _gdk_quartz_keyboard_grab_window = g_object_ref (window);
- keyboard_grab_owner_events = owner_events;
+ _gdk_display_set_has_keyboard_grab (display,
+ window,
+ toplevel,
+ owner_events,
+ 0,
+ time);
return GDK_GRAB_SUCCESS;
}
gdk_display_keyboard_ungrab (GdkDisplay *display,
guint32 time)
{
- if (_gdk_quartz_keyboard_grab_window)
- g_object_unref (_gdk_quartz_keyboard_grab_window);
- _gdk_quartz_keyboard_grab_window = NULL;
-}
-
-static void
-pointer_ungrab_internal (void)
-{
- if (!_gdk_quartz_pointer_grab_window)
- return;
-
- g_object_unref (_gdk_quartz_pointer_grab_window);
- _gdk_quartz_pointer_grab_window = NULL;
-
- pointer_grab_owner_events = FALSE;
- pointer_grab_event_mask = 0;
-
- /* FIXME: Send crossing events */
+ _gdk_display_unset_has_keyboard_grab (display, FALSE);
}
void
gdk_display_pointer_ungrab (GdkDisplay *display,
guint32 time)
{
- pointer_ungrab_internal ();
-}
+ GdkPointerGrabInfo *grab;
-static GdkGrabStatus
-pointer_grab_internal (GdkWindow *window,
- gboolean owner_events,
- GdkEventMask event_mask,
- GdkWindow *confine_to,
- GdkCursor *cursor)
-{
- /* FIXME: Send crossing events */
-
- _gdk_quartz_pointer_grab_window = g_object_ref (window);
- pointer_grab_owner_events = owner_events;
- pointer_grab_event_mask = event_mask;
+ grab = _gdk_display_get_last_pointer_grab (display);
+ if (grab)
+ grab->serial_end = 0;
- return GDK_GRAB_SUCCESS;
+ _gdk_display_pointer_grab_update (display, 0);
}
GdkGrabStatus
GdkCursor *cursor,
guint32 time)
{
- GdkWindow *toplevel;
+ GdkWindow *native;
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
- toplevel = gdk_window_get_toplevel (window);
+ native = gdk_window_get_toplevel (window);
- /* TODO: What do we do for offscreens and their children? We need to proxy the grab somehow */
- if (!GDK_IS_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl))
+ /* TODO: What do we do for offscreens and their children? We need to proxy the grab somehow */
+ if (!GDK_IS_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (native)->impl))
return GDK_GRAB_SUCCESS;
- if (_gdk_quartz_pointer_grab_window)
- {
- if (_gdk_quartz_pointer_grab_window != window)
- generate_grab_broken_event (_gdk_quartz_pointer_grab_window,
- FALSE,
- window);
+ if (!_gdk_window_has_impl (window) &&
+ !gdk_window_is_viewable (window))
+ return GDK_GRAB_NOT_VIEWABLE;
- pointer_ungrab_internal ();
- }
+ _gdk_display_add_pointer_grab (_gdk_display,
+ window,
+ native,
+ owner_events,
+ event_mask,
+ 0,
+ time,
+ FALSE);
- return pointer_grab_internal (window, owner_events, event_mask,
- confine_to, cursor);
+ return GDK_GRAB_SUCCESS;
}
-/* This is used to break any grabs in the case where we have to due to
- * the grab emulation. Instead of enforcing the desktop wide grab, we
- * break it when the app loses focus for example.
- */
static void
-break_all_grabs (void)
+break_all_grabs (guint32 time)
{
- if (_gdk_quartz_keyboard_grab_window)
- {
- generate_grab_broken_event (_gdk_quartz_keyboard_grab_window,
- TRUE,
- NULL);
- g_object_unref (_gdk_quartz_keyboard_grab_window);
- _gdk_quartz_keyboard_grab_window = NULL;
- }
+ GdkPointerGrabInfo *grab;
+
+ if (_gdk_display->keyboard_grab.window)
+ _gdk_display_unset_has_keyboard_grab (_gdk_display, FALSE);
- if (_gdk_quartz_pointer_grab_window)
+ grab = _gdk_display_get_last_pointer_grab (_gdk_display);
+ if (grab)
{
- generate_grab_broken_event (_gdk_quartz_pointer_grab_window,
- FALSE,
- NULL);
- pointer_ungrab_internal ();
+ grab->serial_end = 0;
+ grab->implicit_ungrab = TRUE;
}
+
+ _gdk_display_pointer_grab_update (_gdk_display, 0);
}
static void
return GDK_FILTER_CONTINUE;
}
-/* Checks if the passed in window is interested in the event mask, and
- * if so, it's returned. If not, the event can be propagated through
- * its ancestors until one with the right event mask is found, up to
- * the nearest toplevel.
- */
-static GdkWindow *
-find_window_interested_in_event_mask (GdkWindow *window,
- GdkEventMask event_mask,
- gboolean propagate)
-{
- GdkWindowObject *private;
-
- private = GDK_WINDOW_OBJECT (window);
- while (private)
- {
- if (private->event_mask & event_mask)
- return (GdkWindow *)private;
-
- if (!propagate)
- return NULL;
-
- /* Don't traverse beyond toplevels. */
- if (GDK_WINDOW_TYPE (private) != GDK_WINDOW_CHILD)
- break;
-
- private = private->parent;
- }
-
- return NULL;
-}
-
static guint32
get_time_from_ns_event (NSEvent *event)
{
}
}
-/* Get current mouse window */
-GdkWindow *
-_gdk_quartz_events_get_mouse_window (gboolean consider_grabs)
-{
- if (!consider_grabs)
- return current_mouse_window;
-
- if (_gdk_quartz_pointer_grab_window && !pointer_grab_owner_events)
- return _gdk_quartz_pointer_grab_window;
-
- return current_mouse_window;
-}
-
-/* Update mouse window */
-void
-_gdk_quartz_events_update_mouse_window (GdkWindow *window)
-{
- if (window == current_mouse_window)
- return;
-
-#ifdef G_ENABLE_DEBUG
- if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
- _gdk_quartz_window_debug_highlight (window, 0);
-#endif /* G_ENABLE_DEBUG */
-
- if (window)
- g_object_ref (window);
- if (current_mouse_window)
- g_object_unref (current_mouse_window);
-
- current_mouse_window = window;
-}
-
-/* Update current cursor */
-void
-_gdk_quartz_events_update_cursor (GdkWindow *window)
-{
- GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
- NSCursor *nscursor = nil;
-
- while (private)
- {
- GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
-
- nscursor = impl->nscursor;
- if (nscursor)
- break;
-
- private = private->parent;
- }
-
- GDK_QUARTZ_ALLOC_POOL;
-
- if (!nscursor)
- nscursor = [NSCursor arrowCursor];
-
- if ([NSCursor currentCursor] != nscursor)
- [nscursor set];
-
- GDK_QUARTZ_RELEASE_POOL;
-}
-
-/* Translates coordinates from an ancestor window + coords, to
- * coordinates that are relative the child window.
- */
-static void
-get_child_coordinates_from_ancestor (GdkWindow *ancestor_window,
- gint ancestor_x,
- gint ancestor_y,
- GdkWindow *child_window,
- gint *child_x,
- gint *child_y)
-{
- GdkWindowObject *ancestor_private = GDK_WINDOW_OBJECT (ancestor_window);
- GdkWindowObject *child_private = GDK_WINDOW_OBJECT (child_window);
-
- while (child_private != ancestor_private)
- {
- ancestor_x -= child_private->x;
- ancestor_y -= child_private->y;
-
- child_private = child_private->parent;
- }
-
- *child_x = ancestor_x;
- *child_y = ancestor_y;
-}
-
-/* Translates coordinates from a child window + coords, to
- * coordinates that are relative the ancestor window.
- */
-static void
-get_ancestor_coordinates_from_child (GdkWindow *child_window,
- gint child_x,
- gint child_y,
- GdkWindow *ancestor_window,
- gint *ancestor_x,
- gint *ancestor_y)
-{
- GdkWindowObject *child_private = GDK_WINDOW_OBJECT (child_window);
- GdkWindowObject *ancestor_private = GDK_WINDOW_OBJECT (ancestor_window);
-
- while (child_private != ancestor_private)
- {
- child_x += child_private->x;
- child_y += child_private->y;
-
- child_private = child_private->parent;
- }
-
- *ancestor_x = child_x;
- *ancestor_y = child_y;
-}
-
-/* Translates coordinates relative to one window (in_window) into
- * coordinates relative to another window (out_window).
- */
-static void
-get_converted_window_coordinates (GdkWindow *in_window,
- gint in_x,
- gint in_y,
- GdkWindow *out_window,
- gint *out_x,
- gint *out_y)
-{
- GdkWindow *in_toplevel;
- GdkWindow *out_toplevel;
- int in_origin_x, in_origin_y;
- int out_origin_x, out_origin_y;
-
- if (in_window == out_window)
- {
- *out_x = in_x;
- *out_y = in_y;
- return;
- }
-
- /* First translate to "in" toplevel coordinates, then on to "out"
- * toplevel coordinates, and finally to "out" child (the passed in
- * window) coordinates.
- */
-
- in_toplevel = gdk_window_get_toplevel (in_window);
- out_toplevel = gdk_window_get_toplevel (out_window);
-
- /* Translate in_x, in_y to "in" toplevel coordinates. */
- get_ancestor_coordinates_from_child (in_window, in_x, in_y,
- in_toplevel, &in_x, &in_y);
-
- gdk_window_get_origin (in_toplevel, &in_origin_x, &in_origin_y);
- gdk_window_get_origin (out_toplevel, &out_origin_x, &out_origin_y);
-
- /* Translate in_x, in_y to "out" toplevel coordinates. */
- in_x -= out_origin_x - in_origin_x;
- in_y -= out_origin_y - in_origin_y;
-
- get_child_coordinates_from_ancestor (out_toplevel,
- in_x, in_y,
- out_window,
- out_x, out_y);
-}
-
-/* Given a mouse NSEvent (must be a mouse event for a GDK window),
- * finds the subwindow over which the pointer is located. Returns
- * coordinates relative to the found window. If no window is found,
- * returns the root window, and root window coordinates.
- */
static GdkWindow *
-find_mouse_window_for_ns_event (NSEvent *nsevent,
- gint *x_ret,
- gint *y_ret)
-{
- GdkWindow *event_toplevel;
- GdkWindowImplQuartz *impl;
- GdkWindowObject *private;
- GdkWindow *mouse_toplevel;
- GdkWindow *mouse_window;
- NSPoint point;
- gint x_tmp, y_tmp;
-
- event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
- impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (event_toplevel)->impl);
- private = GDK_WINDOW_OBJECT (event_toplevel);
- point = [nsevent locationInWindow];
-
- x_tmp = point.x;
- y_tmp = private->height - point.y;
-
- mouse_toplevel = gdk_window_get_toplevel (current_mouse_window);
-
- get_converted_window_coordinates (event_toplevel,
- x_tmp, y_tmp,
- mouse_toplevel,
- &x_tmp, &y_tmp);
-
- mouse_window = _gdk_quartz_window_find_child (mouse_toplevel, x_tmp, y_tmp);
- if (mouse_window && mouse_window != mouse_toplevel)
- {
- get_child_coordinates_from_ancestor (mouse_toplevel,
- x_tmp, y_tmp,
- mouse_window,
- &x_tmp, &y_tmp);
- }
- else if (!mouse_window)
- {
- /* This happens for events on the window title buttons and the
- * desktop, treat those as being on the root window.
- */
- get_converted_window_coordinates (mouse_toplevel,
- x_tmp, y_tmp,
- _gdk_root,
- &x_tmp, &y_tmp);
- mouse_window = _gdk_root;
- }
-
- *x_ret = x_tmp;
- *y_ret = y_tmp;
-
- return mouse_window;
-}
-
-/* Trigger crossing events if necessary. This is used when showing a new
- * window, since the tracking rect API doesn't work reliably when a window
- * shows up under the mouse cursor. It's done by finding the topmost window
- * under the mouse pointer and synthesizing crossing events into that
- * window.
- */
-void
-_gdk_quartz_events_trigger_crossing_events (gboolean defer_to_mainloop)
+find_toplevel_under_pointer (GdkDisplay *display,
+ NSPoint screen_point,
+ gint *x,
+ gint *y)
{
- NSPoint point;
- gint x, y;
- gint x_toplevel, y_toplevel;
- GdkWindow *mouse_window;
GdkWindow *toplevel;
- GdkWindowImplQuartz *impl;
- GdkWindowObject *private;
- guint flags = 0;
- NSTimeInterval timestamp = 0;
- NSEvent *current_event;
- NSEvent *nsevent;
- if (defer_to_mainloop)
+ toplevel = display->pointer_info.toplevel_under_pointer;
+ if (toplevel)
{
- nsevent = [NSEvent otherEventWithType:NSApplicationDefined
- location:NSZeroPoint
- modifierFlags:0
- timestamp:0
- windowNumber:0
- context:nil
- subtype:GDK_QUARTZ_EVENT_SUBTYPE_FAKE_CROSSING
- data1:0
- data2:0];
- [NSApp postEvent:nsevent atStart:NO];
- return;
- }
+ GdkWindowObject *private;
+ NSWindow *nswindow;
+ NSPoint point;
- point = [NSEvent mouseLocation];
- x = point.x;
- y = _gdk_quartz_window_get_inverted_screen_y (point.y);
-
- mouse_window = _gdk_quartz_window_find_child (_gdk_root, x, y);
- if (!mouse_window || mouse_window == _gdk_root)
- return;
+ private = (GdkWindowObject *)toplevel;
+ nswindow = ((GdkWindowImplQuartz *)private->impl)->toplevel;
- toplevel = gdk_window_get_toplevel (mouse_window);
+ point = [nswindow convertScreenToBase:screen_point];
- /* We ignore crossing within the same toplevel since that is already
- * handled elsewhere.
- */
- if (toplevel == gdk_window_get_toplevel (current_mouse_window))
- return;
-
- get_converted_window_coordinates (_gdk_root,
- x, y,
- toplevel,
- &x_toplevel, &y_toplevel);
-
- get_converted_window_coordinates (_gdk_root,
- x, y,
- mouse_window,
- &x, &y);
-
- /* Fix up the event to be less fake if possible. */
- current_event = [NSApp currentEvent];
- if (current_event)
- {
- flags = [current_event modifierFlags];
- timestamp = [current_event timestamp];
+ *x = point.x;
+ *y = private->height - point.y;
}
- if (timestamp == 0)
- timestamp = GetCurrentEventTime ();
-
- impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);
- private = GDK_WINDOW_OBJECT (toplevel);
- nsevent = [NSEvent otherEventWithType:NSApplicationDefined
- location:NSMakePoint (x_toplevel, private->height - y_toplevel)
- modifierFlags:flags
- timestamp:timestamp
- windowNumber:[impl->toplevel windowNumber]
- context:nil
- subtype:GDK_QUARTZ_EVENT_SUBTYPE_FAKE_CROSSING
- data1:0
- data2:0];
-
-#ifdef G_ENABLE_DEBUG
- /*_gdk_quartz_window_debug_highlight (mouse_window, 0);*/
-#endif
-
- /* FIXME: create an event, fill it, put on the queue... */
+ return toplevel;
}
/* This function finds the correct window to send an event to, taking
gint *x_root,
gint *y_root)
{
+ GdkQuartzView *view;
GdkWindow *toplevel;
GdkWindowObject *private;
- GdkWindowImplQuartz *impl;
NSPoint point;
- NSPoint base;
+ NSPoint screen_point;
NSEventType event_type;
- toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
+ view = (GdkQuartzView *)[[nsevent window] contentView];
+
+ toplevel = [view gdkWindow];
private = GDK_WINDOW_OBJECT (toplevel);
- impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
point = [nsevent locationInWindow];
- base = [[nsevent window] convertBaseToScreen:point];
+ screen_point = [[nsevent window] convertBaseToScreen:point];
*x = point.x;
*y = private->height - point.y;
- *x_root = base.x;
- *y_root = _gdk_quartz_window_get_inverted_screen_y (base.y);
+ *x_root = screen_point.x;
+ *y_root = _gdk_quartz_window_get_inverted_screen_y (screen_point.y);
event_type = [nsevent type];
case NSRightMouseDragged:
case NSOtherMouseDragged:
{
- GdkWindow *mouse_window;
- GdkEventMask event_mask;
- GdkWindow *real_window;
+ GdkDisplay *display;
+ GdkPointerGrabInfo *grab;
+
+ display = gdk_drawable_get_display (toplevel);
/* From the docs for XGrabPointer:
*
* the grab_window and is reported only if selected by
* event_mask. For either value of owner_events, unreported
* events are discarded.
- *
- * This means we first try the owner, then the grab window,
- * then give up.
*/
- if (0 && _gdk_quartz_pointer_grab_window) /* FIXME: Implement grabs? */
+ grab = _gdk_display_get_last_pointer_grab (display);
+ if (grab)
{
- if (pointer_grab_owner_events)
- {
- mouse_window = find_mouse_window_for_ns_event (nsevent, x, y);
- event_mask = get_event_mask_from_ns_event (nsevent);
- real_window = find_window_interested_in_event_mask (mouse_window, event_mask, TRUE);
-
- if (mouse_window && real_window && mouse_window != real_window)
- get_ancestor_coordinates_from_child (mouse_window,
- *x, *y,
- real_window,
- x, y);
-
- if (real_window)
- return real_window;
- }
+ if ((grab->event_mask & get_event_mask_from_ns_event (nsevent)) == 0)
+ return NULL;
- /* Finally check the grab window. */
- if (pointer_grab_event_mask & get_event_mask_from_ns_event (nsevent))
- {
- GdkWindow *event_toplevel;
+ 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;
- NSPoint point;
- int x_tmp, y_tmp;
+ GdkWindowObject *grab_private;
+ NSWindow *grab_nswindow;
- event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
- grab_toplevel = gdk_window_get_toplevel (_gdk_quartz_pointer_grab_window);
- point = [nsevent locationInWindow];
+ grab_toplevel = gdk_window_get_toplevel (grab->window);
+ grab_private = (GdkWindowObject *)grab_toplevel;
- x_tmp = point.x;
- y_tmp = GDK_WINDOW_OBJECT (grab_toplevel)->height - point.y;
+ grab_nswindow = ((GdkWindowImplQuartz *)grab_private->impl)->toplevel;
+ point = [grab_nswindow convertScreenToBase:screen_point];
- /* Translate the coordinates so they are relative to
- * the grab window instead of the event toplevel for
- * the cases where they are not the same.
- */
- get_converted_window_coordinates (event_toplevel,
- x_tmp, y_tmp,
- _gdk_quartz_pointer_grab_window,
- x, y);
+ /* Note: x_root and y_root are already right. */
+ *x = point.x;
+ *y = grab_private->height - point.y;
- return _gdk_quartz_pointer_grab_window;
+ return grab_toplevel;
}
return NULL;
else
{
/* The non-grabbed case. */
+ GdkWindow *toplevel_under_pointer;
+ gint x_tmp, y_tmp;
- /* Leave events above the window (e.g. possibly on the titlebar)
- * to cocoa.
+ /* 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 (*y < 0)
- return NULL;
+ if (event_type != NSMouseMoved)
+ if (*y < 0)
+ return NULL;
/* FIXME: Also need to leave resize events to cocoa somehow? */
+ /* 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)
+ {
+ toplevel = toplevel_under_pointer;
+ *x = x_tmp;
+ *y = y_tmp;
+ }
+
return toplevel;
}
}
case NSMouseEntered:
case NSMouseExited:
- return toplevel;
+ /* Only handle our own entered/exited events, not the ones for the
+ * titlebar buttons.
+ */
+ if ([view trackingRect] == [nsevent trackingNumber])
+ return toplevel;
+ else
+ return NULL;
case NSKeyDown:
case NSKeyUp:
case NSFlagsChanged:
- {
- if (_gdk_quartz_keyboard_grab_window && !keyboard_grab_owner_events)
- return _gdk_quartz_keyboard_grab_window;
+ if (_gdk_display->keyboard_grab.window && !_gdk_display->keyboard_grab.owner_events)
+ return gdk_window_get_toplevel (_gdk_display->keyboard_grab.window);
- return toplevel;
- }
- break;
+ return toplevel;
default:
/* Ignore everything else. */
GdkCrossingMode mode,
GdkNotifyType detail)
{
- GdkWindowObject *private;
- NSPoint point;
-
- private = GDK_WINDOW_OBJECT (toplevel);
-
- point = [nsevent locationInWindow];
-
event->any.type = event_type;
event->crossing.window = toplevel;
event->crossing.subwindow = NULL;
if (event->key.keyval != GDK_VoidSymbol)
c = gdk_keyval_to_unicode (event->key.keyval);
- if (c)
+ if (c)
{
gsize bytes_written;
gint len;
private = GDK_WINDOW_OBJECT (window);
- /* FIXME: had this before csw:
- _gdk_quartz_events_update_mouse_window (window);
- if (window && !_gdk_quartz_pointer_grab_window)
- _gdk_quartz_events_update_cursor (window);
- */
-
switch ([nsevent type])
{
case NSMouseEntered:
- {
- /* Enter events are considered always to be from the root window as
- * we can't know for sure from what window we enter.
- */
- if (!(private->event_mask & GDK_ENTER_NOTIFY_MASK))
- return FALSE;
+ /* Enter events are considered always to be from the root window as we
+ * can't know for sure from what window we enter.
+ */
+ if (!(private->event_mask & GDK_ENTER_NOTIFY_MASK))
+ return FALSE;
- fill_crossing_event (window, event, nsevent,
- x, y,
- x_root, y_root,
- GDK_ENTER_NOTIFY,
- GDK_CROSSING_NORMAL,
- GDK_NOTIFY_ANCESTOR);
- }
+ fill_crossing_event (window, event, nsevent,
+ x, y,
+ x_root, y_root,
+ GDK_ENTER_NOTIFY,
+ GDK_CROSSING_NORMAL,
+ GDK_NOTIFY_ANCESTOR);
return TRUE;
case NSMouseExited:
- {
- /* Exited always is to the root window as far as we are concerned,
- * since there is no way to reliably get information about what new
- * window is entered when exiting one.
- */
- if (!(private->event_mask & GDK_LEAVE_NOTIFY_MASK))
- return FALSE;
+ /* Exited always is to the root window as far as we are concerned,
+ * since there is no way to reliably get information about what new
+ * window is entered when exiting one.
+ */
+ if (!(private->event_mask & GDK_LEAVE_NOTIFY_MASK))
+ return FALSE;
- /*if (!mouse_window ||
- gdk_window_get_toplevel (mouse_window) ==
- gdk_window_get_toplevel (current_mouse_window))
- {
- mouse_window = _gdk_root;
- }
- */
-
- fill_crossing_event (window, event, nsevent,
- x, y,
- x_root, y_root,
- GDK_LEAVE_NOTIFY,
- GDK_CROSSING_NORMAL,
- GDK_NOTIFY_ANCESTOR);
- }
+ fill_crossing_event (window, event, nsevent,
+ x, y,
+ x_root, y_root,
+ GDK_LEAVE_NOTIFY,
+ GDK_CROSSING_NORMAL,
+ GDK_NOTIFY_ANCESTOR);
return TRUE;
default:
return current_event_mask;
}
-#define GDK_ANY_BUTTON_MASK (GDK_BUTTON1_MASK | \
- GDK_BUTTON2_MASK | \
- GDK_BUTTON3_MASK | \
- GDK_BUTTON4_MASK | \
- GDK_BUTTON5_MASK)
-
-static void
-button_event_check_implicit_grab (GdkWindow *window,
- GdkEvent *event,
- NSEvent *nsevent)
-{
- GdkDisplay *display = gdk_drawable_get_display (window);
-
- /* track implicit grabs for button presses */
- switch (event->type)
- {
- case GDK_BUTTON_PRESS:
- if (!display->pointer_grab.window)
- {
- _gdk_display_set_has_pointer_grab (display,
- window,
- window,
- FALSE,
- gdk_window_get_events (window),
- 0, /* serial */
- event->button.time,
- TRUE);
- }
- break;
-
- case GDK_BUTTON_RELEASE:
- if (display->pointer_grab.window &&
- display->pointer_grab.implicit &&
- (current_button_state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
- {
- _gdk_display_unset_has_pointer_grab (display, TRUE, TRUE,
- event->button.time);
- }
- break;
- default:
- g_assert_not_reached ();
- }
-}
-
static gboolean
gdk_event_translate (GdkEvent *event,
NSEvent *nsevent)
if (event_type == NSAppKitDefined)
{
if ([nsevent subtype] == NSApplicationDeactivatedEventType)
- break_all_grabs ();
+ break_all_grabs (get_time_from_ns_event (nsevent));
/* This could potentially be used to break grabs when clicking
* on the title. The subtype 20 is undocumented so it's probably
return FALSE;
}
- /* Handle our generated "fake" crossing events. */
- if (event_type == NSApplicationDefined &&
- [nsevent subtype] == GDK_QUARTZ_EVENT_SUBTYPE_FAKE_CROSSING)
- {
- /* FIXME: This needs to actually fill in the event we have... */
- _gdk_quartz_events_trigger_crossing_events (FALSE);
- return FALSE; /* ...and return TRUE instead. */
- }
-
/* Keep track of button state, since we don't get that information
* for key events.
*/
*/
if ([(GdkQuartzWindow *)nswindow isInMove])
{
- break_all_grabs ();
+ break_all_grabs (get_time_from_ns_event (nsevent));
return FALSE;
}
}
}
- /* We only activate the application on click if it's not already active,
- * or if it's active but the window isn't focused. This matches most use
- * cases of native apps (no click-through).
+ /* If the app is not active leave the event to AppKit so the window gets
+ * focused correctly and don't do click-through (so we behave like most
+ * native apps). If the app is active, we focus the window and then handle
+ * the event, also to match native apps.
*/
if ((event_type == NSRightMouseDown ||
event_type == NSOtherMouseDown ||
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
if (![NSApp isActive])
- return FALSE;
+ {
+ [NSApp activateIgnoringOtherApps:YES];
+ return FALSE;
+ }
else if (![impl->toplevel isKeyWindow])
- return FALSE;
+ {
+ GdkPointerGrabInfo *grab;
+
+ grab = _gdk_display_get_last_pointer_grab (_gdk_display);
+ if (!grab)
+ [impl->toplevel makeKeyWindow];
+ }
}
current_event_mask = get_event_mask_from_ns_event (nsevent);
case NSLeftMouseDown:
case NSRightMouseDown:
case NSOtherMouseDown:
- fill_button_event (window, event, nsevent, x, y, x_root, y_root);
- button_event_check_implicit_grab (window, event, nsevent);
- break;
-
case NSLeftMouseUp:
case NSRightMouseUp:
case NSOtherMouseUp:
fill_button_event (window, event, nsevent, x, y, x_root, y_root);
- button_event_check_implicit_grab (window, event, nsevent);
break;
case NSLeftMouseDragged: