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