Skip to content
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

Apply yabai's fix for moving windows between spaces in macOS 14.5 #1648

Merged
merged 1 commit into from
May 28, 2024
Merged
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
3 changes: 2 additions & 1 deletion Amethyst.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "43f1b1e9bfd866a37b073557f24d496c85ab3a7508ae523528cda0c3afb30aa9",
"pins" : [
{
"identity" : "cartography",
Expand Down Expand Up @@ -127,5 +128,5 @@
}
}
],
"version" : 2
"version" : 3
}
36 changes: 34 additions & 2 deletions Amethyst/Model/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ func SLPSPostEventRecordTo(_ psn: inout ProcessSerialNumber, _ bytes: inout UInt
@_silgen_name("SLSMoveWindowsToManagedSpace")
func SLSMoveWindowsToManagedSpace(_ cid: Int32, _ window_ids: CFArray, _ sid: Int)

@_silgen_name("SLSSpaceSetCompatID")
func SLSSpaceSetCompatID(_ cid: Int32, _ sid: Int, _ workspace: Int32) -> CGError

@_silgen_name("SLSSetWindowListWorkspace")
func SLSSetWindowListWorkspace(_ cid: Int32, _ window_ids: UnsafePointer<UInt32>, _ window_count: Int32, _ workspace: Int32) -> CGError

let kCPSUserGenerated: UInt32 = 0x200
let kCPSNoWindows: UInt32 = 0x400
// swiftlint:enable identifier_name
Expand Down Expand Up @@ -292,7 +298,7 @@ extension AXWindow: WindowType {
What a mess. See: https://github.com/Hammerspoon/hammerspoon/issues/370#issuecomment-545545468
*/
@discardableResult override func focus() -> Bool {
var pid = self.pid()
let pid = self.pid()
var wid = self.cgID()
var psn = ProcessSerialNumber()
let status = GetProcessForPID(pid, &psn)
Expand Down Expand Up @@ -367,6 +373,32 @@ extension AXWindow: WindowType {
}

func move(toSpace spaceID: CGSSpaceID) {
SLSMoveWindowsToManagedSpace(CGSMainConnectionID(), [cgID()] as CFArray, spaceID)
if ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 14, minorVersion: 5, patchVersion: 0)) {
/*
See:
- https://github.com/ianyh/Amethyst/issues/1643
- https://github.com/koekeishiya/yabai/issues/2240
- https://github.com/koekeishiya/yabai/commit/98bbdbd1363f27d35f09338cded0de1ec010d830
*/
var error: CGError = .success

error = SLSSpaceSetCompatID(CGSMainConnectionID(), spaceID, 0x79616265)
defer { _ = SLSSpaceSetCompatID(CGSMainConnectionID(), spaceID, 0x0) }
guard error == .success else {
log.error("failed to set compat aside id: \(error)")
return
}

var id = cgID()
error = withUnsafeMutablePointer(to: &id, { pointer -> CGError in
return SLSSetWindowListWorkspace(CGSMainConnectionID(), pointer, 1, 0x79616265)
})
guard error == .success else {
log.error("failed to throw window: \(error)")
return
}
} else {
SLSMoveWindowsToManagedSpace(CGSMainConnectionID(), [cgID()] as CFArray, spaceID)
}
}
}
Loading