From eaf74f0ef00d38dc4528a8ddf446a50297e8a111 Mon Sep 17 00:00:00 2001 From: gizabit Date: Sat, 5 Oct 2024 15:47:43 +0200 Subject: [PATCH 1/3] Add swap window action --- Lang/_en_US baseline.txt | Bin 23628 -> 23952 bytes Lang/de_DE.ini | Bin 25258 -> 25626 bytes config.c | 5 +++++ hooks.c | 15 +++++++++++++++ hooks.h | 7 ++++++- languages.h | 13 +++++++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/Lang/_en_US baseline.txt b/Lang/_en_US baseline.txt index c7f9ef8550ae36c0f575587f774c4a2f8078d5e7..4f366828021db1c45ad490a384dd17e5bb59ef66 100644 GIT binary patch delta 158 zcmX@JgK@%c#tmJDlN~g~WP=&X84?)^7bhlh4a&!p#c8rgE~Zp($L26E+o_GYubW0RXFiBt-xK delta 14 WcmbQRoAJyJ#tmJDo6i{?(gFZ9-3HtM diff --git a/Lang/de_DE.ini b/Lang/de_DE.ini index 156ba8baa8ca278f12383c2e012b3138b075ff24..ce84617c46e2f8c74e1941bcf5d02a4720adba93 100644 GIT binary patch delta 236 zcmZ2=lyTMx#tlpnlONcN$plLJMTI9X2;h^2=n6s7mCuj_)KP>_mpnvQ5RxvCdZ4*Ld-2!?)#rqy YuN3G)kRG^w{79|@isx-+j9AG90GlZ_rT_o{ delta 14 WcmbPrf^pSR#tlpnn~Ne>Z~*`@0R|2L diff --git a/config.c b/config.c index 9a5ef088..c9a164a3 100644 --- a/config.c +++ b/config.c @@ -1189,6 +1189,11 @@ INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPAR {TEXT("FocusT"), L10NIDX(input_actions_focust) }, {TEXT("FocusR"), L10NIDX(input_actions_focusr) }, {TEXT("FocusB"), L10NIDX(input_actions_focusb) }, + + {TEXT("SwapL"), L10NIDX(input_actions_swapl) }, + {TEXT("SwapT"), L10NIDX(input_actions_swapt) }, + {TEXT("SwapR"), L10NIDX(input_actions_swapr) }, + {TEXT("SwapB"), L10NIDX(input_actions_swapb) }, {NULL, 0} }; diff --git a/hooks.c b/hooks.c index 92640e7c..50669a77 100644 --- a/hooks.c +++ b/hooks.c @@ -2453,6 +2453,17 @@ static void SetForegroundWindowL(HWND hwnd) PostMessage(state.mdiclient, WM_MDIACTIVATE, (WPARAM)hwnd, 0); } } +// Swaps the position/size of the two specified windows +static void SwapWindows(HWND hwnd1, HWND hwnd2) +{ + if (!hwnd1 || !hwnd2) return; + + RECT rc1, rc2; + if (!GetWindowRect(hwnd1, &rc1) || !GetWindowRect(hwnd2, &rc2)) return; + + SetWindowPos(hwnd2, NULL, rc1.left, rc1.top, rc1.right-rc1.left, rc1.bottom-rc1.top, SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOACTIVATE|SWP_ASYNCWINDOWPOS); + SetWindowPos(hwnd1, NULL, rc2.left, rc2.top, rc2.right-rc2.left, rc2.bottom-rc2.top, SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_ASYNCWINDOWPOS); +} // Returns true if AltDrag must be disabled based on scroll lock // If conf.ScrollLockState&2 then Altdrag is disabled by Scroll Lock // otherwise it is enabled by Scroll lock. @@ -4762,6 +4773,10 @@ static void SClickActions(HWND hwnd, enum action action) case AC_FOCUST: ReallySetForegroundWindow(FindTiledWindow(hwnd, 1)); break; case AC_FOCUSR: ReallySetForegroundWindow(FindTiledWindow(hwnd, 2)); break; case AC_FOCUSB: ReallySetForegroundWindow(FindTiledWindow(hwnd, 3)); break; + case AC_SWAPL: SwapWindows(hwnd, FindTiledWindow(hwnd, 0)); break; + case AC_SWAPT: SwapWindows(hwnd, FindTiledWindow(hwnd, 1)); break; + case AC_SWAPR: SwapWindows(hwnd, FindTiledWindow(hwnd, 2)); break; + case AC_SWAPB: SwapWindows(hwnd, FindTiledWindow(hwnd, 3)); break; case AC_ASONOFF: ActionASOnOff(); break; case AC_MOVEONOFF: ActionMoveOnOff(hwnd); break; diff --git a/hooks.h b/hooks.h index 39314fa7..5a7eda0a 100644 --- a/hooks.h +++ b/hooks.h @@ -143,7 +143,12 @@ ACVALUE(AC_ZOOM, "Zoom", MR) \ ACVALUE(AC_ZOOM2, "Zoom2", MR) \ ACVALUE(AC_NPSTACKED, "NPStacked", ZO) \ - ACVALUE(AC_NPSTACKED2, "NPStacked2", ZO) + ACVALUE(AC_NPSTACKED2, "NPStacked2", ZO) \ + \ + ACVALUE(AC_SWAPL, "SwapL", MR) \ + ACVALUE(AC_SWAPT, "SwapT", MR) \ + ACVALUE(AC_SWAPR, "SwapR", MR) \ + ACVALUE(AC_SWAPB, "SwapB", MR) #define ACVALUE(a, b, c) a, enum action { ACTION_MAP AC_MAXVALUE, AC_SHRT0, AC_SHRTF=AC_SHRT0+36, AC_ORICLICK }; diff --git a/languages.h b/languages.h index b7025e8c..0c89303b 100644 --- a/languages.h +++ b/languages.h @@ -181,6 +181,11 @@ struct strings { TCHAR *input_actions_focusr; TCHAR *input_actions_focusb; + TCHAR *input_actions_swapl; + TCHAR *input_actions_swapt; + TCHAR *input_actions_swapr; + TCHAR *input_actions_swapb; + TCHAR *input_actions_roll; TCHAR *input_actions_alwaysontop; TCHAR *input_actions_borderless; @@ -421,6 +426,10 @@ static const char* l10n_inimapping[] = { "InputActionFocusT", "InputActionFocusR", "InputActionFocusB", + "InputActionSwapL", + "InputActionSwapT", + "InputActionSwapR", + "InputActionSwapB", "InputActionRoll", "InputActionAlwaysOnTop", "InputActionBorderless", @@ -664,6 +673,10 @@ static const struct strings en_US = { /* focust */ TEXT("Focus top window"), /* focusr */ TEXT("Focus right window"), /* focusb */ TEXT("Focus bottom window"), + /* swapl */ TEXT("Swap with left window"), + /* swapt */ TEXT("Swap with top window"), + /* swapr */ TEXT("Swap with right window"), + /* swapb */ TEXT("Swap with bottom window"), /* roll */ TEXT("&Roll/Unroll window"), /* alwaysontop */ TEXT("Toggle always on &top"), /* borderless */ TEXT("Toggle &borderless"), From 800a3fe3e1edb738932d0bf1e28647bf823c03ac Mon Sep 17 00:00:00 2001 From: gizabit Date: Tue, 8 Oct 2024 00:09:13 +0200 Subject: [PATCH 2/3] Animate windows when swapping --- AltSnap.dni | Bin 53944 -> 54500 bytes hooks.c | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/AltSnap.dni b/AltSnap.dni index 7665074072edd6fbfcd703a19794a1398041ec32..1cc30054b66843b4e57e8c7440a01f50d68a7ba9 100644 GIT binary patch delta 420 zcmdn7l=;a@<_!y083!|zGbAz;FgP;gF=R620@)=%Iv>aj2C`CtGQ|wG42BE_47?0n z4Au+^48fBN>x3s8osuz5#L%MvR1MRm05mxRXhI%PPchV%g2@}z#2pnFG=QcALI0R1-EaHl+@=H$Sg!jsSV ca~Z=zL;)D8X+Xci^uWRdi@P^ZU8Sr604p<9lK=n! delta 14 WcmaE|l6l8c<_!y0Z9cO`LIVIgn+H|^ diff --git a/hooks.c b/hooks.c index 50669a77..bc680cc0 100644 --- a/hooks.c +++ b/hooks.c @@ -199,6 +199,8 @@ static struct config { UCHAR MenuShowOffscreenWin; UCHAR MenuShowEmptyLabelWin; UCHAR IgnoreMinMaxInfo; + UCHAR SwapAnimationSteps; + UCHAR SwapAnimationDelay; // [Performance] UCHAR FullWin; UCHAR TransWinOpacity; @@ -310,6 +312,8 @@ static const struct OptionListItem Advanced_uchars[] = { { "MenuShowOffscreenWin", 0 }, { "MenuShowEmptyLabelWin", 0 }, { "IgnoreMinMaxInfo", 0 }, + { "SwapAnimationSteps", 10 }, + { "SwapAnimationDelay", 5 }, }; // [Performance] static const struct OptionListItem Performance_uchars[] = { @@ -2461,6 +2465,20 @@ static void SwapWindows(HWND hwnd1, HWND hwnd2) RECT rc1, rc2; if (!GetWindowRect(hwnd1, &rc1) || !GetWindowRect(hwnd2, &rc2)) return; + if (conf.SwapAnimationSteps > 0) { + float steps = (float)conf.SwapAnimationSteps; + float dleft = (rc2.left - rc1.left) / steps; + float dtop = (rc2.top - rc1.top) / steps; + float dwidth = (rc2.right - rc2.left - rc1.right + rc1.left) / steps; + float dheight = (rc2.bottom - rc2.top - rc1.bottom + rc1.top) / steps; + + for (int i = 0; i < conf.SwapAnimationSteps; i++) { + SetWindowPos(hwnd1, NULL, rc1.left + i*dleft, rc1.top + i*dtop, rc1.right - rc1.left + i*dwidth, rc1.bottom - rc1.top + i*dheight, SWP_NOZORDER | SWP_NOACTIVATE); + SetWindowPos(hwnd2, NULL, rc2.left - i*dleft, rc2.top - i*dtop, rc2.right - rc2.left - i*dwidth, rc2.bottom - rc2.top - i*dheight, SWP_NOZORDER | SWP_NOACTIVATE); + Sleep(conf.SwapAnimationDelay); + } + } + SetWindowPos(hwnd2, NULL, rc1.left, rc1.top, rc1.right-rc1.left, rc1.bottom-rc1.top, SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOACTIVATE|SWP_ASYNCWINDOWPOS); SetWindowPos(hwnd1, NULL, rc2.left, rc2.top, rc2.right-rc2.left, rc2.bottom-rc2.top, SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_ASYNCWINDOWPOS); } From 886eddaacf0da5441ade4d582a49b1b0ff6bd4c8 Mon Sep 17 00:00:00 2001 From: gizabit Date: Wed, 16 Oct 2024 07:18:46 +0200 Subject: [PATCH 3/3] Add flag to disable resize animation --- AltSnap.dni | Bin 54500 -> 55004 bytes hooks.c | 11 +++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/AltSnap.dni b/AltSnap.dni index 1cc30054b66843b4e57e8c7440a01f50d68a7ba9..406892cc6f1f0ca01c0433a0f46f7a189baaeed8 100644 GIT binary patch delta 274 zcmaE|lKIYB<_%}oO#ZQ2gfVrpAg|( diff --git a/hooks.c b/hooks.c index bc680cc0..3da49edb 100644 --- a/hooks.c +++ b/hooks.c @@ -201,6 +201,7 @@ static struct config { UCHAR IgnoreMinMaxInfo; UCHAR SwapAnimationSteps; UCHAR SwapAnimationDelay; + UCHAR SwapAnimateResize; // [Performance] UCHAR FullWin; UCHAR TransWinOpacity; @@ -314,6 +315,7 @@ static const struct OptionListItem Advanced_uchars[] = { { "IgnoreMinMaxInfo", 0 }, { "SwapAnimationSteps", 10 }, { "SwapAnimationDelay", 5 }, + { "SwapAnimateResize", 0 }, }; // [Performance] static const struct OptionListItem Performance_uchars[] = { @@ -2469,8 +2471,13 @@ static void SwapWindows(HWND hwnd1, HWND hwnd2) float steps = (float)conf.SwapAnimationSteps; float dleft = (rc2.left - rc1.left) / steps; float dtop = (rc2.top - rc1.top) / steps; - float dwidth = (rc2.right - rc2.left - rc1.right + rc1.left) / steps; - float dheight = (rc2.bottom - rc2.top - rc1.bottom + rc1.top) / steps; + + float dwidth = 0.0; + float dheight = 0.0; + if (conf.SwapAnimateResize) { + dwidth = (rc2.right - rc2.left - rc1.right + rc1.left) / steps; + dheight = (rc2.bottom - rc2.top - rc1.bottom + rc1.top) / steps; + } for (int i = 0; i < conf.SwapAnimationSteps; i++) { SetWindowPos(hwnd1, NULL, rc1.left + i*dleft, rc1.top + i*dtop, rc1.right - rc1.left + i*dwidth, rc1.bottom - rc1.top + i*dheight, SWP_NOZORDER | SWP_NOACTIVATE);