Skip to content

Commit

Permalink
Set the window as main before activating the app
Browse files Browse the repository at this point in the history
_fixes #101
  • Loading branch information
nikitabobko committed Jun 1, 2024
1 parent b3ede59 commit 4701a5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions Sources/AppBundle/tree/MacWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ final class MacWindow: Window, CustomStringConvertible {
override var isMacosMinimized: Bool { axWindow.get(Ax.minimizedAttr) == true }

@discardableResult
override func nativeFocus() -> Bool { // todo make focus reliable: make async + active waiting
// Raise firstly to make sure that by that time we activate the app, particular window would be already on top
axWindow.raise() && macApp.nsApp.activate(options: .activateIgnoringOtherApps)
override func nativeFocus() -> Bool {
// Raise firstly to make sure that by the time we activate the app, the window would be already on top
axWindow.set(Ax.isMainAttr, true) &&
axWindow.raise() &&
macApp.nsApp.activate(options: .activateIgnoringOtherApps)
}

override func close() -> Bool {
Expand Down
5 changes: 3 additions & 2 deletions Sources/AppBundle/util/accessibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,10 @@ enum Ax {
key: kAXFocusedAttribute,
getter: { $0 as? Bool }
)
static let isMainAttr = ReadableAttrImpl<Bool>(
static let isMainAttr = WritableAttrImpl<Bool>(
key: kAXMainAttribute,
getter: { $0 as? Bool }
getter: { $0 as? Bool },
setter: { $0 as CFTypeRef }
)
static let sizeAttr = WritableAttrImpl<CGSize>(
key: kAXSizeAttribute,
Expand Down

0 comments on commit 4701a5c

Please sign in to comment.