webservices: Don't allocate an XML buffer until it is needed.
[wine.git] / dlls / winex11.drv / wintab.c
blobe4259bf5eb9ab0210b14cb2aea430e1b0db8c623
1 /*
2 * X11 tablet driver
4 * Copyright 2003 CodeWeavers (Aric Stewart)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdlib.h>
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnls.h"
30 #include "x11drv.h"
31 #include "wine/library.h"
32 #include "wine/unicode.h"
33 #include "wine/debug.h"
34 #include "wintab.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(wintab32);
38 #define WT_MAX_NAME_LEN 256
40 typedef struct tagWTI_CURSORS_INFO
42 WCHAR NAME[WT_MAX_NAME_LEN];
43 /* a displayable zero-terminated string containing the name of the
44 * cursor.
46 BOOL ACTIVE;
47 /* whether the cursor is currently connected. */
48 WTPKT PKTDATA;
49 /* a bit mask indicating the packet data items supported when this
50 * cursor is connected.
52 BYTE BUTTONS;
53 /* the number of buttons on this cursor. */
54 BYTE BUTTONBITS;
55 /* the number of bits of raw button data returned by the hardware.*/
56 DWORD cchBTNNAMES;
57 WCHAR *BTNNAMES;
58 /* a list of zero-terminated strings containing the names of the
59 * cursor's buttons. The number of names in the list is the same as the
60 * number of buttons on the cursor. The names are separated by a single
61 * zero character; the list is terminated by two zero characters.
63 BYTE BUTTONMAP[32];
64 /* a 32 byte array of logical button numbers, one for each physical
65 * button.
67 BYTE SYSBTNMAP[32];
68 /* a 32 byte array of button action codes, one for each logical
69 * button.
71 BYTE NPBUTTON;
72 /* the physical button number of the button that is controlled by normal
73 * pressure.
75 UINT NPBTNMARKS[2];
76 /* an array of two UINTs, specifying the button marks for the normal
77 * pressure button. The first UINT contains the release mark; the second
78 * contains the press mark.
80 UINT *NPRESPONSE;
81 /* an array of UINTs describing the pressure response curve for normal
82 * pressure.
84 BYTE TPBUTTON;
85 /* the physical button number of the button that is controlled by
86 * tangential pressure.
88 UINT TPBTNMARKS[2];
89 /* an array of two UINTs, specifying the button marks for the tangential
90 * pressure button. The first UINT contains the release mark; the second
91 * contains the press mark.
93 UINT *TPRESPONSE;
94 /* an array of UINTs describing the pressure response curve for
95 * tangential pressure.
97 DWORD PHYSID;
98 /* a manufacturer-specific physical identifier for the cursor. This
99 * value will distinguish the physical cursor from others on the same
100 * device. This physical identifier allows applications to bind
101 * functions to specific physical cursors, even if category numbers
102 * change and multiple, otherwise identical, physical cursors are
103 * present.
105 UINT MODE;
106 /* the cursor mode number of this cursor type, if this cursor type has
107 * the CRC_MULTIMODE capability.
109 UINT MINPKTDATA;
110 /* the minimum set of data available from a physical cursor in this
111 * cursor type, if this cursor type has the CRC_AGGREGATE capability.
113 UINT MINBUTTONS;
114 /* the minimum number of buttons of physical cursors in the cursor type,
115 * if this cursor type has the CRC_AGGREGATE capability.
117 UINT CAPABILITIES;
118 /* flags indicating cursor capabilities, as defined below:
119 CRC_MULTIMODE
120 Indicates this cursor type describes one of several modes of a
121 single physical cursor. Consecutive cursor type categories
122 describe the modes; the CSR_MODE data item gives the mode number
123 of each cursor type.
124 CRC_AGGREGATE
125 Indicates this cursor type describes several physical cursors
126 that cannot be distinguished by software.
127 CRC_INVERT
128 Indicates this cursor type describes the physical cursor in its
129 inverted orientation; the previous consecutive cursor type
130 category describes the normal orientation.
132 UINT TYPE;
133 /* Manufacturer Unique id for the item type */
134 } WTI_CURSORS_INFO, *LPWTI_CURSORS_INFO;
137 typedef struct tagWTI_DEVICES_INFO
139 WCHAR NAME[WT_MAX_NAME_LEN];
140 /* a displayable null- terminated string describing the device,
141 * manufacturer, and revision level.
143 UINT HARDWARE;
144 /* flags indicating hardware and driver capabilities, as defined
145 * below:
146 HWC_INTEGRATED:
147 Indicates that the display and digitizer share the same surface.
148 HWC_TOUCH
149 Indicates that the cursor must be in physical contact with the
150 device to report position.
151 HWC_HARDPROX
152 Indicates that device can generate events when the cursor is
153 entering and leaving the physical detection range.
154 HWC_PHYSID_CURSORS
155 Indicates that device can uniquely identify the active cursor in
156 hardware.
158 UINT NCSRTYPES;
159 /* the number of supported cursor types.*/
160 UINT FIRSTCSR;
161 /* the first cursor type number for the device. */
162 UINT PKTRATE;
163 /* the maximum packet report rate in Hertz. */
164 WTPKT PKTDATA;
165 /* a bit mask indicating which packet data items are always available.*/
166 WTPKT PKTMODE;
167 /* a bit mask indicating which packet data items are physically
168 * relative, i.e., items for which the hardware can only report change,
169 * not absolute measurement.
171 WTPKT CSRDATA;
172 /* a bit mask indicating which packet data items are only available when
173 * certain cursors are connected. The individual cursor descriptions
174 * must be consulted to determine which cursors return which data.
176 INT XMARGIN;
177 INT YMARGIN;
178 INT ZMARGIN;
179 /* the size of tablet context margins in tablet native coordinates, in
180 * the x, y, and z directions, respectively.
182 AXIS X;
183 AXIS Y;
184 AXIS Z;
185 /* the tablet's range and resolution capabilities, in the x, y, and z
186 * axes, respectively.
188 AXIS NPRESSURE;
189 AXIS TPRESSURE;
190 /* the tablet's range and resolution capabilities, for the normal and
191 * tangential pressure inputs, respectively.
193 AXIS ORIENTATION[3];
194 /* a 3-element array describing the tablet's orientation range and
195 * resolution capabilities.
197 AXIS ROTATION[3];
198 /* a 3-element array describing the tablet's rotation range and
199 * resolution capabilities.
201 WCHAR PNPID[WT_MAX_NAME_LEN];
202 /* a null-terminated string containing the devices Plug and Play ID.*/
203 } WTI_DEVICES_INFO, *LPWTI_DEVICES_INFO;
206 /***********************************************************************
207 * WACOM WINTAB EXTENSIONS TO SUPPORT CSR_TYPE
208 * In Wintab 1.2, a CSR_TYPE feature was added. This adds the
209 * ability to return a type of cursor on a tablet.
210 * Unfortunately, we cannot get the cursor type directly from X,
211 * and it is not specified directly anywhere. So we virtualize
212 * the type here. (This is unfortunate, the kernel module has
213 * the exact type, but we have no way of getting that module to
214 * pass us that type).
216 * Reference linuxwacom driver project wcmCommon.c function
217 * idtotype for a much larger list of CSR_TYPE.
219 * http://linuxwacom.cvs.sourceforge.net/linuxwacom/linuxwacom-prod/src/xdrv/wcmCommon.c?view=markup
221 * The WTI_CURSORS_INFO.TYPE data is supposed to be used like this:
222 * (cursor.TYPE & 0x0F06) == target_cursor_type
223 * Reference: Section Unique ID
224 * http://www.wacomeng.com/devsupport/ibmpc/gddevpc.html
226 #define CSR_TYPE_PEN 0x822
227 #define CSR_TYPE_ERASER 0x82a
228 #define CSR_TYPE_MOUSE_2D 0x007
229 #define CSR_TYPE_MOUSE_4D 0x094
230 /* CSR_TYPE_OTHER is a special value! assumed no real world significance
231 * if a stylus type or eraser type eventually have this value
232 * it'll be a bug. As of 2008 05 21 we can be sure because
233 * linux wacom lists all the known values and this isn't one of them */
234 #define CSR_TYPE_OTHER 0x000
236 typedef struct tagWTPACKET {
237 HCTX pkContext;
238 UINT pkStatus;
239 LONG pkTime;
240 WTPKT pkChanged;
241 UINT pkSerialNumber;
242 UINT pkCursor;
243 DWORD pkButtons;
244 DWORD pkX;
245 DWORD pkY;
246 DWORD pkZ;
247 UINT pkNormalPressure;
248 UINT pkTangentPressure;
249 ORIENTATION pkOrientation;
250 ROTATION pkRotation; /* 1.1 */
251 } WTPACKET, *LPWTPACKET;
254 #ifdef SONAME_LIBXI
256 #include <X11/Xlib.h>
257 #include <X11/extensions/XInput.h>
259 static int motion_type;
260 static int button_press_type;
261 static int button_release_type;
262 static int key_press_type;
263 static int key_release_type;
264 static int proximity_in_type;
265 static int proximity_out_type;
267 static HWND hwndTabletDefault;
268 static WTPACKET gMsgPacket;
269 static DWORD gSerial;
271 /* Reference: http://www.wacomeng.com/devsupport/ibmpc/gddevpc.html
273 * Cursors come in sets of 3 normally
274 * Cursor #0 = puck device 1
275 * Cursor #1 = stylus device 1
276 * Cursor #2 = eraser device 1
277 * Cursor #3 = puck device 2
278 * Cursor #4 = stylus device 2
279 * Cursor #5 = eraser device 2
280 * etc....
282 * A dual tracking/multimode tablet is one
283 * that supports 2 independent cursors of the same or
284 * different types simultaneously on a single tablet.
285 * This makes our cursor layout potentially like this
286 * Cursor #0 = puck 1 device 1
287 * Cursor #1 = stylus 1 device 1
288 * Cursor #2 = eraser 1 device 1
289 * Cursor #3 = puck 2 device 1
290 * Cursor #4 = stylus 2 device 1
291 * Cursor #5 = eraser 2 device 1
292 * Cursor #6 = puck 1 device 2
293 * etc.....
295 * So with multimode tablets we could potentially need
296 * 2 slots of the same type per tablet i.e.
297 * you are using 2 styluses at once so they would
298 * get placed in Cursors #1 and Cursor #4
300 * Now say someone has 2 multimode tablets with 2 erasers each
301 * now we would need Cursor #2, #5, #8, #11
302 * So to support that we need CURSORMAX of 12 (0 to 11)
303 * FIXME: we don't support more than 4 regular tablets or 2 multimode tablets */
304 #define CURSORMAX 12
305 static INT button_state[CURSORMAX];
307 static LOGCONTEXTW gSysContext;
308 static WTI_DEVICES_INFO gSysDevice;
309 static WTI_CURSORS_INFO gSysCursor[CURSORMAX];
310 static INT gNumCursors; /* do NOT use this to iterate through gSysCursor slots */
313 /* XInput stuff */
314 static void *xinput_handle;
316 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
317 MAKE_FUNCPTR(XListInputDevices)
318 MAKE_FUNCPTR(XFreeDeviceList)
319 MAKE_FUNCPTR(XOpenDevice)
320 MAKE_FUNCPTR(XQueryDeviceState)
321 MAKE_FUNCPTR(XGetDeviceButtonMapping)
322 MAKE_FUNCPTR(XCloseDevice)
323 MAKE_FUNCPTR(XSelectExtensionEvent)
324 MAKE_FUNCPTR(XFreeDeviceState)
325 #undef MAKE_FUNCPTR
327 static INT X11DRV_XInput_Init(void)
329 xinput_handle = wine_dlopen(SONAME_LIBXI, RTLD_NOW, NULL, 0);
330 if (xinput_handle)
332 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(xinput_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
333 LOAD_FUNCPTR(XListInputDevices)
334 LOAD_FUNCPTR(XFreeDeviceList)
335 LOAD_FUNCPTR(XOpenDevice)
336 LOAD_FUNCPTR(XGetDeviceButtonMapping)
337 LOAD_FUNCPTR(XCloseDevice)
338 LOAD_FUNCPTR(XSelectExtensionEvent)
339 LOAD_FUNCPTR(XQueryDeviceState)
340 LOAD_FUNCPTR(XFreeDeviceState)
341 #undef LOAD_FUNCPTR
342 return 1;
344 sym_not_found:
345 return 0;
348 static int Tablet_ErrorHandler(Display *dpy, XErrorEvent *event, void* arg)
350 return 1;
353 static void trace_axes(XValuatorInfoPtr val)
355 int i;
356 XAxisInfoPtr axis;
358 for (i = 0, axis = val->axes ; i < val->num_axes; i++, axis++)
359 TRACE(" Axis %d: [resolution %d|min_value %d|max_value %d]\n", i, axis->resolution, axis->min_value, axis->max_value);
362 static BOOL match_token(const char *haystack, const char *needle)
364 const char *p, *q;
365 for (p = haystack; *p; )
367 while (*p && isspace(*p))
368 p++;
369 if (! *p)
370 break;
372 for (q = needle; *q && *p && tolower(*p) == tolower(*q); q++)
373 p++;
374 if (! *q && (isspace(*p) || !*p))
375 return TRUE;
377 while (*p && ! isspace(*p))
378 p++;
380 return FALSE;
383 /* Determining if an X device is a Tablet style device is an imperfect science.
384 ** We rely on common conventions around device names as well as the type reported
385 ** by Wacom tablets. This code will likely need to be expanded for alternate tablet types
387 ** Wintab refers to any device that interacts with the tablet as a cursor,
388 ** (stylus, eraser, tablet mouse, airbrush, etc)
389 ** this is not to be confused with wacom x11 configuration "cursor" device.
390 ** Wacoms x11 config "cursor" refers to its device slot (which we mirror with
391 ** our gSysCursors) for puck like devices (tablet mice essentially).
394 static BOOL is_tablet_cursor(const char *name, const char *type)
396 int i;
397 static const char *tablet_cursor_whitelist[] = {
398 "wacom",
399 "wizardpen",
400 "acecad",
401 "tablet",
402 "cursor",
403 "stylus",
404 "eraser",
405 "pad",
406 NULL
409 for (i=0; tablet_cursor_whitelist[i] != NULL; i++) {
410 if (name && match_token(name, tablet_cursor_whitelist[i]))
411 return TRUE;
412 if (type && match_token(type, tablet_cursor_whitelist[i]))
413 return TRUE;
415 return FALSE;
418 static UINT get_cursor_type(const char *name, const char *type)
420 int i;
421 static const char* tablet_stylus_whitelist[] = {
422 "stylus",
423 "wizardpen",
424 "acecad",
425 "pen",
426 NULL
429 /* First check device type to avoid cases where name is "Pen and Eraser" and type is "ERASER" */
430 for (i=0; tablet_stylus_whitelist[i] != NULL; i++) {
431 if (type && match_token(type, tablet_stylus_whitelist[i]))
432 return CSR_TYPE_PEN;
434 if (type && match_token(type, "eraser"))
435 return CSR_TYPE_ERASER;
436 for (i=0; tablet_stylus_whitelist[i] != NULL; i++) {
437 if (name && match_token(name, tablet_stylus_whitelist[i]))
438 return CSR_TYPE_PEN;
440 if (name && match_token(name, "eraser"))
441 return CSR_TYPE_ERASER;
443 return CSR_TYPE_OTHER;
446 /* cursors are placed in gSysCursor rows depending on their type
447 * see CURSORMAX comments for more detail */
448 static BOOL add_system_cursor(LPWTI_CURSORS_INFO cursor)
450 UINT offset = 0;
452 if (cursor->TYPE == CSR_TYPE_PEN)
453 offset = 1;
454 else if (cursor->TYPE == CSR_TYPE_ERASER)
455 offset = 2;
457 for (; offset < CURSORMAX; offset += 3)
459 if (!gSysCursor[offset].ACTIVE)
461 gSysCursor[offset] = *cursor;
462 ++gNumCursors;
463 return TRUE;
467 return FALSE;
470 static void disable_system_cursors(void)
472 UINT i;
474 for (i = 0; i < CURSORMAX; ++i)
476 gSysCursor[i].ACTIVE = 0;
479 gNumCursors = 0;
483 /***********************************************************************
484 * X11DRV_LoadTabletInfo (X11DRV.@)
486 BOOL CDECL X11DRV_LoadTabletInfo(HWND hwnddefault)
488 const WCHAR SZ_CONTEXT_NAME[] = {'W','i','n','e',' ','T','a','b','l','e','t',' ','C','o','n','t','e','x','t',0};
489 const WCHAR SZ_DEVICE_NAME[] = {'W','i','n','e',' ','T','a','b','l','e','t',' ','D','e','v','i','c','e',0};
490 const WCHAR SZ_NON_PLUGINPLAY[] = {'n','o','n','-','p','l','u','g','i','n','p','l','a','y',0};
492 struct x11drv_thread_data *data = x11drv_init_thread_data();
493 int num_devices;
494 int loop;
495 XDeviceInfo *devices;
496 XDeviceInfo *target = NULL;
497 BOOL axis_read_complete= FALSE;
499 XAnyClassPtr any;
500 XButtonInfoPtr Button;
501 XValuatorInfoPtr Val;
502 XAxisInfoPtr Axis;
504 XDevice *opendevice;
506 if (!X11DRV_XInput_Init())
508 ERR("Unable to initialize the XInput library.\n");
509 return FALSE;
512 hwndTabletDefault = hwnddefault;
514 /* Do base initialization */
515 strcpyW(gSysContext.lcName, SZ_CONTEXT_NAME);
516 strcpyW(gSysDevice.NAME, SZ_DEVICE_NAME);
518 gSysContext.lcOptions = CXO_SYSTEM;
519 gSysContext.lcLocks = CXL_INSIZE | CXL_INASPECT | CXL_MARGIN |
520 CXL_SENSITIVITY | CXL_SYSOUT;
522 gSysContext.lcMsgBase= WT_DEFBASE;
523 gSysContext.lcDevice = 0;
524 gSysContext.lcPktData =
525 PK_CONTEXT | PK_STATUS | PK_SERIAL_NUMBER| PK_TIME | PK_CURSOR |
526 PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION;
527 gSysContext.lcMoveMask=
528 PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION;
529 gSysContext.lcStatus = CXS_ONTOP;
530 gSysContext.lcPktRate = 100;
531 gSysContext.lcBtnDnMask = 0xffffffff;
532 gSysContext.lcBtnUpMask = 0xffffffff;
533 gSysContext.lcSensX = 65536;
534 gSysContext.lcSensY = 65536;
535 gSysContext.lcSensX = 65536;
536 gSysContext.lcSensZ = 65536;
537 gSysContext.lcSysSensX= 65536;
538 gSysContext.lcSysSensY= 65536;
539 gSysContext.lcOutExtX= GetSystemMetrics(SM_CXSCREEN);
540 gSysContext.lcOutExtY= GetSystemMetrics(SM_CYSCREEN);
542 /* initialize cursors */
543 disable_system_cursors();
545 /* Device Defaults */
546 gSysDevice.HARDWARE = HWC_HARDPROX|HWC_PHYSID_CURSORS;
547 gSysDevice.FIRSTCSR= 0;
548 gSysDevice.PKTRATE = 100;
549 gSysDevice.PKTDATA =
550 PK_CONTEXT | PK_STATUS | PK_SERIAL_NUMBER| PK_TIME | PK_CURSOR |
551 PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION;
552 strcpyW(gSysDevice.PNPID, SZ_NON_PLUGINPLAY);
554 devices = pXListInputDevices(data->display, &num_devices);
555 if (!devices)
557 WARN("XInput Extensions reported as not available\n");
558 return FALSE;
560 TRACE("XListInputDevices reports %d devices\n", num_devices);
561 for (loop=0; loop < num_devices; loop++)
563 int class_loop;
564 char *device_type = devices[loop].type ? XGetAtomName(data->display, devices[loop].type) : NULL;
565 WTI_CURSORS_INFO cursor;
567 TRACE("Device %i: [id %d|name %s|type %s|num_classes %d|use %d]\n",
568 loop, (int) devices[loop].id, devices[loop].name, debugstr_a(device_type),
569 devices[loop].num_classes, devices[loop].use );
571 switch (devices[loop].use)
573 case IsXExtensionDevice:
574 #ifdef IsXExtensionPointer
575 case IsXExtensionPointer:
576 #endif
577 #ifdef IsXExtensionKeyboard
578 case IsXExtensionKeyboard:
579 #endif
580 TRACE("Is XExtension: Device, Keyboard, or Pointer\n");
581 target = &devices[loop];
583 if (strlen(target->name) >= WT_MAX_NAME_LEN)
585 ERR("Input device '%s' name too long - skipping\n", wine_dbgstr_a(target->name));
586 break;
589 X11DRV_expect_error(data->display, Tablet_ErrorHandler, NULL);
590 opendevice = pXOpenDevice(data->display,target->id);
591 if (!X11DRV_check_error() && opendevice)
593 unsigned char map[32];
594 int i;
595 int shft = 0;
597 X11DRV_expect_error(data->display,Tablet_ErrorHandler,NULL);
598 cursor.BUTTONS = pXGetDeviceButtonMapping(data->display, opendevice, map, 32);
599 if (X11DRV_check_error() || cursor.BUTTONS <= 0)
601 TRACE("No buttons, Non Tablet Device\n");
602 pXCloseDevice(data->display, opendevice);
603 break;
606 for (i=0; i< cursor.BUTTONS; i++,shft++)
608 cursor.BUTTONMAP[i] = map[i];
609 cursor.SYSBTNMAP[i] = (1<<shft);
611 pXCloseDevice(data->display, opendevice);
613 else
615 WARN("Unable to open device %s\n",target->name);
616 break;
618 MultiByteToWideChar(CP_UNIXCP, 0, target->name, -1, cursor.NAME, WT_MAX_NAME_LEN);
620 if (! is_tablet_cursor(target->name, device_type))
622 WARN("Skipping device %d [name %s|type %s]; not apparently a tablet cursor type device. If this is wrong, please report it to wine-devel@winehq.org\n",
623 loop, devices[loop].name, debugstr_a(device_type));
624 break;
627 cursor.ACTIVE = 1;
628 cursor.PKTDATA = PK_TIME | PK_CURSOR | PK_BUTTONS | PK_X | PK_Y |
629 PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE |
630 PK_ORIENTATION;
632 cursor.PHYSID = target->id;
633 cursor.NPBUTTON = 1;
634 cursor.NPBTNMARKS[0] = 0 ;
635 cursor.NPBTNMARKS[1] = 1 ;
636 cursor.CAPABILITIES = CRC_MULTIMODE;
638 cursor.TYPE = get_cursor_type(target->name, device_type);
640 any = target->inputclassinfo;
642 for (class_loop = 0; class_loop < target->num_classes; class_loop++)
644 switch (any->class)
647 case ValuatorClass:
648 Val = (XValuatorInfoPtr) any;
649 TRACE(" ValidatorInput %d: [class %d|length %d|num_axes %d|mode %d|motion_buffer %ld]\n",
650 class_loop, (int) Val->class, Val->length, Val->num_axes, Val->mode, Val->motion_buffer);
651 if (TRACE_ON(wintab32))
652 trace_axes(Val);
654 /* FIXME: This is imperfect; we compute our devices capabilities based upon the
655 ** first pen type device we find. However, a more correct implementation
656 ** would require acquiring a wide variety of tablets and running through
657 ** the various inputs to see what the values are. Odds are that a
658 ** more 'correct' algorithm would condense to this one anyway.
660 if (!axis_read_complete && cursor.TYPE == CSR_TYPE_PEN)
662 Axis = (XAxisInfoPtr) ((char *) Val + sizeof
663 (XValuatorInfo));
665 if (Val->num_axes>=1)
667 /* Axis 1 is X */
668 gSysDevice.X.axMin = Axis->min_value;
669 gSysDevice.X.axMax= Axis->max_value;
670 gSysDevice.X.axUnits = TU_INCHES;
671 gSysDevice.X.axResolution = Axis->resolution;
672 gSysContext.lcInOrgX = Axis->min_value;
673 gSysContext.lcSysOrgX = Axis->min_value;
674 gSysContext.lcInExtX = Axis->max_value;
675 gSysContext.lcSysExtX = Axis->max_value;
676 Axis++;
678 if (Val->num_axes>=2)
680 /* Axis 2 is Y */
681 gSysDevice.Y.axMin = Axis->min_value;
682 gSysDevice.Y.axMax= Axis->max_value;
683 gSysDevice.Y.axUnits = TU_INCHES;
684 gSysDevice.Y.axResolution = Axis->resolution;
685 gSysContext.lcInOrgY = Axis->min_value;
686 gSysContext.lcSysOrgY = Axis->min_value;
687 gSysContext.lcInExtY = Axis->max_value;
688 gSysContext.lcSysExtY = Axis->max_value;
689 Axis++;
691 if (Val->num_axes>=3)
693 /* Axis 3 is Normal Pressure */
694 gSysDevice.NPRESSURE.axMin = Axis->min_value;
695 gSysDevice.NPRESSURE.axMax= Axis->max_value;
696 gSysDevice.NPRESSURE.axUnits = TU_INCHES;
697 gSysDevice.NPRESSURE.axResolution =
698 Axis->resolution;
699 Axis++;
701 if (Val->num_axes >= 5)
703 /* Axis 4 and 5 are X and Y tilt */
704 XAxisInfoPtr XAxis = Axis;
705 Axis++;
706 if (max (abs(Axis->max_value),
707 abs(XAxis->max_value)))
709 gSysDevice.ORIENTATION[0].axMin = 0;
710 gSysDevice.ORIENTATION[0].axMax = 3600;
711 gSysDevice.ORIENTATION[0].axUnits = TU_CIRCLE;
712 gSysDevice.ORIENTATION[0].axResolution
713 = CASTFIX32(3600);
714 gSysDevice.ORIENTATION[1].axMin = -1000;
715 gSysDevice.ORIENTATION[1].axMax = 1000;
716 gSysDevice.ORIENTATION[1].axUnits = TU_CIRCLE;
717 gSysDevice.ORIENTATION[1].axResolution
718 = CASTFIX32(3600);
719 Axis++;
722 axis_read_complete = TRUE;
724 break;
725 case ButtonClass:
727 int cchBuf = 512;
728 int cchPos = 0;
729 int i;
731 Button = (XButtonInfoPtr) any;
732 TRACE(" ButtonInput %d: [class %d|length %d|num_buttons %d]\n",
733 class_loop, (int) Button->class, Button->length, Button->num_buttons);
734 cursor.BTNNAMES = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*cchBuf);
735 for (i = 0; i < cursor.BUTTONS; i++)
737 /* FIXME - these names are probably incorrect */
738 int cch = strlenW(cursor.NAME) + 1;
739 while (cch > cchBuf - cchPos - 1) /* we want one extra byte for the last NUL */
741 cchBuf *= 2;
742 cursor.BTNNAMES = HeapReAlloc(GetProcessHeap(), 0, cursor.BTNNAMES, sizeof(WCHAR)*cchBuf);
745 strcpyW(cursor.BTNNAMES + cchPos, cursor.NAME);
746 cchPos += cch;
748 cursor.BTNNAMES[cchPos++] = 0;
749 cursor.BTNNAMES = HeapReAlloc(GetProcessHeap(), 0, cursor.BTNNAMES, sizeof(WCHAR)*cchPos);
750 cursor.cchBTNNAMES = cchPos;
752 break;
753 } /* switch any->class */
754 any = (XAnyClassPtr) ((char*) any + any->length);
755 } /* for class_loop */
756 if (!add_system_cursor(&cursor))
757 FIXME("Skipping this cursor due to lack of system cursor slots.\n");
758 break;
759 } /* switch devices.use */
760 XFree(device_type);
761 } /* for XListInputDevices */
762 pXFreeDeviceList(devices);
764 if (axis_read_complete)
765 gSysDevice.NCSRTYPES = gNumCursors;
766 else
768 disable_system_cursors();
769 WARN("Did not find a valid stylus, unable to determine system context parameters. Wintab is disabled.\n");
772 return TRUE;
775 static int figure_deg(int x, int y)
777 float angle;
779 angle = atan2((float)y, (float)x);
780 angle += M_PI_2;
781 if (angle <= 0)
782 angle += 2 * M_PI;
784 return (0.5 + (angle * 1800.0 / M_PI));
787 static int get_button_state(int curnum)
789 return button_state[curnum];
792 static void set_button_state(int curnum, XID deviceid)
794 struct x11drv_thread_data *data = x11drv_thread_data();
795 XDevice *device;
796 XDeviceState *state;
797 XInputClass *class;
798 int loop;
799 int rc = 0;
801 device = pXOpenDevice(data->display,deviceid);
802 state = pXQueryDeviceState(data->display,device);
804 if (state)
806 class = state->data;
807 for (loop = 0; loop < state->num_classes; loop++)
809 if (class->class == ButtonClass)
811 int loop2;
812 XButtonState *button_state = (XButtonState*)class;
813 for (loop2 = 0; loop2 < button_state->num_buttons; loop2++)
815 if (button_state->buttons[loop2 / 8] & (1 << (loop2 % 8)))
817 rc |= (1<<loop2);
821 class = (XInputClass *) ((char *) class + class->length);
824 pXFreeDeviceState(state);
825 button_state[curnum] = rc;
828 static int cursor_from_device(DWORD deviceid, LPWTI_CURSORS_INFO *cursorp)
830 int i;
831 for (i = 0; i < CURSORMAX; i++)
832 if (gSysCursor[i].ACTIVE && gSysCursor[i].PHYSID == deviceid)
834 *cursorp = &gSysCursor[i];
835 return i;
838 ERR("Could not map device id %d to a cursor\n", (int) deviceid);
839 return -1;
842 static BOOL motion_event( HWND hwnd, XEvent *event )
844 XDeviceMotionEvent *motion = (XDeviceMotionEvent *)event;
845 LPWTI_CURSORS_INFO cursor;
846 int curnum = cursor_from_device(motion->deviceid, &cursor);
847 if (curnum < 0)
848 return FALSE;
850 memset(&gMsgPacket,0,sizeof(WTPACKET));
852 TRACE("Received tablet motion event (%p); device id %d, cursor num %d\n",hwnd, (int) motion->deviceid, curnum);
854 /* Set cursor to inverted if cursor is the eraser */
855 gMsgPacket.pkStatus = (cursor->TYPE == CSR_TYPE_ERASER ? TPS_INVERT:0);
856 gMsgPacket.pkTime = EVENT_x11_time_to_win32_time(motion->time);
857 gMsgPacket.pkSerialNumber = gSerial++;
858 gMsgPacket.pkCursor = curnum;
859 gMsgPacket.pkX = motion->axis_data[0];
860 gMsgPacket.pkY = motion->axis_data[1];
861 gMsgPacket.pkOrientation.orAzimuth = figure_deg(motion->axis_data[3],motion->axis_data[4]);
862 gMsgPacket.pkOrientation.orAltitude = ((1000 - 15 * max
863 (abs(motion->axis_data[3]),
864 abs(motion->axis_data[4])))
865 * (gMsgPacket.pkStatus & TPS_INVERT?-1:1));
866 gMsgPacket.pkNormalPressure = motion->axis_data[2];
867 gMsgPacket.pkButtons = get_button_state(curnum);
868 SendMessageW(hwndTabletDefault,WT_PACKET,gMsgPacket.pkSerialNumber,(LPARAM)hwnd);
869 return TRUE;
872 static BOOL button_event( HWND hwnd, XEvent *event )
874 XDeviceButtonEvent *button = (XDeviceButtonEvent *) event;
875 LPWTI_CURSORS_INFO cursor;
876 int curnum = cursor_from_device(button->deviceid, &cursor);
877 if (curnum < 0)
878 return FALSE;
880 memset(&gMsgPacket,0,sizeof(WTPACKET));
882 TRACE("Received tablet button %s event\n", (event->type == button_press_type)?"press":"release");
884 /* Set cursor to inverted if cursor is the eraser */
885 gMsgPacket.pkStatus = (cursor->TYPE == CSR_TYPE_ERASER ? TPS_INVERT:0);
886 set_button_state(curnum, button->deviceid);
887 gMsgPacket.pkTime = EVENT_x11_time_to_win32_time(button->time);
888 gMsgPacket.pkSerialNumber = gSerial++;
889 gMsgPacket.pkCursor = curnum;
890 gMsgPacket.pkX = button->axis_data[0];
891 gMsgPacket.pkY = button->axis_data[1];
892 gMsgPacket.pkOrientation.orAzimuth = figure_deg(button->axis_data[3],button->axis_data[4]);
893 gMsgPacket.pkOrientation.orAltitude = ((1000 - 15 * max(abs(button->axis_data[3]),
894 abs(button->axis_data[4])))
895 * (gMsgPacket.pkStatus & TPS_INVERT?-1:1));
896 gMsgPacket.pkNormalPressure = button->axis_data[2];
897 gMsgPacket.pkButtons = get_button_state(curnum);
898 SendMessageW(hwndTabletDefault,WT_PACKET,gMsgPacket.pkSerialNumber,(LPARAM)hwnd);
899 return TRUE;
902 static BOOL key_event( HWND hwnd, XEvent *event )
904 if (event->type == key_press_type)
905 FIXME("Received tablet key press event\n");
906 else
907 FIXME("Received tablet key release event\n");
908 return FALSE;
911 static BOOL proximity_event( HWND hwnd, XEvent *event )
913 XProximityNotifyEvent *proximity = (XProximityNotifyEvent *) event;
914 LPWTI_CURSORS_INFO cursor;
915 int curnum = cursor_from_device(proximity->deviceid, &cursor);
916 LPARAM proximity_info;
918 TRACE("hwnd=%p\n", hwnd);
920 if (curnum < 0)
921 return FALSE;
923 memset(&gMsgPacket,0,sizeof(WTPACKET));
925 /* Set cursor to inverted if cursor is the eraser */
926 gMsgPacket.pkStatus = (cursor->TYPE == CSR_TYPE_ERASER ? TPS_INVERT:0);
927 gMsgPacket.pkStatus |= (event->type==proximity_out_type)?TPS_PROXIMITY:0;
928 gMsgPacket.pkTime = EVENT_x11_time_to_win32_time(proximity->time);
929 gMsgPacket.pkSerialNumber = gSerial++;
930 gMsgPacket.pkCursor = curnum;
931 gMsgPacket.pkX = proximity->axis_data[0];
932 gMsgPacket.pkY = proximity->axis_data[1];
933 gMsgPacket.pkOrientation.orAzimuth = figure_deg(proximity->axis_data[3],proximity->axis_data[4]);
934 gMsgPacket.pkOrientation.orAltitude = ((1000 - 15 * max(abs(proximity->axis_data[3]),
935 abs(proximity->axis_data[4])))
936 * (gMsgPacket.pkStatus & TPS_INVERT?-1:1));
937 gMsgPacket.pkNormalPressure = proximity->axis_data[2];
938 gMsgPacket.pkButtons = get_button_state(curnum);
940 /* FIXME: LPARAM loword is true when cursor entering context, false when leaving context
941 * This needs to be handled here or in wintab32. Using the proximity_in_type is not correct
942 * but kept for now.
943 * LPARAM hiword is "non-zero when the cursor is leaving or entering hardware proximity"
944 * WPARAM contains context handle.
945 * HWND to HCTX is handled by wintab32.
947 proximity_info = MAKELPARAM((event->type == proximity_in_type),
948 (event->type == proximity_in_type) || (event->type == proximity_out_type));
949 SendMessageW(hwndTabletDefault, WT_PROXIMITY, (WPARAM)hwnd, proximity_info);
950 return TRUE;
953 /***********************************************************************
954 * X11DRV_AttachEventQueueToTablet (X11DRV.@)
956 int CDECL X11DRV_AttachEventQueueToTablet(HWND hOwner)
958 struct x11drv_thread_data *data = x11drv_init_thread_data();
959 int num_devices;
960 int loop;
961 int cur_loop;
962 XDeviceInfo *devices;
963 XDeviceInfo *target = NULL;
964 XDevice *the_device;
965 XEventClass event_list[7];
966 Window win = X11DRV_get_whole_window( hOwner );
968 if (!win || !xinput_handle) return 0;
970 TRACE("Creating context for window %p (%lx) %i cursors\n", hOwner, win, gNumCursors);
972 devices = pXListInputDevices(data->display, &num_devices);
974 X11DRV_expect_error(data->display,Tablet_ErrorHandler,NULL);
975 for (cur_loop=0; cur_loop < CURSORMAX; cur_loop++)
977 char cursorNameA[WT_MAX_NAME_LEN];
978 int event_number=0;
980 if (!gSysCursor[cur_loop].ACTIVE) continue;
982 /* the cursor name fits in the buffer because too long names are skipped */
983 WideCharToMultiByte(CP_UNIXCP, 0, gSysCursor[cur_loop].NAME, -1, cursorNameA, WT_MAX_NAME_LEN, NULL, NULL);
984 for (loop=0; loop < num_devices; loop ++)
985 if (strcmp(devices[loop].name, cursorNameA) == 0)
986 target = &devices[loop];
987 if (!target) {
988 WARN("Cursor Name %s not found in list of targets.\n", cursorNameA);
989 continue;
992 TRACE("Opening cursor %i id %i\n",cur_loop,(INT)target->id);
994 the_device = pXOpenDevice(data->display, target->id);
996 if (!the_device)
998 WARN("Unable to Open device\n");
999 continue;
1002 if (the_device->num_classes > 0)
1004 DeviceKeyPress(the_device, key_press_type, event_list[event_number]);
1005 if (key_press_type) event_number++;
1006 DeviceKeyRelease(the_device, key_release_type, event_list[event_number]);
1007 if (key_release_type) event_number++;
1008 DeviceButtonPress(the_device, button_press_type, event_list[event_number]);
1009 if (button_press_type) event_number++;
1010 DeviceButtonRelease(the_device, button_release_type, event_list[event_number]);
1011 if (button_release_type) event_number++;
1012 DeviceMotionNotify(the_device, motion_type, event_list[event_number]);
1013 if (motion_type) event_number++;
1014 ProximityIn(the_device, proximity_in_type, event_list[event_number]);
1015 if (proximity_in_type) event_number++;
1016 ProximityOut(the_device, proximity_out_type, event_list[event_number]);
1017 if (proximity_out_type) event_number++;
1019 if (key_press_type)
1020 X11DRV_register_event_handler( key_press_type, key_event, "XInput KeyPress" );
1021 if (key_release_type)
1022 X11DRV_register_event_handler( key_release_type, key_event, "XInput KeyRelease" );
1023 if (button_press_type)
1024 X11DRV_register_event_handler( button_press_type, button_event, "XInput ButtonPress" );
1025 if (button_release_type)
1026 X11DRV_register_event_handler( button_release_type, button_event, "XInput ButtonRelease" );
1027 if (motion_type)
1028 X11DRV_register_event_handler( motion_type, motion_event, "XInput MotionNotify" );
1029 if (proximity_in_type)
1030 X11DRV_register_event_handler( proximity_in_type, proximity_event, "XInput ProximityIn" );
1031 if (proximity_out_type)
1032 X11DRV_register_event_handler( proximity_out_type, proximity_event, "XInput ProximityOut" );
1034 pXSelectExtensionEvent(data->display, win, event_list, event_number);
1037 XSync(data->display, False);
1038 X11DRV_check_error();
1040 if (NULL != devices) pXFreeDeviceList(devices);
1041 return 0;
1044 /***********************************************************************
1045 * X11DRV_GetCurrentPacket (X11DRV.@)
1047 int CDECL X11DRV_GetCurrentPacket(LPWTPACKET packet)
1049 *packet = gMsgPacket;
1050 return 1;
1054 static inline int CopyTabletData(LPVOID target, LPCVOID src, INT size)
1057 * It is valid to call CopyTabletData with NULL.
1058 * This handles the WTInfo() case where lpOutput is null.
1060 if(target != NULL)
1061 memcpy(target,src,size);
1062 return(size);
1065 /***********************************************************************
1066 * X11DRV_WTInfoW (X11DRV.@)
1068 UINT CDECL X11DRV_WTInfoW(UINT wCategory, UINT nIndex, LPVOID lpOutput)
1071 * It is valid to call WTInfoA with lpOutput == NULL, as per standard.
1072 * lpOutput == NULL signifies the user only wishes
1073 * to find the size of the data.
1074 * NOTE:
1075 * From now on use CopyTabletData to fill lpOutput. memcpy will break
1076 * the code.
1078 int rc = 0;
1079 LPWTI_CURSORS_INFO tgtcursor;
1080 TRACE("(%u, %u, %p)\n", wCategory, nIndex, lpOutput);
1082 if (!xinput_handle) return 0;
1084 switch(wCategory)
1086 case 0:
1087 /* return largest necessary buffer */
1088 TRACE("%i cursors\n",gNumCursors);
1089 if (gNumCursors>0)
1091 FIXME("Return proper size\n");
1092 rc = 200;
1094 break;
1095 case WTI_INTERFACE:
1096 switch (nIndex)
1098 WORD version;
1099 UINT num;
1100 case IFC_WINTABID:
1102 static const WCHAR driver[] = {'W','i','n','e',' ','W','i','n','t','a','b',' ','1','.','1',0};
1103 rc = CopyTabletData(lpOutput, driver, (strlenW(driver) + 1) * sizeof(WCHAR));
1104 break;
1106 case IFC_SPECVERSION:
1107 version = (0x01) | (0x01 << 8);
1108 rc = CopyTabletData(lpOutput, &version,sizeof(WORD));
1109 break;
1110 case IFC_IMPLVERSION:
1111 version = (0x00) | (0x01 << 8);
1112 rc = CopyTabletData(lpOutput, &version,sizeof(WORD));
1113 break;
1114 case IFC_NDEVICES:
1115 num = 1;
1116 rc = CopyTabletData(lpOutput, &num,sizeof(num));
1117 break;
1118 case IFC_NCURSORS:
1119 num = gNumCursors;
1120 rc = CopyTabletData(lpOutput, &num,sizeof(num));
1121 break;
1122 default:
1123 FIXME("WTI_INTERFACE unhandled index %i\n",nIndex);
1124 rc = 0;
1126 break;
1127 case WTI_DEFSYSCTX:
1128 case WTI_DDCTXS:
1129 case WTI_DEFCONTEXT:
1130 switch (nIndex)
1132 case 0:
1133 /* report 0 if wintab is disabled */
1134 if (0 == gNumCursors)
1135 rc = 0;
1136 else
1137 rc = CopyTabletData(lpOutput, &gSysContext,
1138 sizeof(LOGCONTEXTW));
1139 break;
1140 case CTX_NAME:
1141 rc = CopyTabletData(lpOutput, gSysContext.lcName,
1142 (strlenW(gSysContext.lcName)+1) * sizeof(WCHAR));
1143 break;
1144 case CTX_OPTIONS:
1145 rc = CopyTabletData(lpOutput, &gSysContext.lcOptions,
1146 sizeof(UINT));
1147 break;
1148 case CTX_STATUS:
1149 rc = CopyTabletData(lpOutput, &gSysContext.lcStatus,
1150 sizeof(UINT));
1151 break;
1152 case CTX_LOCKS:
1153 rc= CopyTabletData (lpOutput, &gSysContext.lcLocks,
1154 sizeof(UINT));
1155 break;
1156 case CTX_MSGBASE:
1157 rc = CopyTabletData(lpOutput, &gSysContext.lcMsgBase,
1158 sizeof(UINT));
1159 break;
1160 case CTX_DEVICE:
1161 rc = CopyTabletData(lpOutput, &gSysContext.lcDevice,
1162 sizeof(UINT));
1163 break;
1164 case CTX_PKTRATE:
1165 rc = CopyTabletData(lpOutput, &gSysContext.lcPktRate,
1166 sizeof(UINT));
1167 break;
1168 case CTX_PKTDATA:
1169 rc = CopyTabletData(lpOutput, &gSysContext.lcPktData,
1170 sizeof(WTPKT));
1171 break;
1172 case CTX_PKTMODE:
1173 rc = CopyTabletData(lpOutput, &gSysContext.lcPktMode,
1174 sizeof(WTPKT));
1175 break;
1176 case CTX_MOVEMASK:
1177 rc = CopyTabletData(lpOutput, &gSysContext.lcMoveMask,
1178 sizeof(WTPKT));
1179 break;
1180 case CTX_BTNDNMASK:
1181 rc = CopyTabletData(lpOutput, &gSysContext.lcBtnDnMask,
1182 sizeof(DWORD));
1183 break;
1184 case CTX_BTNUPMASK:
1185 rc = CopyTabletData(lpOutput, &gSysContext.lcBtnUpMask,
1186 sizeof(DWORD));
1187 break;
1188 case CTX_INORGX:
1189 rc = CopyTabletData(lpOutput, &gSysContext.lcInOrgX,
1190 sizeof(LONG));
1191 break;
1192 case CTX_INORGY:
1193 rc = CopyTabletData(lpOutput, &gSysContext.lcInOrgY,
1194 sizeof(LONG));
1195 break;
1196 case CTX_INORGZ:
1197 rc = CopyTabletData(lpOutput, &gSysContext.lcInOrgZ,
1198 sizeof(LONG));
1199 break;
1200 case CTX_INEXTX:
1201 rc = CopyTabletData(lpOutput, &gSysContext.lcInExtX,
1202 sizeof(LONG));
1203 break;
1204 case CTX_INEXTY:
1205 rc = CopyTabletData(lpOutput, &gSysContext.lcInExtY,
1206 sizeof(LONG));
1207 break;
1208 case CTX_INEXTZ:
1209 rc = CopyTabletData(lpOutput, &gSysContext.lcInExtZ,
1210 sizeof(LONG));
1211 break;
1212 case CTX_OUTORGX:
1213 rc = CopyTabletData(lpOutput, &gSysContext.lcOutOrgX,
1214 sizeof(LONG));
1215 break;
1216 case CTX_OUTORGY:
1217 rc = CopyTabletData(lpOutput, &gSysContext.lcOutOrgY,
1218 sizeof(LONG));
1219 break;
1220 case CTX_OUTORGZ:
1221 rc = CopyTabletData(lpOutput, &gSysContext.lcOutOrgZ,
1222 sizeof(LONG));
1223 break;
1224 case CTX_OUTEXTX:
1225 rc = CopyTabletData(lpOutput, &gSysContext.lcOutExtX,
1226 sizeof(LONG));
1227 break;
1228 case CTX_OUTEXTY:
1229 rc = CopyTabletData(lpOutput, &gSysContext.lcOutExtY,
1230 sizeof(LONG));
1231 break;
1232 case CTX_OUTEXTZ:
1233 rc = CopyTabletData(lpOutput, &gSysContext.lcOutExtZ,
1234 sizeof(LONG));
1235 break;
1236 case CTX_SENSX:
1237 rc = CopyTabletData(lpOutput, &gSysContext.lcSensX,
1238 sizeof(LONG));
1239 break;
1240 case CTX_SENSY:
1241 rc = CopyTabletData(lpOutput, &gSysContext.lcSensY,
1242 sizeof(LONG));
1243 break;
1244 case CTX_SENSZ:
1245 rc = CopyTabletData(lpOutput, &gSysContext.lcSensZ,
1246 sizeof(LONG));
1247 break;
1248 case CTX_SYSMODE:
1249 rc = CopyTabletData(lpOutput, &gSysContext.lcSysMode,
1250 sizeof(LONG));
1251 break;
1252 case CTX_SYSORGX:
1253 rc = CopyTabletData(lpOutput, &gSysContext.lcSysOrgX,
1254 sizeof(LONG));
1255 break;
1256 case CTX_SYSORGY:
1257 rc = CopyTabletData(lpOutput, &gSysContext.lcSysOrgY,
1258 sizeof(LONG));
1259 break;
1260 case CTX_SYSEXTX:
1261 rc = CopyTabletData(lpOutput, &gSysContext.lcSysExtX,
1262 sizeof(LONG));
1263 break;
1264 case CTX_SYSEXTY:
1265 rc = CopyTabletData(lpOutput, &gSysContext.lcSysExtY,
1266 sizeof(LONG));
1267 break;
1268 case CTX_SYSSENSX:
1269 rc = CopyTabletData(lpOutput, &gSysContext.lcSysSensX,
1270 sizeof(LONG));
1271 break;
1272 case CTX_SYSSENSY:
1273 rc = CopyTabletData(lpOutput, &gSysContext.lcSysSensY,
1274 sizeof(LONG));
1275 break;
1276 default:
1277 FIXME("WTI_DEFSYSCTX unhandled index %i\n",nIndex);
1278 rc = 0;
1280 break;
1281 case WTI_CURSORS:
1282 case WTI_CURSORS+1:
1283 case WTI_CURSORS+2:
1284 case WTI_CURSORS+3:
1285 case WTI_CURSORS+4:
1286 case WTI_CURSORS+5:
1287 case WTI_CURSORS+6:
1288 case WTI_CURSORS+7:
1289 case WTI_CURSORS+8:
1290 case WTI_CURSORS+9:
1291 case WTI_CURSORS+10:
1292 case WTI_CURSORS+11:
1293 /* CURSORMAX == 12 */
1294 /* FIXME: dynamic cursor support */
1295 /* Apps will poll different slots to detect what cursors are available
1296 * if there isn't a cursor for this slot return 0 */
1297 if (!gSysCursor[wCategory - WTI_CURSORS].ACTIVE)
1298 rc = 0;
1299 else
1301 tgtcursor = &gSysCursor[wCategory - WTI_CURSORS];
1302 switch (nIndex)
1304 case CSR_NAME:
1305 rc = CopyTabletData(lpOutput, tgtcursor->NAME,
1306 (strlenW(tgtcursor->NAME)+1) * sizeof(WCHAR));
1307 break;
1308 case CSR_ACTIVE:
1309 rc = CopyTabletData(lpOutput,&tgtcursor->ACTIVE,
1310 sizeof(BOOL));
1311 break;
1312 case CSR_PKTDATA:
1313 rc = CopyTabletData(lpOutput,&tgtcursor->PKTDATA,
1314 sizeof(WTPKT));
1315 break;
1316 case CSR_BUTTONS:
1317 rc = CopyTabletData(lpOutput,&tgtcursor->BUTTONS,
1318 sizeof(BYTE));
1319 break;
1320 case CSR_BUTTONBITS:
1321 rc = CopyTabletData(lpOutput,&tgtcursor->BUTTONBITS,
1322 sizeof(BYTE));
1323 break;
1324 case CSR_BTNNAMES:
1325 FIXME("Button Names not returned correctly\n");
1326 rc = CopyTabletData(lpOutput,&tgtcursor->BTNNAMES,
1327 tgtcursor->cchBTNNAMES*sizeof(WCHAR));
1328 break;
1329 case CSR_BUTTONMAP:
1330 rc = CopyTabletData(lpOutput,tgtcursor->BUTTONMAP,
1331 sizeof(BYTE)*32);
1332 break;
1333 case CSR_SYSBTNMAP:
1334 rc = CopyTabletData(lpOutput,tgtcursor->SYSBTNMAP,
1335 sizeof(BYTE)*32);
1336 break;
1337 case CSR_NPBTNMARKS:
1338 rc = CopyTabletData(lpOutput,tgtcursor->NPBTNMARKS,
1339 sizeof(UINT)*2);
1340 break;
1341 case CSR_NPBUTTON:
1342 rc = CopyTabletData(lpOutput,&tgtcursor->NPBUTTON,
1343 sizeof(BYTE));
1344 break;
1345 case CSR_NPRESPONSE:
1346 FIXME("Not returning CSR_NPRESPONSE correctly\n");
1347 rc = 0;
1348 break;
1349 case CSR_TPBUTTON:
1350 rc = CopyTabletData(lpOutput,&tgtcursor->TPBUTTON,
1351 sizeof(BYTE));
1352 break;
1353 case CSR_TPBTNMARKS:
1354 rc = CopyTabletData(lpOutput,tgtcursor->TPBTNMARKS,
1355 sizeof(UINT)*2);
1356 break;
1357 case CSR_TPRESPONSE:
1358 FIXME("Not returning CSR_TPRESPONSE correctly\n");
1359 rc = 0;
1360 break;
1361 case CSR_PHYSID:
1363 DWORD id;
1364 id = tgtcursor->PHYSID;
1365 rc = CopyTabletData(lpOutput,&id,sizeof(DWORD));
1367 break;
1368 case CSR_MODE:
1369 rc = CopyTabletData(lpOutput,&tgtcursor->MODE,sizeof(UINT));
1370 break;
1371 case CSR_MINPKTDATA:
1372 rc = CopyTabletData(lpOutput,&tgtcursor->MINPKTDATA,
1373 sizeof(UINT));
1374 break;
1375 case CSR_MINBUTTONS:
1376 rc = CopyTabletData(lpOutput,&tgtcursor->MINBUTTONS,
1377 sizeof(UINT));
1378 break;
1379 case CSR_CAPABILITIES:
1380 rc = CopyTabletData(lpOutput,&tgtcursor->CAPABILITIES,
1381 sizeof(UINT));
1382 break;
1383 case CSR_TYPE:
1384 rc = CopyTabletData(lpOutput,&tgtcursor->TYPE,
1385 sizeof(UINT));
1386 break;
1387 default:
1388 FIXME("WTI_CURSORS unhandled index %i\n",nIndex);
1389 rc = 0;
1392 break;
1393 case WTI_DEVICES:
1394 switch (nIndex)
1396 case DVC_NAME:
1397 rc = CopyTabletData(lpOutput,gSysDevice.NAME,
1398 (strlenW(gSysDevice.NAME)+1) * sizeof(WCHAR));
1399 break;
1400 case DVC_HARDWARE:
1401 rc = CopyTabletData(lpOutput,&gSysDevice.HARDWARE,
1402 sizeof(UINT));
1403 break;
1404 case DVC_NCSRTYPES:
1405 rc = CopyTabletData(lpOutput,&gSysDevice.NCSRTYPES,
1406 sizeof(UINT));
1407 break;
1408 case DVC_FIRSTCSR:
1409 rc = CopyTabletData(lpOutput,&gSysDevice.FIRSTCSR,
1410 sizeof(UINT));
1411 break;
1412 case DVC_PKTRATE:
1413 rc = CopyTabletData(lpOutput,&gSysDevice.PKTRATE,
1414 sizeof(UINT));
1415 break;
1416 case DVC_PKTDATA:
1417 rc = CopyTabletData(lpOutput,&gSysDevice.PKTDATA,
1418 sizeof(WTPKT));
1419 break;
1420 case DVC_PKTMODE:
1421 rc = CopyTabletData(lpOutput,&gSysDevice.PKTMODE,
1422 sizeof(WTPKT));
1423 break;
1424 case DVC_CSRDATA:
1425 rc = CopyTabletData(lpOutput,&gSysDevice.CSRDATA,
1426 sizeof(WTPKT));
1427 break;
1428 case DVC_XMARGIN:
1429 rc = CopyTabletData(lpOutput,&gSysDevice.XMARGIN,
1430 sizeof(INT));
1431 break;
1432 case DVC_YMARGIN:
1433 rc = CopyTabletData(lpOutput,&gSysDevice.YMARGIN,
1434 sizeof(INT));
1435 break;
1436 case DVC_ZMARGIN:
1437 rc = 0; /* unsupported */
1439 rc = CopyTabletData(lpOutput,&gSysDevice.ZMARGIN,
1440 sizeof(INT));
1442 break;
1443 case DVC_X:
1444 rc = CopyTabletData(lpOutput,&gSysDevice.X,
1445 sizeof(AXIS));
1446 break;
1447 case DVC_Y:
1448 rc = CopyTabletData(lpOutput,&gSysDevice.Y,
1449 sizeof(AXIS));
1450 break;
1451 case DVC_Z:
1452 rc = 0; /* unsupported */
1454 rc = CopyTabletData(lpOutput,&gSysDevice.Z,
1455 sizeof(AXIS));
1457 break;
1458 case DVC_NPRESSURE:
1459 rc = CopyTabletData(lpOutput,&gSysDevice.NPRESSURE,
1460 sizeof(AXIS));
1461 break;
1462 case DVC_TPRESSURE:
1463 rc = 0; /* unsupported */
1465 rc = CopyTabletData(lpOutput,&gSysDevice.TPRESSURE,
1466 sizeof(AXIS));
1468 break;
1469 case DVC_ORIENTATION:
1470 rc = CopyTabletData(lpOutput,gSysDevice.ORIENTATION,
1471 sizeof(AXIS)*3);
1472 break;
1473 case DVC_ROTATION:
1474 rc = 0; /* unsupported */
1476 rc = CopyTabletData(lpOutput,&gSysDevice.ROTATION,
1477 sizeof(AXIS)*3);
1479 break;
1480 case DVC_PNPID:
1481 rc = CopyTabletData(lpOutput,gSysDevice.PNPID,
1482 (strlenW(gSysDevice.PNPID)+1)*sizeof(WCHAR));
1483 break;
1484 default:
1485 FIXME("WTI_DEVICES unhandled index %i\n",nIndex);
1486 rc = 0;
1488 break;
1489 default:
1490 FIXME("Unhandled Category %i\n",wCategory);
1492 return rc;
1495 #else /* SONAME_LIBXI */
1497 /***********************************************************************
1498 * AttachEventQueueToTablet (X11DRV.@)
1500 int CDECL X11DRV_AttachEventQueueToTablet(HWND hOwner)
1502 return 0;
1505 /***********************************************************************
1506 * GetCurrentPacket (X11DRV.@)
1508 int CDECL X11DRV_GetCurrentPacket(LPWTPACKET packet)
1510 return 0;
1513 /***********************************************************************
1514 * LoadTabletInfo (X11DRV.@)
1516 BOOL CDECL X11DRV_LoadTabletInfo(HWND hwnddefault)
1518 return FALSE;
1521 /***********************************************************************
1522 * WTInfoW (X11DRV.@)
1524 UINT CDECL X11DRV_WTInfoW(UINT wCategory, UINT nIndex, LPVOID lpOutput)
1526 return 0;
1529 #endif /* SONAME_LIBXI */