]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0058: Cannot map Super Keys in GTK UI v9.1.0058
authorCasey Tucker <dctucker@hotmail.com>
Thu, 25 Jan 2024 21:44:00 +0000 (22:44 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 25 Jan 2024 21:44:00 +0000 (22:44 +0100)
Problem:  Cannot map Super Keys in GTK UI
          (Casey Tucker)
Solution: Enable Super Key mappings in GTK using <D-Key>
          (Casey Tucker)

As a developer who works in both Mac and Linux using the same keyboard,
it can be frustrating having to remember different key combinations or
having to rely on system utilities to remap keys.

This change allows `<D-z>` `<D-x>` `<D-c>` `<D-v>` etc. to be recognized
by the `map` commands, along with the `<D-S-...>` shifted variants.

```vimrc
if has('gui_gtk')
nnoremap  <D-z>    u
nnoremap  <D-S-Z>  <C-r>
vnoremap  <D-x>    "+d
vnoremap  <D-c>    "+y
cnoremap  <D-v>    <C-R>+
inoremap  <D-v>    <C-o>"+gP
nnoremap  <D-v>    "+P
vnoremap  <D-v>    "-d"+P
nnoremap  <D-s>    :w<CR>
inoremap  <D-s>    <C-o>:w<CR>
nnoremap  <D-w>    :q<CR>
nnoremap  <D-q>    :qa<CR>
nnoremap  <D-t>    :tabe<CR>
nnoremap  <D-S-T>  :vs#<CR><C-w>T
nnoremap  <D-a>    ggVG
vnoremap  <D-a>    <ESC>ggVG
inoremap  <D-a>    <ESC>ggVG
nnoremap  <D-f>    /
nnoremap  <D-g>    n
nnoremap  <D-S-G>  N
vnoremap  <D-x>    "+x
endif
```

closes: #12698

Signed-off-by: Casey Tucker <dctucker@hotmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/builtin.txt
runtime/doc/intro.txt
runtime/doc/map.txt
runtime/doc/tags
src/edit.c
src/gui_gtk_x11.c
src/gui_xim.c
src/keymap.h
src/misc2.c
src/testdir/test_mapping.vim
src/version.c

index 9b706ba20030fe9a3c0df7b85ec28da3a164ac86..88cf642ca4ec0403bef9133c506dc9def6a67913 100644 (file)
@@ -1,4 +1,4 @@
-*builtin.txt*  For Vim version 9.1.  Last change: 2024 Jan 23
+*builtin.txt*  For Vim version 9.1.  Last change: 2024 Jan 25
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -3470,7 +3470,7 @@ getcharmod()                                              *getcharmod()*
                        32      mouse double click
                        64      mouse triple click
                        96      mouse quadruple click (== 32 + 64)
-                       128     command (Macintosh only)
+                       128     command (Mac) or super (GTK)
                Only the modifiers that have not been included in the
                character itself are obtained.  Thus Shift-a results in "A"
                without a modifier.  Returns 0 if no modifiers are used.
index 185796f63f526dd181f585c89b76a1e221238ca7..120d65dc8561090e2799844c900b9e4ce07cc5b1 100644 (file)
@@ -1,4 +1,4 @@
-*intro.txt*     For Vim version 9.1.  Last change: 2023 Nov 18
+*intro.txt*     For Vim version 9.1.  Last change: 2024 Jan 25
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -475,7 +475,7 @@ notation    meaning             equivalent  decimal value(s)        ~
 <C-...>                control-key                     *control* *ctrl* *<C-*
 <M-...>                alt-key or meta-key             *meta* *alt* *<M-*
 <A-...>                same as <M-...>                 *<A-*
-<D-...>                command-key (Macintosh only)    *<D-*
+<D-...>                command-key (Mac) / super (GTK) *<D-*
 <t_xx>         key with "xx" entry in termcap
 -----------------------------------------------------------------------
 
index 7d4d53048daeca18289cdfc022c8a186d0ccc13c..cf83ffc0c830cdd28e73f6a4c49e4f9ae5423947 100644 (file)
@@ -1,4 +1,4 @@
-*map.txt*       For Vim version 9.1.  Last change: 2024 Jan 04
+*map.txt*       For Vim version 9.1.  Last change: 2024 Jan 25
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -21,9 +21,10 @@ manual.
    1.9 Using mappings                          |map-typing|
    1.10 Mapping alt-keys                       |:map-alt-keys|
    1.11 Mapping meta-keys                      |:map-meta-keys|
-   1.12 Mapping in modifyOtherKeys mode                |modifyOtherKeys|
-   1.13 Mapping with Kitty keyboard protocol   |kitty-keyboard-protocol|
-   1.14 Mapping an operator                    |:map-operator|
+   1.12 Mapping super-keys or command keys     |:map-super-keys|
+   1.13 Mapping in modifyOtherKeys mode                |modifyOtherKeys|
+   1.14 Mapping with Kitty keyboard protocol   |kitty-keyboard-protocol|
+   1.15 Mapping an operator                    |:map-operator|
 2. Abbreviations               |abbreviations|
 3. Local mappings and functions        |script-local|
 4. User-defined commands       |user-commands|
@@ -985,8 +986,17 @@ For the Meta modifier the "T" character is used.  For example, to map Meta-b
 in Insert mode: >
        :imap <T-b> terrible
 
+1.12 MAPPING SUPER-KEYS or COMMAND-KEYS                *:map-super-keys* *:map-cmd-key*
 
-1.12 MAPPING IN modifyOtherKeys mode                   *modifyOtherKeys*
+The Super modifier is available in GUI mode (when |gui_running| is 1) for
+GVim on Linux and MacVim on Mac OS. If you're on a Mac, this represents the
+Command key, on Linux with the GTK GUI it represents the Super key.
+The character "D" is used for the Super / Command modifier.
+
+For example, to map Command-b in Insert mode: >
+       :imap <D-b> barritone
+
+1.13 MAPPING IN modifyOtherKeys mode                   *modifyOtherKeys*
 
 Xterm and a few other terminals can be put in a mode where keys with modifiers
 are sent with a special escape code.  Vim recognizes these codes and can then
@@ -1048,7 +1058,7 @@ When the 'esckeys' option is off, then modifyOtherKeys will be disabled in
 Insert mode to avoid every key with a modifier causing Insert mode to end.
 
 
-1.13 MAPPING WITH KITTY KEYBOARD PROTOCOL       *kitty-keyboard-protocol*
+1.14 MAPPING WITH KITTY KEYBOARD PROTOCOL       *kitty-keyboard-protocol*
 
 If the value of 'term' contains "kitty" then Vim will send out an escape
 sequence to enable the Kitty keyboard protocol.  This can be changed with the
@@ -1075,7 +1085,7 @@ translated).  The meaning of {value}:
                        previous state is unknown
 
 
