| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library; if not, write to the |
| 16 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 17 |
* Boston, MA 02111-1307, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
| 22 |
* file for a list of people on the GTK+ Team. See the ChangeLog |
| 23 |
* files for a list of changes. These files are distributed with |
| 24 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "config.h" |
| 28 |
#include <stdlib.h> |
| 29 |
|
| 30 |
#import <Cocoa/Cocoa.h> |
| 31 |
#include <Carbon/Carbon.h> |
| 32 |
|
| 33 |
#include "gdkprivate-quartz.h" |
| 34 |
#include "gdkscreen-quartz.h" |
| 35 |
#include "gdkinput.h" |
| 36 |
#include "gdkprivate.h" |
| 37 |
#include "gdkinputprivate.h" |
| 38 |
|
| 39 |
|
| 40 |
#define N_CORE_POINTER_AXES 2 |
| 41 |
#define N_INPUT_DEVICE_AXES 5 |
| 42 |
|
| 43 |
|
| 44 |
static GdkDeviceAxis gdk_input_core_axes[] = { |
| 45 |
{ GDK_AXIS_X, 0, 0 }, |
| 46 |
{ GDK_AXIS_Y, 0, 0 } |
| 47 |
}; |
| 48 |
|
| 49 |
static GdkDeviceAxis gdk_quartz_pen_axes[] = { |
| 50 |
{ GDK_AXIS_X, 0, 0 }, |
| 51 |
{ GDK_AXIS_Y, 0, 0 }, |
| 52 |
{ GDK_AXIS_PRESSURE, 0, 1 }, |
| 53 |
{ GDK_AXIS_XTILT, -1, 1 }, |
| 54 |
{ GDK_AXIS_YTILT, -1, 1 } |
| 55 |
}; |
| 56 |
|
| 57 |
static GdkDeviceAxis gdk_quartz_cursor_axes[] = { |
| 58 |
{ GDK_AXIS_X, 0, 0 }, |
| 59 |
{ GDK_AXIS_Y, 0, 0 }, |
| 60 |
{ GDK_AXIS_PRESSURE, 0, 1 }, |
| 61 |
{ GDK_AXIS_XTILT, -1, 1 }, |
| 62 |
{ GDK_AXIS_YTILT, -1, 1 } |
| 63 |
}; |
| 64 |
|
| 65 |
static GdkDeviceAxis gdk_quartz_eraser_axes[] = { |
| 66 |
{ GDK_AXIS_X, 0, 0 }, |
| 67 |
{ GDK_AXIS_Y, 0, 0 }, |
| 68 |
{ GDK_AXIS_PRESSURE, 0, 1 }, |
| 69 |
{ GDK_AXIS_XTILT, -1, 1 }, |
| 70 |
{ GDK_AXIS_YTILT, -1, 1 } |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
/* Global variables */ |
| 75 |
static GList *_gdk_input_windows = NULL; |
| 76 |
static GList *_gdk_input_devices = NULL; |
| 77 |
static GdkDevice *_gdk_core_pointer = NULL; |
| 78 |
static GdkDevice *_gdk_quartz_pen = NULL; |
| 79 |
static GdkDevice *_gdk_quartz_cursor = NULL; |
| 80 |
static GdkDevice *_gdk_quartz_eraser = NULL; |
| 81 |
static GdkDevice *active_device = NULL; |
| 82 |
|
| 83 |
static void |
| 84 |
gdk_device_finalize (GObject *object) |
| 85 |
{ |
| 86 |
g_error ("A GdkDevice object was finalized. This should not happen"); |
| 87 |
} |
| 88 |
|
| 89 |
static void |
| 90 |
gdk_device_class_init (GObjectClass *class) |
| 91 |
{ |
| 92 |
class->finalize = gdk_device_finalize; |
| 93 |
} |
| 94 |
|
| 95 |
GType |
| 96 |
gdk_device_get_type (void) |
| 97 |
{ |
| 98 |
static GType object_type = 0; |
| 99 |
|
| 100 |
if (!object_type) |
| 101 |
{ |
| 102 |
const GTypeInfo object_info = |
| 103 |
{ |
| 104 |
sizeof (GdkDeviceClass), |
| 105 |
(GBaseInitFunc) NULL, |
| 106 |
(GBaseFinalizeFunc) NULL, |
| 107 |
(GClassInitFunc) gdk_device_class_init, |
| 108 |
NULL, /* class_finalize */ |
| 109 |
NULL, /* class_data */ |
| 110 |
sizeof (GdkDevicePrivate), |
| 111 |
0, /* n_preallocs */ |
| 112 |
(GInstanceInitFunc) NULL, |
| 113 |
}; |
| 114 |
|
| 115 |
object_type = g_type_register_static (G_TYPE_OBJECT, |
| 116 |
"GdkDevice", |
| 117 |
&object_info, 0); |
| 118 |
} |
| 119 |
|
| 120 |
return object_type; |
| 121 |
} |
| 122 |
|
| 123 |
GList * |
| 124 |
gdk_devices_list (void) |
| 125 |
{ |
| 126 |
return _gdk_input_devices; |
| 127 |
} |
| 128 |
|
| 129 |
GList * |
| 130 |
gdk_display_list_devices (GdkDisplay *dpy) |
| 131 |
{ |
| 132 |
return _gdk_input_devices; |
| 133 |
} |
| 134 |
|
| 135 |
const gchar * |
| 136 |
gdk_device_get_name (GdkDevice *device) |
| 137 |
{ |
| 138 |
g_return_val_if_fail (GDK_IS_DEVICE (device), NULL); |
| 139 |
|
| 140 |
return device->name; |
| 141 |
} |
| 142 |
|
| 143 |
GdkInputSource |
| 144 |
gdk_device_get_source (GdkDevice *device) |
| 145 |
{ |
| 146 |
g_return_val_if_fail (GDK_IS_DEVICE (device), 0); |
| 147 |
|
| 148 |
return device->source; |
| 149 |
} |
| 150 |
|
| 151 |
GdkInputMode |
| 152 |
gdk_device_get_mode (GdkDevice *device) |
| 153 |
{ |
| 154 |
g_return_val_if_fail (GDK_IS_DEVICE (device), 0); |
| 155 |
|
| 156 |
return device->mode; |
| 157 |
} |
| 158 |
|
| 159 |
gboolean |
| 160 |
gdk_device_get_has_cursor (GdkDevice *device) |
| 161 |
{ |
| 162 |
g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE); |
| 163 |
|
| 164 |
return device->has_cursor; |
| 165 |
} |
| 166 |
|
| 167 |
void |
| 168 |
gdk_device_set_source (GdkDevice *device, |
| 169 |
GdkInputSource source) |
| 170 |
{ |
| 171 |
device->source = source; |
| 172 |
} |
| 173 |
|
| 174 |
void |
| 175 |
gdk_device_get_key (GdkDevice *device, |
| 176 |
guint index, |
| 177 |
guint *keyval, |
| 178 |
GdkModifierType *modifiers) |
| 179 |
{ |
| 180 |
g_return_if_fail (GDK_IS_DEVICE (device)); |
| 181 |
g_return_if_fail (index < device->num_keys); |
| 182 |
|
| 183 |
if (!device->keys[index].keyval && |
| 184 |
!device->keys[index].modifiers) |
| 185 |
return; |
| 186 |
|
| 187 |
if (keyval) |
| 188 |
*keyval = device->keys[index].keyval; |
| 189 |
|
| 190 |
if (modifiers) |
| 191 |
*modifiers = device->keys[index].modifiers; |
| 192 |
} |
| 193 |
|
| 194 |
void |
| 195 |
gdk_device_set_key (GdkDevice *device, |
| 196 |
guint index, |
| 197 |
guint keyval, |
| 198 |
GdkModifierType modifiers) |
| 199 |
{ |
| 200 |
g_return_if_fail (device != NULL); |
| 201 |
g_return_if_fail (index < device->num_keys); |
| 202 |
|
| 203 |
device->keys[index].keyval = keyval; |
| 204 |
device->keys[index].modifiers = modifiers; |
| 205 |
} |
| 206 |
|
| 207 |
GdkAxisUse |
| 208 |
gdk_device_get_axis_use (GdkDevice *device, |
| 209 |
guint index) |
| 210 |
{ |
| 211 |
g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_AXIS_IGNORE); |
| 212 |
g_return_val_if_fail (index < device->num_axes, GDK_AXIS_IGNORE); |
| 213 |
|
| 214 |
return device->axes[index].use; |
| 215 |
} |
| 216 |
|
| 217 |
gint |
| 218 |
gdk_device_get_n_keys (GdkDevice *device) |
| 219 |
{ |
| 220 |
g_return_val_if_fail (GDK_IS_DEVICE (device), 0); |
| 221 |
|
| 222 |
return device->num_keys; |
| 223 |
} |
| 224 |
|
| 225 |
gint |
| 226 |
gdk_device_get_n_axes (GdkDevice *device) |
| 227 |
{ |
| 228 |
g_return_val_if_fail (GDK_IS_DEVICE (device), 0); |
| 229 |
|
| 230 |
return device->num_axes; |
| 231 |
} |
| 232 |
|
| 233 |
void |
| 234 |
gdk_device_set_axis_use (GdkDevice *device, |
| 235 |
guint index, |
| 236 |
GdkAxisUse use) |
| 237 |
{ |
| 238 |
#if 0 |
| 239 |
/* Remapping axes is unsupported for now */ |
| 240 |
g_return_if_fail (device != NULL); |
| 241 |
g_return_if_fail (index < device->num_axes); |
| 242 |
|
| 243 |
device->axes[index].use = use; |
| 244 |
|
| 245 |
switch (use) |
| 246 |
{ |
| 247 |
case GDK_AXIS_X: |
| 248 |
case GDK_AXIS_Y: |
| 249 |
device->axes[index].min = 0.; |
| 250 |
device->axes[index].max = 0.; |
| 251 |
break; |
| 252 |
case GDK_AXIS_XTILT: |
| 253 |
case GDK_AXIS_YTILT: |
| 254 |
device->axes[index].min = -1.; |
| 255 |
device->axes[index].max = 1; |
| 256 |
break; |
| 257 |
default: |
| 258 |
device->axes[index].min = 0.; |
| 259 |
device->axes[index].max = 1; |
| 260 |
break; |
| 261 |
} |
| 262 |
#endif |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* gdk_input_set_device_state: |
| 267 |
* @device: The devices to set |
| 268 |
* @mask: The new button mask |
| 269 |
* @axes: The new axes values |
| 270 |
* |
| 271 |
* Set the state of a device's inputs for later |
| 272 |
* retrieval by gdk_device_get_state. |
| 273 |
*/ |
| 274 |
static void |
| 275 |
gdk_input_set_device_state (GdkDevice *device, |
| 276 |
GdkModifierType mask, |
| 277 |
gdouble *axes) |
| 278 |
{ |
| 279 |
GdkDevicePrivate *priv; |
| 280 |
gint i; |
| 281 |
|
| 282 |
if (device != _gdk_core_pointer) |
| 283 |
{ |
| 284 |
priv = (GdkDevicePrivate *)device; |
| 285 |
priv->last_state = mask; |
| 286 |
|
| 287 |
for (i = 0; i < device->num_axes; ++i) |
| 288 |
priv->last_axes_state[i] = axes[i]; |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
void |
| 293 |
gdk_device_get_state (GdkDevice *device, |
| 294 |
GdkWindow *window, |
| 295 |
gdouble *axes, |
| 296 |
GdkModifierType *mask) |
| 297 |
{ |
| 298 |
GdkDevicePrivate *priv; |
| 299 |
gint i; |
| 300 |
|
| 301 |
if (device == _gdk_core_pointer) |
| 302 |
{ |
| 303 |
gint x_int, y_int; |
| 304 |
|
| 305 |
gdk_window_get_pointer (window, &x_int, &y_int, mask); |
| 306 |
|
| 307 |
if (axes) |
| 308 |
{ |
| 309 |
axes[0] = x_int; |
| 310 |
axes[1] = y_int; |
| 311 |
} |
| 312 |
} |
| 313 |
else |
| 314 |
{ |
| 315 |
priv = (GdkDevicePrivate *)device; |
| 316 |
|
| 317 |
if (mask) |
| 318 |
*mask = priv->last_state; |
| 319 |
|
| 320 |
if (axes) |
| 321 |
for (i = 0; i < device->num_axes; ++i) |
| 322 |
axes[i] = priv->last_axes_state[i]; |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
void |
| 327 |
gdk_device_free_history (GdkTimeCoord **events, |
| 328 |
gint n_events) |
| 329 |
{ |
| 330 |
gint i; |
| 331 |
|
| 332 |
for (i = 0; i < n_events; i++) |
| 333 |
g_free (events[i]); |
| 334 |
|
| 335 |
g_free (events); |
| 336 |
} |
| 337 |
|
| 338 |
gboolean |
| 339 |
gdk_device_get_history (GdkDevice *device, |
| 340 |
GdkWindow *window, |
| 341 |
guint32 start, |
| 342 |
guint32 stop, |
| 343 |
GdkTimeCoord ***events, |
| 344 |
gint *n_events) |
| 345 |
{ |
| 346 |
g_return_val_if_fail (window != NULL, FALSE); |
| 347 |
g_return_val_if_fail (GDK_WINDOW_IS_QUARTZ (window), FALSE); |
| 348 |
g_return_val_if_fail (events != NULL, FALSE); |
| 349 |
g_return_val_if_fail (n_events != NULL, FALSE); |
| 350 |
|
| 351 |
*n_events = 0; |
| 352 |
*events = NULL; |
| 353 |
return FALSE; |
| 354 |
} |
| 355 |
|
| 356 |
gboolean |
| 357 |
gdk_device_set_mode (GdkDevice *device, |
| 358 |
GdkInputMode mode) |
| 359 |
{ |
| 360 |
/* FIXME: Window mode isn't supported yet */ |
| 361 |
if (device != _gdk_core_pointer && |
| 362 |
(mode == GDK_MODE_DISABLED || mode == GDK_MODE_SCREEN)) |
| 363 |
{ |
| 364 |
device->mode = mode; |
| 365 |
return TRUE; |
| 366 |
} |
| 367 |
|
| 368 |
return FALSE; |
| 369 |
} |
| 370 |
|
| 371 |
gint |
| 372 |
_gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev) |
| 373 |
{ |
| 374 |
return TRUE; |
| 375 |
} |
| 376 |
|
| 377 |
gint |
| 378 |
_gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev) |
| 379 |
{ |
| 380 |
return TRUE; |
| 381 |
} |
| 382 |
|
| 383 |
|
| 384 |
GdkInputWindow * |
| 385 |
_gdk_input_window_find(GdkWindow *window) |
| 386 |
{ |
| 387 |
GList *tmp_list; |
| 388 |
|
| 389 |
for (tmp_list=_gdk_input_windows; tmp_list; tmp_list=tmp_list->next) |
| 390 |
if (((GdkInputWindow *)(tmp_list->data))->window == window) |
| 391 |
return (GdkInputWindow *)(tmp_list->data); |
| 392 |
|
| 393 |
return NULL; /* Not found */ |
| 394 |
} |
| 395 |
|
| 396 |
/* FIXME: this routine currently needs to be called between creation |
| 397 |
and the corresponding configure event (because it doesn't get the |
| 398 |
root_relative_geometry). This should work with |
| 399 |
gtk_window_set_extension_events, but will likely fail in other |
| 400 |
cases */ |
| 401 |
|
| 402 |
void |
| 403 |
gdk_input_set_extension_events (GdkWindow *window, gint mask, |
| 404 |
GdkExtensionMode mode) |
| 405 |
{ |
| 406 |
GdkWindowObject *window_private; |
| 407 |
GList *tmp_list; |
| 408 |
GdkInputWindow *iw; |
| 409 |
|
| 410 |
g_return_if_fail (window != NULL); |
| 411 |
g_return_if_fail (GDK_WINDOW_IS_QUARTZ (window)); |
| 412 |
|
| 413 |
window_private = (GdkWindowObject*) window; |
| 414 |
|
| 415 |
if (mode == GDK_EXTENSION_EVENTS_NONE) |
| 416 |
mask = 0; |
| 417 |
|
| 418 |
if (mask != 0) |
| 419 |
{ |
| 420 |
iw = g_new(GdkInputWindow,1); |
| 421 |
|
| 422 |
iw->window = window; |
| 423 |
iw->mode = mode; |
| 424 |
|
| 425 |
iw->obscuring = NULL; |
| 426 |
iw->num_obscuring = 0; |
| 427 |
iw->grabbed = FALSE; |
| 428 |
|
| 429 |
_gdk_input_windows = g_list_append (_gdk_input_windows,iw); |
| 430 |
window_private->extension_events = mask; |
| 431 |
|
| 432 |
/* Add enter window events to the event mask */ |
| 433 |
/* FIXME, this is not needed for XINPUT_NONE */ |
| 434 |
gdk_window_set_events (window, |
| 435 |
gdk_window_get_events (window) | |
| 436 |
GDK_ENTER_NOTIFY_MASK); |
| 437 |
} |
| 438 |
else |
| 439 |
{ |
| 440 |
iw = _gdk_input_window_find (window); |
| 441 |
if (iw) |
| 442 |
{ |
| 443 |
_gdk_input_windows = g_list_remove (_gdk_input_windows,iw); |
| 444 |
g_free (iw); |
| 445 |
} |
| 446 |
|
| 447 |
window_private->extension_events = 0; |
| 448 |
} |
| 449 |
|
| 450 |
for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next) |
| 451 |
{ |
| 452 |
GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data); |
| 453 |
|
| 454 |
if (gdkdev != (GdkDevicePrivate *)_gdk_core_pointer) |
| 455 |
{ |
| 456 |
if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED |
| 457 |
&& (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL)) |
| 458 |
_gdk_input_enable_window (window,gdkdev); |
| 459 |
else |
| 460 |
_gdk_input_disable_window (window,gdkdev); |
| 461 |
} |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
void |
| 466 |
_gdk_input_window_destroy (GdkWindow *window) |
| 467 |
{ |
| 468 |
GdkInputWindow *input_window; |
| 469 |
|
| 470 |
input_window = _gdk_input_window_find (window); |
| 471 |
g_return_if_fail (input_window != NULL); |
| 472 |
|
| 473 |
_gdk_input_windows = g_list_remove (_gdk_input_windows,input_window); |
| 474 |
g_free (input_window); |
| 475 |
} |
| 476 |
|
| 477 |
void |
| 478 |
_gdk_input_init (void) |
| 479 |
{ |
| 480 |
GdkDevicePrivate *priv; |
| 481 |
|
| 482 |
_gdk_core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL); |
| 483 |
_gdk_core_pointer->name = "Core Pointer"; |
| 484 |
_gdk_core_pointer->source = GDK_SOURCE_MOUSE; |
| 485 |
_gdk_core_pointer->mode = GDK_MODE_SCREEN; |
| 486 |
_gdk_core_pointer->has_cursor = TRUE; |
| 487 |
_gdk_core_pointer->num_axes = N_CORE_POINTER_AXES; |
| 488 |
_gdk_core_pointer->axes = gdk_input_core_axes; |
| 489 |
_gdk_core_pointer->num_keys = 0; |
| 490 |
_gdk_core_pointer->keys = NULL; |
| 491 |
|
| 492 |
_gdk_display->core_pointer = _gdk_core_pointer; |
| 493 |
_gdk_input_devices = g_list_append (NULL, _gdk_core_pointer); |
| 494 |
|
| 495 |
_gdk_quartz_pen = g_object_new (GDK_TYPE_DEVICE, NULL); |
| 496 |
_gdk_quartz_pen->name = "Quartz Pen"; |
| 497 |
_gdk_quartz_pen->source = GDK_SOURCE_PEN; |
| 498 |
_gdk_quartz_pen->mode = GDK_MODE_SCREEN; |
| 499 |
_gdk_quartz_pen->has_cursor = TRUE; |
| 500 |
_gdk_quartz_pen->num_axes = N_INPUT_DEVICE_AXES; |
| 501 |
_gdk_quartz_pen->axes = gdk_quartz_pen_axes; |
| 502 |
_gdk_quartz_pen->num_keys = 0; |
| 503 |
_gdk_quartz_pen->keys = NULL; |
| 504 |
|
| 505 |
priv = (GdkDevicePrivate *)_gdk_quartz_pen; |
| 506 |
priv->last_axes_state = g_malloc_n (_gdk_quartz_pen->num_axes, sizeof (gdouble)); |
| 507 |
|
| 508 |
_gdk_input_devices = g_list_append (_gdk_input_devices, _gdk_quartz_pen); |
| 509 |
|
| 510 |
_gdk_quartz_cursor = g_object_new (GDK_TYPE_DEVICE, NULL); |
| 511 |
_gdk_quartz_cursor->name = "Quartz Cursor"; |
| 512 |
_gdk_quartz_cursor->source = GDK_SOURCE_CURSOR; |
| 513 |
_gdk_quartz_cursor->mode = GDK_MODE_SCREEN; |
| 514 |
_gdk_quartz_cursor->has_cursor = TRUE; |
| 515 |
_gdk_quartz_cursor->num_axes = N_INPUT_DEVICE_AXES; |
| 516 |
_gdk_quartz_cursor->axes = gdk_quartz_cursor_axes; |
| 517 |
_gdk_quartz_cursor->num_keys = 0; |
| 518 |
_gdk_quartz_cursor->keys = NULL; |
| 519 |
|
| 520 |
priv = (GdkDevicePrivate *)_gdk_quartz_cursor; |
| 521 |
priv->last_axes_state = g_malloc_n (_gdk_quartz_cursor->num_axes, sizeof (gdouble)); |
| 522 |
|
| 523 |
_gdk_input_devices = g_list_append (_gdk_input_devices, _gdk_quartz_cursor); |
| 524 |
|
| 525 |
_gdk_quartz_eraser = g_object_new (GDK_TYPE_DEVICE, NULL); |
| 526 |
_gdk_quartz_eraser->name = "Quartz Eraser"; |
| 527 |
_gdk_quartz_eraser->source = GDK_SOURCE_ERASER; |
| 528 |
_gdk_quartz_eraser->mode = GDK_MODE_SCREEN; |
| 529 |
_gdk_quartz_eraser->has_cursor = TRUE; |
| 530 |
_gdk_quartz_eraser->num_axes = N_INPUT_DEVICE_AXES; |
| 531 |
_gdk_quartz_eraser->axes = gdk_quartz_eraser_axes; |
| 532 |
_gdk_quartz_eraser->num_keys = 0; |
| 533 |
_gdk_quartz_eraser->keys = NULL; |
| 534 |
|
| 535 |
priv = (GdkDevicePrivate *)_gdk_quartz_eraser; |
| 536 |
priv->last_axes_state = g_malloc_n (_gdk_quartz_eraser->num_axes, sizeof (gdouble)); |
| 537 |
|
| 538 |
_gdk_input_devices = g_list_append (_gdk_input_devices, _gdk_quartz_eraser); |
| 539 |
|
| 540 |
active_device = _gdk_core_pointer; |
| 541 |
} |
| 542 |
|
| 543 |
void |
| 544 |
_gdk_input_exit (void) |
| 545 |
{ |
| 546 |
GList *tmp_list; |
| 547 |
GdkDevicePrivate *gdkdev; |
| 548 |
|
| 549 |
for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next) |
| 550 |
{ |
| 551 |
gdkdev = (GdkDevicePrivate *)(tmp_list->data); |
| 552 |
if (gdkdev != (GdkDevicePrivate *)_gdk_core_pointer) |
| 553 |
{ |
| 554 |
gdk_device_set_mode ((GdkDevice *)gdkdev, GDK_MODE_DISABLED); |
| 555 |
|
| 556 |
g_free (gdkdev->info.name); |
| 557 |
g_free (gdkdev->info.axes); |
| 558 |
g_free (gdkdev->info.keys); |
| 559 |
g_free (gdkdev->last_axes_state); |
| 560 |
g_free (gdkdev); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
g_list_free (_gdk_input_devices); |
| 565 |
|
| 566 |
for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next) |
| 567 |
{ |
| 568 |
g_free (tmp_list->data); |
| 569 |
} |
| 570 |
g_list_free (_gdk_input_windows); |
| 571 |
} |
| 572 |
|
| 573 |
gboolean |
| 574 |
gdk_device_get_axis (GdkDevice *device, gdouble *axes, GdkAxisUse use, gdouble *value) |
| 575 |
{ |
| 576 |
gint i; |
| 577 |
|
| 578 |
g_return_val_if_fail (device != NULL, FALSE); |
| 579 |
|
| 580 |
if (axes == NULL) |
| 581 |
return FALSE; |
| 582 |
|
| 583 |
for (i = 0; i < device->num_axes; i++) |
| 584 |
if (device->axes[i].use == use) |
| 585 |
{ |
| 586 |
if (value) |
| 587 |
*value = axes[i]; |
| 588 |
return TRUE; |
| 589 |
} |
| 590 |
|
| 591 |
return FALSE; |
| 592 |
} |
| 593 |
|
| 594 |
void |
| 595 |
_gdk_input_window_crossing (GdkWindow *window, |
| 596 |
gboolean enter) |
| 597 |
{ |
| 598 |
} |
| 599 |
|
| 600 |
/** |
| 601 |
* _gdk_input_quartz_tablet_proximity: |
| 602 |
* @deviceType: The result of [nsevent pointingDeviceType] |
| 603 |
* |
| 604 |
* Update the current active device based on a proximity event. |
| 605 |
*/ |
| 606 |
void |
| 607 |
_gdk_input_quartz_tablet_proximity (NSPointingDeviceType deviceType) |
| 608 |
{ |
| 609 |
if (deviceType == NSPenPointingDevice) |
| 610 |
active_device = _gdk_quartz_pen; |
| 611 |
else if (deviceType == NSCursorPointingDevice) |
| 612 |
active_device = _gdk_quartz_cursor; |
| 613 |
else if (deviceType == NSEraserPointingDevice) |
| 614 |
active_device = _gdk_quartz_eraser; |
| 615 |
else |
| 616 |
active_device = _gdk_core_pointer; |
| 617 |
} |
| 618 |
|
| 619 |
/** |
| 620 |
* _gdk_input_fill_quartz_input_event: |
| 621 |
* @event: The GDK mouse event. |
| 622 |
* @nsevent: The NSEvent that generated the mouse event. |
| 623 |
* @input_event: (out): Return location for the input event. |
| 624 |
* |
| 625 |
* Handle extended input for the passed event, the GdkEvent object |
| 626 |
* passed in should be a filled mouse button or motion event. |
| 627 |
* |
| 628 |
* Return value: %TRUE if an extended input event was generated. |
| 629 |
*/ |
| 630 |
gboolean |
| 631 |
_gdk_input_fill_quartz_input_event (GdkEvent *event, |
| 632 |
NSEvent *nsevent, |
| 633 |
GdkEvent *input_event) |
| 634 |
{ |
| 635 |
gdouble *axes; |
| 636 |
gint x, y; |
| 637 |
gint x_target, y_target; |
| 638 |
gdouble x_root, y_root; |
| 639 |
gint state; |
| 640 |
GdkInputWindow *iw; |
| 641 |
GdkWindow *target_window; |
| 642 |
GdkScreenQuartz *screen_quartz; |
| 643 |
|
| 644 |
if ([nsevent subtype] == NSTabletProximityEventSubtype) |
| 645 |
{ |
| 646 |
_gdk_input_quartz_tablet_proximity ([nsevent pointingDeviceType]); |
| 647 |
} |
| 648 |
else if (([nsevent subtype] != NSTabletPointEventSubtype) || |
| 649 |
(active_device == _gdk_core_pointer) || |
| 650 |
(active_device->mode == GDK_MODE_DISABLED)) |
| 651 |
{ |
| 652 |
_gdk_display->ignore_core_events = FALSE; |
| 653 |
return FALSE; |
| 654 |
} |
| 655 |
|
| 656 |
switch (event->any.type) |
| 657 |
{ |
| 658 |
case GDK_MOTION_NOTIFY: |
| 659 |
x = event->motion.x; |
| 660 |
y = event->motion.y; |
| 661 |
state = event->motion.state; |
| 662 |
break; |
| 663 |
case GDK_BUTTON_PRESS: |
| 664 |
case GDK_BUTTON_RELEASE: |
| 665 |
x = event->button.x; |
| 666 |
y = event->button.y; |
| 667 |
state = event->button.state; |
| 668 |
break; |
| 669 |
default: |
| 670 |
/* Not an input related event */ |
| 671 |
return FALSE; |
| 672 |
break; |
| 673 |
} |
| 674 |
|
| 675 |
/* Input events won't be propagated through windows that aren't listening |
| 676 |
* for input events, so _gdk_window_get_input_window_for_event finds the |
| 677 |
* window to directly send the event to. |
| 678 |
*/ |
| 679 |
target_window = _gdk_window_get_input_window_for_event (event->any.window, |
| 680 |
event->any.type, |
| 681 |
0, x, y, 0); |
| 682 |
|
| 683 |
iw = _gdk_input_window_find (target_window); |
| 684 |
|
| 685 |
if (!iw) |
| 686 |
{ |
| 687 |
/* Return if the target window doesn't have extended events enabled or |
| 688 |
* hasn't asked for this type of event. |
| 689 |
*/ |
| 690 |
_gdk_display->ignore_core_events = FALSE; |
| 691 |
return FALSE; |
| 692 |
} |
| 693 |
|
| 694 |
/* The cursor is inside an extended events window, block propagation of the |
| 695 |
* core motion / button events |
| 696 |
*/ |
| 697 |
_gdk_display->ignore_core_events = TRUE; |
| 698 |
|
| 699 |
axes = g_malloc_n (N_INPUT_DEVICE_AXES, sizeof (gdouble)); |
| 700 |
|
| 701 |
gdk_window_get_origin (target_window, &x_target, &y_target); |
| 702 |
|
| 703 |
/* Equation for root x & y taken from _gdk_quartz_window_xy_to_gdk_xy |
| 704 |
* recalculated here to get doubles instead of ints. |
| 705 |
*/ |
| 706 |
screen_quartz = GDK_SCREEN_QUARTZ (_gdk_screen); |
| 707 |
x_root = [NSEvent mouseLocation].x - screen_quartz->min_x; |
| 708 |
y_root = screen_quartz->height - [NSEvent mouseLocation].y + screen_quartz->min_y; |
| 709 |
|
| 710 |
axes[0] = x_root - x_target; |
| 711 |
axes[1] = y_root - y_target; |
| 712 |
axes[2] = [nsevent pressure]; |
| 713 |
axes[3] = [nsevent tilt].x; |
| 714 |
axes[4] = [nsevent tilt].y; |
| 715 |
|
| 716 |
gdk_input_set_device_state (active_device, state, axes); |
| 717 |
|
| 718 |
input_event->any.window = target_window; |
| 719 |
input_event->any.type = event->any.type; |
| 720 |
input_event->any.send_event = event->any.send_event; |
| 721 |
|
| 722 |
switch (event->any.type) |
| 723 |
{ |
| 724 |
case GDK_MOTION_NOTIFY: |
| 725 |
input_event->motion.device = active_device; |
| 726 |
input_event->motion.x = axes[0]; |
| 727 |
input_event->motion.y = axes[1]; |
| 728 |
input_event->motion.axes = axes; |
| 729 |
input_event->motion.x_root = x_root; |
| 730 |
input_event->motion.y_root = y_root; |
| 731 |
|
| 732 |
input_event->motion.time = event->motion.time; |
| 733 |
input_event->motion.state = event->motion.state; |
| 734 |
input_event->motion.is_hint = event->motion.is_hint; |
| 735 |
break; |
| 736 |
case GDK_BUTTON_PRESS: |
| 737 |
case GDK_BUTTON_RELEASE: |
| 738 |
input_event->button.device = active_device; |
| 739 |
input_event->button.x = axes[0]; |
| 740 |
input_event->button.y = axes[1]; |
| 741 |
input_event->button.axes = axes; |
| 742 |
input_event->button.x_root = x_root; |
| 743 |
input_event->button.y_root = y_root; |
| 744 |
|
| 745 |
input_event->button.time = event->button.time; |
| 746 |
input_event->button.state = event->button.state; |
| 747 |
input_event->button.button = event->button.button; |
| 748 |
break; |
| 749 |
default: |
| 750 |
return FALSE; |
| 751 |
break; |
| 752 |
} |
| 753 |
|
| 754 |
return TRUE; |
| 755 |
} |