summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/Inbox.zig4
-rw-r--r--dev/gui/gui.zig37
-rw-r--r--dev/tui/tui.zig59
3 files changed, 12 insertions, 88 deletions
diff --git a/dev/Inbox.zig b/dev/Inbox.zig
index ed3a9835..4df02013 100644
--- a/dev/Inbox.zig
+++ b/dev/Inbox.zig
@@ -23,8 +23,6 @@ pub const Msg = union(enum) {
kind_job: *KindJob,
files_changed,
fs_ready,
- /// The daemon asks for the window again (`pardes-gui --attach`).
- window,
/// A shell a dead session left, its pty's master (Adopt); pid 0 is
/// the last of them told.
adopted: struct { pid: libc.pid_t, fd: c_int },
@@ -44,7 +42,7 @@ pub const Msg = union(enum) {
.adopted => |a| if (a.fd >= 0) {
_ = libc.close(a.fd);
},
- .eof, .files_changed, .fs_ready, .window => {},
+ .eof, .files_changed, .fs_ready => {},
}
}
};
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index c3272957..81d58137 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -990,8 +990,9 @@ fn closeWindow(g: *Gui) void {
};
}
-/// `pardes-gui --attach`: a window again, as the first was made, at the
-/// size the last one had. False when the display will not give one.
+/// A window again, as the first was made, at the size the last one had
+/// (a transparent one: syncWindowOpacity). False when the display will not
+/// give one.
fn reopenWindow(g: *Gui) bool {
const window = c.SDL_CreateWindow("pardes", g.window_w, g.window_h, g.win_flags) orelse return false;
if (comptime builtin.os.tag == .macos) c.ui_macos_trackpad_attach(window);
@@ -2395,10 +2396,8 @@ fn pollGamepad(g: *Gui, in: *Input) void {
const Shell = struct {
core: *pardes.Pardes,
- /// The window's, while one is open; null while detached (`detached` has
- /// it).
+ /// The window's, while one is open; null once detached.
gui: ?*Gui = null,
- detached: ?*Gui = null,
io: std.Io,
gpa: std.mem.Allocator,
fs: ?*ninep_io.Listener = null,
@@ -2452,7 +2451,7 @@ const Shell = struct {
}
/// Detach: the window closed, the session left running with no
- /// window, for `pardes-gui --attach` to open one again.
+ /// window, detached for good: an attach shows it as a client.
fn detachWindow(ctx: ?*anyopaque) void {
const s = shellOf(ctx);
// A replica client's: its link ends.
@@ -2499,29 +2498,13 @@ const Shell = struct {
fn closeTheWindow(s: *Shell) void {
const g = s.gui orelse return;
closeWindow(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.detached = true;
s.core.unattended = s.peers.count() == 0;
- daemon.setState(true);
- }
-
- fn openTheWindow(s: *Shell) void {
- 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.detached = null;
- s.peers.detached = false;
- s.core.unattended = false;
- s.core.needs_frame = true;
- resetScroll(g);
- daemon.setState(false);
+ daemon.setDetached();
}
fn watched(ctx: ?*anyopaque) bool {
@@ -2686,7 +2669,6 @@ const Shell = struct {
},
.files_changed => check_files = true,
.fs_ready => {},
- .window => if (s.gui == null) s.openTheWindow(),
.adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd),
};
if (check_files and file_watch.reloadChanged(s.core, s.io, s.gpa, s.watches))
@@ -3200,13 +3182,6 @@ fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
const s: *Shell = @ptrCast(@alignCast(ctx));
const q = s.queue;
switch (note) {
- .attach => |a| {
- // A terminal for a window session: the daemon refuses that kind
- // before it is sent, so only an old one's would be here.
- if (a.tty >= 0) _ = libc.close(a.tty);
- if (a.stub >= 0) daemon.tellStub(a.stub, "r{s}", .{"a window session takes no terminal"});
- if (a.tty < 0) q.push(.window);
- },
.adopted => |a| {
for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| q.push(.{ .adopted = .{ .pid = pid, .fd = fd } });
q.push(.{ .adopted = .{ .pid = 0, .fd = -1 } });
diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig
index 5c1945e6..42f73559 100644
--- a/dev/tui/tui.zig
+++ b/dev/tui/tui.zig
@@ -104,9 +104,6 @@ const Msg = union(enum) {
/// The terminal's input ended: its end of file, a hangup. A session
/// a daemon keeps carries on detached; any other ends.
quit,
- /// A terminal for this detached session, and its stub's pipe
- /// (daemon.Note.attach).
- attach: struct { tty: posix.fd_t, stub: posix.fd_t },
/// A shell a dead session left, its pty's master (daemon.Note.adopted).
adopted: struct { pid: posix.pid_t, fd: posix.fd_t },
/// A timed wait ran out: the core's next wake has come.
@@ -573,7 +570,7 @@ fn surfaceHasKittyKey(surface: *const pardes.Surface, key: u64) bool {
/// Where a session's terminal comes from: /dev/tty, as a plain `pardes`
/// opens it; one open already (a session forked off its stub,
-/// daemon.forkSession); or none, detached until one is attached (`--detach`).
+/// daemon.forkSession); or none, detached from the start (`--detach`).
/// The terminal a session starts on: /dev/tty, one its stub opened (an
/// upgraded session's is raw already, `termios` the cooked one), or none.
pub const Term = union(enum) { open, fd: struct { fd: posix.fd_t, termios: ?posix.termios = null }, detached };
@@ -811,9 +808,9 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8,
/// A terminal a session draws on, while it has one: entered (raw, the
/// alternate screen, mouse and paste reports) and left (all of it put back,
-/// the terminal closed) at the session's start and end, and at a detach and
-/// a reattach in between (daemon.zig), its stub `daemon.stub`. One a
-/// process: a second terminal on a session is a replica client of it.
+/// the terminal closed) at the session's start and end, or at a detach
+/// (daemon.zig), its stub `daemon.stub`. One a process, the one the session
+/// was born with: an attach is a replica client of it.
const Screen = struct {
io: std.Io,
gpa: std.mem.Allocator,
@@ -1019,10 +1016,6 @@ const Own = struct {
},
.search_rows => |b| b.deinit(gpa),
.kind_job => |j| j.drop(),
- .attach => |a| {
- _ = libc.close(a.tty);
- if (a.stub >= 0) _ = libc.close(a.stub);
- },
.adopted => |a| _ = libc.close(a.fd),
else => {},
};
@@ -1108,12 +1101,6 @@ fn clearNativeImages(
fn deliverNote(ctx: *anyopaque, note: daemon.Note) void {
const loop: *Loop = @ptrCast(@alignCast(ctx));
switch (note) {
- .attach => |a| if (a.tty < 0) {
- if (a.stub >= 0) daemon.tellStub(a.stub, "r{s}", .{"a terminal session takes a terminal"});
- } else loop.postEvent(.{ .attach = .{ .tty = a.tty, .stub = a.stub } }) catch {
- _ = libc.close(a.tty);
- _ = libc.close(a.stub);
- },
.adopted => |a| {
for (a.pids[0..a.n], a.fds[0..a.n]) |pid, fd| loop.postEvent(.{ .adopted = .{ .pid = pid, .fd = fd } }) catch {
_ = libc.close(fd);
@@ -1324,42 +1311,7 @@ const Shell = struct {
if (null_fd > 2) _ = libc.close(null_fd);
}
daemon.tellStubDetached();
- daemon.setState(true);
- }
-
- /// `pardes --attach`'s terminal, for a detached session: its own again,
- /// entered as the first one was, sized, asked what it can do, and drawn
- /// whole. One attached already takes no other (the daemon makes a second
- /// a replica client).
- fn attachTerminal(s: *Shell, fd: posix.fd_t, stub: posix.fd_t, cooked: ?posix.termios) void {
- const screen = s.screen orelse {
- _ = libc.close(fd);
- return refuse(stub, "that session has no terminal of its own to attach to");
- };
- if (screen.on) {
- _ = libc.close(fd);
- return refuse(stub, "that session has a terminal: join it as a client, `pardes --attach=<socket>:<name>`");
- }
- const tty = Screen.ttyOn(s.io, screen.buf, fd, cooked) catch {
- _ = libc.close(fd);
- daemon.setState(true);
- return refuse(stub, "that terminal would not go raw");
- };
- screen.enter(tty) catch {
- daemon.setState(true);
- return refuse(stub, "that terminal would not take the screen");
- };
- daemon.stub = stub;
- s.setAttended(true);
- startInput(s.loop, screen) catch {};
- screen.vx.queryTerminalSend(screen.tty.writer()) catch {};
- s.core.needs_frame = true;
- daemon.setState(false);
- }
-
- /// A terminal refused: its stub told why (a test's has none).
- fn refuse(stub: posix.fd_t, why: []const u8) void {
- if (stub >= 0) daemon.tellStub(stub, "r{s}", .{why});
+ daemon.setDetached();
}
const PtyCalls = host_io.Ptys.Calls(Shell);
@@ -1662,7 +1614,6 @@ const Shell = struct {
core.quit = true;
return true;
},
- .attach => |a| s.attachTerminal(a.tty, a.stub, null),
.adopted => |a| s.ptys.adoptions.adoptShell(s.core, a.pid, a.fd),
.replica => |j| {
s.peers.handed(j.fd, j.view);