diff --git a/config.c b/config.c index df89c518..0dc7f279 100644 --- a/config.c +++ b/config.c @@ -1102,12 +1102,18 @@ LRESULT CALLBACK FindWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara } SetDlgItemText(page, IDC_GWLSTYLE, _itow(GetWindowLongPtr(window, GWL_STYLE), txt, 16)); SetDlgItemText(page, IDC_GWLEXSTYLE, _itow(GetWindowLongPtr(window, GWL_EXSTYLE), txt, 16)); + // WM_NCHITTEST messages info at current pt _itow(HitTestTimeout(nwindow, pt.x, pt.y), txt, 10); wchar_t tt[8]; _itow(HitTestTimeout(window, pt.x, pt.y), tt, 10); wcscat(txt, L"/");wcscat(txt, tt); SetDlgItemText(page, IDC_NCHITTEST, txt); + // IDC_DWMCAPBUTTON RECT rc; + SetDlgItemText(page, IDC_DWMCAPBUTTON + , (GetCaptionButtonsRect(window, &rc) && PtInRect(&rc, pt))?L"Yes":L"No"); + + // Window rectangle info if (GetWindowRectL(window, &rc)) { SetDlgItemText(page, IDC_RECT, RectToStr(&rc, txt)); } diff --git a/hooks.c b/hooks.c index 223a6c02..e5aac7e4 100644 --- a/hooks.c +++ b/hooks.c @@ -356,7 +356,8 @@ static void SendSizeMove(DWORD msg) } ///////////////////////////////////////////////////////////////////////////// // Overloading of the Hittest function to include a whitelist -static int HitTestTimeoutblL(HWND hwnd, LPARAM lParam) +// x and y are in screen coordinate. +static int HitTestTimeoutbl(HWND hwnd, POINT pt) { DorQWORD area=0; @@ -365,12 +366,23 @@ static int HitTestTimeoutblL(HWND hwnd, LPARAM lParam) if (blacklisted(ancestor, &BlkLst.MMBLower)) return 0; if (hwnd != ancestor && blacklisted(ancestor, &BlkLst.NCHittest)) { - SendMessageTimeout(ancestor, WM_NCHITTEST, 0, lParam, SMTO_NORMAL, 200, &area); - if(area == HTCAPTION) return HTCAPTION; + SendMessageTimeout(ancestor, WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y), SMTO_NORMAL, 200, &area); + if(area == HTCAPTION) goto DOUBLECHECK_CAPTION; } - return HitTestTimeoutL(hwnd, lParam); + area = HitTestTimeoutL(hwnd, MAKELPARAM(pt.x, pt.y)); + DOUBLECHECK_CAPTION: + if (area == HTCAPTION) { + // Double check that we are not inside one of the + // caption buttons buttons because of buggy Win10.. + RECT buttonRc; + if (GetCaptionButtonsRect(ancestor, &buttonRc) && PtInRect(&buttonRc, pt)) { + // let us assume it is the minimize button, it makes no sence + // But Windows is too buggy + area = HTMINBUTTON; + } + } + return area; } -#define HitTestTimeoutbl(hwnd, x, y) HitTestTimeoutblL(hwnd, MAKELPARAM(x, y)) ///////////////////////////////////////////////////////////////////////////// // Use NULL to restore old transparency. // Set to -1 to clear old state @@ -3108,7 +3120,7 @@ static int InTitlebar(POINT pt, enum action action, enum button button) // if (blacklisted(hwnd, &BlkLst.Windows)) return 0; // Next hook // Hittest to see if we are in a caption! - int area = HitTestTimeoutbl(nhwnd, pt.x, pt.y); + int area = HitTestTimeoutbl(nhwnd, pt); if (area == HTCAPTION || (button > BT_RMB && IsAreaAnyCap(area))) { return area; } @@ -3497,7 +3509,7 @@ LRESULT CALLBACK TimerWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPar if (IsSamePTT(&state.prevpt, &state.clickpt) && GetAsyncKeyState(1 + (buttonswaped = !!GetSystemMetrics(SM_SWAPBUTTON))) && (ptwnd = WindowFromPoint(state.prevpt)) - &&!IsAreaLongClikcable(HitTestTimeoutbl(ptwnd, state.prevpt.x, state.prevpt.y))) { + &&!IsAreaLongClikcable(HitTestTimeoutbl(ptwnd, state.prevpt))) { // Determine if we should actually move the Window by probing with AC_NONE int ret = init_movement_and_actions(state.prevpt, AC_NONE, 0); if (ret) { // Release mouse click if we have to move. @@ -3754,7 +3766,7 @@ __declspec(dllexport) void Load(HWND mainhwnd) #pragma GCC diagnostic ignored "-Wpointer-sign" static const struct OptionListItem { - UCHAR *dest; wchar_t *section; char *name; int def; + UCHAR *const dest; const wchar_t *section; const char *name; const int def; } optlist[] = { // [General] {&conf.AutoFocus, L"General", "AutoFocus", 0 }, @@ -3791,7 +3803,7 @@ __declspec(dllexport) void Load(HWND mainhwnd) // [Performance] {&conf.FullWin, L"Performance", "FullWin", 2 }, - {&conf.TransWinOpacity, L"Performance", "TransWinOpacity", 0 }, + {&conf.TransWinOpacity, L"Performance", "TransWinOpacity", 0 }, {&conf.RefreshRate, L"Performance", "RefreshRate", 0 }, {&conf.RezTimer, L"Performance", "RezTimer", 0 }, {&conf.MoveRate, L"Performance", "MoveRate", 2 }, @@ -3828,8 +3840,6 @@ __declspec(dllexport) void Load(HWND mainhwnd) conf.AVoff = CLAMP(0, conf.AVoff, 100); conf.AeroSpeedTau = max(1, conf.AeroSpeedTau); conf.MinAlpha = max(1, conf.MinAlpha); - if(conf.TransWinOpacity) - conf.TransWinOpacity = max(16, conf.TransWinOpacity); state.snap = conf.AutoSnap; // [Advanced] Max Speed diff --git a/resource.h b/resource.h index 5d23c73b..974b517c 100644 --- a/resource.h +++ b/resource.h @@ -162,3 +162,4 @@ #define IDC_OUTTB 2083 #define IDC_UNIKEYHOLDMENU 2084 +#define IDC_DWMCAPBUTTON 2085 diff --git a/unfuck.h b/unfuck.h index 5dca40cb..0cafde69 100644 --- a/unfuck.h +++ b/unfuck.h @@ -375,7 +375,7 @@ static void FixDWMRectLL(HWND hwnd, RECT *bbb, const int SnapGap) CopyRect(bbb, &frame); } else { SetRectEmpty(bbb); - //SetRect(bbb, 10, 10, 10, 10); + /*SetRect(bbb, 10, 10, 10, 10);*/ } if (SnapGap) OffsetRect(bbb, -SnapGap, -SnapGap); } @@ -413,6 +413,23 @@ static BOOL IsVisible(HWND hwnd) { return IsWindowVisible(hwnd) && !IsWindowCloaked(hwnd); } + +/* Use the DWM api to obtain the rectangel that *should* contain all + * caption buttons. This is usefull to ensure we are not in one of them. + */ +static BOOL GetCaptionButtonsRect(HWND hwnd, RECT *rc) +{ + int ret = DwmGetWindowAttributeL(hwnd, DWMWA_CAPTION_BUTTON_BOUNDS, rc, sizeof(RECT)); + /* Convert rectangle to to screen coordinate. */ + if (ret == S_OK) { + RECT wrc; + GetWindowRect(hwnd, &wrc); + OffsetRect(rc, wrc.left, wrc.top); + return 1; + } + return 0; +} + static LONG NtSuspendProcessL(HANDLE ProcessHandle) { if (myNtSuspendProcess == IPTR) { /* First time */ diff --git a/window.rc b/window.rc index d8f02954..2783f1d3 100644 --- a/window.rc +++ b/window.rc @@ -51,10 +51,12 @@ BEGIN EDITTEXT IDC_GWLSTYLE, 160,165,50,12,ES_AUTOHSCROLL RTEXT "WM_NCHITTEST:", 0, 10,182,60,8 - EDITTEXT IDC_NCHITTEST, 72,180,30,12,ES_AUTOHSCROLL + EDITTEXT IDC_NCHITTEST, 72,180,25,12,ES_AUTOHSCROLL + RTEXT "In DWM Buttons:", 0, 10,197,60,8 + EDITTEXT IDC_DWMCAPBUTTON, 72,195,25,12,ES_AUTOHSCROLL RTEXT "EXSTYLE:", 0, 115,182,42,8 EDITTEXT IDC_GWLEXSTYLE, 160,180,50,12,ES_AUTOHSCROLL - RTEXT "RECT:", 0, 97,197,25,8 + LTEXT "RECT:", 0, 102,197,22,8 EDITTEXT IDC_RECT, 125,195,85,12,ES_AUTOHSCROLL END