From 6cee9e57f641b60c70d49c56b7a2370135a2946a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 20 Sep 2023 08:53:31 -0700 Subject: [PATCH] macos: prevent mouseEntered/Exited processing if already in that state See the comment in the code. Fixes #494 --- macos/Sources/Ghostty/SurfaceView.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/macos/Sources/Ghostty/SurfaceView.swift b/macos/Sources/Ghostty/SurfaceView.swift index 93abf356e..913b1cfb1 100644 --- a/macos/Sources/Ghostty/SurfaceView.swift +++ b/macos/Sources/Ghostty/SurfaceView.swift @@ -491,6 +491,12 @@ extension Ghostty { } override func mouseEntered(with event: NSEvent) { + // For reasons unknown (Cocoaaaaaaaaa), mouseEntered is called + // multiple times in an unbalanced way with mouseExited when a new + // tab is created. In this scenario, we only want to process our + // callback once since this is stateful and we expect balancing. + if (mouseEntered) { return } + mouseEntered = true // If our cursor is hidden, we hide it on upon entry and we unhide @@ -501,6 +507,9 @@ extension Ghostty { } override func mouseExited(with event: NSEvent) { + // See mouseEntered + if (!mouseEntered) { return } + mouseEntered = false if (cursorVisible == .hidden) {