diff options
| author | sl0p <sl0p@sl0p.foo> | 2026-08-14 00:44:19 +0200 |
|---|---|---|
| committer | sl0p <sl0p@sl0p.foo> | 2026-08-14 00:44:19 +0200 |
| commit | a7d3d42ecbf5d143bd1f98c379051736f97dc0fa (patch) | |
| tree | fed88c198ccb2780b1a63e6136d5612e8a51f7b8 /src | |
| parent | sl0ptty: fix the split guide describing the layout from before the split (diff) | |
| download | slosh-a7d3d42ecbf5d143bd1f98c379051736f97dc0fa.tar.gz slosh-a7d3d42ecbf5d143bd1f98c379051736f97dc0fa.tar.xz slosh-a7d3d42ecbf5d143bd1f98c379051736f97dc0fa.zip | |
sl0ptty: the split guide arms on dwell, not on contact
A pointer crossing a border on its way somewhere else made the screen flash.
The guide now waits for the pointer to rest (hover_delay_ms, 250ms by default,
0 to disable).
The timer is on pointer stillness rather than on the hovered target, which is
what makes a sweep across three borders arm none of them: every motion event
that changes the position restarts the clock, so only stopping counts.
Holding the button on a border skips the wait, because that is intent rather
than passage.
This needs the loop to wake when nothing has happened — a pointer that is
deliberately not moving generates no events to repaint on — which is the same
self-scheduled repaint toasts already needed, so app_next_deadline_ms grew a
second reason rather than the loop growing a second mechanism.
Four older guide tests waited 60ms and now wait for the dwell; they were
asserting on contact because contact was all there was.
398 checks green.
Diffstat (limited to 'src')
| -rw-r--r-- | src/app.c | 26 | ||||
| -rw-r--r-- | src/config.c | 3 | ||||
| -rw-r--r-- | src/config.h | 3 | ||||
| -rw-r--r-- | src/server.c | 9 |
4 files changed, 35 insertions, 6 deletions
@@ -136,6 +136,7 @@ struct app { * the mouse moved and corrected it. */ uint16_t ptr_x, ptr_y; bool ptr_valid; + int64_t ptr_still_since; /* when the pointer last stopped moving */ /* Transient announcements: "copied 13 chars", a notification from a pane, * a config reload. They stack upward from the bottom right and expire on @@ -213,11 +214,25 @@ static void toasts_expire(app_t *a) { a->ntoasts = keep; } -/* When the next toast expires, so a caller's poll can wake for it. */ +/* When something needs repainting on its own: a toast expiring, or a hover + * guide arming. Without the second one the guide would appear on the next + * event rather than when the dwell is up, which for a resting pointer means + * "never". */ int app_next_deadline_ms(app_t *a) { int64_t soonest = -1; for (size_t i = 0; i < a->ntoasts; i++) if (soonest < 0 || a->toasts[i].until < soonest) soonest = a->toasts[i].until; + + if (a->ptr_valid && a->painted) { + int64_t due = a->ptr_still_since + CFG.hover_delay_ms; + if (due > now_ms_()) { + const char *action = hit_test(&a->painted->hits, a->ptr_x, a->ptr_y); + bool on_border = action && (strncmp(action, "border:", 7) == 0 || + strncmp(action, "title:", 6) == 0); + if (on_border && (soonest < 0 || due < soonest)) soonest = due; + } + } + if (soonest < 0) return -1; int64_t in = soonest - now_ms_(); return in <= 0 ? 0 : (int)in; @@ -1187,6 +1202,13 @@ static void draw_split_guide(app_t *a, screen_t *s, node_t *leaf) { a->drag.kind == DRAG_EDGE) return; /* a drag in progress means the pointer is busy */ + /* Arm on dwell, not on contact: a pointer merely crossing a border on its + * way somewhere else should not make the screen flash. Holding the button + * on a border is intent, so that skips the wait. */ + if (a->drag.kind != DRAG_BORDER && + now_ms_() - a->ptr_still_since < CFG.hover_delay_ms) + return; + /* 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*. */ @@ -1916,6 +1938,8 @@ 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); + if (!a->ptr_valid || ev->mx != a->ptr_x || ev->my != a->ptr_y) + a->ptr_still_since = now_ms_(); a->ptr_x = ev->mx; a->ptr_y = ev->my; a->ptr_valid = true; diff --git a/src/config.c b/src/config.c index 14e11ba..f173b2d 100644 --- a/src/config.c +++ b/src/config.c @@ -127,6 +127,7 @@ void config_defaults(config_t *c) { c->min_pane_rows = 6; c->scroll_lines = 3; c->toast_ms = 2500; + c->hover_delay_ms = 250; c->status_bar = true; c->focus_follows_mouse = true; @@ -245,6 +246,8 @@ bool config_load(config_t *c, const char *path, char *err, size_t errcap) { c->scroll_lines = (uint16_t)kdl_arg_int(kdl_child(root, "scroll_lines"), 0, c->scroll_lines); c->toast_ms = (uint16_t)kdl_arg_int(kdl_child(root, "toast_ms"), 0, c->toast_ms); + c->hover_delay_ms = (uint16_t)kdl_arg_int(kdl_child(root, "hover_delay_ms"), 0, + c->hover_delay_ms); const char *sh = kdl_arg(kdl_child(root, "shell"), 0, NULL); if (sh) { diff --git a/src/config.h b/src/config.h index c7a234e..ec89299 100644 --- a/src/config.h +++ b/src/config.h @@ -58,7 +58,8 @@ typedef struct { align_t title_align; uint16_t min_pane_cols, min_pane_rows; uint16_t scroll_lines; - uint16_t toast_ms; /* how long an announcement stays up */ /* rows per wheel notch */ + uint16_t toast_ms; + uint16_t hover_delay_ms; /* how long the pointer must rest to arm a guide */ /* how long an announcement stays up */ /* rows per wheel notch */ bool status_bar; bool focus_follows_mouse; diff --git a/src/server.c b/src/server.c index 94f55ed..1579281 100644 --- a/src/server.c +++ b/src/server.c @@ -217,10 +217,11 @@ int server_run(const char *name, const char *const argv[], uint16_t cols, int t = due <= 0 ? 0 : (int)due; if (timeout < 0 || t < timeout) timeout = t; } - /* a toast expires on its own, so the loop has to wake for it */ - int toast_due = app_next_deadline_ms(s.app); - if (toast_due >= 0 && (timeout < 0 || toast_due < timeout)) { - timeout = toast_due; + /* some things happen without an event: a toast expiring, a hover guide + * arming under a pointer that is deliberately not moving */ + int self_due = app_next_deadline_ms(s.app); + if (self_due >= 0 && (timeout < 0 || self_due < timeout)) { + timeout = self_due; pending_paint = true; } |
