Patch 9.0.0868
Problem:    MS-Windows: after Vim exits console resizing does not work
            properly.
Solution:   Restore screen behavior checks for various WT and VTP
            combinations. (Christopher Plewright, closes #11526,
            closes #11507)
Files:      src/os_win32.c, src/proto/os_win32.pro


*** ../vim-9.0.0867/src/os_win32.c      2022-11-09 23:55:46.888274511 +0000
--- src/os_win32.c      2022-11-12 18:44:45.902743607 +0000
***************
*** 202,208 ****
  static void vtp_sgr_bulks(int argc, int *argv);
  
  static int wt_working = 0;
! static void wt_init();
  
  static int g_color_index_bg = 0;
  static int g_color_index_fg = 7;
--- 202,208 ----
  static void vtp_sgr_bulks(int argc, int *argv);
  
  static int wt_working = 0;
! static void wt_init(void);
  
  static int g_color_index_bg = 0;
  static int g_color_index_fg = 7;
***************
*** 238,243 ****
--- 238,244 ----
  static char_u *exe_path = NULL;
  
  static BOOL win8_or_later = FALSE;
+ static BOOL win11_or_later = FALSE;
  
  /*
   * Get version number including build number
***************
*** 893,898 ****
--- 894,903 ----
                || ovi.dwMajorVersion > 6)
            win8_or_later = TRUE;
  
+       if ((ovi.dwMajorVersion == 10 && ovi.dwBuildNumber >= 22000)
+               || ovi.dwMajorVersion > 10)
+           win11_or_later = TRUE;
+ 
  #ifdef HAVE_ACL
        // Enable privilege for getting or setting SACLs.
        win32_enable_privilege(SE_SECURITY_NAME, TRUE);
***************
*** 2683,2688 ****
--- 2688,2698 ----
      }
      cb->IsValid = TRUE;
  
+     // VTP uses alternate screen buffer.
+     // No need to save buffer contents for restoration.
+     if (win11_or_later && vtp_working)
+       return TRUE;
+ 
      /*
       * Allocate a buffer large enough to hold the entire console screen
       * buffer.  If this ConsoleBuffer structure has already been initialized
***************
*** 2776,2781 ****
--- 2786,2796 ----
      SMALL_RECT WriteRegion;
      int i;
  
+     // VTP uses alternate screen buffer.
+     // No need to restore buffer contents.
+     if (win11_or_later && vtp_working)
+       return TRUE;
+ 
      if (cb == NULL || !cb->IsValid)
        return FALSE;
  
***************
*** 5736,5742 ****
      if (g_fTermcapMode)
        return;
  
!     if (!p_rs && USE_VTP)
        vtp_printf("\033[?1049h");
  
      SaveConsoleBuffer(&g_cbNonTermcap);
--- 5751,5759 ----
      if (g_fTermcapMode)
        return;
  
!     // VTP uses alternate screen buffer.
!     // Switch to a new alternate screen buffer.
!     if (win11_or_later && p_rs && vtp_working)
        vtp_printf("\033[?1049h");
  
      SaveConsoleBuffer(&g_cbNonTermcap);
***************
*** 5816,5832 ****
  # endif
      RestoreConsoleBuffer(cb, p_rs);
      restore_console_color_rgb();
-     SetConsoleCursorInfo(g_hConOut, &g_cci);
  
!     if (p_rs || exiting)
      {
        /*
         * Clear anything that happens to be on the current line.
         */
        coord.X = 0;
        coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1));
!       FillConsoleOutputCharacter(g_hConOut, ' ',
!               cb->Info.dwSize.X, coord, &dwDummy);
        /*
         * The following is just for aesthetics.  If we are exiting without
         * restoring the screen, then we want to have a prompt string
--- 5833,5854 ----
  # endif
      RestoreConsoleBuffer(cb, p_rs);
      restore_console_color_rgb();
  
!     // VTP uses alternate screen buffer.
!     // Switch back to main screen buffer.
!     if (exiting && win11_or_later && p_rs && vtp_working)
!       vtp_printf("\033[?1049l");
! 
!     if (!USE_WT && (p_rs || exiting))
      {
        /*
         * Clear anything that happens to be on the current line.
         */
        coord.X = 0;
        coord.Y = (SHORT) (p_rs ? cb->Info.dwCursorPosition.Y : (Rows - 1));
!       if (!vtp_working)
!           FillConsoleOutputCharacter(g_hConOut, ' ',
!                   cb->Info.dwSize.X, coord, &dwDummy);
        /*
         * The following is just for aesthetics.  If we are exiting without
         * restoring the screen, then we want to have a prompt string
***************
*** 5842,5851 ****
         */
        SetConsoleCursorPosition(g_hConOut, coord);
      }
! 
!     if (!p_rs && USE_VTP)
!       vtp_printf("\033[?1049l");
! 
      g_fTermcapMode = FALSE;
  }
  #endif // !FEAT_GUI_MSWIN || VIMDLL
--- 5864,5870 ----
         */
        SetConsoleCursorPosition(g_hConOut, coord);
      }
!     SetConsoleCursorInfo(g_hConOut, &g_cci);
      g_fTermcapMode = FALSE;
  }
  #endif // !FEAT_GUI_MSWIN || VIMDLL
***************
*** 7946,7953 ****
   * Not stable now.
   */
  #define CONPTY_STABLE_BUILD       MAKE_VER(10, 0, 32767)  // T.B.D.
! // Note: Windows 11 (build >= 22000 means Windows 11, even though the major
! // version says 10!)
  
      static void
  vtp_flag_init(void)
--- 7965,7976 ----
   * Not stable now.
   */
  #define CONPTY_STABLE_BUILD       MAKE_VER(10, 0, 32767)  // T.B.D.
! // Notes:
! // Win 10 22H2 Final is build 19045, it's conpty is widely used.
! // Strangely, 19045 is newer but is a lower build number than the 2020 insider
! // preview which had a build 19587.  And, not sure how stable that was?
! // Win Server 2022 (May 10, 2022) is build 20348, its conpty is widely used.
! // Win 11 starts from build 22000, even though the major version says 10!
  
      static void
  vtp_flag_init(void)
***************
*** 8202,8214 ****
      static void
  wt_init(void)
  {
!     wt_working = (mch_getenv("WT_SESSION") != NULL);
! }
! 
!     int
! use_wt(void)
! {
!     return USE_WT;
  }
  
  # ifdef FEAT_TERMGUICOLORS
--- 8225,8231 ----
      static void
  wt_init(void)
  {
!     wt_working = mch_getenv("WT_SESSION") != NULL;
  }
  
  # ifdef FEAT_TERMGUICOLORS
*** ../vim-9.0.0867/src/proto/os_win32.pro      2022-06-27 23:15:34.000000000 
+0100
--- src/proto/os_win32.pro      2022-11-12 18:42:46.062679269 +0000
***************
*** 72,78 ****
  void fix_arg_enc(void);
  int mch_setenv(char *var, char *value, int x);
  int vtp_printf(char *format, ...);
- int use_wt(void);
  void get_default_console_color(int *cterm_fg, int *cterm_bg, guicolor_T 
*gui_fg, guicolor_T *gui_bg);
  void control_console_color_rgb(void);
  int use_vtp(void);
--- 72,77 ----
*** ../vim-9.0.0867/src/version.c       2022-11-12 17:44:08.268849881 +0000
--- src/version.c       2022-11-12 18:36:58.998487719 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     868,
  /**/

-- 
There is a difference between "should work" and "does work",
it's called testing.

 /// 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/20221112184636.5CB4B1C0473%40moolenaar.net.

Raspunde prin e-mail lui