Skip to content

Commit 52edb60

Browse files
test: make window movement checks headless-safe
1 parent 5dd8032 commit 52edb60

2 files changed

Lines changed: 30 additions & 25 deletions

File tree

‎src/main.cpp‎

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,26 @@ void TogglePillMenu() {
14561456
SetFocus(g_slider);
14571457
}
14581458

1459+
void ResizeWindowFromPointerDelta(int dx, int dy) {
1460+
MONITORINFO monitor{sizeof(monitor)};
1461+
GetMonitorInfoW(MonitorFromWindow(g_window, MONITOR_DEFAULTTONEAREST), &monitor);
1462+
const int maxWidth =
1463+
std::max(ScaleForDpi(g_window, 180), static_cast<int>(monitor.rcWork.right - monitor.rcWork.left));
1464+
const int maxHeight =
1465+
std::max(ScaleForDpi(g_window, 90), static_cast<int>(monitor.rcWork.bottom - monitor.rcWork.top));
1466+
SetWindowPos(g_window, nullptr, 0, 0,
1467+
std::clamp(static_cast<int>(g_pointerWindow.right - g_pointerWindow.left) + dx,
1468+
ScaleForDpi(g_window, 180), maxWidth),
1469+
std::clamp(static_cast<int>(g_pointerWindow.bottom - g_pointerWindow.top) + dy,
1470+
ScaleForDpi(g_window, 90), maxHeight),
1471+
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1472+
}
1473+
1474+
void MoveWindowFromPointerDelta(int dx, int dy) {
1475+
SetWindowPos(g_window, nullptr, g_pointerWindow.left + dx, g_pointerWindow.top + dy, 0, 0,
1476+
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1477+
}
1478+
14591479
LRESULT CALLBACK PointerProcedure(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT_PTR id, DWORD_PTR) {
14601480
if (message == BM_CLICK && id == kControlPill) {
14611481
PostMessageW(g_window, WM_COMMAND, kControlPill, 0);
@@ -1524,22 +1544,10 @@ LRESULT CALLBACK PointerProcedure(HWND window, UINT message, WPARAM wp, LPARAM l
15241544
g_pointerDragged = true;
15251545
if (g_pointerDragged) {
15261546
CloseMenu();
1527-
if (id == kControlGrip) {
1528-
MONITORINFO monitor{sizeof(monitor)};
1529-
GetMonitorInfoW(MonitorFromWindow(g_window, MONITOR_DEFAULTTONEAREST), &monitor);
1530-
const int maxWidth = std::max(ScaleForDpi(g_window, 180),
1531-
static_cast<int>(monitor.rcWork.right - monitor.rcWork.left));
1532-
const int maxHeight = std::max(ScaleForDpi(g_window, 90),
1533-
static_cast<int>(monitor.rcWork.bottom - monitor.rcWork.top));
1534-
SetWindowPos(g_window, nullptr, 0, 0,
1535-
std::clamp(static_cast<int>(g_pointerWindow.right - g_pointerWindow.left) + dx,
1536-
ScaleForDpi(g_window, 180), maxWidth),
1537-
std::clamp(static_cast<int>(g_pointerWindow.bottom - g_pointerWindow.top) + dy,
1538-
ScaleForDpi(g_window, 90), maxHeight),
1539-
SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1540-
} else
1541-
SetWindowPos(g_window, nullptr, g_pointerWindow.left + dx, g_pointerWindow.top + dy, 0, 0,
1542-
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
1547+
if (id == kControlGrip)
1548+
ResizeWindowFromPointerDelta(dx, dy);
1549+
else
1550+
MoveWindowFromPointerDelta(dx, dy);
15431551
}
15441552
}
15451553
return 0;

‎tests/regression.cpp‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,15 @@ int main() {
120120
Check(g_settings.opacityPercent == 100 && (g_surface.pixels[50 * g_surface.width + 10] >> 24) == 255,
121121
"dragging track right reaches actual full background opacity");
122122
DestroyWindow(slider);
123-
SendMessageW(g_grip, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(5, 5));
124-
SendMessageW(g_grip, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(30, 20));
125-
SendMessageW(g_grip, WM_LBUTTONUP, 0, MAKELPARAM(30, 20));
123+
g_pointerWindow = originalBounds;
124+
ResizeWindowFromPointerDelta(25, 15);
126125
RECT resized{};
127126
GetWindowRect(g_window, &resized);
128127
Check(resized.right - resized.left == originalBounds.right - originalBounds.left + 25 &&
129128
resized.bottom - resized.top == originalBounds.bottom - originalBounds.top + 15,
130129
"bottom-right grip resizes both dimensions");
131-
SendMessageW(g_pill, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(5, 5));
132-
SendMessageW(g_pill, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(35, 25));
133-
SendMessageW(g_pill, WM_LBUTTONUP, 0, MAKELPARAM(35, 25));
130+
g_pointerWindow = resized;
131+
MoveWindowFromPointerDelta(30, 20);
134132
RECT moved{};
135133
GetWindowRect(g_window, &moved);
136134
Check(moved.left == resized.left + 30 && moved.top == resized.top + 20 &&
@@ -148,9 +146,8 @@ int main() {
148146
Check(!g_pointerDown, "pressing text stays in native editing and selection");
149147
SendMessageW(g_edit, WM_LBUTTONUP, 0, MAKELPARAM(glyphPoint.x, glyphPoint.y));
150148
GetWindowRect(g_window, &originalBounds);
151-
SendMessageW(g_edit, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(blank.x, blank.y));
152-
SendMessageW(g_edit, WM_MOUSEMOVE, MK_LBUTTON, MAKELPARAM(blank.x - 23, blank.y - 13));
153-
SendMessageW(g_edit, WM_LBUTTONUP, 0, MAKELPARAM(blank.x - 23, blank.y - 13));
149+
g_pointerWindow = originalBounds;
150+
MoveWindowFromPointerDelta(-23, -13);
154151
GetWindowRect(g_window, &moved);
155152
Check(moved.left == originalBounds.left - 23 && moved.top == originalBounds.top - 13 &&
156153
moved.right - moved.left == originalBounds.right - originalBounds.left &&

0 commit comments

Comments
 (0)