Skip to content
This repository has been archived by the owner. It is now read-only.

[plugin|tiling] Support for moving spaces to different monitors #583

Closed
koekeishiya opened this issue Mar 10, 2019 · 9 comments

Comments

@koekeishiya
Copy link
Owner

commented Mar 10, 2019

As mentioned in #425 it is possible to move spaces between different monitors. I spent a couple of hours messing around and have a working proof of concept on macOS Mojave 10.14.3. This will require usage of chunkwm-sa.

@koekeishiya koekeishiya changed the title [chunkwm-sa] Support for moving spaces to different monitors [plugin|tiling] Support for moving spaces to different monitors Mar 10, 2019

koekeishiya added a commit that referenced this issue Apr 9, 2019
@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 9, 2019

Fixed on master.

@koekeishiya koekeishiya closed this Apr 9, 2019

@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 9, 2019

New command: chunkc tiling::desktop --move <index | prev | next>
index is 1-based.

koekeishiya added a commit that referenced this issue Apr 9, 2019
koekeishiya added a commit that referenced this issue Apr 9, 2019
@chipsenkbeil

This comment has been minimized.

Copy link

commented Apr 9, 2019

@koekeishiya, does the new command move the active space to the specified desktop? I've been trying to use it after rebuilding from head, but it just seems to shift focus to the specified monitor without moving any spaces. I've got chwm-sa installed and have been using it to focus desktops for awhile. I'm also on Mojave 10.14.3, which I'm assuming means I'm good with regard to the Mojave requirement.

@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

I haven't actually tested the full solution on 10.14.3, but in theory it should work yes. I had a working POC on 10.14.3 before I upgraded to 10.14.4 and finished the rest of it.

Try to open Console.app and filter on Dock, see if you see the following logs when chwm-sa is injected into the Dock:

NSLog(@"[chunkwm-sa] (0x%llx) dppm found at address 0x%llX (0x%llx)", baseaddr, dppm_addr, dppm_addr - baseaddr);

NSLog(@"[chunkwm-sa] (0x%llx) moveSpace found at address 0x%llX (0x%llx)", baseaddr, move_space_addr, move_space_addr - baseaddr);
@chipsenkbeil

This comment has been minimized.

Copy link

commented Apr 10, 2019

@koekeishiya, I'm not seeing that in the console. If I restart chunkwm, I see the following:

default	13:15:21.656603 -0500	chunkwm	warning: failed to get scripting definition from /System/Library/CoreServices/Dock.app; it may not be scriptable.
default	13:15:21.710658 -0500	Dock	[chunkwm-sa] injection begin
default	13:15:21.710841 -0500	Dock	[chunkwm-sa] payload has already been loaded!
default	13:15:21.710908 -0500	Dock	[chunkwm-sa] injection end

And occasionally I see some other logs like:

default	13:23:18.848575 -0500	Dock	notifyBestAppChanged:(null) UASuggestedActionType=0 <private>/<private> opts=(null) when=Wed Apr 10 13:23:18 2019 confidence=0 from=<private>/<private>

This is after I rebooted and ensured that I had recently run csrutils disabled and kept it disabled. I reran the injection via sudo chunkwm --install-sa and I've been able to use focusing desktops (with no animation). If I turn csrutils back on, the focusing desktops stops working, so I know it's enabled right now.

I reran brew install --HEAD chunkwm to regrab the latest just to make sure, and it grabbed commit 0493d5c and rebuilt everything again.

If I enable debug logging, running chunkc tiling::desktop --move 2 from monitor 1 on space 2 yields this output:

