diff options
| -rw-r--r-- | src/gui/gui.zig | 23 | ||||
| -rw-r--r-- | src/tagline.zig | 41 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index d71f7047..86d751f5 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -1500,6 +1500,9 @@ const Gui = struct { pointer_shape: pardes.Surface.PointerShape = .arrow, pointer_mapped: bool = false, pointer_cell: ?MouseCell = null, + /// The core the hit test asks (hitTest), while a local session runs; + /// null attached, where the session's tag is another process's. + hit_core: ?*pardes.Pardes = null, capture: bool = false, /// Pixels the capture holds past the grid (PARDES_TEST_PAD). @@ -2183,6 +2186,10 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, attach: ?[]const u defer g.glide.deinit(gpa); resetGlyphAtlas(&g); + // The window is dragged by the workspace tag's blank (hitTest): the + // 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 (attach) |requested| return attachRequested(gpa, &g, requested); var attached: ?detached_client.Client = null; try localSession(init, &g, opts_in, test_mode, &attached); @@ -2226,6 +2233,8 @@ fn localSession( break :blk try pardes.dump.initFromDump(allocs.pardes, opts, bytes); } else try pardes.Pardes.init(allocs.pardes, opts); defer core.deinit(); + g.hit_core = core; + defer g.hit_core = null; core.native_images = true; core.native_image_patches = true; observeGuiFont(g, core); @@ -2363,6 +2372,7 @@ fn localSession( if (fs) |f| f.reset(nc); core.deinit(); core = nc; + g.hit_core = nc; shell.core = nc; shell.surface = null; observeGuiFont(g, core); @@ -3640,6 +3650,19 @@ fn mouseCell(g: *const Gui, core: ?*const pardes.Pardes, x: f32, y: f32) ?MouseC return mouseCellWithGeometry(g, core, x, y, windowGeometry(g.window)); } +/// SDL's hit test, asked as the pointer moves over the window: a blank cell +/// of the workspace tag (tagline.workspaceBlank) is the window's to drag, as +/// a title bar is. SDL gives the compositor a B1 press there (Wayland's +/// xdg_toplevel.move, X11's _NET_WM_MOVERESIZE, macOS's own drag), so the +/// press never reaches the core; B2 and B3 there still do. +fn hitTest(_: ?*c.SDL_Window, area: [*c]const c.SDL_Point, data: ?*anyopaque) callconv(.c) c.SDL_HitTestResult { + const g: *Gui = @ptrCast(@alignCast(data orelse return c.SDL_HITTEST_NORMAL)); + const core = g.hit_core orelse return c.SDL_HITTEST_NORMAL; + if (area == null) return c.SDL_HITTEST_NORMAL; + const mc = mouseCell(g, core, @floatFromInt(area.*.x), @floatFromInt(area.*.y)) orelse return c.SDL_HITTEST_NORMAL; + return if (pardes.tagline.workspaceBlank(core, mc.col, mc.row, mc.tag_hit)) c.SDL_HITTEST_DRAGGABLE else c.SDL_HITTEST_NORMAL; +} + fn heldPointerButton(g: *const Gui) ?pardes.Mouse.Button { const buttons = c.SDL_GetMouseState(null, null); if ((buttons & c.SDL_BUTTON_LMASK) != 0 or g.deck.r2_held or g.deck.rpad_click) return .left; diff --git a/src/tagline.zig b/src/tagline.zig index c057772d..79c2c09b 100644 --- a/src/tagline.zig +++ b/src/tagline.zig @@ -11,6 +11,7 @@ const exec = @import("exec.zig"); const config = @import("config.zig"); const pdf_enabled = panes.Pdf.enabled; const dump = @import("dump.zig"); +const Layer = @import("Layer.zig"); const Pane = panes.Pane; const Text = panes.Text; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; @@ -444,6 +445,46 @@ pub fn headerSelection(t: *const Text, text: []const u8, row: usize) ?struct { l return .{ .lo = @max(lo, start) - start, .hi = @min(hi, end) - start }; } +/// Whether the workspace tag is blank at cell (col, row): its inset left of +/// the text, or past the text's end with two cells kept free for the caret +/// (a B1 there still types at the end of the tag). A pixel shell lets the +/// window be dragged by such a cell, as a browser by the space beside its +/// tabs: blank is no text, so no button of acme's is taken from any. A +/// column's tag and a pane's are not: their blank is where B1 types. +pub fn workspaceBlank(p: *Pardes, col: u16, row: u16, tag_hit: ?pardes.TagHit) bool { + if (row >= p.topBarHeight() or col >= p.screen_w) return false; + if (col < TAG_TEXT_INSET) return true; + const text = edit.flatSurface(p, &p.global_tag) catch return false; + const scroll: usize = if (p.header_focus and p.header_column == null) p.header_scroll else 0; + const at = @as(usize, Layer.columnAt(p, .workspace, 0, tag_hit, false, 0) orelse (col - TAG_TEXT_INSET)) + scroll; + return at >= panes.File.displayWidth(modal.lineSlice(text, 0)) + 2; +} + +test "the workspace tag is blank left of its text and past its end, and nowhere else" { + const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 12, .tty_only = true }); + defer p.deinit(); + p.global_tag.own = try p.gpa.dupe(u8, "Newcol Exit"); + p.sync(); + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + _ = try p.render(arena.allocator()); + const end = TAG_TEXT_INSET + "Newcol Exit".len; + try std.testing.expect(workspaceBlank(p, 0, 0, null)); + try std.testing.expect(workspaceBlank(p, TAG_TEXT_INSET - 1, 0, null)); + // Every cell of the text, the gap between its words too, is not. + for (TAG_TEXT_INSET..end) |c| try std.testing.expect(!workspaceBlank(p, @intCast(c), 0, null)); + // The two cells after it are the caret's, then blank to the edge. + try std.testing.expect(!workspaceBlank(p, end, 0, null)); + try std.testing.expect(!workspaceBlank(p, end + 1, 0, null)); + try std.testing.expect(workspaceBlank(p, end + 2, 0, null)); + try std.testing.expect(workspaceBlank(p, 79, 0, null)); + // Below the workspace tag: a column's tag, a pane: never. + for (1..12) |r| try std.testing.expect(!workspaceBlank(p, 79, @intCast(r), null)); + // Hidden, there is none. + p.settings.workspace_tag = false; + try std.testing.expect(!workspaceBlank(p, 79, 0, null)); +} + /// Column and workspace tags are one line, as acme's: a newline typed, /// pasted or restored from a dump into one becomes a space, the caret and /// the selection kept on the same characters. |
