mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Merge pull request #1858 from SkamDart/focus-follows-mouse
feat: focus follows mouse for splits
This commit is contained in:
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,9 +199,9 @@ class TerminalController: NSWindowController, NSWindowDelegate,
|
|||||||
window.isOpaque = true
|
window.isOpaque = true
|
||||||
window.backgroundColor = .windowBackgroundColor
|
window.backgroundColor = .windowBackgroundColor
|
||||||
}
|
}
|
||||||
|
|
||||||
window.hasShadow = ghostty.config.macosWindowShadow
|
window.hasShadow = ghostty.config.macosWindowShadow
|
||||||
|
|
||||||
guard window.hasStyledTabs else { return }
|
guard window.hasStyledTabs else { return }
|
||||||
|
|
||||||
// The titlebar is always updated. We don't need to worry about opacity
|
// The titlebar is always updated. We don't need to worry about opacity
|
||||||
@ -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()
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -245,7 +245,15 @@ extension Ghostty {
|
|||||||
_ = ghostty_config_get(config, &v, key, UInt(key.count))
|
_ = ghostty_config_get(config, &v, key, UInt(key.count))
|
||||||
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"
|
||||||
|
@ -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) {
|
||||||
|
@ -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;
|
||||||
|
@ -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.
|
||||||
|
Reference in New Issue
Block a user