Skip to content

Commit

Permalink
Merge pull request #245 from RamonUnch/RamonUnch-AcMenuCostomize
Browse files Browse the repository at this point in the history
Allow to customize the Action Menu
  • Loading branch information
RamonUnch authored Aug 2, 2022
2 parents 4ca7b14 + 9eae81f commit 8043a74
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
58 changes: 33 additions & 25 deletions altsnap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3078,13 +3078,15 @@ 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,
conf.AggressiveKill // LP_AGGRKILL
| !!(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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8043a74

Please sign in to comment.