summaryrefslogtreecommitdiff
path: root/src/gui/gui.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-24 13:55:12 -0300
committerGabriel Schneider <[email protected]>2026-10-24 16:02:22 -0300
commit4c635f357adb95235429d8905b8598a2643b4f3b (patch)
treedd4f4f9b7e66b2bad71a0d30541c2b4ce2bb4cb9 /src/gui/gui.zig
parent95321ab082a750f4f1ef26d9bb21d1d3d01274f2 (diff)
downloadpardes-4c635f357adb95235429d8905b8598a2643b4f3b.tar.gz
pardes-4c635f357adb95235429d8905b8598a2643b4f3b.zip
drag 2/3: a pane's or column's grip let go past the window's edge opens it in a new window (Handover.zig)
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig75
1 files changed, 73 insertions, 2 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 86d751f5..39eedf89 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1938,11 +1938,27 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u
// 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 window = c.SDL_CreateWindow("pardes", 1120, 720, win_flags) orelse {
+ // `--geometry=WxH[+X+Y]`, as X11 programs take it.
+ var want_w: c_int = 1120;
+ var want_h: c_int = 720;
+ var want_at: ?[2]c_int = null;
+ if (opts_in.geometry) |spec| geometry: {
+ const x_at = std.mem.indexOfScalar(u8, spec, 'x') orelse break :geometry;
+ const plus = std.mem.indexOfAnyPos(u8, spec, x_at, "+-") orelse spec.len;
+ want_w = std.math.clamp(std.fmt.parseInt(c_int, spec[0..x_at], 10) catch break :geometry, 200, 16384);
+ want_h = std.math.clamp(std.fmt.parseInt(c_int, spec[x_at + 1 .. plus], 10) catch break :geometry, 120, 16384);
+ if (plus == spec.len) break :geometry;
+ const second = std.mem.indexOfAnyPos(u8, spec, plus + 1, "+-") orelse break :geometry;
+ const gx = std.fmt.parseInt(c_int, spec[plus + @intFromBool(spec[plus] == '+') .. second], 10) catch break :geometry;
+ const gy = std.fmt.parseInt(c_int, spec[second + @intFromBool(spec[second] == '+') ..], 10) catch break :geometry;
+ want_at = .{ gx, gy };
+ }
+ const window = c.SDL_CreateWindow("pardes", want_w, want_h, win_flags) orelse {
log.err("SDL_CreateWindow: {s}", .{c.SDL_GetError()});
return error.SdlInit;
};
defer c.SDL_DestroyWindow(window);
+ 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
@@ -3198,7 +3214,12 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
};
g.pointer_mapped = true;
g.pointer_cell = mc;
- in.post(.{ .mouse = pointerMouse(button, if (b.down) .press else .release, mc, pointerMods()) });
+ var ev = pointerMouse(button, if (b.down) .press else .release, mc, pointerMods());
+ // Let go past the window's edge (SDL follows a held button out
+ // of the window: Wayland's implicit grab, X11's capture).
+ const win = windowGeometry(g.window);
+ ev.outside = !b.down and (b.x < 0 or b.y < 0 or b.x >= win.window_w or b.y >= win.window_h);
+ in.post(.{ .mouse = ev });
},
c.SDL_EVENT_MOUSE_MOTION => {
const m = sev.motion;
@@ -3886,6 +3907,7 @@ const Shell = struct {
.lsp = lsp,
.pipe = pipe,
.search = search,
+ .hand_over = handOver,
};
const grid_vtable: pardes.Host.VTable = vt: {
@@ -3984,6 +4006,11 @@ const Shell = struct {
b.deinit(s.gpa);
s.saw_event = true;
},
+ .handed => |h| {
+ s.core.update(.{ .handed = .{ .seq = h.seq, .to = if (h.ok) h.words else "", .failure = if (h.ok) null else h.words } });
+ s.gpa.free(h.words);
+ s.saw_event = true;
+ },
.files_changed => check_files = true,
.fs_ready => {},
};
@@ -4555,6 +4582,50 @@ fn search(ctx: ?*anyopaque, gen: u32) void {
pardes.Stream.runHere(s.core, gen);
}
+/// Handover `seq`'s dump to its file, and a worker to carry it to another
+/// window (Handover.start). A new window is as big as this one, and where
+/// the pointer let go of it when the display lets a window say where it
+/// goes (X11; on Wayland the compositor places it).
+fn handOver(ctx: ?*anyopaque, seq: u32, bytes: []const u8) void {
+ const s = shellOf(ctx);
+ const Handover = pardes.Handover;
+ const path = Handover.dumpPath(s.gpa, seq) catch |err| return s.core.update(.{ .handed = .{ .seq = seq, .failure = @errorName(err) } });
+ const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true, .CLOEXEC = true }, @as(libc.mode_t, 0o600));
+ const written = fd >= 0 and host_io.writeFd(fd, bytes);
+ if (fd >= 0) _ = libc.close(fd);
+ if (!written) {
+ _ = libc.unlink(path);
+ s.gpa.free(path);
+ return s.core.update(.{ .handed = .{ .seq = seq, .failure = "cannot write its dump" } });
+ }
+ const job = s.gpa.create(Handover.Job) catch {
+ _ = libc.unlink(path);
+ s.gpa.free(path);
+ return s.core.update(.{ .handed = .{ .seq = seq, .failure = "out of memory" } });
+ };
+ job.* = .{ .gpa = s.gpa, .seq = seq, .path = path, .post = Queue.pushHanded, .post_ctx = s.queue };
+ if (s.gui) |g| {
+ var w: c_int = 0;
+ var h: c_int = 0;
+ _ = c.SDL_GetWindowSize(g.window, &w, &h);
+ var gx: f32 = 0;
+ var gy: f32 = 0;
+ _ = c.SDL_GetGlobalMouseState(&gx, &gy);
+ const placed = !std.mem.eql(u8, std.mem.span(c.SDL_GetCurrentVideoDriver()), "wayland");
+ const geometry = (if (placed)
+ std.fmt.bufPrint(&job.geometry, "{d}x{d}+{d}+{d}", .{ w, h, @as(i32, @intFromFloat(gx)) - 40, @as(i32, @intFromFloat(gy)) - 10 })
+ else
+ std.fmt.bufPrint(&job.geometry, "{d}x{d}", .{ w, h })) catch "";
+ job.geometry_len = geometry.len;
+ }
+ Handover.start(job) catch |err| {
+ _ = libc.unlink(path);
+ s.gpa.free(path);
+ s.gpa.destroy(job);
+ return s.core.update(.{ .handed = .{ .seq = seq, .failure = @errorName(err) } });
+ };
+}
+
fn pollCwds(core: *pardes.Pardes, ptys: *[pardes.MAX_PANES]?Pty) void {
for (ptys, 0..) |slot, id| if (slot) |pt| {
if (pt.fd < 0) continue;