Patch 8.2.4817
Problem:    Win32 GUI: modifiers are not always used.
Solution:   Handle more modifiers. (closes #10269)
Files:      src/gui_w32.c


*** ../vim-8.2.4816/src/gui_w32.c       2022-04-23 11:08:04.069415342 +0100
--- src/gui_w32.c       2022-04-24 15:41:23.484233340 +0100
***************
*** 818,823 ****
--- 818,843 ----
      return len;
  }
  
+     static int
+ get_active_modifiers(void)
+ {
+     int modifiers = 0;
+ 
+     if (GetKeyState(VK_CONTROL) & 0x8000)
+       modifiers |= MOD_MASK_CTRL;
+     if (GetKeyState(VK_SHIFT) & 0x8000)
+       modifiers |= MOD_MASK_SHIFT;
+     if (GetKeyState(VK_MENU) & 0x8000)
+       modifiers |= MOD_MASK_ALT;
+     // Windows handles Ctrl + Alt as AltGr, in that case no modifier is 
actually
+     // pressed.
+     if ((modifiers & (MOD_MASK_CTRL | MOD_MASK_ALT)) ==
+           (MOD_MASK_CTRL | MOD_MASK_ALT))
+       modifiers &= ~(MOD_MASK_CTRL | MOD_MASK_ALT);
+ 
+     return modifiers;
+ }
+ 
  /*
   * Key hit, add it to the input buffer.
   */
***************
*** 829,843 ****
  {
      char_u    string[40];
      int               len = 0;
!     int               modifiers = 0;
      int               ch = cch;   // special keys are negative
  
      dead_key = 0;
  
!     if (GetKeyState(VK_SHIFT) & 0x8000)
!       modifiers |= MOD_MASK_SHIFT;
!     if (GetKeyState(VK_CONTROL) & 0x8000)
!       modifiers |= MOD_MASK_CTRL;
  
      ch = simplify_key(ch, &modifiers);
      // remove the SHIFT modifier for keys where it's already included, e.g.,
--- 849,860 ----
  {
      char_u    string[40];
      int               len = 0;
!     int               modifiers;
      int               ch = cch;   // special keys are negative
  
      dead_key = 0;
  
!     modifiers = get_active_modifiers();
  
      ch = simplify_key(ch, &modifiers);
      // remove the SHIFT modifier for keys where it's already included, e.g.,
***************
*** 887,898 ****
      // ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note
      // that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless
      // CAPSLOCK is pressed) at this point.
!     modifiers = MOD_MASK_ALT;
!     if (GetKeyState(VK_SHIFT) & 0x8000)
!       modifiers |= MOD_MASK_SHIFT;
!     if (GetKeyState(VK_CONTROL) & 0x8000)
!       modifiers |= MOD_MASK_CTRL;
! 
      ch = simplify_key(ch, &modifiers);
      // remove the SHIFT modifier for keys where it's already included, e.g.,
      // '(' and '*'
--- 904,910 ----
      // ALT key pressed. Eg, if the user presses Alt-A, then ch == 'A'. Note
      // that the system distinguishes Alt-a and Alt-A (Alt-Shift-a unless
      // CAPSLOCK is pressed) at this point.
!     modifiers = get_active_modifiers();
      ch = simplify_key(ch, &modifiers);
      // remove the SHIFT modifier for keys where it's already included, e.g.,
      // '(' and '*'
***************
*** 1917,1926 ****
--- 1929,1946 ----
             * VK_BACK, or VK_ESCAPE it means that he actually wants to deal
             * with the dead char now, so do nothing special and let Windows
             * handle it.
+            *
+            * Note that VK_SPACE combines with the dead_key's character and
+            * only one WM_CHAR will be generated by TranslateMessage(), in
+            * the two other cases two WM_CHAR will be generated: the dead
+            * char and VK_BACK or VK_ESCAPE. That is most likely what the
+            * user expects.
             */
            if ((vk == VK_SPACE || vk == VK_BACK || vk == VK_ESCAPE))
            {
                dead_key = 0;
+               TranslateMessage(&msg);
+               return;
            }
            // In modes where we are not typing, dead keys should behave
            // normally
***************
*** 1976,1996 ****
                                                          NULL, NULL) == NULL)
                    break;
  #endif
