| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 2009 Carlos Garnacho <[email protected]> |
| 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, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <stdio.h> |
| 22 |
#include <math.h> |
| 23 |
|
| 24 |
#include <gdk/gdk.h> |
| 25 |
#include "gdkwin32.h" |
| 26 |
#include "gdkprivate-win32.h" |
| 27 |
#include "gdkdevicemanager-win32.h" |
| 28 |
#include "gdkdeviceprivate.h" |
| 29 |
#include "gdkdevice-win32.h" |
| 30 |
#include "gdkdevice-virtual.h" |
| 31 |
#include "gdkdevice-winpointer.h" |
| 32 |
#include "gdkdevice-wintab.h" |
| 33 |
#include "gdkdisplayprivate.h" |
| 34 |
#include "gdkdevicetoolprivate.h" |
| 35 |
#include "gdkseatdefaultprivate.h" |
| 36 |
|
| 37 |
#include <tchar.h> |
| 38 |
#include <tpcshrd.h> |
| 39 |
#include <hidsdi.h> |
| 40 |
#include "winpointer.h" |
| 41 |
|
| 42 |
#define WINTAB32_DLL "Wintab32.dll" |
| 43 |
|
| 44 |
#define PACKETDATA (PK_CONTEXT | PK_CURSOR | PK_BUTTONS | PK_X | PK_Y | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_TANGENT_PRESSURE) |
| 45 |
/* We want everything in absolute mode */ |
| 46 |
#define PACKETMODE (0) |
| 47 |
#include <pktdef.h> |
| 48 |
|
| 49 |
#define DEBUG_WINTAB 1 /* Verbose debug messages enabled */ |
| 50 |
#define TWOPI (2 * G_PI) |
| 51 |
|
| 52 |
typedef BOOL |
| 53 |
(WINAPI *registerPointerDeviceNotifications_t)(HWND window, BOOL notifyRange); |
| 54 |
typedef BOOL |
| 55 |
(WINAPI *getPointerDevices_t)(UINT32 *deviceCount, POINTER_DEVICE_INFO *pointerDevices); |
| 56 |
typedef BOOL |
| 57 |
(WINAPI *getPointerDeviceCursors_t)(HANDLE device, UINT32 *cursorCount, POINTER_DEVICE_CURSOR_INFO *deviceCursors); |
| 58 |
typedef BOOL |
| 59 |
(WINAPI *getPointerDeviceRects_t)(HANDLE device, RECT *pointerDeviceRect, RECT *displayRect); |
| 60 |
typedef BOOL |
| 61 |
(WINAPI *getPointerType_t)(UINT32 pointerId, POINTER_INPUT_TYPE *pointerType); |
| 62 |
typedef BOOL |
| 63 |
(WINAPI *getPointerCursorId_t)(UINT32 pointerId, UINT32 *cursorId); |
| 64 |
typedef BOOL |
| 65 |
(WINAPI *getPointerPenInfo_t)(UINT32 pointerId, POINTER_PEN_INFO *penInfo); |
| 66 |
typedef BOOL |
| 67 |
(WINAPI *getPointerTouchInfo_t)(UINT32 pointerId, POINTER_TOUCH_INFO *touchInfo); |
| 68 |
typedef BOOL |
| 69 |
(WINAPI *getPointerPenInfoHistory_t)(UINT32 pointerId, UINT32 *entriesCount, POINTER_PEN_INFO *penInfo); |
| 70 |
typedef BOOL |
| 71 |
(WINAPI *getPointerTouchInfoHistory_t)(UINT32 pointerId, UINT32 *entriesCount, POINTER_TOUCH_INFO *touchInfo); |
| 72 |
typedef BOOL |
| 73 |
(WINAPI *setGestureConfig_t)(HWND hwnd, DWORD dwReserved, UINT cIDs, PGESTURECONFIG pGestureConfig, UINT cbSize); |
| 74 |
typedef BOOL |
| 75 |
(WINAPI *setWindowFeedbackSetting_t)(HWND hwnd, FEEDBACK_TYPE feedback, DWORD dwFlags, UINT32 size, const VOID *configuration); |
| 76 |
|
| 77 |
static registerPointerDeviceNotifications_t registerPointerDeviceNotifications; |
| 78 |
static getPointerDevices_t getPointerDevices; |
| 79 |
static getPointerDeviceCursors_t getPointerDeviceCursors; |
| 80 |
static getPointerDeviceRects_t getPointerDeviceRects; |
| 81 |
static getPointerType_t getPointerType; |
| 82 |
static getPointerCursorId_t getPointerCursorId; |
| 83 |
static getPointerPenInfo_t getPointerPenInfo; |
| 84 |
static getPointerTouchInfo_t getPointerTouchInfo; |
| 85 |
static getPointerPenInfoHistory_t getPointerPenInfoHistory; |
| 86 |
static getPointerTouchInfoHistory_t getPointerTouchInfoHistory; |
| 87 |
static setGestureConfig_t setGestureConfig; |
| 88 |
static setWindowFeedbackSetting_t setWindowFeedbackSetting; |
| 89 |
|
| 90 |
static ATOM winpointer_notif_window_class; |
| 91 |
static HWND winpointer_notif_window_handle; |
| 92 |
|
| 93 |
static GPtrArray *winpointer_ignored_interactions; |
| 94 |
|
| 95 |
static GList *wintab_contexts = NULL; |
| 96 |
static GdkWindow *wintab_window = NULL; |
| 97 |
extern gint _gdk_input_ignore_core; |
| 98 |
|
| 99 |
typedef UINT (WINAPI *t_WTInfoA) (UINT a, UINT b, LPVOID c); |
| 100 |
typedef UINT (WINAPI *t_WTInfoW) (UINT a, UINT b, LPVOID c); |
| 101 |
typedef BOOL (WINAPI *t_WTEnable) (HCTX a, BOOL b); |
| 102 |
typedef HCTX (WINAPI *t_WTOpenA) (HWND a, LPLOGCONTEXTA b, BOOL c); |
| 103 |
typedef BOOL (WINAPI *t_WTGetA) (HCTX a, LPLOGCONTEXTA b); |
| 104 |
typedef BOOL (WINAPI *t_WTSetA) (HCTX a, LPLOGCONTEXTA b); |
| 105 |
typedef BOOL (WINAPI *t_WTOverlap) (HCTX a, BOOL b); |
| 106 |
typedef BOOL (WINAPI *t_WTPacket) (HCTX a, UINT b, LPVOID c); |
| 107 |
typedef int (WINAPI *t_WTQueueSizeSet) (HCTX a, int b); |
| 108 |
|
| 109 |
static t_WTInfoA p_WTInfoA; |
| 110 |
static t_WTInfoW p_WTInfoW; |
| 111 |
static t_WTEnable p_WTEnable; |
| 112 |
static t_WTOpenA p_WTOpenA; |
| 113 |
static t_WTGetA p_WTGetA; |
| 114 |
static t_WTSetA p_WTSetA; |
| 115 |
static t_WTOverlap p_WTOverlap; |
| 116 |
static t_WTPacket p_WTPacket; |
| 117 |
static t_WTQueueSizeSet p_WTQueueSizeSet; |
| 118 |
|
| 119 |
static gboolean default_display_opened = FALSE; |
| 120 |
|
| 121 |
G_DEFINE_TYPE (GdkDeviceManagerWin32, gdk_device_manager_win32, GDK_TYPE_DEVICE_MANAGER) |
| 122 |
|
| 123 |
static GdkDeviceWintab *gdk_device_manager_find_wintab_device (GdkDeviceManagerWin32 *, HCTX, UINT); |
| 124 |
UINT _wintab_recognize_new_cursors (GdkDeviceManagerWin32 *, HCTX); |
| 125 |
int _gdk_find_wintab_device_index (HCTX); |
| 126 |
|
| 127 |
static GdkDevice * |
| 128 |
create_pointer (GdkDeviceManager *device_manager, |
| 129 |
GType g_type, |
| 130 |
const char *name, |
| 131 |
GdkDeviceType type) |
| 132 |
{ |
| 133 |
return g_object_new (g_type, |
| 134 |
"name", name, |
| 135 |
"type", type, |
| 136 |
"input-source", GDK_SOURCE_MOUSE, |
| 137 |
"input-mode", GDK_MODE_SCREEN, |
| 138 |
"has-cursor", type == GDK_DEVICE_TYPE_MASTER, |
| 139 |
"display", gdk_device_manager_get_display (device_manager), |
| 140 |
"device-manager", device_manager, |
| 141 |
NULL); |
| 142 |
} |
| 143 |
|
| 144 |
static GdkDevice * |
| 145 |
create_keyboard (GdkDeviceManager *device_manager, |
| 146 |
GType g_type, |
| 147 |
const char *name, |
| 148 |
GdkDeviceType type) |
| 149 |
{ |
| 150 |
return g_object_new (g_type, |
| 151 |
"name", name, |
| 152 |
"type", type, |
| 153 |
"input-source", GDK_SOURCE_KEYBOARD, |
| 154 |
"input-mode", GDK_MODE_SCREEN, |
| 155 |
"has-cursor", FALSE, |
| 156 |
"display", gdk_device_manager_get_display (device_manager), |
| 157 |
"device-manager", device_manager, |
| 158 |
NULL); |
| 159 |
} |
| 160 |
|
| 161 |
static void |
| 162 |
gdk_device_manager_win32_init (GdkDeviceManagerWin32 *device_manager_win32) |
| 163 |
{ |
| 164 |
} |
| 165 |
|
| 166 |
static void |
| 167 |
gdk_device_manager_win32_finalize (GObject *object) |
| 168 |
{ |
| 169 |
GdkDeviceManagerWin32 *device_manager_win32; |
| 170 |
|
| 171 |
device_manager_win32 = GDK_DEVICE_MANAGER_WIN32 (object); |
| 172 |
|
| 173 |
g_object_unref (device_manager_win32->core_pointer); |
| 174 |
g_object_unref (device_manager_win32->core_keyboard); |
| 175 |
|
| 176 |
G_OBJECT_CLASS (gdk_device_manager_win32_parent_class)->finalize (object); |
| 177 |
} |
| 178 |
|
| 179 |
static inline double |
| 180 |
rect_width (RECT *rect) |
| 181 |
{ |
| 182 |
return rect->right - rect->left; |
| 183 |
} |
| 184 |
|
| 185 |
static inline double |
| 186 |
rect_height (RECT *rect) |
| 187 |
{ |
| 188 |
return rect->bottom - rect->top; |
| 189 |
} |
| 190 |
|
| 191 |
static inline gboolean |
| 192 |
rect_is_degenerate (RECT *rect) |
| 193 |
{ |
| 194 |
return rect_width (rect) == 0 || rect_height (rect) == 0; |
| 195 |
} |
| 196 |
|
| 197 |
static gboolean |
| 198 |
winpointer_device_update_scale_factors (GdkDeviceWinpointer *device) |
| 199 |
{ |
| 200 |
RECT device_rect; |
| 201 |
RECT display_rect; |
| 202 |
|
| 203 |
if (!getPointerDeviceRects (device->device_handle, &device_rect, &display_rect)) |
| 204 |
{ |
| 205 |
WIN32_API_FAILED ("GetPointerDeviceRects"); |
| 206 |
return FALSE; |
| 207 |
} |
| 208 |
|
| 209 |
if (rect_is_degenerate (&device_rect)) |
| 210 |
{ |
| 211 |
g_warning ("Invalid coordinates from GetPointerDeviceRects"); |
| 212 |
return FALSE; |
| 213 |
} |
| 214 |
|
| 215 |
device->origin_x = display_rect.left; |
| 216 |
device->origin_y = display_rect.top; |
| 217 |
device->scale_x = rect_width (&display_rect) / rect_width (&device_rect); |
| 218 |
device->scale_y = rect_height (&display_rect) / rect_height (&device_rect); |
| 219 |
|
| 220 |
return TRUE; |
| 221 |
} |
| 222 |
|
| 223 |
#define HID_STRING_BYTES_LIMIT 200 |
| 224 |
#define VID_PID_CHARS 4 |
| 225 |
|
| 226 |
static void |
| 227 |
winpointer_get_device_details (HANDLE device, |
| 228 |
char *vid, |
| 229 |
char *pid, |
| 230 |
char **manufacturer, |
| 231 |
char **product) |
| 232 |
{ |
| 233 |
RID_DEVICE_INFO info; |
| 234 |
UINT wchars_count = 0; |
| 235 |
UINT size = 0; |
| 236 |
|
| 237 |
memset (&info, 0, sizeof (info)); |
| 238 |
|
| 239 |
info.cbSize = sizeof (info); |
| 240 |
size = sizeof (info); |
| 241 |
|
| 242 |
if (GetRawInputDeviceInfoW (device, RIDI_DEVICEINFO, &info, &size) > 0 && |
| 243 |
info.dwType == RIM_TYPEHID && |
| 244 |
info.hid.dwVendorId > 0 && |
| 245 |
info.hid.dwProductId > 0) |
| 246 |
{ |
| 247 |
const char *format_string = "%0" G_STRINGIFY (VID_PID_CHARS) "x"; |
| 248 |
|
| 249 |
g_snprintf (vid, VID_PID_CHARS + 1, format_string, (unsigned) info.hid.dwVendorId); |
| 250 |
g_snprintf (pid, VID_PID_CHARS + 1, format_string, (unsigned) info.hid.dwProductId); |
| 251 |
} |
| 252 |
|
| 253 |
if (GetRawInputDeviceInfoW (device, RIDI_DEVICENAME, NULL, &wchars_count) == 0) |
| 254 |
{ |
| 255 |
gunichar2 *path = g_new0 (gunichar2, wchars_count); |
| 256 |
|
| 257 |
if (GetRawInputDeviceInfoW (device, RIDI_DEVICENAME, path, &wchars_count) > 0) |
| 258 |
{ |
| 259 |
HANDLE device_file = CreateFileW (path, |
| 260 |
0, |
| 261 |
FILE_SHARE_READ | |
| 262 |
FILE_SHARE_WRITE | |
| 263 |
FILE_SHARE_DELETE, |
| 264 |
NULL, |
| 265 |
OPEN_EXISTING, |
| 266 |
FILE_FLAG_SESSION_AWARE, |
| 267 |
NULL); |
| 268 |
|
| 269 |
if (device_file != INVALID_HANDLE_VALUE) |
| 270 |
{ |
| 271 |
gunichar2 *buffer = g_malloc0 (HID_STRING_BYTES_LIMIT); |
| 272 |
|
| 273 |
if (HidD_GetManufacturerString (device_file, buffer, HID_STRING_BYTES_LIMIT)) |
| 274 |
if (buffer[0]) |
| 275 |
*manufacturer = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL); |
| 276 |
|
| 277 |
if (HidD_GetProductString (device_file, buffer, HID_STRING_BYTES_LIMIT)) |
| 278 |
if (buffer[0]) |
| 279 |
*product = g_utf16_to_utf8 (buffer, -1, NULL, NULL, NULL); |
| 280 |
|
| 281 |
g_free (buffer); |
| 282 |
CloseHandle (device_file); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
g_free (path); |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
static void |
| 291 |
winpointer_create_device (GdkDeviceManagerWin32 *device_manager, |
| 292 |
POINTER_DEVICE_INFO *info, |
| 293 |
GdkInputSource source) |
| 294 |
{ |
| 295 |
GdkDisplay *display = NULL; |
| 296 |
GdkSeat *seat = NULL; |
| 297 |
GdkDeviceWinpointer *device = NULL; |
| 298 |
unsigned num_touches = 0; |
| 299 |
char vid[VID_PID_CHARS + 1]; |
| 300 |
char pid[VID_PID_CHARS + 1]; |
| 301 |
char *manufacturer = NULL; |
| 302 |
char *product = NULL; |
| 303 |
char *base_name = NULL; |
| 304 |
char *name = NULL; |
| 305 |
UINT32 num_cursors = 0; |
| 306 |
|
| 307 |
memset (pid, 0, VID_PID_CHARS + 1); |
| 308 |
memset (vid, 0, VID_PID_CHARS + 1); |
| 309 |
|
| 310 |
g_object_get (device_manager, "display", &display, NULL); |
| 311 |
seat = gdk_display_get_default_seat (display); |
| 312 |
|
| 313 |
if (!getPointerDeviceCursors (info->device, &num_cursors, NULL)) |
| 314 |
{ |
| 315 |
WIN32_API_FAILED ("GetPointerDeviceCursors"); |
| 316 |
return; |
| 317 |
} |
| 318 |
|
| 319 |
if (num_cursors == 0) |
| 320 |
return; |
| 321 |
|
| 322 |
winpointer_get_device_details (info->device, vid, pid, &manufacturer, &product); |
| 323 |
|
| 324 |
/* build up the name */ |
| 325 |
if (!manufacturer && vid[0]) |
| 326 |
manufacturer = g_strdup (vid); |
| 327 |
|
| 328 |
if (!product && pid[0]) |
| 329 |
product = g_strdup (pid); |
| 330 |
|
| 331 |
if (manufacturer && product) |
| 332 |
base_name = g_strconcat (manufacturer, " ", product, NULL); |
| 333 |
|
| 334 |
if (!base_name && info->productString[0]) |
| 335 |
base_name = g_utf16_to_utf8 (info->productString, -1, NULL, NULL, NULL); |
| 336 |
|
| 337 |
if (!base_name) |
| 338 |
base_name = g_strdup ("Unnamed"); |
| 339 |
|
| 340 |
switch (source) |
| 341 |
{ |
| 342 |
case GDK_SOURCE_PEN: |
| 343 |
name = g_strconcat (base_name, " Pen stylus", NULL); |
| 344 |
break; |
| 345 |
case GDK_SOURCE_ERASER: |
| 346 |
name = g_strconcat (base_name, " Eraser", NULL); |
| 347 |
break; |
| 348 |
case GDK_SOURCE_TOUCHSCREEN: |
| 349 |
num_touches = info->maxActiveContacts; |
| 350 |
name = g_strconcat (base_name, " Finger touch", NULL); |
| 351 |
break; |
| 352 |
default: |
| 353 |
name = g_strdup (base_name); |
| 354 |
break; |
| 355 |
} |
| 356 |
|
| 357 |
device = g_object_new (GDK_TYPE_DEVICE_WINPOINTER, |
| 358 |
"display", display, |
| 359 |
"device-manager", device_manager, |
| 360 |
"seat", seat, |
| 361 |
"type", GDK_DEVICE_TYPE_SLAVE, |
| 362 |
"input-mode", GDK_MODE_SCREEN, |
| 363 |
"has-cursor", TRUE, |
| 364 |
"input-source", source, |
| 365 |
"name", name, |
| 366 |
"num-touches", num_touches, |
| 367 |
"vendor-id", vid[0] ? vid : NULL, |
| 368 |
"product-id", pid[0] ? pid : NULL, |
| 369 |
NULL); |
| 370 |
|
| 371 |
switch (source) |
| 372 |
{ |
| 373 |
case GDK_SOURCE_PEN: |
| 374 |
case GDK_SOURCE_ERASER: |
| 375 |
_gdk_device_add_axis (GDK_DEVICE (device), GDK_NONE, GDK_AXIS_PRESSURE, 0.0, 1.0, 1.0 / 1024.0); |
| 376 |
_gdk_device_add_axis (GDK_DEVICE (device), GDK_NONE, GDK_AXIS_XTILT, -1.0, 1.0, 1.0 / 90.0); |
| 377 |
_gdk_device_add_axis (GDK_DEVICE (device), GDK_NONE, GDK_AXIS_YTILT, -1.0, 1.0, 1.0 / 90.0); |
| 378 |
_gdk_device_add_axis (GDK_DEVICE (device), GDK_NONE, GDK_AXIS_ROTATION, 0.0, 1.0, 1.0 / 360.0); |
| 379 |
|
| 380 |
device->num_axes = 4; |
| 381 |
break; |
| 382 |
case GDK_SOURCE_TOUCHSCREEN: |
| 383 |
_gdk_device_add_axis (GDK_DEVICE (device), GDK_NONE, GDK_AXIS_PRESSURE, 0.0, 1.0, 1.0 / 1024.0); |
| 384 |
|
| 385 |
device->num_axes = 1; |
| 386 |
break; |
| 387 |
} |
| 388 |
|
| 389 |
device->device_handle = info->device; |
| 390 |
device->start_cursor_id = info->startingCursorId; |
| 391 |
device->end_cursor_id = info->startingCursorId + num_cursors - 1; |
| 392 |
|
| 393 |
device->last_axis_data = g_new0 (double, device->num_axes); |
| 394 |
|
| 395 |
switch (source) |
| 396 |
{ |
| 397 |
case GDK_SOURCE_PEN: |
| 398 |
{ |
| 399 |
GdkAxisFlags axes = gdk_device_get_axes (GDK_DEVICE (device)); |
| 400 |
GdkDeviceTool *tool = gdk_device_tool_new (0, 0, GDK_DEVICE_TOOL_TYPE_PEN, axes); |
| 401 |
|
| 402 |
gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool); |
| 403 |
gdk_device_update_tool (GDK_DEVICE (device), tool); |
| 404 |
} |
| 405 |
break; |
| 406 |
case GDK_SOURCE_ERASER: |
| 407 |
{ |
| 408 |
GdkAxisFlags axes = gdk_device_get_axes (GDK_DEVICE (device)); |
| 409 |
GdkDeviceTool *tool = gdk_device_tool_new (0, 0, GDK_DEVICE_TOOL_TYPE_ERASER, axes); |
| 410 |
|
| 411 |
gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool); |
| 412 |
gdk_device_update_tool (GDK_DEVICE (device), tool); |
| 413 |
} |
| 414 |
break; |
| 415 |
case GDK_SOURCE_TOUCHSCREEN: |
| 416 |
break; |
| 417 |
} |
| 418 |
|
| 419 |
if (!winpointer_device_update_scale_factors (device)) |
| 420 |
{ |
| 421 |
g_set_object (&device, NULL); |
| 422 |
goto cleanup; |
| 423 |
} |
| 424 |
|
| 425 |
device_manager->winpointer_devices = g_list_append (device_manager->winpointer_devices, device); |
| 426 |
|
| 427 |
_gdk_device_set_associated_device (GDK_DEVICE (device), device_manager->core_pointer); |
| 428 |
_gdk_device_add_slave (device_manager->core_pointer, GDK_DEVICE (device)); |
| 429 |
|
| 430 |
gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), GDK_DEVICE (device)); |
| 431 |
|
| 432 |
g_signal_emit_by_name (device_manager, "device-added", device); |
| 433 |
|
| 434 |
cleanup: |
| 435 |
g_free (name); |
| 436 |
g_free (base_name); |
| 437 |
g_free (product); |
| 438 |
g_free (manufacturer); |
| 439 |
} |
| 440 |
|
| 441 |
static void |
| 442 |
winpointer_create_devices (GdkDeviceManagerWin32 *device_manager, |
| 443 |
POINTER_DEVICE_INFO *info) |
| 444 |
{ |
| 445 |
switch (info->pointerDeviceType) |
| 446 |
{ |
| 447 |
case POINTER_DEVICE_TYPE_INTEGRATED_PEN: |
| 448 |
case POINTER_DEVICE_TYPE_EXTERNAL_PEN: |
| 449 |
winpointer_create_device (device_manager, info, GDK_SOURCE_PEN); |
| 450 |
winpointer_create_device (device_manager, info, GDK_SOURCE_ERASER); |
| 451 |
break; |
| 452 |
case POINTER_DEVICE_TYPE_TOUCH: |
| 453 |
winpointer_create_device (device_manager, info, GDK_SOURCE_TOUCHSCREEN); |
| 454 |
break; |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
static gboolean |
| 459 |
winpointer_match_device_in_system_list (GdkDeviceWinpointer *device, |
| 460 |
POINTER_DEVICE_INFO *infos, |
| 461 |
UINT32 infos_count) |
| 462 |
{ |
| 463 |
UINT32 i = 0; |
| 464 |
|
| 465 |
for (i = 0; i < infos_count; i++) |
| 466 |
{ |
| 467 |
if (device->device_handle == infos[i].device && |
| 468 |
device->start_cursor_id == infos[i].startingCursorId) |
| 469 |
return TRUE; |
| 470 |
} |
| 471 |
|
| 472 |
return FALSE; |
| 473 |
} |
| 474 |
|
| 475 |
static gboolean |
| 476 |
winpointer_match_system_device_in_device_manager (GdkDeviceManagerWin32 *device_manager, |
| 477 |
POINTER_DEVICE_INFO *info) |
| 478 |
{ |
| 479 |
GList *l = NULL; |
| 480 |
|
| 481 |
for (l = device_manager->winpointer_devices; l; l = l->next) |
| 482 |
{ |
| 483 |
GdkDeviceWinpointer *device = GDK_DEVICE_WINPOINTER (l->data); |
| 484 |
|
| 485 |
if (device->device_handle == info->device && |
| 486 |
device->start_cursor_id == info->startingCursorId) |
| 487 |
return TRUE; |
| 488 |
} |
| 489 |
|
| 490 |
return FALSE; |
| 491 |
} |
| 492 |
|
| 493 |
static void |
| 494 |
winpointer_enumerate_devices (GdkDeviceManagerWin32 *device_manager) |
| 495 |
{ |
| 496 |
POINTER_DEVICE_INFO *infos = NULL; |
| 497 |
UINT32 infos_count = 0; |
| 498 |
UINT32 i = 0; |
| 499 |
GList *current = NULL; |
| 500 |
|
| 501 |
if (!getPointerDevices (&infos_count, NULL)) |
| 502 |
{ |
| 503 |
WIN32_API_FAILED ("GetPointerDevices"); |
| 504 |
return; |
| 505 |
} |
| 506 |
|
| 507 |
infos = g_new0 (POINTER_DEVICE_INFO, infos_count); |
| 508 |
|
| 509 |
/* Note: the device count may increase between the two |
| 510 |
* calls. In such case, the second call will fail with |
| 511 |
* ERROR_INSUFFICIENT_BUFFER. |
| 512 |
* However we'll also get a new WM_POINTERDEVICECHANGE |
| 513 |
* notification, which will start the enumeration again. |
| 514 |
* So do not treat ERROR_INSUFFICIENT_BUFFER as an |
| 515 |
* error, rather return and do the necessary work later |
| 516 |
*/ |
| 517 |
|
| 518 |
if (!getPointerDevices (&infos_count, infos)) |
| 519 |
{ |
| 520 |
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) |
| 521 |
WIN32_API_FAILED ("GetPointerDevices"); |
| 522 |
g_free (infos); |
| 523 |
return; |
| 524 |
} |
| 525 |
|
| 526 |
/* remove any gdk device not present anymore or update info */ |
| 527 |
current = device_manager->winpointer_devices; |
| 528 |
while (current != NULL) |
| 529 |
{ |
| 530 |
GdkDeviceWinpointer *device = GDK_DEVICE_WINPOINTER (current->data); |
| 531 |
GList *next = current->next; |
| 532 |
|
| 533 |
if (!winpointer_match_device_in_system_list (device, infos, infos_count)) |
| 534 |
{ |
| 535 |
GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (device)); |
| 536 |
GdkDeviceTool *tool = (GDK_DEVICE (device))->last_tool; |
| 537 |
|
| 538 |
gdk_device_update_tool (GDK_DEVICE (device), NULL); |
| 539 |
gdk_seat_default_remove_tool (GDK_SEAT_DEFAULT (seat), tool); |
| 540 |
g_clear_pointer (&tool, g_object_unref); |
| 541 |
|
| 542 |
gdk_seat_default_remove_slave (GDK_SEAT_DEFAULT (seat), GDK_DEVICE (device)); |
| 543 |
device_manager->winpointer_devices = g_list_delete_link (device_manager->winpointer_devices, |
| 544 |
current); |
| 545 |
g_signal_emit_by_name (device_manager, "device-removed", device); |
| 546 |
|
| 547 |
_gdk_device_set_associated_device (GDK_DEVICE (device), NULL); |
| 548 |
_gdk_device_remove_slave (device_manager->core_pointer, GDK_DEVICE (device)); |
| 549 |
|
| 550 |
g_object_unref (device); |
| 551 |
} |
| 552 |
else |
| 553 |
winpointer_device_update_scale_factors (device); |
| 554 |
|
| 555 |
current = next; |
| 556 |
} |
| 557 |
|
| 558 |
/* create new gdk devices */ |
| 559 |
for (i = 0; i < infos_count; i++) |
| 560 |
if (!winpointer_match_system_device_in_device_manager (device_manager, |
| 561 |
&infos[i])) |
| 562 |
winpointer_create_devices (device_manager, &infos[i]); |
| 563 |
|
| 564 |
g_free (infos); |
| 565 |
} |
| 566 |
|
| 567 |
static LRESULT CALLBACK |
| 568 |
winpointer_notif_window_proc (HWND hWnd, |
| 569 |
UINT uMsg, |
| 570 |
WPARAM wParam, |
| 571 |
LPARAM lParam) |
| 572 |
{ |
| 573 |
switch (uMsg) |
| 574 |
{ |
| 575 |
case WM_POINTERDEVICECHANGE: |
| 576 |
{ |
| 577 |
LONG_PTR user_data = GetWindowLongPtrW (hWnd, GWLP_USERDATA); |
| 578 |
GdkDeviceManagerWin32 *device_manager = GDK_DEVICE_MANAGER_WIN32 (user_data); |
| 579 |
|
| 580 |
winpointer_enumerate_devices (device_manager); |
| 581 |
} |
| 582 |
return 0; |
| 583 |
} |
| 584 |
|
| 585 |
return DefWindowProcW (hWnd, uMsg, wParam, lParam); |
| 586 |
} |
| 587 |
|
| 588 |
static gboolean |
| 589 |
winpointer_notif_window_create () |
| 590 |
{ |
| 591 |
WNDCLASSEXW wndclass; |
| 592 |
|
| 593 |
memset (&wndclass, 0, sizeof (wndclass)); |
| 594 |
wndclass.cbSize = sizeof (wndclass); |
| 595 |
wndclass.lpszClassName = L"GdkWin32WinPointerNotificationsWindowClass"; |
| 596 |
wndclass.lpfnWndProc = winpointer_notif_window_proc; |
| 597 |
wndclass.hInstance = _gdk_dll_hinstance; |
| 598 |
|
| 599 |
if ((winpointer_notif_window_class = RegisterClassExW (&wndclass)) == 0) |
| 600 |
{ |
| 601 |
WIN32_API_FAILED ("RegisterClassExW"); |
| 602 |
return FALSE; |
| 603 |
} |
| 604 |
|
| 605 |
if (!(winpointer_notif_window_handle = CreateWindowExW (0, |
| 606 |
(LPCWSTR) winpointer_notif_window_class, |
| 607 |
L"GdkWin32 WinPointer Notifications", |
| 608 |
0, |
| 609 |
0, 0, 0, 0, |
| 610 |
HWND_MESSAGE, |
| 611 |
NULL, |
| 612 |
_gdk_dll_hinstance, |
| 613 |
NULL))) |
| 614 |
{ |
| 615 |
WIN32_API_FAILED ("CreateWindowExW"); |
| 616 |
return FALSE; |
| 617 |
} |
| 618 |
|
| 619 |
return TRUE; |
| 620 |
} |
| 621 |
|
| 622 |
static gboolean |
| 623 |
winpointer_ensure_procedures () |
| 624 |
{ |
| 625 |
static HMODULE user32_dll = NULL; |
| 626 |
|
| 627 |
if (!user32_dll) |
| 628 |
{ |
| 629 |
user32_dll = LoadLibraryW (L"user32.dll"); |
| 630 |
if (!user32_dll) |
| 631 |
{ |
| 632 |
WIN32_API_FAILED ("LoadLibraryW"); |
| 633 |
return FALSE; |
| 634 |
} |
| 635 |
|
| 636 |
registerPointerDeviceNotifications = (registerPointerDeviceNotifications_t) |
| 637 |
GetProcAddress (user32_dll, "RegisterPointerDeviceNotifications"); |
| 638 |
getPointerDevices = (getPointerDevices_t) |
| 639 |
GetProcAddress (user32_dll, "GetPointerDevices"); |
| 640 |
getPointerDeviceCursors = (getPointerDeviceCursors_t) |
| 641 |
GetProcAddress (user32_dll, "GetPointerDeviceCursors"); |
| 642 |
getPointerDeviceRects = (getPointerDeviceRects_t) |
| 643 |
GetProcAddress (user32_dll, "GetPointerDeviceRects"); |
| 644 |
getPointerType = (getPointerType_t) |
| 645 |
GetProcAddress (user32_dll, "GetPointerType"); |
| 646 |
getPointerCursorId = (getPointerCursorId_t) |
| 647 |
GetProcAddress (user32_dll, "GetPointerCursorId"); |
| 648 |
getPointerPenInfo = (getPointerPenInfo_t) |
| 649 |
GetProcAddress (user32_dll, "GetPointerPenInfo"); |
| 650 |
getPointerTouchInfo = (getPointerTouchInfo_t) |
| 651 |
GetProcAddress (user32_dll, "GetPointerTouchInfo"); |
| 652 |
getPointerPenInfoHistory = (getPointerPenInfoHistory_t) |
| 653 |
GetProcAddress (user32_dll, "GetPointerPenInfoHistory"); |
| 654 |
getPointerTouchInfoHistory = (getPointerTouchInfoHistory_t) |
| 655 |
GetProcAddress (user32_dll, "GetPointerTouchInfoHistory"); |
| 656 |
setGestureConfig = (setGestureConfig_t) |
| 657 |
GetProcAddress (user32_dll, "SetGestureConfig"); |
| 658 |
setWindowFeedbackSetting = (setWindowFeedbackSetting_t) |
| 659 |
GetProcAddress (user32_dll, "SetWindowFeedbackSetting"); |
| 660 |
} |
| 661 |
|
| 662 |
return registerPointerDeviceNotifications && |
| 663 |
getPointerDevices && |
| 664 |
getPointerDeviceCursors && |
| 665 |
getPointerDeviceRects && |
| 666 |
getPointerType && |
| 667 |
getPointerCursorId && |
| 668 |
getPointerPenInfo && |
| 669 |
getPointerTouchInfo && |
| 670 |
getPointerPenInfoHistory && |
| 671 |
getPointerTouchInfoHistory && |
| 672 |
setGestureConfig; |
| 673 |
} |
| 674 |
|
| 675 |
static gboolean |
| 676 |
winpointer_initialize (GdkDeviceManagerWin32 *device_manager) |
| 677 |
{ |
| 678 |
if (!winpointer_ensure_procedures ()) |
| 679 |
return FALSE; |
| 680 |
|
| 681 |
if (!winpointer_notif_window_create ()) |
| 682 |
return FALSE; |
| 683 |
|
| 684 |
/* associate device_manager with the window */ |
| 685 |
SetLastError (0); |
| 686 |
if (SetWindowLongPtrW (winpointer_notif_window_handle, |
| 687 |
GWLP_USERDATA, |
| 688 |
(LONG_PTR) device_manager) == 0 |
| 689 |
&& GetLastError () != 0) |
| 690 |
{ |
| 691 |
WIN32_API_FAILED ("SetWindowLongPtrW"); |
| 692 |
return FALSE; |
| 693 |
} |
| 694 |
|
| 695 |
if (!registerPointerDeviceNotifications (winpointer_notif_window_handle, FALSE)) |
| 696 |
{ |
| 697 |
WIN32_API_FAILED ("RegisterPointerDeviceNotifications"); |
| 698 |
return FALSE; |
| 699 |
} |
| 700 |
|
| 701 |
winpointer_ignored_interactions = g_ptr_array_new (); |
| 702 |
|
| 703 |
winpointer_enumerate_devices (device_manager); |
| 704 |
|
| 705 |
return TRUE; |
| 706 |
} |
| 707 |
|
| 708 |
void |
| 709 |
gdk_winpointer_initialize_window (GdkWindow *window) |
| 710 |
{ |
| 711 |
HWND hwnd = GDK_WINDOW_HWND (window); |
| 712 |
ATOM key = 0; |
| 713 |
HANDLE val = (HANDLE)(TABLET_DISABLE_PRESSANDHOLD | |
| 714 |
TABLET_DISABLE_PENTAPFEEDBACK | |
| 715 |
TABLET_DISABLE_PENBARRELFEEDBACK | |
| 716 |
TABLET_DISABLE_FLICKS | |
| 717 |
TABLET_DISABLE_FLICKFALLBACKKEYS); |
| 718 |
|
| 719 |
winpointer_ensure_procedures (); |
| 720 |
|
| 721 |
key = GlobalAddAtom (MICROSOFT_TABLETPENSERVICE_PROPERTY); |
| 722 |
API_CALL (SetPropW, (hwnd, (LPCWSTR) key, val)); |
| 723 |
GlobalDeleteAtom (key); |
| 724 |
|
| 725 |
if (setGestureConfig != NULL) |
| 726 |
{ |
| 727 |
GESTURECONFIG gesture_config; |
| 728 |
memset (&gesture_config, 0, sizeof (gesture_config)); |
| 729 |
|
| 730 |
gesture_config.dwID = 0; |
| 731 |
gesture_config.dwWant = 0; |
| 732 |
gesture_config.dwBlock = GC_ALLGESTURES; |
| 733 |
|
| 734 |
API_CALL (setGestureConfig, (hwnd, 0, 1, &gesture_config, sizeof (gesture_config))); |
| 735 |
} |
| 736 |
|
| 737 |
if (setWindowFeedbackSetting != NULL) |
| 738 |
{ |
| 739 |
FEEDBACK_TYPE feedbacks[] = { |
| 740 |
FEEDBACK_TOUCH_CONTACTVISUALIZATION, |
| 741 |
FEEDBACK_PEN_BARRELVISUALIZATION, |
| 742 |
FEEDBACK_PEN_TAP, |
| 743 |
FEEDBACK_PEN_DOUBLETAP, |
| 744 |
FEEDBACK_PEN_PRESSANDHOLD, |
| 745 |
FEEDBACK_PEN_RIGHTTAP, |
| 746 |
FEEDBACK_TOUCH_TAP, |
| 747 |
FEEDBACK_TOUCH_DOUBLETAP, |
| 748 |
FEEDBACK_TOUCH_PRESSANDHOLD, |
| 749 |
FEEDBACK_TOUCH_RIGHTTAP, |
| 750 |
FEEDBACK_GESTURE_PRESSANDTAP |
| 751 |
}; |
| 752 |
gsize i = 0; |
| 753 |
|
| 754 |
for (i = 0; i < G_N_ELEMENTS (feedbacks); i++) |
| 755 |
{ |
| 756 |
BOOL setting = FALSE; |
| 757 |
|
| 758 |
API_CALL (setWindowFeedbackSetting, (hwnd, feedbacks[i], 0, sizeof (BOOL), &setting)); |
| 759 |
} |
| 760 |
} |
| 761 |
} |
| 762 |
|
| 763 |
void |
| 764 |
gdk_winpointer_finalize_window (GdkWindow *window) |
| 765 |
{ |
| 766 |
HWND hwnd = GDK_WINDOW_HWND (window); |
| 767 |
ATOM key = 0; |
| 768 |
|
| 769 |
key = GlobalAddAtom (MICROSOFT_TABLETPENSERVICE_PROPERTY); |
| 770 |
RemovePropW (hwnd, (LPCWSTR) key); |
| 771 |
GlobalDeleteAtom (key); |
| 772 |
} |
| 773 |
|
| 774 |
#if DEBUG_WINTAB |
| 775 |
|
| 776 |
static void |
| 777 |
print_lc(LOGCONTEXT *lc) |
| 778 |
{ |
| 779 |
g_print ("lcName = %s\n", lc->lcName); |
| 780 |
g_print ("lcOptions ="); |
| 781 |
if (lc->lcOptions & CXO_SYSTEM) g_print (" CXO_SYSTEM"); |
| 782 |
if (lc->lcOptions & CXO_PEN) g_print (" CXO_PEN"); |
| 783 |
if (lc->lcOptions & CXO_MESSAGES) g_print (" CXO_MESSAGES"); |
| 784 |
if (lc->lcOptions & CXO_MARGIN) g_print (" CXO_MARGIN"); |
| 785 |
if (lc->lcOptions & CXO_MGNINSIDE) g_print (" CXO_MGNINSIDE"); |
| 786 |
if (lc->lcOptions & CXO_CSRMESSAGES) g_print (" CXO_CSRMESSAGES"); |
| 787 |
g_print ("\n"); |
| 788 |
g_print ("lcStatus ="); |
| 789 |
if (lc->lcStatus & CXS_DISABLED) g_print (" CXS_DISABLED"); |
| 790 |
if (lc->lcStatus & CXS_OBSCURED) g_print (" CXS_OBSCURED"); |
| 791 |
if (lc->lcStatus & CXS_ONTOP) g_print (" CXS_ONTOP"); |
| 792 |
g_print ("\n"); |
| 793 |
g_print ("lcLocks ="); |
| 794 |
if (lc->lcLocks & CXL_INSIZE) g_print (" CXL_INSIZE"); |
| 795 |
if (lc->lcLocks & CXL_INASPECT) g_print (" CXL_INASPECT"); |
| 796 |
if (lc->lcLocks & CXL_SENSITIVITY) g_print (" CXL_SENSITIVITY"); |
| 797 |
if (lc->lcLocks & CXL_MARGIN) g_print (" CXL_MARGIN"); |
| 798 |
g_print ("\n"); |
| 799 |
g_print ("lcMsgBase = %#x, lcDevice = %#x, lcPktRate = %d\n", |
| 800 |
lc->lcMsgBase, lc->lcDevice, lc->lcPktRate); |
| 801 |
g_print ("lcPktData ="); |
| 802 |
if (lc->lcPktData & PK_CONTEXT) g_print (" PK_CONTEXT"); |
| 803 |
if (lc->lcPktData & PK_STATUS) g_print (" PK_STATUS"); |
| 804 |
if (lc->lcPktData & PK_TIME) g_print (" PK_TIME"); |
| 805 |
if (lc->lcPktData & PK_CHANGED) g_print (" PK_CHANGED"); |
| 806 |
if (lc->lcPktData & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); |
| 807 |
if (lc->lcPktData & PK_CURSOR) g_print (" PK_CURSOR"); |
| 808 |
if (lc->lcPktData & PK_BUTTONS) g_print (" PK_BUTTONS"); |
| 809 |
if (lc->lcPktData & PK_X) g_print (" PK_X"); |
| 810 |
if (lc->lcPktData & PK_Y) g_print (" PK_Y"); |
| 811 |
if (lc->lcPktData & PK_Z) g_print (" PK_Z"); |
| 812 |
if (lc->lcPktData & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); |
| 813 |
if (lc->lcPktData & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); |
| 814 |
if (lc->lcPktData & PK_ORIENTATION) g_print (" PK_ORIENTATION"); |
| 815 |
if (lc->lcPktData & PK_ROTATION) g_print (" PK_ROTATION"); |
| 816 |
g_print ("\n"); |
| 817 |
g_print ("lcPktMode ="); |
| 818 |
if (lc->lcPktMode & PK_CONTEXT) g_print (" PK_CONTEXT"); |
| 819 |
if (lc->lcPktMode & PK_STATUS) g_print (" PK_STATUS"); |
| 820 |
if (lc->lcPktMode & PK_TIME) g_print (" PK_TIME"); |
| 821 |
if (lc->lcPktMode & PK_CHANGED) g_print (" PK_CHANGED"); |
| 822 |
if (lc->lcPktMode & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); |
| 823 |
if (lc->lcPktMode & PK_CURSOR) g_print (" PK_CURSOR"); |
| 824 |
if (lc->lcPktMode & PK_BUTTONS) g_print (" PK_BUTTONS"); |
| 825 |
if (lc->lcPktMode & PK_X) g_print (" PK_X"); |
| 826 |
if (lc->lcPktMode & PK_Y) g_print (" PK_Y"); |
| 827 |
if (lc->lcPktMode & PK_Z) g_print (" PK_Z"); |
| 828 |
if (lc->lcPktMode & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); |
| 829 |
if (lc->lcPktMode & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); |
| 830 |
if (lc->lcPktMode & PK_ORIENTATION) g_print (" PK_ORIENTATION"); |
| 831 |
if (lc->lcPktMode & PK_ROTATION) g_print (" PK_ROTATION"); |
| 832 |
g_print ("\n"); |
| 833 |
g_print ("lcMoveMask ="); |
| 834 |
if (lc->lcMoveMask & PK_CONTEXT) g_print (" PK_CONTEXT"); |
| 835 |
if (lc->lcMoveMask & PK_STATUS) g_print (" PK_STATUS"); |
| 836 |
if (lc->lcMoveMask & PK_TIME) g_print (" PK_TIME"); |
| 837 |
if (lc->lcMoveMask & PK_CHANGED) g_print (" PK_CHANGED"); |
| 838 |
if (lc->lcMoveMask & PK_SERIAL_NUMBER) g_print (" PK_SERIAL_NUMBER"); |
| 839 |
if (lc->lcMoveMask & PK_CURSOR) g_print (" PK_CURSOR"); |
| 840 |
if (lc->lcMoveMask & PK_BUTTONS) g_print (" PK_BUTTONS"); |
| 841 |
if (lc->lcMoveMask & PK_X) g_print (" PK_X"); |
| 842 |
if (lc->lcMoveMask & PK_Y) g_print (" PK_Y"); |
| 843 |
if (lc->lcMoveMask & PK_Z) g_print (" PK_Z"); |
| 844 |
if (lc->lcMoveMask & PK_NORMAL_PRESSURE) g_print (" PK_NORMAL_PRESSURE"); |
| 845 |
if (lc->lcMoveMask & PK_TANGENT_PRESSURE) g_print (" PK_TANGENT_PRESSURE"); |
| 846 |
if (lc->lcMoveMask & PK_ORIENTATION) g_print (" PK_ORIENTATION"); |
| 847 |
if (lc->lcMoveMask & PK_ROTATION) g_print (" PK_ROTATION"); |
| 848 |
g_print ("\n"); |
| 849 |
g_print ("lcBtnDnMask = %#x, lcBtnUpMask = %#x\n", |
| 850 |
(guint) lc->lcBtnDnMask, (guint) lc->lcBtnUpMask); |
| 851 |
g_print ("lcInOrgX = %ld, lcInOrgY = %ld, lcInOrgZ = %ld\n", |
| 852 |
lc->lcInOrgX, lc->lcInOrgY, lc->lcInOrgZ); |
| 853 |
g_print ("lcInExtX = %ld, lcInExtY = %ld, lcInExtZ = %ld\n", |
| 854 |
lc->lcInExtX, lc->lcInExtY, lc->lcInExtZ); |
| 855 |
g_print ("lcOutOrgX = %ld, lcOutOrgY = %ld, lcOutOrgZ = %ld\n", |
| 856 |
lc->lcOutOrgX, lc->lcOutOrgY, lc->lcOutOrgZ); |
| 857 |
g_print ("lcOutExtX = %ld, lcOutExtY = %ld, lcOutExtZ = %ld\n", |
| 858 |
lc->lcOutExtX, lc->lcOutExtY, lc->lcOutExtZ); |
| 859 |
g_print ("lcSensX = %g, lcSensY = %g, lcSensZ = %g\n", |
| 860 |
lc->lcSensX / 65536., lc->lcSensY / 65536., lc->lcSensZ / 65536.); |
| 861 |
g_print ("lcSysMode = %d\n", lc->lcSysMode); |
| 862 |
g_print ("lcSysOrgX = %d, lcSysOrgY = %d\n", |
| 863 |
lc->lcSysOrgX, lc->lcSysOrgY); |
| 864 |
g_print ("lcSysExtX = %d, lcSysExtY = %d\n", |
| 865 |
lc->lcSysExtX, lc->lcSysExtY); |
| 866 |
g_print ("lcSysSensX = %g, lcSysSensY = %g\n", |
| 867 |
lc->lcSysSensX / 65536., lc->lcSysSensY / 65536.); |
| 868 |
} |
| 869 |
|
| 870 |
static void |
| 871 |
print_cursor (int index) |
| 872 |
{ |
| 873 |
int size; |
| 874 |
int i; |
| 875 |
char *name; |
| 876 |
BOOL active; |
| 877 |
WTPKT wtpkt; |
| 878 |
BYTE buttons; |
| 879 |
BYTE buttonbits; |
| 880 |
char *btnnames; |
| 881 |
char *p; |
| 882 |
BYTE buttonmap[32]; |
| 883 |
BYTE sysbtnmap[32]; |
| 884 |
BYTE npbutton; |
| 885 |
UINT npbtnmarks[2]; |
| 886 |
UINT *npresponse; |
| 887 |
BYTE tpbutton; |
| 888 |
UINT tpbtnmarks[2]; |
| 889 |
UINT *tpresponse; |
| 890 |
DWORD physid; |
| 891 |
UINT mode; |
| 892 |
UINT minpktdata; |
| 893 |
UINT minbuttons; |
| 894 |
UINT capabilities; |
| 895 |
|
| 896 |
size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, NULL); |
| 897 |
name = g_malloc (size + 1); |
| 898 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_NAME, name); |
| 899 |
g_print ("NAME: %s\n", name); |
| 900 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_ACTIVE, &active); |
| 901 |
g_print ("ACTIVE: %s\n", active ? "YES" : "NO"); |
| 902 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_PKTDATA, &wtpkt); |
| 903 |
g_print ("PKTDATA: %#x:", (guint) wtpkt); |
| 904 |
#define BIT(x) if (wtpkt & PK_##x) g_print (" " #x) |
| 905 |
BIT (CONTEXT); |
| 906 |
BIT (STATUS); |
| 907 |
BIT (TIME); |
| 908 |
BIT (CHANGED); |
| 909 |
BIT (SERIAL_NUMBER); |
| 910 |
BIT (BUTTONS); |
| 911 |
BIT (X); |
| 912 |
BIT (Y); |
| 913 |
BIT (Z); |
| 914 |
BIT (NORMAL_PRESSURE); |
| 915 |
BIT (TANGENT_PRESSURE); |
| 916 |
BIT (ORIENTATION); |
| 917 |
BIT (ROTATION); |
| 918 |
#undef BIT |
| 919 |
g_print ("\n"); |
| 920 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONS, &buttons); |
| 921 |
g_print ("BUTTONS: %d\n", buttons); |
| 922 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONBITS, &buttonbits); |
| 923 |
g_print ("BUTTONBITS: %d\n", buttonbits); |
| 924 |
size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, NULL); |
| 925 |
g_print ("BTNNAMES:"); |
| 926 |
if (size > 0) |
| 927 |
{ |
| 928 |
btnnames = g_malloc (size + 1); |
| 929 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_BTNNAMES, btnnames); |
| 930 |
p = btnnames; |
| 931 |
while (*p) |
| 932 |
{ |
| 933 |
g_print (" %s", p); |
| 934 |
p += strlen (p) + 1; |
| 935 |
} |
| 936 |
} |
| 937 |
g_print ("\n"); |
| 938 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_BUTTONMAP, buttonmap); |
| 939 |
g_print ("BUTTONMAP:"); |
| 940 |
for (i = 0; i < buttons; i++) |
| 941 |
g_print (" %d", buttonmap[i]); |
| 942 |
g_print ("\n"); |
| 943 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_SYSBTNMAP, sysbtnmap); |
| 944 |
g_print ("SYSBTNMAP:"); |
| 945 |
for (i = 0; i < buttons; i++) |
| 946 |
g_print (" %d", sysbtnmap[i]); |
| 947 |
g_print ("\n"); |
| 948 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBUTTON, &npbutton); |
| 949 |
g_print ("NPBUTTON: %d\n", npbutton); |
| 950 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_NPBTNMARKS, npbtnmarks); |
| 951 |
g_print ("NPBTNMARKS: %d %d\n", npbtnmarks[0], npbtnmarks[1]); |
| 952 |
size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, NULL); |
| 953 |
g_print ("NPRESPONSE:"); |
| 954 |
if (size > 0) |
| 955 |
{ |
| 956 |
npresponse = g_malloc (size); |
| 957 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_NPRESPONSE, npresponse); |
| 958 |
for (i = 0; i < size / sizeof (UINT); i++) |
| 959 |
g_print (" %d", npresponse[i]); |
| 960 |
} |
| 961 |
g_print ("\n"); |
| 962 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBUTTON, &tpbutton); |
| 963 |
g_print ("TPBUTTON: %d\n", tpbutton); |
| 964 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_TPBTNMARKS, tpbtnmarks); |
| 965 |
g_print ("TPBTNMARKS: %d %d\n", tpbtnmarks[0], tpbtnmarks[1]); |
| 966 |
size = (*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, NULL); |
| 967 |
g_print ("TPRESPONSE:"); |
| 968 |
if (size > 0) |
| 969 |
{ |
| 970 |
tpresponse = g_malloc (size); |
| 971 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_TPRESPONSE, tpresponse); |
| 972 |
for (i = 0; i < size / sizeof (UINT); i++) |
| 973 |
g_print (" %d", tpresponse[i]); |
| 974 |
} |
| 975 |
g_print ("\n"); |
| 976 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_PHYSID, &physid); |
| 977 |
g_print ("PHYSID: %#x\n", (guint) physid); |
| 978 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_CAPABILITIES, &capabilities); |
| 979 |
g_print ("CAPABILITIES: %#x:", capabilities); |
| 980 |
#define BIT(x) if (capabilities & CRC_##x) g_print (" " #x) |
| 981 |
BIT (MULTIMODE); |
| 982 |
BIT (AGGREGATE); |
| 983 |
BIT (INVERT); |
| 984 |
#undef BIT |
| 985 |
g_print ("\n"); |
| 986 |
if (capabilities & CRC_MULTIMODE) |
| 987 |
{ |
| 988 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_MODE, &mode); |
| 989 |
g_print ("MODE: %d\n", mode); |
| 990 |
} |
| 991 |
if (capabilities & CRC_AGGREGATE) |
| 992 |
{ |
| 993 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_MINPKTDATA, &minpktdata); |
| 994 |
g_print ("MINPKTDATA: %d\n", minpktdata); |
| 995 |
(*p_WTInfoA) (WTI_CURSORS + index, CSR_MINBUTTONS, &minbuttons); |
| 996 |
g_print ("MINBUTTONS: %d\n", minbuttons); |
| 997 |
} |
| 998 |
} |
| 999 |
#endif |
| 1000 |
|
| 1001 |
static void |
| 1002 |
wintab_init_check (GdkDeviceManagerWin32 *device_manager) |
| 1003 |
{ |
| 1004 |
GdkDisplay *display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (device_manager)); |
| 1005 |
GdkWindow *root = gdk_screen_get_root_window (gdk_display_get_default_screen (display)); |
| 1006 |
static gboolean wintab_initialized = FALSE; |
| 1007 |
GdkWindowAttr wa; |
| 1008 |
WORD specversion; |
| 1009 |
HCTX *hctx; |
| 1010 |
UINT ndevices, ncursors; |
| 1011 |
UINT devix; |
| 1012 |
AXIS axis_x, axis_y; |
| 1013 |
int i; |
| 1014 |
wchar_t devname[100]; |
| 1015 |
gchar *devname_utf8; |
| 1016 |
BOOL defcontext_done; |
| 1017 |
HMODULE wintab32; |
| 1018 |
char *wintab32_dll_path; |
| 1019 |
char dummy; |
| 1020 |
int n, k; |
| 1021 |
|
| 1022 |
if (wintab_initialized) |
| 1023 |
return; |
| 1024 |
|
| 1025 |
wintab_initialized = TRUE; |
| 1026 |
|
| 1027 |
wintab_contexts = NULL; |
| 1028 |
|
| 1029 |
n = GetSystemDirectory (&dummy, 0); |
| 1030 |
|
| 1031 |
if (n <= 0) |
| 1032 |
return; |
| 1033 |
|
| 1034 |
wintab32_dll_path = g_malloc (n + 1 + strlen (WINTAB32_DLL)); |
| 1035 |
k = GetSystemDirectory (wintab32_dll_path, n); |
| 1036 |
|
| 1037 |
if (k == 0 || k > n) |
| 1038 |
{ |
| 1039 |
g_free (wintab32_dll_path); |
| 1040 |
return; |
| 1041 |
} |
| 1042 |
|
| 1043 |
if (!G_IS_DIR_SEPARATOR (wintab32_dll_path[strlen (wintab32_dll_path) -1])) |
| 1044 |
strcat (wintab32_dll_path, G_DIR_SEPARATOR_S); |
| 1045 |
strcat (wintab32_dll_path, WINTAB32_DLL); |
| 1046 |
|
| 1047 |
if ((wintab32 = LoadLibrary (wintab32_dll_path)) == NULL) |
| 1048 |
return; |
| 1049 |
|
| 1050 |
if ((p_WTInfoA = (t_WTInfoA) GetProcAddress (wintab32, "WTInfoA")) == NULL) |
| 1051 |
return; |
| 1052 |
if ((p_WTInfoW = (t_WTInfoW) GetProcAddress (wintab32, "WTInfoW")) == NULL) |
| 1053 |
return; |
| 1054 |
if ((p_WTEnable = (t_WTEnable) GetProcAddress (wintab32, "WTEnable")) == NULL) |
| 1055 |
return; |
| 1056 |
if ((p_WTOpenA = (t_WTOpenA) GetProcAddress (wintab32, "WTOpenA")) == NULL) |
| 1057 |
return; |
| 1058 |
if ((p_WTGetA = (t_WTGetA) GetProcAddress (wintab32, "WTGetA")) == NULL) |
| 1059 |
return; |
| 1060 |
if ((p_WTSetA = (t_WTSetA) GetProcAddress (wintab32, "WTSetA")) == NULL) |
| 1061 |
return; |
| 1062 |
if ((p_WTOverlap = (t_WTOverlap) GetProcAddress (wintab32, "WTOverlap")) == NULL) |
| 1063 |
return; |
| 1064 |
if ((p_WTPacket = (t_WTPacket) GetProcAddress (wintab32, "WTPacket")) == NULL) |
| 1065 |
return; |
| 1066 |
if ((p_WTQueueSizeSet = (t_WTQueueSizeSet) GetProcAddress (wintab32, "WTQueueSizeSet")) == NULL) |
| 1067 |
return; |
| 1068 |
|
| 1069 |
if (!(*p_WTInfoA) (0, 0, NULL)) |
| 1070 |
return; |
| 1071 |
|
| 1072 |
(*p_WTInfoA) (WTI_INTERFACE, IFC_SPECVERSION, &specversion); |
| 1073 |
GDK_NOTE (INPUT, g_print ("Wintab interface version %d.%d\n", |
| 1074 |
HIBYTE (specversion), LOBYTE (specversion))); |
| 1075 |
(*p_WTInfoA) (WTI_INTERFACE, IFC_NDEVICES, &ndevices); |
| 1076 |
(*p_WTInfoA) (WTI_INTERFACE, IFC_NCURSORS, &ncursors); |
| 1077 |
#if DEBUG_WINTAB |
| 1078 |
GDK_NOTE (INPUT, g_print ("NDEVICES: %d, NCURSORS: %d\n", |
| 1079 |
ndevices, ncursors)); |
| 1080 |
#endif |
| 1081 |
/* Create a dummy window to receive wintab events */ |
| 1082 |
wa.wclass = GDK_INPUT_OUTPUT; |
| 1083 |
wa.event_mask = GDK_ALL_EVENTS_MASK; |
| 1084 |
wa.width = 2; |
| 1085 |
wa.height = 2; |
| 1086 |
wa.x = -100; |
| 1087 |
wa.y = -100; |
| 1088 |
wa.window_type = GDK_WINDOW_TOPLEVEL; |
| 1089 |
if ((wintab_window = gdk_window_new (root, &wa, GDK_WA_X | GDK_WA_Y)) == NULL) |
| 1090 |
{ |
| 1091 |
g_warning ("gdk_input_wintab_init: gdk_window_new failed"); |
| 1092 |
return; |
| 1093 |
} |
| 1094 |
g_object_ref (wintab_window); |
| 1095 |
|
| 1096 |
for (devix = 0; devix < ndevices; devix++) |
| 1097 |
{ |
| 1098 |
LOGCONTEXT lc; |
| 1099 |
|
| 1100 |
/* We open the Wintab device (hmm, what if there are several, or |
| 1101 |
* can there even be several, probably not?) as a system |
| 1102 |
* pointing device, i.e. it controls the normal Windows |
| 1103 |
* cursor. This seems much more natural. |
| 1104 |
*/ |
| 1105 |
|
| 1106 |
(*p_WTInfoW) (WTI_DEVICES + devix, DVC_NAME, devname); |
| 1107 |
devname_utf8 = g_utf16_to_utf8 (devname, -1, NULL, NULL, NULL); |
| 1108 |
#ifdef DEBUG_WINTAB |
| 1109 |
GDK_NOTE (INPUT, (g_print("Device %u: %s\n", devix, devname_utf8))); |
| 1110 |
#endif |
| 1111 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_X, &axis_x); |
| 1112 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_Y, &axis_y); |
| 1113 |
|
| 1114 |
defcontext_done = FALSE; |
| 1115 |
if (HIBYTE (specversion) > 1 || LOBYTE (specversion) >= 1) |
| 1116 |
{ |
| 1117 |
/* Try to get device-specific default context */ |
| 1118 |
/* Some drivers, e.g. Aiptek, don't provide this info */ |
| 1119 |
if ((*p_WTInfoA) (WTI_DSCTXS + devix, 0, &lc) > 0) |
| 1120 |
defcontext_done = TRUE; |
| 1121 |
#if DEBUG_WINTAB |
| 1122 |
if (defcontext_done) |
| 1123 |
GDK_NOTE (INPUT, (g_print("Using device-specific default context\n"))); |
| 1124 |
else |
| 1125 |
GDK_NOTE (INPUT, (g_print("Note: Driver did not provide device specific default context info despite claiming to support version 1.1\n"))); |
| 1126 |
#endif |
| 1127 |
} |
| 1128 |
|
| 1129 |
if (!defcontext_done) |
| 1130 |
(*p_WTInfoA) (WTI_DEFSYSCTX, 0, &lc); |
| 1131 |
#if DEBUG_WINTAB |
| 1132 |
GDK_NOTE (INPUT, (g_print("Default context:\n"), print_lc(&lc))); |
| 1133 |
#endif |
| 1134 |
lc.lcOptions |= CXO_MESSAGES | CXO_CSRMESSAGES; |
| 1135 |
lc.lcStatus = 0; |
| 1136 |
lc.lcMsgBase = WT_DEFBASE; |
| 1137 |
lc.lcPktRate = 0; |
| 1138 |
lc.lcPktData = PACKETDATA; |
| 1139 |
lc.lcPktMode = PACKETMODE; |
| 1140 |
lc.lcMoveMask = PACKETDATA; |
| 1141 |
lc.lcBtnUpMask = lc.lcBtnDnMask = ~0; |
| 1142 |
lc.lcOutOrgX = axis_x.axMin; |
| 1143 |
lc.lcOutOrgY = axis_y.axMin; |
| 1144 |
lc.lcOutExtX = axis_x.axMax - axis_x.axMin + 1; |
| 1145 |
lc.lcOutExtY = axis_y.axMax - axis_y.axMin + 1; |
| 1146 |
lc.lcOutExtY = -lc.lcOutExtY; /* We want Y growing downward */ |
| 1147 |
#if DEBUG_WINTAB |
| 1148 |
GDK_NOTE (INPUT, (g_print("context for device %u:\n", devix), |
| 1149 |
print_lc(&lc))); |
| 1150 |
#endif |
| 1151 |
hctx = g_new (HCTX, 1); |
| 1152 |
if ((*hctx = (*p_WTOpenA) (GDK_WINDOW_HWND (wintab_window), &lc, TRUE)) == NULL) |
| 1153 |
{ |
| 1154 |
g_warning ("gdk_input_wintab_init: WTOpen failed"); |
| 1155 |
return; |
| 1156 |
} |
| 1157 |
GDK_NOTE (INPUT, g_print ("opened Wintab device %u %p\n", |
| 1158 |
devix, *hctx)); |
| 1159 |
|
| 1160 |
wintab_contexts = g_list_append (wintab_contexts, hctx); |
| 1161 |
|
| 1162 |
/* Set the CXO_SYSTEM flag */ |
| 1163 |
if (!(lc.lcOptions & CXO_SYSTEM)) |
| 1164 |
{ |
| 1165 |
lc.lcOptions |= CXO_SYSTEM; |
| 1166 |
if (!p_WTSetA (*hctx, &lc)) |
| 1167 |
g_warning ("Could not set the CXO_SYSTEM option in the WINTAB context"); |
| 1168 |
} |
| 1169 |
|
| 1170 |
(*p_WTOverlap) (*hctx, TRUE); |
| 1171 |
|
| 1172 |
#if DEBUG_WINTAB |
| 1173 |
GDK_NOTE (INPUT, (g_print("context for device %u after WTOpen:\n", devix), |
| 1174 |
print_lc(&lc))); |
| 1175 |
#endif |
| 1176 |
/* Increase packet queue size to reduce the risk of lost packets. |
| 1177 |
* According to the specs, if the function fails we must try again |
| 1178 |
* with a smaller queue size. |
| 1179 |
*/ |
| 1180 |
GDK_NOTE (INPUT, g_print("Attempting to increase queue size\n")); |
| 1181 |
for (i = 128; i >= 1; i >>= 1) |
| 1182 |
{ |
| 1183 |
if ((*p_WTQueueSizeSet) (*hctx, i)) |
| 1184 |
{ |
| 1185 |
GDK_NOTE (INPUT, g_print("Queue size set to %d\n", i)); |
| 1186 |
break; |
| 1187 |
} |
| 1188 |
} |
| 1189 |
if (!i) |
| 1190 |
GDK_NOTE (INPUT, g_print("Whoops, no queue size could be set\n")); |
| 1191 |
|
| 1192 |
/* Get the cursors that Wintab is currently aware of */ |
| 1193 |
_wintab_recognize_new_cursors(device_manager, *hctx); |
| 1194 |
} |
| 1195 |
} |
| 1196 |
|
| 1197 |
UINT |
| 1198 |
_wintab_recognize_new_cursors (GdkDeviceManagerWin32 *device_manager, |
| 1199 |
HCTX hctx) |
| 1200 |
{ |
| 1201 |
GdkDisplay *display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (device_manager)); |
| 1202 |
int devix; |
| 1203 |
wchar_t devname[100], csrname[100]; |
| 1204 |
gchar *devname_utf8, *csrname_utf8, *device_name; |
| 1205 |
UINT ncsrtypes, firstcsr, cursorix; |
| 1206 |
BOOL active; |
| 1207 |
DWORD physid; |
| 1208 |
AXIS axis_x, axis_y, axis_npressure, axis_or[3], axis_tpressure; |
| 1209 |
GdkDeviceWintab *device; |
| 1210 |
LOGCONTEXT lc; |
| 1211 |
int num_axes; |
| 1212 |
UINT num_new_cursors = 0; |
| 1213 |
|
| 1214 |
devix = _gdk_find_wintab_device_index(hctx); |
| 1215 |
if (devix == -1) |
| 1216 |
return num_new_cursors; |
| 1217 |
|
| 1218 |
(*p_WTInfoW) (WTI_DEVICES + devix, DVC_NAME, devname); |
| 1219 |
devname_utf8 = g_utf16_to_utf8 (devname, -1, NULL, NULL, NULL); |
| 1220 |
#ifdef DEBUG_WINTAB |
| 1221 |
GDK_NOTE (INPUT, (g_print("Finding cursors for device %u: %s\n", devix, devname_utf8))); |
| 1222 |
#endif |
| 1223 |
|
| 1224 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_FIRSTCSR, &firstcsr); |
| 1225 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_NCSRTYPES, &ncsrtypes); |
| 1226 |
for (cursorix = firstcsr; cursorix < firstcsr + ncsrtypes; cursorix++) |
| 1227 |
{ |
| 1228 |
#ifdef DEBUG_WINTAB |
| 1229 |
GDK_NOTE (INPUT, (g_print("Cursor %u:\n", cursorix), print_cursor (cursorix))); |
| 1230 |
#endif |
| 1231 |
/* Skip cursors that are already known to us */ |
| 1232 |
if (gdk_device_manager_find_wintab_device(device_manager, hctx, cursorix) != NULL) |
| 1233 |
continue; |
| 1234 |
|
| 1235 |
active = FALSE; |
| 1236 |
(*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_ACTIVE, &active); |
| 1237 |
if (!active) |
| 1238 |
continue; |
| 1239 |
|
| 1240 |
/* Wacom tablets iterate through all possible cursors, |
| 1241 |
* even if the cursor's presence has not been recognized. |
| 1242 |
* Unrecognized cursors have a physid of zero and are ignored. |
| 1243 |
* Recognized cursors have a non-zero physid and we create a |
| 1244 |
* Wintab device object for each of them. |
| 1245 |
*/ |
| 1246 |
(*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PHYSID, &physid); |
| 1247 |
if (wcscmp (devname, L"WACOM Tablet") == 0 && physid == 0) |
| 1248 |
continue; |
| 1249 |
|
| 1250 |
if (!(*p_WTGetA) (hctx, &lc)) |
| 1251 |
{ |
| 1252 |
g_warning ("wintab_recognize_new_cursors: Failed to retrieve device LOGCONTEXT"); |
| 1253 |
continue; |
| 1254 |
} |
| 1255 |
|
| 1256 |
/* Create a Wintab device for this cursor */ |
| 1257 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_X, &axis_x); |
| 1258 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_Y, &axis_y); |
| 1259 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_NPRESSURE, &axis_npressure); |
| 1260 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_ORIENTATION, axis_or); |
| 1261 |
(*p_WTInfoA) (WTI_DEVICES + devix, DVC_TPRESSURE, &axis_tpressure); |
| 1262 |
(*p_WTInfoW) (WTI_CURSORS + cursorix, CSR_NAME, csrname); |
| 1263 |
csrname_utf8 = g_utf16_to_utf8 (csrname, -1, NULL, NULL, NULL); |
| 1264 |
device_name = g_strconcat (devname_utf8, " ", csrname_utf8, NULL); |
| 1265 |
g_free (csrname_utf8); |
| 1266 |
|
| 1267 |
device = g_object_new (GDK_TYPE_DEVICE_WINTAB, |
| 1268 |
"name", device_name, |
| 1269 |
"type", GDK_DEVICE_TYPE_FLOATING, |
| 1270 |
"input-source", GDK_SOURCE_PEN, |
| 1271 |
"input-mode", GDK_MODE_SCREEN, |
| 1272 |
"has-cursor", lc.lcOptions & CXO_SYSTEM, |
| 1273 |
"display", display, |
| 1274 |
"device-manager", device_manager, |
| 1275 |
NULL); |
| 1276 |
|
| 1277 |
device->sends_core = lc.lcOptions & CXO_SYSTEM; |
| 1278 |
if (device->sends_core) |
| 1279 |
{ |
| 1280 |
_gdk_device_set_associated_device (device_manager->system_pointer, GDK_DEVICE (device)); |
| 1281 |
_gdk_device_add_slave (device_manager->core_pointer, GDK_DEVICE (device)); |
| 1282 |
} |
| 1283 |
|
| 1284 |
device->hctx = hctx; |
| 1285 |
device->cursor = cursorix; |
| 1286 |
(*p_WTInfoA) (WTI_CURSORS + cursorix, CSR_PKTDATA, &device->pktdata); |
| 1287 |
num_axes = 0; |
| 1288 |
|
| 1289 |
if (device->pktdata & PK_X) |
| 1290 |
{ |
| 1291 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1292 |
GDK_NONE, |
| 1293 |
GDK_AXIS_X, |
| 1294 |
axis_x.axMin, |
| 1295 |
axis_x.axMax, |
| 1296 |
axis_x.axResolution / 65535); |
| 1297 |
num_axes++; |
| 1298 |
} |
| 1299 |
|
| 1300 |
if (device->pktdata & PK_Y) |
| 1301 |
{ |
| 1302 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1303 |
GDK_NONE, |
| 1304 |
GDK_AXIS_Y, |
| 1305 |
axis_y.axMin, |
| 1306 |
axis_y.axMax, |
| 1307 |
axis_y.axResolution / 65535); |
| 1308 |
num_axes++; |
| 1309 |
} |
| 1310 |
|
| 1311 |
if (device->pktdata & PK_NORMAL_PRESSURE) |
| 1312 |
{ |
| 1313 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1314 |
GDK_NONE, |
| 1315 |
GDK_AXIS_PRESSURE, |
| 1316 |
axis_npressure.axMin, |
| 1317 |
axis_npressure.axMax, |
| 1318 |
axis_npressure.axResolution / 65535); |
| 1319 |
num_axes++; |
| 1320 |
} |
| 1321 |
|
| 1322 |
if (device->pktdata & PK_ORIENTATION) |
| 1323 |
{ |
| 1324 |
if (device->pktdata & PK_TANGENT_PRESSURE) /* If we have a wheel, disable the twist axis */ |
| 1325 |
axis_or[2].axResolution = 0; |
| 1326 |
|
| 1327 |
device->orientation_axes[0] = axis_or[0]; |
| 1328 |
device->orientation_axes[1] = axis_or[1]; |
| 1329 |
device->orientation_axes[2] = axis_or[2]; |
| 1330 |
|
| 1331 |
/* Wintab gives us azimuth and altitude, which |
| 1332 |
* we convert to x and y tilt in the -1000..1000 range |
| 1333 |
*/ |
| 1334 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1335 |
GDK_NONE, |
| 1336 |
GDK_AXIS_XTILT, |
| 1337 |
-1000, |
| 1338 |
1000, |
| 1339 |
1000); |
| 1340 |
|
| 1341 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1342 |
GDK_NONE, |
| 1343 |
GDK_AXIS_YTILT, |
| 1344 |
-1000, |
| 1345 |
1000, |
| 1346 |
1000); |
| 1347 |
num_axes += 2; |
| 1348 |
|
| 1349 |
if (axis_or[2].axResolution != 0) /* If twist is present */ |
| 1350 |
{ |
| 1351 |
/* Wacom's Wintab driver returns the rotation |
| 1352 |
* of an Art Pen as the orientation twist value. |
| 1353 |
* We're using GDK_AXIS_WHEEL as it's actually |
| 1354 |
* called Wheel/Rotation to the user. |
| 1355 |
* axMin and axMax are back to front on purpose. If you put them |
| 1356 |
* the "correct" way round, rotation will be flipped! |
| 1357 |
*/ |
| 1358 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1359 |
GDK_NONE, |
| 1360 |
GDK_AXIS_WHEEL, |
| 1361 |
axis_or[2].axMax, |
| 1362 |
axis_or[2].axMin, |
| 1363 |
axis_or[2].axResolution / 65535); |
| 1364 |
num_axes++; |
| 1365 |
} |
| 1366 |
} |
| 1367 |
|
| 1368 |
if (device->pktdata & PK_TANGENT_PRESSURE) |
| 1369 |
{ |
| 1370 |
/* This is the finger wheel on a Wacom Airbrush |
| 1371 |
*/ |
| 1372 |
_gdk_device_add_axis (GDK_DEVICE (device), |
| 1373 |
GDK_NONE, |
| 1374 |
GDK_AXIS_WHEEL, |
| 1375 |
axis_tpressure.axMin, |
| 1376 |
axis_tpressure.axMax, |
| 1377 |
axis_tpressure.axResolution / 65535); |
| 1378 |
num_axes++; |
| 1379 |
} |
| 1380 |
|
| 1381 |
device->last_axis_data = g_new (gint, num_axes); |
| 1382 |
|
| 1383 |
GDK_NOTE (INPUT, g_print ("device: (%u) %s axes: %d\n", |
| 1384 |
cursorix, |
| 1385 |
device_name, |
| 1386 |
num_axes)); |
| 1387 |
|
| 1388 |
#if 0 |
| 1389 |
for (i = 0; i < gdkdev->info.num_axes; i++) |
| 1390 |
GDK_NOTE (INPUT, g_print ("... axis %d: %d--%d@%d\n", |
| 1391 |
i, |
| 1392 |
gdkdev->axes[i].min_value, |
| 1393 |
gdkdev->axes[i].max_value, |
| 1394 |
gdkdev->axes[i].resolution)); |
| 1395 |
#endif |
| 1396 |
|
| 1397 |
device_manager->wintab_devices = g_list_append (device_manager->wintab_devices, |
| 1398 |
device); |
| 1399 |
num_new_cursors++; |
| 1400 |
g_free (device_name); |
| 1401 |
} |
| 1402 |
g_free (devname_utf8); |
| 1403 |
return num_new_cursors; |
| 1404 |
} |
| 1405 |
|
| 1406 |
/* Only initialize Wintab after the default display is set for |
| 1407 |
* the first time. WTOpenA() executes code beyond our control, |
| 1408 |
* and it can cause messages to be sent to the application even |
| 1409 |
* before a window is opened. GDK has to be in a fit state to |
| 1410 |
* handle them when they come. |
| 1411 |
* |
| 1412 |
* https://bugzilla.gnome.org/show_bug.cgi?id=774379 |
| 1413 |
*/ |
| 1414 |
static void |
| 1415 |
wintab_default_display_notify_cb (GdkDisplayManager *display_manager) |
| 1416 |
{ |
| 1417 |
GdkDeviceManagerWin32 *device_manager = NULL; |
| 1418 |
GdkDisplay *display = gdk_display_get_default(); |
| 1419 |
|
| 1420 |
if (default_display_opened) |
| 1421 |
return; |
| 1422 |
|
| 1423 |
g_assert (display != NULL); |
| 1424 |
|
| 1425 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 1426 |
device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display)); |
| 1427 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 1428 |
g_assert (display_manager != NULL); |
| 1429 |
|
| 1430 |
default_display_opened = TRUE; |
| 1431 |
GDK_NOTE (INPUT, g_print ("wintab init: doing delayed initialization\n")); |
| 1432 |
wintab_init_check (device_manager); |
| 1433 |
} |
| 1434 |
|
| 1435 |
static void |
| 1436 |
gdk_device_manager_win32_constructed (GObject *object) |
| 1437 |
{ |
| 1438 |
GdkDeviceManagerWin32 *device_manager; |
| 1439 |
GdkSeat *seat; |
| 1440 |
GdkDisplayManager *display_manager = NULL; |
| 1441 |
GdkDisplay *default_display = NULL; |
| 1442 |
const char *tablet_input_api_user_preference = NULL; |
| 1443 |
gboolean have_tablet_input_api_preference = FALSE; |
| 1444 |
|
| 1445 |
device_manager = GDK_DEVICE_MANAGER_WIN32 (object); |
| 1446 |
device_manager->core_pointer = |
| 1447 |
create_pointer (GDK_DEVICE_MANAGER (device_manager), |
| 1448 |
GDK_TYPE_DEVICE_VIRTUAL, |
| 1449 |
"Virtual Core Pointer", |
| 1450 |
GDK_DEVICE_TYPE_MASTER); |
| 1451 |
device_manager->system_pointer = |
| 1452 |
create_pointer (GDK_DEVICE_MANAGER (device_manager), |
| 1453 |
GDK_TYPE_DEVICE_WIN32, |
| 1454 |
"System Aggregated Pointer", |
| 1455 |
GDK_DEVICE_TYPE_SLAVE); |
| 1456 |
_gdk_device_virtual_set_active (device_manager->core_pointer, |
| 1457 |
device_manager->system_pointer); |
| 1458 |
_gdk_device_set_associated_device (device_manager->system_pointer, device_manager->core_pointer); |
| 1459 |
_gdk_device_add_slave (device_manager->core_pointer, device_manager->system_pointer); |
| 1460 |
|
| 1461 |
device_manager->core_keyboard = |
| 1462 |
create_keyboard (GDK_DEVICE_MANAGER (device_manager), |
| 1463 |
GDK_TYPE_DEVICE_VIRTUAL, |
| 1464 |
"Virtual Core Keyboard", |
| 1465 |
GDK_DEVICE_TYPE_MASTER); |
| 1466 |
device_manager->system_keyboard = |
| 1467 |
create_keyboard (GDK_DEVICE_MANAGER (device_manager), |
| 1468 |
GDK_TYPE_DEVICE_WIN32, |
| 1469 |
"System Aggregated Keyboard", |
| 1470 |
GDK_DEVICE_TYPE_SLAVE); |
| 1471 |
_gdk_device_virtual_set_active (device_manager->core_keyboard, |
| 1472 |
device_manager->system_keyboard); |
| 1473 |
_gdk_device_set_associated_device (device_manager->system_keyboard, device_manager->core_keyboard); |
| 1474 |
_gdk_device_add_slave (device_manager->core_keyboard, device_manager->system_keyboard); |
| 1475 |
|
| 1476 |
_gdk_device_set_associated_device (device_manager->core_pointer, device_manager->core_keyboard); |
| 1477 |
_gdk_device_set_associated_device (device_manager->core_keyboard, device_manager->core_pointer); |
| 1478 |
|
| 1479 |
seat = gdk_seat_default_new_for_master_pair (device_manager->core_pointer, |
| 1480 |
device_manager->core_keyboard); |
| 1481 |
gdk_display_add_seat (gdk_device_manager_get_display (GDK_DEVICE_MANAGER (object)), seat); |
| 1482 |
gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), device_manager->system_pointer); |
| 1483 |
gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), device_manager->system_keyboard); |
| 1484 |
g_object_unref (seat); |
| 1485 |
|
| 1486 |
tablet_input_api_user_preference = g_getenv ("GDK_WIN32_TABLET_INPUT_API"); |
| 1487 |
if (g_strcmp0 (tablet_input_api_user_preference, "none") == 0) |
| 1488 |
{ |
| 1489 |
have_tablet_input_api_preference = TRUE; |
| 1490 |
_gdk_win32_tablet_input_api = GDK_WIN32_TABLET_INPUT_API_NONE; |
| 1491 |
} |
| 1492 |
else if (g_strcmp0 (tablet_input_api_user_preference, "wintab") == 0) |
| 1493 |
{ |
| 1494 |
have_tablet_input_api_preference = TRUE; |
| 1495 |
_gdk_win32_tablet_input_api = GDK_WIN32_TABLET_INPUT_API_WINTAB; |
| 1496 |
} |
| 1497 |
else if (g_strcmp0 (tablet_input_api_user_preference, "winpointer") == 0) |
| 1498 |
{ |
| 1499 |
have_tablet_input_api_preference = TRUE; |
| 1500 |
_gdk_win32_tablet_input_api = GDK_WIN32_TABLET_INPUT_API_WINPOINTER; |
| 1501 |
} |
| 1502 |
else |
| 1503 |
{ |
| 1504 |
have_tablet_input_api_preference = FALSE; |
| 1505 |
_gdk_win32_tablet_input_api = GDK_WIN32_TABLET_INPUT_API_WINPOINTER; |
| 1506 |
} |
| 1507 |
|
| 1508 |
if (_gdk_win32_tablet_input_api == GDK_WIN32_TABLET_INPUT_API_WINPOINTER) |
| 1509 |
{ |
| 1510 |
if (!winpointer_initialize (device_manager) && |
| 1511 |
!have_tablet_input_api_preference) |
| 1512 |
_gdk_win32_tablet_input_api = GDK_WIN32_TABLET_INPUT_API_WINTAB; |
| 1513 |
} |
| 1514 |
|
| 1515 |
if (_gdk_win32_tablet_input_api == GDK_WIN32_TABLET_INPUT_API_WINTAB) |
| 1516 |
{ |
| 1517 |
/* Only call Wintab init stuff after the default display |
| 1518 |
* is globally known and accessible through the display manager |
| 1519 |
* singleton. Approach lifted from gtkmodules.c. |
| 1520 |
*/ |
| 1521 |
display_manager = gdk_display_manager_get(); |
| 1522 |
g_assert (display_manager != NULL); |
| 1523 |
default_display = gdk_display_manager_get_default_display (display_manager); |
| 1524 |
g_assert (default_display == NULL); |
| 1525 |
|
| 1526 |
g_signal_connect (display_manager, "notify::default-display", |
| 1527 |
G_CALLBACK (wintab_default_display_notify_cb), |
| 1528 |
NULL); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
|
| 1532 |
static GList * |
| 1533 |
gdk_device_manager_win32_list_devices (GdkDeviceManager *device_manager, |
| 1534 |
GdkDeviceType type) |
| 1535 |
{ |
| 1536 |
GdkDeviceManagerWin32 *device_manager_win32; |
| 1537 |
GList *devices = NULL, *l; |
| 1538 |
|
| 1539 |
device_manager_win32 = (GdkDeviceManagerWin32 *) device_manager; |
| 1540 |
|
| 1541 |
if (type == GDK_DEVICE_TYPE_MASTER) |
| 1542 |
{ |
| 1543 |
devices = g_list_prepend (devices, device_manager_win32->core_keyboard); |
| 1544 |
devices = g_list_prepend (devices, device_manager_win32->core_pointer); |
| 1545 |
} |
| 1546 |
else |
| 1547 |
{ |
| 1548 |
if (type == GDK_DEVICE_TYPE_SLAVE) |
| 1549 |
{ |
| 1550 |
devices = g_list_prepend (devices, device_manager_win32->system_keyboard); |
| 1551 |
devices = g_list_prepend (devices, device_manager_win32->system_pointer); |
| 1552 |
} |
| 1553 |
|
| 1554 |
for (l = device_manager_win32->winpointer_devices; l != NULL; l = l->next) |
| 1555 |
{ |
| 1556 |
GdkDevice *device = l->data; |
| 1557 |
|
| 1558 |
if (gdk_device_get_device_type (device) == type) |
| 1559 |
devices = g_list_prepend (devices, device); |
| 1560 |
} |
| 1561 |
|
| 1562 |
for (l = device_manager_win32->wintab_devices; l != NULL; l = l->next) |
| 1563 |
{ |
| 1564 |
GdkDevice *device = l->data; |
| 1565 |
|
| 1566 |
if (gdk_device_get_device_type (device) == type) |
| 1567 |
devices = g_list_prepend (devices, device); |
| 1568 |
} |
| 1569 |
} |
| 1570 |
|
| 1571 |
return g_list_reverse (devices); |
| 1572 |
} |
| 1573 |
|
| 1574 |
static GdkDevice * |
| 1575 |
gdk_device_manager_win32_get_client_pointer (GdkDeviceManager *device_manager) |
| 1576 |
{ |
| 1577 |
GdkDeviceManagerWin32 *device_manager_win32; |
| 1578 |
|
| 1579 |
device_manager_win32 = (GdkDeviceManagerWin32 *) device_manager; |
| 1580 |
return device_manager_win32->core_pointer; |
| 1581 |
} |
| 1582 |
|
| 1583 |
static void |
| 1584 |
gdk_device_manager_win32_class_init (GdkDeviceManagerWin32Class *klass) |
| 1585 |
{ |
| 1586 |
GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass); |
| 1587 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
| 1588 |
|
| 1589 |
object_class->finalize = gdk_device_manager_win32_finalize; |
| 1590 |
object_class->constructed = gdk_device_manager_win32_constructed; |
| 1591 |
device_manager_class->list_devices = gdk_device_manager_win32_list_devices; |
| 1592 |
device_manager_class->get_client_pointer = gdk_device_manager_win32_get_client_pointer; |
| 1593 |
} |
| 1594 |
|
| 1595 |
static inline void |
| 1596 |
winpointer_ignore_interaction (UINT32 pointer_id) |
| 1597 |
{ |
| 1598 |
g_ptr_array_add (winpointer_ignored_interactions, GUINT_TO_POINTER (pointer_id)); |
| 1599 |
} |
| 1600 |
|
| 1601 |
static inline void |
| 1602 |
winpointer_remove_ignored_interaction (UINT32 pointer_id) |
| 1603 |
{ |
| 1604 |
g_ptr_array_remove_fast (winpointer_ignored_interactions, GUINT_TO_POINTER (pointer_id)); |
| 1605 |
} |
| 1606 |
|
| 1607 |
static inline gboolean |
| 1608 |
winpointer_should_ignore_interaction (UINT32 pointer_id) |
| 1609 |
{ |
| 1610 |
return g_ptr_array_find (winpointer_ignored_interactions, GUINT_TO_POINTER (pointer_id), NULL); |
| 1611 |
} |
| 1612 |
|
| 1613 |
static inline guint32 |
| 1614 |
winpointer_get_time (MSG *msg, POINTER_INFO *info) |
| 1615 |
{ |
| 1616 |
return info->dwTime != 0 ? info->dwTime : msg->time; |
| 1617 |
} |
| 1618 |
|
| 1619 |
static inline gboolean |
| 1620 |
winpointer_is_eraser (POINTER_PEN_INFO *pen_info) |
| 1621 |
{ |
| 1622 |
return (pen_info->penFlags & (PEN_FLAG_INVERTED | PEN_FLAG_ERASER)) != 0; |
| 1623 |
} |
| 1624 |
|
| 1625 |
static inline gboolean |
| 1626 |
winpointer_should_filter_message (MSG *msg, |
| 1627 |
POINTER_INPUT_TYPE type) |
| 1628 |
{ |
| 1629 |
switch (type) |
| 1630 |
{ |
| 1631 |
case PT_TOUCH: |
| 1632 |
return msg->message == WM_POINTERENTER || |
| 1633 |
msg->message == WM_POINTERLEAVE; |
| 1634 |
break; |
| 1635 |
} |
| 1636 |
|
| 1637 |
return FALSE; |
| 1638 |
} |
| 1639 |
|
| 1640 |
static GdkDeviceWinpointer* |
| 1641 |
winpointer_find_device_with_source (GdkDeviceManagerWin32 *device_manager, |
| 1642 |
HANDLE device_handle, |
| 1643 |
UINT32 cursor_id, |
| 1644 |
GdkInputSource input_source) |
| 1645 |
{ |
| 1646 |
GList *l; |
| 1647 |
|
| 1648 |
for (l = device_manager->winpointer_devices; l; l = l->next) |
| 1649 |
{ |
| 1650 |
GdkDeviceWinpointer *device = (GdkDeviceWinpointer*) l->data; |
| 1651 |
|
| 1652 |
if (device->device_handle == device_handle && |
| 1653 |
device->start_cursor_id <= cursor_id && |
| 1654 |
device->end_cursor_id >= cursor_id && |
| 1655 |
gdk_device_get_source (GDK_DEVICE (device)) == input_source) |
| 1656 |
return device; |
| 1657 |
} |
| 1658 |
|
| 1659 |
return NULL; |
| 1660 |
} |
| 1661 |
|
| 1662 |
static GdkEvent* |
| 1663 |
winpointer_allocate_event (MSG *msg, |
| 1664 |
POINTER_INFO *info) |
| 1665 |
{ |
| 1666 |
switch (info->pointerType) |
| 1667 |
{ |
| 1668 |
case PT_PEN: |
| 1669 |
switch (msg->message) |
| 1670 |
{ |
| 1671 |
case WM_POINTERENTER: |
| 1672 |
g_return_val_if_fail (IS_POINTER_NEW_WPARAM (msg->wParam), NULL); |
| 1673 |
return gdk_event_new (GDK_PROXIMITY_IN); |
| 1674 |
break; |
| 1675 |
case WM_POINTERLEAVE: |
| 1676 |
g_return_val_if_fail (!IS_POINTER_INRANGE_WPARAM (msg->wParam), NULL); |
| 1677 |
return gdk_event_new (GDK_PROXIMITY_OUT); |
| 1678 |
break; |
| 1679 |
case WM_POINTERDOWN: |
| 1680 |
return gdk_event_new (GDK_BUTTON_PRESS); |
| 1681 |
break; |
| 1682 |
case WM_POINTERUP: |
| 1683 |
return gdk_event_new (GDK_BUTTON_RELEASE); |
| 1684 |
break; |
| 1685 |
case WM_POINTERUPDATE: |
| 1686 |
return gdk_event_new (GDK_MOTION_NOTIFY); |
| 1687 |
break; |
| 1688 |
} |
| 1689 |
break; |
| 1690 |
case PT_TOUCH: |
| 1691 |
if (IS_POINTER_CANCELED_WPARAM (msg->wParam) || |
| 1692 |
!HAS_POINTER_CONFIDENCE_WPARAM (msg->wParam)) |
| 1693 |
{ |
| 1694 |
winpointer_ignore_interaction (GET_POINTERID_WPARAM (msg->wParam)); |
| 1695 |
|
| 1696 |
if (((info->pointerFlags & POINTER_FLAG_INCONTACT) && |
| 1697 |
(info->pointerFlags & POINTER_FLAG_UPDATE)) |
| 1698 |
|| (info->pointerFlags & POINTER_FLAG_UP)) |
| 1699 |
return gdk_event_new (GDK_TOUCH_CANCEL); |
| 1700 |
else |
| 1701 |
return NULL; |
| 1702 |
} |
| 1703 |
|
| 1704 |
g_return_val_if_fail (msg->message != WM_POINTERENTER && |
| 1705 |
msg->message != WM_POINTERLEAVE, NULL); |
| 1706 |
|
| 1707 |
switch (msg->message) |
| 1708 |
{ |
| 1709 |
case WM_POINTERDOWN: |
| 1710 |
return gdk_event_new (GDK_TOUCH_BEGIN); |
| 1711 |
break; |
| 1712 |
case WM_POINTERUP: |
| 1713 |
return gdk_event_new (GDK_TOUCH_END); |
| 1714 |
break; |
| 1715 |
case WM_POINTERUPDATE: |
| 1716 |
if (IS_POINTER_INCONTACT_WPARAM (msg->wParam)) |
| 1717 |
return gdk_event_new (GDK_TOUCH_UPDATE); |
| 1718 |
else if (IS_POINTER_PRIMARY_WPARAM (msg->wParam)) |
| 1719 |
return gdk_event_new (GDK_MOTION_NOTIFY); |
| 1720 |
else |
| 1721 |
return NULL; |
| 1722 |
break; |
| 1723 |
} |
| 1724 |
break; |
| 1725 |
} |
| 1726 |
|
| 1727 |
g_warn_if_reached (); |
| 1728 |
return NULL; |
| 1729 |
} |
| 1730 |
|
| 1731 |
static void |
| 1732 |
winpointer_make_event (GdkDisplay *display, |
| 1733 |
GdkDeviceManagerWin32 *device_manager, |
| 1734 |
GdkDeviceWinpointer *device, |
| 1735 |
GdkWindow *window, |
| 1736 |
MSG *msg, |
| 1737 |
POINTER_INFO *info) |
| 1738 |
{ |
| 1739 |
guint32 time = 0; |
| 1740 |
double x_root = 0.0; |
| 1741 |
double y_root = 0.0; |
| 1742 |
double x = 0.0; |
| 1743 |
double y = 0.0; |
| 1744 |
unsigned int state = 0; |
| 1745 |
double *axes = NULL; |
| 1746 |
unsigned int button = 0; |
| 1747 |
GdkEventSequence *sequence = NULL; |
| 1748 |
gboolean emulating_pointer = FALSE; |
| 1749 |
POINT client_area_coordinates; |
| 1750 |
GdkWindowImplWin32 *impl = NULL; |
| 1751 |
GdkEvent *evt = NULL; |
| 1752 |
|
| 1753 |
evt = winpointer_allocate_event (msg, info); |
| 1754 |
if (!evt) |
| 1755 |
return; |
| 1756 |
|
| 1757 |
time = winpointer_get_time (msg, info); |
| 1758 |
|
| 1759 |
x_root = device->origin_x + info->ptHimetricLocation.x * device->scale_x; |
| 1760 |
y_root = device->origin_y + info->ptHimetricLocation.y * device->scale_y; |
| 1761 |
|
| 1762 |
client_area_coordinates.x = 0; |
| 1763 |
client_area_coordinates.y = 0; |
| 1764 |
ClientToScreen (GDK_WINDOW_HWND (window), &client_area_coordinates); |
| 1765 |
x = x_root - client_area_coordinates.x; |
| 1766 |
y = y_root - client_area_coordinates.y; |
| 1767 |
|
| 1768 |
/* bring potential win32 negative screen coordinates to |
| 1769 |
the non-negative screen coordinates that GDK expects. */ |
| 1770 |
x_root += _gdk_offset_x; |
| 1771 |
y_root += _gdk_offset_y; |
| 1772 |
|
| 1773 |
/* handle DPI scaling */ |
| 1774 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 1775 |
x_root /= impl->window_scale; |
| 1776 |
y_root /= impl->window_scale; |
| 1777 |
x /= impl->window_scale; |
| 1778 |
y /= impl->window_scale; |
| 1779 |
|
| 1780 |
/* info->dwKeyStates is not reliable. We shall use |
| 1781 |
* GetKeyState here even for Ctrl and Shift. */ |
| 1782 |
state = 0; |
| 1783 |
if (GetKeyState (VK_CONTROL) < 0) |
| 1784 |
state |= GDK_CONTROL_MASK; |
| 1785 |
if (GetKeyState (VK_SHIFT) < 0) |
| 1786 |
state |= GDK_SHIFT_MASK; |
| 1787 |
if (GetKeyState (VK_MENU) < 0) |
| 1788 |
state |= GDK_MOD1_MASK; |
| 1789 |
if (GetKeyState (VK_CAPITAL) & 0x1) |
| 1790 |
state |= GDK_LOCK_MASK; |
| 1791 |
|
| 1792 |
device->last_button_mask = 0; |
| 1793 |
if (((info->pointerFlags & POINTER_FLAG_FIRSTBUTTON) && |
| 1794 |
(info->ButtonChangeType != POINTER_CHANGE_FIRSTBUTTON_DOWN)) |
| 1795 |
|| info->ButtonChangeType == POINTER_CHANGE_FIRSTBUTTON_UP) |
| 1796 |
device->last_button_mask |= GDK_BUTTON1_MASK; |
| 1797 |
if (((info->pointerFlags & POINTER_FLAG_SECONDBUTTON) && |
| 1798 |
(info->ButtonChangeType != POINTER_CHANGE_SECONDBUTTON_DOWN)) |
| 1799 |
|| info->ButtonChangeType == POINTER_CHANGE_SECONDBUTTON_UP) |
| 1800 |
device->last_button_mask |= GDK_BUTTON3_MASK; |
| 1801 |
state |= device->last_button_mask; |
| 1802 |
|
| 1803 |
switch (info->pointerType) |
| 1804 |
{ |
| 1805 |
case PT_PEN: |
| 1806 |
{ |
| 1807 |
POINTER_PEN_INFO *pen_info = (POINTER_PEN_INFO*) info; |
| 1808 |
|
| 1809 |
axes = g_new (double, device->num_axes); |
| 1810 |
axes[0] = (pen_info->penMask & PEN_MASK_PRESSURE) ? pen_info->pressure / 1024.0 : |
| 1811 |
(pen_info->pointerInfo.pointerFlags & POINTER_FLAG_INCONTACT) ? 1.0 : 0.0; |
| 1812 |
axes[1] = (pen_info->penMask & PEN_MASK_TILT_X) ? pen_info->tiltX / 90.0 : 0.0; |
| 1813 |
axes[2] = (pen_info->penMask & PEN_MASK_TILT_Y) ? pen_info->tiltY / 90.0 : 0.0; |
| 1814 |
axes[3] = (pen_info->penMask & PEN_MASK_ROTATION) ? pen_info->rotation / 360.0 : 0.0; |
| 1815 |
} |
| 1816 |
break; |
| 1817 |
case PT_TOUCH: |
| 1818 |
{ |
| 1819 |
POINTER_TOUCH_INFO *touch_info = (POINTER_TOUCH_INFO*) info; |
| 1820 |
|
| 1821 |
axes = g_new (double, device->num_axes); |
| 1822 |
axes[0] = (touch_info->touchMask & TOUCH_MASK_PRESSURE) ? touch_info->pressure / 1024.0 : |
| 1823 |
(touch_info->pointerInfo.pointerFlags & POINTER_FLAG_INCONTACT) ? 1.0 : 0.0; |
| 1824 |
} |
| 1825 |
break; |
| 1826 |
} |
| 1827 |
|
| 1828 |
if (axes) |
| 1829 |
{ |
| 1830 |
memcpy (device->last_axis_data, axes, sizeof (double) * device->num_axes); |
| 1831 |
} |
| 1832 |
|
| 1833 |
sequence = (GdkEventSequence*) GUINT_TO_POINTER (info->pointerId); |
| 1834 |
emulating_pointer = (info->pointerFlags & POINTER_FLAG_PRIMARY) != 0; |
| 1835 |
button = (info->pointerFlags & POINTER_FLAG_FIRSTBUTTON) || |
| 1836 |
(info->ButtonChangeType == POINTER_CHANGE_FIRSTBUTTON_UP) ? 1 : 3; |
| 1837 |
|
| 1838 |
switch (evt->any.type) |
| 1839 |
{ |
| 1840 |
case GDK_PROXIMITY_IN: |
| 1841 |
case GDK_PROXIMITY_OUT: |
| 1842 |
evt->proximity.time = time; |
| 1843 |
break; |
| 1844 |
case GDK_BUTTON_PRESS: |
| 1845 |
case GDK_BUTTON_RELEASE: |
| 1846 |
evt->button.time = time; |
| 1847 |
evt->button.x_root = x_root; |
| 1848 |
evt->button.y_root = y_root; |
| 1849 |
evt->button.x = x; |
| 1850 |
evt->button.y = y; |
| 1851 |
evt->button.state = state; |
| 1852 |
evt->button.axes = axes; |
| 1853 |
evt->button.button = button; |
| 1854 |
break; |
| 1855 |
case GDK_MOTION_NOTIFY: |
| 1856 |
evt->motion.time = time; |
| 1857 |
evt->motion.x_root = x_root; |
| 1858 |
evt->motion.y_root = y_root; |
| 1859 |
evt->motion.x = x; |
| 1860 |
evt->motion.y = y; |
| 1861 |
evt->motion.state = state; |
| 1862 |
evt->motion.axes = axes; |
| 1863 |
break; |
| 1864 |
case GDK_TOUCH_BEGIN: |
| 1865 |
case GDK_TOUCH_UPDATE: |
| 1866 |
case GDK_TOUCH_CANCEL: |
| 1867 |
case GDK_TOUCH_END: |
| 1868 |
evt->touch.time = time; |
| 1869 |
evt->touch.x_root = x_root; |
| 1870 |
evt->touch.y_root = y_root; |
| 1871 |
evt->touch.x = x; |
| 1872 |
evt->touch.y = y; |
| 1873 |
evt->touch.state = state; |
| 1874 |
evt->touch.axes = axes; |
| 1875 |
evt->touch.sequence = sequence; |
| 1876 |
evt->touch.emulating_pointer = emulating_pointer; |
| 1877 |
gdk_event_set_pointer_emulated (evt, emulating_pointer); |
| 1878 |
break; |
| 1879 |
} |
| 1880 |
|
| 1881 |
evt->any.send_event = FALSE; |
| 1882 |
evt->any.window = window; |
| 1883 |
gdk_event_set_device (evt, device_manager->core_pointer); |
| 1884 |
gdk_event_set_source_device (evt, GDK_DEVICE (device)); |
| 1885 |
gdk_event_set_device_tool (evt, ((GdkDevice*)device)->last_tool); |
| 1886 |
gdk_event_set_seat (evt, gdk_device_get_seat (device_manager->core_pointer)); |
| 1887 |
gdk_event_set_screen (evt, gdk_display_get_default_screen (display)); |
| 1888 |
|
| 1889 |
_gdk_device_virtual_set_active (device_manager->core_pointer, GDK_DEVICE (device)); |
| 1890 |
|
| 1891 |
_gdk_win32_append_event (evt); |
| 1892 |
} |
| 1893 |
|
| 1894 |
void |
| 1895 |
gdk_winpointer_input_events (GdkDisplay *display, |
| 1896 |
GdkWindow *window, |
| 1897 |
crossing_cb_t crossing_cb, |
| 1898 |
MSG *msg) |
| 1899 |
{ |
| 1900 |
GdkDeviceManagerWin32 *device_manager = NULL; |
| 1901 |
UINT32 pointer_id = GET_POINTERID_WPARAM (msg->wParam); |
| 1902 |
POINTER_INPUT_TYPE type = PT_POINTER; |
| 1903 |
UINT32 cursor_id = 0; |
| 1904 |
|
| 1905 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 1906 |
device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display)); |
| 1907 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 1908 |
|
| 1909 |
if (!getPointerType (pointer_id, &type)) |
| 1910 |
{ |
| 1911 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerType"); |
| 1912 |
return; |
| 1913 |
} |
| 1914 |
|
| 1915 |
if (!getPointerCursorId (pointer_id, &cursor_id)) |
| 1916 |
{ |
| 1917 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerCursorId"); |
| 1918 |
return; |
| 1919 |
} |
| 1920 |
|
| 1921 |
if (winpointer_should_filter_message (msg, type)) |
| 1922 |
{ |
| 1923 |
return; |
| 1924 |
} |
| 1925 |
|
| 1926 |
if (winpointer_should_ignore_interaction (pointer_id)) |
| 1927 |
{ |
| 1928 |
return; |
| 1929 |
} |
| 1930 |
|
| 1931 |
switch (type) |
| 1932 |
{ |
| 1933 |
case PT_PEN: |
| 1934 |
{ |
| 1935 |
POINTER_PEN_INFO *infos = NULL; |
| 1936 |
UINT32 history_count = 0; |
| 1937 |
GdkDeviceWinpointer *device = NULL; |
| 1938 |
UINT32 h = 0; |
| 1939 |
|
| 1940 |
do |
| 1941 |
{ |
| 1942 |
infos = g_new0 (POINTER_PEN_INFO, history_count); |
| 1943 |
if (!getPointerPenInfoHistory (pointer_id, &history_count, infos)) |
| 1944 |
{ |
| 1945 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerPenInfoHistory"); |
| 1946 |
g_free (infos); |
| 1947 |
return; |
| 1948 |
} |
| 1949 |
} |
| 1950 |
while (!infos && history_count > 0); |
| 1951 |
|
| 1952 |
if (history_count == 0) |
| 1953 |
return; |
| 1954 |
|
| 1955 |
device = winpointer_find_device_with_source (device_manager, |
| 1956 |
infos->pointerInfo.sourceDevice, |
| 1957 |
cursor_id, |
| 1958 |
winpointer_is_eraser (infos) ? |
| 1959 |
GDK_SOURCE_ERASER : GDK_SOURCE_PEN); |
| 1960 |
if (!device) |
| 1961 |
{ |
| 1962 |
g_free (infos); |
| 1963 |
return; |
| 1964 |
} |
| 1965 |
|
| 1966 |
h = history_count - 1; |
| 1967 |
|
| 1968 |
if (crossing_cb) |
| 1969 |
{ |
| 1970 |
POINT screen_pt = infos[h].pointerInfo.ptPixelLocation; |
| 1971 |
guint32 event_time = winpointer_get_time (msg, &infos[h].pointerInfo); |
| 1972 |
|
| 1973 |
crossing_cb(display, GDK_DEVICE (device), window, &screen_pt, event_time); |
| 1974 |
} |
| 1975 |
|
| 1976 |
do |
| 1977 |
winpointer_make_event (display, |
| 1978 |
device_manager, |
| 1979 |
device, |
| 1980 |
window, |
| 1981 |
msg, |
| 1982 |
(POINTER_INFO*) &infos[h]); |
| 1983 |
while (h-- > 0); |
| 1984 |
|
| 1985 |
g_free (infos); |
| 1986 |
} |
| 1987 |
break; |
| 1988 |
case PT_TOUCH: |
| 1989 |
{ |
| 1990 |
POINTER_TOUCH_INFO *infos = NULL; |
| 1991 |
UINT32 history_count = 0; |
| 1992 |
GdkDeviceWinpointer *device = NULL; |
| 1993 |
UINT32 h = 0; |
| 1994 |
|
| 1995 |
do |
| 1996 |
{ |
| 1997 |
infos = g_new0 (POINTER_TOUCH_INFO, history_count); |
| 1998 |
if (!getPointerTouchInfoHistory (pointer_id, &history_count, infos)) |
| 1999 |
{ |
| 2000 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerTouchInfoHistory"); |
| 2001 |
g_free (infos); |
| 2002 |
return; |
| 2003 |
} |
| 2004 |
} |
| 2005 |
while (!infos && history_count > 0); |
| 2006 |
|
| 2007 |
if (history_count == 0) |
| 2008 |
return; |
| 2009 |
|
| 2010 |
device = winpointer_find_device_with_source (device_manager, |
| 2011 |
infos->pointerInfo.sourceDevice, |
| 2012 |
cursor_id, |
| 2013 |
GDK_SOURCE_TOUCHSCREEN); |
| 2014 |
if (!device) |
| 2015 |
{ |
| 2016 |
g_free (infos); |
| 2017 |
return; |
| 2018 |
} |
| 2019 |
|
| 2020 |
h = history_count - 1; |
| 2021 |
|
| 2022 |
if (crossing_cb) |
| 2023 |
{ |
| 2024 |
POINT screen_pt = infos[h].pointerInfo.ptPixelLocation; |
| 2025 |
guint32 event_time = winpointer_get_time (msg, &infos[h].pointerInfo); |
| 2026 |
|
| 2027 |
crossing_cb(display, GDK_DEVICE (device), window, &screen_pt, event_time); |
| 2028 |
} |
| 2029 |
|
| 2030 |
do |
| 2031 |
winpointer_make_event (display, |
| 2032 |
device_manager, |
| 2033 |
device, |
| 2034 |
window, |
| 2035 |
msg, |
| 2036 |
(POINTER_INFO*) &infos[h]); |
| 2037 |
while (h-- > 0); |
| 2038 |
|
| 2039 |
g_free (infos); |
| 2040 |
} |
| 2041 |
break; |
| 2042 |
} |
| 2043 |
} |
| 2044 |
|
| 2045 |
gboolean |
| 2046 |
gdk_winpointer_get_message_info (GdkDisplay *display, |
| 2047 |
MSG *msg, |
| 2048 |
GdkDevice **device, |
| 2049 |
guint32 *time_) |
| 2050 |
{ |
| 2051 |
GdkDeviceManagerWin32 *device_manager = NULL; |
| 2052 |
UINT32 pointer_id = GET_POINTERID_WPARAM (msg->wParam); |
| 2053 |
POINTER_INPUT_TYPE type = PT_POINTER; |
| 2054 |
UINT32 cursor_id = 0; |
| 2055 |
|
| 2056 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 2057 |
device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display)); |
| 2058 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 2059 |
|
| 2060 |
if (!getPointerType (pointer_id, &type)) |
| 2061 |
{ |
| 2062 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerType"); |
| 2063 |
return FALSE; |
| 2064 |
} |
| 2065 |
|
| 2066 |
if (!getPointerCursorId (pointer_id, &cursor_id)) |
| 2067 |
{ |
| 2068 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerCursorId"); |
| 2069 |
return FALSE; |
| 2070 |
} |
| 2071 |
|
| 2072 |
switch (type) |
| 2073 |
{ |
| 2074 |
case PT_PEN: |
| 2075 |
{ |
| 2076 |
POINTER_PEN_INFO pen_info; |
| 2077 |
|
| 2078 |
if (!getPointerPenInfo (pointer_id, &pen_info)) |
| 2079 |
{ |
| 2080 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerPenInfo"); |
| 2081 |
return FALSE; |
| 2082 |
} |
| 2083 |
|
| 2084 |
*device = GDK_DEVICE (winpointer_find_device_with_source (device_manager, |
| 2085 |
pen_info.pointerInfo.sourceDevice, |
| 2086 |
cursor_id, |
| 2087 |
winpointer_is_eraser (&pen_info) ? |
| 2088 |
GDK_SOURCE_ERASER : GDK_SOURCE_PEN)); |
| 2089 |
|
| 2090 |
*time_ = winpointer_get_time (msg, &pen_info.pointerInfo); |
| 2091 |
} |
| 2092 |
break; |
| 2093 |
case PT_TOUCH: |
| 2094 |
{ |
| 2095 |
POINTER_TOUCH_INFO touch_info; |
| 2096 |
|
| 2097 |
if (!getPointerTouchInfo (pointer_id, &touch_info)) |
| 2098 |
{ |
| 2099 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerTouchInfo"); |
| 2100 |
return FALSE; |
| 2101 |
} |
| 2102 |
|
| 2103 |
*device = GDK_DEVICE (winpointer_find_device_with_source (device_manager, |
| 2104 |
touch_info.pointerInfo.sourceDevice, |
| 2105 |
cursor_id, |
| 2106 |
GDK_SOURCE_TOUCHSCREEN)); |
| 2107 |
|
| 2108 |
*time_ = winpointer_get_time (msg, &touch_info.pointerInfo); |
| 2109 |
} |
| 2110 |
break; |
| 2111 |
default: |
| 2112 |
g_warn_if_reached (); |
| 2113 |
return FALSE; |
| 2114 |
break; |
| 2115 |
} |
| 2116 |
|
| 2117 |
return *device ? TRUE : FALSE; |
| 2118 |
} |
| 2119 |
|
| 2120 |
gboolean |
| 2121 |
gdk_winpointer_should_forward_message (MSG *msg) |
| 2122 |
{ |
| 2123 |
UINT32 pointer_id = GET_POINTERID_WPARAM (msg->wParam); |
| 2124 |
POINTER_INPUT_TYPE type = PT_POINTER; |
| 2125 |
|
| 2126 |
if (!getPointerType (pointer_id, &type)) |
| 2127 |
{ |
| 2128 |
WIN32_API_FAILED_LOG_ONCE ("GetPointerType"); |
| 2129 |
return TRUE; |
| 2130 |
} |
| 2131 |
|
| 2132 |
return !(type == PT_PEN || type == PT_TOUCH); |
| 2133 |
} |
| 2134 |
|
| 2135 |
void |
| 2136 |
gdk_winpointer_interaction_ended (MSG *msg) |
| 2137 |
{ |
| 2138 |
winpointer_remove_ignored_interaction (GET_POINTERID_WPARAM (msg->wParam)); |
| 2139 |
} |
| 2140 |
|
| 2141 |
void |
| 2142 |
_gdk_wintab_set_tablet_active (void) |
| 2143 |
{ |
| 2144 |
GList *tmp_list; |
| 2145 |
HCTX *hctx; |
| 2146 |
|
| 2147 |
/* Bring the contexts to the top of the overlap order when one of the |
| 2148 |
* application's windows is activated */ |
| 2149 |
|
| 2150 |
if (!wintab_contexts) |
| 2151 |
return; /* No tablet devices found, or Wintab not initialized yet */ |
| 2152 |
|
| 2153 |
GDK_NOTE (INPUT, g_print ("_gdk_wintab_set_tablet_active: " |
| 2154 |
"Bringing Wintab contexts to the top of the overlap order\n")); |
| 2155 |
|
| 2156 |
tmp_list = wintab_contexts; |
| 2157 |
|
| 2158 |
while (tmp_list) |
| 2159 |
{ |
| 2160 |
hctx = (HCTX *) (tmp_list->data); |
| 2161 |
(*p_WTOverlap) (*hctx, TRUE); |
| 2162 |
tmp_list = tmp_list->next; |
| 2163 |
} |
| 2164 |
} |
| 2165 |
|
| 2166 |
static void |
| 2167 |
decode_tilt (gint *axis_data, |
| 2168 |
AXIS *axes, |
| 2169 |
PACKET *packet) |
| 2170 |
{ |
| 2171 |
double az, el; |
| 2172 |
|
| 2173 |
g_return_if_fail (axis_data != NULL); |
| 2174 |
|
| 2175 |
/* The wintab driver for the Wacom ArtPad II reports |
| 2176 |
* PK_ORIENTATION in CSR_PKTDATA, but the tablet doesn't |
| 2177 |
* actually sense tilt. Catch this by noticing that the |
| 2178 |
* orientation axis's azimuth resolution is zero. |
| 2179 |
* |
| 2180 |
* The same is true of the Huion H610PRO, but in this case |
| 2181 |
* it's the altitude resolution that's zero. GdkEvents with |
| 2182 |
* sensible tilts will need both, so only add the GDK tilt axes |
| 2183 |
* if both wintab axes are going to be well-behaved in use. |
| 2184 |
*/ |
| 2185 |
if (axes == NULL) |
| 2186 |
return; |
| 2187 |
|
| 2188 |
if ((axes[0].axResolution == 0) || |
| 2189 |
(axes[1].axResolution == 0)) |
| 2190 |
{ |
| 2191 |
axis_data[0] = 0; |
| 2192 |
axis_data[1] = 0; |
| 2193 |
} |
| 2194 |
else |
| 2195 |
{ |
| 2196 |
/* |
| 2197 |
* Tested with a Wacom Intuos 5 touch M (PTH-650) + Wacom drivers 6.3.18-5. |
| 2198 |
* Wintab's reference angle leads gdk's by 90 degrees. |
| 2199 |
*/ |
| 2200 |
az = TWOPI * packet->pkOrientation.orAzimuth / |
| 2201 |
(axes[0].axResolution / 65536.); |
| 2202 |
az -= G_PI / 2; |
| 2203 |
el = TWOPI * packet->pkOrientation.orAltitude / |
| 2204 |
(axes[1].axResolution / 65536.); |
| 2205 |
|
| 2206 |
/* X tilt */ |
| 2207 |
axis_data[0] = cos (az) * cos (el) * 1000; |
| 2208 |
/* Y tilt */ |
| 2209 |
axis_data[1] = sin (az) * cos (el) * 1000; |
| 2210 |
} |
| 2211 |
|
| 2212 |
/* Twist (Rotation) if present */ |
| 2213 |
if (axes[2].axResolution != 0) |
| 2214 |
axis_data[2] = packet->pkOrientation.orTwist; |
| 2215 |
} |
| 2216 |
|
| 2217 |
/* |
| 2218 |
* Get the currently active keyboard modifiers (ignoring the mouse buttons) |
| 2219 |
* We could use gdk_window_get_pointer but that function does a lot of other |
| 2220 |
* expensive things besides getting the modifiers. This code is somewhat based |
| 2221 |
* on build_pointer_event_state from gdkevents-win32.c |
| 2222 |
*/ |
| 2223 |
static guint |
| 2224 |
get_modifier_key_state (void) |
| 2225 |
{ |
| 2226 |
guint state; |
| 2227 |
|
| 2228 |
state = 0; |
| 2229 |
/* High-order bit is up/down, low order bit is toggled/untoggled */ |
| 2230 |
if (GetKeyState (VK_CONTROL) < 0) |
| 2231 |
state |= GDK_CONTROL_MASK; |
| 2232 |
if (GetKeyState (VK_SHIFT) < 0) |
| 2233 |
state |= GDK_SHIFT_MASK; |
| 2234 |
if (GetKeyState (VK_MENU) < 0) |
| 2235 |
state |= GDK_MOD1_MASK; |
| 2236 |
if (GetKeyState (VK_CAPITAL) & 0x1) |
| 2237 |
state |= GDK_LOCK_MASK; |
| 2238 |
|
| 2239 |
return state; |
| 2240 |
} |
| 2241 |
|
| 2242 |
int |
| 2243 |
_gdk_find_wintab_device_index (HCTX hctx) |
| 2244 |
{ |
| 2245 |
GList *tmp_list; |
| 2246 |
int devix; |
| 2247 |
|
| 2248 |
/* Find the index of the Wintab driver's input device (probably zero) */ |
| 2249 |
if (!wintab_contexts) |
| 2250 |
return -1; /* No tablet devices found or Wintab not initialized yet */ |
| 2251 |
|
| 2252 |
tmp_list = wintab_contexts; |
| 2253 |
devix = 0; |
| 2254 |
while (tmp_list) |
| 2255 |
{ |
| 2256 |
if ((*(HCTX *) (tmp_list->data)) == hctx) |
| 2257 |
return devix; |
| 2258 |
else |
| 2259 |
{ |
| 2260 |
devix++; |
| 2261 |
tmp_list = tmp_list->next; |
| 2262 |
} |
| 2263 |
} |
| 2264 |
return -1; |
| 2265 |
} |
| 2266 |
|
| 2267 |
static GdkDeviceWintab * |
| 2268 |
gdk_device_manager_find_wintab_device (GdkDeviceManagerWin32 *device_manager, |
| 2269 |
HCTX hctx, |
| 2270 |
UINT cursor) |
| 2271 |
{ |
| 2272 |
GdkDeviceWintab *device; |
| 2273 |
GList *tmp_list; |
| 2274 |
|
| 2275 |
for (tmp_list = device_manager->wintab_devices; tmp_list != NULL; tmp_list = tmp_list->next) |
| 2276 |
{ |
| 2277 |
device = tmp_list->data; |
| 2278 |
|
| 2279 |
if (device->hctx == hctx && |
| 2280 |
device->cursor == cursor) |
| 2281 |
return device; |
| 2282 |
} |
| 2283 |
|
| 2284 |
return NULL; |
| 2285 |
} |
| 2286 |
|
| 2287 |
gboolean |
| 2288 |
gdk_wintab_input_events (GdkDisplay *display, |
| 2289 |
GdkEvent *event, |
| 2290 |
MSG *msg, |
| 2291 |
GdkWindow *window) |
| 2292 |
{ |
| 2293 |
GdkDeviceManagerWin32 *device_manager; |
| 2294 |
GdkDeviceWintab *source_device = NULL; |
| 2295 |
GdkDeviceGrabInfo *last_grab; |
| 2296 |
GdkEventMask masktest; |
| 2297 |
guint key_state; |
| 2298 |
POINT pt; |
| 2299 |
GdkWindowImplWin32 *impl; |
| 2300 |
|
| 2301 |
PACKET packet; |
| 2302 |
gint root_x, root_y; |
| 2303 |
gint num_axes; |
| 2304 |
gint x, y; |
| 2305 |
guint translated_buttons, button_diff, button_mask; |
| 2306 |
/* Translation from tablet button state to GDK button state for |
| 2307 |
* buttons 1-3 - swap button 2 and 3. |
| 2308 |
*/ |
| 2309 |
static guint button_map[8] = {0, 1, 4, 5, 2, 3, 6, 7}; |
| 2310 |
|
| 2311 |
if (event->any.window != wintab_window) |
| 2312 |
{ |
| 2313 |
g_warning ("gdk_wintab_input_events: not wintab_window?"); |
| 2314 |
return FALSE; |
| 2315 |
} |
| 2316 |
|
| 2317 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 2318 |
device_manager = GDK_DEVICE_MANAGER_WIN32 (gdk_display_get_device_manager (display)); |
| 2319 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 2320 |
window = gdk_device_get_window_at_position (device_manager->core_pointer, &x, &y); |
| 2321 |
if (window == NULL) |
| 2322 |
window = gdk_get_default_root_window (); |
| 2323 |
|
| 2324 |
g_object_ref (window); |
| 2325 |
|
| 2326 |
GDK_NOTE (EVENTS_OR_INPUT, |
| 2327 |
g_print ("gdk_wintab_input_events: window=%p %+d%+d\n", |
| 2328 |
GDK_WINDOW_HWND (window), x, y)); |
| 2329 |
|
| 2330 |
if (msg->message == WT_PACKET || msg->message == WT_CSRCHANGE) |
| 2331 |
{ |
| 2332 |
if (!(*p_WTPacket) ((HCTX) msg->lParam, msg->wParam, &packet)) |
| 2333 |
return FALSE; |
| 2334 |
} |
| 2335 |
|
| 2336 |
switch (msg->message) |
| 2337 |
{ |
| 2338 |
case WT_PACKET: |
| 2339 |
source_device = gdk_device_manager_find_wintab_device (device_manager, |
| 2340 |
(HCTX) msg->lParam, |
| 2341 |
packet.pkCursor); |
| 2342 |
|
| 2343 |
/* Check this first, as we get WT_PROXIMITY for disabled devices too */ |
| 2344 |
if (device_manager->dev_entered_proximity > 0) |
| 2345 |
{ |
| 2346 |
/* This is the same code as in WT_CSRCHANGE. Some drivers send |
| 2347 |
* WT_CSRCHANGE after each WT_PROXIMITY with LOWORD(lParam) != 0, |
| 2348 |
* this code is for those that don't. |
| 2349 |
*/ |
| 2350 |
device_manager->dev_entered_proximity -= 1; |
| 2351 |
|
| 2352 |
if (source_device != NULL && |
| 2353 |
source_device->sends_core && |
| 2354 |
gdk_device_get_mode (GDK_DEVICE (source_device)) != GDK_MODE_DISABLED) |
| 2355 |
{ |
| 2356 |
_gdk_device_virtual_set_active (device_manager->core_pointer, |
| 2357 |
GDK_DEVICE (source_device)); |
| 2358 |
_gdk_input_ignore_core += 1; |
| 2359 |
} |
| 2360 |
} |
| 2361 |
else if (source_device != NULL && |
| 2362 |
source_device->sends_core && |
| 2363 |
gdk_device_get_mode (GDK_DEVICE (source_device)) != GDK_MODE_DISABLED && |
| 2364 |
_gdk_input_ignore_core == 0) |
| 2365 |
{ |
| 2366 |
/* A fallback for cases when two devices (disabled and enabled) |
| 2367 |
* were in proximity simultaneously. |
| 2368 |
* In this case the removal of a disabled device would also |
| 2369 |
* make the system pointer active, as we don't know which |
| 2370 |
* device was removed and assume it was the enabled one. |
| 2371 |
* If we are still getting packets for the enabled device, |
| 2372 |
* it means that the device that was removed was the disabled |
| 2373 |
* device, so we must make the enabled device active again and |
| 2374 |
* start ignoring the core pointer events. In practice this means that |
| 2375 |
* removing a disabled device while an enabled device is still |
| 2376 |
* in proximity might briefly make the core pointer active/visible. |
| 2377 |
*/ |
| 2378 |
_gdk_device_virtual_set_active (device_manager->core_pointer, |
| 2379 |
GDK_DEVICE (source_device)); |
| 2380 |
_gdk_input_ignore_core += 1; |
| 2381 |
} |
| 2382 |
|
| 2383 |
if (source_device == NULL || |
| 2384 |
gdk_device_get_mode (GDK_DEVICE (source_device)) == GDK_MODE_DISABLED) |
| 2385 |
return FALSE; |
| 2386 |
|
| 2387 |
/* Don't produce any button or motion events while a window is being |
| 2388 |
* moved or resized, see bug #151090. |
| 2389 |
*/ |
| 2390 |
if (_modal_operation_in_progress & GDK_WIN32_MODAL_OP_SIZEMOVE_MASK) |
| 2391 |
{ |
| 2392 |
GDK_NOTE (EVENTS_OR_INPUT, g_print ("... ignored when moving/sizing\n")); |
| 2393 |
return FALSE; |
| 2394 |
} |
| 2395 |
|
| 2396 |
last_grab = _gdk_display_get_last_device_grab (display, GDK_DEVICE (source_device)); |
| 2397 |
|
| 2398 |
if (last_grab && last_grab->window) |
| 2399 |
{ |
| 2400 |
g_object_unref (window); |
| 2401 |
|
| 2402 |
window = g_object_ref (last_grab->window); |
| 2403 |
} |
| 2404 |
|
| 2405 |
if (window == gdk_get_default_root_window ()) |
| 2406 |
{ |
| 2407 |
GDK_NOTE (EVENTS_OR_INPUT, g_print ("... is root\n")); |
| 2408 |
return FALSE; |
| 2409 |
} |
| 2410 |
|
| 2411 |
num_axes = 0; |
| 2412 |
if (source_device->pktdata & PK_X) |
| 2413 |
source_device->last_axis_data[num_axes++] = packet.pkX; |
| 2414 |
if (source_device->pktdata & PK_Y) |
| 2415 |
source_device->last_axis_data[num_axes++] = packet.pkY; |
| 2416 |
if (source_device->pktdata & PK_NORMAL_PRESSURE) |
| 2417 |
source_device->last_axis_data[num_axes++] = packet.pkNormalPressure; |
| 2418 |
if (source_device->pktdata & PK_ORIENTATION) |
| 2419 |
{ |
| 2420 |
decode_tilt (source_device->last_axis_data + num_axes, |
| 2421 |
source_device->orientation_axes, &packet); |
| 2422 |
/* we could have 3 axes if twist is present */ |
| 2423 |
if (source_device->orientation_axes[2].axResolution == 0) |
| 2424 |
{ |
| 2425 |
num_axes += 2; |
| 2426 |
} |
| 2427 |
else |
| 2428 |
{ |
| 2429 |
num_axes += 3; |
| 2430 |
} |
| 2431 |
} |
| 2432 |
if (source_device->pktdata & PK_TANGENT_PRESSURE) |
| 2433 |
source_device->last_axis_data[num_axes++] = packet.pkTangentPressure; |
| 2434 |
|
| 2435 |
translated_buttons = button_map[packet.pkButtons & 0x07] | (packet.pkButtons & ~0x07); |
| 2436 |
|
| 2437 |
if (translated_buttons != source_device->button_state) |
| 2438 |
{ |
| 2439 |
/* At least one button has changed state so produce a button event |
| 2440 |
* If more than one button has changed state (unlikely), |
| 2441 |
* just care about the first and act on the next the next time |
| 2442 |
* we get a packet |
| 2443 |
*/ |
| 2444 |
button_diff = translated_buttons ^ source_device->button_state; |
| 2445 |
|
| 2446 |
/* Gdk buttons are numbered 1.. */ |
| 2447 |
event->button.button = 1; |
| 2448 |
|
| 2449 |
for (button_mask = 1; button_mask != 0x80000000; |
| 2450 |
button_mask <<= 1, event->button.button++) |
| 2451 |
{ |
| 2452 |
if (button_diff & button_mask) |
| 2453 |
{ |
| 2454 |
/* Found a button that has changed state */ |
| 2455 |
break; |
| 2456 |
} |
| 2457 |
} |
| 2458 |
|
| 2459 |
if (!(translated_buttons & button_mask)) |
| 2460 |
{ |
| 2461 |
event->any.type = GDK_BUTTON_RELEASE; |
| 2462 |
masktest = GDK_BUTTON_RELEASE_MASK; |
| 2463 |
} |
| 2464 |
else |
| 2465 |
{ |
| 2466 |
event->any.type = GDK_BUTTON_PRESS; |
| 2467 |
masktest = GDK_BUTTON_PRESS_MASK; |
| 2468 |
} |
| 2469 |
source_device->button_state ^= button_mask; |
| 2470 |
} |
| 2471 |
else |
| 2472 |
{ |
| 2473 |
event->any.type = GDK_MOTION_NOTIFY; |
| 2474 |
masktest = GDK_POINTER_MOTION_MASK; |
| 2475 |
if (source_device->button_state & (1 << 0)) |
| 2476 |
masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON1_MOTION_MASK; |
| 2477 |
if (source_device->button_state & (1 << 1)) |
| 2478 |
masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON2_MOTION_MASK; |
| 2479 |
if (source_device->button_state & (1 << 2)) |
| 2480 |
masktest |= GDK_BUTTON_MOTION_MASK | GDK_BUTTON3_MOTION_MASK; |
| 2481 |
} |
| 2482 |
|
| 2483 |
/* Now we can check if the window wants the event, and |
| 2484 |
* propagate if necessary. |
| 2485 |
*/ |
| 2486 |
while ((gdk_window_get_device_events (window, GDK_DEVICE (source_device)) & masktest) == 0 && |
| 2487 |
(gdk_device_get_device_type (GDK_DEVICE (source_device)) == GDK_DEVICE_TYPE_SLAVE && |
| 2488 |
(gdk_window_get_events (window) & masktest) == 0)) |
| 2489 |
{ |
| 2490 |
GDK_NOTE (EVENTS_OR_INPUT, g_print ("... not selected\n")); |
| 2491 |
|
| 2492 |
if (window->parent == gdk_get_default_root_window () || window->parent == NULL) |
| 2493 |
return FALSE; |
| 2494 |
|
| 2495 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2496 |
pt.x = x * impl->window_scale; |
| 2497 |
pt.y = y * impl->window_scale; |
| 2498 |
ClientToScreen (GDK_WINDOW_HWND (window), &pt); |
| 2499 |
g_object_unref (window); |
| 2500 |
window = window->parent; |
| 2501 |
impl = GDK_WINDOW_IMPL_WIN32 (window->impl); |
| 2502 |
g_object_ref (window); |
| 2503 |
ScreenToClient (GDK_WINDOW_HWND (window), &pt); |
| 2504 |
x = pt.x / impl->window_scale; |
| 2505 |
y = pt.y / impl->window_scale; |
| 2506 |
GDK_NOTE (EVENTS_OR_INPUT, g_print ("... propagating to %p %+d%+d\n", |
| 2507 |
GDK_WINDOW_HWND (window), x, y)); |
| 2508 |
} |
| 2509 |
|
| 2510 |
event->any.window = window; |
| 2511 |
key_state = get_modifier_key_state (); |
| 2512 |
if (event->any.type == GDK_BUTTON_PRESS || |
| 2513 |
event->any.type == GDK_BUTTON_RELEASE) |
| 2514 |
{ |
| 2515 |
event->button.time = _gdk_win32_get_next_tick (msg->time); |
| 2516 |
if (source_device->sends_core) |
| 2517 |
gdk_event_set_device (event, device_manager->core_pointer); |
| 2518 |
else |
| 2519 |
gdk_event_set_device (event, GDK_DEVICE (source_device)); |
| 2520 |
gdk_event_set_source_device (event, GDK_DEVICE (source_device)); |
| 2521 |
gdk_event_set_seat (event, gdk_device_get_seat (device_manager->core_pointer)); |
| 2522 |
|
| 2523 |
event->button.axes = g_new (gdouble, num_axes); |
| 2524 |
gdk_window_get_origin (window, &root_x, &root_y); |
| 2525 |
|
| 2526 |
_gdk_device_wintab_translate_axes (source_device, |
| 2527 |
window, |
| 2528 |
event->button.axes, |
| 2529 |
&event->button.x, |
| 2530 |
&event->button.y); |
| 2531 |
|
| 2532 |
event->button.x_root = event->button.x + root_x; |
| 2533 |
event->button.y_root = event->button.y + root_y; |
| 2534 |
|
| 2535 |
event->button.state = |
| 2536 |
key_state | ((source_device->button_state << 8) |
| 2537 |
& (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK |
| 2538 |
| GDK_BUTTON3_MASK | GDK_BUTTON4_MASK |
| 2539 |
| GDK_BUTTON5_MASK)); |
| 2540 |
|
| 2541 |
GDK_NOTE (EVENTS_OR_INPUT, |
| 2542 |
g_print ("WINTAB button %s:%d %g,%g\n", |
| 2543 |
(event->button.type == GDK_BUTTON_PRESS ? |
| 2544 |
"press" : "release"), |
| 2545 |
event->button.button, |
| 2546 |
event->button.x, event->button.y)); |
| 2547 |
} |
| 2548 |
else |
| 2549 |
{ |
| 2550 |
event->motion.time = _gdk_win32_get_next_tick (msg->time); |
| 2551 |
event->motion.is_hint = FALSE; |
| 2552 |
if (source_device->sends_core) |
| 2553 |
gdk_event_set_device (event, device_manager->core_pointer); |
| 2554 |
else |
| 2555 |
gdk_event_set_device (event, GDK_DEVICE (source_device)); |
| 2556 |
gdk_event_set_source_device (event, GDK_DEVICE (source_device)); |
| 2557 |
gdk_event_set_seat (event, gdk_device_get_seat (device_manager->core_pointer)); |
| 2558 |
|
| 2559 |
event->motion.axes = g_new (gdouble, num_axes); |
| 2560 |
gdk_window_get_origin (window, &root_x, &root_y); |
| 2561 |
|
| 2562 |
_gdk_device_wintab_translate_axes (source_device, |
| 2563 |
window, |
| 2564 |
event->motion.axes, |
| 2565 |
&event->motion.x, |
| 2566 |
&event->motion.y); |
| 2567 |
|
| 2568 |
event->motion.x_root = event->motion.x + root_x; |
| 2569 |
event->motion.y_root = event->motion.y + root_y; |
| 2570 |
|
| 2571 |
event->motion.state = |
| 2572 |
key_state | ((source_device->button_state << 8) |
| 2573 |
& (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK |
| 2574 |
| GDK_BUTTON3_MASK | GDK_BUTTON4_MASK |
| 2575 |
| GDK_BUTTON5_MASK)); |
| 2576 |
|
| 2577 |
GDK_NOTE (EVENTS_OR_INPUT, |
| 2578 |
g_print ("WINTAB motion: %g,%g\n", |
| 2579 |
event->motion.x, event->motion.y)); |
| 2580 |
} |
| 2581 |
return TRUE; |
| 2582 |
|
| 2583 |
case WT_CSRCHANGE: |
| 2584 |
if (device_manager->dev_entered_proximity > 0) |
| 2585 |
device_manager->dev_entered_proximity -= 1; |
| 2586 |
|
| 2587 |
if ((source_device = |
| 2588 |
gdk_device_manager_find_wintab_device (device_manager, |
| 2589 |
(HCTX) msg->lParam, |
| 2590 |
packet.pkCursor)) == NULL) |
| 2591 |
{ |
| 2592 |
/* Check for new cursors and try again */ |
| 2593 |
if (_wintab_recognize_new_cursors(device_manager, |
| 2594 |
(HCTX) msg->lParam) == 0) |
| 2595 |
return FALSE; |
| 2596 |
if ((source_device = |
| 2597 |
gdk_device_manager_find_wintab_device (device_manager, |
| 2598 |
(HCTX) msg->lParam, |
| 2599 |
packet.pkCursor)) == NULL) |
| 2600 |
return FALSE; |
| 2601 |
} |
| 2602 |
|
| 2603 |
if (source_device->sends_core && |
| 2604 |
gdk_device_get_mode (GDK_DEVICE (source_device)) != GDK_MODE_DISABLED) |
| 2605 |
{ |
| 2606 |
_gdk_device_virtual_set_active (device_manager->core_pointer, |
| 2607 |
GDK_DEVICE (source_device)); |
| 2608 |
_gdk_input_ignore_core += 1; |
| 2609 |
} |
| 2610 |
return FALSE; |
| 2611 |
|
| 2612 |
case WT_PROXIMITY: |
| 2613 |
if (LOWORD (msg->lParam) == 0) |
| 2614 |
{ |
| 2615 |
if (_gdk_input_ignore_core > 0) |
| 2616 |
{ |
| 2617 |
_gdk_input_ignore_core -= 1; |
| 2618 |
|
| 2619 |
if (_gdk_input_ignore_core == 0) |
| 2620 |
_gdk_device_virtual_set_active (device_manager->core_pointer, |
| 2621 |
device_manager->system_pointer); |
| 2622 |
} |
| 2623 |
} |
| 2624 |
else |
| 2625 |
{ |
| 2626 |
device_manager->dev_entered_proximity += 1; |
| 2627 |
} |
| 2628 |
|
| 2629 |
return FALSE; |
| 2630 |
} |
| 2631 |
|
| 2632 |
return FALSE; |
| 2633 |
} |