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

Fix text selection when dragging window with hidden titlebar #5286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

liby
Copy link
Contributor

@liby liby commented Jan 22, 2025

When macos-titlebar-style is set to hidden, dragging the window near the
titlebar area would inadvertently trigger text selection. This was caused
by the mouseDown event being passed to the surface even when in the
titlebar region.

The fix improves the logic in mouseDown handler to properly handle window
dragging without triggering text selection when clicking in the titlebar
area. This provides a smoother window dragging experience while preserving
expected text selection behavior in the terminal area.

demo.mov

Fixes #5259

Copy link
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment. I want to think about this approach a bit more and just explore if there's any other way to detect a titlebar area click but this seems agreeable otherwise.

@@ -124,6 +124,9 @@ extension Ghostty {
// A timer to fallback to ghost emoji if no title is set within the grace period
private var titleFallbackTimer: Timer?

// The height of the titlebar in points, updated when window properties change
private var titlebarHeight: CGFloat = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any reason to cache this. It seems fairly cheap to calculate on the fly, and that removes a whole lot of complexity around keeping it up to date during various events that I suspect we could get wrong at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that caching the titlebar height isn't necessary. The calculation is very lightweight and removing the cache eliminates the complexity of keeping it in sync across various window events.

Regarding alternative approaches for detecting titlebar clicks, I've thought about it and here are some considerations:

  • Using hitTest might be less reliable since the titlebar area is part of our view when using hidden titlebar style

  • Adding a separate view for the titlebar would add complexity without clear benefits

  • Using window delegate methods would be too late as we need to intercept the click before window dragging

I'm open to exploring other approaches if you have specific ideas in mind!

@liby liby force-pushed the bugfix/macos-hidden-titlebar-drag-selection branch from 5591e10 to 381797d Compare January 22, 2025 06:55
@liby liby force-pushed the bugfix/macos-hidden-titlebar-drag-selection branch from 381797d to 9afb385 Compare January 22, 2025 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macOS: Dragging with macos-titlebar-style=hidden should not invoke selection
2 participants