Merge pull request 'test(docks): assert that a dock receives the clicks at any edge' (#59) from fix/dock-click-edge into main
CI / check (push) Successful in 2m20s
CI / check (push) Successful in 2m20s
This commit was merged in pull request #59.
This commit is contained in:
commit
e39f938a39
3 files changed
+109
No files matched your search
@@ -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 */
|
||||
|
||||
@@ -126,6 +126,16 @@ class TestDocks(BaseTest):
|
||||
content, placements = carve_docks(Region((0, 0, -1, -1, 0, 0)), groups, CELL_WIDTH, CELL_HEIGHT)
|
||||
self.ae([r.height for g, r in placements], [0, 0])
|
||||
|
||||
# A dock at the right is placed against the right edge of what remains,
|
||||
# the same way a dock at the left is placed against the left edge
|
||||
groups = []
|
||||
left, right = dock('left', '10%'), dock('right', '5%')
|
||||
content, placements = carve_docks(VIEWPORT, groups, CELL_WIDTH, CELL_HEIGHT)
|
||||
regions = {g.id: rect(r) for g, r in placements}
|
||||
self.ae(regions[left.id], (0, 0, 100, 600))
|
||||
self.ae(regions[right.id], (950, 0, 1000, 600))
|
||||
self.ae(rect(content), (100, 0, 950, 600))
|
||||
|
||||
def test_tab_docks(self):
|
||||
q = make_layout(Tall)
|
||||
windows = make_windows(q, 2)
|
||||
@@ -183,6 +193,9 @@ class TestDocks(BaseTest):
|
||||
self.assertTrue(rect(r)[0] >= allocated.left and rect(r)[2] <= allocated.left + allocated.width)
|
||||
self.ae(rect(dock_regions[0])[1], allocated.top + allocated.height - 2 * CELL_HEIGHT - 2 * DECORATION)
|
||||
self.ae(dock_regions[1].width, allocated.width // 4)
|
||||
# The dock at the right sits past the content, at the right of the area
|
||||
self.assertGreaterEqual(rect(dock_regions[1])[0], rect(content)[2])
|
||||
self.assertLessEqual(rect(dock_regions[1])[2], allocated.left + allocated.width)
|
||||
self.check_no_overlaps(windows)
|
||||
# The decorations chosen by the layout for the owner are preserved
|
||||
self.ae(main.geometry.spaces.left - main.geometry.compensatory.left, DECORATION)
|
||||
|
||||
@@ -834,3 +834,31 @@ class TestMouse(BaseTest):
|
||||
ac([], 4)
|
||||
self.assertTrue(s.callbacks.wtcbuf, 'the wheel event was not reported to the program')
|
||||
parse_bytes(s, b'\x1b[?1000l')
|
||||
|
||||
def test_docked_window_receives_clicks_at_any_edge(self):
|
||||
from kitty.fast_data_types import mock_window_under_mouse
|
||||
|
||||
s = self.create_screen(cols=140, lines=30)
|
||||
w = create_mock_window(s)
|
||||
terminal, right_dock = (0, 0, 1000, 600), (1000, 0, 1400, 600)
|
||||
left_dock, offset_terminal = (0, 0, 400, 600), (400, 0, 1400, 600)
|
||||
|
||||
def under(first, second, x, y):
|
||||
return mock_window_under_mouse(w, *first, *second, x, y)
|
||||
|
||||
# A dock at the right receives the clicks in its own area and the
|
||||
# terminal receives the clicks in the area left over
|
||||
self.ae(under(terminal, right_dock, 500, 300), 1)
|
||||
self.ae(under(terminal, right_dock, 999, 300), 1)
|
||||
self.ae(under(terminal, right_dock, 1000, 300), 2)
|
||||
self.ae(under(terminal, right_dock, 1200, 300), 2)
|
||||
# Swapping the two areas over must give the same answer for a dock at
|
||||
# the left, so the hit test does not depend on the edge
|
||||
self.ae(under(left_dock, offset_terminal, 500, 300), 2)
|
||||
self.ae(under(left_dock, offset_terminal, 100, 300), 1)
|
||||
self.ae(under(left_dock, offset_terminal, 399, 300), 1)
|
||||
# The first window wins when two areas overlap, as with an overlay
|
||||
self.ae(under(terminal, (500, 0, 1400, 600), 700, 300), 1)
|
||||
# A window with an empty area is never hit, even inside the other one
|
||||
self.ae(under(terminal, (0, 0, 0, 0), 1200, 300), 0)
|
||||
self.ae(under((0, 0, 0, 0), right_dock, 1200, 300), 2)
|
||||
Reference in new issue
Block a user