Implement keyboard grabs.

2006-01-16  Anders Carlsson  <andersca@mac.com>

        * gdk/quartz/gdkdisplay-quartz.c:
        * gdk/quartz/gdkevents-quartz.c:
        (gdk_keyboard_grab):
        (gdk_display_keyboard_ungrab):
        (gdk_keyboard_grab_info_libgtk_only):
        (find_window_for_event):
        Implement keyboard grabs.

        (_gdk_quartz_send_map_events):
        * gdk/quartz/gdkmain-quartz.c:
        * gdk/quartz/gdkprivate-quartz.h:
        New function that synthesizes map events.

        * gdk/quartz/gdkwindow-quartz.c:
        (_gdk_windowing_window_init):
        The root window is always visible.

        (all_parents_shown):
        (show_window_internal):
        Send map events.

        (gdk_window_hide):
        Ungrab keyboard and pointer
This commit is contained in:
Anders Carlsson 2006-01-16 10:52:40 +00:00 committed by Anders Carlsson
parent 0550bdd093
commit 4afc4d61c6
7 changed files with 158 additions and 46 deletions

View File

@ -1,3 +1,22 @@
2006-01-16 Anders Carlsson <andersca@mac.com>
Reviewed by NOBODY (OOPS!).
* gdk/quartz/gdkdisplay-quartz.c:
* gdk/quartz/gdkevents-quartz.c:
(gdk_keyboard_grab):
(gdk_display_keyboard_ungrab):
(gdk_keyboard_grab_info_libgtk_only):
(_gdk_quartz_send_map_events):
(find_window_for_event):
* gdk/quartz/gdkmain-quartz.c:
* gdk/quartz/gdkprivate-quartz.h:
* gdk/quartz/gdkwindow-quartz.c:
(_gdk_windowing_window_init):
(all_parents_shown):
(show_window_internal):
(gdk_window_hide):
2006-01-15 Kristian Rietveld <kris@gtk.org>
Fixes #324099, Tommi Komulainen.

View File

@ -1,3 +1,22 @@
2006-01-16 Anders Carlsson <andersca@mac.com>
Reviewed by NOBODY (OOPS!).
* gdk/quartz/gdkdisplay-quartz.c:
* gdk/quartz/gdkevents-quartz.c:
(gdk_keyboard_grab):
(gdk_display_keyboard_ungrab):
(gdk_keyboard_grab_info_libgtk_only):
(_gdk_quartz_send_map_events):
(find_window_for_event):
* gdk/quartz/gdkmain-quartz.c:
* gdk/quartz/gdkprivate-quartz.h:
* gdk/quartz/gdkwindow-quartz.c:
(_gdk_windowing_window_init):
(all_parents_shown):
(show_window_internal):
(gdk_window_hide):
2006-01-15 Kristian Rietveld <kris@gtk.org>
Fixes #324099, Tommi Komulainen.

View File

