312
309
xfce_shortcut_dialog_key_pressed (XfceShortcutDialog *dialog,
313
310
GdkEventKey *event)
313
GdkModifierType consumed, modifiers;
314
guint keyval, mod_mask;
318
318
g_free (dialog->shortcut);
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;
325
gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
327
&keyval, NULL, NULL, &consumed);
329
/* Get the modifiers */
330
modifiers &= ~consumed;
331
modifiers &= mod_mask;
333
/* Get and store the pressed shortcut */
334
dialog->shortcut = gtk_accelerator_name (keyval, modifiers);
323
336
shortcut = g_markup_escape_text (dialog->shortcut, -1);
324
337
text = g_strdup_printf ("<span size='large'><b>%s</b></span>", shortcut);
366
xfce_shortcut_dialog_shortcut_name (XfceShortcutDialog *dialog,
370
XModifierKeymap *modmap;
372
const KeySym *keysyms;
375
gint keysyms_per_keycode = 0;
376
gint min_keycode = 0;
377
gint max_keycode = 0;
382
g_return_val_if_fail (XFCE_IS_SHORTCUT_DIALOG (dialog), NULL);
384
display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
386
gdk_error_trap_push ();
388
XDisplayKeycodes (display, &min_keycode, &max_keycode);
390
keymap = XGetKeyboardMapping (display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode);
392
if (G_LIKELY (keymap != NULL))
394
modmap = XGetModifierMapping (display);
396
if (G_LIKELY (modmap != NULL))
398
for (i = 0; i < 8 * modmap->max_keypermod; ++i)
400
keycode = modmap->modifiermap[i];
402
if (keycode == 0 || keycode < min_keycode || keycode > max_keycode)
405
keysyms = keymap + (keycode - min_keycode) * keysyms_per_keycode;
406
mask = 1 << (i / modmap->max_keypermod);
408
for (j = 0; j < keysyms_per_keycode; ++j)
410
if (keysyms[j] == GDK_Super_L || keysyms[j] == GDK_Super_R)
414
if (keysyms[j] == GDK_Meta_L || keysyms[j] == GDK_Meta_R)
418
if (keysyms[j] == GDK_Hyper_L || keysyms[j] == GDK_Hyper_R)
421
if (keysyms[j] == GDK_Scroll_Lock)
424
if (keysyms[j] == GDK_Num_Lock)
427
if (keysyms[j] == GDK_Caps_Lock)
432
XFreeModifiermap (modmap);
439
gdk_error_trap_pop ();
441
return gtk_accelerator_name (keyval, modifiers);
447
379
xfce_shortcut_dialog_get_shortcut (XfceShortcutDialog *dialog)