1
/* AT-SPI - Assistive Technology Service Provider Interface
2
 *
3
 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
4
 *
5
 * Copyright 2001, 2003 Sun Microsystems Inc.,
6
 * Copyright 2001, 2002 Ximian, Inc.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the
20
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 * Boston, MA 02110-1301, USA.
22
 */
23

            
24
/* deviceeventcontroller-x11.c: X-specific DeviceEventController support */
25

            
26
#include <config.h>
27

            
28
#undef SPI_XKB_DEBUG
29
#undef SPI_DEBUG
30
#undef SPI_KEYEVENT_DEBUG
31

            
32
#include <ctype.h>
33
#include <stdio.h>
34
#include <string.h>
35
#include <sys/time.h>
36

            
37
#define XK_MISCELLANY
38
#define XK_LATIN1
39
#include <X11/keysymdef.h>
40

            
41
#include <glib.h>
42

            
43
#include <dbus/dbus.h>
44

            
45
#include "de-types.h"
46
#include "display.h"
47
#include "event-source.h"
48
#include "keymasks.h"
49
#include "marshal-dbus.h"
50
#include "paths.h"
51

            
52
#include "deviceeventcontroller.h"
53

            
54
#include "deviceeventcontroller-x11.h"
55
#include "reentrant-list.h"
56

            
57
static void spi_dec_x11_emit_modifier_event (SpiDEController *controller,
58
                                             guint prev_mask,
59
                                             guint current_mask);
60

            
61
#define CHECK_RELEASE_DELAY 20
62
#define BIT(c, x) (c[x / 8] & (1 << (x % 8)))
63
static guint check_release_handler = 0;
64
static Accessibility_DeviceEvent pressed_event;
65
static void wait_for_release_event (XEvent *event, SpiDEController *controller);
66

            
67
static int spi_error_code = 0;
68
typedef struct
69
{
70
  gint x;
71
  gint y;
72
} SpiPoint;
73
static SpiPoint last_mouse_pos_static = { 0, 0 };
74
static SpiPoint *last_mouse_pos = &last_mouse_pos_static;
75
static unsigned int mouse_mask_state = 0;
76
static unsigned int mouse_button_mask =
77
    Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
78
static unsigned int key_modifier_mask =
79
    Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | LockMask | ControlMask | SPI_KEYMASK_NUMLOCK;
80
extern unsigned int _numlock_physical_mask;
81

            
82
static XModifierKeymap *xmkeymap = NULL;
83

            
84
static int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
85

            
86
static void spi_controller_register_with_devices (SpiDEController *controller);
87
static gboolean spi_device_event_controller_forward_key_event (SpiDEController *controller,
88
                                                               const XEvent *event);
89

            
90
static SpiDEController *saved_controller;
91

            
92
/* Normally this function would be provided by the macro call in deviceeventcontroller.c:
93
 *   G_DEFINE_TYPE_WITH_CODE (..., G_ADD_PRIVATE (SpiDEController))
94
 *
95
 * However, that machinery creates a static function for
96
 * _get_instance_private, so it is only visible in that file.  Here
97
 * we'll re-define it by hand, using the same name as that generated
98
 * function in case we can later merge the implementations together.
99
 */
100
static SpiDEControllerPrivate *
101
56
spi_device_event_controller_get_instance_private (SpiDEController *controller)
102
{
103
56
  return g_type_instance_get_private ((GTypeInstance *) controller, SPI_DEVICE_EVENT_CONTROLLER_TYPE);
104
}
105

            
106
static unsigned int
107
keysym_mod_mask (KeySym keysym, KeyCode keycode)
108
{
109
  /* we really should use XKB and look directly at the keymap */
110
  /* this is very inelegant */
111
  Display *display = spi_get_display ();
112
  unsigned int mods_rtn = 0;
113
  unsigned int retval = 0;
114
  KeySym sym_rtn;
115

            
116
  if (XkbLookupKeySym (display, keycode, 0, &mods_rtn, &sym_rtn) &&
117
      (sym_rtn == keysym))
118
    {
119
      retval = 0;
120
    }
121
  else if (XkbLookupKeySym (display, keycode, ShiftMask, &mods_rtn, &sym_rtn) &&
122
           (sym_rtn == keysym))
123
    {
124
      retval = ShiftMask;
125
    }
126
  else if (XkbLookupKeySym (display, keycode, Mod2Mask, &mods_rtn, &sym_rtn) &&
127
           (sym_rtn == keysym))
128
    {
129
      retval = Mod2Mask;
130
    }
131
  else if (XkbLookupKeySym (display, keycode, Mod3Mask, &mods_rtn, &sym_rtn) &&
132
           (sym_rtn == keysym))
133
    {
134
      retval = Mod3Mask;
135
    }
136
  else if (XkbLookupKeySym (display, keycode, Mod4Mask, &mods_rtn, &sym_rtn) &&
137
           (sym_rtn == keysym))
138
    {
139
      retval = Mod4Mask;
140
    }
141
  else if (XkbLookupKeySym (display, keycode, Mod5Mask, &mods_rtn, &sym_rtn) &&
142
           (sym_rtn == keysym))
143
    {
144
      retval = Mod5Mask;
145
    }
146
  else if (XkbLookupKeySym (display, keycode,
147
                            ShiftMask | Mod2Mask, &mods_rtn, &sym_rtn) &&
148
           (sym_rtn == keysym))
149
    {
150
      retval = (Mod2Mask | ShiftMask);
151
    }
152
  else if (XkbLookupKeySym (display, keycode,
153
                            ShiftMask | Mod3Mask, &mods_rtn, &sym_rtn) &&
154
           (sym_rtn == keysym))
155
    {
156
      retval = (Mod3Mask | ShiftMask);
157
    }
158
  else if (XkbLookupKeySym (display, keycode,
159
                            ShiftMask | Mod4Mask, &mods_rtn, &sym_rtn) &&
160
           (sym_rtn == keysym))
161
    {
162
      retval = (Mod4Mask | ShiftMask);
163
    }
164
  else if (XkbLookupKeySym (display, keycode,
165
                            ShiftMask | Mod5Mask, &mods_rtn, &sym_rtn) &&
166
           (sym_rtn == keysym))
167
    {
168
      retval = (Mod5Mask | ShiftMask);
169
    }
170
  else
171
    retval = 0xFFFF;
172
  return retval;
173
}
174

            
175
static gboolean
176
replace_map_keysym (SpiDEControllerPrivate *priv, KeyCode keycode, KeySym keysym)
177
{
178
#ifdef HAVE_XKB
179
  Display *dpy = spi_get_display ();
180
  XkbDescPtr desc;
181
  if (!(desc = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd)))
