From a180f7588fce6fe2a14d2742a327c7001c064945 Mon Sep 17 00:00:00 2001 From: Richard Hult Date: Mon, 2 Feb 2009 14:22:37 +0100 Subject: [PATCH] Replace quartz specific keyboard grab code with common code --- gdk/quartz/gdkevents-quartz.c | 53 +++++++++------------------------- gdk/quartz/gdkprivate-quartz.h | 3 -- gdk/quartz/gdkwindow-quartz.c | 4 +-- 3 files changed, 16 insertions(+), 44 deletions(-) diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c index 03e2256236..1f947f1d4a 100644 --- a/gdk/quartz/gdkevents-quartz.c +++ b/gdk/quartz/gdkevents-quartz.c @@ -39,10 +39,6 @@ static GdkWindow *current_mouse_window; /* This is the window corresponding to the key window */ static GdkWindow *current_keyboard_window; -/* 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; @@ -129,44 +125,26 @@ gdk_event_get_graphics_expose (GdkWindow *window) 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; } @@ -175,9 +153,7 @@ 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; + _gdk_display_unset_has_keyboard_grab (display, FALSE); } void @@ -862,9 +838,8 @@ find_window_for_ns_event (NSEvent *nsevent, case NSKeyUp: case NSFlagsChanged: { - /* FIXME: Use common code here instead. */ - 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; } diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h index 0b6faa051d..b942c0ec78 100644 --- a/gdk/quartz/gdkprivate-quartz.h +++ b/gdk/quartz/gdkprivate-quartz.h @@ -164,9 +164,6 @@ void _gdk_quartz_events_send_map_event (GdkWindow *window); GdkEventMask _gdk_quartz_events_get_current_event_mask (void); void _gdk_quartz_events_trigger_crossing_events(gboolean defer_to_mainloop); -extern GdkWindow *_gdk_quartz_keyboard_grab_window; -extern GdkWindow *_gdk_quartz_pointer_grab_window; - /* Event loop */ gboolean _gdk_quartz_event_loop_check_pending (void); NSEvent * _gdk_quartz_event_loop_get_pending (void); diff --git a/gdk/quartz/gdkwindow-quartz.c b/gdk/quartz/gdkwindow-quartz.c index 66a488df5f..f6ab1fcd20 100644 --- a/gdk/quartz/gdkwindow-quartz.c +++ b/gdk/quartz/gdkwindow-quartz.c @@ -956,7 +956,7 @@ _gdk_quartz_window_destroy (GdkWindow *window, if (window == _gdk_display->pointer_grab.window) gdk_pointer_ungrab (0); - if (window == _gdk_quartz_keyboard_grab_window) + if (window == _gdk_display->keyboard_grab.window) gdk_keyboard_ungrab (0); _gdk_quartz_drawable_finish (GDK_DRAWABLE (impl)); @@ -1125,7 +1125,7 @@ gdk_window_quartz_hide (GdkWindow *window) if (window == _gdk_display->pointer_grab.window) gdk_pointer_ungrab (0); - if (window == _gdk_quartz_keyboard_grab_window) + if (window == _gdk_display->keyboard_grab.window) gdk_keyboard_ungrab (0); }