diff options
author | Enan Ajmain <3nan.ajmain@gmail.com> | 2022-10-13 18:48:12 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 05:48:12 -0700 |
commit | 730228f6db1f858795ea83ba2179c875dca37bc7 (patch) | |
tree | b18acb4cf052a385c4317a4f73976e4d48eb7a13 /src | |
parent | 06dfedc87ab4cc575a503195a1358b2984e248c4 (diff) | |
download | rneovim-730228f6db1f858795ea83ba2179c875dca37bc7.tar.gz rneovim-730228f6db1f858795ea83ba2179c875dca37bc7.tar.bz2 rneovim-730228f6db1f858795ea83ba2179c875dca37bc7.zip |
feat(windows): show icon in terminal titlebar, taskbar #20607
closes #20071
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/main.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index d5fa992218..f6ec08c8e0 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -207,6 +207,57 @@ void early_init(mparm_T *paramp) init_signs(); } +#ifdef MSWIN +HWND hWnd = NULL; +static HICON hOrigIconSmall = NULL; +static HICON hOrigIcon = NULL; + +/// Save Windows console icon to be reset later +static void SaveWin32ConsoleIcon(void) +{ + if ((hWnd = GetConsoleWindow()) == NULL) { + return; + } + hOrigIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_SMALL, (LPARAM)0); + hOrigIcon = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_BIG, (LPARAM)0); +} + +static void SetConsoleIcon(HWND hWindow, HICON hIconSmall, HICON hIcon) +{ + if (hWindow == NULL) { + return; + } + if (hIconSmall != NULL) { + SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIconSmall); + } + if (hIcon != NULL) { + SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon); + } +} + +/// Reset Windows console icon to original +static void ResetWin32ConsoleIcon(void) +{ + SetConsoleIcon(hWnd, hOrigIconSmall, hOrigIcon); +} + +/// Set Neovim logo as Windows console icon +static void SetWin32ConsoleIcon(void) +{ + const char *vimruntime = os_getenv("VIMRUNTIME"); + if (vimruntime != NULL) { + snprintf(NameBuff, MAXPATHL, "%s" _PATHSEPSTR "neovim.ico", vimruntime); + if (!os_path_exists(NameBuff)) { + WLOG("neovim.ico not found: %s", NameBuff); + } else { + HICON hVimIcon = LoadImage(NULL, NameBuff, IMAGE_ICON, 64, 64, + LR_LOADFROMFILE | LR_LOADMAP3DCOLORS); + SetConsoleIcon(hWnd, hVimIcon, hVimIcon); + } + } +} +#endif + #ifdef MAKE_LIB int nvim_main(int argc, char **argv); // silence -Wmissing-prototypes int nvim_main(int argc, char **argv) @@ -256,6 +307,11 @@ int main(int argc, char **argv) early_init(¶ms); +#ifdef MSWIN + SaveWin32ConsoleIcon(); + SetWin32ConsoleIcon(); +#endif + set_argv_var(argv, argc); // set v:argv // Check if we have an interactive window. @@ -721,6 +777,10 @@ void getout(int exitval) garbage_collect(false); } +#ifdef MSWIN + ResetWin32ConsoleIcon(); +#endif + os_exit(exitval); } |