182
    {
183
      fprintf (stderr, "ERROR getting map\n");
184
    }
185
  XFlush (dpy);
186
  XSync (dpy, False);
187
  if (desc && desc->map)
188
    {
189
      gint offset = desc->map->key_sym_map[keycode].offset;
190
      desc->map->syms[offset] = keysym;
191
    }
192
  else
193
    {
194
      fprintf (stderr, "Error changing key map: empty server structure\n");
195
    }
196
  XkbSetMap (dpy, XkbAllMapComponentsMask, desc);
197
  /**
198
   *  FIXME: the use of XkbChangeMap, and the reuse of the priv->xkb_desc structure,
199
   * would be far preferable.
200
   * HOWEVER it does not seem to work using XFree 4.3.
201
   **/
202
  /*	    XkbChangeMap (dpy, priv->xkb_desc, priv->changes); */
203
  XFlush (dpy);
204
  XSync (dpy, False);
205
  XkbFreeKeyboard (desc, 0, TRUE);
206

            
207
  return TRUE;
208
#else
209
  return FALSE;
210
#endif
211
}
212

            
213
static gboolean
214
spi_dec_reset_reserved (gpointer data)
215
{
216
  SpiDEControllerPrivate *priv = data;
217
  replace_map_keysym (priv, priv->reserved_keycode, priv->reserved_keysym);
218
  priv->reserved_reset_timeout = 0;
219
  return FALSE;
220
}
221

            
222
static gint
223
spi_dec_x11_get_keycode (SpiDEController *controller,
224
                         gint keysym,
225
                         gchar *key_str,
226
                         gboolean fix,
227
                         guint *modmask)
228
{
229
  KeyCode keycode = 0;
230
  if (key_str && key_str[0])
231
    keysym = XStringToKeysym (key_str);
232
  keycode = XKeysymToKeycode (spi_get_display (), (KeySym) keysym);
233
  if (!keycode && fix)
234
    {
235
      SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
236
      /* if there's no keycode available, fix it */
237
      if (replace_map_keysym (priv, priv->reserved_keycode, keysym))
238
        {
239
          keycode = priv->reserved_keycode;
240
          /*
241
           * queue a timer to restore the old keycode.  Ugly, but required
242
           * due to races / asynchronous X delivery.
243
           * Long-term fix is to extend the X keymap here instead of replace entries.
244
           */
245
          priv->reserved_reset_timeout = g_timeout_add (500, spi_dec_reset_reserved, priv);
246
          g_source_set_name_by_id (priv->reserved_reset_timeout, "[at-spi2-core] spi_dec_reset_reserved");
247
        }
248
      if (modmask)
249
        *modmask = 0;
250
      return keycode;
251
    }
252
  if (modmask)
253
    *modmask = keysym_mod_mask (keysym, keycode);
254
  return keycode;
255
}
256

            
257
static gboolean
258
spi_dec_button_update_and_emit (SpiDEController *controller,
259
                                guint mask_return)
260
{
261
  gchar event_detail[3];
262

            
263
  if ((mask_return & mouse_button_mask) !=
264
      (mouse_mask_state & mouse_button_mask))
265
    {
266
      int button_number = 0;
267
      gboolean is_down = False;
268

            
269
      if (!(mask_return & Button1Mask) &&
270
          (mouse_mask_state & Button1Mask))
271
        {
272
          mouse_mask_state &= ~Button1Mask;
273
          button_number = 1;
274
        }
275
      else if ((mask_return & Button1Mask) &&
276
               !(mouse_mask_state & Button1Mask))
277
        {
278
          mouse_mask_state |= Button1Mask;
279
          button_number = 1;
280
          is_down = True;
281
        }
282
      else if (!(mask_return & Button2Mask) &&
283
               (mouse_mask_state & Button2Mask))
284
        {
285
          mouse_mask_state &= ~Button2Mask;
286
          button_number = 2;
287
        }
288
      else if ((mask_return & Button2Mask) &&
289
               !(mouse_mask_state & Button2Mask))
290
        {
291
          mouse_mask_state |= Button2Mask;
292
          button_number = 2;
293
          is_down = True;
294
        }
295
      else if (!(mask_return & Button3Mask) &&
296
               (mouse_mask_state & Button3Mask))
297
        {
298
          mouse_mask_state &= ~Button3Mask;
299
          button_number = 3;
300
        }
301
      else if ((mask_return & Button3Mask) &&
302
               !(mouse_mask_state & Button3Mask))
303
        {
304
          mouse_mask_state |= Button3Mask;
305
          button_number = 3;
306
          is_down = True;
307
        }
308
      else if (!(mask_return & Button4Mask) &&
309
               (mouse_mask_state & Button4Mask))
310
        {
311
          mouse_mask_state &= ~Button4Mask;
312
          button_number = 4;
313
        }
314
      else if ((mask_return & Button4Mask) &&
315
               !(mouse_mask_state & Button4Mask))
316
        {
317
          mouse_mask_state |= Button4Mask;
318
          button_number = 4;
319
          is_down = True;
320
        }
321
      else if (!(mask_return & Button5Mask) &&
322
               (mouse_mask_state & Button5Mask))
323
        {
324
          mouse_mask_state &= ~Button5Mask;
325
          button_number = 5;
326
        }
327
      else if ((mask_return & Button5Mask) &&
328
               !(mouse_mask_state & Button5Mask))
329
        {
330
          mouse_mask_state |= Button5Mask;
331
          button_number = 5;
332
          is_down = True;
333
        }
334
      if (button_number)
335
        {
336
#ifdef SPI_DEBUG
337
          fprintf (stderr, "Button %d %s\n",
338
                   button_number, (is_down) ? "Pressed" : "Released");
339
#endif
340
          snprintf (event_detail, 3, "%d%c", button_number,
341
                    (is_down) ? 'p' : 'r');
342
          dbus_uint32_t x = last_mouse_pos->x, y = last_mouse_pos->y;
343
          spi_dec_dbus_emit (controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, x, y);
344
        }
345
      return TRUE;
346
    }
347
  else
348
    {
349
      return FALSE;
350
    }
351
}
352

            
353
static guint
354
spi_dec_x11_mouse_check (SpiDEController *controller,
355
                         int *x,
356
                         int *y,
357
                         gboolean *moved)
