diff options
| author | sl0p <sl0p@sl0p.foo> | 2026-08-14 00:28:57 +0200 |
|---|---|---|
| committer | sl0p <sl0p@sl0p.foo> | 2026-08-14 00:28:57 +0200 |
| commit | 61ac1318eaad46363235d41e9cbc31eb7e3e2f84 (patch) | |
| tree | ef9b88ec45dbb7227ad15736f80aa22c3354c6ab | |
| parent | sl0ptty: the border is the button — click an edge to split toward it (diff) | |
| download | slosh-61ac1318eaad46363235d41e9cbc31eb7e3e2f84.tar.gz slosh-61ac1318eaad46363235d41e9cbc31eb7e3e2f84.tar.xz slosh-61ac1318eaad46363235d41e9cbc31eb7e3e2f84.zip | |
sl0ptty: fix the split guide describing the layout from before the split
Which border the pointer is over was remembered from the last motion event, so
after a click split the guide stayed attached to the old pane and the old edge
until the mouse moved and corrected it.
It is derived during the paint now: draw_split_guide asks the hit list where
the pointer is, using the entries that same pass just registered for that pane.
Drawing and hit-testing already could not disagree; now drawing and the layout
cannot either. The pointer position is the only thing kept.
Same lesson as the hit list, one level up: do not remember what you can derive
from the frame you are drawing.
Regression test splits by clicking a border and then deliberately does not move
the mouse, asserting exactly one pane shows a guide, that it is the pane the
pointer is actually inside, and that it is on the edge the pointer is on.
391 checks green.
| -rw-r--r-- | DESIGN.md | 8 | ||||
| -rw-r--r-- | src/app.c | 52 | ||||
| -rw-r--r-- | tests/test_split_ux.py | 36 |
3 files changed, 74 insertions, 22 deletions
@@ -267,6 +267,14 @@ The top border keeps its other job: **click splits upward, drag moves the pane**. A press that never moves is a click — the same distinction the drag machine already had to make. +**The guide is derived, not remembered.** Which border the pointer is over is +worked out *during the paint*, by asking the hit list that same paint just +filled. The first version remembered the answer from the last motion event, +which meant that immediately after a split the guide still described the +layout from before it, until the mouse moved and corrected itself. Same lesson +as the hit list, one level up: do not remember what you can derive from the +frame you are drawing. + ### One drag machine, two verbs (M8) Pane sizes are **weights**, so an even split is simply equal weights and @@ -130,11 +130,12 @@ struct app { char side; /* border press: 'l' 'r' 't' 'b' */ } drag; - /* Which pane border the pointer is over, for the split guide. Recomputed - * from the hit list on every motion, so it cannot describe a border that is - * not there any more. */ - uint32_t hover_pane; - char hover_side; + /* Where the pointer is. Which border that *means* is derived during the + * paint, from the rects painted in that same pass — remembering the answer + * instead left the guide describing the layout from before a split, until + * the mouse moved and corrected it. */ + uint16_t ptr_x, ptr_y; + bool ptr_valid; /* Transient announcements: "copied 13 chars", a notification from a pane, * a config reload. They stack upward from the bottom right and expire on @@ -1181,12 +1182,31 @@ static void draw_pane_status(screen_t *s, node_t *leaf, color_t fg, * dashed line crosses it — the first version was painted under the terminal * and was invisible. Hover only, so an idle frame stays quiet. */ static void draw_split_guide(app_t *a, screen_t *s, node_t *leaf) { - if (a->hover_pane != leaf->id || !a->hover_side) return; + if (!a->ptr_valid) return; + if (a->drag.kind == DRAG_TITLE || a->drag.kind == DRAG_SELECT || + a->drag.kind == DRAG_EDGE) + return; /* a drag in progress means the pointer is busy */ + + /* Ask the hit list where the pointer is, using the entries this very pass + * registered for this pane. Drawing and hit-testing cannot disagree, and + * neither can drawing and *the layout*. */ + const char *action = hit_test(&s->hits, a->ptr_x, a->ptr_y); + if (!action) return; + char side = 0; + char want[48]; + snprintf(want, sizeof want, "border:%u:", leaf->id); + if (strncmp(action, want, strlen(want)) == 0) { + side = action[strlen(want)]; + } else { + snprintf(want, sizeof want, "title:%u", leaf->id); + if (strcmp(action, want) == 0) side = 't'; + } + if (!side) return; + rect_t r = leaf->rect; if (r.w < 4 || r.h < 4) return; uint16_t x1 = (uint16_t)(r.x + r.w - 1), y1 = (uint16_t)(r.y + r.h - 1); color_t hi = FRAME_FOCUS; - char side = a->hover_side; if (side == 'l' || side == 'r') { uint16_t bx = side == 'l' ? r.x : x1; @@ -1896,21 +1916,9 @@ void app_event(app_t *a, const input_event_t *ev) { if (!a->painted) break; const char *action = hit_test(&a->painted->hits, ev->mx, ev->my); - /* Which border the pointer is over, for the guide. */ - if (ev->maction == MOUSE_MOTION && a->drag.kind == DRAG_NONE) { - uint32_t hp = 0; - char hs = 0; - if (action && strncmp(action, "border:", 7) == 0) { - hp = (uint32_t)strtoul(action + 7, NULL, 10); - const char *colon = strchr(action + 7, ':'); - hs = colon && colon[1] ? colon[1] : 0; - } else if (action && strncmp(action, "title:", 6) == 0) { - hp = (uint32_t)strtoul(action + 6, NULL, 10); - hs = 't'; - } - a->hover_pane = hp; - a->hover_side = hs; - } + a->ptr_x = ev->mx; + a->ptr_y = ev->my; + a->ptr_valid = true; if (a->drag.kind != DRAG_NONE) { if (ev->maction == MOUSE_MOTION) { diff --git a/tests/test_split_ux.py b/tests/test_split_ux.py index c394ffe..8009ee6 100644 --- a/tests/test_split_ux.py +++ b/tests/test_split_ux.py @@ -106,6 +106,41 @@ def test_the_guide(): repr(snap.screen()[:200])) +def test_guide_follows_the_new_layout(): + """Regression: the guide described the layout from *before* the split. + + Hover state used to be remembered from the last motion event, so after a + click split the guide stayed attached to the old pane and the old edge + until the mouse moved and corrected it. It is derived during the paint + now, from the rects that paint registered. + """ + with Session(SH, cols=54, rows=12) as s: + s.settle() + p = s.pane() + edge_x, edge_y = p["x"] + p["w"] - 1, p["y"] + 3 + + hover(s, edge_x, edge_y) + s.settle(60) + click(s, edge_x, edge_y) + s.settle(100) # and deliberately no further mouse movement + + snap = s.snapshot() + panes = s.panes() + check("the split happened", len(panes) == 2, str(len(panes))) + + armed = [q for q in panes + if "┃" in "".join(row[q["x"]:q["x"] + q["w"]] for row in snap.text)] + check("exactly one pane shows a guide", len(armed) == 1, str(armed)) + if len(armed) != 1: + return + check("and it is the one the pointer is actually over", + armed[0]["x"] <= edge_x < armed[0]["x"] + armed[0]["w"], + f"pointer at {edge_x}, guide on {armed[0]['x']}..{armed[0]['x'] + armed[0]['w']}") + check("on the edge the pointer is on", + snap.hit_at(edge_x, edge_y) == f"border:{armed[0]['id']}:r", + str(snap.hit_at(edge_x, edge_y))) + + def test_guide_is_per_pane(): with Session(SH, cols=90, rows=14) as s: s.settle() @@ -168,6 +203,7 @@ if __name__ == "__main__": test_no_more_plus() test_each_border_splits_toward_itself() test_the_guide() + test_guide_follows_the_new_layout() test_guide_is_per_pane() test_drag_still_moves() test_tiny_panes_have_no_targets() |