2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:35 DEBUG:     command: 'M', arg: '2'
2019-04-10 13:16:35 DEBUG: 10:desktop   1520:0:Console:Console (11 messages)
2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowTitleChanged'
2019-04-10 13:16:35 DEBUG: carbon: process details
Name: osascript
PID: 98908
PSN: 43604371 0
Policy: 2
Background: 1
2019-04-10 13:16:35 DEBUG: kitty:chipsenkbeil: chunkc tiling::desktop --move 2:1530 window title changed
2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowFocused'
2019-04-10 13:16:35 DEBUG: Console:Console (11 messages):1520 window focused
2019-04-10 13:16:35 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_ApplicationActivated'
2019-04-10 13:16:35 DEBUG: 62666:Console activated
2019-04-10 13:16:35 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_ApplicationDeactivated'
2019-04-10 13:16:35 DEBUG: 21346:kitty deactivated
2019-04-10 13:16:35 DEBUG: chunkwm: processing event of type 'ChunkWM_DisplayChanged'
2019-04-10 13:16:36 DEBUG: 10:desktop   1520:0:Console:Console (11 messages)
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_desktop_mode
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowTitleChanged'
2019-04-10 13:16:36 DEBUG: kitty:~:1530 window title changed
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'd', arg: 'mode'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'd', arg: 'mode'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'd', arg: 'id'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'd', arg: 'id'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'm', arg: 'id'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'm', arg: 'id'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'D', arg: '2'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginCommand'
2019-04-10 13:16:36 DEBUG:     command: 'D', arg: '2'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_ApplicationActivated'
2019-04-10 13:16:36 DEBUG: 21346:kitty activated
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_ApplicationDeactivated'
2019-04-10 13:16:36 DEBUG: 62666:Console deactivated
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowFocused'
2019-04-10 13:16:36 DEBUG: kitty:~:1530 window focused
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_DisplayChanged'
2019-04-10 13:16:36 DEBUG: 2:desktop   1530:0:kitty:~
2019-04-10 13:16:36 DEBUG: 2:desktop   1586:0:kitty:chipsenkbeil: tail -f /tmp/chunk.log
2019-04-10 13:16:36 DEBUG: 2:desktop   1527:0:kitty:dotfiles: nvim
2019-04-10 13:16:36 DEBUG: 2:desktop   432:0:Firefox:chunkwm/chunkwmrc at master · koekeishiya/chunkwm
2019-04-10 13:16:36 DEBUG: 2:desktop   1512:0:kitty:chipsenkbeil: brew edit chunkwm
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_desktop_mode
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: kitty:dotfiles: nvim:1527 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: Firefox:chunkwm/chunkwmrc at master · koekeishiya/chunkwm:432 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: kitty:~:1530 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: kitty:dotfiles: nvim:1527 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: Firefox:chunkwm/chunkwmrc at master · koekeishiya/chunkwm:432 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowMoved'
2019-04-10 13:16:36 DEBUG: kitty:~:1530 window moved
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_WindowFocused'
2019-04-10 13:16:36 DEBUG: kitty:chipsenkbeil: tail -f /tmp/chunk.log:1586 window focused
2019-04-10 13:16:36 DEBUG: chunkwm:Tiling:focused_window_float
2019-04-10 13:16:36 DEBUG: chunkwm: processing event of type 'ChunkWM_PluginBroadcast'
2019-04-10 13:16:37 DEBUG: carbon: process details

On monitor 1, I have an instance of Firefox and multiple instances of the kitty terminal running, so it seems like it thought it moved everything? But everything remained on monitor 1. I was on space 2, and eventually focus shifted to monitor 2 where it focused on the only existing space 10.

@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

default 13:15:21.710658 -0500 Dock [chunkwm-sa] injection begin
default 13:15:21.710841 -0500 Dock [chunkwm-sa] payload has already been loaded!
default 13:15:21.710908 -0500 Dock [chunkwm-sa] injection end

Try to stop chunkwm, pkill the Dock, then start chunkwm, and you should see the messages I mentioned, or something saying that pointer to whatever could not be located.

The command is supposed to move the active desktop to the specified monitor index, and make it the new focused desktop on the target monitor. Windows should be moved with and layout restored, upscaled to the new monitors resolution.

@chipsenkbeil

This comment has been minimized.

Copy link

commented Apr 10, 2019

@koekeishiya, that worked!

