]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkdevice-xi2.c
gdk: remove the GET_EFFECTIVE_KEYMAP() stuff from gdkkeys-x11.c
[~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       info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display),
196                             device_xi2->device_id, &ndevices);
197
198       for (i = 0, j = 0; 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       XIFreeDeviceInfo (info);
238     }
239
240   if (mask)
241     gdk_x11_device_xi2_query_state (device, window,
242                                     NULL, NULL,
243                                     NULL, NULL,
244                                     NULL, NULL,
245                                     mask);
246 }
247
248 static void
249 gdk_x11_device_xi2_set_window_cursor (GdkDevice *device,
250                                       GdkWindow *window,
251                                       GdkCursor *cursor)
252 {
253   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
254
255   /* Non-master devices don't have a cursor */
256   if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
257     return;
258
259   if (cursor)
260     XIDefineCursor (GDK_WINDOW_XDISPLAY (window),
261                     device_xi2->device_id,
262                     GDK_WINDOW_XID (window),
263                     gdk_x11_cursor_get_xcursor (cursor));
264   else
265     XIUndefineCursor (GDK_WINDOW_XDISPLAY (window),
266                       device_xi2->device_id,
267                       GDK_WINDOW_XID (window));
268 }
269
270 static void
271 gdk_x11_device_xi2_warp (GdkDevice *device,
272                          GdkScreen *screen,
273                          gint       x,
274                          gint       y)
275 {
276   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
277   Window dest;
278
279   dest = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
280
281   XIWarpPointer (GDK_SCREEN_XDISPLAY (screen),
282                  device_xi2->device_id,
283                  None, dest,
284                  0, 0, 0, 0, x, y);
285 }
286
287 static gboolean
288 gdk_x11_device_xi2_query_state (GdkDevice        *device,
289                                 GdkWindow        *window,
290                                 GdkWindow       **root_window,
291                                 GdkWindow       **child_window,
292                                 gint             *root_x,
293                                 gint             *root_y,
294                                 gint             *win_x,
295                                 gint             *win_y,
296                                 GdkModifierType  *mask)
297 {
298   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
299   GdkDisplay *display;
300   GdkScreen *default_screen;
301   Window xroot_window, xchild_window;
302   gdouble xroot_x, xroot_y, xwin_x, xwin_y;
303   XIButtonState button_state;
304   XIModifierState mod_state;
305   XIGroupState group_state;
306
307   if (!window || GDK_WINDOW_DESTROYED (window))
308     return FALSE;
309
310   display = gdk_window_get_display (window);
311   default_screen = gdk_display_get_default_screen (display);
312
313   if (G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
314     {
315       if (!XIQueryPointer (GDK_WINDOW_XDISPLAY (window),
316                            device_xi2->device_id,
317                            GDK_WINDOW_XID (window),
318                            &xroot_window,
319                            &xchild_window,
320                            &xroot_x, &xroot_y,
321                            &xwin_x, &xwin_y,
322                            &button_state,
323                            &mod_state,
324                            &group_state))
325         return FALSE;
326     }
327   else
328     {
329       XSetWindowAttributes attributes;
330       Display *xdisplay;
331       Window xwindow, w;
332
333       /* FIXME: untrusted clients not multidevice-safe */
334       xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
335       xwindow = GDK_SCREEN_XROOTWIN (default_screen);
336
337       w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
338                          CopyFromParent, InputOnly, CopyFromParent,
339                          0, &attributes);
340       XIQueryPointer (xdisplay, device_xi2->device_id,
341                       w,
342                       &xroot_window,
343                       &xchild_window,
344                       &xroot_x, &xroot_y,
345                       &xwin_x, &xwin_y,
346                       &button_state,
347                       &mod_state,
348                       &group_state);
349       XDestroyWindow (xdisplay, w);
350     }
351
352   if (root_window)
353     *root_window = gdk_x11_window_lookup_for_display (display, xroot_window);
354
355   if (child_window)
356     *child_window = gdk_x11_window_lookup_for_display (display, xchild_window);
357
358   if (root_x)
359     *root_x = (gint) xroot_x;
360
361   if (root_y)
362     *root_y = (gint) xroot_y;
363
364   if (win_x)
365     *win_x = (gint) xwin_x;
366
367   if (win_y)
368     *win_y = (gint) xwin_y;
369
370   if (mask)
371     *mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
372
373   free (button_state.mask);
374
375   return TRUE;
376 }
377
378 static GdkGrabStatus
379 gdk_x11_device_xi2_grab (GdkDevice    *device,
380                          GdkWindow    *window,
381                          gboolean      owner_events,
382                          GdkEventMask  event_mask,
383                          GdkWindow    *confine_to,
384                          GdkCursor    *cursor,
385                          guint32       time_)
386 {
387   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
388   GdkDisplay *display;
389   XIEventMask mask;
390   Window xwindow;
391   Cursor xcursor;
392   gint status;
393
394   display = gdk_device_get_display (device);
395
396   /* FIXME: confine_to is actually unused */
397
398   xwindow = GDK_WINDOW_XID (window);
399
400   if (!cursor)
401     xcursor = None;
402   else
403     {
404       _gdk_x11_cursor_update_theme (cursor);
405       xcursor = gdk_x11_cursor_get_xcursor (cursor);
406     }
407
408   mask.deviceid = device_xi2->device_id;
409   mask.mask = _gdk_x11_device_xi2_translate_event_mask (event_mask, &mask.mask_len);
410
411 #ifdef G_ENABLE_DEBUG
412   if (_gdk_debug_flags & GDK_DEBUG_NOGRABS)
413     status = GrabSuccess;
414   else
415 #endif
416   status = XIGrabDevice (GDK_DISPLAY_XDISPLAY (display),
417                          device_xi2->device_id,
418                          xwindow,
419                          time_,
420                          xcursor,
421                          GrabModeAsync, GrabModeAsync,
422                          owner_events,
423                          &mask);
424
425   g_free (mask.mask);
426
427   _gdk_x11_display_update_grab_info (display, device, status);
428
429   return _gdk_x11_convert_grab_status (status);
430 }
431
432 static void
433 gdk_x11_device_xi2_ungrab (GdkDevice *device,
434                            guint32    time_)
435 {
436   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
437   GdkDisplay *display;
438   gulong serial;
439
440   display = gdk_device_get_display (device);
441   serial = NextRequest (GDK_DISPLAY_XDISPLAY (display));
442
443   XIUngrabDevice (GDK_DISPLAY_XDISPLAY (display), device_xi2->device_id, time_);
444
445   _gdk_x11_display_update_grab_info_ungrab (display, device, time_, serial);
446 }
447
448 static GdkWindow *
449 gdk_x11_device_xi2_window_at_position (GdkDevice       *device,
450                                        gint            *win_x,
451                                        gint            *win_y,
452                                        GdkModifierType *mask,
453                                        gboolean         get_toplevel)
454 {
455   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
456   GdkDisplay *display;
457   GdkScreen *screen;
458   Display *xdisplay;
459   GdkWindow *window;
460   Window xwindow, root, child, last = None;
461   gdouble xroot_x, xroot_y, xwin_x, xwin_y;
462   XIButtonState button_state = { 0 };
463   XIModifierState mod_state;
464   XIGroupState group_state;
465
466   display = gdk_device_get_display (device);
467   screen = gdk_display_get_default_screen (display);
468
469   /* This function really only works if the mouse pointer is held still
470    * during its operation. If it moves from one leaf window to another
471    * than we'll end up with inaccurate values for win_x, win_y
472    * and the result.
473    */
474   gdk_x11_display_grab (display);
475
476   xdisplay = GDK_SCREEN_XDISPLAY (screen);
477   xwindow = GDK_SCREEN_XROOTWIN (screen);
478
479   if (G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
480     {
481       XIQueryPointer (xdisplay,
482                       device_xi2->device_id,
483                       xwindow,
484                       &root, &child,
485                       &xroot_x, &xroot_y,
486                       &xwin_x, &xwin_y,
487                       &button_state,
488                       &mod_state,
489                       &group_state);
490
491       if (root == xwindow)
492         xwindow = child;
493       else
494         xwindow = root;
495     }
496   else
497     {
498       gint i, screens, width, height;
499       GList *toplevels, *list;
500       Window pointer_window, root, child;
501
502       /* FIXME: untrusted clients case not multidevice-safe */
503       pointer_window = None;
504       screens = gdk_display_get_n_screens (display);
505
506       for (i = 0; i < screens; ++i)
507         {
508           screen = gdk_display_get_screen (display, i);
509           toplevels = gdk_screen_get_toplevel_windows (screen);
510           for (list = toplevels; list != NULL; list = g_list_next (list))
511             {
512               window = GDK_WINDOW (list->data);
513               xwindow = GDK_WINDOW_XID (window);
514
515               /* Free previous button mask, if any */
516               g_free (button_state.mask);
517
518               gdk_x11_display_error_trap_push (display);
519               XIQueryPointer (xdisplay,
520                               device_xi2->device_id,
521                               xwindow,
522                               &root, &child,
523                               &xroot_x, &xroot_y,
524                               &xwin_x, &xwin_y,
525                               &button_state,
526                               &mod_state,
527                               &group_state);
528               if (gdk_x11_display_error_trap_pop (display))
529                 continue;
530               if (child != None)
531                 {
532                   pointer_window = child;
533                   break;
534                 }
535               gdk_window_get_geometry (window, NULL, NULL, &width, &height);
536               if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height)
537                 {
538                   /* A childless toplevel, or below another window? */
539                   XSetWindowAttributes attributes;
540                   Window w;
541
542                   free (button_state.mask);
543
544                   w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0,
545                                      CopyFromParent, InputOnly, CopyFromParent,
546                                      0, &attributes);
547                   XMapWindow (xdisplay, w);
548                   XIQueryPointer (xdisplay,
549                                   device_xi2->device_id,
550                                   xwindow,
551                                   &root, &child,
552                                   &xroot_x, &xroot_y,
553                                   &xwin_x, &xwin_y,
554                                   &button_state,
555                                   &mod_state,
556                                   &group_state);
557                   XDestroyWindow (xdisplay, w);
558                   if (child == w)
559                     {
560                       pointer_window = xwindow;
561                       break;
562                     }
563                 }
564             }
565
566           g_list_free (toplevels);
567           if (pointer_window != None)
568             break;
569         }
570
571       xwindow = pointer_window;
572     }
573
574   while (xwindow)
575     {
576       last = xwindow;
577       free (button_state.mask);
578
579       gdk_x11_display_error_trap_push (display);
580       XIQueryPointer (xdisplay,
581                       device_xi2->device_id,
582                       xwindow,
583                       &root, &xwindow,
584                       &xroot_x, &xroot_y,
585                       &xwin_x, &xwin_y,
586                       &button_state,
587                       &mod_state,
588                       &group_state);
589       if (gdk_x11_display_error_trap_pop (display))
590         break;
591
592       if (get_toplevel && last != root &&
593           (window = gdk_x11_window_lookup_for_display (display, last)) != NULL &&
594           GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
595         {
596           xwindow = last;
597           break;
598         }
599     }
600
601   gdk_x11_display_ungrab (display);
602
603   window = gdk_x11_window_lookup_for_display (display, last);
604
605   if (win_x)
606     *win_x = (window) ? (gint) xwin_x : -1;
607
608   if (win_y)
609     *win_y = (window) ? (gint) xwin_y : -1;
610
611   if (mask)
612     *mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
613
614   free (button_state.mask);
615
616   return window;
617 }
618
619 static void
620 gdk_x11_device_xi2_select_window_events (GdkDevice    *device,
621                                          GdkWindow    *window,
622                                          GdkEventMask  event_mask)
623 {
624   GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
625   XIEventMask evmask;
626
627   evmask.deviceid = device_xi2->device_id;
628   evmask.mask = _gdk_x11_device_xi2_translate_event_mask (event_mask, &evmask.mask_len);
629
630   XISelectEvents (GDK_WINDOW_XDISPLAY (window),
631                   GDK_WINDOW_XID (window),
632                   &evmask, 1);
633
634   g_free (evmask.mask);
635 }
636
637 guchar *
638 _gdk_x11_device_xi2_translate_event_mask (GdkEventMask  event_mask,
639                                           gint         *len)
640 {
641   guchar *mask;
642
643   *len = XIMaskLen (XI_LASTEVENT);
644   mask = g_new0 (guchar, *len);
645
646   if (event_mask & GDK_POINTER_MOTION_MASK ||
647       event_mask & GDK_POINTER_MOTION_HINT_MASK)
648     XISetMask (mask, XI_Motion);
649
650   if (event_mask & GDK_BUTTON_MOTION_MASK ||
651       event_mask & GDK_BUTTON1_MOTION_MASK ||
652       event_mask & GDK_BUTTON2_MOTION_MASK ||
653       event_mask & GDK_BUTTON3_MOTION_MASK)
654     {
655       XISetMask (mask, XI_ButtonPress);
656       XISetMask (mask, XI_ButtonRelease);
657       XISetMask (mask, XI_Motion);
658     }
659
660   if (event_mask & GDK_SCROLL_MASK)
661     {
662       XISetMask (mask, XI_ButtonPress);
663       XISetMask (mask, XI_ButtonRelease);
664     }
665
666   if (event_mask & GDK_BUTTON_PRESS_MASK)
667     XISetMask (mask, XI_ButtonPress);
668
669   if (event_mask & GDK_BUTTON_RELEASE_MASK)
670     XISetMask (mask, XI_ButtonRelease);
671
672   if (event_mask & GDK_KEY_PRESS_MASK)
673     XISetMask (mask, XI_KeyPress);
674
675   if (event_mask & GDK_KEY_RELEASE_MASK)
676     XISetMask (mask, XI_KeyRelease);
677
678   if (event_mask & GDK_ENTER_NOTIFY_MASK)
679     XISetMask (mask, XI_Enter);
680
681   if (event_mask & GDK_LEAVE_NOTIFY_MASK)
682     XISetMask (mask, XI_Leave);
683
684   if (event_mask & GDK_FOCUS_CHANGE_MASK)
685     {
686       XISetMask (mask, XI_FocusIn);
687       XISetMask (mask, XI_FocusOut);
688     }
689
690   return mask;
691 }
692
693 guint
694 _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
695                                      XIButtonState   *buttons_state,
696                                      XIGroupState    *group_state)
697 {
698   guint state = 0;
699
700   if (mods_state)
701     state = (guint) mods_state->base | mods_state->latched | mods_state->locked;
702
703   if (buttons_state)
704     {
705       gint len, i;
706
707       /* We're only interested in the first 5 buttons */
708       len = MIN (5, buttons_state->mask_len * 8);
709
710       for (i = 0; i < len; i++)
711         {
712           if (!XIMaskIsSet (buttons_state->mask, i))
713             continue;
714
715           switch (i)
716             {
717             case 1:
718               state |= GDK_BUTTON1_MASK;
719               break;
720             case 2:
721               state |= GDK_BUTTON2_MASK;
722               break;
723             case 3:
724               state |= GDK_BUTTON3_MASK;
725               break;
726             case 4:
727               state |= GDK_BUTTON4_MASK;
728               break;
729             case 5:
730               state |= GDK_BUTTON5_MASK;
731               break;
732             default:
733               break;
734             }
735         }
736     }
737
738   if (group_state)
739     {
740       gint group;
741
742       group = group_state->base + group_state->latched + group_state->locked;
743
744       /* FIXME: do we need the XKB complications for this ? */
745       group = CLAMP(group, 0, 3);
746
747       state |= group << 13;
748     }
749
750   return state;
751 }
752
753 gint
754 _gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
755 {
756   g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), 0);
757
758   return device->device_id;
759 }
760
761 #else /* XINPUT_2 */
762
763 static void
764 gdk_x11_device_xi2_class_init (GdkX11DeviceXI2Class *klass)
765 {
766 }
767
768 static void
769 gdk_x11_device_xi2_init (GdkX11DeviceXI2 *device)
770 {
771 }
772
773 #endif /* XINPUT_2 */