| 1 |
#include "config.h" |
| 2 |
|
| 3 |
#include "gdkwin32messagesourceprivate.h" |
| 4 |
|
| 5 |
#include "gdkevents.h" |
| 6 |
|
| 7 |
#include <windows.h> |
| 8 |
|
| 9 |
typedef struct _GdkWin32MessageSource GdkWin32MessageSource; |
| 10 |
|
| 11 |
struct _GdkWin32MessageSource |
| 12 |
{ |
| 13 |
GSource source; |
| 14 |
|
| 15 |
GPollFD poll_fd; |
| 16 |
} ; |
| 17 |
|
| 18 |
static gboolean |
| 19 |
gdk_win32_message_source_prepare (GSource *source, |
| 20 |
int *timeout) |
| 21 |
{ |
| 22 |
*timeout = -1; |
| 23 |
|
| 24 |
return GetQueueStatus (QS_ALLINPUT) != 0; |
| 25 |
} |
| 26 |
|
| 27 |
static gboolean |
| 28 |
gdk_win32_message_source_check (GSource *source) |
| 29 |
{ |
| 30 |
GdkWin32MessageSource *self = (GdkWin32MessageSource *) source; |
| 31 |
|
| 32 |
self->poll_fd.revents = 0; |
| 33 |
|
| 34 |
return GetQueueStatus (QS_ALLINPUT) != 0; |
| 35 |
} |
| 36 |
|
| 37 |
static gboolean |
| 38 |
gdk_win32_message_source_dispatch (GSource *source, |
| 39 |
GSourceFunc callback, |
| 40 |
gpointer user_data) |
| 41 |
{ |
| 42 |
MSG msg; |
| 43 |
|
| 44 |
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) |
| 45 |
{ |
| 46 |
TranslateMessage (&msg); |
| 47 |
DispatchMessage (&msg); |
| 48 |
} |
| 49 |
|
| 50 |
return G_SOURCE_CONTINUE; |
| 51 |
} |
| 52 |
|
| 53 |
static void |
| 54 |
gdk_win32_message_source_finalize (GSource *source) |
| 55 |
{ |
| 56 |
#ifdef G_WITH_CYGWIN |
| 57 |
close (self->poll_fd.fd); |
| 58 |
#endif |
| 59 |
} |
| 60 |
|
| 61 |
static GSourceFuncs gdk_win32_message_source_funcs = { |
| 62 |
gdk_win32_message_source_prepare, |
| 63 |
gdk_win32_message_source_check, |
| 64 |
gdk_win32_message_source_dispatch, |
| 65 |
gdk_win32_message_source_finalize, |
| 66 |
}; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
GSource * |
| 76 |
gdk_win32_message_source_new (void) |
| 77 |
{ |
| 78 |
GdkWin32MessageSource *self; |
| 79 |
GSource *source; |
| 80 |
|
| 81 |
source = g_source_new (&gdk_win32_message_source_funcs, sizeof (GdkWin32MessageSource)); |
| 82 |
g_source_set_static_name (source, "GDK Win32 message source"); |
| 83 |
g_source_set_priority (source, GDK_PRIORITY_EVENTS); |
| 84 |
|
| 85 |
self = (GdkWin32MessageSource *) source; |
| 86 |
#ifdef G_WITH_CYGWIN |
| 87 |
self->poll_fd.fd = open ("/dev/windows", O_RDONLY); |
| 88 |
if (self->poll_fd.fd == -1) |
| 89 |
g_error ("can't open \"/dev/windows\": %s", g_strerror (errno)); |
| 90 |
#else |
| 91 |
self->poll_fd.fd = G_WIN32_MSG_HANDLE; |
| 92 |
#endif |
| 93 |
self->poll_fd.events = G_IO_IN; |
| 94 |
|
| 95 |
g_source_add_poll (source, &self->poll_fd); |
| 96 |
g_source_set_can_recurse (source, TRUE); |
| 97 |
|
| 98 |
return source; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
guint |
| 110 |
gdk_win32_message_source_add (GMainContext *context) |
| 111 |
{ |
| 112 |
GSource *source; |
| 113 |
guint id; |
| 114 |
|
| 115 |
source = gdk_win32_message_source_new (); |
| 116 |
id = g_source_attach (source, context); |
| 117 |
g_source_unref (source); |
| 118 |
|
| 119 |
return id; |
| 120 |
} |