From 31d8914521d9fcfc104f731fa1930d8560860e23 Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Tue, 13 Apr 2021 19:20:06 +0200 Subject: [PATCH] + chg/add: configurable position offset on launching new instance + fix: Sticky Window Flag on launching new instance --- Build/Notepad3.ini | 2 + src/Config/Config.cpp | 15 +++--- src/Dialogs.c | 108 +++++++++++++++++++++--------------------- src/Notepad3.c | 20 +++----- src/TypeDefs.h | 6 ++- 5 files changed, 75 insertions(+), 76 deletions(-) diff --git a/Build/Notepad3.ini b/Build/Notepad3.ini index afb079ce8..9410486fa 100644 --- a/Build/Notepad3.ini +++ b/Build/Notepad3.ini @@ -37,6 +37,8 @@ SettingsVersion=4 ;ShellAppUserModelID=Rizonesoft.Notepad3 ;ShellUseSystemMRU=1 ;StickyWindowPosition=0 +;LaunchInstanceWndPosOffset=0 +;LaunchInstanceFullVisible=0 ;UseOldStyleBraceMatching=0 ;WebTemplate1=https://google.com/search?q=%s ;WebTmpl1MenuName=Open Web Action 1 diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 5cde71b1f..20cee1a89 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -47,10 +47,6 @@ extern "C" { #include "DarkMode/DarkMode.h" - -extern "C" WININFO g_IniWinInfo; -extern "C" WININFO g_DefWinInfo; - extern "C" const WCHAR* const TBBUTTON_DEFAULT_IDS_V1; extern "C" const WCHAR* const TBBUTTON_DEFAULT_IDS_V2; @@ -1130,8 +1126,7 @@ void LoadSettings() Defaults2.UndoTransactionTimeout), 0UL, 86400000UL); - // deprecated - + // Settings2 SciDirectWriteTech deprecated Defaults.RenderingTechnology = IniSectionGetInt(IniSecSettings2, L"SciDirectWriteTech", -111); if (Defaults.RenderingTechnology != -111) { if (Settings.SaveSettings) { @@ -1144,7 +1139,7 @@ void LoadSettings() Defaults.RenderingTechnology = SC_TECHNOLOGY_DIRECTWRITE; // new default DirectWrite (D2D) } - // Settings2 deprecated + // Settings2 EnableBidirectionalSupport deprecated Defaults.Bidirectional = IniSectionGetInt(IniSecSettings2, L"EnableBidirectionalSupport", -111); if ((Defaults.Bidirectional != -111) && Settings.SaveSettings) { // cleanup @@ -1162,6 +1157,12 @@ void LoadSettings() Settings2.IMEInteraction = ((codePage == 949 || codePage == 1361) ? SC_IME_INLINE : SC_IME_WINDOWED); } + Defaults2.LaunchInstanceWndPosOffset = 0; + Settings2.LaunchInstanceWndPosOffset = clampi(IniSectionGetInt(IniSecSettings2, L"LaunchInstanceWndPosOffset", Defaults2.LaunchInstanceWndPosOffset), -10000, 10000); + + Defaults2.LaunchInstanceFullVisible = false; + Settings2.LaunchInstanceFullVisible = IniSectionGetBool(IniSecSettings2, L"LaunchInstanceFullVisible", Defaults2.LaunchInstanceFullVisible); + Defaults2.SciFontQuality = SC_EFF_QUALITY_LCD_OPTIMIZED; Settings2.SciFontQuality = clampi(IniSectionGetInt(IniSecSettings2, L"SciFontQuality", Defaults2.SciFontQuality), SC_EFF_QUALITY_DEFAULT, SC_EFF_QUALITY_LCD_OPTIMIZED); diff --git a/src/Dialogs.c b/src/Dialogs.c index 29f70ea5d..2bb733c75 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -4362,59 +4362,6 @@ bool GetWindowRectEx(HWND hwnd, LPRECT pRect) { } -//============================================================================= -// -// GetMyWindowPlacement() -// -WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO* hMonitorInfo, const int offset) -{ - RECT rc; - GetWindowRect(hwnd, &rc); - - MONITORINFO mi = { sizeof(MONITORINFO) }; - GetMonitorInfoFromRect(&rc, &mi); - - // set monitor info - if (hMonitorInfo) { - if (hMonitorInfo->cbSize == mi.cbSize) { - *hMonitorInfo = mi; - } else { - GetMonitorInfoFromRect(&rc, hMonitorInfo); - } - } - - WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) }; - GetWindowPlacement(hwnd, &wndpl); - - // corrections in case of aero snapped position - if (SW_SHOWNORMAL == wndpl.showCmd) { - LONG const width = rc.right - rc.left; - LONG const height = rc.bottom - rc.top; - rc.left -= (mi.rcWork.left - mi.rcMonitor.left); - rc.right = rc.left + width; - rc.top -= (mi.rcWork.top - mi.rcMonitor.top); - rc.bottom = rc.top + height; - wndpl.rcNormalPosition = rc; - } - - WININFO wi = { 0 }; - wi.x = wndpl.rcNormalPosition.left + offset; - wi.y = wndpl.rcNormalPosition.top + offset; - wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left; - wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top; - wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED); - wi.zoom = SciCall_GetZoom(); - - // check if window fits monitor - if ((wi.x + wi.cx) > mi.rcWork.right || (wi.y + wi.cy) > mi.rcWork.bottom) { - wi.x = mi.rcMonitor.left; - wi.y = mi.rcMonitor.top; - } - - return wi; -} - - //============================================================================= // // FitIntoMonitorGeometry() @@ -4472,6 +4419,57 @@ void FitIntoMonitorGeometry(LPRECT pRect, WININFO *pWinInfo, SCREEN_MODE mode) { // ---------------------------------------------------------------------------- +//============================================================================= +// +// GetMyWindowPlacement() +// +WININFO GetMyWindowPlacement(HWND hwnd, MONITORINFO *hMonitorInfo, const int offset) { + RECT rc; + GetWindowRect(hwnd, &rc); + + MONITORINFO mi = { sizeof(MONITORINFO) }; + GetMonitorInfoFromRect(&rc, &mi); + + // set monitor info + if (hMonitorInfo) { + if (hMonitorInfo->cbSize == mi.cbSize) { + *hMonitorInfo = mi; + } else { + GetMonitorInfoFromRect(&rc, hMonitorInfo); + } + } + + WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) }; + GetWindowPlacement(hwnd, &wndpl); + + // corrections in case of aero snapped position + if (SW_SHOWNORMAL == wndpl.showCmd) { + LONG const width = rc.right - rc.left; + LONG const height = rc.bottom - rc.top; + rc.left -= (mi.rcWork.left - mi.rcMonitor.left); + rc.right = rc.left + width; + rc.top -= (mi.rcWork.top - mi.rcMonitor.top); + rc.bottom = rc.top + height; + wndpl.rcNormalPosition = rc; + } + + WININFO wi = { 0 }; + wi.x = wndpl.rcNormalPosition.left + offset; + wi.y = wndpl.rcNormalPosition.top + offset; + wi.cx = wndpl.rcNormalPosition.right - wndpl.rcNormalPosition.left; + wi.cy = wndpl.rcNormalPosition.bottom - wndpl.rcNormalPosition.top; + wi.max = IsZoomed(hwnd) || (wndpl.flags & WPF_RESTORETOMAXIMIZED); + wi.zoom = SciCall_GetZoom(); + + if (Settings2.LaunchInstanceFullVisible) { + RECT rcWi; + RectFromWinInfo(&wi, &rcWi); + FitIntoMonitorGeometry(&rcWi, &wi, SCR_NORMAL); + } + return wi; +} + + //============================================================================= // // WindowPlacementFromInfo() @@ -4542,7 +4540,9 @@ void DialogNewWindow(HWND hwnd, bool bSaveOnRunTools, LPCWSTR lpcwFilePath, WINI } StringCchCat(szParameters, COUNTOF(szParameters), Flags.bSingleFileInstance ? L" -ns" : L" -n"); - WININFO const _wi = wi ? *wi : GetMyWindowPlacement(hwnd, NULL, 0); + WININFO const _wi = (Flags.bStickyWindowPosition ? g_IniWinInfo : + (wi ? *wi : GetMyWindowPlacement(hwnd, NULL, Settings2.LaunchInstanceWndPosOffset))); + StringCchPrintf(tch, COUNTOF(tch), L" -pos %i,%i,%i,%i,%i", _wi.x, _wi.y, _wi.cx, _wi.cy, _wi.max); StringCchCat(szParameters, COUNTOF(szParameters), tch); diff --git a/src/Notepad3.c b/src/Notepad3.c index 01c74e4c4..ab7e26e8f 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3019,25 +3019,17 @@ LRESULT MsgDropFiles(HWND hwnd, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); HDROP const hDrop = (HDROP)wParam; + bool const vkCtrlDown = IsKeyDown(VK_CONTROL); WCHAR szDropFilePath[MAX_PATH + 40]; UINT const cnt = DragQueryFile(hDrop, UINT_MAX, NULL, 0); - int const offset = 20; - MONITORINFO mi = { sizeof(MONITORINFO) }; - WININFO wi = GetMyWindowPlacement(hwnd, &mi, (IsKeyDown(VK_CONTROL) ? offset : 0)); + int const offset = Settings2.LaunchInstanceWndPosOffset; for (UINT i = 0; i < cnt; ++i) { + WININFO wi = GetMyWindowPlacement(hwnd, NULL, (vkCtrlDown ? (offset * (i + 1)) : 0)); DragQueryFile(hDrop, i, szDropFilePath, COUNTOF(szDropFilePath)); _OnDropOneFile(hwnd, szDropFilePath, (((0 == i) && !IsKeyDown(VK_CONTROL)) ? NULL : &wi)); - // offset next window position - wi.x += offset; - wi.y += offset; - // check if window fits monitor - if ((wi.x + wi.cx) > mi.rcWork.right || (wi.y + wi.cy) > mi.rcWork.bottom) { - wi.x = mi.rcMonitor.left; - wi.y = mi.rcMonitor.top; - } } DragFinish(hDrop); @@ -7710,9 +7702,9 @@ static LRESULT _MsgNotifyFromEdit(HWND hwnd, const SCNotification* const scn) case SCN_URIDROPPED: { - WCHAR szBuf[MAX_PATH + 40] = { L'\0' }; - if (MultiByteToWideChar(CP_UTF8, 0, scn->text, -1, szBuf, (int)COUNTOF(szBuf)) > 0) { - return _OnDropOneFile(hwnd, szBuf, false); + WCHAR szFilePath[MAX_PATH + 40] = { L'\0' }; + if (MultiByteToWideChar(CP_UTF8, 0, scn->text, -1, szFilePath, (int)COUNTOF(szFilePath)) > 0) { + return _OnDropOneFile(hwnd, szFilePath, NULL); } } break; diff --git a/src/TypeDefs.h b/src/TypeDefs.h index 192fc459b..c81d8606f 100644 --- a/src/TypeDefs.h +++ b/src/TypeDefs.h @@ -93,6 +93,9 @@ inline void RectFromWinInfo(const WININFO* const pWinInfo, LPRECT pRect) SetRect(pRect, pWinInfo->x, pWinInfo->y, pWinInfo->x + pWinInfo->cx, pWinInfo->y + pWinInfo->cy); } +extern WININFO g_IniWinInfo; +extern WININFO g_DefWinInfo; + // ---------------------------------------------------------------------------- typedef int COLORALPHAREF; @@ -595,7 +598,8 @@ typedef struct _settings2_t DWORD UndoTransactionTimeout; int IMEInteraction; int SciFontQuality; - + int LaunchInstanceWndPosOffset; + bool LaunchInstanceFullVisible; int UpdateDelayMarkAllOccurrences; bool DenyVirtualSpaceAccess; bool UseOldStyleBraceMatching;