#include "gdkprivate-quartz.h"
static GPollFD event_poll_fd;
-static NSEvent *current_event;
+static GQueue *current_events;
static GPollFunc old_poll_func;
static pthread_mutex_t pollfd_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t ready_cond = PTHREAD_COND_INITIALIZER;
static GPollFD *pollfds;
-static GPollFD *pipe_pollfd;
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;
+ return current_events && current_events->head;
}
NSEvent*
_gdk_quartz_event_loop_get_pending (void)
{
- NSEvent *event;
+ NSEvent *event = NULL;
- event = current_event;
- current_event = NULL;
+ if (current_events)
+ event = g_queue_pop_tail (current_events);
return event;
}
dequeue: NO];
retval = (_gdk_event_queue_find_first (_gdk_display) != NULL ||
- event != NULL);
+ (current_events && current_events->head) ||
+ event != NULL);
GDK_THREADS_LEAVE ();
n_active_fds = old_poll_func (pollfds, n_pollfds, -1);
pthread_mutex_lock (&pollfd_mutex);
select_fd_waiting = FALSE;
- n = read (pipe_pollfd->fd, &c, 1);
+ n = read (wakeup_pipe[0], &c, 1);
if (n == 1)
{
g_assert (c == 'A');
{
NSEvent *event;
NSDate *limit_date;
+ gboolean poll_event_fd = FALSE;
int n_active = 0;
int i;
- if (nfds > 1)
+ if (nfds > 1 || ufds[0].fd != -1)
{
if (!select_thread) {
/* Create source used for signalling the main thread */
while (!ready_for_poll)
pthread_cond_wait (&ready_cond, &pollfd_mutex);
- n_pollfds = nfds;
- g_free (pollfds);
- pollfds = g_memdup (ufds, sizeof (GPollFD) * nfds);
+ /* We cheat and use the fake fd (if it's polled) for our pipe */
- /* We cheat and use the fake fd for our pipe */
for (i = 0; i < nfds; i++)
+ if (ufds[i].fd == -1)
+ {
+ poll_event_fd = TRUE;
+ break;
+ }
+
+ g_free (pollfds);
+
+ if (i == nfds)
{
- if (pollfds[i].fd == -1)
- {
- pipe_pollfd = &pollfds[i];
- pollfds[i].fd = wakeup_pipe[0];
- pollfds[i].events = G_IO_IN;
- }
+ n_pollfds = nfds + 1;
+ pollfds = g_new (GPollFD, nfds + 1);
+ memcpy (pollfds, ufds, nfds * sizeof (GPollFD));
+ }
+ else
+ {
+ pollfds = g_memdup (ufds, nfds * sizeof (GPollFD));
+ n_pollfds = nfds;
}
+ pollfds[i].fd = wakeup_pipe[0];
+ pollfds[i].events = G_IO_IN;
+
/* Start our thread */
pthread_cond_signal (&ready_cond);
pthread_cond_wait (&ready_cond, &pollfd_mutex);
{
pthread_mutex_lock (&pollfd_mutex);
- for (i = 0; i < n_pollfds; i++)
+ for (i = 0; i < nfds; i++)
{
if (ufds[i].fd == -1)
continue;
pthread_mutex_unlock (&pollfd_mutex);
- event = [NSApp nextEventMatchingMask: NSAnyEventMask
- untilDate: [NSDate distantPast]
- inMode: NSDefaultRunLoopMode
- dequeue: YES];
-
+ /* Try to get a Cocoa event too, if requested */
+ if (poll_event_fd)
+ event = [NSApp nextEventMatchingMask: NSAnyEventMask
+ untilDate: [NSDate distantPast]
+ inMode: NSDefaultRunLoopMode
+ dequeue: YES];
+ else
+ event = NULL;
}
}
}
}
- current_event = [event retain];
+ if (!current_events)
+ current_events = g_queue_new ();
+ g_queue_push_head (current_events, [event retain]);
n_active ++;
}