mirror of
https://github.com/neovim/neovim.git
synced 2025-01-01 17:23:36 -07:00
Merge #20634 fix(windows): set console icon later in startup
This commit is contained in:
commit
d52e3b97c5
src/nvim
@ -206,57 +206,6 @@ 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)
|
||||
@ -306,11 +255,6 @@ 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.
|
||||
@ -599,6 +543,12 @@ int main(int argc, char **argv)
|
||||
TIME_MSG("UIEnter autocommands");
|
||||
}
|
||||
|
||||
#ifdef MSWIN
|
||||
if (use_builtin_ui) {
|
||||
os_icon_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Adjust default register name for "unnamed" in 'clipboard'. Can only be
|
||||
// done after the clipboard is available and all initial commands that may
|
||||
// modify the 'clipboard' setting have run; i.e. just before entering the
|
||||
@ -776,7 +726,8 @@ void getout(int exitval)
|
||||
}
|
||||
|
||||
#ifdef MSWIN
|
||||
ResetWin32ConsoleIcon();
|
||||
// Restore Windows console icon before exiting.
|
||||
os_icon_set(NULL, NULL);
|
||||
#endif
|
||||
|
||||
os_exit(exitval);
|
||||
|
@ -2,6 +2,7 @@
|
||||
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
|
||||
#include "nvim/os/input.h"
|
||||
#include "nvim/os/os.h"
|
||||
#include "nvim/os/os_win_console.h"
|
||||
#include "nvim/vim.h"
|
||||
|
||||
@ -9,6 +10,10 @@
|
||||
# include "os/os_win_console.c.generated.h"
|
||||
#endif
|
||||
|
||||
static HWND hWnd = NULL;
|
||||
static HICON hOrigIconSmall = NULL;
|
||||
static HICON hOrigIcon = NULL;
|
||||
|
||||
int os_get_conin_fd(void)
|
||||
{
|
||||
const HANDLE conin_handle = CreateFile("CONIN$",
|
||||
@ -45,3 +50,45 @@ void os_replace_stdout_and_stderr_to_conout(void)
|
||||
const int conerr_fd = _open_osfhandle((intptr_t)conout_handle, 0);
|
||||
assert(conerr_fd == STDERR_FILENO);
|
||||
}
|
||||
|
||||
/// Sets Windows console icon, or pass NULL to restore original icon.
|
||||
void os_icon_set(HICON hIconSmall, HICON hIcon)
|
||||
{
|
||||
if (hWnd == NULL) {
|
||||
return;
|
||||
}
|
||||
hIconSmall = hIconSmall ? hIconSmall : hOrigIconSmall;
|
||||
hIcon = hIcon ? hIcon : hOrigIcon;
|
||||
|
||||
if (hIconSmall != NULL) {
|
||||
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIconSmall);
|
||||
}
|
||||
if (hIcon != NULL) {
|
||||
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets Nvim logo as Windows console icon.
|
||||
///
|
||||
/// Saves the original icon so it can be restored at exit.
|
||||
void os_icon_init(void)
|
||||
{
|
||||
if ((hWnd = GetConsoleWindow()) == NULL) {
|
||||
return;
|
||||
}
|
||||
// Save Windows console icon to be restored later.
|
||||
hOrigIconSmall = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_SMALL, (LPARAM)0);
|
||||
hOrigIcon = (HICON)SendMessage(hWnd, WM_GETICON, (WPARAM)ICON_BIG, (LPARAM)0);
|
||||
|
||||
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);
|
||||
os_icon_set(hVimIcon, hVimIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user