]> Pileus Git - ~andy/gtk/blob - gdk/gdkdevice.c
docs: Add docs about how to get a GtkDevice
[~andy/gtk] / gdk / gdkdevice.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include "gdkdeviceprivate.h"
23 #include "gdkdisplayprivate.h"
24 #include "gdkinternals.h"
25 #include "gdkintl.h"
26
27 typedef struct _GdkAxisInfo GdkAxisInfo;
28
29 struct _GdkAxisInfo
30 {
31   GdkAtom label;
32   GdkAxisUse use;
33
34   gdouble min_axis;
35   gdouble max_axis;
36
37   gdouble min_value;
38   gdouble max_value;
39   gdouble resolution;
40 };
41
42 enum {
43   CHANGED,
44   LAST_SIGNAL
45 };
46
47 static guint signals [LAST_SIGNAL] = { 0 };
48
49
50 static void gdk_device_dispose      (GObject      *object);
51 static void gdk_device_set_property (GObject      *object,
52                                      guint         prop_id,
53                                      const GValue *value,
54                                      GParamSpec   *pspec);
55 static void gdk_device_get_property (GObject      *object,
56                                      guint         prop_id,
57                                      GValue       *value,
58                                      GParamSpec   *pspec);
59
60
61 G_DEFINE_ABSTRACT_TYPE (GdkDevice, gdk_device, G_TYPE_OBJECT)
62
63 enum {
64   PROP_0,
65   PROP_DISPLAY,
66   PROP_DEVICE_MANAGER,
67   PROP_NAME,
68   PROP_ASSOCIATED_DEVICE,
69   PROP_TYPE,
70   PROP_INPUT_SOURCE,
71   PROP_INPUT_MODE,
72   PROP_HAS_CURSOR,
73   PROP_N_AXES
74 };
75
76
77 static void
78 gdk_device_class_init (GdkDeviceClass *klass)
79 {
80   GObjectClass *object_class = G_OBJECT_CLASS (klass);
81
82   object_class->dispose = gdk_device_dispose;
83   object_class->set_property = gdk_device_set_property;
84   object_class->get_property = gdk_device_get_property;
85
86   /**
87    * GdkDevice:display:
88    *
89    * The #GdkDisplay the #GdkDevice pertains to.
90    *
91    * Since: 3.0
92    */
93   g_object_class_install_property (object_class,
94                                    PROP_DISPLAY,
95                                    g_param_spec_object ("display",
96                                                         P_("Device Display"),
97                                                         P_("Display which the device belongs to"),
98                                                         GDK_TYPE_DISPLAY,
99                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
100                                                         G_PARAM_STATIC_STRINGS));
101   /**
102    * GdkDevice:device-manager:
103    *
104    * The #GdkDeviceManager the #GdkDevice pertains to.
105    *
106    * Since: 3.0
107    */
108   g_object_class_install_property (object_class,
109                                    PROP_DEVICE_MANAGER,
110                                    g_param_spec_object ("device-manager",
111                                                         P_("Device manager"),
112                                                         P_("Device manager which the device belongs to"),
113                                                         GDK_TYPE_DEVICE_MANAGER,
114                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
115                                                         G_PARAM_STATIC_STRINGS));
116   /**
117    * GdkDevice:name:
118    *
119    * The device name.
120    *
121    * Since: 3.0
122    */
123   g_object_class_install_property (object_class,
124                                    PROP_NAME,
125                                    g_param_spec_string ("name",
126                                                         P_("Device name"),
127                                                         P_("Device name"),
128                                                         NULL,
129                                                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
130                                                         G_PARAM_STATIC_STRINGS));
131   /**
132    * GdkDevice:type:
133    *
134    * Device role in the device manager.
135    *
136    * Since: 3.0
137    */
138   g_object_class_install_property (object_class,
139                                    PROP_TYPE,
140                                    g_param_spec_enum ("type",
141                                                       P_("Device type"),
142                                                       P_("Device role in the device manager"),
143                                                       GDK_TYPE_DEVICE_TYPE,
144                                                       GDK_DEVICE_TYPE_MASTER,
145                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
146                                                       G_PARAM_STATIC_STRINGS));
147   /**
148    * GdkDevice:associated-device:
149    *
150    * Associated pointer or keyboard with this device, if any. Devices of type #GDK_DEVICE_TYPE_MASTER
151    * always come in keyboard/pointer pairs. Other device types will have a %NULL associated device.
152    *
153    * Since: 3.0
154    */
155   g_object_class_install_property (object_class,
156                                    PROP_ASSOCIATED_DEVICE,
157                                    g_param_spec_object ("associated-device",
158                                                         P_("Associated device"),
159                                                         P_("Associated pointer or keyboard with this device"),
160                                                         GDK_TYPE_DEVICE,
161                                                         G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
162   /**
163    * GdkDevice:input-source:
164    *
165    * Source type for the device.
166    *
167    * Since: 3.0
168    */
169   g_object_class_install_property (object_class,
170                                    PROP_INPUT_SOURCE,
171                                    g_param_spec_enum ("input-source",
172                                                       P_("Input source"),
173                                                       P_("Source type for the device"),
174                                                       GDK_TYPE_INPUT_SOURCE,
175                                                       GDK_SOURCE_MOUSE,
176                                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
177                                                       G_PARAM_STATIC_STRINGS));
178   /**
179    * GdkDevice:input-mode:
180    *
181    * Input mode for the device.
182    *
183    * Since: 3.0
184    */
185   g_object_class_install_property (object_class,
186                                    PROP_INPUT_MODE,
187                                    g_param_spec_enum ("input-mode",
188                                                       P_("Input mode for the device"),
189                                                       P_("Input mode for the device"),
190                                                       GDK_TYPE_INPUT_MODE,
191                                                       GDK_MODE_DISABLED,
192                                                       G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
193   /**
194    * GdkDevice:has-cursor:
195    *
196    * Whether the device is represented by a cursor on the screen. Devices of type
197    * %GDK_DEVICE_TYPE_MASTER will have %TRUE here.
198    *
199    * Since: 3.0
200    */
201   g_object_class_install_property (object_class,
202                                    PROP_HAS_CURSOR,
203                                    g_param_spec_boolean ("has-cursor",
204                                                          P_("Whether the device has a cursor"),
205                                                          P_("Whether there is a visible cursor following device motion"),
206                                                          FALSE,
207                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
208                                                          G_PARAM_STATIC_STRINGS));
209   /**
210    * GdkDevice:n-axes:
211    *
212    * Number of axes in the device.
213    *
214    * Since: 3.0
215    */
216   g_object_class_install_property (object_class,
217                                    PROP_N_AXES,
218                                    g_param_spec_uint ("n-axes",
219                                                       P_("Number of axes in the device"),
220                                                       P_("Number of axes in the device"),
221                                                       0, G_MAXUINT, 0,
222                                                       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
223
224   /**
225    * GdkDevice::changed:
226    * @device: the #GdkDevice that changed.
227    *
228    * The ::changed signal is emitted either when the #GdkDevice
229    * has changed the number of either axes or keys. For example
230    * In X this will normally happen when the slave device routing
231    * events through the master device changes (for example, user
232    * switches from the USB mouse to a tablet), in that case the
233    * master device will change to reflect the new slave device
234    * axes and keys.
235    */
236   signals[CHANGED] =
237     g_signal_new (g_intern_static_string ("changed"),
238                   G_TYPE_FROM_CLASS (object_class),
239                   G_SIGNAL_RUN_LAST,
240                   0, NULL, NULL,
241                   g_cclosure_marshal_VOID__VOID,
242                   G_TYPE_NONE, 0);
243 }
244
245 static void
246 gdk_device_init (GdkDevice *device)
247 {
248   device->axes = g_array_new (FALSE, TRUE, sizeof (GdkAxisInfo));
249 }
250
251 static void
252 gdk_device_dispose (GObject *object)
253 {
254   GdkDevice *device = GDK_DEVICE (object);
255
256   if (device->type == GDK_DEVICE_TYPE_SLAVE)
257     _gdk_device_remove_slave (device->associated, device);
258
259   if (device->associated)
260     {
261       _gdk_device_set_associated_device (device->associated, NULL);
262       g_object_unref (device->associated);
263       device->associated = NULL;
264     }
265
266   if (device->axes)
267     {
268       g_array_free (device->axes, TRUE);
269       device->axes = NULL;
270     }
271
272   g_free (device->name);
273   g_free (device->keys);
274
275   device->name = NULL;
276   device->keys = NULL;
277
278   G_OBJECT_CLASS (gdk_device_parent_class)->dispose (object);
279 }
280
281 static void
282 gdk_device_set_property (GObject      *object,
283                          guint         prop_id,
284                          const GValue *value,
285                          GParamSpec   *pspec)
286 {
287   GdkDevice *device = GDK_DEVICE (object);
288
289   switch (prop_id)
290     {
291     case PROP_DISPLAY:
292       device->display = g_value_get_object (value);
293       break;
294     case PROP_DEVICE_MANAGER:
295       device->manager = g_value_get_object (value);
296       break;
297     case PROP_NAME:
298       if (device->name)
299         g_free (device->name);
300
301       device->name = g_value_dup_string (value);
302       break;
303     case PROP_TYPE:
304       device->type = g_value_get_enum (value);
305       break;
306     case PROP_INPUT_SOURCE:
307       device->source = g_value_get_enum (value);
308       break;
309     case PROP_INPUT_MODE:
310       gdk_device_set_mode (device, g_value_get_enum (value));
311       break;
312     case PROP_HAS_CURSOR:
313       device->has_cursor = g_value_get_boolean (value);
314       break;
315     default:
316       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317       break;
318     }
319 }
320
321 static void
322 gdk_device_get_property (GObject    *object,
323                          guint       prop_id,
324                          GValue     *value,
325                          GParamSpec *pspec)
326 {
327   GdkDevice *device = GDK_DEVICE (object);
328
329   switch (prop_id)
330     {
331     case PROP_DISPLAY:
332       g_value_set_object (value, device->display);
333       break;
334     case PROP_DEVICE_MANAGER:
335       g_value_set_object (value, device->manager);
336       break;
337     case PROP_ASSOCIATED_DEVICE:
338       g_value_set_object (value, device->associated);
339       break;
340     case PROP_NAME:
341       g_value_set_string (value, device->name);
342       break;
343     case PROP_TYPE:
344       g_value_set_enum (value, device->type);
345       break;
346     case PROP_INPUT_SOURCE:
347       g_value_set_enum (value, device->source);
348       break;
349     case PROP_INPUT_MODE:
350       g_value_set_enum (value, device->mode);
351       break;
352     case PROP_HAS_CURSOR:
353       g_value_set_boolean (value, device->has_cursor);
354       break;
355     case PROP_N_AXES:
356       g_value_set_uint (value, device->axes->len);
357       break;
358     default:
359       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
360       break;
361     }
362 }
363
364 /**
365  * gdk_device_get_state:
366  * @device: a #GdkDevice.
367  * @window: a #GdkWindow.
368  * @axes: an array of doubles to store the values of the axes of @device in,
369  * or %NULL.
370  * @mask: location to store the modifiers, or %NULL.
371  *
372  * Gets the current state of a pointer device relative to @window.
373  */
374 void
375 gdk_device_get_state (GdkDevice       *device,
376                       GdkWindow       *window,
377                       gdouble         *axes,
378                       GdkModifierType *mask)
379 {
380   g_return_if_fail (GDK_IS_DEVICE (device));
381   g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
382   g_return_if_fail (GDK_IS_WINDOW (window));
383
384   if (GDK_DEVICE_GET_CLASS (device)->get_state)
385     GDK_DEVICE_GET_CLASS (device)->get_state (device, window, axes, mask);
386 }
387
388 /**
389  * gdk_device_get_history:
390  * @device: a #GdkDevice
391  * @window: the window with respect to which which the event coordinates will be reported
392  * @start: starting timestamp for range of events to return
393  * @stop: ending timestamp for the range of events to return
394  * @events: (array length=n_events) (out) (transfer none): location to store a newly-allocated array of #GdkTimeCoord, or %NULL
395  * @n_events: location to store the length of @events, or %NULL
396  *
397  * Obtains the motion history for a pointer device; given a starting and
398  * ending timestamp, return all events in the motion history for
399  * the device in the given range of time. Some windowing systems
400  * do not support motion history, in which case, %FALSE will
401  * be returned. (This is not distinguishable from the case where
402  * motion history is supported and no events were found.)
403  *
404  * Return value: %TRUE if the windowing system supports motion history and
405  *  at least one event was found.
406  **/
407 gboolean
408 gdk_device_get_history (GdkDevice      *device,
409                         GdkWindow      *window,
410                         guint32         start,
411                         guint32         stop,
412                         GdkTimeCoord ***events,
413                         gint           *n_events)
414 {
415   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
416   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
417   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
418
419   if (n_events)
420     *n_events = 0;
421
422   if (events)
423     *events = NULL;
424
425   if (GDK_WINDOW_DESTROYED (window))
426     return FALSE;
427
428   if (!GDK_DEVICE_GET_CLASS (device)->get_history)
429     return FALSE;
430
431   return GDK_DEVICE_GET_CLASS (device)->get_history (device, window,
432                                                      start, stop,
433                                                      events, n_events);
434 }
435
436 GdkTimeCoord **
437 _gdk_device_allocate_history (GdkDevice *device,
438                               gint       n_events)
439 {
440   GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
441   gint i;
442
443   for (i = 0; i < n_events; i++)
444     result[i] = g_malloc (sizeof (GdkTimeCoord) -
445                           sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->axes->len));
446   return result;
447 }
448
449 /**
450  * gdk_device_free_history:
451  * @events: (inout) (transfer none): an array of #GdkTimeCoord.
452  * @n_events: the length of the array.
453  *
454  * Frees an array of #GdkTimeCoord that was returned by gdk_device_get_history().
455  */
456 void
457 gdk_device_free_history (GdkTimeCoord **events,
458                          gint           n_events)
459 {
460   gint i;
461
462   for (i = 0; i < n_events; i++)
463     g_free (events[i]);
464
465   g_free (events);
466 }
467
468 /**
469  * gdk_device_get_name:
470  * @device: a #GdkDevice
471  *
472  * Determines the name of the device.
473  *
474  * Return value: a name
475  *
476  * Since: 2.20
477  **/
478 const gchar *
479 gdk_device_get_name (GdkDevice *device)
480 {
481   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
482
483   return device->name;
484 }
485
486 /**
487  * gdk_device_get_has_cursor:
488  * @device: a #GdkDevice
489  *
490  * Determines whether the pointer follows device motion.
491  *
492  * Return value: %TRUE if the pointer follows device motion
493  *
494  * Since: 2.20
495  **/
496 gboolean
497 gdk_device_get_has_cursor (GdkDevice *device)
498 {
499   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
500   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
501
502   return device->has_cursor;
503 }
504
505 /**
506  * gdk_device_get_source:
507  * @device: a #GdkDevice
508  *
509  * Determines the type of the device.
510  *
511  * Return value: a #GdkInputSource
512  *
513  * Since: 2.20
514  **/
515 GdkInputSource
516 gdk_device_get_source (GdkDevice *device)
517 {
518   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
519
520   return device->source;
521 }
522
523 /**
524  * gdk_device_set_source:
525  * @device: a #GdkDevice.
526  * @source: the source type.
527  *
528  * Sets the source type for an input device.
529  **/
530 void
531 gdk_device_set_source (GdkDevice      *device,
532                        GdkInputSource  source)
533 {
534   g_return_if_fail (GDK_IS_DEVICE (device));
535
536   device->source = source;
537   g_object_notify (G_OBJECT (device), "input-source");
538 }
539
540 /**
541  * gdk_device_get_mode:
542  * @device: a #GdkDevice
543  *
544  * Determines the mode of the device.
545  *
546  * Return value: a #GdkInputSource
547  *
548  * Since: 2.20
549  **/
550 GdkInputMode
551 gdk_device_get_mode (GdkDevice *device)
552 {
553   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
554
555   return device->mode;
556 }
557
558 /**
559  * gdk_device_set_mode:
560  * @device: a #GdkDevice.
561  * @mode: the input mode.
562  *
563  * Sets a the mode of an input device. The mode controls if the
564  * device is active and whether the device's range is mapped to the
565  * entire screen or to a single window.
566  *
567  * Returns: %TRUE if the mode was successfully changed.
568  **/
569 gboolean
570 gdk_device_set_mode (GdkDevice    *device,
571                      GdkInputMode  mode)
572 {
573   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
574
575   if (device->mode == mode)
576     return TRUE;
577
578   if (mode == GDK_MODE_DISABLED &&
579       gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER)
580     return FALSE;
581
582   device->mode = mode;
583   g_object_notify (G_OBJECT (device), "input-mode");
584
585   return TRUE;
586 }
587
588 /**
589  * gdk_device_get_n_keys:
590  * @device: a #GdkDevice
591  *
592  * Returns the number of keys the device currently has.
593  *
594  * Returns: the number of keys.
595  *
596  * Since: 2.24
597  **/
598 gint
599 gdk_device_get_n_keys (GdkDevice *device)
600 {
601   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
602
603   return device->num_keys;
604 }
605
606 /**
607  * gdk_device_get_key:
608  * @device: a #GdkDevice.
609  * @index_: the index of the macro button to get.
610  * @keyval: return value for the keyval.
611  * @modifiers: return value for modifiers.
612  *
613  * If @index_ has a valid keyval, this function will return %TRUE
614  * and fill in @keyval and @modifiers with the keyval settings.
615  *
616  * Returns: %TRUE if keyval is set for @index.
617  *
618  * Since: 2.20
619  **/
620 gboolean
621 gdk_device_get_key (GdkDevice       *device,
622                     guint            index_,
623                     guint           *keyval,
624                     GdkModifierType *modifiers)
625 {
626   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
627   g_return_val_if_fail (index_ < device->num_keys, FALSE);
628
629   if (!device->keys[index_].keyval &&
630       !device->keys[index_].modifiers)
631     return FALSE;
632
633   if (keyval)
634     *keyval = device->keys[index_].keyval;
635
636   if (modifiers)
637     *modifiers = device->keys[index_].modifiers;
638
639   return TRUE;
640 }
641
642 /**
643  * gdk_device_set_key:
644  * @device: a #GdkDevice
645  * @index_: the index of the macro button to set
646  * @keyval: the keyval to generate
647  * @modifiers: the modifiers to set
648  *
649  * Specifies the X key event to generate when a macro button of a device
650  * is pressed.
651  **/
652 void
653 gdk_device_set_key (GdkDevice      *device,
654                     guint           index_,
655                     guint           keyval,
656                     GdkModifierType modifiers)
657 {
658   g_return_if_fail (GDK_IS_DEVICE (device));
659   g_return_if_fail (index_ < device->num_keys);
660
661   device->keys[index_].keyval = keyval;
662   device->keys[index_].modifiers = modifiers;
663 }
664
665 /**
666  * gdk_device_get_axis_use:
667  * @device: a pointer #GdkDevice.
668  * @index_: the index of the axis.
669  *
670  * Returns the axis use for @index_.
671  *
672  * Returns: a #GdkAxisUse specifying how the axis is used.
673  *
674  * Since: 2.20
675  **/
676 GdkAxisUse
677 gdk_device_get_axis_use (GdkDevice *device,
678                          guint      index_)
679 {
680   GdkAxisInfo *info;
681
682   g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_AXIS_IGNORE);
683   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, GDK_AXIS_IGNORE);
684   g_return_val_if_fail (index_ < device->axes->len, GDK_AXIS_IGNORE);
685
686   info = &g_array_index (device->axes, GdkAxisInfo, index_);
687
688   return info->use;
689 }
690
691 /**
692  * gdk_device_set_axis_use:
693  * @device: a pointer #GdkDevice
694  * @index_: the index of the axis
695  * @use: specifies how the axis is used
696  *
697  * Specifies how an axis of a device is used.
698  **/
699 void
700 gdk_device_set_axis_use (GdkDevice   *device,
701                          guint        index_,
702                          GdkAxisUse   use)
703 {
704   GdkAxisInfo *info;
705
706   g_return_if_fail (GDK_IS_DEVICE (device));
707   g_return_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD);
708   g_return_if_fail (index_ < device->axes->len);
709
710   info = &g_array_index (device->axes, GdkAxisInfo, index_);
711   info->use = use;
712
713   switch (use)
714     {
715     case GDK_AXIS_X:
716     case GDK_AXIS_Y:
717       info->min_axis = 0;
718       info->max_axis = 0;
719       break;
720     case GDK_AXIS_XTILT:
721     case GDK_AXIS_YTILT:
722       info->min_axis = -1;
723       info->max_axis = 1;
724       break;
725     default:
726       info->min_axis = 0;
727       info->max_axis = 1;
728       break;
729     }
730 }
731
732 /**
733  * gdk_device_get_display:
734  * @device: a #GdkDevice
735  *
736  * Returns the #GdkDisplay to which @device pertains.
737  *
738  * Returns: (transfer none): a #GdkDisplay. This memory is owned
739  *          by GTK+, and must not be freed or unreffed.
740  *
741  * Since: 3.0
742  **/
743 GdkDisplay *
744 gdk_device_get_display (GdkDevice *device)
745 {
746   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
747
748   return device->display;
749 }
750
751 /**
752  * gdk_device_get_associated_device:
753  * @device: a #GdkDevice
754  *
755  * Returns the associated device to @device, if @device is of type
756  * %GDK_DEVICE_TYPE_MASTER, it will return the paired pointer or
757  * keyboard.
758  *
759  * If @device is of type %GDK_DEVICE_TYPE_SLAVE, it will return
760  * the master device to which @device is attached to.
761  *
762  * If @device is of type %GDK_DEVICE_TYPE_FLOATING, %NULL will be
763  * returned, as there is no associated device.
764  *
765  * Returns: (transfer none): The associated device, or %NULL
766  *
767  * Since: 3.0
768  **/
769 GdkDevice *
770 gdk_device_get_associated_device (GdkDevice *device)
771 {
772   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
773
774   return device->associated;
775 }
776
777 static void
778 _gdk_device_set_device_type (GdkDevice     *device,
779                              GdkDeviceType  type)
780 {
781   if (device->type != type)
782     {
783       device->type = type;
784
785       g_object_notify (G_OBJECT (device), "type");
786     }
787 }
788
789 void
790 _gdk_device_set_associated_device (GdkDevice *device,
791                                    GdkDevice *associated)
792 {
793   g_return_if_fail (GDK_IS_DEVICE (device));
794   g_return_if_fail (associated == NULL || GDK_IS_DEVICE (associated));
795
796   if (device->associated == associated)
797     return;
798
799   if (device->associated)
800     {
801       g_object_unref (device->associated);
802       device->associated = NULL;
803     }
804
805   if (associated)
806     device->associated = g_object_ref (associated);
807
808   if (device->type != GDK_DEVICE_TYPE_MASTER)
809     {
810       if (device->associated)
811         _gdk_device_set_device_type (device, GDK_DEVICE_TYPE_SLAVE);
812       else
813         _gdk_device_set_device_type (device, GDK_DEVICE_TYPE_FLOATING);
814     }
815 }
816
817 /**
818  * gdk_device_list_slave_devices:
819  * @device: a #GdkDevice
820  *
821  * If the device if of type %GDK_DEVICE_TYPE_MASTER, it will return
822  * the list of slave devices attached to it, otherwise it will return
823  * %NULL
824  *
825  * Returns: (transfer container): the list of slave devices, or %NULL. The
826  *          list must be freed with g_list_free(), the contents of the list
827  *          are owned by GTK+ and should not be freed.
828  **/
829 GList *
830 gdk_device_list_slave_devices (GdkDevice *device)
831 {
832   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
833   g_return_val_if_fail (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER, NULL);
834
835   return g_list_copy (device->slaves);
836 }
837
838 void
839 _gdk_device_add_slave (GdkDevice *device,
840                        GdkDevice *slave)
841 {
842   g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
843   g_return_if_fail (gdk_device_get_device_type (slave) != GDK_DEVICE_TYPE_MASTER);
844
845   if (!g_list_find (device->slaves, slave))
846     device->slaves = g_list_prepend (device->slaves, slave);
847 }
848
849 void
850 _gdk_device_remove_slave (GdkDevice *device,
851                           GdkDevice *slave)
852 {
853   GList *elem;
854
855   g_return_if_fail (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_MASTER);
856   g_return_if_fail (gdk_device_get_device_type (slave) != GDK_DEVICE_TYPE_MASTER);
857
858   elem = g_list_find (device->slaves, slave);
859
860   if (!elem)
861     return;
862
863   device->slaves = g_list_delete_link (device->slaves, elem);
864 }
865
866 /**
867  * gdk_device_get_device_type:
868  * @device: a #GdkDevice
869  *
870  * Returns the device type for @device.
871  *
872  * Returns: the #GdkDeviceType for @device.
873  *
874  * Since: 3.0
875  **/
876 GdkDeviceType
877 gdk_device_get_device_type (GdkDevice *device)
878 {
879   g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_DEVICE_TYPE_MASTER);
880
881   return device->type;
882 }
883
884 /**
885  * gdk_device_get_n_axes:
886  * @device: a pointer #GdkDevice
887  *
888  * Returns the number of axes the device currently has.
889  *
890  * Returns: the number of axes.
891  *
892  * Since: 3.0
893  **/
894 gint
895 gdk_device_get_n_axes (GdkDevice *device)
896 {
897   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
898   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, 0);
899
900   return device->axes->len;
901 }
902
903 /**
904  * gdk_device_list_axes:
905  * @device: a pointer #GdkDevice
906  *
907  * Returns a #GList of #GdkAtom<!-- -->s, containing the labels for
908  * the axes that @device currently has.
909  *
910  * Returns: (transfer container) (element-type GdkAtom):
911  *     A #GList of #GdkAtom<!-- -->s, free with g_list_free().
912  *
913  * Since: 3.0
914  **/
915 GList *
916 gdk_device_list_axes (GdkDevice *device)
917 {
918   GList *axes = NULL;
919   gint i;
920
921   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
922   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, NULL);
923
924   for (i = 0; i < device->axes->len; i++)
925     {
926       GdkAxisInfo axis_info;
927
928       axis_info = g_array_index (device->axes, GdkAxisInfo, i);
929       axes = g_list_prepend (axes, GDK_ATOM_TO_POINTER (axis_info.label));
930     }
931
932   return g_list_reverse (axes);
933 }
934
935 /**
936  * gdk_device_get_axis_value:
937  * @device: a pointer #GdkDevice.
938  * @axes: pointer to an array of axes
939  * @axis_label: #GdkAtom with the axis label.
940  * @value: location to store the found value.
941  *
942  * Interprets an array of double as axis values for a given device,
943  * and locates the value in the array for a given axis label, as returned
944  * by gdk_device_list_axes()
945  *
946  * Returns: %TRUE if the given axis use was found, otherwise %FALSE.
947  *
948  * Since: 3.0
949  **/
950 gboolean
951 gdk_device_get_axis_value (GdkDevice *device,
952                            gdouble   *axes,
953                            GdkAtom    axis_label,
954                            gdouble   *value)
955 {
956   gint i;
957
958   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
959   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
960
961   if (axes == NULL)
962     return FALSE;
963
964   for (i = 0; i < device->axes->len; i++)
965     {
966       GdkAxisInfo axis_info;
967
968       axis_info = g_array_index (device->axes, GdkAxisInfo, i);
969
970       if (axis_info.label != axis_label)
971         continue;
972
973       if (value)
974         *value = axes[i];
975
976       return TRUE;
977     }
978
979   return FALSE;
980 }
981
982 /**
983  * gdk_device_get_axis:
984  * @device: a #GdkDevice
985  * @axes: pointer to an array of axes
986  * @use: the use to look for
987  * @value: location to store the found value.
988  *
989  * Interprets an array of double as axis values for a given device,
990  * and locates the value in the array for a given axis use.
991  *
992  * Return value: %TRUE if the given axis use was found, otherwise %FALSE
993  **/
994 gboolean
995 gdk_device_get_axis (GdkDevice  *device,
996                      gdouble    *axes,
997                      GdkAxisUse  use,
998                      gdouble    *value)
999 {
1000   gint i;
1001
1002   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
1003   g_return_val_if_fail (gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD, FALSE);
1004
1005   if (axes == NULL)
1006     return FALSE;
1007
1008   g_return_val_if_fail (device->axes != NULL, FALSE);
1009
1010   for (i = 0; i < device->axes->len; i++)
1011     {
1012       GdkAxisInfo axis_info;
1013
1014       axis_info = g_array_index (device->axes, GdkAxisInfo, i);
1015
1016       if (axis_info.use != use)
1017         continue;
1018
1019       if (value)
1020         *value = axes[i];
1021
1022       return TRUE;
1023     }
1024
1025   return FALSE;
1026 }
1027
1028 static GdkEventMask
1029 get_native_grab_event_mask (GdkEventMask grab_mask)
1030 {
1031   /* Similar to the above but for pointer events only */
1032   return
1033     GDK_POINTER_MOTION_MASK |
1034     GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
1035     GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1036     GDK_SCROLL_MASK |
1037     (grab_mask &
1038      ~(GDK_POINTER_MOTION_HINT_MASK |
1039        GDK_BUTTON_MOTION_MASK |
1040        GDK_BUTTON1_MOTION_MASK |
1041        GDK_BUTTON2_MOTION_MASK |
1042        GDK_BUTTON3_MOTION_MASK));
1043 }
1044
1045 /**
1046  * gdk_device_grab:
1047  * @device: a #GdkDevice. To get the device you can use gtk_get_current_event_device()
1048  *   or gdk_event_get_device() if the grab is in reaction to an event. Also, you can use
1049  *   gdk_device_manager_get_client_pointer() but only in code that isn't triggered by a
1050  *   #GdkEvent and there aren't other means to get a meaningful #GdkDevice to operate on.
1051  * @window: the #GdkWindow which will own the grab (the grab window)
1052  * @grab_ownership: specifies the grab ownership.
1053  * @owner_events: if %FALSE then all device events are reported with respect to
1054  *                @window and are only reported if selected by @event_mask. If
1055  *                %TRUE then pointer events for this application are reported
1056  *                as normal, but pointer events outside this application are
1057  *                reported with respect to @window and only if selected by
1058  *                @event_mask. In either mode, unreported events are discarded.
1059  * @event_mask: specifies the event mask, which is used in accordance with
1060  *              @owner_events.
1061  * @cursor: the cursor to display while the grab is active if the device is
1062  *          a pointer. If this is %NULL then the normal cursors are used for
1063  *          @window and its descendants, and the cursor for @window is used
1064  *          elsewhere.
1065  * @time_: the timestamp of the event which led to this pointer grab. This
1066  *         usually comes from the #GdkEvent struct, though %GDK_CURRENT_TIME
1067  *         can be used if the time isn't known.
1068  *
1069  * Grabs the device so that all events coming from this device are passed to
1070  * this application until the device is ungrabbed with gdk_device_ungrab(),
1071  * or the window becomes unviewable. This overrides any previous grab on the device
1072  * by this client.
1073  *
1074  * Device grabs are used for operations which need complete control over the
1075  * given device events (either pointer or keyboard). For example in GTK+ this
1076  * is used for Drag and Drop operations, popup menus and such.
1077  *
1078  * Note that if the event mask of an X window has selected both button press
1079  * and button release events, then a button press event will cause an automatic
1080  * pointer grab until the button is released. X does this automatically since
1081  * most applications expect to receive button press and release events in pairs.
1082  * It is equivalent to a pointer grab on the window with @owner_events set to
1083  * %TRUE.
1084  *
1085  * If you set up anything at the time you take the grab that needs to be
1086  * cleaned up when the grab ends, you should handle the #GdkEventGrabBroken
1087  * events that are emitted when the grab ends unvoluntarily.
1088  *
1089  * Returns: %GDK_GRAB_SUCCESS if the grab was successful.
1090  *
1091  * Since: 3.0
1092  **/
1093 GdkGrabStatus
1094 gdk_device_grab (GdkDevice        *device,
1095                  GdkWindow        *window,
1096                  GdkGrabOwnership  grab_ownership,
1097                  gboolean          owner_events,
1098                  GdkEventMask      event_mask,
1099                  GdkCursor        *cursor,
1100                  guint32           time_)
1101 {
1102   GdkGrabStatus res;
1103   GdkWindow *native;
1104
1105   g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_GRAB_SUCCESS);
1106   g_return_val_if_fail (GDK_IS_WINDOW (window), GDK_GRAB_SUCCESS);
1107
1108   if (_gdk_native_windows)
1109     native = window;
1110   else
1111     native = gdk_window_get_toplevel (window);
1112
1113   while (native->window_type == GDK_WINDOW_OFFSCREEN)
1114     {
1115       native = gdk_offscreen_window_get_embedder (native);
1116
1117       if (native == NULL ||
1118           (!_gdk_window_has_impl (native) &&
1119            !gdk_window_is_viewable (native)))
1120         return GDK_GRAB_NOT_VIEWABLE;
1121
1122       native = gdk_window_get_toplevel (native);
1123     }
1124
1125   if (native == NULL || GDK_WINDOW_DESTROYED (native))
1126     return GDK_GRAB_NOT_VIEWABLE;
1127
1128   res = GDK_DEVICE_GET_CLASS (device)->grab (device,
1129                                              native,
1130                                              owner_events,
1131                                              get_native_grab_event_mask (event_mask),
1132                                              NULL,
1133                                              cursor,
1134                                              time_);
1135
1136   if (res == GDK_GRAB_SUCCESS)
1137     {
1138       GdkDisplay *display;
1139       gulong serial;
1140
1141       display = gdk_window_get_display (window);
1142       serial = _gdk_display_get_next_serial (display);
1143
1144       _gdk_display_add_device_grab (display,
1145                                     device,
1146                                     window,
1147                                     native,
1148                                     grab_ownership,
1149                                     owner_events,
1150                                     event_mask,
1151                                     serial,
1152                                     time_,
1153                                     FALSE);
1154     }
1155
1156   return res;
1157 }
1158
1159 /**
1160  * gdk_device_ungrab:
1161  * @device: a #GdkDevice
1162  * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
1163  *
1164  * Release any grab on @device.
1165  *
1166  * Since: 3.0
1167  */
1168 void
1169 gdk_device_ungrab (GdkDevice  *device,
1170                    guint32     time_)
1171 {
1172   g_return_if_fail (GDK_IS_DEVICE (device));
1173
1174   GDK_DEVICE_GET_CLASS (device)->ungrab (device, time_);
1175 }
1176
1177 /**
1178  * gdk_device_warp:
1179  * @device: the device to warp.
1180  * @screen: the screen to warp @device to.
1181  * @x: the X coordinate of the destination.
1182  * @y: the Y coordinate of the destination.
1183  *
1184  * Warps @device in @display to the point @x,@y on
1185  * the screen @screen, unless the device is confined
1186  * to a window by a grab, in which case it will be moved
1187  * as far as allowed by the grab. Warping the pointer
1188  * creates events as if the user had moved the mouse
1189  * instantaneously to the destination.
1190  *
1191  * Note that the pointer should normally be under the
1192  * control of the user. This function was added to cover
1193  * some rare use cases like keyboard navigation support
1194  * for the color picker in the #GtkColorSelectionDialog.
1195  *
1196  * Since: 3.0
1197  **/
1198 void
1199 gdk_device_warp (GdkDevice  *device,
1200                  GdkScreen  *screen,
1201                  gint        x,
1202                  gint        y)
1203 {
1204   g_return_if_fail (GDK_IS_DEVICE (device));
1205   g_return_if_fail (GDK_IS_SCREEN (screen));
1206   g_return_if_fail (gdk_device_get_display (device) == gdk_screen_get_display (screen));
1207
1208   GDK_DEVICE_GET_CLASS (device)->warp (device, screen, x, y);
1209 }
1210
1211 /* Private API */
1212 void
1213 _gdk_device_reset_axes (GdkDevice *device)
1214 {
1215   gint i;
1216
1217   for (i = device->axes->len - 1; i >= 0; i--)
1218     g_array_remove_index (device->axes, i);
1219
1220   g_object_notify (G_OBJECT (device), "n-axes");
1221 }
1222
1223 guint
1224 _gdk_device_add_axis (GdkDevice   *device,
1225                       GdkAtom      label_atom,
1226                       GdkAxisUse   use,
1227                       gdouble      min_value,
1228                       gdouble      max_value,
1229                       gdouble      resolution)
1230 {
1231   GdkAxisInfo axis_info;
1232   guint pos;
1233
1234   axis_info.use = use;
1235   axis_info.label = label_atom;
1236   axis_info.min_value = min_value;
1237   axis_info.max_value = max_value;
1238   axis_info.resolution = resolution;
1239
1240   switch (use)
1241     {
1242     case GDK_AXIS_X:
1243     case GDK_AXIS_Y:
1244       axis_info.min_axis = 0;
1245       axis_info.max_axis = 0;
1246       break;
1247     case GDK_AXIS_XTILT:
1248     case GDK_AXIS_YTILT:
1249       axis_info.min_axis = -1;
1250       axis_info.max_axis = 1;
1251       break;
1252     default:
1253       axis_info.min_axis = 0;
1254       axis_info.max_axis = 1;
1255       break;
1256     }
1257
1258   device->axes = g_array_append_val (device->axes, axis_info);
1259   pos = device->axes->len - 1;
1260
1261   g_object_notify (G_OBJECT (device), "n-axes");
1262
1263   return pos;
1264 }
1265
1266 void
1267 _gdk_device_set_keys (GdkDevice *device,
1268                       guint      num_keys)
1269 {
1270   if (device->keys)
1271     g_free (device->keys);
1272
1273   device->num_keys = num_keys;
1274   device->keys = g_new0 (GdkDeviceKey, num_keys);
1275 }
1276
1277 static GdkAxisInfo *
1278 find_axis_info (GArray     *array,
1279                 GdkAxisUse  use)
1280 {
1281   GdkAxisInfo *info;
1282   gint i;
1283
1284   for (i = 0; i < GDK_AXIS_LAST; i++)
1285     {
1286       info = &g_array_index (array, GdkAxisInfo, i);
1287
1288       if (info->use == use)
1289         return info;
1290     }
1291
1292   return NULL;
1293 }
1294
1295 GdkAxisUse
1296 _gdk_device_get_axis_use (GdkDevice *device,
1297                           guint      index_)
1298 {
1299   GdkAxisInfo info;
1300
1301   info = g_array_index (device->axes, GdkAxisInfo, index_);
1302   return info.use;
1303 }
1304
1305 gboolean
1306 _gdk_device_translate_window_coord (GdkDevice *device,
1307                                     GdkWindow *window,
1308                                     guint      index_,
1309                                     gdouble    value,
1310                                     gdouble   *axis_value)
1311 {
1312   GdkAxisInfo axis_info;
1313   GdkAxisInfo *axis_info_x, *axis_info_y;
1314   gdouble device_width, device_height;
1315   gdouble x_offset, y_offset;
1316   gdouble x_scale, y_scale;
1317   gdouble x_min, y_min;
1318   gdouble x_resolution, y_resolution;
1319   gdouble device_aspect;
1320   gint window_width, window_height;
1321
1322   if (index_ >= device->axes->len)
1323     return FALSE;
1324
1325   axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
1326
1327   if (axis_info.use != GDK_AXIS_X &&
1328       axis_info.use != GDK_AXIS_Y)
1329     return FALSE;
1330
1331   if (axis_info.use == GDK_AXIS_X)
1332     {
1333       axis_info_x = &axis_info;
1334       axis_info_y = find_axis_info (device->axes, GDK_AXIS_Y);
1335     }
1336   else
1337     {
1338       axis_info_x = find_axis_info (device->axes, GDK_AXIS_X);
1339       axis_info_y = &axis_info;
1340     }
1341
1342   device_width = axis_info_x->max_value - axis_info_x->min_value;
1343   device_height = axis_info_y->max_value - axis_info_y->min_value;
1344
1345   if (device_width > 0)
1346     x_min = axis_info_x->min_value;
1347   else
1348     {
1349       device_width = gdk_screen_get_width (gdk_window_get_screen (window));
1350       x_min = 0;
1351     }
1352
1353   if (device_height > 0)
1354     y_min = axis_info_y->min_value;
1355   else
1356     {
1357       device_height = gdk_screen_get_height (gdk_window_get_screen (window));
1358       y_min = 0;
1359     }
1360
1361   window_width = gdk_window_get_width (window);
1362   window_height = gdk_window_get_height (window);
1363
1364   x_resolution = axis_info_x->resolution;
1365   y_resolution = axis_info_y->resolution;
1366
1367   /*
1368    * Some drivers incorrectly report the resolution of the device
1369    * as zero (in partiular linuxwacom < 0.5.3 with usb tablets).
1370    * This causes the device_aspect to become NaN and totally
1371    * breaks windowed mode.  If this is the case, the best we can
1372    * do is to assume the resolution is non-zero is equal in both
1373    * directions (which is true for many devices).  The absolute
1374    * value of the resolution doesn't matter since we only use the
1375    * ratio.
1376    */
1377   if (x_resolution == 0 || y_resolution == 0)
1378     {
1379       x_resolution = 1;
1380       y_resolution = 1;
1381     }
1382
1383   device_aspect = (device_height * y_resolution) /
1384     (device_width * x_resolution);
1385
1386   if (device_aspect * window_width >= window_height)
1387     {
1388       /* device taller than window */
1389       x_scale = window_width / device_width;
1390       y_scale = (x_scale * x_resolution) / y_resolution;
1391
1392       x_offset = 0;
1393       y_offset = - (device_height * y_scale - window_height) / 2;
1394     }
1395   else
1396     {
1397       /* window taller than device */
1398       y_scale = window_height / device_height;
1399       x_scale = (y_scale * y_resolution) / x_resolution;
1400
1401       y_offset = 0;
1402       x_offset = - (device_width * x_scale - window_width) / 2;
1403     }
1404
1405   if (axis_value)
1406     {
1407       if (axis_info.use == GDK_AXIS_X)
1408         *axis_value = x_offset + x_scale * (value - x_min);
1409       else
1410         *axis_value = y_offset + y_scale * (value - y_min);
1411     }
1412
1413   return TRUE;
1414 }
1415
1416 gboolean
1417 _gdk_device_translate_screen_coord (GdkDevice *device,
1418                                     GdkWindow *window,
1419                                     gint       window_root_x,
1420                                     gint       window_root_y,
1421                                     guint      index_,
1422                                     gdouble    value,
1423                                     gdouble   *axis_value)
1424 {
1425   GdkAxisInfo axis_info;
1426   gdouble axis_width, scale, offset;
1427
1428   if (device->mode != GDK_MODE_SCREEN)
1429     return FALSE;
1430
1431   if (index_ >= device->axes->len)
1432     return FALSE;
1433
1434   axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
1435
1436   if (axis_info.use != GDK_AXIS_X &&
1437       axis_info.use != GDK_AXIS_Y)
1438     return FALSE;
1439
1440   axis_width = axis_info.max_value - axis_info.min_value;
1441
1442   if (axis_info.use == GDK_AXIS_X)
1443     {
1444       if (axis_width > 0)
1445         scale = gdk_screen_get_width (gdk_window_get_screen (window)) / axis_width;
1446       else
1447         scale = 1;
1448
1449       offset = - window_root_x - window->abs_x;
1450     }
1451   else
1452     {
1453       if (axis_width > 0)
1454         scale = gdk_screen_get_height (gdk_window_get_screen (window)) / axis_width;
1455       else
1456         scale = 1;
1457
1458       offset = - window_root_y - window->abs_y;
1459     }
1460
1461   if (axis_value)
1462     *axis_value = offset + scale * (value - axis_info.min_value);
1463
1464   return TRUE;
1465 }
1466
1467 gboolean
1468 _gdk_device_translate_axis (GdkDevice *device,
1469                             guint      index_,
1470                             gdouble    value,
1471                             gdouble   *axis_value)
1472 {
1473   GdkAxisInfo axis_info;
1474   gdouble axis_width, out;
1475
1476   if (index_ >= device->axes->len)
1477     return FALSE;
1478
1479   axis_info = g_array_index (device->axes, GdkAxisInfo, index_);
1480
1481   if (axis_info.use == GDK_AXIS_X ||
1482       axis_info.use == GDK_AXIS_Y)
1483     return FALSE;
1484
1485   axis_width = axis_info.max_value - axis_info.min_value;
1486   out = (axis_info.max_axis * (value - axis_info.min_value) +
1487          axis_info.min_axis * (axis_info.max_value - value)) / axis_width;
1488
1489   if (axis_value)
1490     *axis_value = out;
1491
1492   return TRUE;
1493 }
1494
1495 gboolean
1496 _gdk_device_query_state (GdkDevice        *device,
1497                          GdkWindow        *window,
1498                          GdkWindow       **root_window,
1499                          GdkWindow       **child_window,
1500                          gint             *root_x,
1501                          gint             *root_y,
1502                          gint             *win_x,
1503                          gint             *win_y,
1504                          GdkModifierType  *mask)
1505 {
1506   return GDK_DEVICE_GET_CLASS (device)->query_state (device,
1507                                                      window,
1508                                                      root_window,
1509                                                      child_window,
1510                                                      root_x,
1511                                                      root_y,
1512                                                      win_x,
1513                                                      win_y,
1514                                                      mask);
1515 }
1516
1517 GdkWindow *
1518 _gdk_device_window_at_position (GdkDevice        *device,
1519                                 gint             *win_x,
1520                                 gint             *win_y,
1521                                 GdkModifierType  *mask,
1522                                 gboolean          get_toplevel)
1523 {
1524   return GDK_DEVICE_GET_CLASS (device)->window_at_position (device,
1525                                                             win_x,
1526                                                             win_y,
1527                                                             mask,
1528                                                             get_toplevel);
1529 }