Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: clicking unfocused window should not encode VT mouse event #2595

Open
mitchellh opened this issue Nov 4, 2024 · 4 comments
Open

macOS: clicking unfocused window should not encode VT mouse event #2595

mitchellh opened this issue Nov 4, 2024 · 4 comments
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK) os/macos

Comments

@mitchellh
Copy link
Contributor

mitchellh commented Nov 4, 2024

See #2593 for detailed discussion including comparisons to other terminals.

Steps to reproduce:

  1. Open Ghostty and launch htop (so we have click targets)
  2. Focus another macOS application while having the Ghostty window visible in the background
  3. Click a process in Ghostty

What you'll see is that the row is highlighted. Ghostty comes to focus and encodes the pty event so htop highlights the row.

What should happen: If the surface is unfocused or the app is unfocused, a click should bring it (the surface and window) to focus but not generate a pty event.

@mitchellh mitchellh added os/macos gui GUI or app issue regardless of platform (i.e. Swift, GTK) labels Nov 4, 2024
@mitchellh
Copy link
Contributor Author

cc @emilazy

@emilazy
Copy link
Contributor

emilazy commented Nov 4, 2024

Happy to try implementing this! Do you have any pointers to where I should start looking for the handling of this behaviour? I’m guessing somewhere in the Swift code?

@mitchellh
Copy link
Contributor Author

Sure! I believe the fix will be entirely Swift. I don't think any Zig will be touched at all.

The direction I was heading into was utilizing acceptsFirstMouse as a signal of when this behavior should happen (the behavior to not encode a mouse event). I added some logging there and in all the mouse events and noticed that:

  1. acceptsFirstMouse always happens before mouseDown
  2. acceptsFirstMouse never happens before any other mouse event (tried right, middle, scrolling)
  3. acceptsFirstMouse happens anytime the window is not focused (i.e. it happens even when the app is focused)

Given this, my thinking was: set a flag in acceptsFirstMouse, when mouseDown sees it, it does NOT call the ghostty mouse event callback, reset the flag.

I don't know if that's robust enough or the right approach, but that's where I was looking...

@emilazy
Copy link
Contributor

emilazy commented Nov 16, 2024

Coming back to this after a while :)

I take it the idea is that we can’t just refuse acceptsFirstMouse because it would break the desired behaviour of still focusing a split on click, so we have to sorta hack around it by using the notification as an indicator of what the next mouse event is going to be?

One complication is that we need command+click to send an event through without raising, as is standard macOS behaviour. Not sure how acceptsFirstMouse will behave with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gui GUI or app issue regardless of platform (i.e. Swift, GTK) os/macos
Projects
None yet
Development

No branches or pull requests

2 participants