Cygwin/X: Update icons directly, rather than modifying the window's class

Update icons directly to windows rather than modifying
the window's class.  Respect custom icons overriden via
the configuration file.

fd.o bugzilla #4491

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
This commit is contained in:
Joe Krahn 2009-01-20 17:22:37 +00:00 committed by Jon TURNEY
parent 9955252564
commit 996357e905
3 changed files with 46 additions and 55 deletions

View File

@ -364,43 +364,37 @@ void
winUpdateIcon (Window id) winUpdateIcon (Window id)
{ {
WindowPtr pWin; WindowPtr pWin;
HICON hIcon, hiconOld; HICON hIcon, hIconSmall=NULL, hIconOld;
pWin = (WindowPtr) LookupIDByType (id, RT_WINDOW); pWin = (WindowPtr) LookupIDByType (id, RT_WINDOW);
if (!pWin) return; if (!pWin) return;
hIcon = winOverrideIcon ((unsigned long)pWin); winWindowPriv(pWin);
if (pWinPriv->hWnd) {
if (!hIcon) hIcon = winOverrideIcon ((unsigned long)pWin);
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); if (!hIcon) {
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
if (hIcon) if (!hIcon) {
{ hIcon = g_hIconX;
winWindowPriv(pWin); hIconSmall = g_hSmallIconX;
} else {
if (pWinPriv->hWnd) /* Leave undefined if not found */
{ hIconSmall = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON));
hiconOld = (HICON) SetClassLong (pWinPriv->hWnd, }
GCL_HICON,
(int) hIcon);
/* Delete the icon if its not the default */
winDestroyIcon(hiconOld);
}
} }
hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON)); /* Set the large icon */
if (hIcon) hIconOld = (HICON) SendMessage (pWinPriv->hWnd,
{ WM_SETICON, ICON_BIG, (LPARAM) hIcon);
winWindowPriv(pWin);
if (pWinPriv->hWnd) /* Delete the icon if its not the default */
{ winDestroyIcon(hIconOld);
hiconOld = (HICON) SetClassLong (pWinPriv->hWnd,
GCL_HICONSM, /* Same for the small icon */
(int) hIcon); hIconOld = (HICON) SendMessage (pWinPriv->hWnd,
winDestroyIcon (hiconOld); WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
} winDestroyIcon(hIconOld);
}
}
} }
void winInitGlobalIcons (void) void winInitGlobalIcons (void)

View File

@ -189,35 +189,28 @@ ReloadEnumWindowsProc (HWND hwnd, LPARAM lParam)
/* It's our baby, either clean or dirty it */ /* It's our baby, either clean or dirty it */
if (lParam==FALSE) if (lParam==FALSE)
{ {
hicon = (HICON)GetClassLong(hwnd, GCL_HICON); /* Reset the window's icon to undefined. */
hicon = (HICON)SendMessage(hwnd, WM_SETICON, ICON_BIG, 0);
/* Unselect any icon in the class structure */ /* If the old icon is generated on-the-fly, get rid of it, will regen */
SetClassLong (hwnd, GCL_HICON, (LONG)LoadIcon (NULL, IDI_APPLICATION));
/* If it's generated on-the-fly, get rid of it, will regen */
winDestroyIcon (hicon); winDestroyIcon (hicon);
hicon = (HICON)GetClassLong(hwnd, GCL_HICONSM); /* Same for the small icon */
hicon = (HICON)SendMessage(hwnd, WM_SETICON, ICON_SMALL, 0);
/* Unselect any icon in the class structure */
SetClassLong (hwnd, GCL_HICONSM, 0);
/* If it's generated on-the-fly, get rid of it, will regen */
winDestroyIcon (hicon); winDestroyIcon (hicon);
/* Remove any menu additions, use bRevert flag */ /* Remove any menu additions; bRevert=TRUE destroys any modified menus */
GetSystemMenu (hwnd, TRUE); GetSystemMenu (hwnd, TRUE);
/* This window is now clean of our taint */ /* This window is now clean of our taint (but with undefined icons) */
} }
else else
{ {
/* Make the icon default, dynamic, or from xwinrc */ /* winUpdateIcon() will set the icon default, dynamic, or from xwinrc */
SetClassLong (hwnd, GCL_HICON, (LONG)g_hIconX);
SetClassLong (hwnd, GCL_HICONSM, (LONG)g_hSmallIconX);
wid = (Window)GetProp (hwnd, WIN_WID_PROP); wid = (Window)GetProp (hwnd, WIN_WID_PROP);
if (wid) if (wid)
winUpdateIcon (wid); winUpdateIcon (wid);
/* Update the system menu for this window */ /* Update the system menu for this window */
SetupSysMenu ((unsigned long)hwnd); SetupSysMenu ((unsigned long)hwnd);
@ -241,8 +234,12 @@ ReloadPrefs (void)
int i; int i;
#ifdef XWIN_MULTIWINDOW #ifdef XWIN_MULTIWINDOW
/* First, iterate over all windows replacing their icon with system */ /* First, iterate over all windows, deleting their icons and custom menus.
/* default one and deleting any custom system menus */ * This is really only needed because winDestroyIcon() will try to
* destroy the old global icons, which will have changed.
* It is probably better to set a windows USER_DATA to flag locally defined
* icons, and use that to accurately know when to destroy old icons.
*/
EnumThreadWindows (g_dwCurrentThreadID, ReloadEnumWindowsProc, FALSE); EnumThreadWindows (g_dwCurrentThreadID, ReloadEnumWindowsProc, FALSE);
#endif #endif

View File

@ -177,12 +177,12 @@ winMWExtWMUpdateIcon (Window id)
if (pRLWinPriv->hWnd) if (pRLWinPriv->hWnd)
{ {
hiconOld = (HICON) SetClassLong (pRLWinPriv->hWnd,
GCL_HICON,
(int) hIcon);
hiconOld = (HICON) SendMessage (pRLWinPriv->hWnd,
WM_SETICON, ICON_BIG, (LPARAM) hIcon);
winDestroyIcon(hiconOld); winDestroyIcon(hiconOld);
} }
hIcon=NULL;
} }
} }