mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix: quick terminal focus-follows-mouse
behaviour
Quick Terminal now focuses on the surface under the mouse pointer when `focus-follows-mouse` is enabled. Fixes #3337
This commit is contained in:

committed by
Jonathan Lopez

parent
0d01dc366d
commit
bfbd043b59
@ -45,6 +45,11 @@ class BaseTerminalController: NSWindowController,
|
|||||||
didSet { surfaceTreeDidChange(from: oldValue, to: surfaceTree) }
|
didSet { surfaceTreeDidChange(from: oldValue, to: surfaceTree) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the terminal surface should focus when the mouse is over it.
|
||||||
|
var focusFollowsMouse: Bool {
|
||||||
|
self.derivedConfig.focusFollowsMouse
|
||||||
|
}
|
||||||
|
|
||||||
/// Non-nil when an alert is active so we don't overlap multiple.
|
/// Non-nil when an alert is active so we don't overlap multiple.
|
||||||
private var alert: NSAlert? = nil
|
private var alert: NSAlert? = nil
|
||||||
|
|
||||||
@ -262,7 +267,6 @@ class BaseTerminalController: NSWindowController,
|
|||||||
|
|
||||||
// Set the main window title
|
// Set the main window title
|
||||||
window.title = to
|
window.title = to
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pwdDidChange(to: URL?) {
|
func pwdDidChange(to: URL?) {
|
||||||
@ -604,15 +608,18 @@ class BaseTerminalController: NSWindowController,
|
|||||||
private struct DerivedConfig {
|
private struct DerivedConfig {
|
||||||
let macosTitlebarProxyIcon: Ghostty.MacOSTitlebarProxyIcon
|
let macosTitlebarProxyIcon: Ghostty.MacOSTitlebarProxyIcon
|
||||||
let windowStepResize: Bool
|
let windowStepResize: Bool
|
||||||
|
let focusFollowsMouse: Bool
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.macosTitlebarProxyIcon = .visible
|
self.macosTitlebarProxyIcon = .visible
|
||||||
self.windowStepResize = false
|
self.windowStepResize = false
|
||||||
|
self.focusFollowsMouse = false
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_ config: Ghostty.Config) {
|
init(_ config: Ghostty.Config) {
|
||||||
self.macosTitlebarProxyIcon = config.macosTitlebarProxyIcon
|
self.macosTitlebarProxyIcon = config.macosTitlebarProxyIcon
|
||||||
self.windowStepResize = config.windowStepResize
|
self.windowStepResize = config.windowStepResize
|
||||||
|
self.focusFollowsMouse = config.focusFollowsMouse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,6 @@ class TerminalController: BaseTerminalController {
|
|||||||
// Update our derived config
|
// Update our derived config
|
||||||
self.derivedConfig = DerivedConfig(config)
|
self.derivedConfig = DerivedConfig(config)
|
||||||
|
|
||||||
guard let window = window as? TerminalWindow else { return }
|
|
||||||
window.focusFollowsMouse = config.focusFollowsMouse
|
|
||||||
|
|
||||||
// If we have no surfaces in our window (is that possible?) then we update
|
// If we have no surfaces in our window (is that possible?) then we update
|
||||||
// our window appearance based on the root config. If we have surfaces, we
|
// our window appearance based on the root config. If we have surfaces, we
|
||||||
// don't call this because the TODO
|
// don't call this because the TODO
|
||||||
@ -422,8 +419,6 @@ class TerminalController: BaseTerminalController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.focusFollowsMouse = config.focusFollowsMouse
|
|
||||||
|
|
||||||
// Apply any additional appearance-related properties to the new window. We
|
// Apply any additional appearance-related properties to the new window. We
|
||||||
// apply this based on the root config but change it later based on surface
|
// apply this based on the root config but change it later based on surface
|
||||||
// config (see focused surface change callback).
|
// config (see focused surface change callback).
|
||||||
|
@ -414,8 +414,6 @@ class TerminalWindow: NSWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var focusFollowsMouse: Bool = false
|
|
||||||
|
|
||||||
// Find the NSTextField responsible for displaying the titlebar's title.
|
// Find the NSTextField responsible for displaying the titlebar's title.
|
||||||
private var titlebarTextField: NSTextField? {
|
private var titlebarTextField: NSTextField? {
|
||||||
guard let titlebarView = titlebarContainer?.subviews
|
guard let titlebarView = titlebarContainer?.subviews
|
||||||
|
@ -617,11 +617,12 @@ extension Ghostty {
|
|||||||
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
let mods = Ghostty.ghosttyMods(event.modifierFlags)
|
||||||
ghostty_surface_mouse_pos(surface, pos.x, frame.height - pos.y, mods)
|
ghostty_surface_mouse_pos(surface, pos.x, frame.height - pos.y, mods)
|
||||||
|
|
||||||
// If focus follows mouse is enabled then move focus to this surface.
|
// Handle focus-follows-mouse
|
||||||
if let window = self.window as? TerminalWindow,
|
if let window,
|
||||||
window.isKeyWindow &&
|
let controller = window.windowController as? BaseTerminalController,
|
||||||
window.focusFollowsMouse &&
|
(window.isKeyWindow &&
|
||||||
!self.focused
|
!self.focused &&
|
||||||
|
controller.focusFollowsMouse)
|
||||||
{
|
{
|
||||||
Ghostty.moveFocus(to: self)
|
Ghostty.moveFocus(to: self)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user