diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gui/gui.zig | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index a2d98baf..e3014c6a 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -3310,11 +3310,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { 5 => .forward, else => return, }; - g.pad_x = b.x; - g.pad_y = b.y; - g.pointer_present = true; - const mc = mouseCell(g, in.core, b.x, b.y); - g.pointer_cell = mc; + const mc = pointAt(g, in.core, b.x, b.y); 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). @@ -3324,9 +3320,6 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { }, c.SDL_EVENT_MOUSE_MOTION => { const m = sev.motion; - g.pad_x = m.x; - g.pad_y = m.y; - g.pointer_present = true; const held: ?pardes.Mouse.Button = if ((m.state & c.SDL_BUTTON_LMASK) != 0) .left else if ((m.state & c.SDL_BUTTON_MMASK) != 0) @@ -3335,18 +3328,13 @@ 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); - g.pointer_cell = mc; + const mc = pointAt(g, in.core, m.x, m.y); in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, pointerMods()) }); }, c.SDL_EVENT_MOUSE_WHEEL => { const w = sev.wheel; if (w.y == 0 and w.x == 0) return; - 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); - g.pointer_cell = mc; + const mc = pointAt(g, in.core, w.mouse_x, w.mouse_y); wheelAt(g, in, .{ .x = w.x, .y = w.y, .integer_y = w.integer_y, .mods = pointerMods() }, mc); }, c.SDL_EVENT_FINGER_DOWN, c.SDL_EVENT_FINGER_MOTION, c.SDL_EVENT_FINGER_UP, c.SDL_EVENT_FINGER_CANCELED => { @@ -3423,14 +3411,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { g.pointer_cell = mc; if (mc.col == old.col and mc.row == old.row) continue; const held = heldPointerButton(g); - in.post(.{ .mouse = .{ - .button = held orelse .none, - .kind = if (held != null) .drag else .motion, - .col = mc.col, - .row = mc.row, - .tag_hit = mc.tag_hit, - .body_hit = mc.body_hit, - } }); + in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, .{}) }); }, .click => |ck| { const button: pardes.Mouse.Button = switch (ck.which) { @@ -3438,9 +3419,7 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { .execute => .middle, .look => .right, }; - g.pointer_present = true; - const mc = mouseCell(g, in.core, g.pad_x, g.pad_y); - g.pointer_cell = mc; + const mc = pointAt(g, in.core, g.pad_x, g.pad_y); in.post(.{ .mouse = .{ .button = button, .kind = if (ck.down) .press else .release, @@ -3451,9 +3430,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); - g.pointer_cell = mc; + const mc = pointAt(g, in.core, g.pad_x, g.pad_y); var left = ticks; while (left != 0) { left += if (ticks > 0) -1 else 1; @@ -3733,6 +3710,17 @@ fn mouseCell(g: *const Gui, core: ?*const pardes.Pardes, x: f32, y: f32) MouseCe return mouseCellWithGeometry(g, core, x, y, windowGeometry(g.window)); } +/// The pointer at window point (x, y), as an event or the gamepad puts it +/// there: where the window keeps it, and the cell under it. +fn pointAt(g: *Gui, core: ?*const pardes.Pardes, x: f32, y: f32) MouseCell { + g.pad_x = x; + g.pad_y = y; + g.pointer_present = true; + const mc = mouseCell(g, core, x, y); + g.pointer_cell = mc; + return mc; +} + /// 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 @@ -3762,14 +3750,7 @@ fn refreshPresentedPointer(g: *Gui, in: *Input) void { g.pointer_cell = mc; if (!moved) return; const held = heldPointerButton(g); - in.post(.{ .mouse = .{ - .button = held orelse .none, - .kind = if (held != null) .drag else .motion, - .col = mc.col, - .row = mc.row, - .tag_hit = mc.tag_hit, - .body_hit = mc.body_hit, - } }); + in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, .{}) }); } fn pollGamepad(g: *Gui, in: *Input) void { @@ -3794,14 +3775,7 @@ fn pollGamepad(g: *Gui, in: *Input) void { g.pointer_cell = mc; if (mc.col != old.col or mc.row != old.row) { const held = heldPointerButton(g); - in.post(.{ .mouse = .{ - .button = held orelse .none, - .kind = if (held != null) .drag else .motion, - .col = mc.col, - .row = mc.row, - .tag_hit = mc.tag_hit, - .body_hit = mc.body_hit, - } }); + in.post(.{ .mouse = pointerMouse(held orelse .none, if (held != null) .drag else .motion, mc, .{}) }); } } const lx: f32 = @floatFromInt(c.SDL_GetGamepadAxis(pad, c.SDL_GAMEPAD_AXIS_LEFTX)); |
