summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:49:44 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:40:08 -0300
commit99fa8f511e1ea575470bfd66b43945168a330f62 (patch)
treec2a5aed2955ca13e679a622faeeef69e78d2ee73
parent0fe85c8dc4afad25aa6b616d9d04d79257b27bf3 (diff)
downloadpardes-99fa8f511e1ea575470bfd66b43945168a330f62.tar.gz
pardes-99fa8f511e1ea575470bfd66b43945168a330f62.zip
gui: mouseCell returns the cell, never null (a window point maps to the grid since no post pass moves one), so its nine orelse branches go, and pointer_mapped, which then always equals pointer_present, with them
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/gui/gui.zig94
1 files changed, 17 insertions, 77 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index ca7b3dd6..a2d98baf 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -1488,7 +1488,6 @@ const Gui = struct {
link_cursor: ?*c.SDL_Cursor = null,
box_cursor: ?*c.SDL_Cursor = null,
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.
@@ -1545,7 +1544,7 @@ const window_fields = [_][:0]const u8{
"glide", "pace_ns", "sel_glow", "hover_glow", "frame_arrival_ns",
"blink_due", "cursor_quad_alpha", "scene_tex", "scene_tex_w", "scene_tex_h",
"scene_failures", "scene_target_failed", "post", "pointer_present", "pointer_shape",
- "pointer_mapped", "pointer_cell", "presented_images", "prepared_images", "touch",
+ "pointer_cell", "presented_images", "prepared_images", "touch",
"live_ctrl", "live_alt", "applied_window_opacity", "capture_tex", "capture_tex_w",
"capture_tex_h", "capture_xfer", "capture_xfer_size", "captured", "capture_dir",
};
@@ -3257,7 +3256,6 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
c.SDL_EVENT_WINDOW_FOCUS_LOST => in.post(.{ .focus = false }),
c.SDL_EVENT_WINDOW_MOUSE_LEAVE => {
g.pointer_present = false;
- g.pointer_mapped = false;
in.post(.pointer_leave);
},
c.SDL_EVENT_KEY_DOWN => {
@@ -3315,20 +3313,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
g.pad_x = b.x;
g.pad_y = b.y;
g.pointer_present = true;
- const mc = mouseCell(g, in.core, b.x, b.y) orelse {
- g.pointer_mapped = false;
- if (!b.down) if (g.pointer_cell) |last| in.post(.{ .mouse = .{
- .button = button,
- .kind = .release,
- .col = last.col,
- .row = last.row,
- .tag_hit = last.tag_hit,
- .body_hit = last.body_hit,
- } });
- in.post(.pointer_leave);
- return;
- };
- g.pointer_mapped = true;
+ const mc = mouseCell(g, in.core, b.x, b.y);
g.pointer_cell = mc;
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
@@ -3350,12 +3335,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
.right
else
null;
- const mc = mouseCell(g, in.core, m.x, m.y) orelse {
- g.pointer_mapped = false;
- in.post(.pointer_leave);
- return;
- };
- g.pointer_mapped = true;
+ const mc = mouseCell(g, in.core, m.x, m.y);
g.pointer_cell = mc;
in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()) });
},
@@ -3365,12 +3345,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
g.pad_x = w.mouse_x;
g.pad_y = w.mouse_y;
g.pointer_present = true;
- const mc = mouseCell(g, in.core, w.mouse_x, w.mouse_y) orelse {
- g.pointer_mapped = false;
- in.post(.pointer_leave);
- return;
- };
- g.pointer_mapped = true;
+ const mc = mouseCell(g, in.core, w.mouse_x, w.mouse_y);
g.pointer_cell = mc;
wheelAt(g, in, .{ .x = w.x, .y = w.y, .integer_y = w.integer_y, .mods = pointerMods() }, mc);
},
@@ -3444,15 +3419,9 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
g.pad_y = std.math.clamp(g.pad_y + dy, 0, geometry.window_h - 1);
c.SDL_WarpMouseInWindow(g.window, g.pad_x, g.pad_y);
g.pointer_present = true;
- const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry) orelse {
- g.pointer_mapped = false;
- in.post(.pointer_leave);
- continue;
- };
- g.pointer_mapped = true;
+ const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry);
g.pointer_cell = mc;
- if (old) |previous|
- if (mc.col == previous.col and mc.row == previous.row) continue;
+ if (mc.col == old.col and mc.row == old.row) continue;
const held = heldPointerButton(g);
in.post(.{ .mouse = .{
.button = held orelse .none,
@@ -3470,20 +3439,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
.look => .right,
};
g.pointer_present = true;
- const mc = mouseCell(g, in.core, g.pad_x, g.pad_y) orelse {
- g.pointer_mapped = false;
- if (!ck.down) if (g.pointer_cell) |last| in.post(.{ .mouse = .{
- .button = button,
- .kind = .release,
- .col = last.col,
- .row = last.row,
- .tag_hit = last.tag_hit,
- .body_hit = last.body_hit,
- } });
- in.post(.pointer_leave);
- continue;
- };
- g.pointer_mapped = true;
+ const mc = mouseCell(g, in.core, g.pad_x, g.pad_y);
g.pointer_cell = mc;
in.post(.{ .mouse = .{
.button = button,
@@ -3496,12 +3452,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void {
},
.wheel => |ticks| {
g.pointer_present = true;
- const mc = mouseCell(g, in.core, g.pad_x, g.pad_y) orelse {
- g.pointer_mapped = false;
- in.post(.pointer_leave);
- continue;
- };
- g.pointer_mapped = true;
+ const mc = mouseCell(g, in.core, g.pad_x, g.pad_y);
g.pointer_cell = mc;
var left = ticks;
while (left != 0) {
@@ -3654,10 +3605,10 @@ test "a click at the window's corner lands in the corner cell with a post chain
try std.testing.expect(core.settings.post.set(.crt, "", true));
var g = testGui(10, 20, 6, 12);
const geometry: WindowGeometry = .{ .window_w = 400, .window_h = 240, .pixel_w = 800, .pixel_h = 480 };
- const last = mouseCellWithGeometry(&g, core, 399.9, 239.9, geometry).?;
+ const last = mouseCellWithGeometry(&g, core, 399.9, 239.9, geometry);
try std.testing.expectEqual(@as(u16, 79), last.col);
try std.testing.expectEqual(@as(u16, 23), last.row);
- const first = mouseCellWithGeometry(&g, core, 0, 0, geometry).?;
+ const first = mouseCellWithGeometry(&g, core, 0, 0, geometry);
try std.testing.expectEqual(@as(u16, 0), first.col);
try std.testing.expectEqual(@as(u16, 0), first.row);
}
@@ -3773,12 +3724,12 @@ 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));
}
@@ -3791,7 +3742,7 @@ fn hitTest(_: ?*c.SDL_Window, area: [*c]const c.SDL_Point, data: ?*anyopaque) ca
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;
+ const mc = mouseCell(g, core, @floatFromInt(area.*.x), @floatFromInt(area.*.y));
return if (pardes.tagline.workspaceBlank(core, mc.col, mc.row, mc.tag_hit)) c.SDL_HITTEST_DRAGGABLE else c.SDL_HITTEST_NORMAL;
}
@@ -3806,14 +3757,8 @@ 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) orelse {
- if (g.pointer_mapped) in.post(.pointer_leave);
- g.pointer_mapped = false;
- return;
- };
- const moved = !g.pointer_mapped or g.pointer_cell == null or
- g.pointer_cell.?.col != mc.col or g.pointer_cell.?.row != mc.row;
- g.pointer_mapped = true;
+ const mc = mouseCell(g, 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;
const held = heldPointerButton(g);
@@ -3844,15 +3789,10 @@ fn pollGamepad(g: *Gui, in: *Input) void {
g.pointer_present = true;
c.SDL_WarpMouseInWindow(g.window, g.pad_x, g.pad_y);
}
- const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry) orelse {
- if (g.pointer_present and g.pointer_mapped) in.post(.pointer_leave);
- if (g.pointer_present) g.pointer_mapped = false;
- return;
- };
+ const mc = mouseCellWithGeometry(g, in.core, g.pad_x, g.pad_y, geometry);
if (g.pointer_present) {
- g.pointer_mapped = true;
g.pointer_cell = mc;
- if (old == null or mc.col != old.?.col or mc.row != old.?.row) {
+ if (mc.col != old.col or mc.row != old.row) {
const held = heldPointerButton(g);
in.post(.{ .mouse = .{
.button = held orelse .none,