From 9eae81f62d19c2fe08495cd336a657d0425446cf Mon Sep 17 00:00:00 2001 From: RamonUnch <74856804+RamonUnch@users.noreply.github.com> Date: Tue, 2 Aug 2022 16:30:58 +0200 Subject: [PATCH] Allow to customize the Action Menu --- altsnap.c | 58 +++++++++++++++++++++++++++++++------------------------ hooks.c | 3 +++ 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/altsnap.c b/altsnap.c index 1062650e..3ac2f4a6 100644 --- a/altsnap.c +++ b/altsnap.c @@ -29,6 +29,7 @@ static wchar_t inipath[MAX_PATH]; // Cool stuff HINSTANCE hinstDLL = NULL; HHOOK keyhook = NULL; +static DWORD ACMenuItems=-1; static char elevated = 0; static char ScrollLockState = 0; static char SnapGap = 0; @@ -93,6 +94,7 @@ int HookSystem() // Reading some config options... UseZones = GetPrivateProfileInt(L"Zones", L"UseZones", 0, inipath); SnapGap = CLAMP(-128, GetPrivateProfileInt(L"Advanced", L"SnapGap", 0, inipath), 127); + ACMenuItems = GetPrivateProfileInt(L"Advanced", L"ACMenuItems", -1, inipath); UpdateTray(); return 0; } @@ -140,32 +142,38 @@ void ShowSClickMenu(HWND hwnd, LPARAM param) POINT pt; GetCursorPos(&pt); HMENU menu = CreatePopupMenu(); - AppendMenu(menu, MF_STRING, AC_ALWAYSONTOP,l10n->input_actions_alwaysontop); - CheckMenuItem(menu, AC_ALWAYSONTOP, param&LP_TOPMOST?MF_CHECKED:MF_UNCHECKED); - - AppendMenu(menu, MF_STRING, AC_BORDERLESS, l10n->input_actions_borderless); - CheckMenuItem(menu, AC_BORDERLESS, param&LP_BORDERLESS?MF_CHECKED:MF_UNCHECKED); - - AppendMenu(menu, MF_STRING, AC_CENTER, l10n->input_actions_center); - AppendMenu(menu, MF_STRING, AC_ROLL, l10n->input_actions_roll); - AppendMenu(menu, MF_STRING, AC_LOWER, l10n->input_actions_lower); - AppendMenu(menu, MF_STRING, AC_MAXHV, l10n->input_actions_maximizehv); - AppendMenu(menu, MF_STRING, AC_MINALL, l10n->input_actions_minallother); - AppendMenu(menu, MF_STRING, AC_SIDESNAP, l10n->input_actions_sidesnap); - AppendMenu(menu, MF_SEPARATOR, 0, NULL); - AppendMenu(menu, MF_STRING, AC_MAXIMIZE, l10n->input_actions_maximize); - CheckMenuItem(menu, AC_MAXIMIZE, param&LP_MAXIMIZED?MF_CHECKED:MF_UNCHECKED); - AppendMenu(menu, MF_STRING, AC_MINIMIZE, l10n->input_actions_minimize); - AppendMenu(menu, MF_STRING, AC_CLOSE, l10n->input_actions_close); - if (param&LP_AGGRKILL) { - AppendMenu(menu, MF_SEPARATOR, 0, NULL); - AppendMenu(menu, MF_STRING, AC_KILL, l10n->input_actions_kill); - } -// InsertMenu(menu, MF_SEPARATOR, 0, NULL); -// InsertMenu(menu, MF_STRING, AC_MUTE, l10n->input_actions_mute); - AppendMenu(menu, MF_SEPARATOR, 0, NULL); - AppendMenu(menu, MF_STRING, AC_NONE, l10n->input_actions_nothing); + #define CHK(LP_FLAG) MF_STRING|(param&LP_FLAG?MF_CHECKED:MF_UNCHECKED) + + #define K !(param&LP_AGGRKILL) + const struct { + const UCHAR hide; const enum action action; const WORD mf; const wchar_t * const str; + } mnlst[] = { + /* hide, action, MF_FLAG/CHECKED, menu string */ + { 0, AC_ALWAYSONTOP, CHK(LP_TOPMOST), l10n->input_actions_alwaysontop }, + { 0, AC_BORDERLESS, CHK(LP_BORDERLESS), l10n->input_actions_borderless }, + { 0, AC_CENTER, MF_STRING, l10n->input_actions_center}, + { 0, AC_ROLL, CHK(LP_ROLLED), l10n->input_actions_roll}, + { 0, AC_LOWER, MF_STRING, l10n->input_actions_lower}, + { 0, AC_MAXHV, MF_STRING, l10n->input_actions_maximizehv}, + { 0, AC_MINALL, MF_STRING, l10n->input_actions_minallother}, + { 0, AC_SIDESNAP, MF_STRING, l10n->input_actions_sidesnap}, + { 0, 0, MF_SEPARATOR, NULL }, /* ------------------------ */ + { 0, AC_MAXIMIZE, CHK(LP_MAXIMIZED), l10n->input_actions_maximize}, + { 0, AC_MINIMIZE, MF_STRING, l10n->input_actions_minimize}, + { 0, AC_CLOSE, MF_STRING, l10n->input_actions_close}, + { K, 0, MF_SEPARATOR, NULL }, /* ------------------------ */ + { K, AC_KILL, MF_STRING, l10n->input_actions_kill}, + { 0, 0, MF_SEPARATOR, NULL }, /* ------------------------ */ + { 0, AC_NONE, MF_STRING, l10n->input_actions_nothing}, + }; + #undef CHK + #undef K + unsigned i; + for (i=0; i < ARR_SZ(mnlst); i++) { + if (!mnlst[i].hide && (ACMenuItems>>i)&1) + AppendMenu(menu, mnlst[i].mf, mnlst[i].action, mnlst[i].str); + } SetForegroundWindow(g_hwnd); // Focus AltSnap's main hwnd. TrackPopupMenu(menu, GetSystemMetrics(SM_MENUDROPALIGNMENT), pt.x, pt.y, 0, hwnd, NULL); DestroyMenu(menu); diff --git a/hooks.c b/hooks.c index 235e201a..1bdc981f 100644 --- a/hooks.c +++ b/hooks.c @@ -3078,6 +3078,7 @@ static int init_movement_and_actions(POINT pt, enum action action, int button) DestroyWindow(g_mchwnd); g_mchwnd = KreateMsgWin(SClickWindowProc, APP_NAME"-SClick"); state.sclickhwnd = state.hwnd; + state.clickpt = pt; // Send message to Open Action Menu PostMessage( g_mainhwnd, WM_SCLICK, (WPARAM)g_mchwnd, @@ -3085,6 +3086,7 @@ static int init_movement_and_actions(POINT pt, enum action action, int button) | !!(GetWindowLongPtr(state.sclickhwnd, GWL_EXSTYLE)&WS_EX_TOPMOST) << 1 // LP_TOPMOST | !!GetBorderlessFlag(state.sclickhwnd) << 2 // LP_BORDERLESS | IsZoomed(state.sclickhwnd) << 3 // LP_MAXIMIZED + | !!(GetRestoreFlag(state.sclickhwnd)&2) << 4 // LP_ROLLED ); state.blockmouseup = 1; return 1; // block mouse down @@ -3565,6 +3567,7 @@ LRESULT CALLBACK SClickWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa enum action action = wParam; // state.sclickhwnd = MDIorNOT(state.sclickhwnd, &state.mdiclient); + state.prevpt = state.clickpt; SClickActions(state.sclickhwnd, action); state.sclickhwnd = NULL; state.unikeymenu = NULL;