Skip to content

Commit

Permalink
Merge pull request #230 from RamonUnch/RamonUnch-patch-3
Browse files Browse the repository at this point in the history
Try to fix bad caption area detection.
  • Loading branch information
RamonUnch authored Jul 26, 2022
2 parents a3e75c3 + dd0dbe1 commit 3217e92
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
6 changes: 6 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
32 changes: 21 additions & 11 deletions hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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 },
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,4 @@

#define IDC_OUTTB 2083
#define IDC_UNIKEYHOLDMENU 2084
#define IDC_DWMCAPBUTTON 2085
19 changes: 18 additions & 1 deletion unfuck.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 4 additions & 2 deletions window.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 3217e92

Please sign in to comment.