Skip to content

Commit

Permalink
Revive window grab space shifting
Browse files Browse the repository at this point in the history
  • Loading branch information
ianyh committed Nov 28, 2024
1 parent 88a2cd7 commit 2960183
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Amethyst.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 112;
CURRENT_PROJECT_VERSION = 113;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
Expand Down Expand Up @@ -1052,7 +1052,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 112;
CURRENT_PROJECT_VERSION = 113;
DEAD_CODE_STRIPPING = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 82P2XLB4UH;
Expand Down
24 changes: 4 additions & 20 deletions Amethyst/Managers/WindowManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -731,34 +731,18 @@ extension WindowManager: WindowTransitionTarget {
guard let targetScreen = CGSpacesInfo<Window>.screenForSpace(space: targetSpace) else {
return
}
if window.isFocused() {
if activeWindows(on: screen).count == 1,
let finder = NSWorkspace.shared.runningApplications.first(where: { $0.bundleIdentifier == "com.apple.finder" }) {
var psn = ProcessSerialNumber()
let status = GetProcessForPID(finder.processIdentifier, &psn)
if status != noErr {
log.error(status)
}
let cgStatus = _SLPSSetFrontProcessWithOptions(&psn, 0, kCPSNoWindows)
if cgStatus != .success {
log.error(cgStatus.rawValue)
}
} else {
focusTransitionCoordinator.moveFocusClockwise()
}
}
markScreen(screen, forReflowWithChange: .remove(window: window))
window.move(toSpace: targetSpace.id)
window.move(toSpaceAtIndex: UInt(spaceIndex + 1))
if targetScreen.screenID() != screen.screenID() {
// necessary to set frame here as window is expected to be at origin relative to targe screen when moved, can be improved.
let newFrame = targetScreen.frameWithoutDockOrMenu()
DispatchQueue.main.sync {
window.setFrame(newFrame, withThreshold: CGSize(width: 25, height: 25))
}
}
if UserConfiguration.shared.followWindowsThrownBetweenSpaces() {
window.focus()
}
// if UserConfiguration.shared.followWindowsThrownBetweenSpaces() {
// window.focus()
// }
markScreen(targetScreen, forReflowWithChange: .add(window: window))
case .resetFocus:
if let screen = screens.screenManagers.first?.screen {
Expand Down
83 changes: 49 additions & 34 deletions Amethyst/Model/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ protocol WindowType: Equatable {
*/
func move(toSpace space: UInt)
/**
Moves the window to the space at an index.
- Parameters:
- space: The index of the space
*/
func move(toSpaceAtIndex space: UInt)
/**
Moves the window to a space.
Expand Down Expand Up @@ -372,40 +380,47 @@ extension AXWindow: WindowType {
move(to: screen.screen)
}
func move(toSpace spaceID: CGSSpaceID) {
let osVersion = ProcessInfo.processInfo.operatingSystemVersion
if (osVersion.majorVersion >= 15) ||
(osVersion.majorVersion == 14 && osVersion.minorVersion >= 5) ||
(osVersion.majorVersion == 13 && osVersion.minorVersion >= 6) ||
(osVersion.majorVersion == 12 && osVersion.minorVersion >= 7) {
/*
See:
- https://github.com/ianyh/Amethyst/issues/1643
- https://github.com/ianyh/Amethyst/issues/1666
- https://github.com/koekeishiya/yabai/issues/2240
- https://github.com/koekeishiya/yabai/issues/2408
- https://github.com/koekeishiya/yabai/commit/98bbdbd1363f27d35f09338cded0de1ec010d830
- https://github.com/koekeishiya/yabai/commit/c8f913cbc0497d1dfe16138f40a8ba6ecaa744f8
*/
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
}
func move(toSpaceAtIndex space: UInt) {
super.move(toSpace: space)
}
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)
}
func move(toSpace spaceID: CGSSpaceID) {
}
// func move(toSpace spaceID: CGSSpaceID) {
// super.move(toSpace: spaceID)
// let osVersion = ProcessInfo.processInfo.operatingSystemVersion
// if (osVersion.majorVersion >= 15) ||
// (osVersion.majorVersion == 14 && osVersion.minorVersion >= 5) ||
// (osVersion.majorVersion == 13 && osVersion.minorVersion >= 6) ||
// (osVersion.majorVersion == 12 && osVersion.minorVersion >= 7) {
// /*
// See:
// - https://github.com/ianyh/Amethyst/issues/1643
// - https://github.com/ianyh/Amethyst/issues/1666
// - https://github.com/koekeishiya/yabai/issues/2240
// - https://github.com/koekeishiya/yabai/issues/2408
// - https://github.com/koekeishiya/yabai/commit/98bbdbd1363f27d35f09338cded0de1ec010d830
// - https://github.com/koekeishiya/yabai/commit/c8f913cbc0497d1dfe16138f40a8ba6ecaa744f8
// */
// 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)
// }
// }
}

0 comments on commit 2960183

Please sign in to comment.