test(docks): assert that a dock receives the clicks at any edge
CI / check (pull_request) Successful in 5m44s

The mouse handling of the docked windows had no test: the existing dock
tests only checked the regions the layout carves, and nothing checked
which window the clicks are routed to, so a click lost on a right dock
could not be caught by the test suite.

The two windows of a tab are now hit tested with their own areas, in both
orders, so the same point on a right dock and on a left dock must resolve
to the dock. The layout tests also pin the position of a right dock, which
previously only had its width and its containment checked.

Refs #44
This commit is contained in:
BlackAngelTV committed 2026-12-03 11:02:04 +01:00
1 parent 84f5500444
commit 408f16f798
3 files changed
+109

No files matched your search

+68
View File
@@ -2183,6 +2183,73 @@ update_mock_pointer(PyObject *self UNUSED, PyObject *args) {
return Py_BuildValue("(iO)", result, updated ? Py_True : Py_False);
}
/* Hit test a point against two windows placed side by side in a mock tab, and
* return 1 or 2 for the window mouse_region() picks, or 0 when none is hit.
* A docked window must receive the clicks in its own area, whatever the edge it
* is docked at, so the edges are given here rather than assumed to be left. */
static PyObject *
mock_window_under_mouse(PyObject *self UNUSED, PyObject *args) {
PyObject *capsule;
int g[2][4];
int mouse_x, mouse_y;
if (!PyArg_ParseTuple(
args,
"O!iiiiiiiiii",
&PyCapsule_Type,
&capsule,
&g[0][0],
&g[0][1],
&g[0][2],
&g[0][3],
&g[1][0],
&g[1][1],
&g[1][2],
&g[1][3],
&mouse_x,
&mouse_y))
return NULL;
Window *w = PyCapsule_GetPointer(capsule, "Window");
if (!w) return NULL;
Screen *screen = w->render_data.screen;
if (!screen) return NULL;
OSWindow *saved_os_window = global_state.callback_os_window;
const id_type saved_hover = global_state.mouse_hover_in_window;
Window windows[2] = {*w, *w};
for (unsigned int i = 0; i < 2; i++) {
Window *win = windows + i;
win->id = w->id + i;
win->visible = true;
win->render_data.screen = screen;
win->render_data.geometry.left = (unsigned int)MAX(0, g[i][0]);
win->render_data.geometry.top = (unsigned int)MAX(0, g[i][1]);
win->render_data.geometry.right = (unsigned int)MAX(0, g[i][2]);
win->render_data.geometry.bottom = (unsigned int)MAX(0, g[i][3]);
zero_at_ptr(&win->padding);
zero_at_ptr(&win->size_mismatch_padding);
}
Tab tab = {.windows = windows, .num_windows = 2};
struct {
FONTS_DATA_HEAD
} fonts = {.logical_dpi_x = 72, .logical_dpi_y = 72, .fcm = {.cell_width = 10, .cell_height = 20}};
OSWindow osw = {
.tabs = &tab,
.num_tabs = 1,
.has_too_few_tabs = true,
.fonts_data = (FONTS_DATA_HANDLE)&fonts,
.viewport_width = 1400,
.viewport_height = 600,
.mouse_x = (double)mouse_x,
.mouse_y = (double)mouse_y};
global_state.callback_os_window = &osw;
global_state.mouse_hover_in_window = 0;
MouseRegion region = mouse_region(false, false);
unsigned long ans = region.window == windows ? 1 : region.window == windows + 1 ? 2 : 0;
global_state.callback_os_window = saved_os_window;
global_state.mouse_hover_in_window = saved_hover;
if (PyErr_Occurred()) return NULL;
return PyLong_FromUnsignedLong(ans);
}
static PyObject *
test_scale_scroll(PyObject *self UNUSED, PyObject *args) {
PyObject *values;
@@ -2258,6 +2325,7 @@ static PyMethodDef module_methods[] = {
METHODB(test_mapped_scroll_steps, METH_VARARGS),
METHODB(send_mock_mouse_event_to_window, METH_VARARGS),
METHODB(update_mock_pointer, METH_VARARGS),
METHODB(mock_window_under_mouse, METH_VARARGS),
METHODB(send_mock_scroll_event_to_window, METH_VARARGS),
METHODB(mock_mouse_selection, METH_VARARGS),
{NULL, NULL, 0, NULL} /* Sentinel */