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.zig227
1 files changed, 21 insertions, 206 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 85245b54..0d8c53ca 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1098,55 +1098,6 @@ const Gui = struct {
deck: deck.Deck = .{},
};
-/// The Gui's fields that are each window's own, one a view (views.zig):
-/// the window and its presenting, its scroll and glide, its pointer, its
-/// blink, its images, its capture. The
-/// device, the atlas, the font and the pipelines are every window's. The
-/// Gui holds the live window's; the others wait in `Shell.windows`.
-const window_fields = [_][:0]const u8{
- "window", "soft_renderer", "soft_texture", "soft_tex_w", "soft_tex_h",
- "window_w", "window_h", "scroll_pane", "scroll_rect", "scroll_body_y",
- "scroll_body_h", "scroll_held_px", "scroll_col", "scroll_row", "scroll_delta",
- "scroll_lag", "scroll_edge", "scroll_edge_len", "scroll_notch", "program_wheel",
- "glide", "pace_ns", "frame_arrival_ns",
- "blink_due", "cursor_quad_alpha", "caret", "input_ns", "pointer_present", "pointer_shape",
- "pointer_cell", "prepared_images", "touch",
- "live_ctrl", "live_alt", "applied_window_opacity", "capture_tex", "capture_tex_w",
- "capture_tex_h", "capture_xfer", "capture_xfer_size", "captured", "capture_dir",
-};
-
-const GuiWindow = blk: {
- @setEvalBranchQuota(100_000);
- const st = @typeInfo(Gui).@"struct";
- var types: [window_fields.len]type = undefined;
- var attrs: [window_fields.len]std.lang.Type.Struct.FieldAttributes = undefined;
- for (window_fields, 0..) |name, i| {
- const at = for (st.field_names, 0..) |n, j| {
- if (std.mem.eql(u8, n, name)) break j;
- } else @compileError("gui: Gui has no field " ++ name);
- types[i] = st.field_types[at];
- attrs[i] = .{ .default_value_ptr = st.field_attrs[at].default_value_ptr };
- }
- break :blk @Struct(.auto, null, &window_fields, &types, &attrs);
-};
-
-fn copyWindow(dst: anytype, src: anytype) void {
- inline for (window_fields) |name| @field(dst, name) = @field(src, name);
-}
-
-/// The live window's share of `g` as a window starts, but its SDL window
-/// (reopenWindow makes that).
-fn freshWindow(g: *Gui) void {
- @setEvalBranchQuota(100_000);
- const st = @typeInfo(Gui).@"struct";
- inline for (window_fields) |name| {
- const at = comptime for (st.field_names, 0..) |n, j| {
- if (std.mem.eql(u8, n, name)) break j;
- } else unreachable;
- if (comptime st.field_attrs[at].defaultValue(st.field_types[at])) |d| @field(g, name) = d;
- }
-}
-
/// What a window held of its own let go (closeWindow lets the window go).
fn releaseWindowParts(g: *Gui, gpa: std.mem.Allocator) void {
if (g.capture_tex) |texture| c.SDL_ReleaseGPUTexture(g.device, texture);
@@ -1858,16 +1809,8 @@ fn localSession(
if (fs) |f| try f.watch(&queue, wakeFs);
_ = c.SDL_StartTextInput(g.window);
- // An upgraded session's views, a window each again.
- if (upgrade.resumed) |*rec| if (!rec.fresh and !headless) shell.resumeWindows();
- // PARDES_TEST_VIEWS=N: N more windows from the start, each a view of the
- // session (views.zig), captured under view-<k>; view 0 live after.
- if (test_mode and upgrade.resumed == null) if (std.c.getenv("PARDES_TEST_VIEWS")) |n| {
- for (0..std.fmt.parseInt(u8, std.mem.span(n), 10) catch 0) |_| shell.openAnotherWindow(null);
- core.toView(0);
- shell.follow();
- };
- defer shell.closeOtherWindows();
+ // An upgraded session's window, its view's again.
+ if (upgrade.resumed) |*rec| if (!rec.fresh and !headless) shell.resumeWindow();
if (test_mode) setStdinRaw() catch {};
shell.threads_ok = true;
@@ -1897,10 +1840,8 @@ fn localSession(
const nc = host_io.restoreCore(gpa, core, rp, &shell.peers, inotify_fd, &watches) orelse break :blk;
pipe_tasks.cancelAll(io);
queue.discardCompletions();
- // One view, the live window (host_io.restoreCore).
- shell.closeOtherWindows();
+ // One view, the window's (host_io.restoreCore).
shell.gview = 0;
- shell.windowed = 1;
shell.stopPtys();
clearNativeImages(g);
g.prepared_images.clearRetainingCapacity();
@@ -2269,8 +2210,6 @@ const StdinFeed = struct {
var seq_start: usize = 0;
while (seq_start < len) {
// ESC]777;<event>;<fields>BEL, the driver's own:
- // view;<k>: what follows is window k's (k from 1), as an event
- // of that window's makes its view live (route).
// mouse;<down|up|motion>;<SDL button, 0 for none>;<x>;<y>[;<mods>]
// mouse;wheel;<amount>;<x>;<y>[;<mods>]: a mouse event at
// window pixels, built as SDL would and run through dispatch,
@@ -2291,13 +2230,7 @@ const StdinFeed = struct {
const event = rest[osc.len..bel];
const semi = std.mem.indexOfScalar(u8, event, ';') orelse event.len;
const fields = event[@min(semi + 1, event.len)..];
- if (std.mem.eql(u8, event[0..semi], "view")) {
- const k = std.fmt.parseInt(u8, fields, 10) catch 0;
- if (in.shell) |sh| if (k >= 1 and pardes.views.isOpen(sh.core, k - 1)) {
- sh.core.toView(k - 1);
- sh.follow();
- };
- } else if (std.mem.eql(u8, event[0..semi], "mouse")) {
+ if (std.mem.eql(u8, event[0..semi], "mouse")) {
if (g) |gp| {
var parts = std.mem.splitScalar(u8, fields, ';');
const kind = parts.next() orelse "";
@@ -2553,8 +2486,7 @@ test "the window's function and editing keys reach a terminal as its cursor keys
const Input = struct {
core: *pardes.Pardes,
- /// The shell whose windows these are: a window closed while others
- /// stay takes its view with it (views.zig).
+ /// 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
/// straight to the core, which only reads here.
@@ -2578,8 +2510,7 @@ const Input = struct {
return;
}
if (in.shell) |s| {
- if (s.windowsOpen() > 1) return s.closeView(s.core.live);
- // The last window, with replica clients: they keep the session,
+ // The window, with replica clients: they keep the session,
// as a Detach would, the daemon holding it.
if (s.peers.count() > 0 and daemon.kept()) return s.closeTheWindow();
}
@@ -3190,19 +3121,16 @@ const Shell = struct {
/// The tick a paced frame is sampled at (waitInput): the clock the
/// core is advanced to while anything moves.
paced_ns: ?u64 = null,
- /// Each other view's window, while another's is in the Gui (views.zig),
- /// and the view whose window the Gui holds (`follow`).
- windows: [pardes.views.max]GuiWindow = undefined,
+ /// The view the window shows (views.zig); a second window on the
+ /// session is a replica client of it (`pardes-gui --attach`).
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,
/// The session's replica clients (src/replica.zig), on sockets: views
- /// of their own with no window here (`windowed`).
+ /// of their own with no window here.
peers: replica.Peers = .{},
- /// The views that are this process's windows (the rest are clients').
- windowed: u8 = 1,
/// This wait took only a replica's post (its input, its join): the pump
/// after it reads no new time, so it moves nothing the replicas'
/// speculations stand on (tui.zig's `mail_only`).
@@ -3261,8 +3189,6 @@ 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");
- // One of several: its window goes, and the session stays in the rest.
- if (s.windowsOpen() > 1) return s.closeView(s.core.live);
if (!daemon.kept()) return s.core.reportFailure(s.core.view().active, "Detach: no pardes daemon keeps this session; closing its window ends it");
s.closeTheWindow();
}
@@ -3273,67 +3199,6 @@ const Shell = struct {
return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS();
}
- /// The Gui holds the window of the core's live view.
- fn follow(s: *Shell) void {
- const g = s.gui orelse return;
- const k = s.core.live;
- if (s.gview == k) return;
- // A replica client's view has no window here: the Gui keeps the one
- // it holds (`windowView` puts that view back when it acts).
- if (s.windowed & (@as(u8, 1) << @intCast(k)) == 0) return;
- if (s.gview < s.windows.len) copyWindow(&s.windows[s.gview], g);
- copyWindow(g, &s.windows[k]);
- s.gview = k;
- }
-
- /// An event of another view's window: that view goes live.
- fn route(s: *Shell, sev: *const c.SDL_Event) void {
- if (!pardes.views.several(s.core)) return;
- const g = s.gui orelse return;
- const w = c.SDL_GetWindowFromEvent(sev) orelse return;
- // The Gui's window's, while a client's view is live: its own again.
- if (w == g.window) {
- _ = s.windowView();
- return;
- }
- for (s.windows, 0..) |win, k| if (k != s.gview and pardes.views.isOpen(s.core, @intCast(k)) and win.window == w) {
- s.core.toView(@intCast(k));
- return s.follow();
- };
- }
-
- /// `pardes-gui --attach` while a window is open: another window, a view
- /// of its own (views.zig), opened as the first was; or (`existing`) an
- /// upgraded session's view's window again.
- fn openAnotherWindow(s: *Shell, existing: ?u8) void {
- const g = s.gui orelse return;
- s.follow();
- const k = existing orelse s.core.openView() orelse return log.err("--attach: this session has as many windows as it takes", .{});
- const live = s.gview;
- copyWindow(&s.windows[live], g);
- freshWindow(g);
- if (!reopenWindow(g)) {
- log.err("--attach: no window: {s}", .{c.SDL_GetError()});
- copyWindow(g, &s.windows[live]);
- return s.core.closeView(k);
- }
- if (s.test_mode) {
- // Its own grid, its captures under view-<k> (PARDES_TEST_VIEWS).
- // ponytail: the path is kept for the session, a few bytes.
- const cols: u32 = if (std.c.getenv("PARDES_TEST_COLS")) |v| std.fmt.parseInt(u16, std.mem.span(v), 10) catch 80 else 80;
- const rows: u32 = if (std.c.getenv("PARDES_TEST_ROWS")) |v| std.fmt.parseInt(u16, std.mem.span(v), 10) catch 24 else 24;
- _ = c.SDL_SetWindowSize(g.window, @intCast(cols * g.cell_w + g.capture_pad), @intCast(rows * g.cell_h + g.capture_pad));
- _ = c.SDL_SyncWindow(g.window);
- g.capture = true;
- g.capture_dir = std.fmt.allocPrint(s.gpa, "{s}/view-{d}", .{ s.windows[live].capture_dir, k }) catch "";
- if (g.capture_dir.len > 0) std.Io.Dir.cwd().createDirPath(s.io, g.capture_dir) catch {};
- }
- s.gview = k;
- s.windowed |= @as(u8, 1) << @intCast(k);
- s.core.toView(k);
- s.core.needs_frame = true;
- }
-
/// The Gui's window's view live, for what the window does to its own
/// (its size, its scroll): a replica client's input may have been the
/// last. True when it was not, and is now.
@@ -3343,25 +3208,6 @@ const Shell = struct {
return true;
}
- /// View `k`'s window closed while others stay: the view goes with it.
- fn closeView(s: *Shell, k: u8) void {
- const g = s.gui orelse return;
- s.core.toView(k);
- s.follow();
- closeWindow(g);
- releaseWindowParts(g, s.gpa);
- s.gview = std.math.maxInt(u8);
- s.windowed &= ~(@as(u8, 1) << @intCast(k));
- s.core.closeView(k);
- // Into another window's view, if a client's was the one left live.
- for (0..pardes.views.max) |i| if (s.windowed & (@as(u8, 1) << @intCast(i)) != 0 and pardes.views.isOpen(s.core, @intCast(i))) {
- if (s.core.live != i) s.core.toView(@intCast(i));
- break;
- };
- s.follow();
- s.core.needs_frame = true;
- }
-
/// 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.
@@ -3380,26 +3226,6 @@ const Shell = struct {
return false;
}
- /// How many of the session's views are windows here.
- fn windowsOpen(s: *const Shell) usize {
- return @popCount(s.windowed & s.core.views_open);
- }
-
- /// The session's end: every window but the live one closed.
- fn closeOtherWindows(s: *Shell) void {
- const g = s.gui orelse return;
- for (0..s.windows.len) |i| {
- const k: u8 = @intCast(i);
- if (k == s.gview or !pardes.views.isOpen(s.core, k)) continue;
- var live: GuiWindow = undefined;
- copyWindow(&live, g);
- copyWindow(g, &s.windows[k]);
- closeWindow(g);
- releaseWindowParts(g, s.gpa);
- copyWindow(g, &live);
- }
- }
-
fn closeTheWindow(s: *Shell) void {
const g = s.gui orelse return;
closeWindow(g);
@@ -3503,19 +3329,14 @@ const Shell = struct {
}
}
- /// An upgraded session's views, a window each again: the Gui's is the
- /// live view's, the others open as `--attach` opens one; a replica
- /// client's, kept for its rejoin (views.away), none.
- fn resumeWindows(s: *Shell) void {
- const live = s.core.live;
- s.gview = live;
+ /// An upgraded session's window, its view's again; every other view
+ /// but a replica client's, kept for its rejoin (views.away), closes.
+ fn resumeWindow(s: *Shell) void {
+ s.gview = s.core.live;
for (0..pardes.views.max) |i| {
const k: u8 = @intCast(i);
- if (k != live and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.openAnotherWindow(k);
+ if (k != s.gview and pardes.views.isOpen(s.core, k) and !pardes.views.isAway(s.core, k)) s.core.closeView(k);
}
- s.windowed |= @as(u8, 1) << @intCast(live);
- s.core.toView(live);
- s.follow();
}
const vtable: pardes.Host.VTable = .{
@@ -3636,7 +3457,7 @@ const Shell = struct {
},
.files_changed => check_files = true,
.fs_ready => {},
- .window => if (s.gui != null) s.openAnotherWindow(null) else s.openTheWindow(),
+ .window => if (s.gui == null) s.openTheWindow(),
.adopted => |a| s.adoptions.adoptShell(s.core, a.pid, a.fd),
};
if (check_files and file_watch.reloadChanged(s.core, s.io, s.gpa, s.watches))
@@ -3658,7 +3479,6 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
const s = shellOf(ctx);
const core = s.core;
var in: Input = .{ .core = core, .shell = s };
- s.follow();
s.mail_only = true;
s.took_input = false;
defer s.waited = true;
@@ -3751,21 +3571,21 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
motion = sev;
} else {
if (motion) |*m| {
- s.route(m);
+ _ = s.windowView();
dispatch(g, &in, m);
}
motion = null;
if (sev.type == c.SDL_EVENT_MOUSE_MOTION) {
motion = sev;
} else {
- s.route(&sev);
+ _ = s.windowView();
dispatch(g, &in, &sev);
}
}
if (!c.SDL_PollEvent(&sev)) break;
}
if (motion) |*m| {
- s.route(m);
+ _ = s.windowView();
dispatch(g, &in, m);
}
}
@@ -3792,11 +3612,11 @@ fn waitInput(ctx: ?*anyopaque, timeout_ms: u32) void {
pardes.turn.wake();
if (more) {
if (!s.split(&sev)) {
- s.route(&sev);
+ _ = s.windowView();
dispatch(g, &in, &sev);
while (c.SDL_PollEvent(&sev)) {
if (s.split(&sev)) break;
- s.route(&sev);
+ _ = s.windowView();
dispatch(g, &in, &sev);
}
}
@@ -3842,7 +3662,6 @@ fn waitDetached(core: *pardes.Pardes, timeout_ms: u32) void {
fn pollFrame(ctx: ?*anyopaque) void {
const s = shellOf(ctx);
- s.follow();
s.reconcilePtys();
const core = s.core;
if (s.fs) |f| if (f.tick().pending) s.queue.push(.fs_ready);
@@ -4110,7 +3929,6 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
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();
- s.follow();
const g = s.gui orelse return;
frame_started_ns = monoNs();
const frame = surface;
@@ -4129,7 +3947,6 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
fn postPresent(ctx: ?*anyopaque) void {
const s = shellOf(ctx);
- s.follow();
const g = s.gui orelse return;
// No image (a minimized window): nothing was drawn to point at.
if (!s.presented) return;
@@ -7628,9 +7445,7 @@ fn rulePx(chrome: *const pardes.Chrome) f32 {
/// by which every size given in logical pixels is drawn, as acme scales its
/// Border, ButtonBorder and Scrollgap (scalesize). Cells, glyphs and what is
/// measured in them are already the display's pixels and are not scaled.
-/// ponytail: one per process: a session's windows (views.zig) on screens
-/// of two densities draw at the density of the last one opened or moved;
-/// a field of `window_fields` when that matters.
+/// One per process, as its window is.
var display_scale: f32 = 1;
/// The window's display scale, or PARDES_TEST_SCALE (a harness forcing 2x);