Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+fix: Correction for settings2 DrawAnimatedWindow #5111

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
+fix: Correction for settings2 DrawAnimatedWindow
  • Loading branch information
RaiKoHoff committed Feb 24, 2024
commit 6aceba202a20d4b607e5e64bd174d1c2235223ca
47 changes: 32 additions & 15 deletions src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -676,30 +676,44 @@ static bool GetTrayWndRect(LPRECT lpTrayRect) {


// Check to see if the animation has been disabled
bool GetSetDoAnimateMinimize(const int flag)
// call SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1 | 0 for reset);
bool SetAnimateMinimizeRestore(const int flag)
{
static int systemFlag = 0;
bool bAnim = false;

ANIMATIONINFO ai;
ai.cbSize = sizeof(ai);
SystemParametersInfo(SPI_GETANIMATION, sizeof(ai), &ai, 0);
bool const bRes = ai.iMinAnimate ? true : false;
if (flag == 0 && bRes) {
ai.iMinAnimate = 0;
SystemParametersInfo(SPI_SETANIMATION, sizeof(ai), &ai, 0);

if (systemFlag == 0) {
systemFlag = ai.iMinAnimate ? 1 : -1;
bAnim = ai.iMinAnimate ? true : false;
}
if (flag == 0) { // reset
ai.iMinAnimate = (systemFlag == 1) ? 1 : 0;
SystemParametersInfo(SPI_SETANIMATION, sizeof(ai), &ai, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
bAnim = ai.iMinAnimate ? true : false;
systemFlag = 0;
}
else if (flag > 0 && !bRes) {
else if (flag > 0) { // set animation
ai.iMinAnimate = 1;
SystemParametersInfo(SPI_SETANIMATION, sizeof(ai), &ai, 0);
SystemParametersInfo(SPI_SETANIMATION, sizeof(ai), &ai, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
bAnim = true;
}
return bRes;
else { // disable animation
ai.iMinAnimate = 0;
SystemParametersInfo(SPI_SETANIMATION, sizeof(ai), &ai, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
bAnim = false;
}
return bAnim;
}



void MinimizeWndToTray(HWND hWnd) {

bool const bAnimate = GetSetDoAnimateMinimize(-1);

if (bAnimate) {
if (SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1)) {

// Get the rect of the window. It is safe to use the rect of the whole
// window - DrawAnimatedRects will only draw the caption
Expand All @@ -718,14 +732,14 @@ void MinimizeWndToTray(HWND hWnd) {

// Hide the window
ShowWindow(hWnd, SW_MINIMIZE);
if (bAnimate) { Sleep(500); }
ShowWindow(hWnd, SW_HIDE);
Globals.bMinimizedToTray = true;
SetAnimateMinimizeRestore(0); // reset
}

void RestoreWndFromTray(HWND hWnd) {

if (GetSetDoAnimateMinimize(-1)) {
if (SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1)) {

// Get the rect of the tray and the window. Note that the window rect
// is still valid even though the window is hidden
Expand All @@ -744,6 +758,7 @@ void RestoreWndFromTray(HWND hWnd) {
SetActiveWindow(hWnd);
SetForegroundWindow(hWnd);
Globals.bMinimizedToTray = false;
SetAnimateMinimizeRestore(0); // reset

// Remove the tray icon. As described above, remove the icon after the
// call to DrawAnimatedRects, or the taskbar will not refresh itself
Expand Down Expand Up @@ -4751,12 +4766,13 @@ void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode, UINT n
}
else {
WINDOWPLACEMENT wndpl = WindowPlacementFromInfo(hwnd, &winInfo, mode, nCmdShow);
if (GetSetDoAnimateMinimize(-1) && wndpl.showCmd) {
if (SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1) && wndpl.showCmd) {
DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition);
}
SetWindowPlacement(hwnd, &wndpl); // 1st set correct screen (DPI Aware)
RelAdjustRectForDPI(&wndpl.rcNormalPosition, winInfo.dpi, Scintilla_GetWindowDPI(hwnd));
SetWindowPlacement(hwnd, &wndpl); // 2nd resize position to correct DPI settings
SetAnimateMinimizeRestore(0);
}
SetWindowPos(hwnd, Settings.AlwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
s_bPrevFullScreenFlag = false;
Expand All @@ -4772,13 +4788,14 @@ void SnapToWinInfoPos(HWND hwnd, const WININFO winInfo, SCREEN_MODE mode, UINT n
GetMonitorInfo(MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY), &mi);
SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~dwRmvFScrStyle);
WINDOWPLACEMENT const wndpl = WindowPlacementFromInfo(hwnd, NULL, mode, nCmdShow);
if (GetSetDoAnimateMinimize(-1) && wndpl.showCmd) {
if (SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1) && wndpl.showCmd) {
DrawAnimatedRects(hwnd, IDANI_CAPTION, &rcCurrent, &wndpl.rcNormalPosition);
}
SetWindowPlacement(hwnd, &wndpl);
SetWindowPos(hwnd, HWND_TOPMOST, mi.rcMonitor.left, mi.rcMonitor.top,
mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top,
SWP_NOOWNERZORDER | SWP_FRAMECHANGED);
SetAnimateMinimizeRestore(0);
Settings.ShowTitlebar = Settings.ShowMenubar = Settings.ShowToolbar = Settings.ShowStatusbar = false;
Settings.AlwaysOnTop = true;
s_bPrevFullScreenFlag = true;
Expand Down
2 changes: 1 addition & 1 deletion src/Dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// ----------------------------------------------------------------------------

// === MinimizeToTray Functions - see comments in Dialogs.c ===
bool GetSetDoAnimateMinimize(const int flag);
bool SetAnimateMinimizeRestore(const int flag);
void MinimizeWndToTray(HWND hWnd);
void RestoreWndFromTray(HWND hWnd);

Expand Down
1 change: 1 addition & 0 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,7 @@ void CloseNonModalDialogs()
void CloseApplication()
{
CloseNonModalDialogs();
SetAnimateMinimizeRestore(0); // reset to system settings
PostMessage(Globals.hwndMain, WM_CLOSE, 0, 0);
}

Expand Down
22 changes: 18 additions & 4 deletions src/Notepad3.c
Original file line number Diff line number Diff line change
Expand Up @@ -1936,8 +1936,6 @@ HWND InitInstance(const HINSTANCE hInstance, int nCmdShow)
// initial set text in front of ShowWindow()
EditSetNewText(Globals.hwndEdit, "", 0, false, false);

GetSetDoAnimateMinimize(Settings2.DrawAnimatedWindow ? 1 : 0);

ShowWindowAsync(s_hwndEditFrame, SW_SHOWDEFAULT);
ShowWindowAsync(Globals.hwndEdit, SW_SHOWDEFAULT);
//~SnapToWinInfoPos(hwndMain, g_IniWinInfo, SCR_NORMAL, SW_HIDE); ~ instead set all needed properties here:
Expand Down Expand Up @@ -3522,8 +3520,16 @@ LRESULT MsgThemeChanged(HWND hwnd, WPARAM wParam,LPARAM lParam)
//
LRESULT MsgSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
if (wParam == SIZE_MINIMIZED) {
switch (wParam) {
case SIZE_MINIMIZED:
SetAnimateMinimizeRestore(0); // reset
return FALSE;
case SIZE_MAXIMIZED:
case SIZE_RESTORED:
SetAnimateMinimizeRestore(0); // reset
break;
default:
break;
}

int x = 0;
Expand Down Expand Up @@ -7623,12 +7629,20 @@ LRESULT MsgSysCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
SetNotifyIconTitle(hwnd);
return FALSE; // swallowed
}
else {
SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1);
}
break;

case SC_MAXIMIZE:
SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1);
break;

case SC_RESTORE: {
SetAnimateMinimizeRestore(Settings2.DrawAnimatedWindow ? 1 : -1);
LRESULT lrv = DefWindowProc(hwnd, umsg, wParam, lParam);
ShowOwnedPopups(hwnd, true);
return(lrv);
return (lrv);
}

default:
Expand Down