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