Skip to content

Commit 381e64d

Browse files
committed
Merge branch 'feature/fix-widget-position-in-shared-space-mode' into develop
2 parents 6b13a60 + df1b05a commit 381e64d

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

Core/Sources/Preferences/Keys.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public struct UserDefaultPreferenceKeys {
124124
public var hideCommonPrecedingSpacesInSuggestion: HideCommonPrecedingSpacesInSuggestion {
125125
.init()
126126
}
127+
128+
public struct ForceOrderWidgetToFront: UserDefaultPreferenceKey {
129+
public let defaultValue = true
130+
public let key = "ForceOrderWidgetToFront"
131+
}
132+
133+
public var forceOrderWidgetToFront: HideCommonPrecedingSpacesInSuggestion {
134+
.init()
135+
}
127136

128137
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
129138
}

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,15 @@ extension SuggestionWidgetController {
315315
}
316316
317317
self.updateWindowLocation(animated: false)
318-
panelWindow.orderFront(nil)
319-
widgetWindow.orderFront(nil)
320-
tabWindow.orderFront(nil)
318+
319+
if UserDefaults.shared.value(for: \.forceOrderWidgetToFront)
320+
|| notification.name == kAXWindowMovedNotification
321+
{
322+
// We need to bring them front when the app enters fullscreen.
323+
panelWindow.orderFront(nil)
324+
widgetWindow.orderFront(nil)
325+
tabWindow.orderFront(nil)
326+
}
321327
}
322328
}
323329
}
@@ -389,8 +395,8 @@ extension SuggestionWidgetController {
389395
focusElement.description == "Source Editor",
390396
let parent = focusElement.parent,
391397
let frame = parent.rect,
392-
let screen = NSScreen.main,
393-
let firstScreen = NSScreen.screens.first
398+
let screen = NSScreen.screens.first(where: { $0.frame.origin == .zero }),
399+
let firstScreen = NSScreen.main
394400
{
395401
let mode = UserDefaults.shared.value(for: \.suggestionWidgetPositionMode)
396402
switch mode {

Core/Sources/SuggestionWidget/WidgetPositionStrategy.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ enum UpdateLocationStrategy {
3737
)
3838
}
3939
return HorizontalMovable().framesForWindows(
40-
y: activeScreen.frame.height - frame.maxY,
40+
y: mainScreen.frame.height - frame.maxY,
4141
alignPanelTopToAnchor: nil,
4242
editorFrame: editorFrame,
4343
mainScreen: mainScreen,
@@ -58,7 +58,7 @@ enum UpdateLocationStrategy {
5858
alignPanelTopToAnchor: Bool
5959
) {
6060
return HorizontalMovable().framesForWindows(
61-
y: activeScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
61+
y: mainScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
6262
alignPanelTopToAnchor: false,
6363
editorFrame: editorFrame,
6464
mainScreen: mainScreen,
@@ -82,13 +82,13 @@ enum UpdateLocationStrategy {
8282
) {
8383
let maxY = max(
8484
y,
85-
activeScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
86-
4 + mainScreen.frame.minY
85+
mainScreen.frame.height - editorFrame.maxY + Style.widgetPadding,
86+
4 + activeScreen.frame.minY
8787
)
8888
let y = min(
8989
maxY,
90-
mainScreen.frame.maxY - 4,
91-
activeScreen.frame.height - editorFrame.minY - Style.widgetHeight - Style
90+
activeScreen.frame.maxY - 4,
91+
mainScreen.frame.height - editorFrame.minY - Style.widgetHeight - Style
9292
.widgetPadding
9393
)
9494

@@ -101,7 +101,7 @@ enum UpdateLocationStrategy {
101101

102102
let proposedPanelX = proposedAnchorFrameOnTheRightSide.maxX + Style
103103
.widgetPadding * 2
104-
let putPanelToTheRight = mainScreen.frame.maxX > proposedPanelX + Style.panelWidth
104+
let putPanelToTheRight = activeScreen.frame.maxX > proposedPanelX + Style.panelWidth
105105
let alignPanelTopToAnchor = fixedAlignment ?? (y > activeScreen.frame.midY)
106106

107107
if putPanelToTheRight {
@@ -132,7 +132,7 @@ enum UpdateLocationStrategy {
132132
)
133133
let proposedPanelX = proposedAnchorFrameOnTheLeftSide.minX - Style
134134
.widgetPadding * 2 - Style.panelWidth
135-
let putAnchorToTheLeft = proposedPanelX > mainScreen.frame.minX
135+
let putAnchorToTheLeft = proposedPanelX > activeScreen.frame.minX
136136

137137
if putAnchorToTheLeft {
138138
let anchorFrame = proposedAnchorFrameOnTheLeftSide

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct WidgetContextMenu: View {
9494
@AppStorage(\.realtimeSuggestionToggle) var realtimeSuggestionToggle
9595
@AppStorage(\.acceptSuggestionWithAccessibilityAPI) var acceptSuggestionWithAccessibilityAPI
9696
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion) var hideCommonPrecedingSpacesInSuggestion
97+
@AppStorage(\.forceOrderWidgetToFront) var forceOrderWidgetToFront
9798

9899
var body: some View {
99100
Group {
@@ -133,6 +134,15 @@ struct WidgetContextMenu: View {
133134
}
134135
})
135136

137+
Button(action: {
138+
forceOrderWidgetToFront.toggle()
139+
}, label: {
140+
Text("Force Order Widget to Front")
141+
if forceOrderWidgetToFront {
142+
Image(systemName: "checkmark")
143+
}
144+
})
145+
136146
Divider()
137147

138148
Button(action: {

0 commit comments

Comments
 (0)