Skip to content

Commit

Permalink
Fix text selection when dragging window with hidden titlebar
Browse files Browse the repository at this point in the history
  • Loading branch information
liby committed Jan 22, 2025
1 parent ddf7173 commit 9afb385
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions macos/Sources/Ghostty/SurfaceView_AppKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ 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
private var titlebarHeight: CGFloat {
guard let window = self.window else { return 0 }
return window.frame.height - window.contentLayoutRect.height
}

/// Event monitor (see individual events for why)
private var eventMonitor: Any? = nil

Expand Down Expand Up @@ -579,12 +585,30 @@ extension Ghostty {
return true
}

override func mouseDown(with event: NSEvent) {
guard let surface = self.surface else { return }
private func handleSurfaceMouseDown(_ surface: ghostty_surface_t, _ event: NSEvent) {
let mods = Ghostty.ghosttyMods(event.modifierFlags)
ghostty_surface_mouse_button(surface, GHOSTTY_MOUSE_PRESS, GHOSTTY_MOUSE_LEFT, mods)
}

override func mouseDown(with event: NSEvent) {
guard let surface = self.surface else { return }
guard let window = self.window else {
handleSurfaceMouseDown(surface, event)
return
}

// Convert point to view coordinates
let point = self.convert(event.locationInWindow, from: nil)
let isInTitlebarRegion = point.y >= (self.frame.height - titlebarHeight)

if isInTitlebarRegion {
window.performDrag(with: event)
return
}

handleSurfaceMouseDown(surface, event)
}

override func mouseUp(with event: NSEvent) {
// Always reset our pressure when the mouse goes up
prevPressureStage = 0
Expand Down

0 comments on commit 9afb385

Please sign in to comment.