2005-11-22 10:03:32 +00:00
|
|
|
/* gdkevents-quartz.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
* Copyright (C) 1998-2002 Tor Lillqvist
|
2007-06-01 21:03:34 +00:00
|
|
|
* Copyright (C) 2005-2007 Imendio AB
|
2005-11-22 10:03:32 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/sysctl.h>
|
2006-03-27 18:46:38 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <unistd.h>
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-17 20:36:26 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
2006-07-17 18:39:43 +00:00
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
#include "gdkscreen.h"
|
2006-07-17 18:39:43 +00:00
|
|
|
#include "gdkkeysyms.h"
|
2005-11-22 10:03:32 +00:00
|
|
|
#include "gdkprivate-quartz.h"
|
|
|
|
|
|
|
|
/* This is the window the mouse is currently over */
|
2007-06-01 21:46:45 +00:00
|
|
|
static GdkWindow *current_mouse_window;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
/* This is the window corresponding to the key window */
|
2007-06-01 21:46:45 +00:00
|
|
|
static GdkWindow *current_keyboard_window;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
/* This is the pointer grab window */
|
2007-06-01 21:46:45 +00:00
|
|
|
GdkWindow *_gdk_quartz_pointer_grab_window;
|
|
|
|
static gboolean pointer_grab_owner_events;
|
2005-11-22 10:03:32 +00:00
|
|
|
static GdkEventMask pointer_grab_event_mask;
|
2007-06-01 21:46:45 +00:00
|
|
|
static gboolean pointer_grab_implicit;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
/* This is the keyboard grab window */
|
2007-06-01 21:46:45 +00:00
|
|
|
GdkWindow * _gdk_quartz_keyboard_grab_window;
|
|
|
|
static gboolean keyboard_grab_owner_events;
|
|
|
|
|
2007-07-03 20:31:59 +00:00
|
|
|
/* This is the event mask and button state from the last event */
|
|
|
|
static GdkEventMask current_event_mask;
|
|
|
|
static int current_button_state;
|
|
|
|
|
2007-06-01 21:46:45 +00:00
|
|
|
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);
|
2006-07-20 08:06:54 +00:00
|
|
|
|
2007-06-30 19:39:45 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-17 20:36:26 +00:00
|
|
|
/* A category that exposes the protected carbon event for an NSEvent. */
|
|
|
|
@interface NSEvent (GdkQuartzNSEvent)
|
|
|
|
- (void *)gdk_quartz_event_ref;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSEvent (GdkQuartzNSEvent)
|
|
|
|
- (void *)gdk_quartz_event_ref
|
|
|
|
{
|
|
|
|
return _eventRef;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
void
|
|
|
|
_gdk_events_init (void)
|
|
|
|
{
|
2006-12-28 09:04:48 +00:00
|
|
|
_gdk_quartz_event_loop_init ();
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
current_mouse_window = g_object_ref (_gdk_root);
|
|
|
|
current_keyboard_window = g_object_ref (_gdk_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_events_pending (void)
|
|
|
|
{
|
2006-05-15 19:01:57 +00:00
|
|
|
return (_gdk_event_queue_find_first (_gdk_display) ||
|
2006-12-28 09:04:48 +00:00
|
|
|
(_gdk_quartz_event_loop_get_current () != NULL));
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkEvent*
|
|
|
|
gdk_event_get_graphics_expose (GdkWindow *window)
|
|
|
|
{
|
|
|
|
/* FIXME: Implement */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-07 20:19:22 +00:00
|
|
|
static void
|
|
|
|
generate_grab_broken_event (GdkWindow *window,
|
|
|
|
gboolean keyboard,
|
|
|
|
gboolean implicit,
|
|
|
|
GdkWindow *grab_window)
|
|
|
|
{
|
|
|
|
if (!GDK_WINDOW_DESTROYED (window))
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
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 = implicit;
|
|
|
|
event->grab_broken.grab_window = grab_window;
|
2006-07-07 20:19:22 +00:00
|
|
|
|
2006-07-20 08:06:54 +00:00
|
|
|
append_event (event);
|
2006-07-07 20:19:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
GdkGrabStatus
|
|
|
|
gdk_keyboard_grab (GdkWindow *window,
|
|
|
|
gint owner_events,
|
|
|
|
guint32 time)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (window != NULL, 0);
|
|
|
|
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
|
|
|
|
|
|
|
|
if (_gdk_quartz_keyboard_grab_window)
|
2006-07-07 20:19:22 +00:00
|
|
|
{
|
2006-07-24 10:46:21 +00:00
|
|
|
if (_gdk_quartz_keyboard_grab_window != window)
|
|
|
|
generate_grab_broken_event (_gdk_quartz_keyboard_grab_window,
|
|
|
|
TRUE, FALSE, window);
|
|
|
|
|
2006-07-07 20:19:22 +00:00
|
|
|
g_object_unref (_gdk_quartz_keyboard_grab_window);
|
|
|
|
}
|
2006-01-16 10:52:40 +00:00
|
|
|
|
|
|
|
_gdk_quartz_keyboard_grab_window = g_object_ref (window);
|
|
|
|
keyboard_grab_owner_events = owner_events;
|
|
|
|
|
|
|
|
return GDK_GRAB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_keyboard_grab_info_libgtk_only (GdkDisplay *display,
|
|
|
|
GdkWindow **grab_window,
|
|
|
|
gboolean *owner_events)
|
|
|
|
{
|
|
|
|
if (_gdk_quartz_keyboard_grab_window)
|
|
|
|
{
|
|
|
|
if (grab_window)
|
|
|
|
*grab_window = _gdk_quartz_keyboard_grab_window;
|
|
|
|
if (owner_events)
|
|
|
|
*owner_events = keyboard_grab_owner_events;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
static void
|
2006-07-24 10:46:21 +00:00
|
|
|
pointer_ungrab_internal (gboolean only_if_implicit)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2006-01-16 10:52:40 +00:00
|
|
|
if (!_gdk_quartz_pointer_grab_window)
|
2005-11-22 10:03:32 +00:00
|
|
|
return;
|
|
|
|
|
2006-07-24 10:46:21 +00:00
|
|
|
if (only_if_implicit && !pointer_grab_implicit)
|
2005-11-22 10:03:32 +00:00
|
|
|
return;
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
g_object_unref (_gdk_quartz_pointer_grab_window);
|
|
|
|
_gdk_quartz_pointer_grab_window = NULL;
|
2006-07-24 10:46:21 +00:00
|
|
|
|
2007-05-28 20:51:11 +00:00
|
|
|
pointer_grab_owner_events = FALSE;
|
|
|
|
pointer_grab_event_mask = 0;
|
|
|
|
pointer_grab_implicit = FALSE;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
/* FIXME: Send crossing events */
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_display_pointer_is_grabbed (GdkDisplay *display)
|
|
|
|
{
|
2007-06-03 18:48:47 +00:00
|
|
|
return (_gdk_quartz_pointer_grab_window != NULL &&
|
|
|
|
!pointer_grab_implicit);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_pointer_grab_info_libgtk_only (GdkDisplay *display,
|
|
|
|
GdkWindow **grab_window,
|
|
|
|
gboolean *owner_events)
|
|
|
|
{
|
2006-01-16 10:52:40 +00:00
|
|
|
if (!_gdk_quartz_pointer_grab_window)
|
2005-11-22 10:03:32 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (grab_window)
|
2006-01-16 10:52:40 +00:00
|
|
|
*grab_window = _gdk_quartz_pointer_grab_window;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
if (owner_events)
|
|
|
|
*owner_events = pointer_grab_owner_events;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_display_pointer_ungrab (GdkDisplay *display,
|
|
|
|
guint32 time)
|
|
|
|
{
|
|
|
|
pointer_ungrab_internal (FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkGrabStatus
|
|
|
|
pointer_grab_internal (GdkWindow *window,
|
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
GdkWindow *confine_to,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
gboolean implicit)
|
|
|
|
{
|
|
|
|
/* FIXME: Send crossing events */
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
_gdk_quartz_pointer_grab_window = g_object_ref (window);
|
2005-11-22 10:03:32 +00:00
|
|
|
pointer_grab_owner_events = owner_events;
|
|
|
|
pointer_grab_event_mask = event_mask;
|
|
|
|
pointer_grab_implicit = implicit;
|
|
|
|
|
|
|
|
return GDK_GRAB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkGrabStatus
|
|
|
|
gdk_pointer_grab (GdkWindow *window,
|
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
GdkWindow *confine_to,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint32 time)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
|
|
|
|
g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-03 18:48:47 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window != window)
|
|
|
|
generate_grab_broken_event (_gdk_quartz_pointer_grab_window,
|
|
|
|
FALSE, pointer_grab_implicit, window);
|
|
|
|
|
|
|
|
pointer_ungrab_internal (FALSE);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_grab_internal (window, owner_events, event_mask,
|
|
|
|
confine_to, cursor, FALSE);
|
|
|
|
}
|
|
|
|
|
2007-06-16 15:43:23 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
if (_gdk_quartz_keyboard_grab_window)
|
|
|
|
{
|
|
|
|
generate_grab_broken_event (_gdk_quartz_keyboard_grab_window,
|
|
|
|
TRUE, FALSE,
|
|
|
|
NULL);
|
|
|
|
g_object_unref (_gdk_quartz_keyboard_grab_window);
|
|
|
|
_gdk_quartz_keyboard_grab_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_gdk_quartz_pointer_grab_window)
|
|
|
|
{
|
|
|
|
generate_grab_broken_event (_gdk_quartz_pointer_grab_window,
|
|
|
|
FALSE, pointer_grab_implicit,
|
|
|
|
NULL);
|
|
|
|
pointer_ungrab_internal (FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
static void
|
|
|
|
fixup_event (GdkEvent *event)
|
|
|
|
{
|
|
|
|
if (event->any.window)
|
|
|
|
g_object_ref (event->any.window);
|
|
|
|
if (((event->any.type == GDK_ENTER_NOTIFY) ||
|
|
|
|
(event->any.type == GDK_LEAVE_NOTIFY)) &&
|
|
|
|
(event->crossing.subwindow != NULL))
|
|
|
|
g_object_ref (event->crossing.subwindow);
|
|
|
|
event->any.send_event = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
append_event (GdkEvent *event)
|
|
|
|
{
|
|
|
|
fixup_event (event);
|
|
|
|
_gdk_event_queue_append (_gdk_display, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkFilterReturn
|
|
|
|
apply_filters (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GList *filters)
|
|
|
|
{
|
|
|
|
GdkFilterReturn result = GDK_FILTER_CONTINUE;
|
|
|
|
GdkEvent *event;
|
|
|
|
GList *node;
|
|
|
|
GList *tmp_list;
|
|
|
|
|
|
|
|
event = gdk_event_new (GDK_NOTHING);
|
|
|
|
if (window != NULL)
|
|
|
|
event->any.window = g_object_ref (window);
|
|
|
|
((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
|
|
|
|
|
|
|
|
/* I think GdkFilterFunc semantics require the passed-in event
|
|
|
|
* to already be in the queue. The filter func can generate
|
|
|
|
* more events and append them after it if it likes.
|
|
|
|
*/
|
|
|
|
node = _gdk_event_queue_append (_gdk_display, event);
|
|
|
|
|
|
|
|
tmp_list = filters;
|
|
|
|
while (tmp_list)
|
|
|
|
{
|
|
|
|
GdkEventFilter *filter = (GdkEventFilter *) tmp_list->data;
|
|
|
|
|
|
|
|
tmp_list = tmp_list->next;
|
|
|
|
result = filter->function (nsevent, event, filter->data);
|
|
|
|
if (result != GDK_FILTER_CONTINUE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == GDK_FILTER_CONTINUE || result == GDK_FILTER_REMOVE)
|
|
|
|
{
|
|
|
|
_gdk_event_queue_remove_link (_gdk_display, node);
|
|
|
|
g_list_free_1 (node);
|
|
|
|
gdk_event_free (event);
|
|
|
|
}
|
|
|
|
else /* GDK_FILTER_TRANSLATE */
|
|
|
|
{
|
|
|
|
((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
|
|
|
|
fixup_event (event);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-05-28 20:24:59 +00:00
|
|
|
/* 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.
|
2005-11-22 10:03:32 +00:00
|
|
|
*/
|
|
|
|
static GdkWindow *
|
2007-05-28 20:24:59 +00:00
|
|
|
find_window_interested_in_event_mask (GdkWindow *window,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
gboolean propagate)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-05-28 20:24:59 +00:00
|
|
|
GdkWindowObject *private;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-05-28 20:24:59 +00:00
|
|
|
private = GDK_WINDOW_OBJECT (window);
|
|
|
|
while (private)
|
|
|
|
{
|
2005-11-22 10:03:32 +00:00
|
|
|
if (private->event_mask & event_mask)
|
2007-05-28 20:24:59 +00:00
|
|
|
return (GdkWindow *)private;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
if (!propagate)
|
|
|
|
return NULL;
|
2007-05-28 20:24:59 +00:00
|
|
|
|
|
|
|
/* Don't traverse beyond toplevels. */
|
|
|
|
if (GDK_WINDOW_TYPE (private) != GDK_WINDOW_CHILD)
|
|
|
|
break;
|
|
|
|
|
|
|
|
private = private->parent;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint32
|
2007-06-01 21:03:34 +00:00
|
|
|
get_time_from_ns_event (NSEvent *event)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
double time = [event timestamp];
|
|
|
|
|
|
|
|
return time * 1000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-06-01 21:03:34 +00:00
|
|
|
get_mouse_button_from_ns_event (NSEvent *event)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-01 21:03:34 +00:00
|
|
|
int button;
|
|
|
|
|
|
|
|
button = [event buttonNumber];
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return 1;
|
|
|
|
case 1:
|
|
|
|
return 3;
|
|
|
|
case 2:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return button + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-03 20:31:59 +00:00
|
|
|
static GdkModifierType
|
|
|
|
get_mouse_button_modifiers_from_ns_event (NSEvent *event)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
GdkModifierType state = 0;
|
|
|
|
|
|
|
|
/* This maps buttons 1 to 5 to GDK_BUTTON[1-5]_MASK */
|
|
|
|
button = get_mouse_button_from_ns_event (event);
|
|
|
|
if (button >= 1 && button <= 5)
|
|
|
|
state = (1 << (button + 7));
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2007-06-01 21:03:34 +00:00
|
|
|
static GdkModifierType
|
|
|
|
get_keyboard_modifiers_from_ns_event (NSEvent *nsevent)
|
|
|
|
{
|
|
|
|
GdkModifierType modifiers = 0;
|
|
|
|
int nsflags;
|
|
|
|
|
|
|
|
nsflags = [nsevent modifierFlags];
|
|
|
|
|
|
|
|
if (nsflags & NSAlphaShiftKeyMask)
|
|
|
|
modifiers |= GDK_LOCK_MASK;
|
|
|
|
if (nsflags & NSShiftKeyMask)
|
|
|
|
modifiers |= GDK_SHIFT_MASK;
|
|
|
|
if (nsflags & NSControlKeyMask)
|
|
|
|
modifiers |= GDK_CONTROL_MASK;
|
|
|
|
if (nsflags & NSCommandKeyMask)
|
|
|
|
modifiers |= GDK_MOD1_MASK;
|
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
/* Return an event mask from an NSEvent */
|
|
|
|
static GdkEventMask
|
|
|
|
get_event_mask_from_ns_event (NSEvent *nsevent)
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
switch ([nsevent type])
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
return GDK_BUTTON_PRESS_MASK;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
return GDK_BUTTON_RELEASE_MASK;
|
|
|
|
case NSMouseMoved:
|
2006-07-20 08:06:54 +00:00
|
|
|
return GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK;
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSScrollWheel:
|
|
|
|
/* Since applications that want button press events can get
|
|
|
|
* scroll events on X11 (since scroll wheel events are really
|
|
|
|
* button press events there), we need to use GDK_BUTTON_PRESS_MASK too.
|
|
|
|
*/
|
2006-07-20 08:06:54 +00:00
|
|
|
return GDK_SCROLL_MASK | GDK_BUTTON_PRESS_MASK;
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSLeftMouseDragged:
|
2006-08-15 20:13:13 +00:00
|
|
|
return (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON1_MASK);
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSRightMouseDragged:
|
2006-08-15 20:13:13 +00:00
|
|
|
return (GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK | GDK_BUTTON3_MOTION_MASK |
|
|
|
|
GDK_BUTTON3_MASK);
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSOtherMouseDragged:
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
GdkEventMask mask;
|
|
|
|
|
|
|
|
mask = (GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_POINTER_MOTION_HINT_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK);
|
|
|
|
|
2007-06-01 21:03:34 +00:00
|
|
|
if (get_mouse_button_from_ns_event (nsevent) == 2)
|
2006-08-15 20:13:13 +00:00
|
|
|
mask |= (GDK_BUTTON2_MOTION_MASK | GDK_BUTTON2_MOTION_MASK |
|
|
|
|
GDK_BUTTON2_MASK);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
case NSKeyDown:
|
|
|
|
case NSKeyUp:
|
2006-07-07 20:19:22 +00:00
|
|
|
case NSFlagsChanged:
|
|
|
|
{
|
2007-04-06 21:12:48 +00:00
|
|
|
switch (_gdk_quartz_keys_event_type (nsevent))
|
2006-07-20 08:06:54 +00:00
|
|
|
{
|
|
|
|
case GDK_KEY_PRESS:
|
|
|
|
return GDK_KEY_PRESS_MASK;
|
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
return GDK_KEY_RELEASE_MASK;
|
|
|
|
case GDK_NOTHING:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
2006-07-07 20:19:22 +00:00
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEvent *
|
|
|
|
create_focus_event (GdkWindow *window,
|
|
|
|
gboolean in)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
|
|
|
|
event = gdk_event_new (GDK_FOCUS_CHANGE);
|
|
|
|
event->focus_change.window = window;
|
|
|
|
event->focus_change.in = in;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2006-07-19 17:06:40 +00:00
|
|
|
/* Note: Used to both set a new focus window and to unset the old one. */
|
2005-11-22 10:03:32 +00:00
|
|
|
void
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_update_focus_window (GdkWindow *window,
|
|
|
|
gboolean got_focus)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2006-07-19 17:06:40 +00:00
|
|
|
GdkEvent *event;
|
|
|
|
|
|
|
|
if (got_focus && window == current_keyboard_window)
|
|
|
|
return;
|
|
|
|
|
2006-07-24 10:46:21 +00:00
|
|
|
/* FIXME: Don't do this when grabbed? Or make GdkQuartzWindow
|
|
|
|
* disallow it in the first place instead?
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!got_focus && window == current_keyboard_window)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-06 08:29:20 +00:00
|
|
|
event = create_focus_event (current_keyboard_window, FALSE);
|
|
|
|
append_event (event);
|
|
|
|
g_object_unref (current_keyboard_window);
|
|
|
|
current_keyboard_window = NULL;
|
2006-07-19 17:06:40 +00:00
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2006-07-19 17:06:40 +00:00
|
|
|
if (got_focus)
|
|
|
|
{
|
|
|
|
if (current_keyboard_window)
|
|
|
|
{
|
|
|
|
event = create_focus_event (current_keyboard_window, FALSE);
|
|
|
|
append_event (event);
|
|
|
|
g_object_unref (current_keyboard_window);
|
|
|
|
current_keyboard_window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
event = create_focus_event (window, TRUE);
|
2005-11-22 10:03:32 +00:00
|
|
|
append_event (event);
|
2006-07-19 17:06:40 +00:00
|
|
|
current_keyboard_window = g_object_ref (window);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-07-20 08:06:54 +00:00
|
|
|
convert_window_coordinates_to_root (GdkWindow *window,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble *x_root,
|
|
|
|
gdouble *y_root)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2006-07-17 08:07:55 +00:00
|
|
|
gint ox, oy;
|
|
|
|
|
|
|
|
*x_root = x;
|
|
|
|
*y_root = y;
|
|
|
|
|
|
|
|
if (gdk_window_get_origin (window, &ox, &oy))
|
|
|
|
{
|
|
|
|
*x_root += ox;
|
|
|
|
*y_root += oy;
|
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-06-01 21:46:45 +00:00
|
|
|
/* FIXME: Refactor and share with scroll event. */
|
2005-11-22 10:03:32 +00:00
|
|
|
static GdkEvent *
|
|
|
|
create_crossing_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkEventType event_type,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
2007-06-01 21:46:45 +00:00
|
|
|
gint x_tmp, y_tmp;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
event = gdk_event_new (event_type);
|
2007-06-01 21:46:45 +00:00
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event->crossing.window = window;
|
|
|
|
event->crossing.subwindow = NULL; /* FIXME */
|
2007-06-01 21:03:34 +00:00
|
|
|
event->crossing.time = get_time_from_ns_event (nsevent);
|
2006-07-17 08:07:55 +00:00
|
|
|
|
2007-06-01 21:46:45 +00:00
|
|
|
/* Split out this block: */
|
|
|
|
{
|
|
|
|
NSWindow *nswindow;
|
|
|
|
GdkWindow *toplevel;
|
2007-06-30 19:50:31 +00:00
|
|
|
GdkWindowImplQuartz *impl;
|
2007-06-01 21:46:45 +00:00
|
|
|
NSPoint point;
|
|
|
|
|
|
|
|
nswindow = [nsevent window];
|
|
|
|
point = [nsevent locationInWindow];
|
|
|
|
|
|
|
|
toplevel = [(GdkQuartzView *)[nswindow contentView] gdkWindow];
|
2007-06-30 19:50:31 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (toplevel)->impl);
|
2007-06-01 21:46:45 +00:00
|
|
|
|
|
|
|
x_tmp = point.x;
|
2007-06-30 19:50:31 +00:00
|
|
|
y_tmp = impl->height - point.y;
|
2007-06-01 21:46:45 +00:00
|
|
|
|
|
|
|
get_converted_window_coordinates (toplevel,
|
|
|
|
x_tmp, y_tmp,
|
|
|
|
window,
|
|
|
|
&x_tmp, &y_tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
event->crossing.x = x_tmp;
|
|
|
|
event->crossing.y = y_tmp;
|
|
|
|
|
|
|
|
convert_window_coordinates_to_root (window,
|
|
|
|
event->crossing.x,
|
|
|
|
event->crossing.y,
|
2006-07-17 08:07:55 +00:00
|
|
|
&event->crossing.x_root,
|
|
|
|
&event->crossing.y_root);
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event->crossing.mode = mode;
|
|
|
|
event->crossing.detail = detail;
|
2007-06-03 18:51:16 +00:00
|
|
|
event->crossing.state = get_keyboard_modifiers_from_ns_event (nsevent);
|
|
|
|
|
|
|
|
/* FIXME: focus and button state */
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
synthesize_enter_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
|
2006-04-13 08:51:33 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window != NULL &&
|
|
|
|
!pointer_grab_owner_events &&
|
|
|
|
!(pointer_grab_event_mask & GDK_ENTER_NOTIFY_MASK))
|
|
|
|
return;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
if (!(GDK_WINDOW_OBJECT (window)->event_mask & GDK_ENTER_NOTIFY_MASK))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event = create_crossing_event (window, nsevent, GDK_ENTER_NOTIFY,
|
|
|
|
mode, detail);
|
|
|
|
|
|
|
|
append_event (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
synthesize_enter_events (GdkWindow *from,
|
|
|
|
GdkWindow *to,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
GdkWindow *prev = gdk_window_get_parent (to);
|
|
|
|
|
|
|
|
if (prev != from)
|
|
|
|
synthesize_enter_events (from, prev, nsevent, mode, detail);
|
|
|
|
synthesize_enter_event (to, nsevent, mode, detail);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
synthesize_leave_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
|
2006-04-13 08:51:33 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window != NULL &&
|
|
|
|
!pointer_grab_owner_events &&
|
|
|
|
!(pointer_grab_event_mask & GDK_LEAVE_NOTIFY_MASK))
|
|
|
|
return;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
if (!(GDK_WINDOW_OBJECT (window)->event_mask & GDK_LEAVE_NOTIFY_MASK))
|
|
|
|
return;
|
|
|
|
|
|
|
|
event = create_crossing_event (window, nsevent, GDK_LEAVE_NOTIFY,
|
|
|
|
mode, detail);
|
|
|
|
|
|
|
|
append_event (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
synthesize_leave_events (GdkWindow *from,
|
|
|
|
GdkWindow *to,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
GdkNotifyType detail)
|
|
|
|
{
|
|
|
|
GdkWindow *next = gdk_window_get_parent (from);
|
|
|
|
|
|
|
|
synthesize_leave_event (from, nsevent, mode, detail);
|
|
|
|
if (next != to)
|
|
|
|
synthesize_leave_events (next, to, nsevent, mode, detail);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
synthesize_crossing_events (GdkWindow *window,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
|
|
|
{
|
|
|
|
GdkWindow *intermediate, *tem, *common_ancestor;
|
|
|
|
|
2007-06-30 21:50:06 +00:00
|
|
|
if (window == current_mouse_window)
|
|
|
|
return;
|
|
|
|
|
2007-07-13 19:09:10 +00:00
|
|
|
if (_gdk_quartz_window_is_ancestor (current_mouse_window, window))
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
/* Pointer has moved to an inferior window. */
|
|
|
|
synthesize_leave_event (current_mouse_window, nsevent, mode, GDK_NOTIFY_INFERIOR);
|
|
|
|
|
|
|
|
/* If there are intermediate windows, generate ENTER_NOTIFY
|
|
|
|
* events for them
|
|
|
|
*/
|
|
|
|
intermediate = gdk_window_get_parent (window);
|
|
|
|
|
|
|
|
if (intermediate != current_mouse_window)
|
|
|
|
{
|
|
|
|
synthesize_enter_events (current_mouse_window, intermediate, nsevent, mode, GDK_NOTIFY_VIRTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
synthesize_enter_event (window, nsevent, mode, GDK_NOTIFY_ANCESTOR);
|
|
|
|
}
|
2007-07-13 19:09:10 +00:00
|
|
|
else if (_gdk_quartz_window_is_ancestor (window, current_mouse_window))
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
/* Pointer has moved to an ancestor window. */
|
|
|
|
synthesize_leave_event (current_mouse_window, nsevent, mode, GDK_NOTIFY_ANCESTOR);
|
|
|
|
|
|
|
|
/* If there are intermediate windows, generate LEAVE_NOTIFY
|
|
|
|
* events for them
|
|
|
|
*/
|
|
|
|
intermediate = gdk_window_get_parent (current_mouse_window);
|
|
|
|
if (intermediate != window)
|
|
|
|
{
|
|
|
|
synthesize_leave_events (intermediate, window, nsevent, mode, GDK_NOTIFY_VIRTUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
synthesize_enter_event (window, nsevent, mode, GDK_NOTIFY_INFERIOR);
|
|
|
|
}
|
|
|
|
else if (current_mouse_window)
|
|
|
|
{
|
|
|
|
/* Find least common ancestor of current_mouse_window and window */
|
|
|
|
tem = current_mouse_window;
|
|
|
|
do {
|
|
|
|
common_ancestor = gdk_window_get_parent (tem);
|
|
|
|
tem = common_ancestor;
|
|
|
|
} while (common_ancestor &&
|
2007-07-13 19:09:10 +00:00
|
|
|
!_gdk_quartz_window_is_ancestor (common_ancestor, window));
|
2005-11-22 10:03:32 +00:00
|
|
|
if (common_ancestor)
|
|
|
|
{
|
|
|
|
synthesize_leave_event (current_mouse_window, nsevent, mode, GDK_NOTIFY_NONLINEAR);
|
|
|
|
intermediate = gdk_window_get_parent (current_mouse_window);
|
|
|
|
if (intermediate != common_ancestor)
|
|
|
|
{
|
|
|
|
synthesize_leave_events (intermediate, common_ancestor,
|
|
|
|
nsevent, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
|
|
|
|
}
|
|
|
|
intermediate = gdk_window_get_parent (window);
|
|
|
|
if (intermediate != common_ancestor)
|
|
|
|
{
|
|
|
|
synthesize_enter_events (common_ancestor, intermediate,
|
|
|
|
nsevent, mode, GDK_NOTIFY_NONLINEAR_VIRTUAL);
|
|
|
|
}
|
|
|
|
synthesize_enter_event (window, nsevent, mode, GDK_NOTIFY_NONLINEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-06 08:29:20 +00:00
|
|
|
/* This means we have no current_mouse_window, which probably
|
|
|
|
* means that there is a bug somewhere, we should always have
|
|
|
|
* the root in we don't have another window. Does this ever
|
|
|
|
* happen?
|
2006-08-08 21:06:03 +00:00
|
|
|
*/
|
2007-06-06 08:29:20 +00:00
|
|
|
g_warning ("Trying to create crossing event when current_mouse_window is NULL");
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
2007-06-30 19:50:31 +00:00
|
|
|
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_update_mouse_window (window);
|
2007-06-17 18:41:36 +00:00
|
|
|
|
|
|
|
/* FIXME: This does't work when someone calls gdk_window_set_cursor
|
|
|
|
* during a grab. The right behavior is that the cursor doesn't
|
|
|
|
* change when a grab is in effect, but in that case it does.
|
|
|
|
*/
|
|
|
|
if (window && !_gdk_quartz_pointer_grab_window)
|
|
|
|
_gdk_quartz_events_update_cursor (window);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
void
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_send_map_events (GdkWindow *window)
|
2006-01-16 10:52:40 +00:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GdkWindow *interested_window;
|
|
|
|
GdkWindowObject *private = (GdkWindowObject *)window;
|
|
|
|
|
|
|
|
interested_window = find_window_interested_in_event_mask (window,
|
|
|
|
GDK_STRUCTURE_MASK,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
if (interested_window)
|
|
|
|
{
|
|
|
|
GdkEvent *event = gdk_event_new (GDK_MAP);
|
|
|
|
event->any.window = interested_window;
|
|
|
|
append_event (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = private->children; list != NULL; list = list->next)
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_send_map_events ((GdkWindow *)list->data);
|
2006-01-16 10:52:40 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
/* Get current mouse window */
|
|
|
|
GdkWindow *
|
2007-07-13 19:09:10 +00:00
|
|
|
_gdk_quartz_events_get_mouse_window (gboolean consider_grabs)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-07-13 19:09:10 +00:00
|
|
|
if (!consider_grabs)
|
|
|
|
return current_mouse_window;
|
|
|
|
|
2006-07-24 10:46:21 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window && !pointer_grab_owner_events)
|
2006-07-20 08:06:54 +00:00
|
|
|
return _gdk_quartz_pointer_grab_window;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
return current_mouse_window;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update mouse window */
|
|
|
|
void
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_update_mouse_window (GdkWindow *window)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-06 09:06:59 +00:00
|
|
|
if (window == current_mouse_window)
|
|
|
|
return;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
if (window)
|
|
|
|
g_object_ref (window);
|
|
|
|
if (current_mouse_window)
|
|
|
|
g_object_unref (current_mouse_window);
|
|
|
|
|
|
|
|
current_mouse_window = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update current cursor */
|
|
|
|
void
|
2007-04-06 21:12:48 +00:00
|
|
|
_gdk_quartz_events_update_cursor (GdkWindow *window)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkWindowObject *private = GDK_WINDOW_OBJECT (window);
|
|
|
|
NSCursor *nscursor = nil;
|
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
while (private)
|
|
|
|
{
|
|
|
|
GdkWindowImplQuartz *impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
nscursor = impl->nscursor;
|
|
|
|
if (nscursor)
|
|
|
|
break;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
private = private->parent;
|
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-07-14 12:14:36 +00:00
|
|
|
GDK_QUARTZ_ALLOC_POOL;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
if (!nscursor)
|
|
|
|
nscursor = [NSCursor arrowCursor];
|
|
|
|
|
|
|
|
if ([NSCursor currentCursor] != nscursor)
|
|
|
|
[nscursor set];
|
2007-07-14 12:14:36 +00:00
|
|
|
|
|
|
|
GDK_QUARTZ_RELEASE_POOL;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:11:55 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2007-06-01 21:46:45 +00:00
|
|
|
/* 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;
|
|
|
|
|
2007-06-06 16:23:50 +00:00
|
|
|
if (in_window == out_window)
|
|
|
|
{
|
|
|
|
*out_x = in_x;
|
|
|
|
*out_y = in_y;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-06-01 21:46:45 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
2007-06-06 18:42:07 +00:00
|
|
|
/* 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,
|
2007-06-30 21:50:06 +00:00
|
|
|
* returns the root window, and root window coordinates.
|
2007-06-30 19:39:45 +00:00
|
|
|
*/
|
2005-11-22 10:03:32 +00:00
|
|
|
static GdkWindow *
|
2007-06-06 18:42:07 +00:00
|
|
|
find_mouse_window_for_ns_event (NSEvent *nsevent,
|
2007-06-01 21:03:34 +00:00
|
|
|
gint *x_ret,
|
|
|
|
gint *y_ret)
|
2007-05-28 21:11:55 +00:00
|
|
|
{
|
2007-06-06 18:42:07 +00:00
|
|
|
GdkWindow *event_toplevel;
|
2007-06-30 19:50:31 +00:00
|
|
|
GdkWindowImplQuartz *impl;
|
2007-06-06 18:42:07 +00:00
|
|
|
GdkWindow *mouse_toplevel;
|
|
|
|
GdkWindow *mouse_window;
|
2007-05-28 21:11:55 +00:00
|
|
|
NSPoint point;
|
|
|
|
gint x_tmp, y_tmp;
|
|
|
|
|
2007-06-06 18:42:07 +00:00
|
|
|
event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
|
2007-06-30 19:50:31 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (event_toplevel)->impl);
|
2007-05-28 21:11:55 +00:00
|
|
|
point = [nsevent locationInWindow];
|
|
|
|
|
|
|
|
x_tmp = point.x;
|
2007-06-30 19:50:31 +00:00
|
|
|
y_tmp = impl->height - point.y;
|
2007-05-28 21:11:55 +00:00
|
|
|
|
2007-06-06 18:42:07 +00:00
|
|
|
mouse_toplevel = gdk_window_get_toplevel (current_mouse_window);
|
2007-05-28 21:11:55 +00:00
|
|
|
|
2007-06-06 18:42:07 +00:00
|
|
|
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);
|
2007-06-30 21:50:06 +00:00
|
|
|
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)
|
2007-06-06 18:42:07 +00:00
|
|
|
{
|
2007-06-30 21:50:06 +00:00
|
|
|
/* This happens for events on the window title buttons and the
|
|
|
|
* desktop, treat those as being on the root window.
|
2007-06-06 18:42:07 +00:00
|
|
|
*/
|
2007-06-30 21:50:06 +00:00
|
|
|
get_converted_window_coordinates (mouse_toplevel,
|
|
|
|
x_tmp, y_tmp,
|
|
|
|
_gdk_root,
|
|
|
|
&x_tmp, &y_tmp);
|
|
|
|
mouse_window = _gdk_root;
|
2007-06-06 18:42:07 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:11:55 +00:00
|
|
|
*x_ret = x_tmp;
|
|
|
|
*y_ret = y_tmp;
|
|
|
|
|
2007-06-06 18:42:07 +00:00
|
|
|
return mouse_window;
|
2007-05-28 21:11:55 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
/* Synthesizes crossing events if necessary, based on the passed in
|
|
|
|
* NSEvent. Uses NSMouseEntered and NSMouseExisted for toplevels and
|
|
|
|
* the mouse moved/dragged events for child windows, to see if the
|
|
|
|
* mouse window has changed.
|
2007-05-28 21:11:55 +00:00
|
|
|
*/
|
2007-06-17 18:41:36 +00:00
|
|
|
static void
|
|
|
|
synthesize_crossing_events_for_ns_event (NSEvent *nsevent)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-16 16:16:43 +00:00
|
|
|
NSEventType event_type;
|
2007-06-17 18:41:36 +00:00
|
|
|
GdkWindow *mouse_window;
|
|
|
|
gint x;
|
|
|
|
gint y;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-16 16:16:43 +00:00
|
|
|
event_type = [nsevent type];
|
2007-05-28 21:11:55 +00:00
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
switch (event_type)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-17 18:41:36 +00:00
|
|
|
case NSMouseMoved:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
2007-06-30 19:39:45 +00:00
|
|
|
/* We only handle moving the pointer to another GDK window.
|
|
|
|
* Leaving to a non-GDK toplevel window (or window title bar or
|
|
|
|
* the desktop) is covered by NSMouseExited events.
|
2007-06-06 18:42:07 +00:00
|
|
|
*/
|
2007-06-30 19:39:45 +00:00
|
|
|
mouse_window = find_mouse_window_for_ns_event (nsevent, &x, &y);
|
2007-06-30 21:50:06 +00:00
|
|
|
if (mouse_window != _gdk_root)
|
2007-06-17 18:41:36 +00:00
|
|
|
synthesize_crossing_events (mouse_window, GDK_CROSSING_NORMAL, nsevent, x, y);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSMouseEntered:
|
|
|
|
{
|
|
|
|
GdkWindow *event_toplevel;
|
2007-06-30 19:50:31 +00:00
|
|
|
GdkWindowImplQuartz *impl;
|
2007-06-17 18:41:36 +00:00
|
|
|
NSPoint point;
|
|
|
|
|
2007-06-30 19:39:45 +00:00
|
|
|
/* This is the only case where we actually use the window from
|
|
|
|
* the event since we need to know which toplevel we entered
|
|
|
|
* so it can be tracked properly.
|
|
|
|
*/
|
2007-06-17 18:41:36 +00:00
|
|
|
event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
|
2007-06-30 19:50:31 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (event_toplevel)->impl);
|
2007-06-30 21:50:06 +00:00
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
point = [nsevent locationInWindow];
|
|
|
|
|
|
|
|
x = point.x;
|
2007-06-30 19:50:31 +00:00
|
|
|
y = impl->height - point.y;
|
2007-06-17 18:41:36 +00:00
|
|
|
|
|
|
|
mouse_window = _gdk_quartz_window_find_child (event_toplevel, x, y);
|
|
|
|
|
2007-06-30 19:39:45 +00:00
|
|
|
/* Treat unknown windows (like the title bar buttons or
|
|
|
|
* desktop) as the root window.
|
2007-06-17 18:41:36 +00:00
|
|
|
*/
|
2007-06-30 19:39:45 +00:00
|
|
|
if (!mouse_window)
|
2007-06-17 18:41:36 +00:00
|
|
|
mouse_window = _gdk_root;
|
|
|
|
|
|
|
|
if (mouse_window != event_toplevel)
|
|
|
|
get_converted_window_coordinates (event_toplevel,
|
|
|
|
x, y,
|
|
|
|
mouse_window,
|
|
|
|
&x, &y);
|
|
|
|
|
2007-06-30 19:55:20 +00:00
|
|
|
synthesize_crossing_events (mouse_window, GDK_CROSSING_NORMAL, nsevent, x, y);
|
2007-06-17 18:41:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSMouseExited:
|
|
|
|
{
|
|
|
|
GdkWindow *event_toplevel;
|
2007-06-30 19:50:31 +00:00
|
|
|
GdkWindowImplQuartz *impl;
|
2007-06-17 18:41:36 +00:00
|
|
|
NSPoint point;
|
|
|
|
|
2007-06-30 19:39:45 +00:00
|
|
|
/* We only use NSMouseExited when leaving to the root
|
|
|
|
* window. The other cases are handled above by checking the
|
|
|
|
* motion/button events, or getting a NSMouseEntered for
|
|
|
|
* another GDK window. The reason we don't use NSMouseExited
|
|
|
|
* for other windows is that quartz first delivers the entered
|
|
|
|
* event and then the exited which is the opposite from what
|
|
|
|
* we need.
|
2007-06-17 18:41:36 +00:00
|
|
|
*/
|
|
|
|
event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
|
2007-06-30 19:50:31 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (event_toplevel)->impl);
|
2007-06-17 18:41:36 +00:00
|
|
|
point = [nsevent locationInWindow];
|
|
|
|
|
|
|
|
x = point.x;
|
2007-06-30 19:50:31 +00:00
|
|
|
y = impl->height - point.y;
|
2007-06-17 18:41:36 +00:00
|
|
|
|
2007-06-30 19:55:20 +00:00
|
|
|
x += GDK_WINDOW_OBJECT (event_toplevel)->x;
|
|
|
|
y += GDK_WINDOW_OBJECT (event_toplevel)->y;
|
2007-06-17 18:41:36 +00:00
|
|
|
|
2007-06-30 21:50:06 +00:00
|
|
|
/* If there is a window other than the root window at this
|
|
|
|
* position, it means we didn't exit to the root window and we
|
|
|
|
* ignore the event.
|
|
|
|
*
|
|
|
|
* FIXME: This is not enough, it doesn't catch the case where
|
|
|
|
* we leave a GDK window to a non-GDK window that has GDK
|
|
|
|
* windows below it.
|
2007-06-17 18:41:36 +00:00
|
|
|
*/
|
|
|
|
mouse_window = _gdk_quartz_window_find_child (_gdk_root, x, y);
|
2007-06-30 21:50:06 +00:00
|
|
|
|
|
|
|
if (gdk_window_get_toplevel (mouse_window) ==
|
|
|
|
gdk_window_get_toplevel (current_mouse_window))
|
|
|
|
mouse_window = _gdk_root;
|
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
if (mouse_window == _gdk_root)
|
|
|
|
synthesize_crossing_events (_gdk_root, GDK_CROSSING_NORMAL, nsevent, x, y);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
2007-06-17 18:41:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function finds the correct window to send an event to, taking
|
|
|
|
* into account grabs, event propagation, and event masks.
|
|
|
|
*/
|
|
|
|
static GdkWindow *
|
|
|
|
find_window_for_ns_event (NSEvent *nsevent,
|
|
|
|
gint *x,
|
|
|
|
gint *y)
|
|
|
|
{
|
|
|
|
NSEventType event_type;
|
|
|
|
|
|
|
|
event_type = [nsevent type];
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
switch (event_type)
|
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
case NSMouseMoved:
|
|
|
|
case NSScrollWheel:
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
|
|
|
{
|
|
|
|
GdkWindow *mouse_window;
|
|
|
|
GdkEventMask event_mask;
|
|
|
|
GdkWindow *real_window;
|
|
|
|
|
2007-05-28 21:11:55 +00:00
|
|
|
/* 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.
|
|
|
|
*
|
|
|
|
* This means we first try the owner, then the grab window,
|
|
|
|
* then give up.
|
|
|
|
*/
|
|
|
|
if (_gdk_quartz_pointer_grab_window)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-05-28 21:11:55 +00:00
|
|
|
if (pointer_grab_owner_events)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-06 18:42:07 +00:00
|
|
|
mouse_window = find_mouse_window_for_ns_event (nsevent, x, y);
|
2007-05-28 21:11:55 +00:00
|
|
|
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;
|
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-06 16:23:50 +00:00
|
|
|
/* Finally check the grab window. */
|
2007-05-28 21:11:55 +00:00
|
|
|
if (pointer_grab_event_mask & get_event_mask_from_ns_event (nsevent))
|
|
|
|
{
|
2007-06-06 16:23:50 +00:00
|
|
|
GdkWindow *event_toplevel;
|
2007-05-28 21:11:55 +00:00
|
|
|
GdkWindow *grab_toplevel;
|
|
|
|
NSPoint point;
|
|
|
|
int x_tmp, y_tmp;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-06 16:23:50 +00:00
|
|
|
event_toplevel = [(GdkQuartzView *)[[nsevent window] contentView] gdkWindow];
|
2007-05-28 21:11:55 +00:00
|
|
|
grab_toplevel = gdk_window_get_toplevel (_gdk_quartz_pointer_grab_window);
|
|
|
|
point = [nsevent locationInWindow];
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-05-28 21:11:55 +00:00
|
|
|
x_tmp = point.x;
|
|
|
|
y_tmp = GDK_WINDOW_IMPL_QUARTZ (GDK_WINDOW_OBJECT (grab_toplevel)->impl)->height - point.y;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-06 16:23:50 +00:00
|
|
|
/* 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);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
return _gdk_quartz_pointer_grab_window;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-05-28 21:11:55 +00:00
|
|
|
return NULL;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
2007-05-28 21:11:55 +00:00
|
|
|
else
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-05-28 21:11:55 +00:00
|
|
|
/* The non-grabbed case. */
|
2007-06-06 18:42:07 +00:00
|
|
|
mouse_window = find_mouse_window_for_ns_event (nsevent, x, y);
|
2007-05-28 21:11:55 +00:00
|
|
|
event_mask = get_event_mask_from_ns_event (nsevent);
|
|
|
|
real_window = find_window_interested_in_event_mask (mouse_window, event_mask, TRUE);
|
|
|
|
|
|
|
|
/* We have to translate the coordinates if the actual
|
|
|
|
* window is different from the mouse window.
|
|
|
|
*/
|
|
|
|
if (mouse_window && real_window && mouse_window != real_window)
|
|
|
|
get_ancestor_coordinates_from_child (mouse_window,
|
|
|
|
*x, *y,
|
|
|
|
real_window,
|
|
|
|
x, y);
|
|
|
|
|
|
|
|
return real_window;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-24 10:46:21 +00:00
|
|
|
break;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSMouseEntered:
|
|
|
|
case NSMouseExited:
|
2007-06-17 18:41:36 +00:00
|
|
|
/* Already handled in synthesize_crossing_events_for_ns_event. */
|
2005-11-22 10:03:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSKeyDown:
|
|
|
|
case NSKeyUp:
|
2006-07-07 20:19:22 +00:00
|
|
|
case NSFlagsChanged:
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkEventMask event_mask;
|
|
|
|
|
2006-01-16 10:52:40 +00:00
|
|
|
if (_gdk_quartz_keyboard_grab_window && !keyboard_grab_owner_events)
|
|
|
|
return _gdk_quartz_keyboard_grab_window;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event_mask = get_event_mask_from_ns_event (nsevent);
|
2006-07-24 10:46:21 +00:00
|
|
|
return find_window_interested_in_event_mask (current_keyboard_window, event_mask, TRUE);
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2007-06-17 14:29:21 +00:00
|
|
|
/* Ignore everything else. */
|
|
|
|
break;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEvent *
|
2007-06-01 21:03:34 +00:00
|
|
|
create_button_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
GdkEventType type;
|
2007-07-03 20:31:59 +00:00
|
|
|
gint state;
|
|
|
|
gint button;
|
|
|
|
|
|
|
|
state = get_keyboard_modifiers_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
switch ([nsevent type])
|
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
type = GDK_BUTTON_PRESS;
|
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
type = GDK_BUTTON_RELEASE;
|
2007-07-03 20:31:59 +00:00
|
|
|
state |= get_mouse_button_modifiers_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2007-06-01 21:03:34 +00:00
|
|
|
button = get_mouse_button_from_ns_event (nsevent);
|
2006-07-24 10:46:21 +00:00
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event = gdk_event_new (type);
|
|
|
|
event->button.window = window;
|
2007-06-01 21:03:34 +00:00
|
|
|
event->button.time = get_time_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
event->button.x = x;
|
|
|
|
event->button.y = y;
|
|
|
|
/* FIXME event->axes */
|
2007-07-03 20:31:59 +00:00
|
|
|
event->button.state = state;
|
2005-11-22 10:03:32 +00:00
|
|
|
event->button.button = button;
|
|
|
|
event->button.device = _gdk_display->core_pointer;
|
|
|
|
convert_window_coordinates_to_root (window, x, y,
|
|
|
|
&event->button.x_root,
|
|
|
|
&event->button.y_root);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEvent *
|
2007-06-01 21:03:34 +00:00
|
|
|
create_motion_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
gint x,
|
|
|
|
gint y)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
GdkEventType type;
|
|
|
|
GdkModifierType state = 0;
|
|
|
|
|
|
|
|
switch ([nsevent type])
|
|
|
|
{
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
2007-07-03 20:31:59 +00:00
|
|
|
state = get_mouse_button_modifiers_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
/* Fall through */
|
|
|
|
case NSMouseMoved:
|
|
|
|
type = GDK_MOTION_NOTIFY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
2007-06-01 21:03:34 +00:00
|
|
|
state |= get_keyboard_modifiers_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
event = gdk_event_new (type);
|
|
|
|
event->motion.window = window;
|
2007-06-01 21:03:34 +00:00
|
|
|
event->motion.time = get_time_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
event->motion.x = x;
|
|
|
|
event->motion.y = y;
|
|
|
|
/* FIXME event->axes */
|
|
|
|
event->motion.state = state;
|
|
|
|
event->motion.is_hint = FALSE;
|
|
|
|
event->motion.device = _gdk_display->core_pointer;
|
|
|
|
convert_window_coordinates_to_root (window, x, y,
|
|
|
|
&event->motion.x_root, &event->motion.y_root);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEvent *
|
2007-06-01 21:03:34 +00:00
|
|
|
create_scroll_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkScrollDirection direction)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkEvent *event;
|
2006-07-17 08:07:55 +00:00
|
|
|
NSPoint point;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event = gdk_event_new (GDK_SCROLL);
|
|
|
|
event->scroll.window = window;
|
2007-06-01 21:03:34 +00:00
|
|
|
event->scroll.time = get_time_from_ns_event (nsevent);
|
2006-07-17 08:07:55 +00:00
|
|
|
|
|
|
|
point = [nsevent locationInWindow];
|
|
|
|
event->scroll.x = point.x;
|
|
|
|
event->scroll.y = point.y;
|
|
|
|
convert_window_coordinates_to_root (window, event->scroll.x, event->scroll.y,
|
|
|
|
&event->scroll.x_root,
|
|
|
|
&event->scroll.y_root);
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event->scroll.direction = direction;
|
|
|
|
event->scroll.device = _gdk_display->core_pointer;
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEvent *
|
2007-06-01 21:03:34 +00:00
|
|
|
create_key_event (GdkWindow *window,
|
|
|
|
NSEvent *nsevent,
|
|
|
|
GdkEventType type)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
|
|
|
GdkEvent *event;
|
2006-07-17 18:39:43 +00:00
|
|
|
gchar buf[7];
|
|
|
|
gunichar c = 0;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2006-07-07 20:19:22 +00:00
|
|
|
event = gdk_event_new (type);
|
2005-11-22 10:03:32 +00:00
|
|
|
event->key.window = window;
|
2007-06-01 21:03:34 +00:00
|
|
|
event->key.time = get_time_from_ns_event (nsevent);
|
|
|
|
event->key.state = get_keyboard_modifiers_from_ns_event (nsevent);
|
2005-11-22 10:03:32 +00:00
|
|
|
event->key.hardware_keycode = [nsevent keyCode];
|
|
|
|
event->key.group = ([nsevent modifierFlags] & NSAlternateKeyMask) ? 1 : 0;
|
2006-07-17 18:39:43 +00:00
|
|
|
|
|
|
|
event->key.keyval = GDK_VoidSymbol;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
gdk_keymap_translate_keyboard_state (NULL,
|
|
|
|
event->key.hardware_keycode,
|
|
|
|
event->key.state,
|
|
|
|
event->key.group,
|
|
|
|
&event->key.keyval,
|
|
|
|
NULL, NULL, NULL);
|
|
|
|
|
2007-04-06 21:12:48 +00:00
|
|
|
event->key.is_modifier = _gdk_quartz_keys_is_modifier (event->key.hardware_keycode);
|
2006-07-17 18:39:43 +00:00
|
|
|
|
2007-07-03 18:49:09 +00:00
|
|
|
/* If the key press is a modifier, the state should include the mask
|
|
|
|
* for that modifier but only for releases, not presses. This
|
|
|
|
* matches the X11 backend behavior.
|
|
|
|
*/
|
|
|
|
if (event->key.is_modifier)
|
|
|
|
{
|
|
|
|
int mask = 0;
|
|
|
|
|
|
|
|
switch (event->key.keyval)
|
|
|
|
{
|
|
|
|
case GDK_Meta_R:
|
|
|
|
case GDK_Meta_L:
|
|
|
|
mask = GDK_MOD1_MASK;
|
|
|
|
break;
|
|
|
|
case GDK_Shift_R:
|
|
|
|
case GDK_Shift_L:
|
|
|
|
mask = GDK_SHIFT_MASK;
|
|
|
|
break;
|
|
|
|
case GDK_Caps_Lock:
|
|
|
|
mask = GDK_LOCK_MASK;
|
|
|
|
break;
|
|
|
|
case GDK_Alt_R:
|
|
|
|
case GDK_Alt_L:
|
|
|
|
mask = GDK_MOD5_MASK;
|
|
|
|
break;
|
|
|
|
case GDK_Control_R:
|
|
|
|
case GDK_Control_L:
|
|
|
|
mask = GDK_CONTROL_MASK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mask = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == GDK_KEY_PRESS)
|
|
|
|
event->key.state &= ~mask;
|
|
|
|
else if (type == GDK_KEY_RELEASE)
|
|
|
|
event->key.state |= mask;
|
|
|
|
}
|
|
|
|
|
2007-07-03 20:31:59 +00:00
|
|
|
event->key.state |= current_button_state;
|
|
|
|
|
2006-07-17 18:39:43 +00:00
|
|
|
event->key.string = NULL;
|
|
|
|
|
|
|
|
/* Fill in ->string since apps depend on it, taken from the x11 backend. */
|
|
|
|
if (event->key.keyval != GDK_VoidSymbol)
|
|
|
|
c = gdk_keyval_to_unicode (event->key.keyval);
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
gsize bytes_written;
|
|
|
|
gint len;
|
|
|
|
|
|
|
|
len = g_unichar_to_utf8 (c, buf);
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
|
|
|
event->key.string = g_locale_from_utf8 (buf, len,
|
|
|
|
NULL, &bytes_written,
|
|
|
|
NULL);
|
|
|
|
if (event->key.string)
|
|
|
|
event->key.length = bytes_written;
|
|
|
|
}
|
|
|
|
else if (event->key.keyval == GDK_Escape)
|
|
|
|
{
|
|
|
|
event->key.length = 1;
|
|
|
|
event->key.string = g_strdup ("\033");
|
|
|
|
}
|
|
|
|
else if (event->key.keyval == GDK_Return ||
|
|
|
|
event->key.keyval == GDK_KP_Enter)
|
|
|
|
{
|
|
|
|
event->key.length = 1;
|
|
|
|
event->key.string = g_strdup ("\r");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!event->key.string)
|
|
|
|
{
|
|
|
|
event->key.length = 0;
|
|
|
|
event->key.string = g_strdup ("");
|
|
|
|
}
|
|
|
|
|
2006-07-07 20:19:22 +00:00
|
|
|
GDK_NOTE(EVENTS,
|
|
|
|
g_message ("key %s:\t\twindow: %p key: %12s %d",
|
|
|
|
type == GDK_KEY_PRESS ? "press" : "release",
|
|
|
|
event->key.window,
|
|
|
|
event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
|
|
|
|
event->key.keyval));
|
2005-11-22 10:03:32 +00:00
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2007-04-06 21:12:48 +00:00
|
|
|
GdkEventMask
|
|
|
|
_gdk_quartz_events_get_current_event_mask (void)
|
2006-08-15 20:13:13 +00:00
|
|
|
{
|
2007-07-03 20:31:59 +00:00
|
|
|
return current_event_mask;
|
2006-08-15 20:13:13 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
static gboolean
|
|
|
|
gdk_event_translate (NSEvent *nsevent)
|
|
|
|
{
|
2007-06-16 16:16:43 +00:00
|
|
|
NSWindow *nswindow;
|
2005-11-22 10:03:32 +00:00
|
|
|
GdkWindow *window;
|
|
|
|
GdkFilterReturn result;
|
|
|
|
GdkEvent *event;
|
|
|
|
int x, y;
|
|
|
|
|
2007-06-16 16:16:43 +00:00
|
|
|
/* There is no support for real desktop wide grabs, so we break
|
|
|
|
* grabs when the application loses focus (gets deactivated).
|
|
|
|
*/
|
|
|
|
if ([nsevent type] == NSAppKitDefined)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2007-06-16 16:16:43 +00:00
|
|
|
if ([nsevent subtype] == NSApplicationDeactivatedEventType)
|
|
|
|
break_all_grabs ();
|
|
|
|
|
|
|
|
/* This could potentially be used to break grabs when clicking
|
|
|
|
* on the title. The subtype 20 is undocumented so it's probably
|
|
|
|
* not a good idea: else if (subtype == 20) break_all_grabs ();
|
|
|
|
*/
|
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2007-06-17 20:36:26 +00:00
|
|
|
/* Special-case menu shortcut events. We create command events for
|
|
|
|
* those and forward to the corresponding menu.
|
|
|
|
*/
|
2007-06-25 19:54:04 +00:00
|
|
|
if ((!_gdk_quartz_keyboard_grab_window ||
|
|
|
|
(_gdk_quartz_keyboard_grab_window && keyboard_grab_owner_events)) &&
|
|
|
|
[nsevent type] == NSKeyDown)
|
2007-06-17 20:36:26 +00:00
|
|
|
{
|
|
|
|
EventRef event_ref;
|
|
|
|
MenuRef menu_ref;
|
|
|
|
MenuItemIndex index;
|
|
|
|
|
|
|
|
event_ref = [nsevent gdk_quartz_event_ref];
|
|
|
|
if (IsMenuKeyEvent (NULL, event_ref,
|
|
|
|
kMenuEventQueryOnly,
|
|
|
|
&menu_ref, &index))
|
|
|
|
{
|
|
|
|
MenuCommand menu_command;
|
|
|
|
HICommand hi_command;
|
|
|
|
|
|
|
|
if (GetMenuItemCommandID (menu_ref, index, &menu_command) != noErr)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hi_command.commandID = menu_command;
|
|
|
|
hi_command.menu.menuRef = menu_ref;
|
|
|
|
hi_command.menu.menuItemIndex = index;
|
|
|
|
|
|
|
|
CreateEvent (NULL, kEventClassCommand, kEventCommandProcess,
|
|
|
|
0, kEventAttributeUserEvent, &event_ref);
|
|
|
|
SetEventParameter (event_ref, kEventParamDirectObject,
|
|
|
|
typeHICommand,
|
|
|
|
sizeof (HICommand), &hi_command);
|
|
|
|
|
|
|
|
SendEventToEventTarget (event_ref, GetMenuEventTarget (menu_ref));
|
|
|
|
|
|
|
|
ReleaseEvent (event_ref);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-03 20:31:59 +00:00
|
|
|
/* Keep track of button state, since we don't get that information
|
|
|
|
* for key events.
|
|
|
|
*/
|
|
|
|
switch ([nsevent type])
|
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
|
|
|
current_button_state |= get_mouse_button_modifiers_from_ns_event (nsevent);
|
|
|
|
break;
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
current_button_state &= ~get_mouse_button_modifiers_from_ns_event (nsevent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-06-16 16:16:43 +00:00
|
|
|
nswindow = [nsevent window];
|
|
|
|
|
|
|
|
/* Ignore events for no window or ones not created by GDK. */
|
|
|
|
if (!nswindow || ![[nswindow contentView] isKindOfClass:[GdkQuartzView class]])
|
|
|
|
return FALSE;
|
|
|
|
|
2007-06-16 21:39:42 +00:00
|
|
|
/* Ignore events and break grabs while the window is being
|
|
|
|
* dragged. This is a workaround for the window getting events for
|
|
|
|
* the window title.
|
|
|
|
*/
|
|
|
|
if ([(GdkQuartzWindow *)nswindow isInMove])
|
|
|
|
{
|
|
|
|
break_all_grabs ();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-06-16 16:16:43 +00:00
|
|
|
/* Apply any global filters. */
|
|
|
|
if (_gdk_default_filters)
|
|
|
|
{
|
|
|
|
result = apply_filters (NULL, nsevent, _gdk_default_filters);
|
2007-06-01 21:03:34 +00:00
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
/* If result is GDK_FILTER_CONTINUE, we continue as if nothing
|
|
|
|
* happened. If it is GDK_FILTER_REMOVE,
|
|
|
|
* we return TRUE and won't send the message to Quartz.
|
|
|
|
*/
|
|
|
|
if (result == GDK_FILTER_REMOVE)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-06-17 18:41:36 +00:00
|
|
|
/* Take care of NSMouseEntered/Exited events and mouse movements
|
|
|
|
* events and emit the right GDK crossing events.
|
|
|
|
*/
|
|
|
|
synthesize_crossing_events_for_ns_event (nsevent);
|
|
|
|
|
|
|
|
/* Find the right GDK window to send the event to, taking grabs and
|
2007-06-16 16:16:43 +00:00
|
|
|
* event masks into consideration.
|
|
|
|
*/
|
2007-06-01 21:03:34 +00:00
|
|
|
window = find_window_for_ns_event (nsevent, &x, &y);
|
2005-11-22 10:03:32 +00:00
|
|
|
if (!window)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-06-16 16:16:43 +00:00
|
|
|
/* Apply any window filters. */
|
2005-11-22 10:03:32 +00:00
|
|
|
result = apply_filters (window, nsevent, ((GdkWindowObject *) window)->filters);
|
|
|
|
if (result == GDK_FILTER_REMOVE)
|
|
|
|
return TRUE;
|
2006-08-15 20:13:13 +00:00
|
|
|
|
2007-06-17 14:29:21 +00:00
|
|
|
/* We need the appliction to be activated on clicks so that popups
|
|
|
|
* like context menus get events routed properly. This is handled
|
|
|
|
* automatically for left mouse button presses but not other
|
|
|
|
* buttons, so we do it here.
|
|
|
|
*/
|
|
|
|
if ([nsevent type] == NSRightMouseDown || [nsevent type] == NSOtherMouseDown)
|
|
|
|
{
|
|
|
|
if (![NSApp isActive])
|
|
|
|
[NSApp activateIgnoringOtherApps:YES];
|
|
|
|
}
|
|
|
|
|
2007-07-03 20:31:59 +00:00
|
|
|
current_event_mask = get_event_mask_from_ns_event (nsevent);
|
2006-08-15 20:13:13 +00:00
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
switch ([nsevent type])
|
|
|
|
{
|
|
|
|
case NSLeftMouseDown:
|
|
|
|
case NSRightMouseDown:
|
|
|
|
case NSOtherMouseDown:
|
2006-07-24 10:46:21 +00:00
|
|
|
{
|
|
|
|
GdkEventMask event_mask;
|
2005-11-22 10:03:32 +00:00
|
|
|
|
2006-07-24 10:46:21 +00:00
|
|
|
/* Emulate implicit grab, when the window has both PRESS and RELEASE
|
2007-06-03 18:48:47 +00:00
|
|
|
* in its mask, like X.
|
2006-07-24 10:46:21 +00:00
|
|
|
*/
|
2007-05-28 20:55:26 +00:00
|
|
|
event_mask = (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
2006-07-24 10:46:21 +00:00
|
|
|
if (!_gdk_quartz_pointer_grab_window &&
|
|
|
|
(GDK_WINDOW_OBJECT (window)->event_mask & event_mask) == event_mask)
|
|
|
|
{
|
2007-06-03 18:48:47 +00:00
|
|
|
pointer_grab_internal (window, FALSE,
|
2006-07-24 10:46:21 +00:00
|
|
|
GDK_WINDOW_OBJECT (window)->event_mask,
|
|
|
|
NULL, NULL, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
event = create_button_event (window, nsevent, x, y);
|
|
|
|
append_event (event);
|
|
|
|
|
|
|
|
_gdk_event_button_generate (_gdk_display, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSLeftMouseUp:
|
|
|
|
case NSRightMouseUp:
|
|
|
|
case NSOtherMouseUp:
|
|
|
|
event = create_button_event (window, nsevent, x, y);
|
|
|
|
append_event (event);
|
|
|
|
|
|
|
|
/* Ungrab implicit grab */
|
2007-05-28 20:55:26 +00:00
|
|
|
if (_gdk_quartz_pointer_grab_window && pointer_grab_implicit)
|
2005-11-22 10:03:32 +00:00
|
|
|
pointer_ungrab_internal (TRUE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSLeftMouseDragged:
|
|
|
|
case NSRightMouseDragged:
|
|
|
|
case NSOtherMouseDragged:
|
|
|
|
case NSMouseMoved:
|
|
|
|
event = create_motion_event (window, nsevent, x, y);
|
|
|
|
append_event (event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollWheel:
|
|
|
|
{
|
|
|
|
float dx = [nsevent deltaX];
|
|
|
|
float dy = [nsevent deltaY];
|
|
|
|
GdkScrollDirection direction;
|
|
|
|
|
|
|
|
/* The delta is how much the mouse wheel has moved. Since there's no such thing in GTK+
|
|
|
|
* we accomodate by sending a different number of scroll wheel events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* First do y events */
|
|
|
|
if (dy < 0.0)
|
|
|
|
{
|
|
|
|
dy = -dy;
|
|
|
|
direction = GDK_SCROLL_DOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
direction = GDK_SCROLL_UP;
|
|
|
|
|
|
|
|
while (dy > 0.0)
|
|
|
|
{
|
|
|
|
event = create_scroll_event (window, nsevent, direction);
|
|
|
|
append_event (event);
|
|
|
|
dy--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now do x events */
|
|
|
|
if (dx < 0.0)
|
|
|
|
{
|
|
|
|
dx = -dx;
|
|
|
|
direction = GDK_SCROLL_RIGHT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
direction = GDK_SCROLL_LEFT;
|
|
|
|
|
|
|
|
while (dx > 0.0)
|
|
|
|
{
|
|
|
|
event = create_scroll_event (window, nsevent, direction);
|
|
|
|
append_event (event);
|
|
|
|
dx--;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-06-17 14:29:21 +00:00
|
|
|
break;
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
case NSKeyDown:
|
|
|
|
case NSKeyUp:
|
2006-07-07 20:19:22 +00:00
|
|
|
case NSFlagsChanged:
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
GdkEventType type;
|
|
|
|
|
2007-04-06 21:12:48 +00:00
|
|
|
type = _gdk_quartz_keys_event_type (nsevent);
|
2006-07-07 20:19:22 +00:00
|
|
|
if (type == GDK_NOTHING)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
event = create_key_event (window, nsevent, type);
|
|
|
|
append_event (event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2006-07-20 08:06:54 +00:00
|
|
|
break;
|
2007-06-17 14:29:21 +00:00
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
default:
|
2007-06-17 14:29:21 +00:00
|
|
|
/* Ignore everything elsee. */
|
|
|
|
break;
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gdk_events_queue (GdkDisplay *display)
|
|
|
|
{
|
2006-12-28 09:04:48 +00:00
|
|
|
NSEvent *current_event = _gdk_quartz_event_loop_get_current ();
|
|
|
|
|
2006-07-19 17:06:40 +00:00
|
|
|
if (current_event)
|
|
|
|
{
|
2006-12-19 15:53:44 +00:00
|
|
|
if (!gdk_event_translate (current_event))
|
2006-07-19 17:06:40 +00:00
|
|
|
[NSApp sendEvent:current_event];
|
2006-12-19 15:53:44 +00:00
|
|
|
|
2006-12-28 09:04:48 +00:00
|
|
|
_gdk_quartz_event_loop_release_current ();
|
2006-07-19 17:06:40 +00:00
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_flush (void)
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
/* Not supported. */
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
2007-02-18 10:56:13 +00:00
|
|
|
void
|
|
|
|
gdk_display_add_client_message_filter (GdkDisplay *display,
|
|
|
|
GdkAtom message_type,
|
|
|
|
GdkFilterFunc func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
/* Not supported. */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_add_client_message_filter (GdkAtom message_type,
|
|
|
|
GdkFilterFunc func,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
/* Not supported. */
|
|
|
|
}
|
|
|
|
|
2005-11-22 10:03:32 +00:00
|
|
|
void
|
|
|
|
gdk_display_sync (GdkDisplay *display)
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
/* Not supported. */
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_display_flush (GdkDisplay *display)
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
/* Not supported. */
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_event_send_client_message_for_display (GdkDisplay *display,
|
|
|
|
GdkEvent *event,
|
|
|
|
GdkNativeWindow winid)
|
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
/* Not supported. */
|
2005-11-22 10:03:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_screen_broadcast_client_message (GdkScreen *screen,
|
2006-07-20 08:06:54 +00:00
|
|
|
GdkEvent *event)
|
2005-11-22 10:03:32 +00:00
|
|
|
{
|
2006-07-20 08:06:54 +00:00
|
|
|
/* Not supported. */
|
2005-11-22 10:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gdk_screen_get_setting (GdkScreen *screen,
|
|
|
|
const gchar *name,
|
|
|
|
GValue *value)
|
|
|
|
{
|
2007-03-10 20:50:58 +00:00
|
|
|
if (strcmp (name, "gtk-double-click-time") == 0)
|
2006-07-24 12:31:17 +00:00
|
|
|
{
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
float t;
|
|
|
|
|
|
|
|
GDK_QUARTZ_ALLOC_POOL;
|
|
|
|
|
|
|
|
t = [defaults floatForKey:@"com.apple.mouse.doubleClickThreshold"];
|
|
|
|
if (t == 0.0)
|
|
|
|
{
|
|
|
|
/* No user setting, use the default in OS X. */
|
|
|
|
t = 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
GDK_QUARTZ_RELEASE_POOL;
|
|
|
|
|
|
|
|
g_value_set_int (value, t * 1000);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-11-22 10:03:32 +00:00
|
|
|
|
|
|
|
/* FIXME: Add more settings */
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|