~ubuntu-branches/ubuntu/trusty/libxfce4ui/trusty

« back to all changes in this revision

Viewing changes to libxfce4kbd-private/xfce-shortcut-dialog.c

  • Committer: Package Import Robot
  • Author(s): Yves-Alexis Perez
  • Date: 2013-05-21 21:32:57 UTC
  • mfrom: (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130521213257-q5nqhxkutb9ze4ld
Tags: 4.10.0-2
* Upload to unstable.
* debian/rules:
  - enable all hardening flags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* vi:set expandtab sw=2 sts=2: */
2
 
/*-
 
2
/*
3
3
 * Copyright (c) 2008 Jannis Pohlmann <jannis@xfce.org>
4
4
 *
5
5
 * This library is free software; you can redistribute it and/or
43
43
                                                       GdkEventKey             *event);
44
44
static gboolean xfce_shortcut_dialog_key_released     (XfceShortcutDialog      *dialog,
45
45
                                                       GdkEventKey             *event);
46
 
static gchar   *xfce_shortcut_dialog_shortcut_name    (XfceShortcutDialog      *dialog,
47
 
                                                       guint                    keyval,
48
 
                                                       guint                    modifiers);
49
46
 
50
47
 
51
48
 
312
309
xfce_shortcut_dialog_key_pressed (XfceShortcutDialog *dialog,
313
310
                                  GdkEventKey        *event)
314
311
{
315
 
  gchar *text;
316
 
  gchar *shortcut;
 
312
  GdkKeymap       *keymap;
 
313
  GdkModifierType  consumed, modifiers;
 
314
  guint            keyval, mod_mask;
 
315
  gchar           *text;
 
316
  gchar           *shortcut;
317
317
 
318
318
  g_free (dialog->shortcut);
319
319
 
320
 
  /* Determine and remember the current shortcut */
321
 
  dialog->shortcut = xfce_shortcut_dialog_shortcut_name (dialog, event->keyval, event->state);
 
320
  /* Get the keyboard state */
 
321
  mod_mask = gtk_accelerator_get_default_mod_mask ();
 
322
  keymap = gdk_keymap_get_default ();
 
323
  modifiers = event->state;
 
324
 
 
325
  gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
 
326
                                       modifiers, 0,
 
327
                                       &keyval, NULL, NULL, &consumed);
 
328
 
 
329
  /* Get the modifiers */
 
330
  modifiers &= ~consumed;
 
331
  modifiers &= mod_mask;
 
332
 
 
333
  /* Get and store the pressed shortcut */
 
334
  dialog->shortcut = gtk_accelerator_name (keyval, modifiers);
322
335
 
323
336
  shortcut = g_markup_escape_text (dialog->shortcut, -1);
324
337
  text = g_strdup_printf ("<span size='large'><b>%s</b></span>", shortcut);
362
375
 
363
376
 
364
377
 
365
 
static gchar *
366
 
xfce_shortcut_dialog_shortcut_name (XfceShortcutDialog *dialog,
367
 
                                    guint               keyval,
368
 
                                    guint               modifiers)
369
 
{
370
 
  XModifierKeymap *modmap;
371
 
  Display         *display;
372
 
  const KeySym    *keysyms;
373
 
  KeyCode          keycode;
374
 
  KeySym          *keymap;
375
 
  gint             keysyms_per_keycode = 0;
376
 
  gint             min_keycode = 0;
377
 
  gint             max_keycode = 0;
378
 
  gint             mask;
379
 
  gint             i;
380
 
  gint             j;
381
 
 
382
 
  g_return_val_if_fail (XFCE_IS_SHORTCUT_DIALOG (dialog), NULL);
383
 
 
384
 
  display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
385
 
 
386
 
  gdk_error_trap_push ();
387
 
 
388
 
  XDisplayKeycodes (display, &min_keycode, &max_keycode);
389
 
 
390
 
  keymap = XGetKeyboardMapping (display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode);
391
 
 
392
 
  if (G_LIKELY (keymap != NULL))
393
 
    {
394
 
      modmap = XGetModifierMapping (display);
395
 
 
396
 
      if (G_LIKELY (modmap != NULL))
397
 
        {
398
 
          for (i = 0; i < 8 * modmap->max_keypermod; ++i)
399
 
            {
400
 
              keycode = modmap->modifiermap[i];
401
 
 
402
 
              if (keycode == 0 || keycode < min_keycode || keycode > max_keycode)
403
 
                continue;
404
 
 
405
 
              keysyms = keymap + (keycode - min_keycode) * keysyms_per_keycode;
406
 
              mask = 1 << (i / modmap->max_keypermod);
407
 
 
408
 
              for (j = 0; j < keysyms_per_keycode; ++j)
409
 
                {
410
 
                  if (keysyms[j] == GDK_Super_L || keysyms[j] == GDK_Super_R)
411
 
                    modifiers &= ~mask;
412
 
 
413
 
#if 0
414
 
                  if (keysyms[j] == GDK_Meta_L || keysyms[j] == GDK_Meta_R)
415
 
                    modifiers &= ~mask;
416
 
#endif
417
 
 
418
 
                  if (keysyms[j] == GDK_Hyper_L || keysyms[j] == GDK_Hyper_R)
419
 
                    modifiers &= ~mask;
420
 
 
421
 
                  if (keysyms[j] == GDK_Scroll_Lock)
422
 
                    modifiers &= ~mask;
423
 
 
424
 
                  if (keysyms[j] == GDK_Num_Lock)
425
 
                    modifiers &= ~mask;
426
 
 
427
 
                  if (keysyms[j] == GDK_Caps_Lock)
428
 
                    modifiers &= ~mask;
429
 
                }
430
 
            }
431
 
 
432
 
          XFreeModifiermap (modmap);
433
 
        }
434
 
 
435
 
      XFree (keymap);
436
 
    }
437
 
 
438
 
  gdk_flush ();
439
 
  gdk_error_trap_pop ();
440
 
 
441
 
  return gtk_accelerator_name (keyval, modifiers);
442
 
}
443
 
 
444
 
 
445
 
 
446
378
const gchar*
447
379
xfce_shortcut_dialog_get_shortcut (XfceShortcutDialog *dialog)
448
380
{