Skip to content

Commit 63c8239

Browse files
authored
fix moving window to space in sonoma (#3638)
1 parent 707e137 commit 63c8239

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

extensions/spaces/libspaces.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
#pragma mark - Support Functions and Classes
1414

15+
// https://github.com/koekeishiya/yabai/commit/7bacdd59bdf39b53012e024b442d61913095794e#diff-fab09245ac7f0bacbd4b3648bdd51eff6c41dc937f5dbaaf7459ff9ea70d3557R17-R27
16+
static bool workspace_is_macos_sonoma14_5_or_newer(void) {
17+
NSOperatingSystemVersion os_version = [[NSProcessInfo processInfo] operatingSystemVersion];
18+
if (os_version.majorVersion > 14) return true;
19+
if (os_version.majorVersion == 14 && os_version.minorVersion >= 5) return true;
20+
return false;
21+
}
22+
1523
#pragma mark - Module Functions
1624

1725
/// hs.spaces.screensHaveSeparateSpaces() -> bool
@@ -171,7 +179,15 @@ static int spaces_moveWindowToSpace(lua_State *L) { // NOTE: wrapped in init.lua
171179
CFRelease(spacesList);
172180
return 2 ;
173181
}
174-
SLSMoveWindowsToManagedSpace(g_connection, (__bridge CFArrayRef)windows, sid) ;
182+
183+
// https://github.com/koekeishiya/yabai/commit/98bbdbd1363f27d35f09338cded0de1ec010d830
184+
if (workspace_is_macos_sonoma14_5_or_newer()) {
185+
SLSSpaceSetCompatID(g_connection, sid, 0x79616265);
186+
SLSSetWindowListWorkspace(g_connection, &wid, 1, 0x79616265);
187+
SLSSpaceSetCompatID(g_connection, sid, 0x0);
188+
} else {
189+
SLSMoveWindowsToManagedSpace(g_connection, (__bridge CFArrayRef)windows, sid) ;
190+
}
175191
}
176192
lua_pushboolean(L, true) ;
177193
CFRelease(spacesList) ;

extensions/spaces/private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ extern CFArrayRef SLSCopyWindowsWithOptionsAndTags(int cid, uint32_t owner, CFAr
1313
extern void SLSMoveWindowsToManagedSpace(int cid, CFArrayRef window_list, uint64_t sid);
1414
extern CFArrayRef SLSCopySpacesForWindows(int cid, int selector, CFArrayRef window_list);
1515

16+
extern CGError SLSSpaceSetCompatID(int cid, uint64_t sid, int workspace);
17+
extern CGError SLSSetWindowListWorkspace(int cid, uint32_t *window_list, int window_count, int workspace);
1618
// extern uint64_t SLSManagedDisplayGetCurrentSpace(int cid, CFStringRef uuid) ;
1719
// extern CFStringRef SLSCopyManagedDisplayForSpace(int cid, uint64_t sid);
1820
// extern CFStringRef SLSSpaceCopyName(int cid, uint64_t sid);

extensions/spaces/spaces.lua

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@
1111
---
1212
--- It is recommended that you also enable "Displays have separate Spaces" in System Preferences -> Mission Control.
1313
---
14-
--- This module is a distillation of my previous `hs._asm.undocumented.spaces` module, changes inspired by reviewing the `Yabai` source, and some experimentation with `hs.axuielement`. If you require more sophisticated control, I encourage you to check out https://github.com/koekeishiya/yabai -- it does require some additional setup (changes to SIP, possibly edits to `sudoers`, etc.) but may be worth the extra steps for some power users.
15-
16-
-- TODO:
17-
-- does this work if "Displays have Separate Spaces" isn't checked in System Preferences ->
18-
-- Mission Control? What changes, and can we work around it?
19-
--
20-
-- need working hs.window.filter (or replacement) for pruning windows list and making use of other space windows
21-
22-
-- I think we're probably done with Yabai duplication -- basic functionality desired is present, minus window id pruning
23-
-- + yabai supports *some* stuff on M1 without injection... investigate
24-
-- * move window to space -- according to M1 tracking issue
25-
-- + ids of windows on other spaces -- partial; see hs.window.filter comment above
14+
--- Portions of this module are based on code and fixes discovered by the developers of Yabai (https://github.com/koekeishiya/yabai). This has been noted in the relevant places of the source code for this module if you wish more information. Yabai provides much functionality with regards to the manipulation of macOS Spaces and power users may want to consider utilizing Yabai as an adjunct to Hammerspoon.
2615

2716
local USERDATA_TAG = "hs.spaces"
2817
local module = require(table.concat({ USERDATA_TAG:match("^([%w%._]+%.)([%w_]+)$") }, "lib"))

0 commit comments

Comments
 (0)