]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkdevice-xi2.c
bc6261be6f9f6f2de295204a280c50ab906f4435
[~andy/gtk] / gdk / x11 / gdkdevice-xi2.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 "gdkx11device-xi2.h"
23 #include "gdkdeviceprivate.h"
24
25 #include "gdkintl.h"
26 #include "gdkasync.h"
27 #include "gdkprivate-x11.h"
28
29 #ifdef XINPUT_2
30
31 #include <stdlib.h>
32 #include <X11/Xlib.h>
33 #include <X11/Xutil.h>
34 #include <X11/extensions/XInput2.h>
35
36 #endif
37
38 struct _GdkX11DeviceXI2
39 {
40   GdkDevice parent_instance;
41
42   gint device_id;
43 };
44
45 struct _GdkX11DeviceXI2Class
46 {
47   GdkDeviceClass parent_class;
48 };
49
50 G_DEFINE_TYPE (GdkX11DeviceXI2, gdk_x11_device_xi2, GDK_TYPE_DEVICE)
51
52 #ifdef XINPUT_2
53
54 static void gdk_x11_device_xi2_get_property (GObject      *object,
55                                              guint         prop_id,
56                                              GValue       *value,
57                                              GParamSpec   *pspec);
58 static void gdk_x11_device_xi2_set_property (GObject      *object,
59                                              guint         prop_id,
60                                              const GValue *value,
61                                              GParamSpec   *pspec);
62
63 static void gdk_x11_device_xi2_get_state (GdkDevice       *device,
64                                           GdkWindow       *window,
65                                           gdouble         *axes,
66                                           GdkModifierType *mask);
67 static void gdk_x11_device_xi2_set_window_cursor (GdkDevice *device,
68                                                   GdkWindow *window,
69                                                   GdkCursor *cursor);
70 static void gdk_x11_device_xi2_warp (GdkDevice *device,
71                                      GdkScreen *screen,
72                                      gint       x,
73                                      gint       y);
74 static gboolean gdk_x11_device_xi2_query_state (GdkDevice        *device,
75                                                 GdkWindow        *window,
76                                                 GdkWindow       **root_window,
77                                                 GdkWindow       **child_window,
78                                                 gint             *root_x,
79                                                 gint             *root_y,
80                                                 gint             *win_x,
81                                                 gint             *win_y,
82                                                 GdkModifierType  *mask);
83
84 static GdkGrabStatus gdk_x11_device_xi2_grab   (GdkDevice     *device,
85                                                 GdkWindow     *window,
86                                                 gboolean       owner_events,
87                                                 GdkEventMask   event_mask,
88                                                 GdkWindow     *confine_to,
89                                                 GdkCursor     *cursor,
90                                                 guint32        time_);
91 static void          gdk_x11_device_xi2_ungrab (GdkDevice     *device,
92                                                 guint32        time_);
93
94 static GdkWindow * gdk_x11_device_xi2_window_at_position (GdkDevice       *device,
95                                                           gint            *win_x,
96                                                           gint            *win_y,
97                                                           GdkModifierType *mask,
98                                                           gboolean         get_toplevel);
99 static void  gdk_x11_device_xi2_select_window_events (GdkDevice    *device,
100                                                       GdkWindow    *window,
101                                                       GdkEventMask  event_mask);
102
103
104 enum {
105   PROP_0,
106   PROP_DEVICE_ID
107 };
108
109 static void
110 gdk_x11_device_xi2_class_init (GdkX11DeviceXI2Class *klass)
111 {
112   GObjectClass *object_class = G_OBJECT_CLASS (klass);
113   GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
114
115   object_class->get_property = gdk_x11_device_xi2_get_property;
116   object_class->set_property = gdk_x11_device_xi2_set_property;
117
118   device_class->get_state = gdk_x11_device_xi2_get_state;
119   device_class->set_window_cursor = gdk_x11_device_xi2_set_window_cursor;
120   device_class->warp = gdk_x11_device_xi2_warp;
121   device_class->query_state = gdk_x11_device_xi2_query_state;
122   device_class->grab = gdk_x11_device_xi2_grab;
123   device_class->ungrab = gdk_x11_device_xi2_ungrab;
124   device_class->window_at_position = gdk_x11_device_xi2_window_at_position;
125   device_class->select_window_events = gdk_x11_device_xi2_select_window_events;
126
127   g_object_class_install_property (object_class,
128                                    PROP_DEVICE_ID,
129                                    g_param_spec_int ("device-id",
130                                                      P_("Device ID"),
131                                                      P_("Device identifier"),
132                                                      0, G_MAXINT, 0,
133                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
134 }
135
136 static void
137 gdk_x11_device_xi2_init (GdkX11DeviceXI2 *device)
138 {
139 }
140
141 static void
142 gdk_x11_device_xi2_get_property (GObject    *object,
143                                  guint       prop_id,
144                                  GValue     *value,
145                                  GParamSpec *pspec)
146 {
147   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (object);
148
149   switch (prop_id)
150     {
151     case PROP_DEVICE_ID:
152       g_value_set_int (value, device_xi2->device_id);
153       break;
154     default:
155       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
156       break;
157     }
158 }
159
160 static void
161 gdk_x11_device_xi2_set_property (GObject      *object,
162                                  guint         prop_id,
163                                  const GValue *value,
164                                  GParamSpec   *pspec)
165 {
166   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (object);
167
168   switch (prop_id)
169     {
170     case PROP_DEVICE_ID:
171       device_xi2->device_id = g_value_get_int (value);
172       break;
173     default:
174       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
175       break;
176     }
177 }
178
179 static void
180 gdk_x11_device_xi2_get_state (GdkDevice       *device,
181                               GdkWindow       *window,
182                               gdouble         *axes,
183                               GdkModifierType *mask)
184 {
185   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
186
187   if (axes)
188     {
189       GdkDisplay *display;
190       XIDeviceInfo *info;
191       gint i, j, ndevices;
192
193       display = gdk_device_get_display (device);
194
195       gdk_x11_display_error_trap_push (display);
196       info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display),
197                             device_xi2->device_id, &ndevices);
198       gdk_x11_display_error_trap_pop_ignored (display);
199
200       for (i = 0, j = 0; info && i < info->num_classes; i++)
201         {
202           XIAnyClassInfo *class_info = info->classes[i];
203           GdkAxisUse use;
204           gdouble value;
205
206           if (class_info->type != XIValuatorClass)
207             continue;
208
209           value = ((XIValuatorClassInfo *) class_info)->value;
210           use = gdk_device_get_axis_use (device, j);
211
212           switch (use)
213             {
214             case GDK_AXIS_X:
215             case GDK_AXIS_Y:
216             case GDK_AXIS_IGNORE:
217               if (gdk_device_get_mode (device) == GDK_MODE_WINDOW)
218                 _gdk_device_translate_window_coord (device, window, j, value, &axes[j]);
219               else
220                 {
221                   gint root_x, root_y;
222
223                   /* FIXME: Maybe root coords chaching should happen here */
224                   gdk_window_get_origin (window, &root_x, &root_y);
225                   _gdk_device_translate_screen_coord (device, window,
226                                                       root_x, root_y,
227                                                       j, value,
228                                                       &axes[j]);
229                 }
230               break;
231             default:
232               _gdk_device_translate_axis (device, j, value, &axes[j]);
233               break;
234             }
235
236           j++;
237         }
238
239       if (info)
240         XIFreeDeviceInfo (info);
241     }
242
243   if (mask)
244     gdk_x11_device_xi2_query_state (device, window,
245                                     NULL, NULL,
246                                     NULL, NULL,
247                                     NULL, NULL,
248                                     mask);
249 }
250
251 static void
252 gdk_x11_device_xi2_set_window_cursor (GdkDevice *device,
253                                       GdkWindow *window,
254                                       GdkCursor *cursor)
255 {
256   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
257
258   /* Non-master devices don't have a cursor */
259   if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
260     return;
261
262   if (cursor)
263     XIDefineCursor (GDK_WINDOW_XDISPLAY (window),
264                     device_xi2->device_id,
265                     GDK_WINDOW_XID (window),
266                     gdk_x11_cursor_get_xcursor (cursor));
267   else
268     XIUndefineCursor (GDK_WINDOW_XDISPLAY (window),
269                       device_xi2->device_id,
270                       GDK_WINDOW_XID (window));
271 }
272
273 static void
274 gdk_x11_device_xi2_warp (GdkDevice *device,
275                          GdkScreen *screen,
276                          gint       x,
277                          gint       y)
278 {
279   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
280   Window dest;
281
282   dest = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
283
284   XIWarpPointer (GDK_SCREEN_XDISPLAY (screen),
285                  device_xi2->device_id,
286                  None, dest,
287                  0, 0, 0, 0, x, y);
288 }
289
290 static gboolean
291 gdk_x11_device_xi2_query_state (GdkDevice        *device,
292                                 GdkWindow        *window,
293                                 GdkWindow       **root_window,
294                                 GdkWindow       **child_window,
295                                 gint             *root_x,
296                                 gint             *root_y,
297                                 gint             *win_x,
298                                 gint             *win_y,
299                                 GdkModifierType  *mask)
300 {
301   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
302   GdkDisplay *display;
303   GdkScreen *default_screen;
304   Window xroot_window, xchild_window;
305   gdouble xroot_x, xroot_y, xwin_x, xwin_y;
306   XIButtonState button_state;
307   XIModifierState mod_state;
308   XIGroupState group_state;
309
310   if (!window || GDK_WINDOW_DESTROYED (window))
311     return FALSE;
312
313   display = gdk_window_get_display (window);
314   default_screen = gdk_display_get_default_screen (display);
315
316   if (G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
317     {
318       if (!XIQueryPointer (GDK_WINDOW_XDISPLAY (window),
319                            device_xi2->device_id,
320                            GDK_WINDOW_XID (window),
321                            &xroot_window,
322                            &xchild_window,
323                            &xroot_x, &xroot_y,
324                            &xwin_x, &xwin_y,
325                            &button_state,
326                            &mod_state,
327                            &group_state))
328         return FALSE;
329     }
330   else
331     {
332       XSetWindowAttributes attributes;
333       Display *xdisplay;
334       Window xwindow, w;
335
336       /* FIXME: untrusted clients not multidevice-safe */
337       xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
338       xwindow = GDK_SCREEN_XROOTWIN (default_screen);
339
340       w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
341                          CopyFromParent, InputOnly, CopyFromParent,
342                          0, &attributes);
343       XIQueryPointer (xdisplay, device_xi2->device_id,
344                       w,
345                       &xroot_window,
346                       &xchild_window,
347                       &xroot_x, &xroot_y,
348                       &xwin_x, &xwin_y,
349                       &button_state,
350                       &mod_state,
351                       &group_state);
352       XDestroyWindow (xdisplay, w);
353     }
354
355   if (root_window)
356     *root_window = gdk_x11_window_lookup_for_display (display, xroot_window);
357
358   if (child_window)
359     *child_window = gdk_x11_window_lookup_for_display (display, xchild_window);
360
361   if (root_x)
362     *root_x = (gint) xroot_x;
363
364   if (root_y)
365     *root_y = (gint) xroot_y;
366
367   if (win_x)
368     *win_x = (gint) xwin_x;
369
370   if (win_y)
371     *win_y = (gint) xwin_y;
372
373   if (mask)
374     *mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
375
376   free (button_state.mask);
377
378   return TRUE;
379 }
380
381 static GdkGrabStatus
382 gdk_x11_device_xi2_grab (GdkDevice    *device,
383                          GdkWindow    *window,
384                          gboolean      owner_events,
385                          GdkEventMask  event_mask,
386                          GdkWindow    *confine_to,
387                          GdkCursor    *cursor,
388                          guint32       time_)
389 {
390   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
391   GdkDisplay *display;
392   XIEventMask mask;
393   Window xwindow;
394   Cursor xcursor;
395   gint status;
396
397   display = gdk_device_get_display (device);
398
399   /* FIXME: confine_to is actually unused */
400
401   xwindow = GDK_WINDOW_XID (window);
402
403   if (!cursor)
404     xcursor = None;
405   else
406     {
407       _gdk_x11_cursor_update_theme (cursor);
408       xcursor = gdk_x11_cursor_get_xcursor (cursor);
409     }
410
411   mask.deviceid = device_xi2->device_id;
412   mask.mask = _gdk_x11_device_xi2_translate_event_mask (event_mask, &mask.mask_len);
413
414 #ifdef G_ENABLE_DEBUG
415   if (_gdk_debug_flags & GDK_DEBUG_NOGRABS)
416     status = GrabSuccess;
417   else
418 #endif
419   status = XIGrabDevice (GDK_DISPLAY_XDISPLAY (display),
420                          device_xi2->device_id,
421                          xwindow,
422                          time_,
423                          xcursor,
424                          GrabModeAsync, GrabModeAsync,
425                          owner_events,
426                          &mask);
427
428   g_free (mask.mask);
429
430   _gdk_x11_display_update_grab_info (display, device, status);
431
432   return _gdk_x11_convert_grab_status (status);
433 }
434
435 static void
436 gdk_x11_device_xi2_ungrab (GdkDevice *device,
437                            guint32    time_)
438 {
439   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
440   GdkDisplay *display;
441   gulong serial;
442
443   display = gdk_device_get_display (device);
444   serial = NextRequest (GDK_DISPLAY_XDISPLAY (display));
445
446   XIUngrabDevice (GDK_DISPLAY_XDISPLAY (display), device_xi2->device_id, time_);
447
448   _gdk_x11_display_update_grab_info_ungrab (display, device, time_, serial);
449 }
450
451 static GdkWindow *
452 gdk_x11_device_xi2_window_at_position (GdkDevice       *device,
453                                        gint            *win_x,
454                                        gint            *win_y,
455                                        GdkModifierType *mask,
456                                        gboolean         get_toplevel)
457 {
458   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
459   GdkDisplay *display;
460   GdkScreen *screen;
461   Display *xdisplay;
462   GdkWindow *window;
463   Window xwindow, root, child, last = None;
464   gdouble xroot_x, xroot_y, xwin_x, xwin_y;
465   XIButtonState button_state = { 0 };
466   XIModifierState mod_state;
467   XIGroupState group_state;
468
469   display = gdk_device_get_display (device);
470   screen = gdk_display_get_default_screen (display);
471
472   /* This function really only works if the mouse pointer is held still
473    * during its operation. If it moves from one leaf window to another
474    * than we'll end up with inaccurate values for win_x, win_y
475    * and the result.
476    */
477   gdk_x11_display_grab (display);
478
479   xdisplay = GDK_SCREEN_XDISPLAY (screen);
480   xwindow = GDK_SCREEN_XROOTWIN (screen);
481
482   if (G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
483     {
484       XIQueryPointer (xdisplay,
485                       device_xi2->device_id,
486                       xwindow,
487                       &root, &child,
488                       &xroot_x, &xroot_y,
489                       &xwin_x, &xwin_y,
490                       &button_state,
491                       &mod_state,
492                       &group_state);
493
494       if (root == xwindow)
495         xwindow = child;
496       else
497         xwindow = root;
498     }
499   else
500     {
501       gint i, screens, width, height;
502       GList *toplevels, *list;
503       Window pointer_window, root, child;
504
505       /* FIXME: untrusted clients case not multidevice-safe */
506       pointer_window = None;
507       screens = gdk_display_get_n_screens (display);
508
509       for (i = 0; i < screens; ++i)
510         {
511           screen = gdk_display_get_screen (display, i);
512           toplevels = gdk_screen_get_toplevel_windows (screen);
513           for (list = toplevels; list != NULL; list = g_list_next (list))
514             {
515               window = GDK_WINDOW (list->data);
516               xwindow = GDK_WINDOW_XID (window);
517
518               /* Free previous button mask, if any */
519               g_free (button_state.mask);
520
521               gdk_x11_display_error_trap_push (display);
522               XIQueryPointer (xdisplay,
523                               device_xi2->device_id,
524                               xwindow,
525                               &root, &child,
526                               &xroot_x, &xroot_y,
527                               &xwin_x, &xwin_y,
528                               &button_state,
529                               &mod_state,
530                               &group_state);
531               if (gdk_x11_display_error_trap_pop (display))
532                 continue;
533               if (child != None)
534                 {
535                   pointer_window = child;
536                   break;
537                 }
538               gdk_window_get_geometry (window, NULL, NULL, &width, &height);
539               if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height)
540                 {
541                   /* A childless toplevel, or below another window? */
542                   XSetWindowAttributes attributes;
543                   Window w;
544
545                   free (button_state.mask);
546
547                   w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0,
548                                      CopyFromParent, InputOnly, CopyFromParent,
549                                      0, &attributes);
550                   XMapWindow (xdisplay, w);
551                   XIQueryPointer (xdisplay,
552                                   device_xi2->device_id,
553                                   xwindow,
554                                   &root, &child,
555                                   &xroot_x, &xroot_y,
556                                   &xwin_x, &xwin_y,
557                                   &button_state,
558                                   &mod_state,
559                                   &group_state);
560                   XDestroyWindow (xdisplay, w);
561                   if (child == w)
562                     {
563                       pointer_window = xwindow;
564                       break;
565                     }
566                 }
567             }
568
569           g_list_free (toplevels);
570           if (pointer_window != None)
571             break;
572         }
573
574       xwindow = pointer_window;
575     }
576
577   while (xwindow)
578     {
579       last = xwindow;
580       free (button_state.mask);
581
582       gdk_x11_display_error_trap_push (display);
583       XIQueryPointer (xdisplay,
584                       device_xi2->device_id,
585                       xwindow,
586                       &root, &xwindow,
587                       &xroot_x, &xroot_y,
588                       &xwin_x, &xwin_y,
589                       &button_state,
590                       &mod_state,
591                       &group_state);
592       if (gdk_x11_display_error_trap_pop (display))
593         break;
594
595       if (get_toplevel && last != root &&
596           (window = gdk_x11_window_lookup_for_display (display, last)) != NULL &&
597           GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
598         {
599           xwindow = last;
600           break;
601         }
602     }
603
604   gdk_x11_display_ungrab (display);
605
606   window = gdk_x11_window_lookup_for_display (display, last);
607
608   if (win_x)
609     *win_x = (window) ? (gint) xwin_x : -1;
610
611   if (win_y)
612     *win_y = (window) ? (gint) xwin_y : -1;
613
614   if (mask)
615     *mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
616
617   free (button_state.mask);
618
619   return window;
620 }
621
622 static void
623 gdk_x11_device_xi2_select_window_events (GdkDevice    *device,
624                                          GdkWindow    *window,
625                                          GdkEventMask  event_mask)
626 {
627   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
628   XIEventMask evmask;
629
630   evmask.deviceid = device_xi2->device_id;
631   evmask.mask = _gdk_x11_device_xi2_translate_event_mask (event_mask, &evmask.mask_len);
632
633   XISelectEvents (GDK_WINDOW_XDISPLAY (window),
634                   GDK_WINDOW_XID (window),
635                   &evmask, 1);
636
637   g_free (evmask.mask);
638 }
639
640 guchar *
641 _gdk_x11_device_xi2_translate_event_mask (GdkEventMask  event_mask,
642                                           gint         *len)
643 {
644   guchar *mask;
645
646   *len = XIMaskLen (XI_LASTEVENT);
647   mask = g_new0 (guchar, *len);
648
649   if (event_mask & GDK_POINTER_MOTION_MASK ||
650       event_mask & GDK_POINTER_MOTION_HINT_MASK)
651     XISetMask (mask, XI_Motion);
652
653   if (event_mask & GDK_BUTTON_MOTION_MASK ||
654       event_mask & GDK_BUTTON1_MOTION_MASK ||
655       event_mask & GDK_BUTTON2_MOTION_MASK ||
656       event_mask & GDK_BUTTON3_MOTION_MASK)
657     {
658       XISetMask (mask, XI_ButtonPress);
659       XISetMask (mask, XI_ButtonRelease);
660       XISetMask (mask, XI_Motion);
661     }
662
663   if (event_mask & GDK_SCROLL_MASK)
664     {
665       XISetMask (mask, XI_ButtonPress);
666       XISetMask (mask, XI_ButtonRelease);
667     }
668
669   if (event_mask & GDK_BUTTON_PRESS_MASK)
670     XISetMask (mask, XI_ButtonPress);
671
672   if (event_mask & GDK_BUTTON_RELEASE_MASK)
673     XISetMask (mask, XI_ButtonRelease);
674
675   if (event_mask & GDK_KEY_PRESS_MASK)
676     XISetMask (mask, XI_KeyPress);
677
678   if (event_mask & GDK_KEY_RELEASE_MASK)
679     XISetMask (mask, XI_KeyRelease);
680
681   if (event_mask & GDK_ENTER_NOTIFY_MASK)
682     XISetMask (mask, XI_Enter);
683
684   if (event_mask & GDK_LEAVE_NOTIFY_MASK)
685     XISetMask (mask, XI_Leave);
686
687   if (event_mask & GDK_FOCUS_CHANGE_MASK)
688     {
689       XISetMask (mask, XI_FocusIn);
690       XISetMask (mask, XI_FocusOut);
691     }
692
693   return mask;
694 }
695
696 guint
697 _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
698                                      XIButtonState   *buttons_state,
699                                      XIGroupState    *group_state)
700 {
701   guint state = 0;
702
703   if (mods_state)
704     state = (guint) mods_state->base | mods_state->latched | mods_state->locked;
705
706   if (buttons_state)
707     {
708       gint len, i;
709
710       /* We're only interested in the first 5 buttons */
711       len = MIN (5, buttons_state->mask_len * 8);
712
713       for (i = 0; i < len; i++)
714         {
715           if (!XIMaskIsSet (buttons_state->mask, i))
716             continue;
717
718           switch (i)
719             {
720             case 1:
721               state |= GDK_BUTTON1_MASK;
722               break;
723             case 2:
724               state |= GDK_BUTTON2_MASK;
725               break;
726             case 3:
727               state |= GDK_BUTTON3_MASK;
728               break;
729             case 4:
730               state |= GDK_BUTTON4_MASK;
731               break;
732             case 5:
733               state |= GDK_BUTTON5_MASK;
734               break;
735             default:
736               break;
737             }
738         }
739     }
740
741   if (group_state)
742     {
743       gint group;
744
745       group = group_state->base | group_state->latched | group_state->locked;
746
747       /* FIXME: do we need the XKB complications for this ? */
748       group = CLAMP(group, 0, 3);
749
750       state |= group << 13;
751     }
752
753   return state;
754 }
755
756 gint
757 _gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
758 {
759   g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), 0);
760
761   return device->device_id;
762 }
763
764 #else /* XINPUT_2 */
765
766 static void
767 gdk_x11_device_xi2_class_init (GdkX11DeviceXI2Class *klass)
768 {
769 }
770
771 static void
772 gdk_x11_device_xi2_init (GdkX11DeviceXI2 *device)
773 {
774 }
775
776 #endif /* XINPUT_2 */