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,19 +961,6 @@ fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
|
|||||||
} else |_| {}
|
} else |_| {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're scrolling up or down, then send a mouse event
|
|
||||||
if (yoff != 0) {
|
|
||||||
const pos = window.getCursorPos() catch |err| {
|
|
||||||
log.err("error reading cursor position: {}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
win.mouseReport(if (yoff < 0) .five else .four, .press, win.mouse.mods, pos) catch |err| {
|
|
||||||
log.err("error reporting mouse event: {}", .{err});
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
//log.info("SCROLL: {} {}", .{ xoff, yoff });
|
//log.info("SCROLL: {} {}", .{ xoff, yoff });
|
||||||
_ = xoff;
|
_ = xoff;
|
||||||
|
|
||||||
@ -982,13 +969,27 @@ fn scrollCallback(window: glfw.Window, xoff: f64, yoff: f64) void {
|
|||||||
const delta: isize = sign * @max(@divFloor(win.grid_size.rows, 15), 1);
|
const delta: isize = sign * @max(@divFloor(win.grid_size.rows, 15), 1);
|
||||||
log.info("scroll: delta={}", .{delta});
|
log.info("scroll: delta={}", .{delta});
|
||||||
|
|
||||||
// Modify our viewport, this requires a lock since it affects rendering
|
|
||||||
{
|
{
|
||||||
win.renderer_state.mutex.lock();
|
win.renderer_state.mutex.lock();
|
||||||
defer win.renderer_state.mutex.unlock();
|
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|
|
win.io.terminal.scrollViewport(.{ .delta = delta }) catch |err|
|
||||||
log.err("error scrolling viewport err={}", .{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) {
|
||||||
|
const pos = window.getCursorPos() catch |err| {
|
||||||
|
log.err("error reading cursor position: {}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
win.mouseReport(if (yoff < 0) .five else .four, .press, win.mouse.mods, pos) catch |err| {
|
||||||
|
log.err("error reporting mouse event: {}", .{err});
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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