From 0ed4cbfb2271f2df475a6bf05f5011abeb32b833 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann <jannis@xfce.org> Date: Sun, 7 Sep 2008 21:20:37 +0000 Subject: [PATCH] * settings-dialogs/frap-shortcuts.{c,h}, settings-dialogs/frap-shortcuts-dialog.c: Update to latest libfrap version. (Old svn revision: 27738) --- ChangeLog | 6 ++ settings-dialogs/frap-shortcuts-dialog.c | 3 +- settings-dialogs/frap-shortcuts.c | 130 +++++++++++++++++------ settings-dialogs/frap-shortcuts.h | 85 +++++++-------- 4 files changed, 148 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 37ab1b532..4c060ff39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-09-07 23:19 jannis + + * settings-dialogs/frap-shortcuts.{c,h}, + settings-dialogs/frap-shortcuts-dialog.c: Update to latest libfrap + version. + 2008-09-07 18:50 jannis * settings-dialogs/Makefile.am, settings-dialogs/frap-shortcuts.{c,h}, diff --git a/settings-dialogs/frap-shortcuts-dialog.c b/settings-dialogs/frap-shortcuts-dialog.c index 810219f67..d22aec9ac 100644 --- a/settings-dialogs/frap-shortcuts-dialog.c +++ b/settings-dialogs/frap-shortcuts-dialog.c @@ -312,7 +312,8 @@ frap_shortcuts_dialog_key_pressed (FrapShortcutsDialog *dialog, GdkEventKey *event) { /* Determine and remember the current shortcut */ - dialog->shortcut = frap_shortcuts_get_gdk_accelerator_name (event->keyval, event->state); + g_free (dialog->shortcut); + dialog->shortcut = frap_shortcuts_get_accelerator_name (event->keyval, event->state); return FALSE; } diff --git a/settings-dialogs/frap-shortcuts.c b/settings-dialogs/frap-shortcuts.c index 1e01b6f89..d73df1f93 100644 --- a/settings-dialogs/frap-shortcuts.c +++ b/settings-dialogs/frap-shortcuts.c @@ -64,6 +64,7 @@ static guint frap_shortcuts_x11_get_ignore_mask (void); static guint frap_shortcuts_x11_get_use_mask (void); static guint frap_shortcuts_gdk_remove_duplicate_modifiers (guint modifiers); static guint frap_shortcuts_x11_add_gdk_modifiers (guint modifiers); +static guint frap_shortcuts_gdk_add_x11_modifiers (guint modifiers); #if 0 static void frap_shortcuts_print_gdk_modifiers (guint modifiers); #endif @@ -238,7 +239,7 @@ frap_shortcuts_conflict_dialog (XfconfChannel *channel, if (xfconf_channel_get_property (channel, property, &value) && frap_shortcuts_parse_value (&value, &other_type, &other_action)) { - if ((type != other_type || g_utf8_collate (action, other_action) != 0) && !(type == other_type && ignore_same_type)) + if ((type != other_type || action == NULL || g_utf8_collate (action, other_action) != 0) && !(type == other_type && ignore_same_type)) { for (i = 0; conflict_messages[i].message != NULL; ++i) if (conflict_messages[i].owner_type == type && conflict_messages[i].other_type == other_type) @@ -334,20 +335,11 @@ frap_shortcuts_remove_shortcut (XfconfChannel *channel, -void -frap_shortcuts_get_gdk_accelerator (const gchar *name, - guint *keyval, - guint *modifiers) -{ - gtk_accelerator_parse (name, keyval, modifiers); -} - - - gchar * -frap_shortcuts_get_gdk_accelerator_name (guint keyval, - guint modifiers) +frap_shortcuts_get_accelerator_name (guint keyval, + guint modifiers) { + modifiers = frap_shortcuts_x11_add_gdk_modifiers (modifiers); modifiers = frap_shortcuts_gdk_remove_duplicate_modifiers (modifiers); return gtk_accelerator_name (keyval, modifiers); @@ -356,27 +348,15 @@ frap_shortcuts_get_gdk_accelerator_name (guint keyval, void -frap_shortcuts_get_x11_accelerator (const gchar *name, - guint *keyval, - guint *modifiers) +frap_shortcuts_parse_accelerator (const gchar *name, + guint *keyval, + guint *modifiers) { gtk_accelerator_parse (name, keyval, modifiers); } -gchar * -frap_shortcuts_get_x11_accelerator_name (guint keyval, - guint modifiers) -{ - modifiers = frap_shortcuts_x11_add_gdk_modifiers (modifiers); - modifiers = frap_shortcuts_gdk_remove_duplicate_modifiers (modifiers); - - return gtk_accelerator_name (keyval, modifiers); -} - - - void frap_shortcuts_set_shortcut_callback (FrapShortcutsFunc callback, gpointer user_data) @@ -437,13 +417,16 @@ frap_shortcuts_grab_shortcut (const gchar *shortcut, screens = gdk_display_get_n_screens (display); /* Parse the shortcut */ - frap_shortcuts_get_x11_accelerator (shortcut, &keyval, &modifiers); + frap_shortcuts_parse_accelerator (shortcut, &keyval, &modifiers); + + g_debug ("grab_shortcut: shortcut = %s, keyval = 0x%x, modifiers = 0x%x, ungrab = %i", shortcut, keyval, modifiers, ungrab); /* Determine mask containing ignored modifier bits */ ignore_mask = frap_shortcuts_x11_get_ignore_mask (); use_mask = frap_shortcuts_x11_get_use_mask (); /* Mask used modifiers */ + modifiers = frap_shortcuts_gdk_add_x11_modifiers (modifiers); modifiers &= use_mask; /* Determine keycode */ @@ -743,6 +726,93 @@ frap_shortcuts_x11_add_gdk_modifiers (guint modifiers) +static guint +frap_shortcuts_gdk_add_x11_modifiers (guint modifiers) +{ + XModifierKeymap *modmap; + const KeySym *keysyms; + Display *display; + KeyCode keycode; + KeySym *keymap; + guint modifiers_result = modifiers; + gint keysyms_per_keycode = 0; + gint min_keycode = 0; + gint max_keycode = 0; + gint mask; + gint i; + gint j; + + display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + + gdk_error_trap_push (); + + XDisplayKeycodes (display, &min_keycode, &max_keycode); + + keymap = XGetKeyboardMapping (display, min_keycode, max_keycode - min_keycode + 1, &keysyms_per_keycode); + + if (keymap == NULL) + return modifiers_result; + + modmap = XGetModifierMapping (display); + + if (modmap == NULL) + { + XFree (keymap); + return modifiers_result; + } + + for (i = 0; i < 8 * modmap->max_keypermod; ++i) + { + keycode = modmap->modifiermap[i]; + + if (keycode == 0 || keycode < min_keycode || keycode > max_keycode) + continue; + + keysyms = keymap + (keycode - min_keycode) * keysyms_per_keycode; + + mask = 1 << (i / modmap->max_keypermod); + + for (j = 0; j < keysyms_per_keycode; ++j) + { + switch (keysyms[j]) + { + case GDK_Super_L: + case GDK_Super_R: + if ((modifiers & GDK_SUPER_MASK) == GDK_SUPER_MASK) + modifiers_result |= mask; + break; + +#if 0 + case GDK_Hyper_L: + case GDK_Hyper_R: + if ((modifiers & GDK_HYPER_MASK) == GDK_HYPER_MASK) + modifiers_result |= mask; + break; +#endif + + case GDK_Meta_L: + case GDK_Meta_R: + if ((modifiers & GDK_META_MASK) == GDK_META_MASK) + modifiers_result |= mask; + break; + + default: + break; + } + } + } + + XFreeModifiermap (modmap); + XFree (keymap); + + gdk_flush (); + gdk_error_trap_pop (); + + return modifiers_result; +} + + + #if 0 static void frap_shortcuts_print_gdk_modifiers (guint modifiers) @@ -834,7 +904,7 @@ frap_shortcuts_handle_key_press (XKeyEvent *xevent) * callback for each of them */ keysym = XKeycodeToKeysym (GDK_DISPLAY_XDISPLAY (display), xevent->keycode, 0); - shortcut = frap_shortcuts_get_x11_accelerator_name (keysym, xevent->state); + shortcut = frap_shortcuts_get_accelerator_name (keysym, xevent->state); if (frap_shortcuts_callback_context.callback != NULL) frap_shortcuts_callback_context.callback (shortcut, frap_shortcuts_callback_context.user_data); diff --git a/settings-dialogs/frap-shortcuts.h b/settings-dialogs/frap-shortcuts.h index af08655df..7d02a97ac 100644 --- a/settings-dialogs/frap-shortcuts.h +++ b/settings-dialogs/frap-shortcuts.h @@ -40,52 +40,47 @@ typedef void (*FrapShortcutsFunc) (const gchar *shortcut, -XfconfChannel *frap_shortcuts_get_channel (void) G_GNUC_WARN_UNUSED_RESULT; -gchar *frap_shortcuts_get_property_name (const gchar *shortcut); -const gchar *frap_shortcuts_get_type_name (FrapShortcutsType type); -gboolean frap_shortcuts_parse_value (const GValue *value, - FrapShortcutsType *type, - gchar **action); -gboolean frap_shortcuts_has_shortcut (XfconfChannel *channel, - const gchar *shortcut); -gboolean frap_shortcuts_parse_shortcut (XfconfChannel *channel, - const gchar *shortcut, - FrapShortcutsType *type, - gchar **action); -gboolean frap_shortcuts_conflict_dialog (XfconfChannel *channel, - const gchar *shortcut, - const gchar *action, - FrapShortcutsType type, - gboolean ignore_same_type); -void frap_shortcuts_set_shortcut (XfconfChannel *channel, - const gchar *shortcut, - const gchar *action, - FrapShortcutsType type); -void frap_shortcuts_remove_shortcut (XfconfChannel *channel, - const gchar *shortcut); - -void frap_shortcuts_get_gdk_accelerator (const gchar *name, - guint *keyval, - guint *modifiers); -gchar *frap_shortcuts_get_gdk_accelerator_name (guint keyval, - guint modifiers); -void frap_shortcuts_get_x11_accelerator (const gchar *name, - guint *keyval, - guint *modifiers); -gchar *frap_shortcuts_get_x11_accelerator_name (guint keyval, - guint modifiers); +XfconfChannel *frap_shortcuts_get_channel (void) G_GNUC_WARN_UNUSED_RESULT; +gchar *frap_shortcuts_get_property_name (const gchar *shortcut); +const gchar *frap_shortcuts_get_type_name (FrapShortcutsType type); +gboolean frap_shortcuts_parse_value (const GValue *value, + FrapShortcutsType *type, + gchar **action); +gboolean frap_shortcuts_has_shortcut (XfconfChannel *channel, + const gchar *shortcut); +gboolean frap_shortcuts_parse_shortcut (XfconfChannel *channel, + const gchar *shortcut, + FrapShortcutsType *type, + gchar **action); +gboolean frap_shortcuts_conflict_dialog (XfconfChannel *channel, + const gchar *shortcut, + const gchar *action, + FrapShortcutsType type, + gboolean ignore_same_type); +void frap_shortcuts_set_shortcut (XfconfChannel *channel, + const gchar *shortcut, + const gchar *action, + FrapShortcutsType type); +void frap_shortcuts_remove_shortcut (XfconfChannel *channel, + const gchar *shortcut); + +gchar *frap_shortcuts_get_accelerator_name (guint keyval, + guint modifiers); +void frap_shortcuts_parse_accelerator (const gchar *name, + guint *keyval, + guint *modifiers); -void frap_shortcuts_set_shortcut_callback (FrapShortcutsFunc callback, - gpointer user_data); -void frap_shortcuts_add_filter (GdkFilterFunc callback, - gpointer user_data); -gboolean frap_shortcuts_grab_shortcut (const gchar *shortcut, - gboolean ungrab); -gboolean frap_shortcuts_grab_shortcut_real (Display *display, - Window window, - KeyCode keycode, - guint modifiers, - gboolean ungrab); +void frap_shortcuts_set_shortcut_callback (FrapShortcutsFunc callback, + gpointer user_data); +void frap_shortcuts_add_filter (GdkFilterFunc callback, + gpointer user_data); +gboolean frap_shortcuts_grab_shortcut (const gchar *shortcut, + gboolean ungrab); +gboolean frap_shortcuts_grab_shortcut_real (Display *display, + Window window, + KeyCode keycode, + guint modifiers, + gboolean ungrab); -- GitLab