-1.14 MAPPING AN OPERATOR                               *:map-operator*
+1.15 MAPPING AN OPERATOR                               *:map-operator*
 
 An operator is used before a {motion} command.  To define your own operator
 you must create a mapping that first sets the 'operatorfunc' option and then
index 809c6fd33f0c776b17d1b6d637600cfbf93a7cd3..9a89916e082be985877982b926585aca3a753dcf 100644 (file)
@@ -2873,6 +2873,7 @@ $quote    eval.txt        /*$quote*
 :map-arguments map.txt /*:map-arguments*
 :map-buffer    map.txt /*:map-buffer*
 :map-cmd       map.txt /*:map-cmd*
+:map-cmd-key   map.txt /*:map-cmd-key*
 :map-commands  map.txt /*:map-commands*
 :map-expression        map.txt /*:map-expression*
 :map-local     map.txt /*:map-local*
@@ -2885,6 +2886,7 @@ $quote    eval.txt        /*$quote*
 :map-special   map.txt /*:map-special*
 :map-special-chars     map.txt /*:map-special-chars*
 :map-special-keys      map.txt /*:map-special-keys*
+:map-super-keys        map.txt /*:map-super-keys*
 :map-undo      map.txt /*:map-undo*
 :map-unique    map.txt /*:map-unique*
 :map-verbose   map.txt /*:map-verbose*
index 672028bbbae7f1d298b1723952b2648a8b47dd1c..e9a994f6b28fcb4d0753b8335fa1d96a6a896253 100644 (file)
@@ -2023,7 +2023,7 @@ insert_special(
      * Only use mod_mask for special keys, to avoid things like <S-Space>,
      * unless 'allow_modmask' is TRUE.
      */
-#ifdef MACOS_X
+#if defined(MACOS_X) || defined(FEAT_GUI_GTK)
     // Command-key never produces a normal key
     if (mod_mask & MOD_MASK_CMD)
        allow_modmask = TRUE;
index 87838b948881459ba7b4cd4244f7257d903b1bf3..4dfa5ff3cbdec401d8bab12c10a4c059404f2c72 100644 (file)
@@ -1119,11 +1119,14 @@ modifiers_gdk2vim(guint state)
     if (state & GDK_MOD1_MASK)
        modifiers |= MOD_MASK_ALT;
 #if GTK_CHECK_VERSION(2,10,0)
-    if (state & GDK_SUPER_MASK)
+    if (state & GDK_META_MASK)
        modifiers |= MOD_MASK_META;
