Skip to content

Commit 73382db

Browse files
Allsochenlwouis
authored andcommitted
feat: bring back the cursor follow focus feature (#3882)
1 parent 9bafd03 commit 73382db

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

resources/l10n/Localizable.strings

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@
151151
/* No comment provided by engineer. */
152152
"Crash reports policy" = "Crash reports policy";
153153

154+
/* No comment provided by engineer. */
155+
"Cursor follows focus" = "Cursor follows focus";
156+
154157
/* No comment provided by engineer. */
155158
"Customize App Icons style…" = "Customize App Icons style…";
156159

@@ -265,6 +268,9 @@
265268
/* No comment provided by engineer. */
266269
"Minimize/Deminimize window" = "Minimize/Deminimize window";
267270

271+
/* No comment provided by engineer. */
272+
"Miscellaneous" = "Miscellaneous";
273+
268274
/* No comment provided by engineer. */
269275
"Multiple screens" = "Multiple screens";
270276

src/logic/Preferences.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Preferences {
2626
"arrowKeysEnabled": "true",
2727
"vimKeysEnabled": "false",
2828
"mouseHoverEnabled": "false",
29+
"cursorFollowFocusEnabled": "false",
2930
"showMinimizedWindows": ShowHowPreference.show.indexAsString,
3031
"showMinimizedWindows2": ShowHowPreference.show.indexAsString,
3132
"showMinimizedWindows3": ShowHowPreference.show.indexAsString,
@@ -117,6 +118,7 @@ class Preferences {
117118
// periphery:ignore
118119
static var vimKeysEnabled: Bool { UserDefaults.standard.bool("vimKeysEnabled") }
119120
static var mouseHoverEnabled: Bool { UserDefaults.standard.bool("mouseHoverEnabled") }
121+
static var cursorFollowFocusEnabled: Bool { UserDefaults.standard.bool("cursorFollowFocusEnabled") }
120122
static var showTabsAsWindows: Bool { UserDefaults.standard.bool("showTabsAsWindows") }
121123
static var hideColoredCircles: Bool { UserDefaults.standard.bool("hideColoredCircles") }
122124
static var windowDisplayDelay: DispatchTimeInterval { DispatchTimeInterval.milliseconds(UserDefaults.standard.int("windowDisplayDelay")) }

src/ui/App.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,21 @@ class App: AppCenterApplication, NSApplicationDelegate {
234234
hideUi(true)
235235
if let window = selectedWindow, MissionControl.state() == .inactive {
236236
window.focus()
237+
if Preferences.cursorFollowFocusEnabled {
238+
moveCursorToSelectedWindow(window)
239+
}
237240
} else {
238241
previewPanel.orderOut(nil)
239242
}
240243
}
241244

245+
func moveCursorToSelectedWindow(_ window: Window) {
246+
let referenceWindow = window.referenceWindowForTabbedWindow()
247+
guard let position = referenceWindow?.position, let size = referenceWindow?.size else { return }
248+
let point = CGPoint(x: position.x + size.width / 2, y: position.y + size.height / 2)
249+
CGWarpMouseCursorPosition(point)
250+
}
251+
242252
func refreshOpenUi(_ windowsToUpdate: [Window]? = nil) {
243253
guard appIsBeingUsed else { return }
244254
let currentScreen = NSScreen.preferred() // fix screen between steps since it could change (e.g. mouse moved to another screen)

src/ui/preferences-window/tabs/controls/AdditionalControlsSheet.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,25 @@ class AdditionalControlsSheet: SheetWindow {
88
rightViews: [LabelAndControl.makeSwitch("vimKeysEnabled", extraAction: ControlsTab.vimKeysEnabledCallback)])
99
let enableMouse = TableGroupView.Row(leftTitle: NSLocalizedString("Select windows on mouse hover", comment: ""),
1010
rightViews: [LabelAndControl.makeSwitch("mouseHoverEnabled")])
11+
let enableCursorFollowFocus = TableGroupView.Row(leftTitle: NSLocalizedString("Cursor follows focus", comment: ""),
12+
rightViews: [LabelAndControl.makeSwitch("cursorFollowFocusEnabled")])
1113

1214
ControlsTab.arrowKeysCheckbox = enableArrows.rightViews[0] as? Switch
1315
ControlsTab.vimKeysCheckbox = enableVimKeys.rightViews[0] as? Switch
1416
ControlsTab.arrowKeysEnabledCallback(ControlsTab.arrowKeysCheckbox)
1517
ControlsTab.vimKeysEnabledCallback(ControlsTab.vimKeysCheckbox)
1618

17-
let table = TableGroupView(title: NSLocalizedString("Additional controls", comment: ""),
19+
let table1 = TableGroupView(title: NSLocalizedString("Additional controls", comment: ""),
1820
width: PreferencesWindow.width)
19-
_ = table.addRow(enableArrows)
20-
_ = table.addRow(enableVimKeys)
21-
_ = table.addRow(enableMouse)
22-
return table
21+
_ = table1.addRow(enableArrows)
22+
_ = table1.addRow(enableVimKeys)
23+
_ = table1.addRow(enableMouse)
24+
25+
let table2 = TableGroupView(title: NSLocalizedString("Miscellaneous", comment: ""),
26+
width: PreferencesWindow.width)
27+
_ = table2.addRow(enableCursorFollowFocus)
28+
29+
let view = TableGroupSetView(originalViews: [table1, table2], padding: 0)
30+
return view
2331
}
2432
}

0 commit comments

Comments
 (0)