]> Pileus Git - ~andy/gtk/blob - gdk/win32/gdkdevicemanager-win32.c
Tweak include order a bit to get around compilation errors
[~andy/gtk] / gdk / win32 / gdkdevicemanager-win32.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <math.h>
25
26 #include <gdk/gdk.h>
27 #include "gdkwin32.h"
28 #include "gdkprivate-win32.h"
29 #include "gdkdevicemanager-win32.h"
30 #include "gdkdeviceprivate.h"
31 #include "gdkdevice-win32.h"
32 #include "gdkdevice-wintab.h"
33 #include "gdkdisplayprivate.h"
34
35 #define WINTAB32_DLL "Wintab32.dll"
36
37 #define PACKETDATA (PK_CONTEXT | PK_CURSOR | PK_BUTTONS | PK_X | PK_Y  | PK_NORMAL_PRESSURE | PK_ORIENTATION)
38 /* We want everything in absolute mode */
39 #define PACKETMODE (0)
40 #include <pktdef.h>
41
42 #define DEBUG_WINTAB 1          /* Verbose debug messages enabled */
43 #define PROXIMITY_OUT_DELAY 200 /* In milliseconds, see set_ignore_core */
44 #define TWOPI (2 * G_PI)
45
46 static GList     *wintab_contexts = NULL;
47 static GdkWindow *wintab_window = NULL;
48 static guint      ignore_core_timer = 0;
49 extern gint       _gdk_input_ignore_core;
50
51 typedef UINT (WINAPI *t_WTInfoA) (UINT a, UINT b, LPVOID c);
52 typedef UINT (WINAPI *t_WTInfoW) (UINT a, UINT b, LPVOID c);
53 typedef BOOL (WINAPI *t_WTEnable) (HCTX a, BOOL b);
54 typedef HCTX (WINAPI *t_WTOpenA) (HWND a, LPLOGCONTEXTA b, BOOL c);
55 typedef BOOL (WINAPI *t_WTOverlap) (HCTX a, BOOL b);
56 typedef BOOL (WINAPI *t_WTPacket) (HCTX a, UINT b, LPVOID c);
57 typedef int (WINAPI *t_WTQueueSizeSet) (HCTX a, int b);
58
59 static t_WTInfoA p_WTInfoA;
60 static t_WTInfoW p_WTInfoW;
61 static t_WTEnable p_WTEnable;
62 static t_WTOpenA p_WTOpenA;
63 static t_WTOverlap p_WTOverlap;
64 static t_WTPacket p_WTPacket;
65 static t_WTQueueSizeSet p_WTQueueSizeSet;
66
67
68 static void    gdk_device_manager_win32_finalize    (GObject *object);
69 static void    gdk_device_manager_win32_constructed (GObject *object);
70
71 static GList * gdk_device_manager_win32_list_devices (GdkDeviceManager *device_manager,
72                                                       GdkDeviceType     type);
73 static GdkDevice * gdk_device_manager_win32_get_client_pointer (GdkDeviceManager *device_manager);
74
75
76 G_DEFINE_TYPE (GdkDeviceManagerWin32, gdk_device_manager_win32, GDK_TYPE_DEVICE_MANAGER)
77
78 static void
79 gdk_device_manager_win32_class_init (GdkDeviceManagerWin32Class *klass)
80 {
81   GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass);
82   GObjectClass *object_class = G_OBJECT_CLASS (klass);
83
84   object_class->finalize = gdk_device_manager_win32_finalize;
85   object_class->constructed = gdk_device_manager_win32_constructed;
86   device_manager_class->list_devices = gdk_device_manager_win32_list_devices;
87   device_manager_class->get_client_pointer = gdk_device_manager_win32_get_client_pointer;
88 }
89
90 static GdkDevice *
91 create_core_pointer (GdkDeviceManager *device_manager)
92 {
93   return g_object_new (GDK_TYPE_DEVICE_WIN32,
94                        "name", "Core Pointer",
95                        "type", GDK_DEVICE_TYPE_MASTER,
96                        "input-source", GDK_SOURCE_MOUSE,
97                        "input-mode", GDK_MODE_SCREEN,
98                        "has-cursor", TRUE,
99                        "display", _gdk_display,
100                        "device-manager", device_manager,
101                        NULL);
102 }
103
104 static GdkDevice *
105 create_core_keyboard (GdkDeviceManager *device_manager)
106 {
107   return g_object_new (GDK_TYPE_DEVICE_WIN32,
108                        "name", "Core Keyboard",
109                        "type", GDK_DEVICE_TYPE_MASTER,
110                        "input-source", GDK_SOURCE_KEYBOARD,
111                        "input-mode", GDK_MODE_SCREEN,
112                        "has-cursor", FALSE,
113                        "display", _gdk_display,
114                        "device-manager", device_manager,
115                        NULL);
116 }
117
118 static void
119 gdk_device_manager_win32_init (GdkDeviceManagerWin32 *device_manager_win32)
120 {
121 }
122
123 static void
124 gdk_device_manager_win32_finalize (GObject *object)
125 {
126   GdkDeviceManagerWin32 *device_manager_win32;
127
128   device_manager_win32 = GDK_DEVICE_MANAGER_WIN32 (object);
129
130   g_object_unref (device_manager_win32->core_pointer);
131   g_object_unref (device_manager_win32->core_keyboard);
132
133   G_OBJECT_CLASS (gdk_device_manager_win32_parent_class)->finalize (object);
134 }
135
136 #if DEBUG_WINTAB
137
138 static void
139 print_lc(LOGCONTEXT *lc)
140 {
141   g_print ("lcName = %s\n", lc->lcName);
142   g_print ("lcOptions =");
143   if (lc->lcOptions & CXO_SYSTEM) g_print (" CXO_SYSTEM");
144   if (lc->lcOptions & CXO_PEN) g_print (" CXO_PEN");
145   if (lc->lcOptions & CXO_MESSAGES) g_print (" CXO_MESSAGES");
146   if (lc->lcOptions & CXO_MARGIN) g_print (" CXO_MARGIN");
147   if (lc->lcOptions & CXO_MGNINSIDE) g_print (" CXO_MGNINSIDE");
148   if (lc->lcOptions & CXO_CSRMESSAGES) g_print (" CXO_CSRMESSAGES");
149   g_print ("\n");
150   g_print ("lcStatus =");
151   if (lc->lcStatus & CXS_DISABLED) g_print (" CXS_DISABLED");
152   if (lc->lcStatus & CXS_OBSCURED) g_print (" CXS_OBSCURED");
153   if (lc->lcStatus & CXS_ONTOP) g_print (" CXS_ONTOP");
154   g_print ("\n");
155   g_print ("lcLocks =");
156   if (lc->lcLocks & CXL_INSIZE) g_print (" CXL_INSIZE");
157   if (lc->lcLocks & CXL_INASPECT) g_print (" CXL_INASPECT");
158   if (lc->lcLocks & CXL_SENSITIVITY) g_print (" CXL_SENSITIVITY");
159   if (lc->lcLocks & CXL_MARGIN) g_print (" CXL_MARGIN");
160   g_print ("\n");
161   g_print ("lcMsgBase = %#x, lcDevice = %#x, lcPktRate = %d\n",
162           lc->lcMsgBase, lc->lcDevice, lc->lcPktRate);
163   g_print ("lcPktData =");
164   if (lc->lcPktData & PK_CONTEXT) g_print (" PK_CONTEXT");
165   if (lc->lcPktData & PK_STATUS) g_print (" PK_STATUS");
166   if (lc->lcPktData & PK_TIME) g_print (" PK_TIME");
167   if (lc->lcPktData & PK_CHANGED) g_print (" PK_CHANGED");
168   if (lc->lcPktData & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER");
169   if (lc->lcPktData & PK_CURSOR) g_print (" PK_CURSOR");
170   if (lc->lcPktData & PK_BUTTONS) g_print (" PK_BUTTONS");
171   if (lc->lcPktData & PK_X) g_print (" PK_X");
172   if (lc->lcPktData & PK_Y) g_print (" PK_Y");
173   if (lc->lcPktData & PK_Z) g_print (" PK_Z");
174   if (lc->lcPktData & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE");
175   if (lc->lcPktData & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE");
176   if (lc->lcPktData & PK_ORIENTATION) g_print (" PK_ORIENTATION");
177   if (lc->lcPktData & PK_ROTATION) g_print (" PK_ROTATION");
178   g_print ("\n");
179   g_print ("lcPktMode =");
180   if (lc->lcPktMode & PK_CONTEXT) g_print (" PK_CONTEXT");
181   if (lc->lcPktMode & PK_STATUS) g_print (" PK_STATUS");
182   if (lc->lcPktMode & PK_TIME) g_print (" PK_TIME");
183   if (lc->lcPktMode & PK_CHANGED) g_print (" PK_CHANGED");
184   if (lc->lcPktMode & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER");
185   if (lc->lcPktMode & PK_CURSOR) g_print (" PK_CURSOR");
186   if (lc->lcPktMode & PK_BUTTONS) g_print (" PK_BUTTONS");
187   if (lc->lcPktMode & PK_X) g_print (" PK_X");
188   if (lc->lcPktMode & PK_Y) g_print (" PK_Y");
189   if (lc->lcPktMode & PK_Z) g_print (" PK_Z");
190   if (lc->lcPktMode & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE");
191   if (lc->lcPktMode & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE");
192   if (lc->lcPktMode & PK_ORIENTATION) g_print (" PK_ORIENTATION");
193   if (lc->lcPktMode & PK_ROTATION) g_print (" PK_ROTATION");
194   g_print ("\n");
195   g_print ("lcMoveMask =");
196   if (lc->lcMoveMask & PK_CONTEXT) g_print (" PK_CONTEXT");
197   if (lc->lcMoveMask & PK_STATUS) g_print (" PK_STATUS");
198   if (lc->lcMoveMask & PK_TIME) g_print (" PK_TIME");
199   if (lc->lcMoveMask & PK_CHANGED) g_print (" PK_CHANGED");
200   if (lc->lcMoveMask & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER");
201   if (lc->lcMoveMask & PK_CURSOR) g_print (" PK_CURSOR");
202   if (lc->lcMoveMask & PK_BUTTONS) g_print (" PK_BUTTONS");
203   if (lc->lcMoveMask & PK_X) g_print (" PK_X");
204   if (lc->lcMoveMask & PK_Y) g_print (" PK_Y");
205   if (lc->lcMoveMask & PK_Z) g_print (" PK_Z");
206   if (lc->lcMoveMask & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE");
207   if (lc->lcMoveMask & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE");
208   if (lc->lcMoveMask & PK_ORIENTATION) g_print (" PK_ORIENTATION");
209   if (lc->lcMoveMask & PK_ROTATION) g_print (" PK_ROTATION");
210   g_print ("\n");
211   g_print ("lcBtnDnMask = %#x, lcBtnUpMask = %#x\n",
212           (guint) lc->lcBtnDnMask, (guint) lc->lcBtnUpMask);
213   g_print ("lcInOrgX = %ld, lcInOrgY = %ld, lcInOrgZ = %ld\n",
214           lc->lcInOrgX, lc->lcInOrgY, lc->lcInOrgZ);
215   g_print ("lcInExtX = %ld, lcInExtY = %ld, lcInExtZ = %ld\n",
216           lc->lcInExtX, lc->lcInExtY, lc->lcInExtZ);
217   g_print ("lcOutOrgX = %ld, lcOutOrgY = %ld, lcOutOrgZ = %ld\n",
218           lc->lcOutOrgX, lc->lcOutOrgY, lc->lcOutOrgZ);
219   g_print ("lcOutExtX = %ld, lcOutExtY = %ld, lcOutExtZ = %ld\n",
220           lc->lcOutExtX, lc->lcOutExtY, lc->lcOutExtZ);
221   g_print ("lcSensX = %g, lcSensY = %g, lcSensZ = %g\n",
222           lc->lcSensX / 65536., lc->lcSensY / 65536., lc->lcSensZ / 65536.);
223   g_print ("lcSysMode = %d\n", lc->lcSysMode);
224   g_print ("lcSysOrgX = %d, lcSysOrgY = %d\n",
225           lc->lcSysOrgX, lc->lcSysOrgY);
226   g_print ("lcSysExtX = %d, lcSysExtY = %d\n",
227           lc->lcSysExtX, lc->lcSysExtY);
228   g_print ("lcSysSensX = %g, lcSysSensY = %g\n",
229           lc->lcSysSensX / 65536., lc->lcSysSensY / 65536.);
230 }
231
232 static void
233 print_cursor (int index)
234 {
235   int size;
236   int i;
237   char *name;
238   BOOL active;
239   WTPKT wtpkt;
240   BYTE buttons;
241   BYTE buttonbits;
242   char *btnnames;
243   char *p;
244   BYTE buttonmap[32];
245   BYTE sysbtnmap[32];
246   BYTE npbutton;
247   UINT npbtnmarks[2];
248   UINT *npresponse;
249   BYTE tpbutton;
250   UINT tpbtnmarks[2];
251   UINT *tpresponse;
252   DWORD physid;
253   UINT mode;
254   UINT minpktdata;
255   UINT minbuttons;
256   UINT capabilities;
257
258   size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, NULL);
259   name = g_malloc (size + 1);
260   (*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, name);
261   g_print ("NAME: %s\n", name);
262   (*p_WTInfoA) (WTI_CURSORS + index, CSR_ACTIVE, &active);
263   g_print ("ACTIVE: %s\n", active ? "YES" : "NO");
264   (*p_WTInfoA) (WTI_CURSORS + index, CSR_PKTDATA, &wtpkt);
265   g_print ("PKTDATA: %#x:", (guint) wtpkt);
266 #define BIT(x) if (wtpkt & PK_##x) g_print (" " #x)
267   BIT (CONTEXT);
268   BIT (STATUS);
269   BIT (TIME);
270   BIT (CHANGED);
271   BIT (SERIAL_NUMBER);
272   BIT (BUTTONS);
273   BIT (X);
274   BIT (Y);
275   BIT (Z);
276   BIT (NORMAL_PRESSURE);
277   BIT (TANGENT_PRESSURE);
278   BIT (ORIENTATION);
279   BIT (ROTATION);
280 #undef BIT
281   g_print ("\n");
282   (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONS, &buttons);
283   g_print ("BUTTONS: %d\n", buttons);
284   (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONBITS, &buttonbits);
285   g_print ("BUTTONBITS: %d\n", buttonbits);
286   size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, NULL);
287   g_print ("BTNNAMES:");
288   if (size > 0)
289     {
290       btnnames = g_malloc (size + 1);
291       (*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, btnnames);
292       p = btnnames;
293       while (*p)
294         {
295           g_print (" %s", p);
296           p += strlen (p) + 1;
297         }
298     }
299   g_print ("\n");
300   (*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONMAP, buttonmap);
301   g_print ("BUTTONMAP:");
302   for (i = 0; i < buttons; i++)
303     g_print (" %d", buttonmap[i]);
304   g_print ("\n");
305   (*p_WTInfoA) (WTI_CURSORS + index, CSR_SYSBTNMAP, sysbtnmap);
306   g_print ("SYSBTNMAP:");
307   for (i = 0; i < buttons; i++)
308     g_print (" %d", sysbtnmap[i]);
309   g_print ("\n");
310   (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBUTTON, &npbutton);
311   g_print ("NPBUTTON: %d\n", npbutton);
312   (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBTNMARKS, npbtnmarks);
313   g_print ("NPBTNMARKS: %d %d\n", npbtnmarks[0], npbtnmarks[1]);
314   size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, NULL);
315   g_print ("NPRESPONSE:");
316   if (size > 0)
317     {
318       npresponse = g_malloc (size);
319       (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, npresponse);
320       for (i = 0; i < size / sizeof (UINT); i++)
321         g_print (" %d", npresponse[i]);
322     }
323   g_print ("\n");
324   (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBUTTON, &tpbutton);
325   g_print ("TPBUTTON: %d\n", tpbutton);
326   (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBTNMARKS, tpbtnmarks);
327   g_print ("TPBTNMARKS: %d %d\n", tpbtnmarks[0], tpbtnmarks[1]);
328   size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, NULL);
329   g_print ("TPRESPONSE:");
330   if (size > 0)
331     {
332       tpresponse = g_malloc (size);
333       (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, tpresponse);
334       for (i = 0; i < size / sizeof (UINT); i++)
335         g_print (" %d", tpresponse[i]);
336     }
337   g_print ("\n");
338   (*p_WTInfoA) (WTI_CURSORS + index, CSR_PHYSID, &physid);
339   g_print ("PHYSID: %#x\n", (guint) physid);
340   (*p_WTInfoA) (WTI_CURSORS + index, CSR_CAPABILITIES, &capabilities);
341   g_print ("CAPABILITIES: %#x:", capabilities);
342 #define BIT(x) if (capabilities & CRC_##x) g_print (" " #x)
343   BIT (MULTIMODE);
344   BIT (AGGREGATE);
345   BIT (INVERT);
346 #undef BIT
347   g_print ("\n");
348   if (capabilities & CRC_MULTIMODE)
349     {
350       (*p_WTInfoA) (WTI_CURSORS + index, CSR_MODE, &mode);
351       g_print ("MODE: %d\n", mode);
352     }
353   if (capabilities & CRC_AGGREGATE)
354     {
355       (*p_WTInfoA) (WTI_CURSORS + index, CSR_MINPKTDATA, &minpktdata);
356       g_print ("MINPKTDATA: %d\n", minpktdata);
357       (*p_WTInfoA) (WTI_CURSORS + index, CSR_MINBUTTONS, &minbuttons);
358       g_print ("MINBUTTONS: %d\n", minbuttons);
359     }
360 }
361 #endif
362
363 static void
364 _gdk_input_wintab_init_check (GdkDeviceManagerWin32 *device_manager)
365 {
366   static gboolean wintab_initialized = FALSE;
367   GdkDeviceWintab *device;
368   GdkWindowAttr wa;
369   WORD specversion;
370   HCTX *hctx;
371   UINT ndevices, ncursors, ncsrtypes, firstcsr, hardware;
372   BOOL active;
373   DWORD physid;
374   AXIS axis_x, axis_y, axis_npressure, axis_or[3];
375   int i, devix, cursorix, num_axes = 0;
376   wchar_t devname[100], csrname[100];
377   gchar *devname_utf8, *csrname_utf8, *device_name;
378   BOOL defcontext_done;
379   HMODULE wintab32;
380   char *wintab32_dll_path;
381   char dummy;
382   int n, k;
383
384   if (wintab_initialized)
385     return;
386
387   wintab_initialized = TRUE;
388
389   wintab_contexts = NULL;
390
391   if (_gdk_input_ignore_wintab)
392     return;
393
394   n = GetSystemDirectory (&dummy, 0);
395
396   if (n <= 0)
397     return;
398
399   wintab32_dll_path = g_malloc (n + 1 + strlen (WINTAB32_DLL));
400   k = GetSystemDirectory (wintab32_dll_path, n);
401   
402   if (k == 0 || k > n)
403     {
404       g_free (wintab32_dll_path);
405       return;
406     }
407
408   if (!G_IS_DIR_SEPARATOR (wintab32_dll_path[strlen (wintab32_dll_path) -1]))
409     strcat (wintab32_dll_path, G_DIR_SEPARATOR_S);
410   strcat (wintab32_dll_path, WINTAB32_DLL);
411
412   if ((wintab32 = LoadLibrary (wintab32_dll_path)) == NULL)
413     return;
414
415   if ((p_WTInfoA = (t_WTInfoA) GetProcAddress (wintab32, "WTInfoA")) == NULL)
416     return;
417   if ((p_WTInfoW = (t_WTInfoW) GetProcAddress (wintab32, "WTInfoW")) == NULL)
418     return;
419   if ((p_WTEnable = (t_WTEnable) GetProcAddress (wintab32, "WTEnable")) == NULL)
420     return;
421   if ((p_WTOpenA = (t_WTOpenA) GetProcAddress (wintab32, "WTOpenA")) == NULL)
422     return;
423   if ((p_WTOverlap = (t_WTOverlap) GetProcAddress (wintab32, "WTOverlap")) == NULL)
424     return;
425   if ((p_WTPacket = (t_WTPacket) GetProcAddress (wintab32, "WTPacket")) == NULL)
426     return;
427   if ((p_WTQueueSizeSet = (t_WTQueueSizeSet) GetProcAddress (wintab32, "WTQueueSizeSet")) == NULL)
428     return;
429
430   if (!(*p_WTInfoA) (0, 0, NULL))
431     return;
432
433   (*p_WTInfoA) (WTI_INTERFACE, IFC_SPECVERSION, &specversion);
434   GDK_NOTE (INPUT, g_print ("Wintab interface version %d.%d\n",
435                             HIBYTE (specversion), LOBYTE (specversion)));
436   (*p_WTInfoA) (WTI_INTERFACE, IFC_NDEVICES, &ndevices);
437   (*p_WTInfoA) (WTI_INTERFACE, IFC_NCURSORS, &ncursors);
438 #if DEBUG_WINTAB
439   GDK_NOTE (INPUT, g_print ("NDEVICES: %d, NCURSORS: %d\n",
440                             ndevices, ncursors));
441 #endif
442   /* Create a dummy window to receive wintab events */
443   wa.wclass = GDK_INPUT_OUTPUT;
444   wa.event_mask = GDK_ALL_EVENTS_MASK;
445   wa.width = 2;
446   wa.height = 2;
447   wa.x = -100;
448   wa.y = -100;
449   wa.window_type = GDK_WINDOW_TOPLEVEL;
450   if ((wintab_window = gdk_window_new (NULL, &wa, GDK_WA_X|GDK_WA_Y)) == NULL)
451     {
452       g_warning ("gdk_input_wintab_init: gdk_window_new failed");
453       return;
454     }
455   g_object_ref (wintab_window);
456
457   for (devix = 0; devix < ndevices; devix++)
458     {
459       LOGCONTEXT lc;
460
461       /* We open the Wintab device (hmm, what if there are several, or
462        * can there even be several, probably not?) as a system
463        * pointing device, i.e. it controls the normal Windows
464        * cursor. This seems much more natural.
465        */
466
467       (*p_WTInfoW) (WTI_DEVICES + devix, DVC_NAME, devname);
468       devname_utf8 = g_utf16_to_utf8 (devname, -1, NULL, NULL, NULL);
469 #ifdef DEBUG_WINTAB
470       GDK_NOTE (INPUT, (g_print("Device %d: %s\n", devix, devname_utf8)));
471 #endif
472       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NCSRTYPES, &ncsrtypes);
473       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_FIRSTCSR, &firstcsr);
474       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_HARDWARE, &hardware);
475       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_X, &axis_x);
476       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_Y, &axis_y);
477       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_NPRESSURE, &axis_npressure);
478       (*p_WTInfoA) (WTI_DEVICES + devix, DVC_ORIENTATION, axis_or);
479
480       defcontext_done = FALSE;
481       if (HIBYTE (specversion) > 1 || LOBYTE (specversion) >= 1)
482         {
483           /* Try to get device-specific default context */
484           /* Some drivers, e.g. Aiptek, don't provide this info */
485           if ((*p_WTInfoA) (WTI_DSCTXS + devix, 0, &lc) > 0)
486             defcontext_done = TRUE;
487 #if DEBUG_WINTAB
488           if (defcontext_done)
489             GDK_NOTE (INPUT, (g_print("Using device-specific default context\n")));
490           else
491             GDK_NOTE (INPUT, (g_print("Note: Driver did not provide device specific default context info despite claiming to support version 1.1\n")));
492 #endif
493         }
494
495       if (!defcontext_done)
496         (*p_WTInfoA) (WTI_DEFSYSCTX, 0, &lc);
497 #if DEBUG_WINTAB
498       GDK_NOTE (INPUT, (g_print("Default context:\n"), print_lc(&lc)));
499 #endif
500       lc.lcOptions |= CXO_MESSAGES;
501       lc.lcStatus = 0;
502       lc.lcMsgBase = WT_DEFBASE;
503       lc.lcPktRate = 0;
504       lc.lcPktData = PACKETDATA;
505       lc.lcPktMode = PACKETMODE;
506       lc.lcMoveMask = PACKETDATA;
507       lc.lcBtnUpMask = lc.lcBtnDnMask = ~0;
508       lc.lcOutOrgX = axis_x.axMin;
509       lc.lcOutOrgY = axis_y.axMin;
510       lc.lcOutExtX = axis_x.axMax - axis_x.axMin;
511       lc.lcOutExtY = axis_y.axMax - axis_y.axMin;
512       lc.lcOutExtY = -lc.lcOutExtY; /* We want Y growing downward */
513 #if DEBUG_WINTAB
514       GDK_NOTE (INPUT, (g_print("context for device %d:\n", devix),
515                         print_lc(&lc)));
516 #endif
517       hctx = g_new (HCTX, 1);
518       if ((*hctx = (*p_WTOpenA) (GDK_WINDOW_HWND (wintab_window), &lc, TRUE)) == NULL)
519         {
520           g_warning ("gdk_input_wintab_init: WTOpen failed");
521           return;
522         }
523       GDK_NOTE (INPUT, g_print ("opened Wintab device %d %p\n",
524                                 devix, *hctx));
525
526       wintab_contexts = g_list_append (wintab_contexts, hctx);
527 #if 0
528       (*p_WTEnable) (*hctx, TRUE);
529 #endif
530       (*p_WTOverlap) (*hctx, TRUE);
531
532 #if DEBUG_WINTAB
533       GDK_NOTE (INPUT, (g_print("context for device %d after WTOpen:\n", devix),
534                         print_lc(&lc)));
535 #endif
536       /* Increase packet queue size to reduce the risk of lost packets.
537        * According to the specs, if the function fails we must try again
538        * with a smaller queue size.
539        */
540       GDK_NOTE (INPUT, g_print("Attempting to increase queue size\n"));
541       for (i = 32; i >= 1; i >>= 1)
542         {
543           if ((*p_WTQueueSizeSet) (*hctx, i))
544             {
545               GDK_NOTE (INPUT, g_print("Queue size set to %d\n", i));
546               break;
547             }
548         }
549       if (!i)
550         GDK_NOTE (INPUT, g_print("Whoops, no queue size could be set\n"));
551       for (cursorix = firstcsr; cursorix < firstcsr + ncsrtypes; cursorix++)
552         {
553 #ifdef DEBUG_WINTAB
554           GDK_NOTE (INPUT, (g_print("Cursor %d:\n", cursorix), print_cursor (cursorix)));
555 #endif
556           active = FALSE;
557           (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_ACTIVE, &active);
558           if (!active)
559             continue;
560
561           /* Wacom tablets seem to report cursors corresponding to
562            * nonexistent pens or pucks. At least my ArtPad II reports
563            * six cursors: a puck, pressure stylus and eraser stylus,
564            * and then the same three again. I only have a
565            * pressure-sensitive pen. The puck instances, and the
566            * second instances of the styluses report physid zero. So
567            * at least for Wacom, skip cursors with physid zero.
568            */
569           (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid);
570           if (wcscmp (devname, L"WACOM Tablet") == 0 && physid == 0)
571             continue;
572
573           (*p_WTInfoW) (WTI_CURSORS + cursorix, CSR_NAME, csrname);
574           csrname_utf8 = g_utf16_to_utf8 (csrname, -1, NULL, NULL, NULL);
575           device_name = g_strconcat (devname_utf8, " ", csrname_utf8, NULL);
576
577           device = g_object_new (GDK_TYPE_DEVICE_WINTAB,
578                                  "name", device_name,
579                                  "type", GDK_DEVICE_TYPE_SLAVE,
580                                  "source", GDK_SOURCE_PEN,
581                                  "mode", GDK_MODE_SCREEN,
582                                  "has-cursor", FALSE,
583                                  "display", _gdk_display,
584                                  "device-manager", device_manager,
585                                  NULL);
586
587           g_free (csrname_utf8);
588
589           device->hctx = *hctx;
590           device->cursor = cursorix;
591           (*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PKTDATA, &device->pktdata);
592
593           if (device->pktdata & PK_X)
594             {
595               _gdk_device_add_axis (GDK_DEVICE (device),
596                                     GDK_NONE,
597                                     GDK_AXIS_X,
598                                     axis_x.axMin,
599                                     axis_x.axMax,
600                                     axis_x.axResolution / 65535);
601               num_axes++;
602             }
603
604           if (device->pktdata & PK_Y)
605             {
606               _gdk_device_add_axis (GDK_DEVICE (device),
607                                     GDK_NONE,
608                                     GDK_AXIS_Y,
609                                     axis_y.axMin,
610                                     axis_y.axMax,
611                                     axis_y.axResolution / 65535);
612               num_axes++;
613             }
614
615
616           if (device->pktdata & PK_NORMAL_PRESSURE)
617             {
618               _gdk_device_add_axis (GDK_DEVICE (device),
619                                     GDK_NONE,
620                                     GDK_AXIS_PRESSURE,
621                                     axis_npressure.axMin,
622                                     axis_npressure.axMax,
623                                     axis_npressure.axResolution / 65535);
624               num_axes++;
625             }
626
627           /* The wintab driver for the Wacom ArtPad II reports
628            * PK_ORIENTATION in CSR_PKTDATA, but the tablet doesn't
629            * actually sense tilt. Catch this by noticing that the
630            * orientation axis's azimuth resolution is zero.
631            */
632           if ((device->pktdata & PK_ORIENTATION) && axis_or[0].axResolution == 0)
633             {
634               device->orientation_axes[0] = axis_or[0];
635               device->orientation_axes[1] = axis_or[1];
636
637               /* Wintab gives us aximuth and altitude, which
638                * we convert to x and y tilt in the -1000..1000 range
639                */
640               _gdk_device_add_axis (GDK_DEVICE (device),
641                                     GDK_NONE,
642                                     GDK_AXIS_XTILT,
643                                     -1000,
644                                     1000,
645                                     1000);
646
647               _gdk_device_add_axis (GDK_DEVICE (device),
648                                     GDK_NONE,
649                                     GDK_AXIS_YTILT,
650                                     -1000,
651                                     1000,
652                                     1000);
653               num_axes += 2;
654             }
655
656           device->last_axis_data = g_new (gint, num_axes);
657
658           GDK_NOTE (INPUT, g_print ("device: (%d) %s axes: %d\n",
659                                     cursorix,
660                                     device_name,
661                                     num_axes));
662
663 #if 0
664           for (i = 0; i < gdkdev->info.num_axes; i++)
665             GDK_NOTE (INPUT, g_print ("... axis %d: %d--%d@%d\n",
666                                       i,
667                                       gdkdev->axes[i].min_value,
668                                       gdkdev->axes[i].max_value,
669                                       gdkdev->axes[i].resolution));
670 #endif
671
672           device_manager->wintab_devices = g_list_append (device_manager->wintab_devices,
673                                                           device);
674
675           g_free (device_name);
676         }
677
678       g_free (devname_utf8);
679     }
680 }
681
682 static void
683 gdk_device_manager_win32_constructed (GObject *object)
684 {
685   GdkDeviceManagerWin32 *device_manager;
686
687   device_manager = GDK_DEVICE_MANAGER_WIN32 (object);
688   device_manager->core_pointer = create_core_pointer (GDK_DEVICE_MANAGER (device_manager));
689   device_manager->core_keyboard = create_core_keyboard (GDK_DEVICE_MANAGER (device_manager));
690
691   _gdk_device_set_associated_device (device_manager->core_pointer, device_manager->core_keyboard);
692   _gdk_device_set_associated_device (device_manager->core_keyboard, device_manager->core_pointer);
693
694   _gdk_input_wintab_init_check (device_manager);
695 }
696
697 static GList *
698 gdk_device_manager_win32_list_devices (GdkDeviceManager *device_manager,
699                                        GdkDeviceType     type)
700 {
701   GdkDeviceManagerWin32 *device_manager_win32;
702   GList *devices = NULL;
703
704   device_manager_win32 = (GdkDeviceManagerWin32 *) device_manager;
705
706   if (type == GDK_DEVICE_TYPE_MASTER)
707     {
708       devices = g_list_prepend (devices, device_manager_win32->core_keyboard);
709       devices = g_list_prepend (devices, device_manager_win32->core_pointer);
710     }
711   else if (type == GDK_DEVICE_TYPE_FLOATING)
712     devices = g_list_copy (device_manager_win32->wintab_devices);
713
714   return devices;
715 }
716
717 static GdkDevice *
718 gdk_device_manager_win32_get_client_pointer (GdkDeviceManager *device_manager)
719 {
720   GdkDeviceManagerWin32 *device_manager_win32;
721
722   device_manager_win32 = (GdkDeviceManagerWin32 *) device_manager;
723   return device_manager_win32->core_pointer;
724 }
725
726 void
727 _gdk_input_set_tablet_active (void)
728 {
729   GList *tmp_list;
730   HCTX *hctx;
731
732   /* Bring the contexts to the top of the overlap order when one of the
733    * application's windows is activated */
734
735   if (!wintab_contexts)
736     return; /* No tablet devices found, or Wintab not initialized yet */
737
738   GDK_NOTE (INPUT, g_print ("_gdk_input_set_tablet_active: "
739                             "Bringing Wintab contexts to the top of the overlap order\n"));
740
741   tmp_list = wintab_contexts;
742
743   while (tmp_list)
744     {
745       hctx = (HCTX *) (tmp_list->data);
746       (*p_WTOverlap) (*hctx, TRUE);
747       tmp_list = tmp_list->next;
748     }
749 }
750
751 static void
752 decode_tilt (gint   *axis_data,
753              AXIS   *axes,
754              PACKET *packet)
755 {
756   double az, el;
757
758   /* As I don't have a tilt-sensing tablet,
759    * I cannot test this code.
760    */
761   az = TWOPI * packet->pkOrientation.orAzimuth /
762     (axes[0].axResolution / 65536.);
763   el = TWOPI * packet->pkOrientation.orAltitude /
764     (axes[1].axResolution / 65536.);
765
766   /* X tilt */
767   axis_data[0] = cos (az) * cos (el) * 1000;
768   /* Y tilt */
769   axis_data[1] = sin (az) * cos (el) * 1000;
770 }
771
772 /*
773  * Get the currently active keyboard modifiers (ignoring the mouse buttons)
774  * We could use gdk_window_get_pointer but that function does a lot of other
775  * expensive things besides getting the modifiers. This code is somewhat based
776  * on build_pointer_event_state from gdkevents-win32.c
777  */
778 static guint
779 get_modifier_key_state (void)
780 {
781   guint state;
782
783   state = 0;
784   /* High-order bit is up/down, low order bit is toggled/untoggled */
785   if (GetKeyState (VK_CONTROL) < 0)
786     state |= GDK_CONTROL_MASK;
787   if (GetKeyState (VK_SHIFT) < 0)
788     state |= GDK_SHIFT_MASK;
789   if (GetKeyState (VK_MENU) < 0)
790     state |= GDK_MOD1_MASK;
791   if (GetKeyState (VK_CAPITAL) & 0x1)
792     state |= GDK_LOCK_MASK;
793
794   return state;
795 }
796
797 static gboolean
798 ignore_core_timefunc (gpointer data)
799 {
800   /* The delay has passed */
801   _gdk_input_ignore_core = FALSE;
802   ignore_core_timer = 0;
803
804   return FALSE; /* remove timeout */
805 }
806
807 /*
808  * Set or unset the _gdk_input_ignore_core variable that tells GDK
809  * to ignore events for the core pointer when the tablet is in proximity
810  * The unsetting is delayed slightly so that if a tablet event arrives
811  * just after proximity out, it does not cause a core pointer event
812  * which e.g. causes GIMP to switch tools.
813  */
814 static void
815 set_ignore_core (gboolean ignore)
816 {
817   if (ignore)
818     {
819       _gdk_input_ignore_core = TRUE;
820       /* Remove any pending clear */
821       if (ignore_core_timer)
822         {
823           g_source_remove (ignore_core_timer);
824           ignore_core_timer = 0;
825         }
826     }
827   else if (!ignore_core_timer)
828     ignore_core_timer = gdk_threads_add_timeout (PROXIMITY_OUT_DELAY,
829                                                  ignore_core_timefunc, NULL);
830 }
831
832 static GdkDeviceWintab *
833 _gdk_device_manager_find_wintab_device (HCTX hctx,
834                                         UINT cursor)
835 {
836   GdkDeviceManagerWin32 *device_manager;
837   GdkDeviceWintab *device;
838   GList *tmp_list;
839
840   device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (_gdk_display));
841   tmp_list = device_manager->wintab_devices;
842
843   while (tmp_list)
844     {
845       device = tmp_list->data;
846       tmp_list = tmp_list->next;
847
848       if (device->hctx == hctx &&
849           device->cursor == cursor)
850         return device;
851     }
852
853   return NULL;
854 }
855
856 gboolean
857 _gdk_input_other_event (GdkEvent  *event,
858                         MSG       *msg,
859                         GdkWindow *window)
860 {
861   GdkDisplay *display;
862   GdkDeviceWintab *device = NULL;
863   GdkDeviceGrabInfo *last_grab;
864   GdkEventMask masktest;
865   guint key_state;
866   POINT pt;
867
868   PACKET packet;
869   gdouble root_x, root_y;
870   gint num_axes;
871   gint x, y;
872   guint translated_buttons, button_diff, button_mask;
873   /* Translation from tablet button state to GDK button state for
874    * buttons 1-3 - swap button 2 and 3.
875    */
876   static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7};
877
878   if (event->any.window != wintab_window)
879     {
880       g_warning ("_gdk_input_other_event: not wintab_window?");
881       return FALSE;
882     }
883
884   window = gdk_window_at_pointer (&x, &y);
885   if (window == NULL)
886     window = _gdk_root;
887
888   g_object_ref (window);
889   display = gdk_window_get_display (window);
890
891   GDK_NOTE (EVENTS_OR_INPUT,
892             g_print ("_gdk_input_other_event: window=%p %+d%+d\n",
893                GDK_WINDOW_HWND (window), x, y));
894
895   if (msg->message == WT_PACKET)
896     {
897       if (!(*p_WTPacket) ((HCTX) msg->lParam, msg->wParam, &packet))
898         return FALSE;
899     }
900
901   switch (msg->message)
902     {
903     case WT_PACKET:
904       /* Don't produce any button or motion events while a window is being
905        * moved or resized, see bug #151090.
906        */
907       if (_modal_operation_in_progress)
908         {
909           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... ignored when moving/sizing\n"));
910           return FALSE;
911         }
912
913       if ((device = _gdk_device_manager_find_wintab_device ((HCTX) msg->lParam,
914                                                             packet.pkCursor)) == NULL)
915         return FALSE;
916
917       if (gdk_device_get_mode (GDK_DEVICE (device)) == GDK_MODE_DISABLED)
918         return FALSE;
919
920       last_grab = _gdk_display_get_last_device_grab (_gdk_display, GDK_DEVICE (device));
921
922       if (last_grab && last_grab->window)
923         {
924           g_object_unref (window);
925
926           window = g_object_ref (last_grab->window);
927         }
928
929       if (window == _gdk_root)
930         {
931           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n"));
932           return FALSE;
933         }
934
935       num_axes = 0;
936       if (device->pktdata & PK_X)
937         device->last_axis_data[num_axes++] = packet.pkX;
938       if (device->pktdata & PK_Y)
939         device->last_axis_data[num_axes++] = packet.pkY;
940       if (device->pktdata & PK_NORMAL_PRESSURE)
941         device->last_axis_data[num_axes++] = packet.pkNormalPressure;
942       if (device->pktdata & PK_ORIENTATION)
943         {
944           decode_tilt (device->last_axis_data + num_axes,
945                        device->orientation_axes, &packet);
946           num_axes += 2;
947         }
948
949       translated_buttons = button_map[packet.pkButtons & 0x07] | (packet.pkButtons & ~0x07);
950
951       if (translated_buttons != device->button_state)
952         {
953           /* At least one button has changed state so produce a button event
954            * If more than one button has changed state (unlikely),
955            * just care about the first and act on the next the next time
956            * we get a packet
957            */
958           button_diff = translated_buttons ^ device->button_state;
959
960           /* Gdk buttons are numbered 1.. */
961           event->button.button = 1;
962
963           for (button_mask = 1; button_mask != 0x80000000;
964                button_mask <<= 1, event->button.button++)
965             {
966               if (button_diff & button_mask)
967                 {
968                   /* Found a button that has changed state */
969                   break;
970                 }
971             }
972
973           if (!(translated_buttons & button_mask))
974             {
975               event->any.type = GDK_BUTTON_RELEASE;
976               masktest = GDK_BUTTON_RELEASE_MASK;
977             }
978           else
979             {
980               event->any.type = GDK_BUTTON_PRESS;
981               masktest = GDK_BUTTON_PRESS_MASK;
982             }
983           device->button_state ^= button_mask;
984         }
985       else
986         {
987           event->any.type = GDK_MOTION_NOTIFY;
988           masktest = GDK_POINTER_MOTION_MASK;
989           if (device->button_state & (1 << 0))
990             masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK;
991           if (device->button_state & (1 << 1))
992             masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON2_MOTION_MASK;
993           if (device->button_state & (1 << 2))
994             masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON3_MOTION_MASK;
995         }
996
997       /* Now we can check if the window wants the event, and
998        * propagate if necessary.
999        */
1000       while (gdk_window_get_device_events (window, GDK_DEVICE (device)) == 0)
1001         {
1002           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... not selected\n"));
1003
1004           if (window->parent == GDK_WINDOW (_gdk_root))
1005             return FALSE;
1006
1007           /* It is not good to propagate the extended events up to the parent
1008            * if this window wants normal (not extended) motion/button events */
1009           if (window->event_mask & masktest)
1010             {
1011               GDK_NOTE (EVENTS_OR_INPUT,
1012                         g_print ("... wants ordinary event, ignoring this\n"));
1013               return FALSE;
1014             }
1015
1016           pt.x = x;
1017           pt.y = y;
1018           ClientToScreen (GDK_WINDOW_HWND (window), &pt);
1019           g_object_unref (window);
1020           window = window->parent;
1021           g_object_ref (window);
1022           ScreenToClient (GDK_WINDOW_HWND (window), &pt);
1023           x = pt.x;
1024           y = pt.y;
1025           GDK_NOTE (EVENTS_OR_INPUT, g_print ("... propagating to %p %+d%+d\n",
1026                                               GDK_WINDOW_HWND (window), x, y));
1027         }
1028
1029       if (gdk_window_get_device_events (window, GDK_DEVICE (device)) == 0)
1030         return FALSE;
1031
1032       event->any.window = window;
1033       key_state = get_modifier_key_state ();
1034       if (event->any.type == GDK_BUTTON_PRESS ||
1035           event->any.type == GDK_BUTTON_RELEASE)
1036         {
1037           event->button.time = _gdk_win32_get_next_tick (msg->time);
1038           gdk_event_set_device (event, GDK_DEVICE (device));
1039
1040           event->button.axes = g_new (gdouble, num_axes);
1041           _gdk_device_wintab_get_window_coords (window, &root_x, &root_y);
1042
1043           _gdk_device_wintab_translate_axes (device,
1044                                              window,
1045                                              event->button.axes,
1046                                              &event->button.x,
1047                                              &event->button.y);
1048
1049           event->button.x_root = event->button.x + root_x;
1050           event->button.y_root = event->button.y + root_y;
1051
1052           event->button.state =
1053             key_state | ((device->button_state << 8)
1054                          & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
1055                             | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
1056                             | GDK_BUTTON5_MASK));
1057
1058           GDK_NOTE (EVENTS_OR_INPUT,
1059                     g_print ("WINTAB button %s:%d %g,%g\n",
1060                              (event->button.type == GDK_BUTTON_PRESS ?
1061                               "press" : "release"),
1062                              event->button.button,
1063                              event->button.x, event->button.y));
1064         }
1065       else
1066         {
1067           event->motion.time = _gdk_win32_get_next_tick (msg->time);
1068           event->motion.is_hint = FALSE;
1069           gdk_event_set_device (event, GDK_DEVICE (device));
1070
1071           event->motion.axes = g_new (gdouble, num_axes);
1072           _gdk_device_wintab_get_window_coords (window, &root_x, &root_y);
1073
1074           _gdk_device_wintab_translate_axes (device,
1075                                              window,
1076                                              event->motion.axes,
1077                                              &event->motion.x,
1078                                              &event->motion.y);
1079
1080           event->motion.x_root = event->motion.x + root_x;
1081           event->motion.y_root = event->motion.y + root_y;
1082
1083           event->motion.state =
1084             key_state | ((device->button_state << 8)
1085                          & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK
1086                             | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK
1087                             | GDK_BUTTON5_MASK));
1088
1089           GDK_NOTE (EVENTS_OR_INPUT,
1090                     g_print ("WINTAB motion: %g,%g\n",
1091                              event->motion.x, event->motion.y));
1092         }
1093       return TRUE;
1094
1095     case WT_PROXIMITY:
1096       if (LOWORD (msg->lParam) == 0)
1097         {
1098           event->proximity.type = GDK_PROXIMITY_OUT;
1099           set_ignore_core (FALSE);
1100         }
1101       else
1102         {
1103           event->proximity.type = GDK_PROXIMITY_IN;
1104           set_ignore_core (TRUE);
1105         }
1106       event->proximity.time = _gdk_win32_get_next_tick (msg->time);
1107       gdk_event_set_device (event, GDK_DEVICE (device));
1108
1109       GDK_NOTE (EVENTS_OR_INPUT,
1110                 g_print ("WINTAB proximity %s\n",
1111                          (event->proximity.type == GDK_PROXIMITY_IN ?
1112                           "in" : "out")));
1113       return TRUE;
1114     }
1115
1116   return FALSE;
1117 }