summaryrefslogtreecommitdiff
path: root/gdk/quartz
diff options
context:
space:
mode:
authorRichard Hult <richard@imendio.com>2007-12-10 19:00:23 +0000
committerRichard Hult <rhult@src.gnome.org>2007-12-10 19:00:23 +0000
commitfd8c2c01a9e4f8f9bb20de818c8d7be31c4b0df3 (patch)
tree7ee88bf350b035f03edb4177629b76ae9ae4f4a7 /gdk/quartz
parent9355ef9ee5bcbfec773ab6551331ce7671190dfe (diff)
downloadgtk+-fd8c2c01a9e4f8f9bb20de818c8d7be31c4b0df3.tar.gz
Fix a bug where we could end up trying to handle the same event more than
2007-12-10 Richard Hult <richard@imendio.com> * gdk/quartz/gdkprivate-quartz.h: * gdk/quartz/gdkeventloop-quartz.c: (_gdk_quartz_event_loop_get_pending), (_gdk_quartz_event_loop_check_pending), (_gdk_quartz_event_loop_release_event), (gdk_event_prepare), (gdk_event_check), (gdk_event_dispatch): * gdk/quartz/gdkevents-quartz.c: (gdk_events_pending) (_gdk_events_queue): Fix a bug where we could end up trying to handle the same event more than once. Based on patch from Paul Davis. svn path=/trunk/; revision=19143
Diffstat (limited to 'gdk/quartz')
-rw-r--r--gdk/quartz/gdkeventloop-quartz.c63
-rw-r--r--gdk/quartz/gdkevents-quartz.c15
-rw-r--r--gdk/quartz/gdkprivate-quartz.h5
3 files changed, 52 insertions, 31 deletions
diff --git a/gdk/quartz/gdkeventloop-quartz.c b/gdk/quartz/gdkeventloop-quartz.c
index d9e9ad85e7..a696a39e75 100644
--- a/gdk/quartz/gdkeventloop-quartz.c
+++ b/gdk/quartz/gdkeventloop-quartz.c
@@ -24,12 +24,37 @@ static guint n_pollfds;
static CFRunLoopSourceRef select_main_thread_source;
static CFRunLoopRef main_thread_run_loop;
+gboolean
+_gdk_quartz_event_loop_check_pending (void)
+{
+ return current_event != NULL;
+}
+
+NSEvent*
+_gdk_quartz_event_loop_get_pending (void)
+{
+ NSEvent *event;
+
+ event = current_event;
+ current_event = NULL;
+
+ return event;
+}
+
+void
+_gdk_quartz_event_loop_release_event (NSEvent *event)
+{
+ [event release];
+}
+
static gboolean
gdk_event_prepare (GSource *source,
gint *timeout)
{
NSEvent *event;
gboolean retval;
+
+ GDK_THREADS_ENTER ();
GDK_QUARTZ_ALLOC_POOL;
@@ -45,19 +70,27 @@ gdk_event_prepare (GSource *source,
GDK_QUARTZ_RELEASE_POOL;
+ GDK_THREADS_LEAVE ();
+
return retval;
}
static gboolean
gdk_event_check (GSource *source)
{
+ gboolean retval;
+
+ GDK_THREADS_ENTER ();
+
if (_gdk_event_queue_find_first (_gdk_display) != NULL ||
- current_event)
- return TRUE;
+ _gdk_quartz_event_loop_check_pending ())
+ retval = TRUE;
+ else
+ retval = FALSE;
- /* FIXME: We should maybe try to fetch an event again here */
+ GDK_THREADS_LEAVE ();
- return FALSE;
+ return retval;
}
static gboolean
@@ -67,6 +100,8 @@ gdk_event_dispatch (GSource *source,
{
GdkEvent *event;
+ GDK_THREADS_ENTER ();
+
GDK_QUARTZ_ALLOC_POOL;
_gdk_events_queue (_gdk_display);
@@ -83,6 +118,8 @@ gdk_event_dispatch (GSource *source,
GDK_QUARTZ_RELEASE_POOL;
+ GDK_THREADS_LEAVE ();
+
return TRUE;
}
@@ -264,11 +301,6 @@ poll_func (GPollFD *ufds, guint nfds, gint timeout_)
{
ufds[0].revents = G_IO_IN;
- /* FIXME: We can't assert here, but we might need to have a
- * queue for events instead.
- */
- /*g_assert (current_event == NULL);*/
-
current_event = [event retain];
n_active ++;
@@ -298,16 +330,3 @@ _gdk_quartz_event_loop_init (void)
}
-NSEvent *
-_gdk_quartz_event_loop_get_current (void)
-{
- return current_event;
-}
-
-void
-_gdk_quartz_event_loop_release_current (void)
-{
- [current_event release];
- current_event = NULL;
-}
-
diff --git a/gdk/quartz/gdkevents-quartz.c b/gdk/quartz/gdkevents-quartz.c
index 01dea29dca..832646cd6b 100644
--- a/gdk/quartz/gdkevents-quartz.c
+++ b/gdk/quartz/gdkevents-quartz.c
@@ -130,7 +130,7 @@ gboolean
gdk_events_pending (void)
{
return (_gdk_event_queue_find_first (_gdk_display) ||
- (_gdk_quartz_event_loop_get_current () != NULL));
+ (_gdk_quartz_event_loop_check_pending ()));
}
GdkEvent*
@@ -1829,14 +1829,15 @@ gdk_event_translate (NSEvent *nsevent)
void
_gdk_events_queue (GdkDisplay *display)
{
- NSEvent *current_event = _gdk_quartz_event_loop_get_current ();
+ NSEvent *event;
- if (current_event)
+ event = _gdk_quartz_event_loop_get_pending ();
+ if (event)
{
- if (!gdk_event_translate (current_event))
- [NSApp sendEvent:current_event];
-
- _gdk_quartz_event_loop_release_current ();
+ if (!gdk_event_translate (event))
+ [NSApp sendEvent:event];
+
+ _gdk_quartz_event_loop_release_event (event);
}
}
diff --git a/gdk/quartz/gdkprivate-quartz.h b/gdk/quartz/gdkprivate-quartz.h
index c3b7b0bc63..e322e43405 100644
--- a/gdk/quartz/gdkprivate-quartz.h
+++ b/gdk/quartz/gdkprivate-quartz.h
@@ -158,8 +158,9 @@ extern GdkWindow *_gdk_quartz_keyboard_grab_window;
extern GdkWindow *_gdk_quartz_pointer_grab_window;
/* Event loop */
-NSEvent * _gdk_quartz_event_loop_get_current (void);
-void _gdk_quartz_event_loop_release_current (void);
+gboolean _gdk_quartz_event_loop_check_pending (void);
+NSEvent * _gdk_quartz_event_loop_get_pending (void);
+void _gdk_quartz_event_loop_release_event (NSEvent *event);
/* FIXME: image */
GdkImage *_gdk_quartz_image_copy_to_image (GdkDrawable *drawable,