mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
fix deadlock with mouse reports
This commit is contained in:
@ -961,7 +961,24 @@ fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
|
|||||||
} else |_| {}
|
} else |_| {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're scrolling up or down, then send a mouse event
|
//log.info("SCROLL: {} {}", .{ xoff, yoff });
|
||||||
|
_ = xoff;
|
||||||
|
|
||||||
|
// Positive is up
|
||||||
|
const sign: isize = if (yoff > 0) -1 else 1;
|
||||||
|
const delta: isize = sign * @max(@divFloor(win.grid_size.rows, 15), 1);
|
||||||
|
log.info("scroll: delta={}", .{delta});
|
||||||
|
|
||||||
|
{
|
||||||
|
win.renderer_state.mutex.lock();
|
||||||
|
defer win.renderer_state.mutex.unlock();
|
||||||
|
|
||||||
|
// Modify our viewport, this requires a lock since it affects rendering
|
||||||
|
win.io.terminal.scrollViewport(.{ .delta = delta }) catch |err|
|
||||||
|
log.err("error scrolling viewport err={}", .{err});
|
||||||
|
|
||||||
|
// If we're scrolling up or down, then send a mouse event. This requires
|
||||||
|
// a lock since we read terminal state.
|
||||||
if (yoff != 0) {
|
if (yoff != 0) {
|
||||||
const pos = window.getCursorPos() catch |err| {
|
const pos = window.getCursorPos() catch |err| {
|
||||||
log.err("error reading cursor position: {}", .{err});
|
log.err("error reading cursor position: {}", .{err});
|
||||||
@ -973,22 +990,6 @@ fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//log.info("SCROLL: {} {}", .{ xoff, yoff });
|
|
||||||
_ = xoff;
|
|
||||||
|
|
||||||
// Positive is up
|
|
||||||
const sign: isize = if (yoff > 0) -1 else 1;
|
|
||||||
const delta: isize = sign * @max(@divFloor(win.grid_size.rows, 15), 1);
|
|
||||||
log.info("scroll: delta={}", .{delta});
|
|
||||||
|
|
||||||
// Modify our viewport, this requires a lock since it affects rendering
|
|
||||||
{
|
|
||||||
win.renderer_state.mutex.lock();
|
|
||||||
defer win.renderer_state.mutex.unlock();
|
|
||||||
|
|
||||||
win.io.terminal.scrollViewport(.{ .delta = delta }) catch |err|
|
|
||||||
log.err("error scrolling viewport err={}", .{err});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
win.queueRender() catch unreachable;
|
win.queueRender() catch unreachable;
|
||||||
@ -1007,12 +1008,6 @@ fn mouseReport(
|
|||||||
// TODO: posToViewport currently clamps to the window boundary,
|
// TODO: posToViewport currently clamps to the window boundary,
|
||||||
// do we want to not report mouse events at all outside the window?
|
// do we want to not report mouse events at all outside the window?
|
||||||
|
|
||||||
// Everything in here requires reading/writing mouse state so we
|
|
||||||
// acquire a big lock. Mouse events are rare so this should be okay
|
|
||||||
// but we can make this more fine-grained later.
|
|
||||||
self.renderer_state.mutex.lock();
|
|
||||||
defer self.renderer_state.mutex.unlock();
|
|
||||||
|
|
||||||
// Depending on the event, we may do nothing at all.
|
// Depending on the event, we may do nothing at all.
|
||||||
switch (self.io.terminal.modes.mouse_event) {
|
switch (self.io.terminal.modes.mouse_event) {
|
||||||
.none => return,
|
.none => return,
|
||||||
|
Reference in New Issue
Block a user