comparison src/os_win32.c @ 26336:a2e6da79274d v8.2.3699

patch 8.2.3699: the +title feature adds a lot of #ifdef but little code Commit: https://github.com/vim/vim/commit/651fca85c71a4c5807f8f828f9ded30fbd754325 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 29 20:39:38 2021 +0000 patch 8.2.3699: the +title feature adds a lot of #ifdef but little code Problem: The +title feature adds a lot of #ifdef but little code. Solution: Graduate the +title feature.
author Bram Moolenaar <Bram@vim.org>
date Mon, 29 Nov 2021 21:45:04 +0100
parents fa8161b003f6
children fc859aea8cec
comparison
equal deleted inserted replaced
26335:c12a888d1f63 26336:a2e6da79274d
44 #else 44 #else
45 # include <direct.h> 45 # include <direct.h>
46 #endif 46 #endif
47 47
48 #ifndef PROTO 48 #ifndef PROTO
49 # if defined(FEAT_TITLE) && !defined(FEAT_GUI_MSWIN) 49 # if !defined(FEAT_GUI_MSWIN)
50 # include <shellapi.h> 50 # include <shellapi.h>
51 # endif 51 # endif
52 #endif 52 #endif
53 53
54 #ifdef FEAT_JOB_CHANNEL 54 #ifdef FEAT_JOB_CHANNEL
2681 static ConsoleBuffer g_cbOrig = { 0 }; 2681 static ConsoleBuffer g_cbOrig = { 0 };
2682 # endif 2682 # endif
2683 static ConsoleBuffer g_cbNonTermcap = { 0 }; 2683 static ConsoleBuffer g_cbNonTermcap = { 0 };
2684 static ConsoleBuffer g_cbTermcap = { 0 }; 2684 static ConsoleBuffer g_cbTermcap = { 0 };
2685 2685
2686 # ifdef FEAT_TITLE
2687 char g_szOrigTitle[256] = { 0 }; 2686 char g_szOrigTitle[256] = { 0 };
2688 HWND g_hWnd = NULL; // also used in os_mswin.c 2687 HWND g_hWnd = NULL; // also used in os_mswin.c
2689 static HICON g_hOrigIconSmall = NULL; 2688 static HICON g_hOrigIconSmall = NULL;
2690 static HICON g_hOrigIcon = NULL; 2689 static HICON g_hOrigIcon = NULL;
2691 static HICON g_hVimIcon = NULL; 2690 static HICON g_hVimIcon = NULL;
2692 static BOOL g_fCanChangeIcon = FALSE; 2691 static BOOL g_fCanChangeIcon = FALSE;
2693 2692
2694 // ICON* are not defined in VC++ 4.0 2693 // ICON* are not defined in VC++ 4.0
2695 # ifndef ICON_SMALL 2694 # ifndef ICON_SMALL
2696 # define ICON_SMALL 0 2695 # define ICON_SMALL 0
2697 # endif 2696 # endif
2698 # ifndef ICON_BIG 2697 # ifndef ICON_BIG
2699 # define ICON_BIG 1 2698 # define ICON_BIG 1
2700 # endif 2699 # endif
2701 /* 2700 /*
2702 * GetConsoleIcon() 2701 * GetConsoleIcon()
2703 * Description: 2702 * Description:
2704 * Attempts to retrieve the small icon and/or the big icon currently in 2703 * Attempts to retrieve the small icon and/or the big icon currently in
2705 * use by a given window. 2704 * use by a given window.
2787 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL) 2786 if (mch_icon_load((HANDLE *)&g_hVimIcon) == FAIL || g_hVimIcon == NULL)
2788 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0); 2787 g_hVimIcon = ExtractIcon(NULL, (LPCSTR)exe_name, 0);
2789 if (g_hVimIcon != NULL) 2788 if (g_hVimIcon != NULL)
2790 g_fCanChangeIcon = TRUE; 2789 g_fCanChangeIcon = TRUE;
2791 } 2790 }
2792 # endif
2793 2791
2794 static int g_fWindInitCalled = FALSE; 2792 static int g_fWindInitCalled = FALSE;
2795 static int g_fTermcapMode = FALSE; 2793 static int g_fTermcapMode = FALSE;
2796 static CONSOLE_CURSOR_INFO g_cci; 2794 static CONSOLE_CURSOR_INFO g_cci;
2797 2795
2848 2846
2849 GetConsoleCursorInfo(g_hConOut, &g_cci); 2847 GetConsoleCursorInfo(g_hConOut, &g_cci);
2850 GetConsoleMode(g_hConIn, &g_cmodein); 2848 GetConsoleMode(g_hConIn, &g_cmodein);
2851 GetConsoleMode(g_hConOut, &g_cmodeout); 2849 GetConsoleMode(g_hConOut, &g_cmodeout);
2852 2850
2853 # ifdef FEAT_TITLE
2854 SaveConsoleTitleAndIcon(); 2851 SaveConsoleTitleAndIcon();
2855 /* 2852 /*
2856 * Set both the small and big icons of the console window to Vim's icon. 2853 * Set both the small and big icons of the console window to Vim's icon.
2857 * Note that Vim presently only has one size of icon (32x32), but it 2854 * Note that Vim presently only has one size of icon (32x32), but it
2858 * automatically gets scaled down to 16x16 when setting the small icon. 2855 * automatically gets scaled down to 16x16 when setting the small icon.
2859 */ 2856 */
2860 if (g_fCanChangeIcon) 2857 if (g_fCanChangeIcon)
2861 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon); 2858 SetConsoleIcon(g_hWnd, g_hVimIcon, g_hVimIcon);
2862 # endif
2863 2859
2864 ui_get_shellsize(); 2860 ui_get_shellsize();
2865 2861
2866 # ifdef MCH_WRITE_DUMP 2862 # ifdef MCH_WRITE_DUMP
2867 fdDump = fopen("dump", "wt"); 2863 fdDump = fopen("dump", "wt");
2907 2903
2908 ml_close_all(TRUE); // remove all memfiles 2904 ml_close_all(TRUE); // remove all memfiles
2909 2905
2910 if (g_fWindInitCalled) 2906 if (g_fWindInitCalled)
2911 { 2907 {
2912 # ifdef FEAT_TITLE
2913 mch_restore_title(SAVE_RESTORE_BOTH); 2908 mch_restore_title(SAVE_RESTORE_BOTH);
2914 /* 2909 /*
2915 * Restore both the small and big icons of the console window to 2910 * Restore both the small and big icons of the console window to
2916 * what they were at startup. Don't do this when the window is 2911 * what they were at startup. Don't do this when the window is
2917 * closed, Vim would hang here. 2912 * closed, Vim would hang here.
2918 */ 2913 */
2919 if (g_fCanChangeIcon && !g_fForceExit) 2914 if (g_fCanChangeIcon && !g_fForceExit)
2920 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon); 2915 SetConsoleIcon(g_hWnd, g_hOrigIconSmall, g_hOrigIcon);
2921 # endif
2922 2916
2923 # ifdef MCH_WRITE_DUMP 2917 # ifdef MCH_WRITE_DUMP
2924 if (fdDump) 2918 if (fdDump)
2925 { 2919 {
2926 time_t t; 2920 time_t t;
4755 char_u *cmd, 4749 char_u *cmd,
4756 int options) // SHELL_*, see vim.h 4750 int options) // SHELL_*, see vim.h
4757 { 4751 {
4758 int x = 0; 4752 int x = 0;
4759 int tmode = cur_tmode; 4753 int tmode = cur_tmode;
4760 #ifdef FEAT_TITLE
4761 WCHAR szShellTitle[512]; 4754 WCHAR szShellTitle[512];
4762 4755
4763 // Change the title to reflect that we are in a subshell. 4756 // Change the title to reflect that we are in a subshell.
4764 if (GetConsoleTitleW(szShellTitle, ARRAY_LENGTH(szShellTitle) - 4) > 0) 4757 if (GetConsoleTitleW(szShellTitle, ARRAY_LENGTH(szShellTitle) - 4) > 0)
4765 { 4758 {
4778 SetConsoleTitleW(szShellTitle); 4771 SetConsoleTitleW(szShellTitle);
4779 vim_free(wn); 4772 vim_free(wn);
4780 } 4773 }
4781 } 4774 }
4782 } 4775 }
4783 #endif
4784 4776
4785 out_flush(); 4777 out_flush();
4786 4778
4787 #ifdef MCH_WRITE_DUMP 4779 #ifdef MCH_WRITE_DUMP
4788 if (fdDump) 4780 if (fdDump)
4811 if (cmdbase == NULL || STRNICMP(cmdbase, "start", 5) != 0 4803 if (cmdbase == NULL || STRNICMP(cmdbase, "start", 5) != 0
4812 || !VIM_ISWHITE(cmdbase[5])) 4804 || !VIM_ISWHITE(cmdbase[5]))
4813 { 4805 {
4814 // Use a terminal window to run the command in. 4806 // Use a terminal window to run the command in.
4815 x = mch_call_shell_terminal(cmd, options); 4807 x = mch_call_shell_terminal(cmd, options);
4816 # ifdef FEAT_TITLE
4817 resettitle(); 4808 resettitle();
4818 # endif
4819 return x; 4809 return x;
4820 } 4810 }
4821 } 4811 }
4822 #endif 4812 #endif
4823 4813
5060 ) 5050 )
5061 { 5051 {
5062 smsg(_("shell returned %d"), x); 5052 smsg(_("shell returned %d"), x);
5063 msg_putchar('\n'); 5053 msg_putchar('\n');
5064 } 5054 }
5065 #ifdef FEAT_TITLE
5066 resettitle(); 5055 resettitle();
5067 #endif
5068 5056
5069 signal(SIGINT, SIG_DFL); 5057 signal(SIGINT, SIG_DFL);
5070 #if defined(__GNUC__) && !defined(__MINGW32__) 5058 #if defined(__GNUC__) && !defined(__MINGW32__)
5071 signal(SIGKILL, SIG_DFL); 5059 signal(SIGKILL, SIG_DFL);
5072 #else 5060 #else
5629 ClearConsoleBuffer(g_attrCurrent); 5617 ClearConsoleBuffer(g_attrCurrent);
5630 set_console_color_rgb(); 5618 set_console_color_rgb();
5631 ResizeConBufAndWindow(g_hConOut, Columns, Rows); 5619 ResizeConBufAndWindow(g_hConOut, Columns, Rows);
5632 } 5620 }
5633 5621
5634 # ifdef FEAT_TITLE
5635 resettitle(); 5622 resettitle();
5636 # endif
5637 5623
5638 GetConsoleMode(g_hConIn, &cmodein); 5624 GetConsoleMode(g_hConIn, &cmodein);
5639 if (g_fMouseActive) 5625 if (g_fMouseActive)
5640 { 5626 {
5641 cmodein |= ENABLE_MOUSE_INPUT; 5627 cmodein |= ENABLE_MOUSE_INPUT;