Skip to content

fix and feat #4164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/logic/NSScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extension NSScreen {

static func updatePreferred() {
preferred = detectPreferred() ?? NSScreen.screens.first!
debugPrint("11111111",preferred)
}

private static func detectPreferred() -> NSScreen? {
Expand Down
1 change: 1 addition & 0 deletions src/logic/Spaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Spaces {
if let mainScreen = NSScreen.main,
let uuid = mainScreen.uuid() {
currentSpaceId = CGSManagedDisplayGetCurrentSpace(CGS_CONNECTION, uuid)
debugPrint("55|",currentSpaceId," ",mainScreen)
}
currentSpaceIndex = idsAndIndexes.first { (spaceId: CGSSpaceID, _) -> Bool in
spaceId == currentSpaceId
Expand Down
17 changes: 16 additions & 1 deletion src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Window {
var application: Application
var axObserver: AXObserver?
var rowIndex: Int?

var spaceIds = [UInt64]()
var isNormal = true

static let notifications = [
kAXUIElementDestroyedNotification,
Expand All @@ -36,10 +39,13 @@ class Window {
]

init(_ axUiElement: AXUIElement, _ application: Application, _ wid: CGWindowID, _ axTitle: String?, _ isFullscreen: Bool, _ isMinimized: Bool, _ position: CGPoint?, _ size: CGSize?) {
let subRole = try? axUiElement.subrole()
self.isNormal = subRole == "AXStandardWindow"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We alread check this in the isActualWindow method, which is used before calling this constructor. So I think rechecking here is not necessary.

Perhaps you saw something that I'm missing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method(isActualWindow) is not perfect, so use lark to open a metting window. There will be a forced front
and small meeting window in the upper right corner. It is meaningless to switch to this window.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isActualWindow checks if the window is reasonable to list in our switcher. It should be either a standard-window, or a dialog. It should have a title, a size bigger than a minimum size, etc.

Some apps are incorrectly coded, and they will end up having their windows either show up when they should't show up, or not show when they should show.

We've hard-coded some exceptions over the years. These days I don't want to hard-code any exception. It's on the broken apps to fix themselves. It's not on AltTab to add magic code to repair specific apps. Furthermore, these apps change quickly, so our workarounds may break things later.

It's definitely on the broken apps to fix themselves. Their broken code affects AltTab and it also affects other accessibility apps.

Here this lark is most likely having an issue. I suggest you report it to their support, so they get it fixed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact is that lark does not adapt to this software, but as a developer, I can understand your considerations. I accept it.

// TODO: make a efficient batched AXUIElementCopyMultipleAttributeValues call once for each window, and store the values
self.axUiElement = axUiElement
self.application = application
cgWindowId = wid
debugPrint("33init")
spaceId = Spaces.currentSpaceId
spaceIndex = Spaces.currentSpaceIndex
self.isFullscreen = isFullscreen
Expand Down Expand Up @@ -235,7 +241,16 @@ class Window {
func isOnScreen(_ screen: NSScreen) -> Bool {
if NSScreen.screensHaveSeparateSpaces {
if let screenUuid = screen.uuid(), let screenSpaces = Spaces.screenSpacesMap[screenUuid] {
return screenSpaces.contains { $0 == spaceId }
debugPrint("22|",spaceId,screen,screenSpaces,title!)
for v1 in screenSpaces {
for v2 in spaceIds {
if v1 == v2 {
return true
}
}
}
return false
// return screenSpaces.contains { $0 == spaceId }
}
} else {
let referenceWindow = referenceWindowForTabbedWindow()
Expand Down
17 changes: 15 additions & 2 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ class Windows {
// note: for some reason, it behaves differently if you minimize the tab group after moving it to another space
if let cgWindowId = window.cgWindowId {
let spaceIds = cgWindowId.spaces()
window.spaceIds = spaceIds
debugPrint("44|",window.cgWindowId!,spaceIds,window.spaceId,window.title!,Spaces.currentSpaceId)
if spaceIds.count == 1 {
window.spaceId = spaceIds.first!
window.spaceIndex = Spaces.idsAndIndexes.first { $0.0 == spaceIds.first! }!.1
Expand All @@ -298,6 +300,8 @@ class Windows {
window.spaceIndex = Spaces.currentSpaceIndex
window.isOnAllSpaces = true
}
debugPrint("44|",window.cgWindowId!,spaceIds,window.spaceId,window.title!)

}
}

Expand Down Expand Up @@ -345,14 +349,23 @@ class Windows {
}

private static func refreshIfWindowShouldBeShownToTheUser(_ window: Window) {
window.shouldShowTheUser =
var isSameApp = false
if let a = window.application.runningApplication.bundleIdentifier{
if let b = NSWorkspace.shared.frontmostApplication?.bundleIdentifier{
if a.contains(b) || b.contains(a) {
isSameApp = true
}
}
}
window.shouldShowTheUser = window.isNormal &&
Comment on lines +352 to +360
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please share why you added this check? Currently we compare the pid of the 2 apps. It seems it's not enough, and you added another check of bundleIds. Could you please share in which cases checking the pids was not working?

To my knowledge, every app has a pid, but not every app has a bundleID. So in that sense, checking pid should be broader, and sufficient.

Copy link
Author

@chenxiankong chenxiankong Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When some apps start windows, they may add a suffix to the bundle.
for example, main app`s bundle is com.bytedance.lark
if lark start a video chat window, the bundle may be com.bytedance.lark.video
these code want to fix it

you can use lark(https://www.larksuite.com/) and start a meeting window and test it

!(window.application.bundleIdentifier.flatMap { id in
Preferences.blacklist.contains {
id.hasPrefix($0.bundleIdentifier) &&
($0.hide == .always || (window.isWindowlessApp && $0.hide != .none))
}
} ?? false) &&
!(Preferences.appsToShow[App.app.shortcutIndex] == .active && window.application.pid != NSWorkspace.shared.frontmostApplication?.processIdentifier) &&
!(Preferences.appsToShow[App.app.shortcutIndex] == .active &&
(window.application.pid != NSWorkspace.shared.frontmostApplication?.processIdentifier && !isSameApp)) &&
!(!(Preferences.showHiddenWindows[App.app.shortcutIndex] != .hide) && window.isHidden) &&
((!Preferences.hideWindowlessApps && window.isWindowlessApp) ||
!window.isWindowlessApp &&
Expand Down