Merge pull request #2026 from ghostty-org/gtk-follow

apprt/gtk: ignore mouse movement if no actual movement occurs
This commit is contained in:
Mitchell Hashimoto
2024-08-01 06:29:12 -07:00
committed by GitHub

View File

@ -1394,11 +1394,21 @@ fn gtkMouseMotion(
const self = userdataSelf(ud.?);
const scaled = self.scaledCoordinates(x, y);
self.cursor_pos = .{
const pos: apprt.CursorPos = .{
.x = @floatCast(@max(0, scaled.x)),
.y = @floatCast(scaled.y),
};
// GTK can send spurious mouse movement events. Ignore them
// because this can cause actual issues:
// https://github.com/ghostty-org/ghostty/issues/2022
if (pos.x == self.cursor_pos.x and pos.y == self.cursor_pos.y) {
return;
}
// Our pos changed, update
self.cursor_pos = pos;
// If we don't have focus, and we want it, grab it.
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
if (c.gtk_widget_has_focus(gl_widget) == 0 and self.app.config.@"focus-follows-mouse") {