diff --git a/Lang/_en_US baseline.txt b/Lang/_en_US baseline.txt index f800f79c..ee8044e0 100644 Binary files a/Lang/_en_US baseline.txt and b/Lang/_en_US baseline.txt differ diff --git a/Lang/fr_FR.ini b/Lang/fr_FR.ini index 96528ec5..6e68e2a6 100644 Binary files a/Lang/fr_FR.ini and b/Lang/fr_FR.ini differ diff --git a/Lang/it_IT.ini b/Lang/it_IT.ini index 1a5a9474..7000540f 100644 Binary files a/Lang/it_IT.ini and b/Lang/it_IT.ini differ diff --git a/altsnap.c b/altsnap.c index 5c7f73ab..1dde4fed 100644 --- a/altsnap.c +++ b/altsnap.c @@ -373,22 +373,18 @@ static LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP WriteCurrentLayoutNumber(); } else if (wmId == CMD_EDITLAYOUT) { if (G_HotKeyProc) { - unsigned len = G_HotKeyProc(hwnd, WM_GETZONESLEN, LayoutNumber, 0); - if (!len) { + RECT *zones = NULL; + unsigned len = G_HotKeyProc(hwnd, WM_GETZONES, LayoutNumber, (LPARAM)&zones); + if (!len || !zones) { // Empty layout, Let's open a new Test Window return !NewTestWindow(); } - RECT *zones = (RECT*)malloc(len * sizeof(*zones)); - if(!zones) return 0; - - G_HotKeyProc(hwnd, WM_GETZONES, LayoutNumber, (LPARAM)zones); // Open them from bottom to top to ensure // the windows are in the correct order. while (len--) { const RECT *rc = &zones[len]; NewTestWindowAt(rc->left, rc->top, rc->right-rc->left, rc->bottom-rc->top); } - free(zones); } } } else if (msg == WM_QUERYENDSESSION) { @@ -514,8 +510,8 @@ int WINAPI tWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, TCHAR *params, int // Ask old HotKey window to perform an action. const TCHAR *actionstr = lstrstr(params, TEXT("-a")); if (actionstr && actionstr[2] && actionstr[3] && actionstr[4]) { - enum action action = MapActionW(&actionstr[3]); - PostMessage(previnst, WM_HOTKEY, (actionstr[2] == 'p')*0x1000+action, 0); + action_t action = MapActionW(&actionstr[3]); + PostMessage(previnst, WM_HOTKEY, (actionstr[2] == 'p')*0x1000+action.ac, PACK_ACTION(action)); return 0; } // Change layout if asked... diff --git a/config.c b/config.c index 3c31b34e..b9138b2d 100644 --- a/config.c +++ b/config.c @@ -266,7 +266,8 @@ static BOOL CALLBACK PropSheetProc(HWND hwnd, UINT msg, LPARAM lParam) UpdateStrings(); // Set new icon specifically for the taskbar and Alt+Tab, without changing window icon - HICON taskbar_icon = (HICON)LoadImageA(g_hinst, "APP_ICON", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); + //HICON taskbar_icon = (HICON)LoadImageA(g_hinst, MAKEINTRESOURCEA(APP_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); + HICON taskbar_icon = LoadIcon(g_hinst, MAKEINTRESOURCE(APP_ICON)); SendMessage(g_cfgwnd, WM_SETICON, ICON_BIG, (LPARAM) taskbar_icon); } return TRUE; @@ -301,6 +302,27 @@ static DWORD IsUACEnabled() static int CB_GetCurSelDlgItem(HWND hwnd, UINT id) { return (int)(DWORD)SendMessage(GetDlgItem(hwnd, id), CB_GETCURSEL, 0, 0); } #define CB_GetCurSelId(id) CB_GetCurSelDlgItem(hwnd, id) #define CB_GetText(id, txt, txtlen) (int)(DWORD)SendMessage(GetDlgItem(hwnd, id), WM_GETTEXT, (WPARAM)txtlen, (LPARAM)txt) + +static LRESULT CB_GetTextAndIdx(HWND hwnd, TCHAR *txt, size_t txtlen) +{ + LRESULT idx = SendMessage(hwnd, CB_GETCURSEL, 0, 0); + if (idx < 0) { + GetWindowText(hwnd, txt, txtlen); // Edit mode + } else { + size_t itemlen = SendMessage(hwnd, CB_GETLBTEXTLEN, idx, 0); + if (txtlen > itemlen) // We have enough space + SendMessage(hwnd, CB_GETLBTEXT, idx, (LPARAM)txt); + } + return idx; +} + +static LRESULT CB_AddStringIfNotPresentAndGetIdx(HWND hwnd, const TCHAR *txt) +{ + LRESULT new_index = SendMessage(hwnd, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)txt); + if (new_index < 0) + new_index = CB_AddString(hwnd, txt); + return new_index; +} static void WriteOptionBoolW(HWND hwnd, WORD id, const TCHAR *section, const char *name_s) { TCHAR name[64]; @@ -420,15 +442,15 @@ static void UpdateDialogStrings(HWND hwnd, const struct dialogstring * const str } // Options to bead or written... enum opttype {T_BOL=0, T_BMK=1, T_STR=2}; -struct optlst { +typedef struct optlst { short idc; UCHAR type; UCHAR bitN; TCHAR *section; char *name; void *def; -}; -static void ReadDialogOptions(HWND hwnd,const struct optlst *ol, unsigned size) +} optlst_t; +static void ReadDialogOptions(HWND hwnd,const optlst_t *ol, unsigned size) { unsigned i; for (i=0; i < size; i++) { @@ -440,7 +462,7 @@ static void ReadDialogOptions(HWND hwnd,const struct optlst *ol, unsigned size) ReadOptionStrW(hwnd, ol[i].idc, ol[i].section, ol[i].name, (TCHAR*)ol[i].def); } } -static void WriteDialogOptions(HWND hwnd,const struct optlst *ol, unsigned size) +static void WriteDialogOptions(HWND hwnd,const optlst_t *ol, unsigned size) { unsigned i; for (i=0; i < size; i++) { @@ -491,7 +513,7 @@ static INT_PTR CALLBACK GeneralPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam { #define V (void *) // Options to bead or written... - static const struct optlst optlst[] = { + static const optlst_t optlst[] = { // dialog id, type, bit number, section name, option name, def val. { IDC_AUTOFOCUS, T_BOL, 0, TEXT("General"), "AutoFocus", V 0 }, { IDC_AERO, T_BOL, 0, TEXT("General"), "Aero", V 1 }, @@ -757,13 +779,13 @@ static void CheckConfigHotKeys(const struct hk_struct *hotkeys, HWND hwnd, const } -struct actiondl { +typedef struct tagActiondl { TCHAR *action; short l10nidx; -// const unsigned short flgs; -// const TCHAR *const l10n; -}; -static void FillActionDropListS(HWND hwnd, int idc, TCHAR *inioption, const struct actiondl *actions) +// BYTE params1_type; +// BYTE params2_type; +} actiondl_t; +static void FillActionDropListS(HWND hwnd, int idc, TCHAR *inioption, const actiondl_t *actions) { HWND control = GetDlgItem(hwnd, idc); TCHAR txt[64]; @@ -782,32 +804,40 @@ static void FillActionDropListS(HWND hwnd, int idc, TCHAR *inioption, const stru } } if (sel < 0) { - // sel is negative if the string was not found in the struct actiondl: + // sel is negative if the string was not found in the actiondl_t: // UNKNOWN ACTION, so we add it manually at the end of the list CB_AddString(control, txt); sel = j; // And select this unknown action. } CB_SetCurSel(control, sel); } -static void WriteActionDropListS(HWND hwnd, int idc, TCHAR *inioption, const struct actiondl *actions) + +static int GetActionStringFromDropList(HWND hwnd, int idc, const actiondl_t *actions, TCHAR *obuf, size_t obuflen) { HWND control = GetDlgItem(hwnd, idc); int j = SendMessage(control, CB_GETCURSEL, 0, 0); if (j >= 0 && actions[j].action) { // Inside of known values - WritePrivateProfileString(TEXT("Input"), inioption, actions[j].action, inipath); - return; // DONE! + lstrcpy_s(obuf, obuflen, actions[j].action); // DONE! + return 1; } // User directly Wrote the specified string? - TCHAR txt[128]; txt[0] = TEXT('\0'); - if (0 < (int)(DWORD)SendMessage(control, WM_GETTEXT, ARR_SZ(txt), (LPARAM)txt) && *txt ) { + int len = (int)(DWORD)SendMessage(control, WM_GETTEXT, obuflen, (LPARAM)obuf); + if (0 < len && *obuf) { // Action was direcly written! - j = SendMessage(control, CB_FINDSTRINGEXACT, /*start index=*/-1, (LPARAM)txt); + j = SendMessage(control, CB_FINDSTRINGEXACT, /*start index=*/-1, (LPARAM)obuf); if (j>=0 && actions[j].action) // Found index. - WritePrivateProfileString(TEXT("Input"), inioption, actions[j].action, inipath); - else - WritePrivateProfileString(TEXT("Input"), inioption, txt, inipath); + lstrcpy_s(obuf, obuflen, actions[j].action); // DONE! + + return 1; } + return 0; +} +static void WriteActionDropListS(HWND hwnd, int idc, TCHAR *inioption, const actiondl_t *actions) +{ + TCHAR txt[128]; txt[0] = TEXT('\0'); + GetActionStringFromDropList(hwnd, idc, actions, txt, ARR_SZ(txt)); + WritePrivateProfileString(TEXT("Input"), inioption, txt, inipath); } ///////////////////////////////////////////////////////////////////////////// static INT_PTR CALLBACK MousePageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -862,7 +892,7 @@ static INT_PTR CALLBACK MousePageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, {TEXT("Menu"), L10NIDX(InputActionMenu) }, \ - static const struct actiondl mouse_actions[] = { + static const actiondl_t mouse_actions[] = { // Specific to the Primary/Alternate/Titlebar // And not available for the MoveUp/ResizeUp {TEXT("Move"), L10NIDX(InputActionMove) }, @@ -876,12 +906,12 @@ static INT_PTR CALLBACK MousePageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, }; // Actions on MoveUp/ResizeUP - const struct actiondl *mouse_actionsUP = &mouse_actions[3]; + const actiondl_t *mouse_actionsUP = &mouse_actions[3]; // While moving/resizing - const struct actiondl *mouse_actionsWMR = &mouse_actions[3]; + const actiondl_t *mouse_actionsWMR = &mouse_actions[3]; -// static const struct actiondl mouse_actionsWMR[] = { +// static const actiondl_t mouse_actionsWMR[] = { // // Spetial actions first // {TEXT("ZoneSnapTogg"), L10NIDX(input_actions_zonesnaptog) }, // {TEXT("SnapTogg"), L10NIDX(input_actions_snaptogg) }, @@ -901,7 +931,7 @@ static INT_PTR CALLBACK MousePageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, { IDC_HSCROLL, {TEXT("HScroll"), TEXT("HScrollB"), TEXT("HScrollT"), TEXT("HScrollM"), TEXT("HScrollR") } } }; - static const struct actiondl scroll_actions[] = { + static const actiondl_t scroll_actions[] = { {TEXT("AltTab"), L10NIDX(InputActionAltTab) }, {TEXT("Volume"), L10NIDX(InputActionVolume) }, {TEXT("Transparency"), L10NIDX(InputActionTransparency) }, @@ -926,7 +956,7 @@ static INT_PTR CALLBACK MousePageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, { 0, 0 } }; - static const struct optlst optlst[] = { + static const optlst_t optlst[] = { { IDC_TTBACTIONSNA, T_BMK, 0, TEXT("Input"), "TTBActions", 0 }, { IDC_TTBACTIONSWA, T_BMK, 1, TEXT("Input"), "TTBActions", 0 }, { IDC_LONGCLICKMOVE, T_BOL, 0, TEXT("Input"), "LongClickMove", 0 } @@ -1102,9 +1132,9 @@ static LRESULT WINAPI PickShortcutWinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM HWND phwnd = GetParent(hwnd); EnableDlgItem(phwnd, IDC_SHORTCUTS_PICK, 1); EnumChildWindows(phwnd, EnableAllControlsProc, 1); - NMHDR lpn; - lpn.hwndFrom = NULL; lpn.code = PSN_SETACTIVE; - SendMessage(phwnd, WM_NOTIFY, 0, (LPARAM)&lpn); +// NMHDR lpn; +// lpn.hwndFrom = NULL; lpn.code = PSN_SETACTIVE; +// SendMessage(phwnd, WM_NOTIFY, 0, (LPARAM)&lpn); HWND sethwnd = GetDlgItem(phwnd, IDC_SHORTCUTS_SET); EnableWindow(sethwnd, TRUE); SetFocus(sethwnd); @@ -1115,6 +1145,114 @@ static LRESULT WINAPI PickShortcutWinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM } return 0; } + +// Dialog procedure for the Advanced Action construction from base action +typedef struct tagAdvancedActionParam { + const actiondl_t *base_action_lst; + TCHAR outbuf[64]; +} advancedActionParam_t; +static INT_PTR CALLBACK AdvancedActionDlgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) +{ + switch (msg) { + + case WM_INITDIALOG: { + advancedActionParam_t *acp = (advancedActionParam_t *)lp; + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lp); + + FillActionDropListS(hwnd, IDC_ACTIONP0, NULL, acp->base_action_lst); + SendDlgItemMessage(hwnd, IDC_ACTIONP0, CB_SETCURSEL, (WPARAM)-1, 0); + + /* 1=>LEFT, 2=>TOP, 3=>RIGHT, 4=>BOTTOM */ + HWND ctrl = GetDlgItem(hwnd, IDC_ACTIONP1); + CB_AddString(ctrl, TEXT("---")); // 0 + CB_AddString(ctrl, l10n->WayLeft); // 1 / L + CB_AddString(ctrl, l10n->WayUp); // 2 / U + CB_AddString(ctrl, l10n->WayRight); // 3 / R + CB_AddString(ctrl, l10n->WayDown); // 4 / D + + // Copy localized OK, CANCEL button from parent + HWND parent = GetAncestor(hwnd, GA_ROOTOWNER); + if (parent) { + TCHAR txt[32]; + if (GetDlgItemText(parent, IDOK, txt, ARR_SZ(txt))) + SetDlgItemText(hwnd, IDOK, txt); + if (GetDlgItemText(parent, IDCANCEL, txt, ARR_SZ(txt))) + SetDlgItemText(hwnd, IDCANCEL, txt); + } + + return TRUE; /* Autofocus first element in dialog */ + } break; + + case WM_COMMAND: { + int id = LOWORD(wp); + if (id == IDOK) { + advancedActionParam_t *acp = (advancedActionParam_t *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + if(!acp) return 0; + mem00(acp->outbuf, sizeof(acp->outbuf)); + // Get the text from the action string display to return + GetDlgItemText(hwnd, IDC_ACTIONTSTRING, acp->outbuf, ARR_SZ(acp->outbuf) - 1); + EndDialog(hwnd, IDOK); + return TRUE; + } else if (id == IDCANCEL) { + EndDialog(hwnd, IDCANCEL); + return TRUE; + } else { + int ev = HIWORD(wp); + int update_action_string = + (ev == CBN_SELCHANGE || ev == CBN_EDITCHANGE || ev == EN_UPDATE) + &&(id == IDC_ACTIONP0 || id == IDC_ACTIONP1 || IDC_ACTIONP2); + + if (update_action_string) { + advancedActionParam_t *acp = (advancedActionParam_t *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + TCHAR acstr[128], param1[16], param2[32]; acstr[0] = TEXT('\0'); + + // ACTION PARAM0: base action + GetActionStringFromDropList(hwnd, IDC_ACTIONP0, acp->base_action_lst, acstr, ARR_SZ(acstr)-8); + + // ACTION PARAM1: direction flags + param1[0] = TEXT('0'); param1[1] = TEXT('\0'); + int direction = SendDlgItemMessage(hwnd, IDC_ACTIONP1, CB_GETCURSEL, 0, 0); + if (direction < 0) { + GetDlgItemText(hwnd, IDC_ACTIONP1, param1, ARR_SZ(param1)); + } else if (direction <= 4) { + static const TCHAR *directionchars = TEXT("0LURD"); + param1[0] = directionchars[direction]; + param1[1] = TEXT('\0'); + } + // ACTION PARAM2 number... + int param2len = GetDlgItemText(hwnd, IDC_ACTIONP2, param2, ARR_SZ(param2)); + + // Add PARAM1 if needed + if ((*param1 && *param1 != TEXT('0')) || (param2len && *param2)) { + lstrcat_s(acstr, ARR_SZ(acstr), TEXT("_")); + lstrcat_s(acstr, ARR_SZ(acstr), param1); + // Add PARAM2 if needed + if (param2len && *param2) { + lstrcat_s(acstr, ARR_SZ(acstr), TEXT("_")); + lstrcat_s(acstr, ARR_SZ(acstr), param2); + } + } + + // show the whole string + SetDlgItemText(hwnd, IDC_ACTIONTSTRING, acstr); + return TRUE; + } + } + } break; + + case WM_SYSCOMMAND: + { + if(wp == SC_CLOSE) { + EndDialog(hwnd, IDCANCEL); + return TRUE; + } + } break; + + } /* end switch(msg) */ + + return FALSE; /* non processed */ +} + ///////////////////////////////////////////////////////////////////////////// static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { @@ -1130,7 +1268,7 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara { IDC_RIGHTCTRL, VK_RCONTROL }, { 0, 0 } }; - static const struct actiondl kb_actions[] = { + static const actiondl_t kb_actions[] = { {TEXT("Move"), L10NIDX(InputActionMove) }, {TEXT("Resize"), L10NIDX(InputActionResize) }, {TEXT("Close"), L10NIDX(InputActionClose) }, @@ -1148,7 +1286,7 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara {TEXT("Nothing"), L10NIDX(InputActionNothing) }, {NULL, 0} }; - static const struct actiondl kbshortcut_actions[] = { + static const actiondl_t kbshortcut_actions[] = { {TEXT("Kill"), L10NIDX(InputActionKill) }, {TEXT("Pause"), L10NIDX(InputActionPause) }, {TEXT("Resume"), L10NIDX(InputActionResume) }, @@ -1175,38 +1313,14 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara {TEXT("AltTabFullList"),L10NIDX(InputActionAltTabFullList) }, {TEXT("ExtendTNEdge"),L10NIDX(InputActionExtendTNEdge) }, - {TEXT("XTNLEdge"), L10NIDX(InputActionXTNLEdge) }, - {TEXT("XTNTEdge"), L10NIDX(InputActionXTNTEdge) }, - {TEXT("XTNREdge"), L10NIDX(InputActionXTNREdge) }, - {TEXT("XTNBEdge"), L10NIDX(InputActionXTNBEdge) }, {TEXT("MoveTNEdge"), L10NIDX(InputActionMoveTNEdge) }, - {TEXT("MTNLEdge"), L10NIDX(InputActionMTNLEdge) }, - {TEXT("MTNTEdge"), L10NIDX(InputActionMTNTEdge) }, - {TEXT("MTNREdge"), L10NIDX(InputActionMTNREdge) }, - {TEXT("MTNBEdge"), L10NIDX(InputActionMTNBEdge) }, - - {TEXT("MLZone"), L10NIDX(InputActionMLZone) }, - {TEXT("MTZone"), L10NIDX(InputActionMTZone) }, - {TEXT("MRZone"), L10NIDX(InputActionMRZone) }, - {TEXT("MBZone"), L10NIDX(InputActionMBZone) }, - {TEXT("XLZone"), L10NIDX(InputActionXLZone) }, - {TEXT("XTZone"), L10NIDX(InputActionXTZone) }, - {TEXT("XRZone"), L10NIDX(InputActionXRZone) }, - {TEXT("XBZone"), L10NIDX(InputActionXBZone) }, - - {TEXT("StepL"), L10NIDX(InputActionStepL) }, - {TEXT("StepT"), L10NIDX(InputActionStepT) }, - {TEXT("StepR"), L10NIDX(InputActionStepR) }, - {TEXT("StepB"), L10NIDX(InputActionStepB) }, - {TEXT("SStepL"), L10NIDX(InputActionSStepL) }, - {TEXT("SStepT"), L10NIDX(InputActionSStepT) }, - {TEXT("SStepR"), L10NIDX(InputActionSStepR) }, - {TEXT("SStepB"), L10NIDX(InputActionSStepB) }, - - {TEXT("FocusL"), L10NIDX(InputActionFocusL) }, - {TEXT("FocusT"), L10NIDX(InputActionFocusT) }, - {TEXT("FocusR"), L10NIDX(InputActionFocusR) }, - {TEXT("FocusB"), L10NIDX(InputActionFocusB) }, + + {TEXT("MZone"), L10NIDX(InputActionMZone) }, + {TEXT("XZone"), L10NIDX(InputActionXZone) }, + + {TEXT("Step"), L10NIDX(InputActionStep) }, + + {TEXT("Focus"), L10NIDX(InputActionFocus) }, {TEXT("NLayout"), L10NIDX(InputActionNLayout) }, {TEXT("PLayout"), L10NIDX(InputActionPLayout) }, @@ -1215,7 +1329,7 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara }; // Hotkeys - static const struct actiondl togglekeys[] = { + static const actiondl_t togglekeys[] = { {TEXT(""), L10NIDX(InputActionNothing)}, {TEXT("A4 A5"), L10NIDX(InputHotkeysAlt)}, {TEXT("5B 5C"), L10NIDX(InputHotkeysWinkey)}, @@ -1231,7 +1345,7 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara {TEXT("A1"), L10NIDX(InputHotkeysRightShift)}, {NULL, 0}, }; - static const struct optlst optlst[] = { + static const optlst_t optlst[] = { { IDC_SCROLLLOCKSTATE, T_BMK, 0, TEXT("Input"), "ScrollLockState", 0}, { IDC_UNIKEYHOLDMENU, T_BOL, 0, TEXT("Input"), "UniKeyHoldMenu", 0}, { IDC_KEYCOMBO, T_BOL, 0, TEXT("Input"), "KeyCombo", 0 }, @@ -1275,14 +1389,15 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara // KEYBOARD SHORTCUTS HANDLING // READ Keyboard Shortcut - if (id == IDC_SHORTCUTS_AC && event == CBN_SELCHANGE) { + if (id == IDC_SHORTCUTS_AC && (event == CBN_SELCHANGE || event == CBN_EDITCHANGE)) { // Update the shortcut with the current one. - int i = CB_GetCurSelId(IDC_SHORTCUTS_AC); + TCHAR txt[64]; + int i = CB_GetTextAndIdx((HWND)lParam, txt, ARR_SZ(txt)); edit_shortcut_idx = i; - WORD shortcut= GetPrivateProfileInt(TEXT("KBShortcuts"), kbshortcut_actions[i].action, 0, inipath); + //MessageBox(hwnd, txt, NULL, 0); + WORD shortcut = GetPrivateProfileInt(TEXT("KBShortcuts"), txt, 0, inipath); BYTE vKey = LOBYTE(shortcut); BYTE mod = HIBYTE(shortcut); - TCHAR txt[LPTR_HDIGITS+1]; SetDlgItemText(hwnd, IDC_SHORTCUTS_VK, LPTR2Hex(txt, vKey)); CheckDlgButton(hwnd, IDC_CONTROL,(mod&MOD_CONTROL)? BST_CHECKED: BST_UNCHECKED); @@ -1291,9 +1406,9 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara CheckDlgButton(hwnd, IDC_ALT, (mod&MOD_ALT)? BST_CHECKED: BST_UNCHECKED); EnableDlgItem(hwnd, IDC_SHORTCUTS_SET, 0); } - // WRITE Current Keyboard Shortcut + // WRITE Current Keyboard Shortcut to ini file if (id == IDC_SHORTCUTS_SET) { - TCHAR txt[UINT_DIGITS+1]; + TCHAR txt[UINT_DIGITS+1], action_string_buf[64]; // MOD_ALT=1, MOD_CONTROL=2, MOD_SHIFT=4, MOD_WIN=8 GetDlgItemText(hwnd, IDC_SHORTCUTS_VK, txt, 3); BYTE vKey = lstrhex2u(txt); @@ -1302,9 +1417,13 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara | (IsChecked(IDC_SHIFT)<<2) | (IsChecked(IDC_WINKEY)<<3); WORD shortcut = vKey | (mod << 8); - int i = CB_GetCurSelId(IDC_SHORTCUTS_AC); - if (kbshortcut_actions[i].action && kbshortcut_actions[i].action[0] != '\0') - WritePrivateProfileString(TEXT("KBShortcuts"), kbshortcut_actions[i].action, Uint2lStr(txt, shortcut), inipath); + action_string_buf[0] = TEXT('\0'); + int astrlen = GetDlgItemText(hwnd, IDC_SHORTCUTS_AC, action_string_buf, ARR_SZ(action_string_buf)); + if (0 < astrlen && *action_string_buf) { + const TCHAR *intstr = shortcut ? Uint2lStr(txt, shortcut) : NULL; // NULL will remove the KEY + edit_shortcut_idx = CB_AddStringIfNotPresentAndGetIdx(GetDlgItem(hwnd, IDC_SHORTCUTS_AC), action_string_buf); + WritePrivateProfileString(TEXT("KBShortcuts"), action_string_buf, intstr, inipath); + } EnableDlgItem(hwnd, IDC_SHORTCUTS_SET, 0); SetFocus(GetDlgItem(hwnd, IDC_SHORTCUTS_AC)); goto APPLY_ALL; @@ -1348,6 +1467,21 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara SetDlgItemText(hwnd, IDC_SHORTCUTS_VK, TEXT("")); EnableDlgItem(hwnd, IDC_SHORTCUTS_SET, 1); } + if (id == IDC_ADVANCEDBT_AC) { + // We must show the advanced action modal dialog + // and fill the IDC_SHORTCUTS_AC combobox with it. + advancedActionParam_t acp; + acp.base_action_lst = kbshortcut_actions; + acp.outbuf[0] = TEXT('\0'); + int code = DialogBoxParam(g_hinst, MAKEINTRESOURCE(IDD_ACTIONPARAM), hwnd, AdvancedActionDlgProc, (LPARAM)&acp); + if (code == IDOK && acp.outbuf[0]) { + HWND control = GetDlgItem(hwnd, IDC_SHORTCUTS_AC); + int new_index = CB_AddStringIfNotPresentAndGetIdx(control, acp.outbuf); + CB_SetCurSel(control, new_index); + edit_shortcut_idx = new_index; + SetFocus(control); + } + } } else if (msg == WM_NOTIFY) { if (pnmh->code == PSN_SETACTIVE) { @@ -1360,10 +1494,28 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara FillActionDropListS(hwnd, IDC_GRABWITHALT, TEXT("GrabWithAlt"), kb_actions); FillActionDropListS(hwnd, IDC_GRABWITHALTB, TEXT("GrabWithAltB"), kb_actions); - FillActionDropListS(hwnd, IDC_SHORTCUTS_AC, NULL, kbshortcut_actions); + + //FillActionDropListS(hwnd, IDC_SHORTCUTS_AC, NULL, kbshortcut_actions); + { // Fill combobox with all the shortcuts that are currently configured + TCHAR kbsec[1600]; + HWND control = GetDlgItem(hwnd, IDC_SHORTCUTS_AC); + CB_ResetContent(control); + GetPrivateProfileSection(TEXT("KBShortcuts"), kbsec, ARR_SZ(kbsec), inipath); + for (TCHAR *p=kbsec; *p != TEXT('\0'); p += lstrlen(p) + 1) { + //MessageBox(hwnd, p, TEXT("KBShortcuts"), 0); + TCHAR *pp = lstrchr(p, TEXT('=')); + if(!pp) continue; // No equal sign... + *pp = TEXT('\0'); + if (!lstrcmpi(p, TEXT("UsePtWindow"))) + continue; + CB_AddString(control, p); + p = pp+1; + } + } CB_SetCurSel(GetDlgItem(hwnd, IDC_SHORTCUTS_AC), edit_shortcut_idx); EnableDlgItem(hwnd, IDC_SHORTCUTS_SET, 0); - if(pnmh->hwndFrom != NULL)PostMessage(hwnd, WM_COMMAND, IDC_SHORTCUTS_AC|CBN_SELCHANGE<<16, 0); + if (pnmh->hwndFrom != NULL) + PostMessage(hwnd, WM_COMMAND, IDC_SHORTCUTS_AC|CBN_SELCHANGE<<16, (LPARAM)GetDlgItem(hwnd, IDC_SHORTCUTS_AC)); // ModKey init HWND control = GetDlgItem(hwnd, IDC_MODKEY); @@ -1439,7 +1591,7 @@ static INT_PTR CALLBACK KeyboardPageDialogProc(HWND hwnd, UINT msg, WPARAM wPara static INT_PTR CALLBACK BlacklistPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { #pragma GCC diagnostic ignored "-Wint-conversion" - static const struct optlst optlst[] = { + static const optlst_t optlst[] = { { IDC_PROCESSBLACKLIST, T_STR, 0, TEXT("Blacklist"), "Processes", TEXT("") }, { IDC_BLACKLIST, T_STR, 0, TEXT("Blacklist"), "Windows", TEXT("") }, { IDC_SCROLLLIST, T_STR, 0, TEXT("Blacklist"), "Scroll", TEXT("") }, @@ -2027,7 +2179,7 @@ static HWND NewTestWindowAt(int x, int y, int width, int height) static INT_PTR CALLBACK AdvancedPageDialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { #define V (void *) - static const struct optlst optlst[] = { + static const optlst_t optlst[] = { { IDC_AUTOREMAXIMIZE, T_BOL, 0, TEXT("Advanced"), "AutoRemaximize", V 0 }, { IDC_AEROTOPMAXIMIZES, T_BMK, 0, TEXT("Advanced"), "AeroTopMaximizes", V 1 },// bit 0 { IDC_AERODBCLICKSHIFT, T_BMK, 1, TEXT("Advanced"), "AeroTopMaximizes", V 1 },// bit 1 diff --git a/hooks.c b/hooks.c index c0741266..92e355fd 100644 --- a/hooks.c +++ b/hooks.c @@ -68,7 +68,7 @@ enum buttonstate {STATE_NONE, STATE_DOWN, STATE_UP}; #define BT_PROBE (1<<16) -static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, int button); +static int init_movement_and_actions(POINT pt, HWND hwnd, action_t action, int button); static void FinishMovementAsync(); static void MoveTransWin(int x, int y, int w, int h); static void MouseMoveNow(POINT pt); @@ -155,10 +155,10 @@ static struct { UINT dpi; } origin; - UCHAR sactiondone; + action_t sactiondone; UCHAR xxbutton; UCHAR ignorept; - enum action action; + action_t action; struct resizeXY resize; HWND cached_hwnd_blacklist; TCHAR exename[MAX_PATH]; @@ -217,8 +217,6 @@ static struct config { UCHAR AutoRemaximize; UCHAR SnapThreshold; UCHAR AeroThreshold; - UCHAR KBMoveStep; - UCHAR KBMoveSStep; UCHAR AeroTopMaximizes; UCHAR UseCursor; UCHAR MinAlpha; @@ -291,12 +289,13 @@ static struct config { UCHAR MenuAccelMap[36 + 1]; UCHAR pad0[3]; - enum action Mouse[NACPB*(20+4)]; // Up to 20 buttons + vertical and horizontal wheels D/U; - enum action GrabWithAlt[NACPB]; // Actions without click - enum action MoveUp[NACPB]; // Actions on (long) Move Up w/o drag - enum action ResizeUp[NACPB]; // Actions on (long) Resize Up w/o drag + action_t Mouse[NACPB*(20+4)]; // Up to 20 buttons + vertical and horizontal wheels D/U; + action_t GrabWithAlt[NACPB]; // Actions without click + action_t MoveUp[NACPB]; // Actions on (long) Move Up w/o drag + action_t ResizeUp[NACPB]; // Actions on (long) Resize Up w/o drag - UCHAR *inputSequences[AC_SHRTF-AC_SHRT0]; // 36 + UCHAR *inputSequences[36]; // 36 + action_t KBShortcutsList[64]; } conf; struct OptionListItem { @@ -327,8 +326,6 @@ static const struct OptionListItem Advanced_uchars[] = { { "AutoRemaximize", 0 }, { "SnapThreshold", 20 }, { "AeroThreshold", 5 }, - { "KBMoveStep", 100 }, - { "KBMoveSStep", 10 }, { "AeroTopMaximizes", 1 }, { "UseCursor", 1 }, { "MinAlpha", 32 }, @@ -805,32 +802,29 @@ static struct rgSnWnds { BOOL CALLBACK EnumSnappedWindows(HWND hwnd, LPARAM lParam) { - RECT wnd; + struct snwdata snw = { 0 }; if (ShouldSnapTo(hwnd) && !IsZoomed(hwnd) - && GetWindowRectL(hwnd, &wnd)) { + && GetWindowRectL(hwnd, &snw.rc)) { unsigned restore; - if (conf.SmartAero&2 || IsWindowSnapped(hwnd)) { // In SMARTER snapping mode or if the WINDOW IS SNAPPED // We only consider the position of the window // to determine its snapping state MONITORINFO mi; GetMonitorInfoFromWin(hwnd, &mi); - snwnds.it[snwnds.num].flag = WhichSideRectInRect(&mi.rcWork, &wnd); + snw.flag = WhichSideRectInRect(&mi.rcWork, &snw.rc); } else if ((restore = GetRestoreFlag(hwnd)) && restore&SNAPPED && restore&SNAPPEDSIDE) { // The window was AltSnapped... - snwnds.it[snwnds.num].flag = restore; + snw.flag = restore; } else { // thiw window is not snapped. return TRUE; // next hwnd } // Add the window to the list - struct snwdata *new_wnd = (struct snwdata *)ListAppend(&snwnds, NULL, sizeof(*snwnds.it)); - if (!new_wnd) return FALSE; - OffsetRectMDI(&wnd); - CopyRect(&new_wnd->rc, &wnd); - new_wnd->hwnd = hwnd; + snw.hwnd = hwnd; + OffsetRectMDI(&snw.rc); + ListAppend(&snwnds, &snw, sizeof(*snwnds.it)); } return TRUE; } @@ -892,7 +886,7 @@ static void EndDeferWindowPosNow(HDWP hwndSS) static int ShouldResizeTouching() { - return state.action == AC_RESIZE + return state.action.ac == AC_RESIZE && ( (conf.StickyResize&1 && state.shift) || ((conf.StickyResize&3)==2 && !state.shift) ); @@ -1777,33 +1771,33 @@ static pure int ModKey() } /////////////////////////////////////////////////////////////////////////// // Get action of button -static enum action GetAction(const int button) +static action_t GetAction(const int button) { if (button) { // Ugly pointer arithmetic (LMB <==> button == 2) return conf.Mouse[(button-2)*NACPB+ModKey()]; } else { - return AC_NONE; + return (action_t){ AC_NONE }; } } -static enum action GetActionT(const int button) +static action_t GetActionT(const int button) { if (button) { // Ugly pointer arithmetic +2 compared to non titlebar return conf.Mouse[2+(button-2)*NACPB+ModKey()]; } else { - return AC_NONE; + return (action_t){ AC_NONE }; } } -static enum action GetActionMR(const int button) +static action_t GetActionMR(const int button) { if (button) { // Ugly pointer arithmetic // state.action == 1 or 2 // MB[4/5] == Action/Alt while moving // MB[6/7] == Action/Alt while Resizing - int offset = state.action<<1; // 2 or 4 + int offset = state.action.ac << 1; // 2 or 4 return conf.Mouse[2+offset+(button-2)*NACPB+ModKey()]; } else { - return AC_NONE; + return (action_t) { AC_NONE }; } } #define IsHotkey(a) IsHotkeyy(a, conf.Hotkeys) @@ -1992,13 +1986,13 @@ static BOOL GetMDInfo(POINT *mdicpt, RECT *wnd) } /////////////////////////////////////////////////////////////////////////// // -static void SetOriginFromRestoreData(HWND hwnd, enum action action) +static void SetOriginFromRestoreData(HWND hwnd, action_t action) { // Set Origin width and height needed for AC_MOVE/RESIZE/CENTER/MAXHV int rwidth=0, rheight=0; unsigned rdata_flag = GetRestoreData(hwnd, &rwidth, &rheight); // Clear snapping info if asked. - if (rdata_flag&SNCLEAR || (conf.SmartAero&4 && action == AC_MOVE)) { + if (rdata_flag&SNCLEAR || (conf.SmartAero&4 && action.ac == AC_MOVE)) { ClearRestoreData(hwnd); rdata_flag=0; } @@ -2140,7 +2134,7 @@ static void MouseMoveNow(POINT pt) MoveWindow(g_mainhwnd, pt.x-128, pt.y-128, 256, 256, FALSE); if (state.moving == CURSOR_ONLY) { - if (state.action == AC_RESIZE) { + if (state.action.ac == AC_RESIZE) { RECT rc; GetWindowRect(state.hwnd, &rc); SetEdgeAndOffset(&rc, pt); @@ -2158,7 +2152,7 @@ static void MouseMoveNow(POINT pt) if (!state.moving) { LastWin.odpi = state.origin.dpi; SetOriginFromRestoreData(state.hwnd, state.action); - if (state.action == AC_MOVE) { + if (state.action.ac == AC_MOVE) { was_snapped = IsWindowSnapped(state.hwnd); RestoreOldWin(pt, was_snapped, &wnd); } @@ -2175,7 +2169,7 @@ static void MouseMoveNow(POINT pt) // Get new position for window LastWin.end = 0; LastWin.moveonly = 0; - if (state.action == AC_MOVE) { + if (state.action.ac == AC_MOVE) { // SWP_NOSIZE to SetWindowPos LastWin.moveonly = state.moving; posx = pt.x-state.offset.x; @@ -2212,7 +2206,7 @@ static void MouseMoveNow(POINT pt) EnumOnce(RECALC_INVISIBLE_BORDERS); } - } else if (state.action == AC_RESIZE) { + } else if (state.action.ac == AC_RESIZE) { // Restore the window (to monitor size) if it's maximized if (!state.moving && IsZoomed(state.hwnd)) { RestoreToMonitorSize(state.hwnd, &wnd); @@ -2422,7 +2416,7 @@ static void SendUnicodeKey(WORD w) /////////////////////////////////////////////////////////////////////////// static void RestrictToCurentMonitor() { - if (state.action || state.alt) { + if (state.action.ac || state.alt) { POINT pt; GetCursorPos(&pt); state.origin.maximized = 0; // To prevent auto-remax on Ctrl @@ -2436,7 +2430,7 @@ static void HotkeyUp() // The way this works is that the alt key is "disguised" by sending // ctrl keydown/keyup events LOG("HotkeyUp()"); - if (state.blockaltup || state.action) { + if (state.blockaltup || state.action.ac) { Send_CTRL(); state.blockaltup = 0; // If there is more that one key down remaining @@ -2447,14 +2441,14 @@ static void HotkeyUp() // Hotkeys have been released state.alt = 0; state.alt1 = 0; - if (state.action - && (conf.GrabWithAlt[0] || conf.GrabWithAlt[1]) + if (state.action.ac + && (conf.GrabWithAlt[0].ac || conf.GrabWithAlt[1].ac) && (MOUVEMENT(conf.GrabWithAlt[0]) || MOUVEMENT(conf.GrabWithAlt[1]))) { FinishMovementAsync(); } // Unhook mouse if no actions is ongoing. - if (!state.action) { + if (!state.action.ac) { UnhookMouse(); } } @@ -2573,7 +2567,7 @@ static int ScrollLockState() if( (conf.ScrollLockState&1) && !( !(GetKeyState(VK_SCROLL)&1) ^ !(conf.ScrollLockState&2) ) ) { - if (state.action) + if (state.action.ac) FinishMovementAsync(); return 1; } @@ -2591,7 +2585,7 @@ static void LogState(const char *Title) "shift=%d\n" "alt=%d\n" "alt1=%d\n" - , (int)state.action + , (int)state.action.ac , (int)state.moving , (int)state.ctrl , (int)state.shift @@ -2689,7 +2683,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP if (ScrollLockState()) return CallNextHookEx(NULL, nCode, wParam, lParam); if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) { - if (!state.alt && !state.action + if (!state.alt && !state.action.ac && (!conf.KeyCombo || (state.alt1 && state.alt1 != vkey)) && IsHotkey(vkey) && (!conf.MaxKeysNum || TotNumberOfKeysDown() < conf.MaxKeysNum)) { @@ -2719,10 +2713,10 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP // Hook mouse HookMouse(); - if (conf.GrabWithAlt[0] || conf.GrabWithAlt[1]) { + if (conf.GrabWithAlt[0].ac || conf.GrabWithAlt[1].ac) { POINT pt; - enum action action = conf.GrabWithAlt[IsModKey(vkey) || (!IsHotkey(conf.ModKey[0])&&ModKey())]; - if (action) { + action_t action = conf.GrabWithAlt[IsModKey(vkey) || (!IsHotkey(conf.ModKey[0])&&ModKey())]; + if (action.ac) { state.blockmouseup = 0; // In case. GetCursorPos(&pt); if (!init_movement_and_actions(pt, NULL, action, vkey)) { @@ -2731,7 +2725,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP state.blockmouseup = 0; // In case. } } - } else if (conf.KeyCombo && !state.alt1 && !state.action && IsHotkey(vkey)) { + } else if (conf.KeyCombo && !state.alt1 && !state.action.ac && IsHotkey(vkey)) { state.alt1 = vkey; } else if (IsHotkeyy(vkey, conf.Shiftkeys)) { @@ -2746,13 +2740,13 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP } // Block keydown to prevent Windows from changing keyboard layout - if (state.alt && state.action) { + if (state.alt && state.action.ac) { return 1; } - } else if (vkey == VK_SPACE && state.action && !IsSamePTT(&state.clickpt, &state.prevpt)) { + } else if (vkey == VK_SPACE && state.action.ac && !IsSamePTT(&state.clickpt, &state.prevpt)) { ToggleSnapState(); return 1; // Block to avoid sys menu. - } else if (state.alt && state.action == conf.GrabWithAlt[ModKey()] && IsKillkey(vkey)) { + } else if (state.alt && state.action.ac == conf.GrabWithAlt[ModKey()].ac && IsKillkey(vkey)) { // Release Hook on Alt+KillKey // eg: DisplayFusion Alt+Tab elevated windows captures AltUp HotkeyUp(); @@ -2771,8 +2765,8 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP } // Stop current action - if (state.action || state.alt) { - enum action action = state.action; + if (state.action.ac || state.alt) { + action_t action = state.action; HideTransWin(); // Send WM_EXITSIZEMOVE and EVENT_SYSTEM_MOVESIZEEND NotifySizeMoveStaEnd(state.hwnd, 0); @@ -2783,12 +2777,12 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP UnhookMouse(); // Block ESC if an action was ongoing - if (action) return 1; + if (action.ac) return 1; } } else if (!state.ctrl && (state.alt!=vkey) /* avoid cursor trapping at first Ctrl dwn if Ctrl was used as hotkey */ && (vkey == VK_LCONTROL || vkey == VK_RCONTROL) - && (!IsHotkey(vkey) || state.action) /* If Ctrl is an hotkey, skip unless already moving */ + && (!IsHotkey(vkey) || state.action.ac) /* If Ctrl is an hotkey, skip unless already moving */ && !(kbh->scanCode&SCANCODE_SIMULATED) /* Ignore ALT GR Scan Code (&0x0200) */ && !IsModKey(vkey)/*vkey != conf.ModKey*/ ) { RestrictToCurentMonitor(); @@ -2797,7 +2791,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP //LOGA("sC=%lu", kbh->scanCode); state.ctrl = 1; state.ctrlpt = state.prevpt; // Save point where ctrl was pressed. - if (state.action) { + if (state.action.ac) { SetForegroundWindowL(state.hwnd); } } else if (state.sclickhwnd && g_mchwnd && state.alt && (vkey == VK_LMENU || vkey == VK_RMENU)) { @@ -2806,7 +2800,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP || (IsWindow(state.sclickhwnd) && IsWindow(g_mchwnd) && IsMenu(state.unikeymenu))) return 1; } else if ((xxbtidx = XXButtonIndex(vkey)) >=0 - && (GetAction(BT_MMB+xxbtidx) || GetActionT(BT_MMB+xxbtidx) || IsHotclick(BT_MMB+xxbtidx))) { + && (GetAction(BT_MMB+xxbtidx).ac || GetActionT(BT_MMB+xxbtidx).ac || IsHotclick(BT_MMB+xxbtidx))) { if (!state.xxbutton) { state.xxbutton = 1; // To Ignore autorepeat... SimulateXButton(WM_XBUTTONDOWN, xxbtidx); @@ -2882,7 +2876,7 @@ __declspec(dllexport) LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wP ClipCursorOnce(NULL); // Release cursor trapping state.ctrl = 0; // If there is no ongoing action then Control UP prevents AltDragging... - if (!state.action) state.alt = 0; + if (!state.action.ac) state.alt = 0; } } @@ -3445,7 +3439,7 @@ static HCURSOR CursorToDraw() if (conf.UseCursor == 3) { return LoadCursor(NULL, IDC_ARROW); } - if (state.action == AC_MOVE) { + if (state.action.ac == AC_MOVE) { if (conf.UseCursor == 4) return LoadCursor(NULL, IDC_SIZEALL); cursor = LoadCursor(NULL, conf.UseCursor>1? IDC_ARROW: IDC_HAND); @@ -3635,7 +3629,7 @@ static int ActionMove(POINT pt, int button) { // If this is a double-click if (IsDoubleClick(button)) { - SetOriginFromRestoreData(state.hwnd, AC_MOVE); + SetOriginFromRestoreData(state.hwnd, (action_t){ AC_MOVE }); LastWin.hwnd = NULL; if (state.shift) { RollWindow(state.hwnd, 0); // Roll/Unroll Window... @@ -3645,7 +3639,7 @@ static int ActionMove(POINT pt, int button) // Toggle Maximize window ToggleMaxRestore(state.hwnd); } - state.action = AC_NONE; // Stop move action + state.action = (action_t){ AC_NONE }; // Stop move action state.clicktime = 0; // Reset double-click time state.blockmouseup = 1; // Block the mouseup, otherwise it can trigger a context menu // Prevent mousedown from propagating @@ -3769,7 +3763,7 @@ static void SnapToCorner(HWND hwnd, struct resizeXY resize, UCHAR flags) if (!(flags&SNTO_MOVETO) && !IsResizable(hwnd)) flags = SNTO_MOVETO | SNTO_NEXTBD; // Move to next bd instead - SetOriginFromRestoreData(hwnd, AC_MOVE); + SetOriginFromRestoreData(hwnd, (action_t){ AC_MOVE }); struct rgMMI mmi; GetMinMaxInfo(hwnd, &mmi.Min, &mmi.Max); // for CLAMPH/W functions @@ -3889,12 +3883,12 @@ static void SnapToCorner(HWND hwnd, struct resizeXY resize, UCHAR flags) static int ActionResize(POINT pt, const RECT *wnd, int button) { if(!state.resizable) { - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; return 0;// Next Hook } // Aero-move this window if this is a double-click if (IsDoubleClick(button)) { - state.action = AC_NONE; // Stop resize action + state.action = (action_t){ AC_NONE };; // Stop resize action SnapToCorner(state.hwnd, AUTORESIZE, !state.shift ^ !(conf.AeroTopMaximizes&2)); state.blockmouseup = 1; // Block mouse up (context menu would pop) state.clicktime = 0; // Reset double-click time @@ -3911,7 +3905,7 @@ static int ActionResize(POINT pt, const RECT *wnd, int button) state.offset.x = wnd->right-pt.x; } else if (conf.ResizeCenter == 2) { // Switch to Move action - state.action = AC_MOVE; + state.action.ac = AC_MOVE; } else if (conf.ResizeCenter == 3) { // Use diagonals to select pure L/C R/C T/C B/C SetEdgeToClosestSide(wnd, pt); @@ -3961,7 +3955,7 @@ static void CenterWindow(HWND hwnd, unsigned flags, int full_monitor) POINT pt; int width, height; if (flags & CW_RESTORE) { - SetOriginFromRestoreData(hwnd, AC_MOVE); + SetOriginFromRestoreData(hwnd, (action_t){ AC_MOVE }); width = state.origin.width; height = state.origin.height; } else { @@ -4303,7 +4297,7 @@ static void MaximizeHV(HWND hwnd, int horizontal) POINT pt; GetCursorPos(&pt); GetMonitorRect(&pt, 0, &mon); - SetOriginFromRestoreData(hwnd, AC_MOVE); + SetOriginFromRestoreData(hwnd, (action_t){ AC_MOVE }); SetRestoreData(hwnd, state.origin.width, state.origin.height, SNAPPED); FixDWMRect(hwnd, &bd); @@ -4401,8 +4395,12 @@ static pure BOOL IsRectInMonitors(const RECT *rc) } // Move the window step by step to a direction. // signed step size and direction = 0 for X 1 for Y -static void StepWindow(HWND hwnd, short step, UCHAR direction) +static void StepWindow(HWND hwnd, action_t action) { + // action.fl = 1=>LEFT, 2=>TOP, 3=>RIGHT, 4=>BOTTOM + short step = action.fl <= 2 ? -action.wp : +action.wp; + UCHAR direction = !(action.fl & 1); + RECT rc; if (IsZoomed(hwnd)) { //return; @@ -4589,7 +4587,7 @@ static void ActionStackList(int lasermode) } static void ActionASOnOff() { - if (state.action) FinishMovementAsync(); + if (state.action.ac) FinishMovementAsync(); state.altsnaponoff = !GetProp(g_mainhwnd, APP_ASONOFF); SetProp(g_mainhwnd, APP_ASONOFF, (HANDLE)(DorQWORD)state.altsnaponoff); PostMessage(g_mainhwnd, WM_UPDATETRAY, 0, 0); @@ -4760,18 +4758,20 @@ static HWND FindTiledWindow(HWND hwnd, unsigned char direction) } return NULL; } + ///////////////////////////////////////////////////////////////////////////// // Single click commands -static void SClickActions(HWND hwnd, enum action action) +static void SClickActions(HWND hwnd, action_t action) { - const struct resizeXY RXY_LEFT_CENTER = {RZ_LEFT, RZ_YCENTER}; - const struct resizeXY RXY_RIGHT_CENTER = {RZ_RIGHT, RZ_YCENTER}; - const struct resizeXY RXY_CENTER_TOP = {RZ_XCENTER, RZ_TOP}; - const struct resizeXY RXY_CENTER_BOTTOM = {RZ_XCENTER, RZ_BOTTOM}; - + const struct resizeXY rxy_map[] = { + { RZ_LEFT, RZ_YCENTER }, + { RZ_XCENTER, RZ_TOP }, + { RZ_RIGHT, RZ_YCENTER }, + { RZ_XCENTER, RZ_BOTTOM }, + }; state.sactiondone = action; - LOG("Going to perform action %d", (int)action); - switch (action) { + LOG("Going to perform action (%d)_%d_%d", (int)action.ac, (int)action.fl, (int)action.wp); + switch (action.ac) { case AC_MINIMIZE: MinimizeWindow(hwnd); break; case AC_MAXIMIZE: ActionMaximize(hwnd); break; case AC_CENTER: CenterWindow(hwnd, !state.shift /*state.shift? 0: CW_RESTORE*/, 0); break; @@ -4779,7 +4779,10 @@ static void SClickActions(HWND hwnd, enum action action) case AC_ALWAYSONTOP: TogglesAlwaysOnTop(hwnd); break; case AC_CLOSE: PostMessage(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0); break; case AC_LOWER: ActionLower(hwnd, 0, state.shift, IsCtrlDown()); break; - case AC_FOCUS: ActionLower(hwnd, +120, state.shift, 1); break; + case AC_FOCUS: + if (action.fl == 0) { ActionLower(hwnd, +120, state.shift, 1); } + else if (action.fl <= 4) { ReallySetForegroundWindow(FindTiledWindow(hwnd, action.fl-1)); } + break; case AC_BORDERLESS: ActionBorderless(hwnd); break; case AC_KILL: ActionKill(hwnd); break; case AC_PAUSE: ActionPause(hwnd, 1); break; @@ -4790,8 +4793,14 @@ static void SClickActions(HWND hwnd, enum action action) case AC_MUTE: Send_KEY(VK_VOLUME_MUTE); break; case AC_SIDESNAP: SnapToCorner(hwnd, AUTORESIZE, !!state.shift); break; case AC_EXTENDSNAP: SnapToCorner(hwnd, AUTORESIZE, !state.shift); break; - case AC_EXTENDTNEDGE:SnapToCorner(hwnd, AUTORESIZE, state.shift?SNTO_MOVETO|SNTO_NEXTBD:SNTO_EXTEND|SNTO_NEXTBD); break; - case AC_MOVETNEDGE: SnapToCorner(hwnd, AUTORESIZE, state.shift?SNTO_EXTEND|SNTO_NEXTBD:SNTO_MOVETO|SNTO_NEXTBD); break; + case AC_EXTENDTNEDGE: + if (!action.fl) SnapToCorner(hwnd, AUTORESIZE, state.shift?SNTO_MOVETO|SNTO_NEXTBD:SNTO_EXTEND|SNTO_NEXTBD); + else SnapToCorner(hwnd, rxy_map[min(action.fl-1, 3)], SNTO_EXTEND|SNTO_NEXTBD); + break; + case AC_MOVETNEDGE: + if(!action.fl) SnapToCorner(hwnd, AUTORESIZE, state.shift?SNTO_EXTEND|SNTO_NEXTBD:SNTO_MOVETO|SNTO_NEXTBD); + else SnapToCorner(hwnd, rxy_map[min(action.fl-1, 3)], SNTO_MOVETO|SNTO_NEXTBD); + break; case AC_MENU: ActionMenu(hwnd); break; case AC_NSTACKED: ActionAltTab(state.prevpt, +120, state.shift, EnumStackedWindowsProc); break; case AC_NSTACKED2: ActionAltTab(state.prevpt, +120, !state.shift, EnumStackedWindowsProc); break; @@ -4805,51 +4814,26 @@ static void SClickActions(HWND hwnd, enum action action) case AC_ALTTABFULLLIST: PostMessage(g_mainhwnd, WM_STACKLIST, TRK_MOVETOMONITOR | TRK_LASERMODE, state.shift?(LPARAM)EnumAltTabWindows:(LPARAM)EnumAllAltTabWindows); break; - case AC_MLZONE: MoveWindowToTouchingZone(hwnd, 0, 0); break; // mLeft - case AC_MTZONE: MoveWindowToTouchingZone(hwnd, 1, 0); break; // mTop - case AC_MRZONE: MoveWindowToTouchingZone(hwnd, 2, 0); break; // mRight - case AC_MBZONE: MoveWindowToTouchingZone(hwnd, 3, 0); break; // mBottom - case AC_XLZONE: MoveWindowToTouchingZone(hwnd, 0, 1); break; // xLeft - case AC_XTZONE: MoveWindowToTouchingZone(hwnd, 1, 1); break; // xTop - case AC_XRZONE: MoveWindowToTouchingZone(hwnd, 2, 1); break; // xRight - case AC_XBZONE: MoveWindowToTouchingZone(hwnd, 3, 1); break; // xBottom - case AC_XTNLEDGE: SnapToCorner(hwnd, RXY_LEFT_CENTER, SNTO_EXTEND|SNTO_NEXTBD); break; - case AC_XTNTEDGE: SnapToCorner(hwnd, RXY_CENTER_TOP, SNTO_EXTEND|SNTO_NEXTBD); break; - case AC_XTNREDGE: SnapToCorner(hwnd, RXY_RIGHT_CENTER, SNTO_EXTEND|SNTO_NEXTBD); break; - case AC_XTNBEDGE: SnapToCorner(hwnd, RXY_CENTER_BOTTOM, SNTO_EXTEND|SNTO_NEXTBD); break; - case AC_MTNLEDGE: SnapToCorner(hwnd, RXY_LEFT_CENTER, SNTO_MOVETO|SNTO_NEXTBD); break; - case AC_MTNTEDGE: SnapToCorner(hwnd, RXY_CENTER_TOP, SNTO_MOVETO|SNTO_NEXTBD); break; - case AC_MTNREDGE: SnapToCorner(hwnd, RXY_RIGHT_CENTER, SNTO_MOVETO|SNTO_NEXTBD); break; - case AC_MTNBEDGE: SnapToCorner(hwnd, RXY_CENTER_BOTTOM, SNTO_MOVETO|SNTO_NEXTBD); break; - case AC_STEPL: StepWindow(hwnd, -conf.KBMoveStep, 0); break; - case AC_STEPT: StepWindow(hwnd, -conf.KBMoveStep, 1); break; - case AC_STEPR: StepWindow(hwnd, +conf.KBMoveStep, 0); break; - case AC_STEPB: StepWindow(hwnd, +conf.KBMoveStep, 1); break; - case AC_SSTEPL: StepWindow(hwnd, -conf.KBMoveSStep, 0); break; - case AC_SSTEPT: StepWindow(hwnd, -conf.KBMoveSStep, 1); break; - case AC_SSTEPR: StepWindow(hwnd, +conf.KBMoveSStep, 0); break; - case AC_SSTEPB: StepWindow(hwnd, +conf.KBMoveSStep, 1); break; - case AC_FOCUSL: ReallySetForegroundWindow(FindTiledWindow(hwnd, 0)); break; - 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_MZONE: MoveWindowToTouchingZone(hwnd, action.fl-1, 0); break; + case AC_XZONE: MoveWindowToTouchingZone(hwnd, action.fl-1, 1); break; + case AC_STEP: StepWindow(hwnd, action); break; case AC_NLAYOUT: SendMessage(g_mainhwnd, WM_COMMAND, CMD_SNAPLAYOUT+(conf.LayoutNumber + 1) % conf.MaxLayouts, 0); break; case AC_PLAYOUT: SendMessage(g_mainhwnd, WM_COMMAND, CMD_SNAPLAYOUT+(conf.LayoutNumber + conf.MaxLayouts - 1) % conf.MaxLayouts, 0); break; case AC_ASONOFF: ActionASOnOff(); break; case AC_MOVEONOFF: ActionMoveOnOff(hwnd); break; - default: - // Shortcuts 0 - 35 - if (AC_SHRT0 <=action && action < AC_SHRT0+ARR_SZ(conf.inputSequences) - && conf.inputSequences[action-AC_SHRT0] ) { - SendInputSequence(conf.inputSequences[action-AC_SHRT0]); break; + case AC_SHRT: + if(action.fl < ARR_SZ(conf.inputSequences) && conf.inputSequences[action.fl] ) { + SendInputSequence(conf.inputSequences[action.fl]); } + break; } } ///////////////////////////////////////////////////////////////////////////// // -static int DoWheelActions(HWND hwnd, enum action action) +static int DoWheelActions(HWND hwnd, action_t action) { state.sactiondone = action; // Return if in the scroll blacklist. @@ -4857,7 +4841,7 @@ static int DoWheelActions(HWND hwnd, enum action action) return 0; // Next hook! } int ret=1; - switch (action) { + switch (action.ac) { case AC_ALTTAB: ActionAltTab(state.prevpt, state.delta, /*laser=0*/0 , state.shift?EnumStackedWindowsProc:EnumAltTabWindows); break; case AC_VOLUME: ActionVolume(state.delta); break; @@ -4870,21 +4854,22 @@ static int DoWheelActions(HWND hwnd, enum action action) case AC_ZOOM2: ret = ActionZoom(hwnd, state.delta, 1); break; case AC_NPSTACKED: ActionAltTab(state.prevpt, state.delta, state.shift, EnumStackedWindowsProc); break; case AC_NPSTACKED2: ActionAltTab(state.prevpt, state.delta, !state.shift, EnumStackedWindowsProc); break; - case AC_NPLAYOUT: SClickActions(hwnd, state.delta < 0 ? AC_PLAYOUT : AC_NLAYOUT); + case AC_NPLAYOUT: SClickActions(hwnd, state.delta < 0 ? (action_t){ AC_PLAYOUT } : (action_t){ AC_NLAYOUT }); // case AC_BRIGHTNESS: ActionBrightness(state.prevpt, state.delta); break; - default: { - ret = 0; // No action + case AC_SHRT: { + action_t rac = action; // Use Shrt(X) on WheelUp and Shrt(X+1) on Wheel Down. - UCHAR rac = action + (state.delta<0); - if (AC_SHRT0 <=rac && rac < AC_SHRT0+ARR_SZ(conf.inputSequences) - && conf.inputSequences[rac-AC_SHRT0] ) { - ret = 1; - SendInputSequence(conf.inputSequences[rac-AC_SHRT0]); break; - } else { - SClickActions(hwnd, action); + rac.fl += (state.delta < 0); + if (rac.fl < ARR_SZ(conf.inputSequences) + && conf.inputSequences[rac.fl] ) { ret = 1; + SendInputSequence(conf.inputSequences[rac.fl]); break; } - }break; + }break; + + default: + SClickActions(hwnd, action); + ret = 1; } // ret is 0: next hook or 1: block whel and AltUp. state.blockaltup = ret && state.alt > BT_HWHEELU; // block or not; @@ -4925,10 +4910,10 @@ static int xpure DoubleClamp(int ptx, int left, int right, int rwidth) } ///////////////////////////////////////////////////////////////////////////// // If we pass buttonX BT_PROBE it will tell us if we pass the blacklist. -static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, int buttonX) +static int init_movement_and_actions(POINT pt, HWND hwnd, action_t action, int buttonX) { //RGTICTAC tt; RGTic(&tt); - LOG("\ninit_movement_and_actions(pt=%d,%d, hwnd=%x, action=%d, button=%d)", pt.x, pt.y, (UINT)(INT_PTR)hwnd, (int)action, buttonX); + LOG("\ninit_movement_and_actions(pt=%d,%d, hwnd=%x, action=%d, button=%d)", pt.x, pt.y, (UINT)(INT_PTR)hwnd, (int)action.ac, buttonX); RECT wnd; state.prevpt = pt; // in case int button = LOWORD(buttonX); @@ -4989,7 +4974,7 @@ static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, in //LOGA("Blacklists passed! in %d us", (int)RGTac(&tt)); // If no action is to be done then we passed all balcklists - if (probemode || action == AC_NONE) return 1; + if (probemode || action.ac == AC_NONE) return 1; // Set state state.blockaltup = state.alt; // If alt is down... @@ -5010,7 +4995,7 @@ static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, in if (MOUVEMENT(action)) { state.sactiondone = action; if (GetProp(state.hwnd, APP_MOVEONOFF)) { - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; return 0; // Movement was disabled for this window. } // AutoFocus on movement/resize. @@ -5035,7 +5020,7 @@ static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, in StartSpeedMes(); // Speed timer int ret; - if (state.action == AC_MOVE) { + if (state.action.ac == AC_MOVE) { ret = ActionMove(pt, button); } else { ret = ActionResize(pt, &wnd, button); @@ -5053,11 +5038,11 @@ static int init_movement_and_actions(POINT pt, HWND hwnd, enum action action, in // Wheel actions, directly return here // because maybe the action will not be done if (GetProp(state.hwnd, APP_MOVEONOFF)) { - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; return 0; // Wheel was disabled for this window. } return DoWheelActions(state.hwnd, action); - } else if (action==AC_RESTORE) { + } else if (action.ac==AC_RESTORE) { int rwidth, rheight; if (GetRestoreData(state.hwnd, &rwidth, &rheight)&SNAPPED) { ClearRestoreData(state.hwnd); @@ -5102,11 +5087,11 @@ static int xpure IsAreaTopRZ(int area) { return (area >= HTTOP && area <= HTTOPRIGHT); // Top resizing border } -static int InTitlebar(POINT pt, enum action action, enum button button) +static int InTitlebar(POINT pt, action_t action, enum button button) { int willtest = ((conf.TTBActions&1) && !state.alt) || ((conf.TTBActions&2) && state.alt); - if (willtest && action) { + if (willtest && action.ac) { HWND nhwnd = WindowFromPoint(pt); if (!nhwnd) return 0; // Next hook! // HWND hwnd = MDIorNOT(nhwnd, &state.mdiclient); @@ -5129,7 +5114,7 @@ static int InTitlebar(POINT pt, enum action action, enum button button) } ///////////////////////////////////////////////////////////////////////////// // Actions to be performed in the Titlebar... -static int TitleBarActions(POINT pt, enum action action, enum button button) +static int TitleBarActions(POINT pt, action_t action, enum button button) { state.hittest = 0; // Cursor in titlebar? if (!conf.TTBActions) return -1; // fall through @@ -5149,7 +5134,7 @@ static DWORD WINAPI FinishMovementNow(LPVOID pp) ShowSnapLayoutPreview(ZONES_PREV_HIDE); //Sleep(5000); if (!conf.FullWin && LastWin.hwnd && state.moving == 1) { - if (state.action == AC_RESIZE) { + if (state.action.ac == AC_RESIZE) { ResizeAllSnappedWindows(); } if (IsWindow(LastWin.hwnd) && !LastWin.snap){ @@ -5172,8 +5157,8 @@ static DWORD WINAPI FinishMovementNow(LPVOID pp) // Auto Remaximize if option enabled and conditions are met. if (conf.AutoRemaximize && state.moving && (state.origin.maximized || state.origin.fullscreen) - && !state.shift && !state.mdiclient && state.action == AC_MOVE) { - state.action = AC_NONE; + && !state.shift && !state.mdiclient && state.action.ac == AC_MOVE) { + state.action = (action_t){ AC_NONE }; HMONITOR monitor = MonitorFromPoint(state.prevpt, MONITOR_DEFAULTTONEAREST); if (monitor != state.origin.monitor) { @@ -5192,7 +5177,7 @@ static DWORD WINAPI FinishMovementNow(LPVOID pp) if(conf.FullWin && state.moving == 1) NotifySizeMoveStaEnd(state.hwnd, 0); - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; state.moving = 0; state.snap = conf.AutoSnap; state.cached_hwnd_blacklist = NULL; @@ -5239,18 +5224,18 @@ static DWORD WINAPI DoMoveResizeMaxMinComboAction(LPVOID pp) } else if (state.resizable) { LockMovement(); if (IsHotclick(state.alt)) { - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; state.moving = 0; } MaximizeRestore_atpt(state.hwnd, SW_MAXIMIZE, 2); } return 1; } -static int ClickComboActions(enum action action) +static int ClickComboActions(action_t action) { if (!(conf.MMMaximize&1)) return 0; // Maximize/Restore the window if pressing Move, Resize mouse buttons. - if (state.action == AC_MOVE && action == AC_RESIZE) { + if (state.action.ac == AC_MOVE && action.ac == AC_RESIZE) { PostThreadMessage(g_WorkerThreadID, WM_DOWORK, (WPARAM)DoMoveResizeMaxMinComboAction, 0); state.blockmouseup = 1; return 1; @@ -5259,25 +5244,25 @@ static int ClickComboActions(enum action action) } // Generalization of Click combo. -static void DoComboActions(enum action action, enum button button) +static void DoComboActions(action_t action, enum button button) { // For safety if( !MOUVEMENT(state.action) ) return; - enum action accombo = GetActionMR(button); + action_t accombo = GetActionMR(button); if (ActionInfo(accombo) & (ACINFO_MOVE|ACINFO_RESIZE|ACINFO_CLOSE)) { LockMovement(); } if (BT_WHEELD <= button && button <= BT_HWHEELU) { // Handle wheel combo. - if (accombo) { + if (accombo.ac) { DoWheelActions(state.hwnd, accombo); // No mouseup to block for wheel actions... } } else { // Other buttons. - if (accombo) { + if (accombo.ac) { SClickActions(state.hwnd, accombo); state.blockmouseup = 1; } else { @@ -5363,7 +5348,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) state.clicktime = 0; } // Move the window && (state.moving || !IsSamePTT(&pt, &state.clickpt)) - if (state.action && !state.blockmouseup) { // resize or move... + if (state.action.ac && !state.blockmouseup) { // resize or move... // Move the window every few frames. static DWORD oldtime; if (conf.RezTimer==1) { @@ -5375,7 +5360,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) } } else { static UCHAR updaterate; - updaterate = (updaterate+1)%(state.action==AC_MOVE? conf.MoveRate: conf.ResizeRate); + updaterate = (updaterate+1)%(state.action.ac==AC_MOVE? conf.MoveRate: conf.ResizeRate); if (!updaterate) { MouseMove(pt); } else if (conf.RezTimer == 3 && msg->time != oldtime) { @@ -5397,28 +5382,28 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) // LOGA("button=%d, %s", button, buttonstate==STATE_DOWN?"DOWN":buttonstate==STATE_UP?"UP":"NONE"); // Get actions or alternate (depends on ModKey())! - enum action action = GetAction(button); // Normal action - enum action ttbact = GetActionT(button);// Titlebar action + action_t action = GetAction(button); // Normal action + action_t ttbact = GetActionT(button);// Titlebar action // Handle another click if we are already busy with an action - if (buttonstate == STATE_DOWN && state.action && state.action != conf.GrabWithAlt[ModKey()]) { + if (buttonstate == STATE_DOWN && state.action.ac && state.action.ac != conf.GrabWithAlt[ModKey()].ac) { // Handle click combo action! DoComboActions(action, button); return 1; // Block mousedown so altsnap does not remove g_mainhwnd } // Handle Titlebars actions if any - if (ttbact && buttonstate == STATE_DOWN) { + if (ttbact.ac && buttonstate == STATE_DOWN) { int ret = TitleBarActions(pt, ttbact, button); // If we have nothing to do in the titlebar - if (ret < 0 && conf.InactiveScroll && !state.alt && !state.action + if (ret < 0 && conf.InactiveScroll && !state.alt && !state.action.ac && (wParam == WM_MOUSEWHEEL || wParam == WM_MOUSEHWHEEL)) { // Scroll inactive window with wheel action... ret = ScrollPointedWindow(pt, state.delta, wParam); } if (ret == 0) return CALLNEXTHOOK; else if (ret == 1) return 1; - ttbact = AC_NONE; // No titlebar action to be done. + ttbact = (action_t){AC_NONE }; // No titlebar action to be done. } // Check if the click is is a Hotclick and should enable ALT. @@ -5428,17 +5413,17 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) state.alt = button; // Start an action now if hotclick is also an action. // If action == AC_NONE, we are checking for blacklists... - if (!action) { + if (!action.ac) { // If no action is to be made,we must reset // clickpt and actiondone for the Click UP // to be forwarded. - state.sactiondone = AC_NONE; + state.sactiondone = (action_t){ AC_NONE }; state.clickpt = pt; } int ret = init_movement_and_actions(pt, NULL, action, button); if (ret) { // Not balcklisted, action may have been performed! - if (action) state.alt = 0; // Done! + if (action.ac) state.alt = 0; // Done! return 1; } @@ -5452,7 +5437,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) // Block hotclick up if not an action // Because it will not be done by state.blockmouseup // if (!action) return 1; - if (!action && (conf.AblockHotclick || state.sactiondone)) + if (!action.ac && (conf.AblockHotclick || state.sactiondone.ac)) return 1; // If no action is to be done, we forward the click Send_Click_Thread(button); @@ -5468,7 +5453,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) return CALLNEXTHOOK; } else if (state.blockmouseup) { state.blockmouseup--; - if(!state.blockmouseup && !state.action && !state.alt) + if(!state.blockmouseup && !state.action.ac && !state.alt) UnhookMouseOnly(); // We no longer need the hook. //LOGA("blocked BT%d mouse up", button); return 1; @@ -5476,7 +5461,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) } // Long click grab timer - if (conf.LongClickMove && !state.action && !state.alt) { + if (conf.LongClickMove && !state.action.ac && !state.alt) { if (wParam == WM_LBUTTONDOWN) { state.clickpt = pt; // Start Grab timer @@ -5489,14 +5474,14 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) } // Nothing to do... - if (!action && !ttbact && buttonstate == STATE_DOWN) + if (!action.ac && !ttbact.ac && buttonstate == STATE_DOWN) return CALLNEXTHOOK;//CallNextHookEx(NULL, nCode, wParam, lParam); // INIT ACTIONS on mouse down if Alt is down... if (buttonstate == STATE_DOWN && state.alt) { //LogState("BUTTON DOWN:\n"); // Double ckeck some hotkey is pressed. - if (!state.action + if (!state.action.ac && !IsHotclick(state.alt) && !IsHotkeyDown()) { UnhookMouse(); @@ -5512,10 +5497,10 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) //LogState("BUTTON UP:\n"); SetWindowTrans(NULL); // Reset window transparency - if( action - &&( state.action == action || (state.action == AC_MOVE && action == AC_RESIZE)) + if( action.ac + &&( state.action.ac == action.ac || (state.action.ac == AC_MOVE && action.ac == AC_RESIZE)) &&(!state.moving || state.moving == DRAG_WAIT)// No drag occured - && state.sactiondone <= AC_RESIZE // Only move/resize may have happened in the meantime + && state.sactiondone.ac <= AC_RESIZE // Only move/resize may have happened in the meantime && !IsCtrlDown() // Ctrl is not down (because of focusing) && IsSamePTT(&pt, &state.clickpt) // same point (within drag) && !IsDoubleClick(button)) { // Long click unless PiercingClick=1 @@ -5523,10 +5508,10 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) // Mouse UP actions here only in case of MOVEMENT!: // Perform an action on mouse up without drag on move/resize int inTTB = 2*(!!state.hittest); //If we are in the titlebar add two - if (action == AC_MOVE) action = conf.MoveUp[ModKey()+inTTB]; - if (action == AC_RESIZE) action = conf.ResizeUp[ModKey()+inTTB]; + if (action.ac == AC_MOVE) action = conf.MoveUp[ModKey()+inTTB]; + if (action.ac == AC_RESIZE) action = conf.ResizeUp[ModKey()+inTTB]; - if (action > AC_RESIZE) { + if (action.ac > AC_RESIZE) { SClickActions(state.hwnd, action); } else { LOG("Forwarding the %d the click!", button); @@ -5539,7 +5524,7 @@ LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam) } // If a button performing an action is released, // we finish all moveent and proceed. - if (action && state.action) { + if (action.ac && state.action.ac) { FinishMovementAsync(); return 1; } @@ -5587,7 +5572,7 @@ static void UnhookMouseOnly() static void UnhookMouse() { // Stop action - state.action = AC_NONE; + state.action = (action_t){ AC_NONE }; state.ctrl = 0; state.shift = 0; state.moving = 0; @@ -5655,13 +5640,13 @@ static VOID CALLBACK TimerWindowProc(HWND hwnd, UINT msg, UINT_PTR idEvent, DWOR &&!IsAreaLongClikcable(HitTestTimeoutbl(ptwnd, pt))) { // Determine if we should actually move the Window by probing with AC_NONE state.hittest = 0; // No specific hittest here. - int ret = init_movement_and_actions(pt, NULL, AC_MOVE, BT_PROBE); + int ret = init_movement_and_actions(pt, NULL, (action_t){ AC_MOVE }, BT_PROBE); if (ret) { // Release mouse click if we have to move. InterlockedIncrement(&state.ignoreclick); mouse_event(buttonswaped?MOUSEEVENTF_RIGHTUP:MOUSEEVENTF_LEFTUP , 0, 0, 0, GetMessageExtraInfo()); InterlockedDecrement(&state.ignoreclick); - init_movement_and_actions(pt, NULL, AC_MOVE, 0); + init_movement_and_actions(pt, NULL, (action_t){ AC_MOVE }, 0); } } KillTimer(g_mainhwnd, GRAB_TIMER); @@ -5919,10 +5904,10 @@ LRESULT CALLBACK MenuWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara } else if (HIWORD(wParam) && IsWindow(state.sclickhwnd) ) { // ACTION MENU LOWORD(wParam) has to be zero to differenctiae with unikey menu LOG("Action Menu WM_COMMAND, wp=%X, lp=%X", (UINT)wParam, (UINT)lParam); - enum action action = (enum action)HIWORD(wParam); - if (action) { + action_t action = (action_t){ HIWORD(wParam) }; // TOTO: FIXME!!!!!!! + if (action.ac) { state.prevpt = state.clickpt; - if(action == AC_ORICLICK) { + if(action.ac == AC_ORICLICK) { ShowWindow(hwnd, SW_HIDE); SetCursorPos(state.clickpt.x, state.clickpt.y); Send_Click(state.clickbutton); @@ -5932,8 +5917,8 @@ LRESULT CALLBACK MenuWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara // We should not refocus windows if those // actions were performed... - if (action == AC_LOWER || action == AC_MINIMIZE - || action == AC_KILL || action == AC_CLOSE) + if (action.ac == AC_LOWER || action.ac == AC_MINIMIZE + || action.ac == AC_KILL || action.ac == AC_CLOSE) fhwndori = NULL; } // Menu closes now. @@ -6042,29 +6027,32 @@ LRESULT CALLBACK MenuWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara LRESULT CALLBACK HotKeysWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_HOTKEY) { - int actionint = 0; int ptwindow = 0; + action_t action = (action_t){ AC_NONE }; if (wParam > 0xC000) { // HOTKEY // The user Pressed a hotkey. - actionint = wParam - 0xC000; // Remove the Offset + size_t action_idx = wParam - 0xC001; // Remove the Offset + assert(action_idx < ARR_SZ(conf.KBShortcutsList)); + action = conf.KBShortcutsList[action_idx]; ptwindow = conf.UsePtWindow; - LOG("Hotkey Pressed, action = %d", actionint); + LOG("Hotkey Pressed, action = %d", action.ac); } else if (0x0000 < wParam && wParam < 0x1000) { // The user called AltSnap.exe -afACTION - actionint = wParam - 0x0000; // Remove the Offset + UNPACK_ACTION(action, lParam); + assert(wParam - 0x0000 == action.ac); ptwindow = 0; } else if (0x1000 < wParam && wParam < 0x2000) { // The user called AltSnap.exe -apACTION - actionint = wParam - 0x1000; // Remove the Offset + UNPACK_ACTION(action, lParam); + assert(wParam - 0x1000 == action.ac); ptwindow = 1; } - enum action action = (enum action)actionint; - if (action > AC_RESIZE) { // Exclude resize action in case... + if (action.ac > AC_RESIZE) { // Exclude resize action in case... POINT pt; GetMsgPT(&pt); static const enum action noinitactions[] = { AC_KILL, AC_PAUSE, AC_RESUME, AC_ASONOFF, AC_NONE }; - if (IsActionInList(action, noinitactions)) { + if (IsActionInList((enum action)action.ac, noinitactions)) { // Some actions pass directly through the default blacklists... HWND targethwnd = ptwindow? WindowFromPoint(pt): GetForegroundWindow(); if (IsWindow(targethwnd)) { @@ -6077,7 +6065,7 @@ LRESULT CALLBACK HotKeysWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara target_hwnd = GetForegroundWindow(); // List of actions for which point should default to center. static const enum action resetPTaclist[] = {AC_MENU, AC_NSTACKED, AC_PSTACKED, AC_NONE }; - if (IsActionInList(action, resetPTaclist)) { + if (IsActionInList((enum action)action.ac, resetPTaclist)) { state.ignorept = 1; } // Might be of use for something? @@ -6107,14 +6095,11 @@ LRESULT CALLBACK HotKeysWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara return GetLayoutRez(wParam); } else if (msg == WM_GETBESTLAYOUT) { return GetBestLayoutFromMonitors(); - } else if (msg == WM_GETZONESLEN) { - unsigned idx = (unsigned)wParam; - return nzones[idx]; } else if (msg == WM_GETZONES) { - unsigned idx = (unsigned)wParam; - RECT *dZones = (RECT*)lParam; - CopyZones(dZones, idx); - return 0; + unsigned layout_idx = (unsigned)wParam; + RECT **dZones = (RECT**)lParam; + if (dZones) *dZones = Zones[layout_idx]; + return nzones[layout_idx]; // Return number of zones on the layout } return DefWindowProc(hwnd, msg, wParam, lParam); @@ -6159,8 +6144,8 @@ __declspec(dllexport) void WINAPI Unload() } } - for (unsigned ac=AC_MENU; acleft, fr->top, CLAMPW(fr->right-fr->left), CLAMPH(fr->bottom-fr->top)); //} -static void SetOriginFromRestoreData(HWND hnwd, enum action action); +static void SetOriginFromRestoreData(HWND hnwd, action_t action); static HMONITOR GetMonitorInfoFromWin(HWND hwnd, MONITORINFO *mi); static void MoveWindowToTouchingZone(HWND hwnd, UCHAR direction, UCHAR extend) { if(!(conf.UseZones&1) || state.mdiclient || !state.resizable) // Zones disabled return; - SetOriginFromRestoreData(hwnd, AC_MOVE); + SetOriginFromRestoreData(hwnd, (action_t){ AC_MOVE }); // 1st get current window position. RECT rc; GetWindowRectL(hwnd, &rc);