From db169f81346f3a642b645937218dc3d1dae3301f Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Thu, 26 Nov 2020 23:44:29 +0900 Subject: [PATCH] Add support for hyper modifier key * src/pgtkterm.c (x_find_modifier_meanings): Autodetect key mask. (pgtk_gtk_to_emacs_modifiers): Use autodetected mask instead of GDK's. (pgtk_emacs_to_gtk_modifiers): Use autodetected mask instead of GDK's. (key_press_event): Ignore hyper as well as super. * src/pgtkterm.h (struct pgtk_display_info): New member for hyper. --- src/pgtkterm.c | 27 +++++++++++++++++++++++---- src/pgtkterm.h | 2 +- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 6f2bb2898b2..0cf9bb84e76 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -5441,6 +5441,25 @@ x_find_modifier_meanings (struct pgtk_display_info *dpyinfo) { dpyinfo->super_mod_mask = GDK_MOD4_MASK; } + + state = GDK_HYPER_MASK; + r = gdk_keymap_map_virtual_modifiers (keymap, &state); + if (r) + { + /* Hyper key exists. */ + if (state == GDK_HYPER_MASK) + { + dpyinfo->hyper_mod_mask = GDK_MOD3_MASK; /* maybe this is hyper. */ + } + else + { + dpyinfo->hyper_mod_mask = state & ~GDK_HYPER_MASK; + } + } + else + { + dpyinfo->hyper_mod_mask = GDK_MOD3_MASK; + } } static void @@ -5497,7 +5516,7 @@ pgtk_gtk_to_emacs_modifiers (struct pgtk_display_info *dpyinfo, int state) mod |= mod_alt; if (state & dpyinfo->super_mod_mask) mod |= mod_super; - if (state & GDK_HYPER_MASK) + if (state & dpyinfo->hyper_mod_mask) mod |= mod_hyper; return mod; } @@ -5521,7 +5540,7 @@ pgtk_emacs_to_gtk_modifiers (struct pgtk_display_info *dpyinfo, int state) if (state & mod_super) mask |= dpyinfo->super_mod_mask; if (state & mod_hyper) - mask |= GDK_HYPER_MASK; + mask |= dpyinfo->hyper_mod_mask; if (state & shift_modifier) mask |= GDK_SHIFT_MASK; if (state & mod_ctrl) @@ -5613,10 +5632,10 @@ key_press_event (GtkWidget * widget, GdkEvent * event, gpointer * user_data) { /* While super is pressed, gtk_im_context_filter_keypress() always process the * key events ignoring super. - * As a work around, don't call it while super is pressed... + * As a work around, don't call it while super or hyper are pressed... */ struct pgtk_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); - if (!(event->key.state & dpyinfo->super_mod_mask)) + if (!(event->key.state & (dpyinfo->super_mod_mask | dpyinfo->hyper_mod_mask))) { if (pgtk_im_filter_keypress (f, &event->key)) return TRUE; diff --git a/src/pgtkterm.h b/src/pgtkterm.h index a777885518e..09b3b21b170 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -235,7 +235,7 @@ struct pgtk_display_info struct frame *last_mouse_glyph_frame; /* Modifier masks in gdk */ - int meta_mod_mask, alt_mod_mask, super_mod_mask; + int meta_mod_mask, alt_mod_mask, super_mod_mask, hyper_mod_mask; /* The last click event. */ GdkEvent *last_click_event; -- 2.39.5