Mouse input becomes stuck and selection scroll runs forever after switching focus #10713
Issue DescriptionWhile using AI cli agents to do long running work I've experience mouse input freeze after text selection, where keyboard input still works. When this happens I can still Alt-Tab between windows and type in the terminal, but any selection or click (left or right) with the mouse is non-responsive. Closing the application and restarting fixes the issue for a time. Succinct summary: Expected BehaviorMouse state should reset cleanly when the window loses focus. Selection should stop, auto-scroll should stop, and mouse input should work normally when you return. Actual Behavior
Even without the auto-scroll scenario, simply holding any mouse button and alt-tabbing away can leave the mouse state stuck. Reproduction Steps
Ghostty LogsNo response Ghostty VersionOS Version InformationUbuntu 25.10 (Linux only) Display ServerWayland (Linux only) Desktop Environment/Window ManagerGNOME Shell 49.0 Minimal Ghostty ConfigurationDefault configuration, no changes.Additional Relevant ConfigurationNo response I acknowledge that:
|
Replies: 12 comments 5 replies
|
I created this patch (with codex cli), built and have been running it for a few days. It appears to have fixed my issues. I was going to open a PR but read the contributing docs. diff --git a/src/Surface.zig b/src/Surface.zig
--- a/src/Surface.zig
+++ b/src/Surface.zig
@@ -1159,7 +1159,13 @@ fn selectionScrollTick(self: *Surface) !void {
// If we don't have a left mouse button down then we
// don't do anything.
- if (self.mouse.left_click_count == 0) return;
+ if (self.mouse.left_click_count == 0) {
+ self.queueIo(
+ .{ .selection_scroll = false },
+ .unlocked,
+ );
+ return;
+ }
@@ -3323,6 +3329,24 @@ pub fn focusCallback(self: *Surface, focused: bool) !void {
}
}
+ // Reset mouse state on focus loss
+ if (!focused) {
+ self.mouse.left_click_count = 0;
+ for (&self.mouse.click_state, 0..) |*state, i| {
+ if (state.* == .press) {
+ const button: input.MouseButton = @enumFromInt(i);
+ _ = self.mouseButtonCallback(.release, button, self.mouse.mods) catch |err| blk: {
+ log.warn("error releasing mouse button on focus loss err={}", .{err});
+ break :blk false;
+ };
+ }
+ }
+
+ if (self.selection_scroll_active) {
+ self.queueIo(.{ .selection_scroll = false }, .unlocked);
+ }
+ }
+
// Schedule render which also drains our mailbox
try self.queueRender();
diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig
--- a/src/apprt/gtk/class/surface.zig
+++ b/src/apprt/gtk/class/surface.zig
@@ -2750,7 +2750,7 @@
- log.warn("error in key callback err={}", .{err});
+ log.warn("error in mouse callback err={}", .{err});
@@ -2803,7 +2803,7 @@
- log.warn("error in key callback err={}", .{err});
+ log.warn("error in mouse callback err={}", .{err}); |
|
I have the same issue as you, I am not familiar with submitting particular issues but I am just going to copy your patch fix. I am running my stuff on a Mac mini and use a Logitech mouse, so that also may be causing issues somehow(?) Will send updates if this actually works |
macOS users. Your problem is very likely not the same problem as this issue. It likely has already been fixed in #11276. Stop adding noise to this issue.