scale x, speed up scrolling

This commit is contained in:
Mitchell Hashimoto
2023-06-29 11:47:28 -07:00
parent 32031701b8
commit de5468e214
2 changed files with 34 additions and 9 deletions

View File

@ -299,7 +299,11 @@ extension Ghostty {
if event.hasPreciseScrollingDeltas { if event.hasPreciseScrollingDeltas {
mods = 1 mods = 1
// TODO(mitchellh): do we have to scale the x/y here? // We do a 2x speed multiplier. This is subjective, it "feels" better to me.
x *= 2;
y *= 2;
// TODO(mitchellh): do we have to scale the x/y here by window scale factor?
} }
// Determine our momentum value // Determine our momentum value

View File

@ -1342,11 +1342,32 @@ pub fn scrollCallback(
}; };
}; };
// Positive is right // For detailed comments see the y calculation above.
const x_sign: isize = if (xoff < 0) -1 else 1; const x: ScrollAmount = if (xoff == 0) .{} else x: {
const x_delta_unsigned: usize = if (xoff == 0) 0 else 1; if (!scroll_mods.precision) {
const x_delta: isize = x_sign * @intCast(isize, x_delta_unsigned); const x_sign: isize = if (xoff < 0) -1 else 1;
log.info("scroll: delta_y={} delta_x={}", .{ y.delta, x_delta }); const x_delta_unsigned: usize = 1;
const x_delta: isize = x_sign * @intCast(isize, x_delta_unsigned);
break :x .{ .sign = x_sign, .delta_unsigned = x_delta_unsigned, .delta = x_delta };
}
const poff = self.mouse.pending_scroll_x + (xoff * -1);
const cell_size = self.cell_size.width;
if (@fabs(poff) < cell_size) {
self.mouse.pending_scroll_x = poff;
break :x .{};
}
const amount = poff / cell_size;
self.mouse.pending_scroll_x = poff - (amount * cell_size);
break :x .{
.delta_unsigned = @intFromFloat(usize, @fabs(amount)),
.delta = @intFromFloat(isize, amount),
};
};
log.info("scroll: delta_y={} delta_x={}", .{ y.delta, x.delta });
{ {
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
@ -1376,9 +1397,9 @@ pub fn scrollCallback(
} }
} }
if (x_delta_unsigned > 0) { if (x.delta_unsigned > 0) {
const seq = if (x_delta < 0) "\x1bOC" else "\x1bOD"; const seq = if (x.delta < 0) "\x1bOC" else "\x1bOD";
for (0..x_delta_unsigned) |_| { for (0..x.delta_unsigned) |_| {
_ = self.io_thread.mailbox.push(.{ _ = self.io_thread.mailbox.push(.{
.write_stable = seq, .write_stable = seq,
}, .{ .forever = {} }); }, .{ .forever = {} });