mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
refactor(windows): redundant icon messages #34274
Problem: Two separate window messages are used to get
the original console icon and set a new
one on windows, although the `WM_SETICON`
message returns the original icon itself.
Solution: Replace the two `WM_GETICON` messages with
two `WM_SETICON` messages, save the return
values and remove the call to `os_icon_set`.
Also, replace `os_icon_set` with `os_icon_reset`
as its only usage is now resetting the
icon to the original one.
(cherry picked from commit 7e393ff4f2
)
This commit is contained in:

committed by
Justin M. Keyes

parent
e0ddf93bb0
commit
33cec55a26
@@ -811,7 +811,7 @@ void getout(int exitval)
|
|||||||
|
|
||||||
#ifdef MSWIN
|
#ifdef MSWIN
|
||||||
// Restore Windows console icon before exiting.
|
// Restore Windows console icon before exiting.
|
||||||
os_icon_set(NULL, NULL);
|
os_icon_reset();
|
||||||
os_title_reset();
|
os_title_reset();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ int os_open_conin_fd(void)
|
|||||||
|
|
||||||
void os_clear_hwnd(void)
|
void os_clear_hwnd(void)
|
||||||
{
|
{
|
||||||
hWnd = NULL;
|
hWnd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void os_replace_stdin_to_conin(void)
|
void os_replace_stdin_to_conin(void)
|
||||||
@@ -58,20 +58,17 @@ void os_replace_stdout_and_stderr_to_conout(void)
|
|||||||
assert(conerr_fd == STDERR_FILENO);
|
assert(conerr_fd == STDERR_FILENO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets Windows console icon, or pass NULL to restore original icon.
|
/// Resets Windows console icon if we got an original one on startup.
|
||||||
void os_icon_set(HICON hIconSmall, HICON hIcon)
|
void os_icon_reset(void) {
|
||||||
{
|
|
||||||
if (hWnd == NULL) {
|
if (hWnd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hIconSmall = hIconSmall ? hIconSmall : hOrigIconSmall;
|
|
||||||
hIcon = hIcon ? hIcon : hOrigIcon;
|
|
||||||
|
|
||||||
if (hIconSmall != NULL) {
|
if (hOrigIconSmall) {
|
||||||
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hIconSmall);
|
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hOrigIconSmall);
|
||||||
}
|
}
|
||||||
if (hIcon != NULL) {
|
if (hOrigIcon) {
|
||||||
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
|
SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hOrigIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,9 +80,6 @@ void os_icon_init(void)
|
|||||||
if ((hWnd = GetConsoleWindow()) == NULL) {
|
if ((hWnd = GetConsoleWindow()) == NULL) {
|
||||||
return;
|
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");
|
const char *vimruntime = os_getenv("VIMRUNTIME");
|
||||||
if (vimruntime != NULL) {
|
if (vimruntime != NULL) {
|
||||||
@@ -95,7 +89,8 @@ void os_icon_init(void)
|
|||||||
} else {
|
} else {
|
||||||
HICON hVimIcon = LoadImage(NULL, NameBuff, IMAGE_ICON, 64, 64,
|
HICON hVimIcon = LoadImage(NULL, NameBuff, IMAGE_ICON, 64, 64,
|
||||||
LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
|
LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
|
||||||
os_icon_set(hVimIcon, hVimIcon);
|
hOrigIconSmall = (HICON)SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)hVimIcon);
|
||||||
|
hOrigIcon = (HICON)SendMessage(hWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hVimIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user