summaryrefslogtreecommitdiff
path: root/dev/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 12:13:55 -0300
committerGabriel Schneider <[email protected]>2026-11-24 12:23:08 -0300
commit3b3264d4236ae5624a46e0119c77d9ff2148a6d1 (patch)
treebc9a881e7590a6c367b0fe1e50ae7608128ef1a8 /dev/gui/gui.zig
parentfe8d39e583cd19458727aa1caf01af3cc15abda6 (diff)
downloadpardes-3b3264d4236ae5624a46e0119c77d9ff2148a6d1.tar.gz
pardes-3b3264d4236ae5624a46e0119c77d9ff2148a6d1.zip
gui, tui: a run of pointer motions is one input, merged where the window's events become inputs (dispatch holds the last, Input.moved; Input.post posts it before whatever input comes next, a pass's end posts it), so the session's own window and a client's window, and every road into either (SDL's queue, the test feed, a finger's or a pad's posts after it), take motions the same way: the user's "resizing feels very slow with several clients" (2026-11-24): a client window fed every SDL event as an input (Client.wait), each a step of the session, a unit to every client and a frame of each; and the session's own window, with a client attached, held every motion after a wait's first for the next wait (Shell.split ran before waitInput's own merging loop), a wait, a pump, a unit and a frame a motion (the hunt's real window: 1652 motions in 0.35 s were 1655 frames of the session, 0.65 s behind the pointer); now split takes a motion after a motion as the same input, waitInput's merging loop is gone (its two dispatch loops are one, Shell.takeEvents), and a client feeds each input as it comes but a held motion, which goes with the next input or the pass's end (Client.feed flushes it); the tty session's own terminal had the same split (tui.zig: a second motion held before waitOnce's merge): split now lets a motion that goes on the wait's run through, by the merge's own test (movesOn); a terminal client's road merged already (its split is the session's only); --client-motion (300 motions a road, 30 bytes each, read 1024 bytes a pass: at most ten passes, each one input): a window client of a terminal's session 305 -> 14 inputs by the feed and 305 -> 14 by SDL's queue (the terminal client watching 765 -> 144 units over the run), the session's own window a drag with a terminal client attached 95 -> 9 frames (that client's draws 128 -> 13); Debug both ends, load 1.5-3
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'dev/gui/gui.zig')
-rw-r--r--dev/gui/gui.zig107
1 files changed, 56 insertions, 51 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index 2e5dc5c2..b569e7f2 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -1159,9 +1159,11 @@ const Client = struct {
cl.pending.append(cl.gpa, e) catch {};
}
- /// What the window's input made, applied at once and sent; what the
- /// window reads beside its frame (Gui.facts) as its view is now.
+ /// What the window's input made, its last motion with it (Input.moved),
+ /// applied at once and sent; what the window reads beside its frame
+ /// (Gui.facts) as its view is now.
fn feed(cl: *Client, l: *ClientLoop) void {
+ cl.in.flush();
const r = l.link.r;
for (cl.pending.items) |ev| {
const predicted = r.echo.stats.predicted;
@@ -1287,8 +1289,9 @@ const Client = struct {
return ms;
}
- /// SDL's wait: each event dispatched and fed; then what the reader
- /// took, the window's own pictures' draws done.
+ /// SDL's wait: each event dispatched and fed (a run of motions one
+ /// input, Input.moved); then what the reader took, the window's own
+ /// pictures' draws done.
pub fn wait(cl: *Client, l: *ClientLoop, ms: u32) void {
const g = cl.g;
const link = &l.link;
@@ -1301,11 +1304,14 @@ const Client = struct {
while (got) : (got = c.SDL_PollEvent(&sev)) {
if (sev.type == c.SDL_EVENT_USER) continue;
dispatch(g, &cl.in, &sev);
- cl.feed(l);
+ // Fed as it comes, the next event's hits read in the frame it
+ // predicts; a motion goes with the next input, or the pass's.
+ if (cl.in.moved == null) cl.feed(l);
if (cl.in.redraw) link.dirty = true;
cl.in.redraw = false;
if (link.quit) break;
}
+ cl.feed(l);
cl.takeSaid(l);
// Its draws done (api.draw: this window's own pictures).
if (cl.shell.takeDraws()) link.dirty = true;
@@ -1764,8 +1770,27 @@ const Input = struct {
/// Something the window draws of its own changed (a display's scale, a
/// touchpad's fraction): the runner draws again.
redraw: bool = false,
+ /// The pointer's last motion `dispatch` took, not posted yet: a run of
+ /// motions is one input, its last, posted before whatever input comes
+ /// next or at the pass's end (`flush`). The core reads only a motion's
+ /// cell and held button; posted each, every one was a step of the
+ /// session, and with clients a unit to each and a frame of each (1652
+ /// motions in 0.35 s were 1655 frames of the session, 2026-11-24).
+ moved: ?pardes.Mouse = null,
fn post(in: *Input, ev: pardes.Event) void {
+ in.flush();
+ in.send(ev);
+ }
+
+ /// The pass's last motion (`moved`) posted.
+ fn flush(in: *Input) void {
+ const m = in.moved orelse return;
+ in.moved = null;
+ in.send(.{ .mouse = m });
+ }
+
+ fn send(in: *Input, ev: pardes.Event) void {
// A replica client's: fed after the event (Client.feed).
if (in.client) |cl| return cl.post(ev);
const g = if (in.shell) |s| s.gui else null;
@@ -1917,7 +1942,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
else
physical_held;
const mc = pointAt(g, m.x, m.y);
- in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()) });
+ in.moved = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods());
},
c.SDL_EVENT_MOUSE_WHEEL => {
const w = sev.wheel;
@@ -2437,8 +2462,9 @@ const Shell = struct {
mail_only: bool = false,
waited: bool = false,
/// With replica clients, a wait takes one person's input (tui.zig
- /// `split`): the next is held for the next wait.
- took_input: bool = false,
+ /// `split`), the type of its first event here: the next is held for
+ /// the next wait.
+ took: ?u32 = null,
held: ?c.SDL_Event = null,
fn host(s: *Shell) pardes.Host {
@@ -2471,6 +2497,17 @@ const Shell = struct {
return true;
}
+ /// The window's events from `sev` on, SDL's queue after it, made inputs
+ /// (`dispatch`: a run of motions one, Input.moved) until the queue is
+ /// empty or one is held for the next wait (`split`).
+ fn takeEvents(s: *Shell, g: *Gui, in: *Input, sev: *c.SDL_Event) void {
+ while (!s.split(sev)) {
+ _ = s.windowView();
+ dispatch(g, in, sev);
+ if (!c.SDL_PollEvent(sev)) break;
+ }
+ }
+
/// With replica clients, a wait takes one person's input and its pump
/// makes one unit of it (tui.zig `split`): whether `sev`, a second, is
/// held for the next wait. Any event but a wake is no replica's post.
@@ -2482,11 +2519,13 @@ const Shell = struct {
c.SDL_EVENT_KEY_DOWN, c.SDL_EVENT_TEXT_INPUT, c.SDL_EVENT_MOUSE_BUTTON_DOWN, c.SDL_EVENT_MOUSE_BUTTON_UP, c.SDL_EVENT_MOUSE_MOTION, c.SDL_EVENT_MOUSE_WHEEL, c.SDL_EVENT_WINDOW_FOCUS_GAINED, c.SDL_EVENT_WINDOW_FOCUS_LOST, c.SDL_EVENT_WINDOW_MOUSE_LEAVE, c.SDL_EVENT_FINGER_DOWN, c.SDL_EVENT_FINGER_MOTION, c.SDL_EVENT_FINGER_UP => {},
else => return false,
};
- if (s.took_input) {
+ if (s.took) |took| {
+ // A run of motions is one input, its last (Input.moved).
+ if (took == c.SDL_EVENT_MOUSE_MOTION and sev.type == took) return false;
s.held = sev.*;
return true;
}
- s.took_input = true;
+ s.took = sev.type;
return false;
}
@@ -2658,7 +2697,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
const core = s.core;
var in: Input = .{ .core = core, .shell = s };
s.mail_only = true;
- s.took_input = false;
+ s.took = null;
defer s.waited = true;
if (s.gui) |g| {
if (s.surface != null) startGamepads(g);
@@ -2739,35 +2778,9 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
virtual.* = @max(virtual.*, core.nextWake() orelse virtual.*);
}
}
- if (got) {
- // A run of queued motions is one move to its last position (the
- // handler reads only absolute x/y and held buttons): acting on
- // each would repeat hover and selection work the next undoes.
- var motion: ?c.SDL_Event = null;
- while (true) {
- if (s.split(&sev)) break;
- if (sev.type == c.SDL_EVENT_MOUSE_MOTION and (motion == null or motion.?.motion.windowID == sev.motion.windowID)) {
- motion = sev;
- } else {
- if (motion) |*m| {
- _ = s.windowView();
- dispatch(g, &in, m);
- }
- motion = null;
- if (sev.type == c.SDL_EVENT_MOUSE_MOTION) {
- motion = sev;
- } else {
- _ = s.windowView();
- dispatch(g, &in, &sev);
- }
- }
- if (!c.SDL_PollEvent(&sev)) break;
- }
- if (motion) |*m| {
- _ = s.windowView();
- dispatch(g, &in, m);
- }
- }
+ // A run of queued motions is one move to its last position
+ // (Input.moved), whoever's input it is.
+ if (got) s.takeEvents(g, &in, &sev);
runDemo(g, &in, core);
// Paced: what came before the tick is in; wait out the rest of it,
// unless an input came: its frame is drawn at once (the paced loop
@@ -2789,17 +2802,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
pardes.turn.rest();
const more = c.SDL_PollEvent(&sev);
pardes.turn.wake();
- if (more) {
- if (!s.split(&sev)) {
- _ = s.windowView();
- dispatch(g, &in, &sev);
- while (c.SDL_PollEvent(&sev)) {
- if (s.split(&sev)) break;
- _ = s.windowView();
- dispatch(g, &in, &sev);
- }
- }
- } else {
+ if (more) s.takeEvents(g, &in, &sev) else {
// The events asked for every 100 µs, the core busy between.
const until = c.SDL_GetTicksNS() + 100 * std.time.ns_per_us;
while (c.SDL_GetTicksNS() < @min(until, tick)) std.atomic.spinLoopHint();
@@ -2816,6 +2819,8 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
return;
}
}
+ // The pass's last motion, before what the ptys said (`split`).
+ in.flush();
s.drainQueue();
if (s.gui) |g| pollGamepad(g, &in);
if (in.redraw) core.needs_frame = true;