@ -91,13 +91,6 @@ gdk_display_get_default_screen (GdkDisplay *display)
return _gdk_screen;
}
void
gdk_display_keyboard_ungrab (GdkDisplay *display,
guint32 time)
{
/* FIXME: Implement */
}
void
gdk_display_beep (GdkDisplay *display)
{

View File

@ -37,11 +37,15 @@ static GdkWindow *current_mouse_window;
static GdkWindow *current_keyboard_window;
/* This is the pointer grab window */
static GdkWindow *pointer_grab_window;
GdkWindow *_gdk_quartz_pointer_grab_window;
static gboolean pointer_grab_owner_events;
static GdkEventMask pointer_grab_event_mask;
static gboolean pointer_grab_implicit;
/* This is the keyboard grab window */
GdkWindow *_gdk_quartz_keyboard_grab_window;
static gboolean keyboard_grab_owner_events;
static gboolean
gdk_event_prepare (GSource *source,
gint *timeout)
@ -191,18 +195,62 @@ gdk_event_get_graphics_expose (GdkWindow *window)
return NULL;
}
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)
gdk_keyboard_ungrab (time);
_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;
}
static void
pointer_ungrab_internal (gboolean implicit)
{
if (!pointer_grab_window)
if (!_gdk_quartz_pointer_grab_window)
return;
if (pointer_grab_implicit && !implicit)
return;
g_object_unref (pointer_grab_window);
g_object_unref (_gdk_quartz_pointer_grab_window);
pointer_grab_window = NULL;
_gdk_quartz_pointer_grab_window = NULL;
/* FIXME: Send crossing events */
}
@ -210,7 +258,7 @@ pointer_ungrab_internal (gboolean implicit)
gboolean
gdk_display_pointer_is_grabbed (GdkDisplay *display)
{
return pointer_grab_window != NULL;
return _gdk_quartz_pointer_grab_window != NULL;
}
gboolean
@ -218,11 +266,11 @@ gdk_pointer_grab_info_libgtk_only (GdkDisplay *display,
GdkWindow **grab_window,
gboolean *owner_events)
{
if (!pointer_grab_window)
if (!_gdk_quartz_pointer_grab_window)
return FALSE;
if (grab_window)
*grab_window = pointer_grab_window;
*grab_window = _gdk_quartz_pointer_grab_window;
if (owner_events)
*owner_events = pointer_grab_owner_events;
@ -247,7 +295,7 @@ pointer_grab_internal (GdkWindow *window,
{
/* FIXME: Send crossing events */
pointer_grab_window = g_object_ref (window);
_gdk_quartz_pointer_grab_window = g_object_ref (window);
pointer_grab_owner_events = owner_events;
pointer_grab_event_mask = event_mask;
pointer_grab_implicit = implicit;
@ -266,7 +314,7 @@ gdk_pointer_grab (GdkWindow *window,
g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
g_return_val_if_fail (confine_to == NULL || GDK_IS_WINDOW (confine_to), 0);
if (pointer_grab_window)
if (_gdk_quartz_pointer_grab_window)
{
if (!pointer_grab_implicit)
return GDK_GRAB_ALREADY_GRABBED;
@ -744,6 +792,29 @@ synthesize_crossing_events (GdkWindow *window,
_gdk_quartz_update_mouse_window (window);
}
void
_gdk_quartz_send_map_events (GdkWindow *window)
{
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)
_gdk_quartz_send_map_events ((GdkWindow *)list->data);
}
/* Get current mouse window */
GdkWindow *
_gdk_quartz_get_mouse_window (void)
@ -815,7 +886,7 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
if (!mouse_window)
mouse_window = _gdk_root;
if (pointer_grab_window)
if (_gdk_quartz_pointer_grab_window)
{
if (mouse_window != current_mouse_window)
synthesize_crossing_events (mouse_window, GDK_CROSSING_NORMAL, nsevent, *x, *y);
@ -851,13 +922,13 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
GdkEventMask event_mask;
GdkWindow *real_window;
if (pointer_grab_window)
if (_gdk_quartz_pointer_grab_window)
{
if (pointer_grab_event_mask & get_event_mask_from_ns_event (nsevent))
{
int tempx, tempy;
GdkWindowObject *w = GDK_WINDOW_OBJECT (pointer_grab_window);
GdkWindowObject *grab_toplevel = GDK_WINDOW_OBJECT (gdk_window_get_toplevel (pointer_grab_window));
GdkWindowObject *w = GDK_WINDOW_OBJECT (_gdk_quartz_pointer_grab_window);
GdkWindowObject *grab_toplevel = GDK_WINDOW_OBJECT (gdk_window_get_toplevel (_gdk_quartz_pointer_grab_window));
tempx = point.x;
tempy = GDK_WINDOW_IMPL_QUARTZ (grab_toplevel->impl)->height -
@ -874,7 +945,7 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
*x = tempx;
*y = tempy;
return pointer_grab_window;
return _gdk_quartz_pointer_grab_window;
}
else
{
@ -923,6 +994,9 @@ find_window_for_event (NSEvent *nsevent, gint *x, gint *y)
GdkEventMask event_mask;
GdkWindow *real_window;
if (_gdk_quartz_keyboard_grab_window && !keyboard_grab_owner_events)
return _gdk_quartz_keyboard_grab_window;
keyboard_window = find_current_keyboard_window ();
event_mask = get_event_mask_from_ns_event (nsevent);
real_window = find_window_interested_in_event_mask (keyboard_window, event_mask, TRUE);
@ -1125,7 +1199,7 @@ gdk_event_translate (NSEvent *nsevent)
case NSRightMouseDown:
case NSOtherMouseDown:
/* Emulate implicit grab */
if (!pointer_grab_window)
if (!_gdk_quartz_pointer_grab_window)
{
pointer_grab_internal (window, FALSE, GDK_WINDOW_OBJECT (window)->event_mask,
NULL, NULL, TRUE);
@ -1145,7 +1219,7 @@ gdk_event_translate (NSEvent *nsevent)
append_event (event);
/* Ungrab implicit grab */
if (pointer_grab_window &&
if (_gdk_quartz_pointer_grab_window &&
pointer_grab_implicit)
pointer_ungrab_internal (TRUE);
break;

View File

@ -31,26 +31,6 @@ _gdk_windowing_init (void)
{
}
GdkGrabStatus
gdk_keyboard_grab (GdkWindow *window,
gint owner_events,
guint32 time)
{
/* FIXME: Implement */
return GDK_GRAB_SUCCESS;
}
gboolean
gdk_keyboard_grab_info_libgtk_only (GdkDisplay *display,
GdkWindow **grab_window,
gboolean *owner_events)
{
/* FIXME: Implement */
return FALSE;
}
void
gdk_error_trap_push (void)
{

View File

@ -110,4 +110,9 @@ GdkImage *_gdk_quartz_copy_to_image (GdkDrawable *drawable,
gint width,
gint height);
void _gdk_quartz_send_map_events (GdkWindow *window);
extern GdkWindow *_gdk_quartz_keyboard_grab_window;
extern GdkWindow *_gdk_quartz_pointer_grab_window;
#endif /* __GDK_PRIVATE_QUARTZ_H__ */

View File

@ -392,8 +392,10 @@ _gdk_windowing_window_init (void)
g_assert (_gdk_root == NULL);
_gdk_root = g_object_new (GDK_TYPE_WINDOW, NULL);
private = (GdkWindowObject *)_gdk_root;
private->state = 0; /* We don't want GDK_WINDOW_STATE_WITHDRAWN here */
private->window_type = GDK_WINDOW_ROOT;
private->depth = 24;
}
@ -426,6 +428,20 @@ _gdk_windowing_window_destroy_foreign (GdkWindow *window)
/* FIXME: Implement */
}
static gboolean
all_parents_shown (GdkWindowObject *private)
{
while (GDK_WINDOW_IS_MAPPED (private))
{
if (private->parent)
private = (GdkWindowObject *)private->parent;
else
return TRUE;
}
return FALSE;
}
static void
show_window_internal (GdkWindow *window, gboolean raise)
{
@ -441,7 +457,7 @@ show_window_internal (GdkWindow *window, gboolean raise)
impl = GDK_WINDOW_IMPL_QUARTZ (private->impl);
/* FIXME: We need to raise the window (move it to the top in the list)*/
/* FIXME: We need to raise the window (move it to the top in the list) */
if (impl->toplevel)
{
@ -454,6 +470,9 @@ show_window_internal (GdkWindow *window, gboolean raise)
[impl->view setNeedsDisplay:YES];
}
if (all_parents_shown (private->parent))
_gdk_quartz_send_map_events (window);
gdk_synthesize_window_state (window, GDK_WINDOW_STATE_WITHDRAWN, 0);
GDK_QUARTZ_RELEASE_POOL;
@ -504,8 +523,11 @@ gdk_window_hide (GdkWindow *window)
[impl->view setHidden:YES];
}
gdk_pointer_ungrab (0);
if (window == _gdk_quartz_pointer_grab_window)
gdk_pointer_ungrab (0);
if (window == _gdk_quartz_keyboard_grab_window)
gdk_keyboard_ungrab (0);
}
void