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

How to change workspace/monitor assignment when monitor configuration changes? #476

Closed
3 tasks done
ianjsikes opened this issue Aug 30, 2024 · 1 comment
Closed
3 tasks done

Comments

@ianjsikes
Copy link

On my work laptop, I commonly change between one of three display configurations:

  • Office (laptop and one large external monitor)
  • Home office (laptop closed, two large external monitors)
  • Coffee shop (laptop only)

What I would like to do is assign windows to workspaces (via on-window-detected), and then assign workspaces to monitors. So something like workspace-to-monitor-force-assignment seems like what I want, but I need the workspace<->monitor mapping to change dynamically based on which of these display configurations is active.

Is there currently a way to do this with AeroSpace? I previously had a working Yabai config that did this, but I can't use it due to my work laptop not allowing disabling SIP.

If this isn't currently supported, here is an idea of how it could work:

If aerospace move-workspace-to-monitor accepted identifiers for which workspace to move to which monitor, rather than relying solely on the current focus state, it would be easy to write a organize-workspaces.sh script. Something like this:

`organize-workspaces.sh`
#!/bin/bash

# These were obtained by plugging in the appropriate
# monitors and running `aerospace list-monitors | pbcopy`
LAPTOP_MODE='1 | Built-in Retina Display'
HOME_OFFICE_MODE='1 | DELL U2720Q
2 | DELL S2721DGF'
OFFICE_MODE='1 | Built-in Retina Display
2 | DELL U2720Q'

CURRENT_MODE="$(aerospace list-monitors)"

case $CURRENT_MODE in

$LAPTOP_MODE)
    # Don't need to do anything here because everything should auto-move to the only existing display
    ;;

$HOME_OFFICE_MODE)
    aerospace move-workspace-to-monitor --workspace "code" --monitor "DELL U2720Q"
    aerospace move-workspace-to-monitor --workspace "term" --monitor "DELL U2720Q"
    aerospace move-workspace-to-monitor --workspace "slack" --monitor "DELL S2721DGF"
    aerospace move-workspace-to-monitor --workspace "browse" --monitor "DELL S2721DGF"
    ;;

$OFFICE_MODE)
    aerospace move-workspace-to-monitor --workspace "code" --monitor "DELL U2720Q"
    aerospace move-workspace-to-monitor --workspace "term" --monitor "DELL U2720Q"
    aerospace move-workspace-to-monitor --workspace "slack" --monitor "Built-in Retina Display"
    aerospace move-workspace-to-monitor --workspace "browse" --monitor "Built-in Retina Display"
    ;;
esac
`aerospace.toml`
[[on-window-detected]]
check-further-callbacks = true
run = 'layout floating'

[[on-window-detected]]
if.app-id = 'com.microsoft.VSCode'
run = ['move-node-to-workspace code']

[[on-window-detected]]
if.app-id = 'com.github.wez.wezterm'
run = ['move-node-to-workspace term']

[[on-window-detected]]
if.app-id = 'com.google.Chrome'
run = ['move-node-to-workspace browse']

[[on-window-detected]]
if.app-id = 'com.tinyspeck.slackmacgap'
run = ['move-node-to-workspace slack']

[[on-window-detected]]
if.app-id = 'us.zoom.xos'
run = ['move-node-to-workspace zoom']

[[on-window-detected]]
if.app-id = 'org.mozilla.firefoxdeveloperedition'
run = ['move-node-to-workspace fun']

[[on-window-detected]]
if.app-id = 'com.anytype.anytype'
run = ['move-node-to-workspace notes']

And then I'd just need to either manually run this script when changing displays, which isn't too annoying, or figure out some way to automatically trigger it.

Checklist

aerospace CLI client version: 0.14.2-Beta 0cb8dbdfc5ee73b8cbc200f175f467ebead55201
AeroSpace.app server version: 0.14.2-Beta 0cb8dbdfc5ee73b8cbc200f175f467ebead55201
@nikitabobko
Copy link
Owner

(1) You can specify multiple patterns as an array in workspace-to-monitor-force-assignment. The first matching pattern will be used. If monitor is not presented, the pattern matches nothing. It's sufficient for some cases of different monitor configurations

If aerospace move-workspace-to-monitor accepted identifiers for which workspace to move to which monitor, rather than relying solely on the current focus state

(2) -> #186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants