diff options
| -rw-r--r-- | dev/gui/gui.zig | 107 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 19 |
2 files changed, 69 insertions, 57 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; diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index f0011273..e2cdd2fa 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1572,11 +1572,9 @@ const Shell = struct { var motion: ?Msg = null; var ev = first; while (true) { - if (s.split(ev)) break; + if (s.split(ev, motion)) break; if (ev == .mouse and (ev.mouse.type == .motion or ev.mouse.type == .drag)) { - if (motion) |m| if (m.mouse.button != ev.mouse.button or m.mouse.type != ev.mouse.type or - @as(u3, @bitCast(m.mouse.mods)) != @as(u3, @bitCast(ev.mouse.mods))) - { + if (motion) |m| if (!movesOn(m, ev)) { _ = s.apply(m); }; motion = ev; @@ -1605,14 +1603,16 @@ const Shell = struct { /// a person's input, and none after a pty's output: a step reads the /// terminals as the clients' deltas bring them, sent after each unit /// (docs/next-daemon.md, part B terminal notes). One that must wait is - /// held for the next. Whether `ev` is. - fn split(s: *Shell, ev: Msg) bool { + /// held for the next. Whether `ev` is; a motion that goes on this + /// wait's run of them (`streak`) is that one input, its last. + fn split(s: *Shell, ev: Msg, streak: ?Msg) bool { if (!s.peers.recording) return false; switch (ev) { .key_press => if (s.in_paste) return false, .mouse, .paste, .paste_end, .reply_dropped, .winsize, .focus_in, .focus_out => {}, else => return false, } + if (streak) |m| if (movesOn(m, ev)) return false; if (s.took_output or s.took_input) { s.held = ev; s.input_seen = true; @@ -1622,6 +1622,13 @@ const Shell = struct { return false; } + /// Whether `ev` goes on the motion `streak`: one move to its last cell + /// (the same button, kind and modifiers). + fn movesOn(streak: Msg, ev: Msg) bool { + return ev == .mouse and ev.mouse.type == streak.mouse.type and ev.mouse.button == streak.mouse.button and + @as(u3, @bitCast(ev.mouse.mods)) == @as(u3, @bitCast(streak.mouse.mods)); + } + fn apply(s: *Shell, event: Msg) bool { const core = s.core; const tz_event = tracy.zone(@src(), "event"); |