default	13:32:41.036189 -0500	chunkwm	warning: failed to get scripting definition from /System/Library/CoreServices/Dock.app; it may not be scriptable.
default	13:32:41.061869 -0500	Dock	        OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(ascr,gdut handler=0x7fff51a0c7a0 isSys=YES) err=0/noErr
default	13:32:41.103359 -0500	Dock	[chunkwm-sa] injection begin
default	13:32:41.108328 -0500	Dock	[chunkwm-sa] loaded payload
default	13:32:41.108562 -0500	Dock	[chunkwm-sa] (0x107cdd000) dock.spaces found at address 0x1081DDA10 (0x9c4d)
default	13:32:41.108678 -0500	Dock	[chunkwm-sa] (0x107cdd000) dppm found at address 0x1081DDAC0 (0x500ac0)
default	13:32:41.109029 -0500	Dock	[chunkwm-sa] (0x107cdd000) addSpace found at address 0x107F66390 (0x289390)
default	13:32:41.109246 -0500	Dock	[chunkwm-sa] (0x107cdd000) removeSpace found at address 0x108066EA0 (0x389ea0)
default	13:32:41.109537 -0500	Dock	[chunkwm-sa] (0x107cdd000) moveSpace found at address 0x108056800 (0x379800)
default	13:32:41.110133 -0500	Dock	[chunkwm-sa] failed to get pointer to setFrontWindow function..
default	13:32:41.110220 -0500	Dock	[chunkwm-sa] now listening on port 5050..
default	13:32:41.110475 -0500	Dock	[chunkwm-sa] injection end

It looks like everything is shifted right now when I do it, though. Is that expected? It makes sense to add the new space to the end of the existing spaces (I think?), but everything shifting is a little disorienting, especially since I label my spaces and intend to use 1 for dev, 2 for web, 3 for schedule, etc.

I guess this is where I could try to write a script to have a virtual mapping of spaces to the actual space locations. I wanted to try to use this feature to make chunkwm a little closer to i3's behavior when navigating between monitors so I don't need to remember or deal with key bindings for monitor traversal.

On monitor 1, I had spaces 1 through 6. On monitor 2, I had spaces 7 through 10.

monitor one
1 - kitty terminal of dotfiles and WhatPulse open
2 - Firefox open
3 - kitty terminal running ikhal open
4 - kitty terminal running neomutt open
5 - quip program open
6 - company chat open

monitor two
7 - console.app open
8 - kitty terminal that ran neofetch open
9 - keynote open
10 - terminal running newsboat open

if from space 1, I open a new terminal and run chunkc tiling::desktop --move 2, the new layout is

monitor one
1 - Firefox open
2 - kitty terminal running ikhal open
3 - kitty terminal running neomutt open
4 - quip program open
5 - company chat open

monitor two
6 - console.app open
7 - kitty terminal that ran neofetch open
8 - keynote open
9 - terminal running newsboat open
10 - kitty terminal of dotfiles and WhatPulse open


[EDIT] Oh, it looks like moving the space to another monitor tries to place it at the current space of that monitor. Didn't realize that, either.

So, if I had been on monitor 1 space 1 and run the command to send to monitor 2 which was on space 8, then it looks like it drops the results into space 8 and shifts everything from 8 to the left.

@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

It looks like everything is shifted right now when I do it, though. Is that expected? It makes sense to add the new space to the end of the existing spaces (I think?)

We move the space after the currently active space of the target monitor.

If you have 3 spaces on monitor1 and 5 spaces on monitor2. The active space of monitor2 is 3. When you move a space from monitor1 to monitor2, the moved space will become the new space4 on monitor2, and all the spaces behind it are shifted up by 1 desktop number. All the spaces before it will be shifted down by one number, the same way as if you had opened expose and dragged the space to reorder. This is due to how macOS enumerate desktops.

I guess this is where I could try to write a script to have a virtual mapping of spaces to the actual space locations. I wanted to try to use this feature to make chunkwm a little closer to i3's behavior when navigating between monitors so I don't need to remember or deal with key bindings for monitor traversal.

Spaces have a unique UUID internally that remain even after reordering. They also have an internal ID that remain through reordering, but they all get reset if you delete the space and create a new one.
We could utilize this to allow binding a name to a space, and we could allow the space focusing command to refer to these names. Not sure what the best system for mapping names to spaces would be though.

@koekeishiya

This comment has been minimized.

Copy link
Owner Author

commented Apr 10, 2019

@chipsenkbeil

Added #599 to keep track of the "naming spaces" suggestion + some more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants
You can’t perform that action at this time.