!               if (GetKeyState(VK_SHIFT) & 0x8000)
!                   modifiers |= MOD_MASK_SHIFT;
!               /*
!                * Don't use caps-lock as shift, because these are special keys
!                * being considered here, and we only want letters to get
!                * shifted -- webb
!                */
!               /*
!               if (GetKeyState(VK_CAPITAL) & 0x0001)
!                   modifiers ^= MOD_MASK_SHIFT;
!               */
!               if (GetKeyState(VK_CONTROL) & 0x8000)
!                   modifiers |= MOD_MASK_CTRL;
!               if (GetKeyState(VK_MENU) & 0x8000)
!                   modifiers |= MOD_MASK_ALT;
  
                if (special_keys[i].vim_code1 == NUL)
                    key = special_keys[i].vim_code0;
--- 1996,2002 ----
                                                          NULL, NULL) == NULL)
                    break;
  #endif
!               modifiers = get_active_modifiers();
  
                if (special_keys[i].vim_code1 == NUL)
                    key = special_keys[i].vim_code0;
***************
*** 2036,2048 ****
            int         i;
            UINT        scan_code;
  
-           if (GetKeyState(VK_SHIFT) & 0x8000)
-               modifiers |= MOD_MASK_SHIFT;
-           if (GetKeyState(VK_CONTROL) & 0x8000)
-               modifiers |= MOD_MASK_CTRL;
-           if (GetKeyState(VK_LMENU) & 0x8000)
-               modifiers |= MOD_MASK_ALT;
- 
            // Construct the state table with only a few modifiers, we don't
            // really care about the presence of Ctrl/Alt as those modifiers are
            // handled by Vim separately.
--- 2042,2047 ----
***************
*** 2051,2057 ****
                keyboard_state[VK_SHIFT] = 0x80;
            if (GetKeyState(VK_CAPITAL) & 0x0001)
                keyboard_state[VK_CAPITAL] = 0x01;
!           if (GetKeyState(VK_RMENU) & 0x8000)
            {
                keyboard_state[VK_MENU] = 0x80;
                keyboard_state[VK_CONTROL] = 0x80;
--- 2050,2058 ----
                keyboard_state[VK_SHIFT] = 0x80;
            if (GetKeyState(VK_CAPITAL) & 0x0001)
                keyboard_state[VK_CAPITAL] = 0x01;
!           // Alt-Gr is synthesized as Alt + Ctrl.
!           if ((GetKeyState(VK_MENU) & 0x8000) &&
!                   (GetKeyState(VK_CONTROL) & 0x8000))
            {
                keyboard_state[VK_MENU] = 0x80;
                keyboard_state[VK_CONTROL] = 0x80;
***************
*** 3795,3805 ****
  
      if (fnames != NULL)
      {
!       if ((GetKeyState(VK_SHIFT) & 0x8000) != 0)
            modifiers |= MOUSE_SHIFT;
!       if ((GetKeyState(VK_CONTROL) & 0x8000) != 0)
            modifiers |= MOUSE_CTRL;
!       if ((GetKeyState(VK_MENU) & 0x8000) != 0)
            modifiers |= MOUSE_ALT;
  
        gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles);
--- 3796,3808 ----
  
      if (fnames != NULL)
      {
!       int kbd_modifiers = get_active_modifiers();
! 
!       if ((kbd_modifiers & MOD_MASK_SHIFT) != 0)
            modifiers |= MOUSE_SHIFT;
!       if ((kbd_modifiers & MOD_MASK_CTRL) != 0)
            modifiers |= MOUSE_CTRL;
!       if ((kbd_modifiers & MOD_MASK_ALT) != 0)
            modifiers |= MOUSE_ALT;
  
        gui_handle_drop(pt.x, pt.y, modifiers, fnames, cFiles);
*** ../vim-8.2.4816/src/version.c       2022-04-24 12:44:29.206042724 +0100
--- src/version.c       2022-04-24 15:42:55.380299261 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4817,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
39. You move into a new house and setup the Wifi router before
    unpacking any kitchen stuff.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220424144745.3EA151C43E7%40moolenaar.net.

Raspunde prin e-mail lui