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 15:56:58 -0300
commit95321ab082a750f4f1ef26d9bb21d1d3d01274f2 (patch)
tree916ff2929d41c37407c735906436e160529b5fde /src/gui/gui.zig
parentf4e295a0b61ae34e8abfd339eb1b6f658f8bf329 (diff)
downloadpardes-95321ab082a750f4f1ef26d9bb21d1d3d01274f2.tar.gz
pardes-95321ab082a750f4f1ef26d9bb21d1d3d01274f2.zip
drag 1/3: the window is dragged by the workspace tag's blank (SDL hit test)
Diffstat (limited to 'src/gui/gui.zig')
-rw-r--r--src/gui/gui.zig23
1 files changed, 23 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;