summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.zig182
1 files changed, 85 insertions, 97 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 56782f7a..18cb8b7b 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -3132,7 +3132,7 @@ test "the window's function and editing keys reach a terminal as its cursor keys
}
const Input = struct {
- core: ?*pardes.Pardes = null,
+ core: *pardes.Pardes,
/// The shell whose windows these are: a window closed while others
/// stay takes its view with it (views.zig).
shell: ?*Shell = null,
@@ -3148,7 +3148,7 @@ const Input = struct {
if (in.shell) |s| if (s.core.view != s.gview) {
_ = s.windowView();
};
- if (in.core) |core| return core.update(ev);
+ in.core.update(ev);
}
fn close(in: *Input) void {
@@ -3163,7 +3163,7 @@ const Input = struct {
// as a Detach would, the daemon holding it.
if (s.peers.count() > 0 and daemon.kept()) return s.closeTheWindow();
}
- if (in.core) |core| core.quit = true;
+ in.core.quit = true;
in.quit = true;
}
};
@@ -3194,7 +3194,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
resetGlyphAtlas(g);
if (in.remote) |r| {
r.link.dirty = true;
- } else if (in.core) |core| core.needs_frame = true;
+ } else in.core.needs_frame = true;
},
c.SDL_EVENT_WINDOW_FOCUS_GAINED => g.post.focus(true),
c.SDL_EVENT_WINDOW_FOCUS_LOST => g.post.focus(false),
@@ -3208,7 +3208,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) if (in.core) |core| upgrade.noticeNewer(core);
+ if (in.remote == null) upgrade.noticeNewer(in.core);
},
c.SDL_EVENT_WINDOW_FOCUS_LOST => in.post(.{ .focus = false }),
c.SDL_EVENT_WINDOW_MOUSE_LEAVE => {
@@ -3233,7 +3233,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
r.link.dirty = true;
} else {
refitFont(g, in.core);
- if (in.core) |core| observeGuiFont(g, core);
+ observeGuiFont(g, in.core);
}
}
return;
@@ -3407,7 +3407,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
.cap_n => .{ .cp = 'N', .text = "N" },
.enter => .{ .cp = pardes.Key.enter },
.tab => .{ .cp = pardes.Key.tab },
- .tty_toggle => .{ .cp = if (in.core) |core| core.opts.tty_toggle else config.tty_toggle_default, .ctrl = true },
+ .tty_toggle => .{ .cp = in.core.opts.tty_toggle, .ctrl = true },
},
}),
.rumble => if (g.gamepad) |pad| {
@@ -3461,7 +3461,7 @@ fn pixelCell(px: f32, cell: u32) u16 {
}
fn gridCellAtDimensions(
- core: ?*const pardes.Pardes,
+ core: *const pardes.Pardes,
x: f32,
y: f32,
body_w: f32,
@@ -3472,20 +3472,20 @@ fn gridCellAtDimensions(
var point: MouseCell = .{ .col = @intFromFloat(@min(@floor(@max(x, 0) / @max(body_w, 1)), 10_000)), .row = row };
// On the rule over this row, which is where two panes meet if they do.
point.rule_above = row > 0 and @max(y, 0) - @as(f32, @floatFromInt(row)) * @max(body_h, 1) < dp(rule_grab_px);
- if (core) |p| if (p.presentation.pointerFractional(p.screen_w, p.screen_h, x / @max(body_w, 1), y / @max(body_h, 1))) |mapped| {
- for (p.surface.tagLayers()) |*layer| {
- if (layer.tagHit(mapped.x * body_w, mapped.y * body_h, body_w, body_h, tagline_w, @floatFromInt(p.row_metrics.tagline_h))) |hit| {
+ if (core.presentation.pointerFractional(core.screen_w, core.screen_h, x / @max(body_w, 1), y / @max(body_h, 1))) |mapped| {
+ for (core.surface.tagLayers()) |*layer| {
+ if (layer.tagHit(mapped.x * body_w, mapped.y * body_h, body_w, body_h, tagline_w, @floatFromInt(core.row_metrics.tagline_h))) |hit| {
point.tag_hit = hit;
break;
}
}
- };
+ }
return point;
}
-fn gridCellAtPixels(g: *const Gui, core: ?*const pardes.Pardes, x: f32, y: f32) MouseCell {
+fn gridCellAtPixels(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell {
var point = gridCellAtDimensions(core, x, y, @floatFromInt(g.cell_w), @floatFromInt(g.cell_h), @floatFromInt(g.tagline_width));
- if (core) |p| if (p.presentation.pointerFractional(p.screen_w, p.screen_h, x / @as(f32, @floatFromInt(g.cell_w)), y / @as(f32, @floatFromInt(g.cell_h)))) |mapped| for (p.surface.bodyLayers()) |*layer| {
+ if (core.presentation.pointerFractional(core.screen_w, core.screen_h, x / @as(f32, @floatFromInt(g.cell_w)), y / @as(f32, @floatFromInt(g.cell_h)))) |mapped| for (core.surface.bodyLayers()) |*layer| {
if (layer.bodyHit(mapped.x * @as(f32, @floatFromInt(g.cell_w)), mapped.y * @as(f32, @floatFromInt(g.cell_h)), @floatFromInt(g.cell_w), @floatFromInt(g.cell_h), @floatFromInt(g.tagline_width), @floatFromInt(g.tagline_height))) |hit| {
point.body_hit = hit;
break;
@@ -3554,68 +3554,61 @@ test "a click at the window's corner lands in the corner cell with a post chain
/// part of dispatch after the pointer is placed, so a test can turn it.
fn wheelAt(g: *Gui, in: *Input, w: WheelTurn, mc: MouseCell) void {
if (w.y != 0 and std.math.isFinite(w.y)) {
- if (in.core) |core| {
- const hit: ?usize = for (core.panes, 0..) |slot, i| {
- if (slot == null) continue;
- const r = core.rects[i];
- if (mc.col >= r.x and mc.col < r.x + r.w and mc.row >= r.y and mc.row < r.y + r.h) break i;
- } else null;
- if (g.scroll_pane) |old| if (hit == null or hit.? != old) {
+ const core = in.core;
+ const hit: ?usize = for (core.panes, 0..) |slot, i| {
+ if (slot == null) continue;
+ const r = core.rects[i];
+ if (mc.col >= r.x and mc.col < r.x + r.w and mc.row >= r.y and mc.row < r.y + r.h) break i;
+ } else null;
+ if (g.scroll_pane) |old| if (hit == null or hit.? != old) {
+ resetScroll(g);
+ };
+ if (hit) |id| {
+ const pdf_target = if (comptime pardes.pdf_enabled)
+ core.native_images and core.panes[id].?.pdfPage() != null
+ else
+ false;
+ const pane = core.panes[id].?;
+ if (pdf_target) {
resetScroll(g);
- };
- if (hit) |id| {
- const pdf_target = if (comptime pardes.pdf_enabled)
- core.native_images and core.panes[id].?.pdfPage() != null
- else
- false;
- const pane = core.panes[id].?;
- if (pdf_target) {
- resetScroll(g);
- in.post(.{ .pdf_scroll = .{
- .pane = @intCast(id),
- .delta_pixels = -w.y * @as(f32, @floatFromInt(g.cell_h)),
- .glide = notchOf(w.y, w.integer_y) != null,
- } });
- } else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) {
- // The program's (codex, htop, less): every whole
- // turn goes to it, no glide, for nothing of ours
- // moves. Shift keeps the wheel pardes's.
- resetScroll(g);
- g.program_wheel = accumulateWheelDelta(g.program_wheel, w.y);
- while (g.program_wheel >= 1) : (g.program_wheel -= 1)
- 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) {
- // ponytail: a replica client's wheel moves the view a
- // whole row a turn, with no glide and no touchpad's
- // fraction: its core's clock is the session's, which
- // moves only as its units come.
- if (notchOf(w.y, w.integer_y)) |lines| {
- g.program_wheel = @floatFromInt(lines);
- } else g.program_wheel = accumulateWheelDelta(g.program_wheel, w.y);
- while (g.program_wheel >= 1) : (g.program_wheel -= 1)
- in.post(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = mc.col, .row = mc.row, .shift = true } });
- while (g.program_wheel <= -1) : (g.program_wheel += 1)
- in.post(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .shift = true } });
- } else {
- g.scroll_pane = id;
- g.scroll_col = mc.col;
- g.scroll_row = mc.row;
- // A mouse wheel's notch is a whole line and
- // glides (G6); a touchpad's fraction moves the
- // picture by itself, under the finger.
- if (notchOf(w.y, w.integer_y)) |lines| {
- g.scroll_notch +|= lines;
- } else g.scroll_delta = accumulateWheelDelta(g.scroll_delta, w.y);
- }
+ in.post(.{ .pdf_scroll = .{
+ .pane = @intCast(id),
+ .delta_pixels = -w.y * @as(f32, @floatFromInt(g.cell_h)),
+ .glide = notchOf(w.y, w.integer_y) != null,
+ } });
+ } else if (!w.mods.shift and pane.isTerminal() and pardes.panes.terminal.ownsWheel(pane)) {
+ // The program's (codex, htop, less): every whole
+ // turn goes to it, no glide, for nothing of ours
+ // moves. Shift keeps the wheel pardes's.
+ resetScroll(g);
+ g.program_wheel = accumulateWheelDelta(g.program_wheel, w.y);
+ while (g.program_wheel >= 1) : (g.program_wheel -= 1)
+ 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) {
+ // ponytail: a replica client's wheel moves the view a
+ // whole row a turn, with no glide and no touchpad's
+ // fraction: its core's clock is the session's, which
+ // moves only as its units come.
+ if (notchOf(w.y, w.integer_y)) |lines| {
+ g.program_wheel = @floatFromInt(lines);
+ } else g.program_wheel = accumulateWheelDelta(g.program_wheel, w.y);
+ while (g.program_wheel >= 1) : (g.program_wheel -= 1)
+ in.post(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = mc.col, .row = mc.row, .shift = true } });
+ while (g.program_wheel <= -1) : (g.program_wheel += 1)
+ in.post(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = mc.col, .row = mc.row, .shift = true } });
+ } else {
+ g.scroll_pane = id;
+ g.scroll_col = mc.col;
+ g.scroll_row = mc.row;
+ // A mouse wheel's notch is a whole line and
+ // glides (G6); a touchpad's fraction moves the
+ // picture by itself, under the finger.
+ if (notchOf(w.y, w.integer_y)) |lines| {
+ g.scroll_notch +|= lines;
+ } else g.scroll_delta = accumulateWheelDelta(g.scroll_delta, w.y);
}
- } else {
- g.scroll_delta = accumulateWheelDelta(g.scroll_delta, w.y);
- while (g.scroll_delta >= 1) : (g.scroll_delta -= 1)
- 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.scroll_delta <= -1) : (g.scroll_delta += 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 } });
}
}
if (w.x != 0) in.post(.{ .mouse = .{
@@ -3658,18 +3651,18 @@ fn pointerMods() PointerMods {
return .{ .ctrl = (m & c.SDL_KMOD_CTRL) != 0, .shift = (m & c.SDL_KMOD_SHIFT) != 0, .alt = (m & c.SDL_KMOD_ALT) != 0, .super = (m & c.SDL_KMOD_GUI) != 0 };
}
-fn mouseCellWithGeometry(g: *const Gui, core: ?*const pardes.Pardes, x: f32, y: f32, geometry: WindowGeometry) MouseCell {
+fn mouseCellWithGeometry(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32, geometry: WindowGeometry) MouseCell {
const physical = windowPointToPixels(geometry, x, y);
return gridCellAtPixels(g, core, physical.x, physical.y);
}
-fn mouseCell(g: *const Gui, core: ?*const pardes.Pardes, x: f32, y: f32) MouseCell {
+fn mouseCell(g: *const Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell {
return mouseCellWithGeometry(g, core, x, y, windowGeometry(g.window));
}
/// The pointer at window point (x, y), as an event or the gamepad puts it
/// there: where the window keeps it, and the cell under it.
-fn pointAt(g: *Gui, core: ?*const pardes.Pardes, x: f32, y: f32) MouseCell {
+fn pointAt(g: *Gui, core: *const pardes.Pardes, x: f32, y: f32) MouseCell {
g.pad_x = x;
g.pad_y = y;
g.pointer_present = true;
@@ -3701,8 +3694,7 @@ fn heldPointerButton(g: *const Gui) ?pardes.Mouse.Button {
fn refreshPresentedPointer(g: *Gui, in: *Input) void {
if (!g.pointer_present) return;
- const core = in.core orelse return;
- const mc = mouseCell(g, core, g.pad_x, g.pad_y);
+ const mc = mouseCell(g, in.core, g.pad_x, g.pad_y);
const moved = g.pointer_cell == null or g.pointer_cell.?.col != mc.col or g.pointer_cell.?.row != mc.row;
g.pointer_cell = mc;
if (!moved) return;
@@ -6240,7 +6232,7 @@ fn drawNativeImagesGpu(
fn renderFrame(
g: *Gui,
gpa: std.mem.Allocator,
- core: ?*pardes.Pardes,
+ core: *pardes.Pardes,
surface: *const pardes.Surface,
) !bool {
if (surface.pointer_shape != g.pointer_shape) {
@@ -6290,7 +6282,7 @@ fn renderFrame(
// G6: what the scroll just done moved the pane's rows by, measured on
// this frame against the last (the glide follows it from there).
if (g.glide.pending) g.glide.measure(gpa, surface);
- g.sel_glow.now_ns = if (core) |p| p.now_ns else c.SDL_GetTicksNS();
+ g.sel_glow.now_ns = core.now_ns;
// Off, or while panes move, no glow and nothing fading.
if (surface.chrome.fx & 1 == 0 or surface.panelTracks().len != 0) g.sel_glow = .{ .now_ns = g.sel_glow.now_ns };
g.hover_glow.now_ns = g.sel_glow.now_ns;
@@ -6333,13 +6325,10 @@ fn renderFrame(
const quad_mode = chrome.cursor_glide & 2 != 0 and (chrome.cursor_glide & 1 != 0 or blink_alpha < 1 or g.glide.follow.offset != 0);
g.cursor_quad_alpha = if (quad_mode) chrome.cursor_alpha * blink_alpha else 0;
// The probe's view of this frame's motion (FrameStats.Frame).
- if (core) |p| {
- const probe = &p.frames;
- // A focused PDF's strip is the core's (pdf_view.draw).
- const pdf_focus = if (p.panes[p.active]) |pane| pane.hasPdf() else false;
- if (!pdf_focus) probe.scroll = g.glide.follow.offset;
- probe.caret = caretRow(g, surface) orelse 0;
- }
+ // A focused PDF's strip is the core's (pdf_view.draw).
+ const pdf_focus = if (core.panes[core.active]) |pane| pane.hasPdf() else false;
+ if (!pdf_focus) core.frames.scroll = g.glide.follow.offset;
+ core.frames.caret = caretRow(g, surface) orelse 0;
const cursors_shown = groups.tracks == 0 and !quad_mode;
var overlay_count = buildOverlay(g, core, surface, sw, sh);
if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count))
@@ -6596,7 +6585,7 @@ fn renderFrame(
std.debug.assert(cell_next[index] == group.cell_start + group.cell_count);
// The body's context rows, which its scroll leaves where they are.
const scrolling: ?usize = if (g.glide.follow.offset != 0) g.glide.pane else g.scroll_pane;
- const held: u16 = if (core) |p| if (scrolling) |id| if (p.panes[id]) |pane| pane.context_rows else 0 else 0 else 0;
+ const held: u16 = if (scrolling) |id| if (core.panes[id]) |pane| pane.context_rows else 0 else 0;
shifted = emitScrollRows(g, instances, cell_total, surface, layout, win_w, win_h, page, held);
// Over a theme's plaques a see-through cell with no ink blends to
// the plaque under it, so it draws nothing: its quad goes, and the
@@ -6688,8 +6677,8 @@ fn renderFrame(
.spare = spare[0..postSpare(surface, layout, &spare)],
.background = chrome.page orelse bg_default,
.foreground = chrome.fg orelse fg_default,
- .selection_foreground = if (core) |p| p.theme().sel_fg else chrome.sel_fg,
- .selection_background = if (core) |p| p.theme().sel_bg else chrome.sel_bg,
+ .selection_foreground = core.theme().sel_fg,
+ .selection_background = core.theme().sel_bg,
});
const chain_zone = tracy.zone(@src(), "post chain");
defer chain_zone.end();
@@ -10488,7 +10477,7 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface,
/// everything.
fn buildOverlay(
g: *Gui,
- core: ?*const pardes.Pardes,
+ core: *const pardes.Pardes,
surface: *const pardes.Surface,
sw: u32,
sh: u32,
@@ -10538,9 +10527,8 @@ fn appendCursorGlide(g: *Gui, surface: *const pardes.Surface, builder: *OverlayB
builder.addTri(px[0][0], px[0][1], px[2][0], px[2][1], px[3][0], px[3][1], color);
}
-fn appendWorkspacePet(g: *Gui, core: ?*const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void {
- const p = core orelse return;
- const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(p.settings.pet)));
+fn appendWorkspacePet(g: *Gui, core: *const pardes.Pardes, surface: *const pardes.Surface, builder: *OverlayBuilder) void {
+ const kind: pet.Kind = @fromBackingInt(@intCast(@backingInt(core.settings.pet)));
if (kind == .off or surface.rows == 0 or surface.cols == 0) {
g.pet_state = .{};
return;
@@ -10563,8 +10551,8 @@ fn appendWorkspacePet(g: *Gui, core: ?*const pardes.Pardes, surface: *const pard
// sample keeps this independent of input, render rate and scene effects,
// without creating another timer or forcing core animation ticks.
const pose = g.pet_state.sample(kind, c.SDL_GetTicks(), region) orelse return;
- const ink = overlayRgb(p.chromeTheme().tag_fg);
- const eye = overlayRgb(p.chromeTheme().tag_bg);
+ const ink = overlayRgb(core.chromeTheme().tag_fg);
+ const eye = overlayRgb(core.chromeTheme().tag_bg);
// Behind the cursor: the overlay is over the cells, so the pixels a
// cursor covers are left out.
var boxes: [max_cursors]CursorBox = undefined;