-#endif
+    if (state & GDK_SUPER_MASK)
+       modifiers |= MOD_MASK_CMD;
+#else
     if (state & GDK_MOD4_MASK)
-       modifiers |= MOD_MASK_META;
+       modifiers |= MOD_MASK_CMD;
+#endif
 
     return modifiers;
 }
index c9b1c6cb4da79d7930ba8b27478eeaf00b90e849..c124e8b71ead2217fc3ead57dcaf6ca9746aea2a 100644 (file)
@@ -1063,6 +1063,9 @@ xim_reset(void)
     int
 xim_queue_key_press_event(GdkEventKey *event, int down)
 {
+#ifdef FEAT_GUI_GTK
+    if (event->state & GDK_SUPER_MASK) return FALSE;
+#endif
     if (down)
     {
        // Workaround GTK2 XIM 'feature' that always converts keypad keys to
index 6fddc7f56517cde894345d647737a59cb4dabb99..29e2a055ca671850fcd65e5edb37424db4131987 100644 (file)
@@ -500,8 +500,8 @@ enum key_extra
 #define MOD_MASK_2CLICK            0x20        // use MOD_MASK_MULTI_CLICK
 #define MOD_MASK_3CLICK            0x40        // use MOD_MASK_MULTI_CLICK
 #define MOD_MASK_4CLICK            0x60        // use MOD_MASK_MULTI_CLICK
-#ifdef MACOS_X
-# define MOD_MASK_CMD      0x80
+#if defined(MACOS_X) || defined(FEAT_GUI_GTK)
+# define MOD_MASK_CMD      0x80        // aka SUPER
 #endif
 
 #define MOD_MASK_MULTI_CLICK   (MOD_MASK_2CLICK|MOD_MASK_3CLICK|MOD_MASK_4CLICK)
index 169eb5197cfe2e0bcda4bb67a8e87acced0e338b..57ee287a4bf2fb93c64045f1e09f339bc85c3b64 100644 (file)
@@ -817,7 +817,7 @@ static struct modmasktable
     {MOD_MASK_MULTI_CLICK,     MOD_MASK_2CLICK,        (char_u)'2'},
     {MOD_MASK_MULTI_CLICK,     MOD_MASK_3CLICK,        (char_u)'3'},
     {MOD_MASK_MULTI_CLICK,     MOD_MASK_4CLICK,        (char_u)'4'},
-#ifdef MACOS_X
+#if defined(MACOS_X) || defined(FEAT_GUI_GTK)
     {MOD_MASK_CMD,             MOD_MASK_CMD,           (char_u)'D'},
 #endif
     // 'A' must be the last one
@@ -1130,7 +1130,11 @@ simplify_key(int key, int *modifiers)
     int            key0;
     int            key1;
 
-    if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)))
+    if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT
+#ifdef FEAT_GUI_GTK
+           | MOD_MASK_CMD
+#endif
+    )))
        return key;
 
     // TAB is a special case
@@ -1582,6 +1586,9 @@ may_remove_shift_modifier(int modifiers, int key)
 {
     if ((modifiers == MOD_MASK_SHIFT
                || modifiers == (MOD_MASK_SHIFT | MOD_MASK_ALT)
+#ifdef FEAT_GUI_GTK
+               || modifiers == (MOD_MASK_SHIFT | MOD_MASK_CMD)
+#endif
                || modifiers == (MOD_MASK_SHIFT | MOD_MASK_META))
            && ((key >= '!' && key <= '/')
                || (key >= ':' && key <= 'Z')
index e81173d2bc26816f276ceedd268abb2918357b6e..e361f3e65d51452d39d0b7ab149c37a96f06902a 100644 (file)
@@ -247,6 +247,24 @@ func Test_map_meta_multibyte()
   iunmap <M-á>
 endfunc
 
+func Test_map_super_quotes()
+  if has('gui_gtk') || has('gui_gtk3') || has("macos")
+    imap <D-"> foo
+    call feedkeys("Go-\<*D-\">-\<Esc>", "xt")
+    call assert_equal("-foo-", getline('$'))
+    set nomodified
+    iunmap <D-">
+  endif
+endfunc
+
+func Test_map_super_multibyte()
+  if has('gui_gtk') || has('gui_gtk3') || has("macos")
+    imap <D-á> foo
+    call assert_match('i  <D-á>\s*foo', execute('imap'))
+    iunmap <D-á>
+  endif
+endfunc
+
 func Test_abbr_after_line_join()
   new
   abbr foo bar
index 8f13f3f18d62bce66fb96714e9517d75a197278b..10a70e3c01d0686e4d6a2bac2f88b10c2d285562 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    58,
 /**/
     57,
 /**/