summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig164
1 files changed, 104 insertions, 60 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index fb9834cc..65e3088c 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -446,7 +446,7 @@ const Gui = struct {
font_name_len: u8 = 0,
/// A replica client's: the session's font request it last followed
/// (syncReplicaFont), as a hash of the request.
- remote_font_request: ?u64 = null,
+ session_font_request: ?u64 = null,
px: f32,
tagline_px: f32,
tagline_percent: u8,
@@ -540,12 +540,17 @@ const Gui = struct {
/// What a window is opened again with (reopenWindow): the flags (not
/// hidden), its size when it was closed (present keeps its present mode).
win_flags: c.SDL_WindowFlags = 0,
+ /// A native Wayland window: transparent at the first WindowOpacity
+ /// under 100 (syncWindowOpacity).
+ wayland: bool = false,
window_w: c_int = 1120,
window_h: c_int = 720,
/// The window runNative destroys at the end: the one open then, if any.
window_slot: ?*?*c.SDL_Window = null,
gamepad: ?*c.SDL_Gamepad = null,
+ /// The gamepad subsystem started (startGamepads).
+ gamepads: bool = false,
pad_x: f32 = 0,
pad_y: f32 = 0,
pad_scroll: f32 = 0, // fractional vertical wheel ticks (left stick)
@@ -578,7 +583,7 @@ fn acknowledgeGuiFont(g: *const Gui, core: *pardes.Pardes) void {
}
/// A replica client's font is the window's raster state: it follows the
-/// session's request by the face's name on this machine (fonts.remote),
+/// session's request by the face's name on this machine (fonts.fromSession),
/// never acknowledging it or otherwise changing the replicated core.
fn syncReplicaFont(g: *Gui, core: *const pardes.Pardes, gpa: std.mem.Allocator) bool {
const f = &core.settings.font;
@@ -590,12 +595,12 @@ fn syncReplicaFont(g: *Gui, core: *const pardes.Pardes, gpa: std.mem.Allocator)
hash.update(name);
hash.update(std.mem.asBytes(&f.requested_size_hundredths));
const request = hash.final();
- if (g.remote_font_request == request) return false;
- g.remote_font_request = request;
+ if (g.session_font_request == request) return false;
+ g.session_font_request = request;
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
- const face = fonts.remote(arena.allocator(), path, name) orelse {
- log.warn("remote font is not installed here: {s}", .{name});
+ const face = fonts.fromSession(arena.allocator(), path, name) orelse {
+ log.warn("the session's font is not installed here: {s}", .{name});
return false;
};
const bytes = filesystem.readFile(gpa, face.path) catch return false;
@@ -762,20 +767,20 @@ fn coverFrame(cover: []Cover, cols: u16, rows: u16, body_layers: []const pardes.
};
}
-pub fn run(init: std.process.Init, opts: pardes.Options, headless: bool) !void {
- return runNative(init, opts, headless, null);
+pub fn run(init: std.process.Init, opts: pardes.Options, detached: bool) !void {
+ return runNative(init, opts, detached, null);
}
/// `pardes-gui --attach=<socket>:<session>` (and `<host>:<session>`,
/// through ssh, main.zig): this window a replica client of a session
-/// elsewhere, as the tty's `remote` is a terminal's (`remoteSession`).
-pub fn remote(init: std.process.Init, opts: pardes.Options, path: []const u8, session: []const u8, far: bool) !void {
+/// elsewhere, as the tty's `runClient` is a terminal's (`clientSession`).
+pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, session: []const u8, far: bool) !void {
return runNative(init, opts, false, .{ .path = path, .session = session, .far = far });
}
const Dial = struct { path: []const u8, session: []const u8, far: bool };
-fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, dial: ?Dial) !void {
+fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, dial: ?Dial) !void {
const gpa = init.gpa;
const env = init.environ_map;
@@ -802,7 +807,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
_ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI", "1"); // SDL_HINT_JOYSTICK_HIDAPI
_ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI_STEAMDECK", "1"); // ..._STEAMDECK
if (comptime builtin.os.tag == .macos) _ = c.SDL_SetHint(c.SDL_HINT_MAC_SCROLL_MOMENTUM, "1");
- if (!c.SDL_Init(c.SDL_INIT_VIDEO | c.SDL_INIT_GAMEPAD)) {
+ // The gamepads after the first frame (startGamepads).
+ if (!c.SDL_Init(c.SDL_INIT_VIDEO)) {
log.err("SDL_Init: {s}", .{c.SDL_GetError()});
return error.SdlInit;
}
@@ -819,14 +825,16 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
if (!test_mode) win_flags |= c.SDL_WINDOW_HIGH_PIXEL_DENSITY;
// A test run renders to the capture texture; keep it off the desktop.
if (test_mode) win_flags |= c.SDL_WINDOW_HIDDEN;
+ // Background-only opacity needs per-pixel alpha (whole-window compositor
+ // opacity would dim the text as well), so a transparent window, which
+ // the GPU API will not claim: it presents through SDL_Renderer, EGL and
+ // GL beside Vulkan, and its first present is slow. So a window starts
+ // opaque, and is made again transparent at the first WindowOpacity
+ // under 100 (syncWindowOpacity): SDL takes the flag only at creation.
const native_wayland = !test_mode and std.mem.eql(u8, std.mem.span(c.SDL_GetCurrentVideoDriver()), "wayland");
- // Background-only opacity needs per-pixel alpha; whole-window compositor
- // opacity would dim the text as well. SDL requires this flag at creation.
- const surface_opacity = native_wayland;
- if (surface_opacity) win_flags |= c.SDL_WINDOW_TRANSPARENT;
const reopen_flags = win_flags;
// `--detach`: a window never shown, closed once the session is up.
- if (headless) win_flags |= c.SDL_WINDOW_HIDDEN;
+ if (detached) win_flags |= c.SDL_WINDOW_HIDDEN;
// `--geometry=WxH[+X+Y]`, as X11 programs take it.
var want_w: c_int = 1120;
var want_h: c_int = 720;
@@ -851,7 +859,6 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
defer if (window_slot) |open| c.SDL_DestroyWindow(open);
if (want_at) |at| _ = c.SDL_SetWindowPosition(window, at[0], at[1]);
updateDisplayScale(window);
- if (native_wayland) log.info("Wayland opacity: background-only transparent surface", .{});
// On Linux the desktop's own cursor theme draws them (the compositor's
// cursor-shape protocol, else XCURSOR_THEME), at its size and scale:
// the arrow is its default, acme's box its move, as the plan9 theme
@@ -875,7 +882,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
} else log.err("SDL_CreateCursor: {s}", .{c.SDL_GetError()});
var presenter = try Present.init(window, .{
.test_mode = test_mode,
- .surface_opacity = surface_opacity,
+ .surface_opacity = false,
.present_modes = &.{ c.SDL_GPU_PRESENTMODE_IMMEDIATE, c.SDL_GPU_PRESENTMODE_MAILBOX, c.SDL_GPU_PRESENTMODE_VSYNC },
.debug = true,
});
@@ -943,6 +950,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
.demo = if (env.get("PARDES_FRAMES_DEMO")) |path| try pardes.FrameStats.readScript(init.arena.allocator(), init.io, path) else &.{},
.demo_next = if (env.get("PARDES_FRAMES_DEMO") != null) 0 else null,
.win_flags = reopen_flags,
+ .wayland = native_wayland,
.window_w = want_w,
.window_h = want_h,
.window_slot = &window_slot,
@@ -968,8 +976,8 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, headless: bool, di
// compositor moves it, as it does a title bar.
if (!test_mode and !c.SDL_SetWindowHitTest(window, hitTest, &g))
log.warn("SDL_SetWindowHitTest: {s}", .{c.SDL_GetError()});
- if (dial) |to| return remoteSession(init, &g, opts_in, test_mode, to);
- try localSession(init, &g, opts_in, test_mode, headless);
+ if (dial) |to| return clientSession(init, &g, opts_in, test_mode, to);
+ try localSession(init, &g, opts_in, test_mode, detached);
}
/// Detach: the window closed (and with it its swapchain or renderer); the
@@ -1009,7 +1017,7 @@ fn localSession(
g: *Gui,
opts_in: pardes.Options,
test_mode: bool,
- headless: bool,
+ detached: bool,
) !void {
const io = init.io;
const gpa = init.gpa;
@@ -1109,7 +1117,7 @@ fn localSession(
frame_capture_dir = if (std.c.getenv("PARDES_FRAMES_CAPTURE")) |dir| std.mem.span(dir) else null;
const host = shell.host();
core.host = host;
- shell.peers = .{ .gpa = gpa, .io = io, .name = daemon.name(), .wake = sdlWake, .alone_unattended = headless };
+ shell.peers = .{ .gpa = gpa, .io = io, .name = daemon.name(), .wake = sdlWake, .detached = detached };
defer shell.peers.deinit();
// Before the core goes: each client sees its link end.
defer shell.peers.dropAll(shell.core);
@@ -1132,7 +1140,7 @@ fn localSession(
_ = c.SDL_StartTextInput(g.window);
// An upgraded session's window, its view's again.
- if (upgrade.resumed) |*rec| if (!rec.fresh and !headless) shell.resumeWindow();
+ if (upgrade.resumed) |*rec| if (!rec.fresh and !detached) shell.resumeWindow();
if (test_mode) setStdinRaw() catch {};
shell.threads_ok = true;
@@ -1140,7 +1148,7 @@ fn localSession(
defer pardes.lsp.setStatusSink(null, null);
host_io.setExitWake(&queue, Queue.wakeForExit);
defer host_io.setExitWake(null, null);
- if (headless) {
+ if (detached) {
shell.closeTheWindow();
// Nothing else may wake the first wait.
daemon.watch(&shell, deliverNote);
@@ -1190,7 +1198,7 @@ fn localSession(
}
}
-/// A window's link to a session elsewhere (`remoteSession`): what the
+/// A window's link to a session elsewhere (`clientSession`): what the
/// window's input made, fed to the replica once its own view is put back,
/// and what the link's reader took off the stream.
const Client = struct {
@@ -1272,7 +1280,7 @@ const Client = struct {
}
/// Its own view drawn in the window, outside any step, as the tty's
- /// client draws its terminal (tui.zig `Remote.draw`): what presenting
+ /// client draws its terminal (tui.zig `Client.draw`): what presenting
/// writes in the core (a frame skipped, one owed) is put back.
fn draw(cl: *Client, s: *Shell) void {
const r = cl.link.r;
@@ -1302,7 +1310,7 @@ fn clientReader(cl: *Client, fd: c_int, rest: *replica.Framer) void {
}
/// What the window does over its own view (`Replica.within`), its inputs
-/// posted to the client (`Input.remote`): an SDL event dispatched, its size
+/// posted to the client (`Input.client`): an SDL event dispatched, its size
/// (the tagline's face too), the pointer under a frame that moved, the
/// timedemo's and the test feed's steps.
const OwnView = struct {
@@ -1316,9 +1324,9 @@ const OwnView = struct {
fn run(v: *OwnView, core: *pardes.Pardes) anyerror!void {
if (v.sev) |sev| return dispatch(v.g, v.in, sev);
const g = v.g;
- if (syncReplicaFont(g, core, v.s.gpa)) v.s.remote.?.link.dirty = true;
- if (scrollRows(g, v.in, v.s.gpa)) v.s.remote.?.link.dirty = true;
- if (fitTaglineFont(g, core.settings.font.tagline_percent)) v.s.remote.?.link.dirty = true;
+ if (syncReplicaFont(g, core, v.s.gpa)) v.s.client.?.link.dirty = true;
+ if (scrollRows(g, v.in, v.s.gpa)) v.s.client.?.link.dirty = true;
+ if (fitTaglineFont(g, core.settings.font.tagline_percent)) v.s.client.?.link.dirty = true;
const geom = windowCells(g);
if (resizeOf(core.view(), geom.cols, geom.rows, g.cell_w, g.cell_h, g.tagline_width, g.tagline_height)) |ev| v.in.post(ev);
if (v.pointer) refreshPresentedPointer(g, v.in);
@@ -1333,9 +1341,9 @@ const OwnView = struct {
/// is, a replica client of that session (docs/next-daemon.md, "Phase 6: GUI
/// replica notes"). Its own core, loaded from the session's dump, applies
/// its input at once (src/replica.zig) and draws its own view; the
-/// session's units are the truth it rolls back to. The tty's `remote`, with
+/// session's units are the truth it rolls back to. The tty's `runClient`, with
/// a window for a terminal.
-fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_mode: bool, to: Dial) !void {
+fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_mode: bool, to: Dial) !void {
const io = init.io;
const gpa = init.gpa;
const Said = struct {
@@ -1394,7 +1402,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
.inotify_fd = -1,
.watches = &watches,
.test_mode = test_mode,
- .remote = &client,
+ .client = &client,
};
g.no_blink = test_mode;
defer g.hit_core = null;
@@ -1404,7 +1412,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
// session let it go to upgrade. The window stays as it is.
while (true) {
const core = r.core();
- g.remote_font_request = null;
+ g.session_font_request = null;
shell.core = core;
shell.gview = joined.view;
shell.surface = null;
@@ -1422,7 +1430,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
log.warn("{s}", .{link.notice()});
}
const reader = try std.Thread.spawn(.{}, clientReader, .{ &client, joined.fd, &joined.rest });
- var in: Input = .{ .core = core, .shell = &shell, .remote = &client };
+ var in: Input = .{ .core = core, .shell = &shell, .client = &client };
// What it is, then its size, are its view's first inputs.
link.input(.{ .frontend = .{ .windowed = true, .native_images = true, .native_image_patches = true } });
var drew = false;
@@ -1460,6 +1468,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
if (link.quietCheck()) |wait| ms = if (ms < 0) @intCast(wait) else @min(ms, @as(c_int, @intCast(wait)));
// Idle, its frame drawn: the next input needs no copy taken.
if (ms != 0) r.ready();
+ if (shell.surface != null) startGamepads(g);
var sev = std.mem.zeroes(c.SDL_Event);
g.input_seen = false;
var got = c.SDL_WaitEventTimeout(&sev, ms);
@@ -1488,7 +1497,7 @@ fn remoteSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_
reader.join();
client.lock.lockUncancelable(io);
for (client.inbox.items) |msg| switch (msg) {
- .unit, .screen, .refused => |b| std.heap.c_allocator.free(b),
+ .unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b),
.checked => {},
};
client.inbox.clearRetainingCapacity();
@@ -1762,13 +1771,13 @@ const Input = struct {
core: *pardes.Pardes,
/// The shell whose window this is (views.zig: its view is `gview`).
shell: ?*Shell = null,
- /// A replica client's (`remote`): its inputs go to its link, never
+ /// A replica client's (`runClient`): its inputs go to its link, never
/// straight to the core, which only reads here.
- remote: ?*Client = null,
+ client: ?*Client = null,
quit: bool = false,
fn post(in: *Input, ev: pardes.Event) void {
- if (in.remote) |r| return r.post(ev);
+ if (in.client) |r| return r.post(ev);
// The window's input is its own view's, a replica client's input
// the session's last or not.
if (in.shell) |s| if (s.core.live != s.gview) {
@@ -1778,7 +1787,7 @@ const Input = struct {
}
fn close(in: *Input) void {
- if (in.remote) |r| {
+ if (in.client) |r| {
r.link.quit = true;
in.quit = true;
return;
@@ -1815,7 +1824,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
updateDisplayScale(g.window);
// Underlines are drawn into the glyphs a logical pixel thick.
resetGlyphAtlas(g);
- if (in.remote) |r| {
+ if (in.client) |r| {
r.link.dirty = true;
} else in.core.needs_frame = true;
},
@@ -1829,7 +1838,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
c.SDL_EVENT_WINDOW_CLOSE_REQUESTED => in.close(),
c.SDL_EVENT_WINDOW_FOCUS_GAINED => {
in.post(.{ .focus = true });
- if (in.remote == null) upgrade.noticeNewer(in.core);
+ if (in.client == null) upgrade.noticeNewer(in.core);
},
c.SDL_EVENT_WINDOW_FOCUS_LOST => in.post(.{ .focus = false }),
c.SDL_EVENT_WINDOW_MOUSE_LEAVE => {
@@ -2149,7 +2158,7 @@ fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
in.post(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = mc.col, .row = mc.row, .tag_hit = mc.tag_hit, .body_hit = mc.body_hit, .ctrl = w.mods.ctrl, .shift = w.mods.shift, .alt = w.mods.alt } });
while (g.program_wheel <= -1) : (g.program_wheel += 1)
in.post(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .tag_hit = mc.tag_hit, .body_hit = mc.body_hit, .ctrl = w.mods.ctrl, .shift = w.mods.shift, .alt = w.mods.alt } });
- } else if (in.remote != null) {
+ } else if (in.client != null) {
// A replica client's notch is whole rows at once, with no
// glide; a touchpad's fraction is the window's picture
// (scrollRows), its whole rows ordinary inputs.
@@ -2209,7 +2218,7 @@ const WheelTurn = struct { x: f32 = 0, y: f32 = 0, integer_y: i32 = 0, precise:
fn setFontPx(g: *Gui, in: *Input, want: f32) void {
if (want == g.px) return;
g.px = want;
- if (in.remote) |r| {
+ if (in.client) |r| {
refitFont(g, null);
r.link.dirty = true;
} else {
@@ -2383,10 +2392,10 @@ fn pollGamepad(g: *Gui, in: *Input) void {
const Shell = struct {
core: *pardes.Pardes,
- /// The window's, while one is open; null while detached (`parked` has
+ /// The window's, while one is open; null while detached (`detached` has
/// it).
gui: ?*Gui = null,
- parked: ?*Gui = null,
+ detached: ?*Gui = null,
/// Shells a dead session left (Adopt), each waiting for the spawn of
/// the terminal pane made for it.
adoptions: host_io.Adoptions = .{},
@@ -2422,8 +2431,8 @@ const Shell = struct {
gview: u8 = 0,
/// Upgrade was asked from this pane, to be done between steps (`upgradeNow`).
upgrade_asked: ?u8 = null,
- /// This window a replica client of a session elsewhere (`remote`).
- remote: ?*Client = null,
+ /// This window a replica client of a session elsewhere (`runClient`).
+ client: ?*Client = null,
/// The session's replica clients (src/replica.zig), on sockets: views
/// of their own with no window here.
peers: replica.Peers = .{},
@@ -2485,7 +2494,7 @@ const Shell = struct {
// A replica client's: its link ends.
if (s.peers.detach(s.core.live)) return;
if (s.gui == null) return s.core.reportFailure(s.core.view().active, "Detach: no window is open");
- if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon keeps this session; closing its window ends it");
+ if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon lists this session; closing its window ends it");
s.closeTheWindow();
}
@@ -2526,25 +2535,25 @@ const Shell = struct {
fn closeTheWindow(s: *Shell) void {
const g = s.gui orelse return;
closeWindow(g);
- s.parked = g;
+ s.detached = g;
s.gui = null;
s.presented = false;
s.surface = null;
// Its clients look at it still (Peers keeps it attended).
- s.peers.alone_unattended = true;
+ s.peers.detached = true;
s.core.unattended = s.peers.count() == 0;
daemon.setState(true);
}
fn openTheWindow(s: *Shell) void {
- const g = s.parked orelse return;
+ const g = s.detached orelse return;
if (!reopenWindow(g)) {
log.err("--attach: no window: {s}", .{c.SDL_GetError()});
return daemon.setState(true);
}
s.gui = g;
- s.parked = null;
- s.peers.alone_unattended = false;
+ s.detached = null;
+ s.peers.detached = false;
s.core.unattended = false;
s.core.needs_frame = true;
resetScroll(g);
@@ -2780,6 +2789,7 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
s.took_input = false;
defer s.waited = true;
if (s.gui) |g| {
+ if (s.surface != null) startGamepads(g);
var sev = std.mem.zeroes(c.SDL_Event);
// Idle is asleep until an event: SDL's own, and the user events the
// shell's queue raises for a terminal's output, a completion, a file
@@ -3172,6 +3182,31 @@ fn finishWindowOpacity(core: *pardes.Pardes, applied: *u8, failure: ?[]const u8)
fn syncWindowOpacity(g: *Gui, core: *pardes.Pardes) void {
if (!core.settings.window_opacity_pending) return;
+ // The first opacity under 100 on Wayland: the window made again,
+ // transparent, presenting through SDL_Renderer from then on (the
+ // capture's format, the swapchain's, is one it uploads). At a start's
+ // own WindowOpacity this is before its first frame, so unseen.
+ const unorm = g.present.swapchain_format == c.SDL_GPU_TEXTUREFORMAT_B8G8R8A8_UNORM or g.present.swapchain_format == c.SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
+ if (g.wayland and !g.present.surface_opacity and core.settings.window_opacity < 100 and unorm) {
+ // A `--detach` session's window stays hidden.
+ const hidden = c.SDL_GetWindowFlags(g.window) & c.SDL_WINDOW_HIDDEN;
+ const mode = g.present.present_mode;
+ closeWindow(g);
+ g.present.soft_present = true;
+ g.present.surface_opacity = true;
+ g.present.present_mode = c.SDL_GPU_PRESENTMODE_VSYNC;
+ g.win_flags |= c.SDL_WINDOW_TRANSPARENT | hidden;
+ log.info("WindowOpacity under 100: the window made again, transparent, presenting through SDL_Renderer", .{});
+ if (!reopenWindow(g)) {
+ // No renderer for it: opaque again, as it was.
+ g.present.soft_present = false;
+ g.present.surface_opacity = false;
+ g.present.present_mode = mode;
+ g.win_flags &= ~@as(c.SDL_WindowFlags, c.SDL_WINDOW_TRANSPARENT);
+ if (!reopenWindow(g)) core.quit = true;
+ }
+ g.win_flags &= ~hidden;
+ }
// Offscreen captures also support per-pixel alpha. Never approximate this
// with SDL_SetWindowOpacity: that would make foreground text translucent.
finishWindowOpacity(core, &g.applied_window_opacity, if (g.present.surface_opacity or g.present.capture or core.settings.window_opacity == 100)
@@ -3184,7 +3219,7 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
const s = shellOf(ctx);
const core = s.core;
// A replica client draws outside the pump, which marks it there.
- if (s.remote != null) core.frames.mark_render = pardes.FrameStats.nowNs();
+ if (s.client != null) core.frames.mark_render = pardes.FrameStats.nowNs();
const g = s.gui orelse return;
frame_started_ns = monoNs();
const frame = surface;
@@ -3201,6 +3236,15 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
if (!s.presented and s.skipped_presents <= 3) core.present_skipped = true;
}
+/// The gamepad subsystem, started once the first frame is drawn, as the
+/// loop first waits: its scan (udev, hidapi, libusb) took 40 ms of a start.
+/// A pad plugged in already is added by it (GAMEPAD_ADDED).
+fn startGamepads(g: *Gui) void {
+ if (g.gamepads) return;
+ g.gamepads = true;
+ if (!c.SDL_InitSubSystem(c.SDL_INIT_GAMEPAD)) log.warn("SDL_InitSubSystem(GAMEPAD): {s}", .{c.SDL_GetError()});
+}
+
fn postPresent(ctx: ?*anyopaque) void {
const s = shellOf(ctx);
const g = s.gui orelse return;
@@ -3736,7 +3780,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
});
// A replica client's rows apply after its view is parked again:
// its scroll has not moved yet.
- if (in.remote == null and pane.scroll() == was) {
+ if (in.client == null and pane.scroll() == was) {
resetScroll(g);
return false;
}
@@ -3746,7 +3790,7 @@ fn scrollRows(g: *Gui, in: *Input, gpa: std.mem.Allocator) bool {
// the last one, a fraction of a row off, and the next turn's frame
// jumps from there (against the turn when it reverses).
const moved = st.rows != 0 or st.lag != g.scroll_lag;
- if (moved and in.remote == null) core.needs_frame = true;
+ if (moved and in.client == null) core.needs_frame = true;
g.scroll_lag = st.lag;
g.scroll_rect = r;
const body_y = core.bodyTop(pane, r);
@@ -7985,7 +8029,7 @@ test "trackpad rotation never types search keys into an insert-mode file or raw
_ = try core.setTestFile("unchanged\n");
var client: Client = .{ .link = undefined, .io = std.testing.io, .gpa = gpa, .texts = .init(gpa) };
defer client.deinit();
- var in: Input = .{ .core = core, .remote = &client };
+ var in: Input = .{ .core = core, .client = &client };
var g: Gui = undefined;
g.trackpad = .{};
var ev: c.UITrackpadEvent = std.mem.zeroes(c.UITrackpadEvent);
@@ -8054,7 +8098,7 @@ test "detached trackpad scrolling keeps fractions local and queues whole rows fo
_ = try core.render(arena.allocator());
var client: Client = .{ .link = undefined, .io = std.testing.io, .gpa = gpa, .texts = .init(gpa) };
defer client.deinit();
- var in: Input = .{ .core = core, .remote = &client };
+ var in: Input = .{ .core = core, .client = &client };
const id = core.view().active;
const r = core.view().rects[id];
var g: Gui = undefined;