feat: show alttab on display with active menubar when needed (#2107)
closes #2107
This commit is contained in:
1 parent
bf905b1562
commit
917e661e88
2 files changed
+18
-5
No files matched your search
@@ -138,7 +138,7 @@ func CGSCopyWindowsWithOptionsAndTags(_ cid: CGSConnectionID, _ owner: Int, _ sp
|
||||
// returns the current space ID on the provided display UUID
|
||||
// * macOS 10.10+
|
||||
@_silgen_name("CGSManagedDisplayGetCurrentSpace")
|
||||
func CGSManagedDisplayGetCurrentSpace(_ cid: CGSConnectionID, _ displayUuid: CFString) -> CGSSpaceID
|
||||
func CGSManagedDisplayGetCurrentSpace(_ cid: CGSConnectionID, _ displayUuid: ScreenUuid) -> CGSSpaceID
|
||||
|
||||
// adds the provided windows to the provided spaces
|
||||
// * macOS 10.10-12.2
|
||||
@@ -251,6 +251,11 @@ func CGSSpaceGetType(_ cid: CGSConnectionID, _ sid: CGSSpaceID) -> CGSSpaceType
|
||||
@_silgen_name("CGSSpaceAddWindowsAndRemoveFromSpaces")
|
||||
func CGSSpaceAddWindowsAndRemoveFromSpaces(_ cid: CGSConnectionID, _ sid: CGSSpaceID, _ wid: NSArray, _ notSure: Int) -> Void
|
||||
|
||||
// get the display UUID with the active menubar (other menubar are dimmed)
|
||||
@_silgen_name("CGSCopyActiveMenuBarDisplayIdentifier")
|
||||
func CGSCopyActiveMenuBarDisplayIdentifier(_ cid: CGSConnectionID) -> ScreenUuid
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
// below are some notes on some private APIs I experimented with
|
||||
// ------------------------------------------------------------
|
||||
@@ -263,7 +268,7 @@ func CGSSpaceAddWindowsAndRemoveFromSpaces(_ cid: CGSConnectionID, _ sid: CGSSpa
|
||||
//// returns true if the current screen is animating
|
||||
//// useful to detect Spaces transitions, windows going fullscreen, etc
|
||||
//@_silgen_name("SLSManagedDisplayIsAnimating")
|
||||
//func SLSManagedDisplayIsAnimating(_ cid: CGSConnectionID, _ displayUuid: CFString) -> Bool
|
||||
//func SLSManagedDisplayIsAnimating(_ cid: CGSConnectionID, _ displayUuid: ScreenUuid) -> Bool
|
||||
|
||||
//@_silgen_name("CGSGetSymbolicHotKeyValue")
|
||||
//func CGSGetSymbolicHotKeyValue(_ hotKey: Int, _ options: inout UInt32, _ keyCode: inout UInt32, _ modifiers: inout UInt32) -> CGError
|
||||
|
||||
@@ -26,19 +26,27 @@ extension NSScreen {
|
||||
}
|
||||
|
||||
// NSScreen.main docs are incorrect. It stopped returning the screen with the key window in macOS 10.9
|
||||
|
||||
// see https://stackoverflow.com/a/56268826/2249756
|
||||
// There are a few cases where .main doesn't return the screen with the key window:
|
||||
// * if the active screen shows a fullscreen app, it always returns screens[0]
|
||||
// * if NSScreen.screensHaveSeparateSpaces == false, and key window is on another screen than screens[0], it still returns screens[0]
|
||||
// we find the screen with the key window ourselves manually
|
||||
static func active() -> NSScreen? {
|
||||
if let app = Applications.find(NSWorkspace.shared.frontmostApplication?.processIdentifier),
|
||||
let focusedWindow = app.focusedWindow {
|
||||
return NSScreen.screens.first { focusedWindow.isOnScreen($0) }
|
||||
if let app = Applications.find(NSWorkspace.shared.frontmostApplication?.processIdentifier) {
|
||||
if let focusedWindow = app.focusedWindow {
|
||||
return NSScreen.screens.first { focusedWindow.isOnScreen($0) }
|
||||
}
|
||||
return NSScreen.withActiveMenubar()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// there is only 1 active menubar. Other screens will show their menubar dimmed
|
||||
static func withActiveMenubar() -> NSScreen? {
|
||||
return NSScreen.screens.first { CGSCopyActiveMenuBarDisplayIdentifier(cgsMainConnectionId) == $0.uuid() }
|
||||
}
|
||||
|
||||
static func withMouse() -> NSScreen? {
|
||||
return NSScreen.screens.first { NSMouseInRect(NSEvent.mouseLocation, $0.frame, false) }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user