358
{
359
  int win_x_return, win_y_return;
360
  unsigned int mask_return;
361
  Window root_return, child_return;
362
  Display *display = spi_get_display ();
363

            
364
  if (display == NULL)
365
    {
366
      return 0;
367
    }
368

            
369
  XQueryPointer (display, DefaultRootWindow (display),
370
                 &root_return, &child_return,
371
                 x, y,
372
                 &win_x_return, &win_y_return, &mask_return);
373
  /*
374
   * Since many clients grab the pointer, and X goes an automatic
375
   * pointer grab on mouse-down, we often must detect mouse button events
376
   * by polling rather than via a button grab.
377
   * The while loop (rather than if) is used since it's possible that
378
   * multiple buttons have changed state since we last checked.
379
   */
380
  if (mask_return != mouse_mask_state)
381
    {
382
      while (spi_dec_button_update_and_emit (controller, mask_return))
383
        ;
384
    }
385

            
386
  if (*x != last_mouse_pos->x || *y != last_mouse_pos->y)
387
    {
388
      // TODO: combine these two signals?
389
      dbus_uint32_t ix = *x, iy = *y;
390
      spi_dec_dbus_emit (controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Abs", "", ix, iy);
391
      ix -= last_mouse_pos->x;
392
      iy -= last_mouse_pos->y;
393
      spi_dec_dbus_emit (controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Rel", "", ix, iy);
394
      last_mouse_pos->x = *x;
395
      last_mouse_pos->y = *y;
396
      *moved = True;
397
    }
398
  else
399
    {
400
      *moved = False;
401
    }
402

            
403
  return mask_return;
404
}
405

            
406
#ifdef WE_NEED_UGRAB_MOUSE
407
static int
408
spi_dec_ungrab_mouse (gpointer data)
409
{
410
  Display *display = spi_get_display ();
411
  if (display)
412
    {
413
      XUngrabButton (spi_get_display (), AnyButton, AnyModifier,
414
                     XDefaultRootWindow (spi_get_display ()));
415
    }
416
  return FALSE;
417
}
418
#endif
419

            
420
static void
421
spi_dec_clear_unlatch_pending (SpiDEController *controller)
422
{
423
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
424
  priv->xkb_latch_mask = 0;
425
}
426

            
427
static void
428
spi_device_event_controller_forward_mouse_event (SpiDEController *controller,
429
                                                 XEvent *xevent)
430
{
431
  gchar event_detail[3];
432
  XButtonEvent *xbutton_event = (XButtonEvent *) xevent;
433
  dbus_uint32_t ix, iy;
434

            
435
  int button = xbutton_event->button;
436

            
437
  unsigned int mouse_button_state = xbutton_event->state;
438

            
439
  switch (button)
440
    {
441
    case 1:
442
      mouse_button_state |= Button1Mask;
443
      break;
444
    case 2:
445
      mouse_button_state |= Button2Mask;
446
      break;
447
    case 3:
448
      mouse_button_state |= Button3Mask;
449
      break;
450
    case 4:
451
      mouse_button_state |= Button4Mask;
452
      break;
453
    case 5:
454
      mouse_button_state |= Button5Mask;
455
      break;
456
    }
457

            
458
  last_mouse_pos->x = ((XButtonEvent *) xevent)->x_root;
459
  last_mouse_pos->y = ((XButtonEvent *) xevent)->y_root;
460

            
461
#ifdef SPI_DEBUG
462
  fprintf (stderr, "mouse button %d %s (%x)\n",
463
           xbutton_event->button,
464
           (xevent->type == ButtonPress) ? "Press" : "Release",
465
           mouse_button_state);
466
#endif
467
  snprintf (event_detail, 3, "%d%c", button,
468
            (xevent->type == ButtonPress) ? 'p' : 'r');
469

            
470
  if ((mouse_button_state & mouse_button_mask) !=
471
      (mouse_mask_state & mouse_button_mask))
472
    {
473
      if ((mouse_mask_state & key_modifier_mask) !=
474
          (mouse_button_state & key_modifier_mask))
475
        spi_dec_x11_emit_modifier_event (controller,
476
                                         mouse_mask_state, mouse_button_state);
477
      mouse_mask_state = mouse_button_state;
478
      ix = last_mouse_pos->x;
479
      iy = last_mouse_pos->y;
480
      spi_dec_dbus_emit (controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, ix, iy);
481
    }
482

            
483
  XAllowEvents (spi_get_display (),
484
                ReplayPointer,
485
                CurrentTime);
486
}
487

            
488
static void
489
global_filter_fn (XEvent *xevent, void *data)
490
{
491
  SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (data);
492
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
493
  Display *display = spi_get_display ();
494

            
495
  if (xevent->type == MappingNotify)
496
    xmkeymap = NULL;
497

            
498
  if (xevent->type == KeyPress || xevent->type == KeyRelease)
499
    {
500
      if (priv->xevie_display == NULL)
501
        {
502
          gboolean is_consumed;
503

            
504
          is_consumed =
505
              spi_device_event_controller_forward_key_event (controller, xevent);
506

            
507
          if (is_consumed)
508
            {
509
              int n_events;
510
              int i;
511
              XEvent next_event;
512
              n_events = XPending (display);
513

            
514
#ifdef SPI_KEYEVENT_DEBUG
515
              g_print ("Number of events pending: %d\n", n_events);
516
#endif
517
              for (i = 0; i < n_events; i++)
518
                {
519
                  XNextEvent (display, &next_event);
520
                  if (next_event.type != KeyPress &&
521
                      next_event.type != KeyRelease)
522
                    g_warning ("Unexpected event type %d in queue", next_event.type);
523
                }
524

            
525
              XAllowEvents (display, AsyncKeyboard, CurrentTime);
526
              if (n_events)
527
                XUngrabKeyboard (display, CurrentTime);
528
            }
529
          else
530
            {
531
              if (xevent->type == KeyPress)
532
                wait_for_release_event (xevent, controller);
533
              XAllowEvents (display, ReplayKeyboard, CurrentTime);
534
            }
535
        }
536

            
537
      return;
538
    }
539
  if (xevent->type == ButtonPress || xevent->type == ButtonRelease)
540
    {
541
      spi_device_event_controller_forward_mouse_event (controller, xevent);
542
    }
543
  if (xevent->type == priv->xkb_base_event_code)
544
    {
545
      XkbAnyEvent *xkb_ev = (XkbAnyEvent *) xevent;
546
      /* ugly but probably necessary...*/
547
      XSynchronize (display, TRUE);
548

            
549
      if (xkb_ev->xkb_type == XkbStateNotify)
550
        {
551
          XkbStateNotifyEvent *xkb_snev =
552
              (XkbStateNotifyEvent *) xkb_ev;
553
          /* check the mouse, to catch mouse events grabbed by
554
           * another client; in case we should revert this XKB delatch
555
           */
556
          if (!priv->pending_xkb_mod_relatch_mask)
557
            {
558
              int x, y;
559
              gboolean moved;
560
              spi_dec_x11_mouse_check (controller, &x, &y, &moved);
561
            }
562
          /* we check again, since the previous call may have
563
             changed this flag */
564
          if (priv->pending_xkb_mod_relatch_mask)
565
            {
566
              unsigned int feedback_mask;
567
#ifdef SPI_XKB_DEBUG
568
              fprintf (stderr, "relatching %x\n",
569
                       priv->pending_xkb_mod_relatch_mask);
570
#endif
571
              /* temporarily turn off the latch bell, if it's on */
572
              XkbGetControls (display,
573
                              XkbAccessXFeedbackMask,
574
                              priv->xkb_desc);
575
              feedback_mask = priv->xkb_desc->ctrls->ax_options;
576
              if (feedback_mask & XkbAX_StickyKeysFBMask)
577
                {
578
                  XkbControlsChangesRec changes = { XkbAccessXFeedbackMask,
579
                                                    0, False };
580
                  priv->xkb_desc->ctrls->ax_options &= ~(XkbAX_StickyKeysFBMask);
581
                  XkbChangeControls (display, priv->xkb_desc, &changes);
582
                }
583
              /* TODO: account for lock as well as latch */
584
              XkbLatchModifiers (display,
585
                                 XkbUseCoreKbd,
586
                                 priv->pending_xkb_mod_relatch_mask,
587
                                 priv->pending_xkb_mod_relatch_mask);
588
              if (feedback_mask & XkbAX_StickyKeysFBMask)
589
                {
590
                  XkbControlsChangesRec changes = { XkbAccessXFeedbackMask,
591
                                                    0, False };
592
                  priv->xkb_desc->ctrls->ax_options = feedback_mask;
593
                  XkbChangeControls (display, priv->xkb_desc, &changes);
594
                }
595
#ifdef SPI_XKB_DEBUG
596
              fprintf (stderr, "relatched %x\n",
597
                       priv->pending_xkb_mod_relatch_mask);
598
#endif
599
              priv->pending_xkb_mod_relatch_mask = 0;
600
            }
601
          else
602
            {
603
              priv->xkb_latch_mask = xkb_snev->latched_mods;
604
            }
605
        }
606
      XSynchronize (display, FALSE);
607
    }
608

            
609
  return;
610
}
611

            
612
static gboolean
613
spi_clear_error_state (void)
614
{
615
  gboolean retval = spi_error_code != 0;
616
  spi_error_code = 0;
617
  return retval;
618
}
619

            
620
static int
621
_spi_controller_device_error_handler (Display *display, XErrorEvent *error)
622
{
623
  if (error->error_code == BadAccess)
624
    {
625
      g_message ("Could not complete key grab: grab already in use.\n");
626
      spi_error_code = BadAccess;
627
      return 0;
628
    }
629
  else
630
    {
631
      return (*x_default_error_handler) (display, error);
632
    }
633
}
634

            
635
static void
636
28
spi_controller_register_with_devices (SpiDEController *controller)
637
{
638
28
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
639
  int event_base, error_base, major_version, minor_version;
640

            
641
28
  if (XTestQueryExtension (spi_get_display (), &event_base, &error_base, &major_version, &minor_version))
642
    {
643
28
      XTestGrabControl (spi_get_display (), True);
644
    }
645

            
646
  /* calls to device-specific implementations and routines go here */
647
  /* register with: keyboard hardware code handler */
648
  /* register with: (translated) keystroke handler */
649

            
650
28
  priv->have_xkb = XkbQueryExtension (spi_get_display (),
651
                                      &priv->xkb_major_extension_opcode,
652
                                      &priv->xkb_base_event_code,
653
                                      &priv->xkb_base_error_code, NULL, NULL);
654
28
  if (priv->have_xkb)
655
    {
656
      gint i;
657
28
      guint64 reserved = 0;
658
28
      priv->xkb_desc = XkbGetMap (spi_get_display (), XkbKeySymsMask, XkbUseCoreKbd);
659
28
      XkbSelectEvents (spi_get_display (),
660
                       XkbUseCoreKbd,
661
                       XkbStateNotifyMask, XkbStateNotifyMask);
662
28
      _numlock_physical_mask = XkbKeysymToModifiers (spi_get_display (),
663
                                                     XK_Num_Lock);
664
28
      for (i = priv->xkb_desc->max_key_code; i >= priv->xkb_desc->min_key_code; --i)
665
        {
666
28
          if (priv->xkb_desc->map->key_sym_map[i].kt_index[0] == XkbOneLevelIndex)
667
            {
668
28
              if (XkbKeycodeToKeysym (spi_get_display (), i, 0, 0) != 0)
669
                {
670
                  /* don't use this one if there's a grab client! */
671

            
672
                  /* Runtime errors are generated from these functions,
673
                   * that are then quashed. Equivalent to:
674
                   * try
675
                   *   {Blah}
676
                   * except
677
                   *   {;}
678
                   */
679

            
680
28
                  spi_x_error_trap ();
681
28
                  XGrabKey (spi_get_display (), i, 0,
682
                            spi_get_root_window (),
683
                            TRUE,
684
                            GrabModeSync, GrabModeSync);
685
28
                  XSync (spi_get_display (), TRUE);
686
28
                  XUngrabKey (spi_get_display (), i, 0,
687
                              spi_get_root_window ());
688
28
                  if (!spi_x_error_release ())
689
                    {
690
28
                      reserved = i;
691
28
                      break;
692
                    }
693
                }
694
            }
695
        }
696
28
      if (reserved)
697
        {
698
28
          priv->reserved_keycode = reserved;
699
28
          priv->reserved_keysym = XkbKeycodeToKeysym (spi_get_display (), reserved, 0, 0);
700
        }
701
      else
702
        {
703
          priv->reserved_keycode = XKeysymToKeycode (spi_get_display (), XK_numbersign);
704
          priv->reserved_keysym = XK_numbersign;
705
        }
706
#ifdef SPI_RESERVED_DEBUG
707
      unsigned sym = 0;
708
      sym = XKeycodeToKeysym (spi_get_display (), reserved, 0);
709
      fprintf (stderr, "%x\n", sym);
710
      fprintf (stderr, "setting the reserved keycode to %d (%s)\n",
711
               reserved,
712
               XKeysymToString (XKeycodeToKeysym (spi_get_display (),
713
                                                  reserved, 0)));
714
#endif
715
    }
716

            
717
28
  spi_set_filter (global_filter_fn, controller);
718
28
  spi_set_events (KeyPressMask | KeyReleaseMask);
719

            
720
28
  x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
721
28
}
722

            
723
static Accessibility_DeviceEvent
724
spi_keystroke_from_x_key_event (XKeyEvent *x_key_event)
725
{
726
  Accessibility_DeviceEvent key_event;
727
  KeySym keysym;
728
  const int cbuf_bytes = 20;
729
  char cbuf[21];
730
  int nbytes;
731

            
732
  nbytes = XLookupString (x_key_event, cbuf, cbuf_bytes, &keysym, NULL);
733
  key_event.id = (dbus_int32_t) (keysym);
734
  key_event.hw_code = (dbus_int16_t) x_key_event->keycode;
735
  if (((XEvent *) x_key_event)->type == KeyPress)
736
    {
737
      key_event.type = Accessibility_KEY_PRESSED_EVENT;
738
    }
739
  else
740
    {
741
      key_event.type = Accessibility_KEY_RELEASED_EVENT;
742
    }
743
  key_event.modifiers = (dbus_uint16_t) (x_key_event->state);
744
  key_event.is_text = FALSE;
745
  switch (keysym)
746
    {
747
    case ' ':
748
      key_event.event_string = g_strdup ("space");
749
      break;
750
    case XK_Tab:
751
      key_event.event_string = g_strdup ("Tab");
752
      break;
753
    case XK_BackSpace:
754
      key_event.event_string = g_strdup ("Backspace");
755
      break;
756
    case XK_Return:
757
      key_event.event_string = g_strdup ("Return");
758
      break;
759
    case XK_Home:
760
      key_event.event_string = g_strdup ("Home");
761
      break;
762
    case XK_Page_Down:
763
      key_event.event_string = g_strdup ("Page_Down");
764
      break;
765
    case XK_Page_Up:
766
      key_event.event_string = g_strdup ("Page_Up");
767
      break;
768
    case XK_F1:
769
      key_event.event_string = g_strdup ("F1");
770
      break;
771
    case XK_F2:
772
      key_event.event_string = g_strdup ("F2");
773
      break;
774
    case XK_F3:
775
      key_event.event_string = g_strdup ("F3");
776
      break;
777
    case XK_F4:
778
      key_event.event_string = g_strdup ("F4");
779
      break;
780
    case XK_F5:
781
      key_event.event_string = g_strdup ("F5");
782
      break;
783
    case XK_F6:
784
      key_event.event_string = g_strdup ("F6");
785
      break;
786
    case XK_F7:
787
      key_event.event_string = g_strdup ("F7");
788
      break;
789
    case XK_F8:
790
      key_event.event_string = g_strdup ("F8");
791
      break;
792
    case XK_F9:
793
      key_event.event_string = g_strdup ("F9");
794
      break;
795
    case XK_F10:
796
      key_event.event_string = g_strdup ("F10");
797
      break;
798
    case XK_F11:
799
      key_event.event_string = g_strdup ("F11");
800
      break;
801
    case XK_F12:
802
      key_event.event_string = g_strdup ("F12");
803
      break;
804
    case XK_End:
805
      key_event.event_string = g_strdup ("End");
806
      break;
807
    case XK_Escape:
808
      key_event.event_string = g_strdup ("Escape");
809
      break;
810
    case XK_Up:
811
      key_event.event_string = g_strdup ("Up");
812
      break;
813
    case XK_Down:
814
      key_event.event_string = g_strdup ("Down");
815
      break;
816
    case XK_Left:
817
      key_event.event_string = g_strdup ("Left");
818
      break;
819
    case XK_Right:
820
      key_event.event_string = g_strdup ("Right");
821
      break;
822
    default:
823
      if (nbytes > 0)
824
        {
825
          gunichar c;
826
          cbuf[nbytes] = '\0'; /* OK since length is cbuf_bytes+1 */
827
          key_event.event_string = g_strdup (cbuf);
828
          c = keysym2ucs (keysym);
829
          if (c > 0 && !g_unichar_iscntrl (c))
830
            {
831
              key_event.is_text = TRUE;
832
              /* incorrect for some composed chars? */
833
            }
834
        }
835
      else
836
        {
837
          key_event.event_string = g_strdup ("");
838
        }
839
    }
840

            
841
  key_event.timestamp = (dbus_uint32_t) x_key_event->time;
842
#ifdef SPI_KEYEVENT_DEBUG
843
  {
844
    char *pressed_str = "pressed";
845
    char *released_str = "released";
846
    char *state_ptr;
847

            
848
    if (key_event.type == Accessibility_KEY_PRESSED_EVENT)
849
      state_ptr = pressed_str;
850
    else
851
      state_ptr = released_str;
852

            
853
    fprintf (stderr,
854
             "Key %lu %s (%c), modifiers %d; string=%s [%x] %s\n",
855
             (unsigned long) keysym,
856
             state_ptr,
857
             keysym ? (int) keysym : '*',
858
             (int) x_key_event->state,
859
             key_event.event_string,
860
             key_event.event_string[0],
861
             (key_event.is_text == TRUE) ? "(text)" : "(not text)");
862
  }
863
#endif
864
#ifdef SPI_DEBUG
865
  fprintf (stderr, "%s%c\n",
866
           (x_key_event->state & Mod1Mask) ? "Alt-" : "",
867
           ((x_key_event->state & ShiftMask) ^ (x_key_event->state & LockMask)) ? g_ascii_toupper (keysym) : g_ascii_tolower (keysym));
868
  fprintf (stderr, "serial: %x Time: %x\n", x_key_event->serial, x_key_event->time);
869
#endif /* SPI_DEBUG */
870
  return key_event;
871
}
872

            
873
static gboolean
874
spi_dec_x11_grab_key (SpiDEController *controller,
875
                      guint key_val,
876
                      Accessibility_ControllerEventMask mod_mask)
877
{
878
  XGrabKey (spi_get_display (),
879
            key_val,
880
            mod_mask,
881
            spi_get_root_window (),
882
            True,
883
            GrabModeSync,
884
            GrabModeSync);
885
  XSync (spi_get_display (), False);
886
  return spi_clear_error_state ();
887
}
888

            
889
static void
890
spi_dec_x11_ungrab_key (SpiDEController *controller,
891
                        guint key_val,
892
                        Accessibility_ControllerEventMask mod_mask)
893
{
894
  XUngrabKey (spi_get_display (),
895
              key_val,
896
              mod_mask,
897
              spi_get_root_window ());
898
}
899

            
900
static unsigned int
901
xkb_get_slowkeys_delay (SpiDEController *controller)
902
{
903
  unsigned int retval = 0;
904
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
905
#ifdef HAVE_XKB
906
#ifdef XKB_HAS_GET_SLOW_KEYS_DELAY
907
  retval = XkbGetSlowKeysDelay (spi_get_display (),
908
                                XkbUseCoreKbd, &bounce_delay);
909
#else
910
  if (!(priv->xkb_desc == (XkbDescPtr) BadAlloc || priv->xkb_desc == NULL))
911
    {
912
      Status s = XkbGetControls (spi_get_display (),
913
                                 XkbAllControlsMask, priv->xkb_desc);
914
      if (s == Success)
915
        {
916
          if (priv->xkb_desc->ctrls->enabled_ctrls & XkbSlowKeysMask)
917
            retval = priv->xkb_desc->ctrls->slow_keys_delay;
918
        }
919
    }
920
#endif
921
#endif
922
#ifdef SPI_XKB_DEBUG
923
  fprintf (stderr, "SlowKeys delay: %d\n", (int) retval);
924
#endif
925
  return retval;
926
}
927

            
928
static unsigned int
929
xkb_get_bouncekeys_delay (SpiDEController *controller)
930
{
931
  unsigned int retval = 0;
932
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
933
#ifdef HAVE_XKB
934
#ifdef XKB_HAS_GET_BOUNCE_KEYS_DELAY
935
  retval = XkbGetBounceKeysDelay (spi_get_display (),
936
                                  XkbUseCoreKbd, &bounce_delay);
937
#else
938
  if (!(priv->xkb_desc == (XkbDescPtr) BadAlloc || priv->xkb_desc == NULL))
939
    {
940
      Status s = XkbGetControls (spi_get_display (),
941
                                 XkbAllControlsMask, priv->xkb_desc);
942
      if (s == Success)
943
        {
944
          if (priv->xkb_desc->ctrls->enabled_ctrls & XkbBounceKeysMask)
945
            retval = priv->xkb_desc->ctrls->debounce_delay;
946
        }
947
    }
948
#endif
949
#endif
950
#ifdef SPI_XKB_DEBUG
951
  fprintf (stderr, "BounceKeys delay: %d\n", (int) retval);
952
#endif
953
  return retval;
954
}
955

            
956
static gboolean
957
spi_dec_x11_synth_keycode_press (SpiDEController *controller,
958
                                 unsigned int keycode)
959
{
960
  unsigned int time = CurrentTime;
961
  unsigned int bounce_delay;
962
#ifdef THIS_IS_BROKEN
963
  unsigned int elapsed_msec;
964
  struct timeval tv;
965
#endif
966
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
967

            
968
  spi_x_error_trap ();
969
  if (keycode == priv->last_release_keycode)
970
    {
971
      bounce_delay = xkb_get_bouncekeys_delay (controller);
972
      if (bounce_delay)
973
        {
974
#ifdef THIS_IS_BROKEN
975
          gettimeofday (&tv, NULL);
976
          elapsed_msec =
977
              (tv.tv_sec - priv->last_release_time.tv_sec) * 1000 + (tv.tv_usec - priv->last_release_time.tv_usec) / 1000;
978
#ifdef SPI_XKB_DEBUG
979
          fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
980
                   (long) (tv.tv_usec - priv->last_release_time.tv_usec));
981
#endif
982
          if (elapsed_msec < bounce_delay)
983
            time = bounce_delay - elapsed_msec + 1;
984
#else
985
          time = bounce_delay + 10;
986
          /* fudge for broken XTest */
987
#endif
988
#ifdef SPI_XKB_DEBUG
989
          fprintf (stderr, "waiting %d ms\n", time);
990
#endif
991
        }
992
    }
993
  XTestFakeKeyEvent (spi_get_display (), keycode, True, time);
994
  priv->last_press_keycode = keycode;
995
  XFlush (spi_get_display ());
996
  XSync (spi_get_display (), False);
997
  gettimeofday (&priv->last_press_time, NULL);
998
  return TRUE;
999
}
static gboolean
spi_dec_x11_synth_keycode_release (SpiDEController *controller,
                                   unsigned int keycode)
{
  unsigned int time = CurrentTime;
  unsigned int slow_delay;
#ifdef THIS_IS_BROKEN_DUNNO_WHY
  unsigned int elapsed_msec;
  struct timeval tv;
#endif
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
  spi_x_error_trap ();
  if (keycode == priv->last_press_keycode)
    {
      slow_delay = xkb_get_slowkeys_delay (controller);
      if (slow_delay)
        {
#ifdef THIS_IS_BROKEN_DUNNO_WHY
          gettimeofday (&tv, NULL);
          elapsed_msec =
              (tv.tv_sec - priv->last_press_time.tv_sec) * 1000 + (tv.tv_usec - priv->last_press_time.tv_usec) / 1000;
#ifdef SPI_XKB_DEBUG
          fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
                   (long) (tv.tv_usec - priv->last_press_time.tv_usec));
#endif
          if (elapsed_msec < slow_delay)
            time = slow_delay - elapsed_msec + 1;
#else
          time = slow_delay + 10;
          /* our XTest seems broken, we have to add slop as above */
#endif
#ifdef SPI_XKB_DEBUG
          fprintf (stderr, "waiting %d ms\n", time);
#endif
        }
    }
  XTestFakeKeyEvent (spi_get_display (), keycode, False, time);
  priv->last_release_keycode = keycode;
  XSync (spi_get_display (), False);
  gettimeofday (&priv->last_release_time, NULL);
  return TRUE;
}
static gboolean
spi_dec_x11_lock_modifiers (SpiDEController *controller, unsigned modifiers)
{
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
  if (priv->have_xkb)
    {
      return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
                               modifiers, modifiers);
    }
  else
    {
      int mod_index;
      if (xmkeymap == NULL)
        xmkeymap = XGetModifierMapping (spi_get_display ());
      for (mod_index = 0; mod_index < 8; mod_index++)
        if (modifiers & (1 << mod_index))
          spi_dec_x11_synth_keycode_press (controller, xmkeymap->modifiermap[mod_index]);
      return TRUE;
    }
}
static gboolean
spi_dec_x11_unlock_modifiers (SpiDEController *controller, unsigned modifiers)
{
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
  if (priv->have_xkb)
    {
      return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
                               modifiers, 0);
    }
  else
    {
      int mod_index;
      if (xmkeymap == NULL)
        xmkeymap = XGetModifierMapping (spi_get_display ());
      for (mod_index = 0; mod_index < 8; mod_index++)
        if (modifiers & (1 << mod_index))
          spi_dec_x11_synth_keycode_release (controller, xmkeymap->modifiermap[mod_index]);
      return TRUE;
    }
}
static KeySym
keysym_for_unichar (SpiDEController *controller, gunichar unichar)
{
  return (KeySym) ucs2keysym ((long) unichar);
}
static gboolean
spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint keycode, const char *keystring)
{
  /* probably we need to create and inject an XIM handler eventually. */
  /* for now, try to match the string to existing
   * keycode+modifier states.
   */
  KeySym *keysyms;
  gint maxlen = 0;
  gunichar unichar = 0;
  gint i = 0;
  gboolean retval = TRUE;
  const gchar *c;
  KeySym keysym;
  if (!(keystring && *keystring && g_utf8_validate (keystring, -1, &c)))
    {
      retval = FALSE;
    }
  else
    {
#ifdef SPI_DEBUG
      fprintf (stderr, "[keystring synthesis attempted on %s]\n", keystring);
#endif
      maxlen = strlen (keystring) + 1;
      keysyms = g_new0 (KeySym, maxlen);
      while (keystring && (unichar = g_utf8_get_char (keystring)))
        {
          char bytes[6];
          gint mbytes;
          mbytes = g_unichar_to_utf8 (unichar, bytes);
          bytes[mbytes] = '\0';
#ifdef SPI_DEBUG
          fprintf (stderr, "[unichar %s]", bytes);
#endif
          keysym = keysym_for_unichar (controller, unichar);
          if (keysym == NoSymbol)
            {
#ifdef SPI_DEBUG
              fprintf (stderr, "no keysym for %s", bytes);
#endif
              retval = FALSE;
              break;
            }
          keysyms[i++] = keysym;
          keystring = g_utf8_next_char (keystring);
        }
      keysyms[i++] = 0;
      XSynchronize (spi_get_display (), TRUE);
      for (i = 0; keysyms[i]; ++i)
        {
          if (!spi_dec_synth_keysym (controller, keysyms[i]))
            {
#ifdef SPI_DEBUG
              fprintf (stderr, "could not synthesize %c\n",
                       (int) keysyms[i]);
#endif
              retval = FALSE;
              break;
            }
        }
      XSynchronize (spi_get_display (), FALSE);
      g_free (keysyms);
    }
  if (synth_type == Accessibility_KEY_SYM)
    {
      keysym = keycode;
    }
  else
    {
      keysym = XkbKeycodeToKeysym (spi_get_display (), keycode, 0, 0);
    }
  if (XkbKeysymToModifiers (spi_get_display (), keysym) == 0)
    {
      spi_dec_clear_unlatch_pending (controller);
    }
  return retval;
}
static void
28
spi_dec_x11_init (SpiDEController *controller)
{
28
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
28
  spi_events_init (spi_get_display ());
28
  gettimeofday (&priv->last_press_time, NULL);
28
  gettimeofday (&priv->last_release_time, NULL);
28
  spi_controller_register_with_devices (controller);
28
  saved_controller = controller;
28
}
static void
spi_dec_x11_finalize (SpiDEController *controller)
{
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
  /* disconnect any special listeners, get rid of outstanding keygrabs */
  XUngrabKey (spi_get_display (), AnyKey, AnyModifier, DefaultRootWindow (spi_get_display ()));
  if (priv->xkb_desc)
    XkbFreeKeyboard (priv->xkb_desc, 0, True);
  /* TODO: Should free the keymap */
}
static gboolean
spi_device_event_controller_forward_key_event (SpiDEController *controller,
                                               const XEvent *event)
{
  SpiDEControllerPrivate *priv = spi_device_event_controller_get_instance_private (controller);
  Accessibility_DeviceEvent key_event;
  gboolean ret;
  g_assert (event->type == KeyPress || event->type == KeyRelease);
  key_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
  if (priv->xevie_display == NULL)
    spi_controller_update_key_grabs (controller, &key_event);
  /* relay to listeners, and decide whether to consume it or not */
  ret = spi_controller_notify_keylisteners (controller, &key_event, TRUE);
  g_free (key_event.event_string);
  return ret;
}
static gboolean
is_key_released (long code)
{
  char keys[32];
  int down;
  XQueryKeymap (spi_get_display (), keys);
  down = BIT (keys, code);
  return (down == 0);
}
static gboolean
check_release (gpointer data)
{
  gboolean released;
  Accessibility_DeviceEvent *event = (Accessibility_DeviceEvent *) data;
  KeyCode code = event->hw_code;
  released = is_key_released (code);
  if (released)
    {
      check_release_handler = 0;
      event->type = Accessibility_KEY_RELEASED_EVENT;
      spi_controller_notify_keylisteners (saved_controller, event, TRUE);
    }
  return (released == 0);
}
static void
wait_for_release_event (XEvent *event,
                        SpiDEController *controller)
{
  pressed_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
  check_release_handler = g_timeout_add (CHECK_RELEASE_DELAY, check_release, &pressed_event);
  g_source_set_name_by_id (check_release_handler, "[at-spi2-core] check_release");
}
static void
spi_dec_x11_emit_modifier_event (SpiDEController *controller, guint prev_mask, guint current_mask)
{
  dbus_uint32_t d1, d2;
#ifdef SPI_XKB_DEBUG
  fprintf (stderr, "MODIFIER CHANGE EVENT! %x to %x\n",
           prev_mask, current_mask);
#endif
  /* set bits for the virtual modifiers like NUMLOCK */
  if (prev_mask & _numlock_physical_mask)
    prev_mask |= SPI_KEYMASK_NUMLOCK;
  if (current_mask & _numlock_physical_mask)
    current_mask |= SPI_KEYMASK_NUMLOCK;
  d1 = prev_mask & key_modifier_mask;
  d2 = current_mask & key_modifier_mask;
  spi_dec_dbus_emit (controller, SPI_DBUS_INTERFACE_EVENT_KEYBOARD, "Modifiers", "", d1, d2);
}
static void
spi_dec_x11_generate_mouse_event (SpiDEController *controller,
                                  gint x,
                                  gint y,
                                  const char *eventName)
{
  int button = 0;
  gboolean err = FALSE;
  Display *display = spi_get_display ();
  switch (eventName[0])
    {
    case 'b':
      switch (eventName[1])
        {
        /* TODO: check number of buttons before parsing */
        case '1':
          button = 1;
          break;
        case '2':
          button = 2;
          break;
        case '3':
          button = 3;
          break;
        case '4':
          button = 4;
          break;
        case '5':
          button = 5;
          break;
        default:
          err = TRUE;
        }
      if (!err)
        {
          if (x != -1 && y != -1)
            {
              XTestFakeMotionEvent (display, DefaultScreen (display),
                                    x, y, 0);
            }
          XTestFakeButtonEvent (display, button, !(eventName[2] == 'r'), 0);
          if (eventName[2] == 'c')
            XTestFakeButtonEvent (display, button, FALSE, 1);
          else if (eventName[2] == 'd')
            {
              XTestFakeButtonEvent (display, button, FALSE, 1);
              XTestFakeButtonEvent (display, button, TRUE, 2);
              XTestFakeButtonEvent (display, button, FALSE, 3);
            }
        }
      break;
    case 'r': /* relative motion */
      XTestFakeRelativeMotionEvent (display, x, y, 0);
      break;
    case 'a': /* absolute motion */
      XTestFakeMotionEvent (display, DefaultScreen (display),
                            x, y, 0);
      break;
    }
}
void
28
spi_dec_setup_x11 (SpiDEControllerClass *klass)
{
28
  klass->plat.get_keycode = spi_dec_x11_get_keycode;
28
  klass->plat.mouse_check = spi_dec_x11_mouse_check;
28
  klass->plat.synth_keycode_press = spi_dec_x11_synth_keycode_press;
28
  klass->plat.synth_keycode_release = spi_dec_x11_synth_keycode_release;
28
  klass->plat.lock_modifiers = spi_dec_x11_lock_modifiers;
28
  klass->plat.unlock_modifiers = spi_dec_x11_unlock_modifiers;
28
  klass->plat.synth_keystring = spi_dec_x11_synth_keystring;
28
  klass->plat.grab_key = spi_dec_x11_grab_key;
28
  klass->plat.ungrab_key = spi_dec_x11_ungrab_key;
28
  klass->plat.emit_modifier_event = spi_dec_x11_emit_modifier_event;
28
  klass->plat.generate_mouse_event = spi_dec_x11_generate_mouse_event;
28
  klass->plat.init = spi_dec_x11_init;
28
  klass->plat.finalize = spi_dec_x11_finalize;
28
}