nikitabobko / AeroSpace

AeroSpace is an i3-like tiling window manager for macOS
https://nikitabobko.github.io/AeroSpace/guide
MIT License
7.19k stars 115 forks source link

Add command to programatically run all on-window-detected callbacks #107

Open carlosflorencio opened 10 months ago

carlosflorencio commented 10 months ago

Hi,

It's possible to have a command that runs all the on-window-detected callbacks?

Use-case: I have the apps <> workspaces affinities setup like:

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

[[on-window-detected]]
if.app-id = 'com.vivaldi.Vivaldi'
run = ['move-node-to-workspace 2']

...

Sometimes I move apps between workspaces and then have the need to reposition them back to the initial workspaces. So it would be useful to have a command like aerospace force-window-detected to run all the rules the move the windows back to their original workspace.

Also a different request/question, it's possible to assign layouts to workspaces in the config file? e.g workspace 1 to start with the h_accordion layout.

nikitabobko commented 10 months ago

So it would be useful to have a command like aerospace force-window-detected to run all the rules the move the windows back to their original workspace.

Nice. I like the suggestion. The hardest part here is to come up with a good name for the command

Brainstorming:

  1. force-window-detected (the suggested name)
  2. run-on-window-detected-callbacks
  3. force-run-on-window-detected-callbacks
  4. redetect-windows

Right now, 2 and 3 are my favorite. IMO, they are the most clear. Ideas are welcome

Also a different request/question, it's possible to assign layouts to workspaces in the config file? e.g workspace 1 to start with the h_accordion layout.

Right now. it's not possible, but probably it'd be nice to have. What is your use case?

I'm curious if it were possible to run layout command in on-window-detected callback, would it resolve your issue? (this way you will apply the layout only if the specific window is detected, but maybe it's exactly what you want to, I don't know your use cases)

The hardest part is to come up with a good syntax

Brainstorming:

# (a)
default-root-container-layout = 'tiles'
workspace.1.default-root-container-layout = 'tiles'

# (b)
[default-root-container-layout]
workspace.1 = 'tiles'
workspace.2 = 'accordion'
workspace.all = 'tiles' # 'all' will be a reserved name for workspaces since 0.8.0, anyway

# (c)
[default-root-container-layout]
workspace.1 = 'tiles'
workspace.2 = 'accordion'
other = 'tiles'
carlosflorencio commented 10 months ago

Regarding the command name, I think the second option is good: run-on-window-detected-callbacks!

Right now. it's not possible, but probably it'd be nice to have. What is your use case?

The use case is to fast switch maximised apps in the same workspace. E.g I like to have a workspace for IDEs where I have multiple instances (different folders/projects opened) and I like a stacked/accordion layout for that.

I'm curious if it were possible to run layout command in on-window-detected callback, would it resolve your issue?

Yes sort of, but when using different apps I would need a rule for each of them to set the layout. It feels more natural to set the layout at the workspace configuration level.

Regarding the syntax, I like your options (a) and (b). Another approach would be to set the layout also in callback style on-workspace-changed (https://github.com/nikitabobko/AeroSpace/issues/87):

[[on-workspace-changed]]
if.workspace-id = '1'
if.during-aerospace-startup = true  # only run this once
run = ['layout h_accordion']
GraemeARobinson commented 9 months ago

+1 for this feature request

nikitabobko commented 9 months ago

Also a different request/question, it's possible to assign layouts to workspaces in the config file? e.g workspace 1 to start with the h_accordion layout.

I just realized that it's already possible with after-startup-command

after-startup-command = [
    'workspace 1', 'layout h_accordion',
    'workspace 2', 'layout h_accordion'
]
carlosflorencio commented 9 months ago

@nikitabobko yeah nice catch. Just tested and works well :). Could be useful to have an example in the docs as a reminder.

quulah commented 3 months ago

I'm guessing this combined with after-startup-command might help with the issues I'm having with startup order.

Aerospace, among many other apps, starts automatically. Depending on the order, and I think when Aerospace starts up last, it won't move apps to workspaces nor tile them automatically.

I have to restart many of the applications that end up sadly floating around.

nikitabobko commented 3 months ago

it won't move apps to workspaces nor tile them automatically.

@quulah No, it shouldn't matter. Do you have if.during-aerospace-startup = false in your config by any chance?

quulah commented 3 months ago

Hmm. No, I don't have that. 🤔

My intention is to have a few workspaces with tiling and specific applications assigned to those, and then one without as a dump for everything else.

The config looks like this for (hopefully) the relevant bits:

start-at-login = true
after-startup-command = []
after-login-command = []
default-root-container-layout = 'tiles'
...
# Default - 1
[[on-window-detected]]
if.workspace = '1:default'
check-further-callbacks = true
run = 'layout floating'

[[on-window-detected]]
check-further-callbacks = true
run = 'move-node-to-workspace 1:default'

...

# Messaging - 4
[[on-window-detected]]
if.workspace = '4:messaging'
check-further-callbacks = true
run = 'layout tiling'

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

[[on-window-detected]]
if.app-id = 'com.microsoft.teams2'
run = 'move-node-to-workspace 4:messaging'

And it sort of works, except for the startup problem. Not sure if I'm doing something too funky. :)

If this seems like something that should work I can open another issue to track that.