Merge pull request #1858 from SkamDart/focus-follows-mouse

feat: focus follows mouse for splits
This commit is contained in:
Mitchell Hashimoto
2024-06-18 17:09:54 -04:00
committed by GitHub
6 changed files with 39 additions and 3 deletions

View File

@ -111,6 +111,8 @@ class TerminalController: NSWindowController, NSWindowDelegate,
//MARK: - Methods //MARK: - Methods
func configDidReload() { func configDidReload() {
guard let window = window as? TerminalWindow else { return }
window.focusFollowsMouse = ghostty.config.focusFollowsMouse
syncAppearance() syncAppearance()
} }
@ -342,6 +344,8 @@ class TerminalController: NSWindowController, NSWindowDelegate,
} }
} }
window.focusFollowsMouse = ghostty.config.focusFollowsMouse
// Apply any additional appearance-related properties to the new window. // Apply any additional appearance-related properties to the new window.
syncAppearance() syncAppearance()
} }

View File

@ -369,6 +369,8 @@ 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 titlebarContainer = contentView?.superview?.subviews guard let titlebarContainer = contentView?.superview?.subviews

View File

@ -246,6 +246,14 @@ extension Ghostty {
return v return v
} }
var focusFollowsMouse : Bool {
guard let config = self.config else { return false }
var v = false;
let key = "focus-follows-mouse"
_ = ghostty_config_get(config, &v, key, UInt(key.count))
return v
}
var backgroundColor: Color { var backgroundColor: Color {
var rgb: UInt32 = 0 var rgb: UInt32 = 0
let bg_key = "background" let bg_key = "background"

View File

@ -480,6 +480,14 @@ extension Ghostty {
let pos = self.convert(event.locationInWindow, from: nil) let pos = self.convert(event.locationInWindow, from: nil)
ghostty_surface_mouse_pos(surface, pos.x, frame.height - pos.y) ghostty_surface_mouse_pos(surface, pos.x, frame.height - pos.y)
// If focus follows mouse is enabled then move focus to this surface.
if let window = self.window as? TerminalWindow,
window.isKeyWindow &&
window.focusFollowsMouse &&
!self.focused
{
Ghostty.moveFocus(to: self)
}
} }
override func mouseDragged(with event: NSEvent) { override func mouseDragged(with event: NSEvent) {

View File

@ -1204,6 +1204,12 @@ fn gtkMouseMotion(
.y = @floatCast(scaled.y), .y = @floatCast(scaled.y),
}; };
// If we don't have focus, and we want it, grab it.
const gl_widget = @as(*c.GtkWidget, @ptrCast(self.gl_area));
if (c.gtk_widget_has_focus(gl_widget) == 0 and self.app.config.@"focus-follows-mouse") {
self.grabFocus();
}
self.core_surface.cursorPosCallback(self.cursor_pos) catch |err| { self.core_surface.cursorPosCallback(self.cursor_pos) catch |err| {
log.err("error in cursor pos callback err={}", .{err}); log.err("error in cursor pos callback err={}", .{err});
return; return;

View File

@ -747,6 +747,14 @@ keybind: Keybinds = .{},
/// This configuration currently only works with GTK. /// This configuration currently only works with GTK.
@"window-new-tab-position": WindowNewTabPosition = .current, @"window-new-tab-position": WindowNewTabPosition = .current,
// If true, when there are multiple split panes, the mouse selects the pane
// that is focused. This only applies to the currently focused window; i.e.
// mousing over a split in an unfocused window will now focus that split
// and bring the window to front.
//
// Default is false.
@"focus-follows-mouse": bool = false,
/// When enabled, the full GTK titlebar is displayed instead of your window /// When enabled, the full GTK titlebar is displayed instead of your window
/// manager's simple titlebar. The behavior of this option will vary with your /// manager's simple titlebar. The behavior of this option will vary with your
/// window manager. /// window manager.