From 29fb70197c668638dba5060b0bcac50778919229 Mon Sep 17 00:00:00 2001 From: Cameron Dart <8763518+SkamDart@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:07:33 -0700 Subject: [PATCH] macos: surface focus follow mouse --- macos/Sources/Features/Terminal/TerminalController.swift | 5 +++-- macos/Sources/Features/Terminal/TerminalWindow.swift | 2 ++ macos/Sources/Ghostty/SurfaceView_AppKit.swift | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/macos/Sources/Features/Terminal/TerminalController.swift b/macos/Sources/Features/Terminal/TerminalController.swift index 86fb02442..98e90e565 100644 --- a/macos/Sources/Features/Terminal/TerminalController.swift +++ b/macos/Sources/Features/Terminal/TerminalController.swift @@ -197,9 +197,10 @@ class TerminalController: NSWindowController, NSWindowDelegate, window.isOpaque = true window.backgroundColor = .windowBackgroundColor } - + window.hasShadow = ghostty.config.macosWindowShadow - + window.focusFollowsMouse = ghostty.config.focusFollowsMouse + guard window.hasStyledTabs else { return } // The titlebar is always updated. We don't need to worry about opacity diff --git a/macos/Sources/Features/Terminal/TerminalWindow.swift b/macos/Sources/Features/Terminal/TerminalWindow.swift index 9e4d3600e..2d54db321 100644 --- a/macos/Sources/Features/Terminal/TerminalWindow.swift +++ b/macos/Sources/Features/Terminal/TerminalWindow.swift @@ -369,6 +369,8 @@ class TerminalWindow: NSWindow { } } + var focusFollowsMouse: Bool = false + // Find the NSTextField responsible for displaying the titlebar's title. private var titlebarTextField: NSTextField? { guard let titlebarContainer = contentView?.superview?.subviews diff --git a/macos/Sources/Ghostty/SurfaceView_AppKit.swift b/macos/Sources/Ghostty/SurfaceView_AppKit.swift index a5347e1ad..3c5cd71ef 100644 --- a/macos/Sources/Ghostty/SurfaceView_AppKit.swift +++ b/macos/Sources/Ghostty/SurfaceView_AppKit.swift @@ -480,6 +480,10 @@ extension Ghostty { let pos = self.convert(event.locationInWindow, from: nil) ghostty_surface_mouse_pos(surface, pos.x, frame.height - pos.y) + guard let window = self.window as? TerminalWindow else { return } + if !self.focused && window.focusFollowsMouse { + Ghostty.moveFocus(to: self) + } } override func mouseDragged(with event: NSEvent) {