Skip to content

Commit

Permalink
Support on-window-detected
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Nov 19, 2023
1 parent 2accc42 commit 0d2da42
Show file tree
Hide file tree
Showing 22 changed files with 554 additions and 82 deletions.
14 changes: 10 additions & 4 deletions AeroSpace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
1311398A83B998908773C54D /* FocusCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EAADE8D2FB5D05FA5456B0 /* FocusCommandTest.swift */; };
1C46EBB55D401C0D1AFD50F0 /* CollectionEx.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51CE37C1B8D858C81A396F40 /* CollectionEx.swift */; };
1FD8762CC7C132D01D4B3090 /* cliUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5EB6F0170422A7606D89BCF0 /* cliUtil.swift */; };
21D0512B48E0E3C28F8CA42A /* parseOnWindowDetected.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A9DFF8980BB3F90A3793BE9 /* parseOnWindowDetected.swift */; };
22175400298B985658E774EE /* ResizeCommandTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7ACD4E9C6C0C08F1B0622C57 /* ResizeCommandTest.swift */; };
238EF26CAAADD1FE11312D7C /* default-config.toml in Resources */ = {isa = PBXBuildFile; fileRef = 8FE45A887100EB70912B07F0 /* default-config.toml */; };
2821C1C7AAEF4C290633EA72 /* FullscreenCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ECC990B6C2D66D343216A12 /* FullscreenCommand.swift */; };
Expand Down Expand Up @@ -115,6 +116,7 @@
07A342893BEB5525BA1F8B74 /* ResultEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultEx.swift; sourceTree = "<group>"; };
083785CBAE36EC57F5F51BC8 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
09685297933511208058F7CF /* AeroSpace.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AeroSpace.app; sourceTree = BUILT_PRODUCTS_DIR; };
0A9DFF8980BB3F90A3793BE9 /* parseOnWindowDetected.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = parseOnWindowDetected.swift; sourceTree = "<group>"; };
0AEE5470AF418906B180A593 /* mouse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = mouse.swift; sourceTree = "<group>"; };
0D36D0F8EEB30A7BABC42343 /* LazySequenceProtocolEx.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LazySequenceProtocolEx.swift; sourceTree = "<group>"; };
0D9301F99737BE4888DBC2A3 /* FocusedWorkspaceSourceOfTruth.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FocusedWorkspaceSourceOfTruth.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -308,6 +310,7 @@
9752080BBA547C2A0EF076F0 /* Config.swift */,
1C0D40CBD65704BA9595C2FA /* keysMap.swift */,
67DBAF4ECF8A0B931FC34EAD /* parseConfig.swift */,
0A9DFF8980BB3F90A3793BE9 /* parseOnWindowDetected.swift */,
9164C9401F7DDCACE9278DA4 /* startAtLogin.swift */,
);
path = config;
Expand Down Expand Up @@ -656,6 +659,7 @@
B19980B36D066FD4947D2F92 /* normalizeContainers.swift in Sources */,
A5BFF75CF8021A585BC1F9D5 /* parseCommand.swift in Sources */,
A0765C31043BCFB0420BF1C9 /* parseConfig.swift in Sources */,
21D0512B48E0E3C28F8CA42A /* parseOnWindowDetected.swift in Sources */,
B3702BB393A9B03CCAE4C60E /* refresh.swift in Sources */,
8086A22EDCDC4C906C337D0B /* resizeWithMouse.swift in Sources */,
43E3628E37D2439B820FFC82 /* server.swift in Sources */,
Expand Down Expand Up @@ -750,7 +754,7 @@
MACOSX_DEPLOYMENT_TARGET = 13.0;
PRODUCT_NAME = "aerospace-debug";
SDKROOT = macosx;
SWIFT_VERSION = 5.8;
SWIFT_VERSION = 5.9;
};
name = Debug;
};
Expand All @@ -770,7 +774,7 @@
PRODUCT_BUNDLE_IDENTIFIER = bobko.aerospace.cli;
PRODUCT_NAME = aerospace;
SDKROOT = macosx;
SWIFT_VERSION = 5.8;
SWIFT_VERSION = 5.9;
};
name = Release;
};
Expand All @@ -794,7 +798,7 @@
PRODUCT_NAME = "AeroSpace-Debug";
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "src/Bridged-Header.h";
SWIFT_VERSION = 5.8;
SWIFT_VERSION = 5.9;
};
name = Debug;
};
Expand Down Expand Up @@ -865,6 +869,7 @@
"@loader_path/../Frameworks",
);
SDKROOT = macosx;
SWIFT_VERSION = 5.9;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AeroSpace-Debug.app/Contents/MacOS/AeroSpace-Debug";
};
name = Release;
Expand All @@ -881,6 +886,7 @@
"@loader_path/../Frameworks",
);
SDKROOT = macosx;
SWIFT_VERSION = 5.9;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AeroSpace-Debug.app/Contents/MacOS/AeroSpace-Debug";
};
name = Debug;
Expand Down Expand Up @@ -908,7 +914,7 @@
PRODUCT_NAME = AeroSpace;
SDKROOT = macosx;
SWIFT_OBJC_BRIDGING_HEADER = "src/Bridged-Header.h";
SWIFT_VERSION = 5.8;
SWIFT_VERSION = 5.9;
};
name = Release;
};
Expand Down
15 changes: 9 additions & 6 deletions config-examples/default-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ indent-for-nested-containers-with-the-same-orientation = 30
# Start AeroSpace at login
start-at-login = false

# Normalization. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#normalization
# Normalizations. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#normalization
enable-normalization-flatten-containers = true
enable-normalization-opposite-orientation-for-nested-containers = true

Expand Down Expand Up @@ -50,7 +50,12 @@ default-root-container-orientation = 'auto'
# workspace_name_5 = '^built-in retina display$' # Case insensitive regex match
# workspace_name_6 = ['secondary', 'dell'] # You can specify multiple patterns. The first matching pattern will be used

# It's a declaration of 'main' binding mode. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
# See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#on-window-detected-callback
# [[on-window-detected]]
# appId = 'com.apple.systempreferences' # Application ID match
# run = ['move-node-to-workspace S', 'layout floating'] # The callback itself

# 'main' binding mode declaration. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
# 'main' binding mode must be always presented
[mode.main.binding]

Expand Down Expand Up @@ -158,20 +163,18 @@ alt-shift-tab = 'move-workspace-to-monitor next'
alt-shift-semicolon = 'mode service'
alt-shift-slash = 'mode join'

# It's a declaration of binding mode. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
# 'service' binding mode declaration. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
[mode.service.binding]
r = ['flatten-workspace-tree', 'mode main'] # reset layout
#s = ['layout sticky tiling', 'mode main'] # sticky is not yet supported https://github.com/nikitabobko/AeroSpace/issues/2
f = ['layout floating tiling', 'mode main'] # Toggle between floating and tiling layout
backspace = ['close-all-windows-but-current', 'mode main']
esc = 'mode main'
enter = 'mode main'

# It's a declaration of binding mode. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
# 'join' binding mode declaration. See: https://github.com/nikitabobko/AeroSpace/blob/main/docs/guide.md#bindings-modes
[mode.join.binding]
alt-shift-h = ['join-with left', 'mode main']
alt-shift-j = ['join-with down', 'mode main']
alt-shift-k = ['join-with up', 'mode main']
alt-shift-l = ['join-with right', 'mode main']
esc = ['reload-config', 'mode main']
enter = 'mode main'
10 changes: 5 additions & 5 deletions docs/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ In addition to [regular commands](./commands.md), the CLI provides commands list
list-apps
```

- Available since: 0.6.0-Beta

Prints the list of ordinary applications that appears in the Dock and may have a user interface.

Output format is the table with the following colums:
Expand All @@ -31,6 +29,9 @@ Output example:

The command is useful to inspect list of applications to compose filter for [`on-window-detected`](./guide.md#on-window-detected-callback)

> - Available since: 0.6.0-Beta
> - The command doesn't have arguments
## version

```
Expand All @@ -39,8 +40,7 @@ version
-v
```

- Available since: 0.4.0-Beta

Prints the version and commit hash to stdout

This command doesn't have any arguments
> - Available since: 0.4.0-Beta
> - The command doesn't have arguments
18 changes: 10 additions & 8 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ Commands listed in this file can be used in the config and CLI
close-all-windows-but-current
```

On the focused workspace, closes all windows but current. This command doesn't have any arguments.
On the focused workspace, closes all windows but current.

> - The command doesn't have arguments.
## enable

Expand All @@ -42,7 +44,7 @@ When you disable AeroSpace, windows from currently invisible workspaces will be

Key events are not intercepted when AeroSpace is disabled

- Available since: 0.5.0-Beta
> - Available since: 0.5.0-Beta
## exec-and-forget

Expand Down Expand Up @@ -84,7 +86,7 @@ Flattens [the tree](./guide.md#tree) of currently focused workspace.

The command is useful when you messed up with your layout, and it's easier to "reset" it and start again.

- This command doesn't have any arguments.
> - The command doesn't have arguments.
## focus

Expand Down Expand Up @@ -115,8 +117,8 @@ Toggles the fullscreen mode for the currently focused window.
Switching to a different window within the same workspace while the current focused window is in fullscreen mode results
in the fullscreen window exiting fullscreen mode.

- This command doesn't have any arguments.
- Available since: 0.3.0-Beta
> - Available since: 0.3.0-Beta
> - The command doesn't have arguments.
## join-with

Expand Down Expand Up @@ -291,7 +293,7 @@ reload-config

Reloads currently active config.

- This command doesn't have any arguments.
> - The command doesn't have arguments.
## resize

Expand Down Expand Up @@ -335,7 +337,7 @@ orientation of the parent container
> `split` command does nothing if `enable-normalization-flatten-containers` is turned on. Consider using `join-with` if you want
> to keep `enable-normalization-flatten-containers` enabled
- Available since: 0.3.0-Beta
> - Available since: 0.3.0-Beta
## workspace-back-and-forth

Expand All @@ -345,7 +347,7 @@ workspace-back-and-forth

Switches between currently active workspace and previously active workspace back and forth.

- This command doesn't have any arguments.
> - The command doesn't have arguments.
## workspace

Expand Down
54 changes: 52 additions & 2 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Emulation of virtual workspaces](#emulation-of-virtual-workspaces)
- [A note on mission control](#a-note-on-mission-control)
- [A note on 'Displays have separate Spaces'](#a-note-on-displays-have-separate-spaces)
- ['on-window-detected' callback](#on-window-detected-callback)
- [Multiple monitors](#multiple-monitors)
- [Assign workspaces to monitors](#assign-workspaces-to-monitors)

Expand Down Expand Up @@ -225,6 +226,55 @@ Overview of 'Displays have separate Spaces'
| Is it possible for window to span across several monitors? | 😔 No | 😊 Yes |
| macOS status bar ... | ... is displayed on both monitors | ... is displayed only on main monitor |

## 'on-window-detected' callback

> - Available since: 0.6.0-Beta
You can use `on-window-detected` callback to run commands that run on new window detection.

```toml
[[on-window-detected]]
app-id = 'com.apple.systempreferences' # Application ID match
app-name-regex-substring = 'settings' # Case insensetive regex substring
window-title-regex-substring = 'substring' # Case insensetive regex substring
run = ['move-node-to-workspace S', 'layout floating'] # The callback itself
```

> [!IMPORTANT]
> Some windows initialize their title after window initialization. `window-title-regex-substring` may not work as expected
> for such windows
Examples of automations:

- Assign apps on particular workspaces
```toml
[[on-window-detected]]
app-id = 'org.alacritty'
run = 'move-node-to-workspace T' # mnemonics 'Terminal'

[[on-window-detected]]
app-id = 'com.google.Chrome'
run = 'move-node-to-workspace W' # mnemonics 'Web browser'

[[on-window-detected]]
app-id = 'com.jetbrains.intellij'
run = 'move-node-to-workspace I' # mnemonics 'Ide'
```
- Make all windows float by default
```toml
[[on-window-detected]]
run = 'layout floating'
```
- Float 'System Settings' app
```toml
[[on-window-detected]]
app-id = 'com.apple.systempreferences'
run = 'layout floating'
```

See the [list of popular application IDs](./popular-apps-ids.md), or you can
use [`aerospace list-apps`](./cli-commands.md#list-apps) CLI command to get IDs of running applications

## Multiple monitors

- The pool of workspaces is shared between monitors
Expand Down Expand Up @@ -252,6 +302,8 @@ monitor often makes sense.
### Assign workspaces to monitors

> - Available since: 0.5.0-Beta
You can use `workspace-to-monitor-force-assignment` syntax to assign workspaces to always appear on particular monitors

```toml
Expand All @@ -273,5 +325,3 @@ Supported monitor patterns:
You can specify multiple patterns as an array. The first matching pattern will be used

[`move-workspace-to-monitor`](./commands.md#move-workspace-to-monitor) command has no effect for workspaces that have monitor assignment

- Available since: 0.5.0-Beta
89 changes: 89 additions & 0 deletions docs/popular-apps-ids.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
= List of popular and built-in applications IDs

The list is useful to compose custom xref:guide.md#on-window-detected-callback[`+on-window-detected+` callback]

[cols="2,3"]
|===

|1Password|`com.1password.1password`
|Activity Monitor|`com.apple.ActivityMonitor`
|AirPort Utility|`com.apple.airport.airportutility`
|Alacritty|`org.alacritty`
|Android Studio|`com.google.android.studio`
|App Store|`com.apple.AppStore`
|AppCode|`com.jetbrains.AppCode`
|Arc Browser|`company.thebrowser.Browser`
|Audio MIDI Setup|`com.apple.audio.AudioMIDISetup`
|Automator|`com.apple.Automator`
|Battle.net|`net.battle.app`
|Books|`com.apple.iBooksX`
|CLion|`com.jetbrains.CLion`
|Calculator|`com.apple.calculator`
|Calendar|`com.apple.iCal`
|Chess|`com.apple.Chess`
|Clock|`com.apple.clock`
|ColorSync Utility|`com.apple.ColorSyncUtility`
|Console|`com.apple.Console`
|Contacts|`com.apple.AddressBook`
|Dictionary|`com.apple.Dictionary`
|Disk Utility|`com.apple.DiskUtility`
|Docker|`com.docker.docker`
|FaceTime|`com.apple.FaceTime`
|Find My|`com.apple.findmy`
|Finder|`com.apple.finder`
|Firefox|`org.mozilla.firefox`
|Freeform|`com.apple.freeform`
|GIMP|`org.gimp.gimp-2.10`
|Google Chrome|`com.google.Chrome`
|Grapher|`com.apple.grapher`
|Home|`com.apple.Home`
|Inkscape|`org.inkscape.Inkscape`
|IntelliJ IDEA Community|`com.jetbrains.intellij.ce`
|IntelliJ IDEA Ultimate|`com.jetbrains.intellij`
|Karabiner-Elements|`org.pqrs.Karabiner-Elements.Settings`
|Keychain Access|`com.apple.keychainaccess`
|Keynote|`com.apple.iWork.Keynote`
|Kitty|`net.kovidgoyal.kitty`
|Mail|`com.apple.mail`
|Maps|`com.apple.Maps`
|Marta|`org.yanex.marta`
|Messages|`com.apple.MobileSMS`
|Music|`com.apple.Music`
|Notes|`com.apple.Notes`
|Pages|`com.apple.iWork.Pages`
|Photo Booth|`com.apple.PhotoBooth`
|Photos|`com.apple.Photos`
|Podcasts|`com.apple.podcasts`
|Preview|`com.apple.Preview`
|PyCharm Community|`com.jetbrains.pycharm.ce`
|PyCharm Professional|`com.jetbrains.pycharm`
|QuickTime Player|`com.apple.QuickTimePlayerX`
|Reminders|`com.apple.reminders`
|Safari|`com.apple.Safari`
|Shortcuts|`com.apple.shortcuts`
|Slack|`com.tinyspeck.slackmacgap`
|Spotify|`com.spotify.client`
|Steam|`com.valvesoftware.steam`
|Stocks|`com.apple.stocks`
|Sublime Merge|`com.sublimemerge`
|Sublime Text|`com.sublimetext.4`
|System Settings|`com.apple.systempreferences`
|TV|`com.apple.TV`
|Telegram|`com.tdesktop.Telegram`
|Terminal|`com.apple.Terminal`
|TextEdit|`com.apple.TextEdit`
|Thunderbird|`org.mozilla.thunderbird`
|Time Machine|`com.apple.backup.launcher`
|Tor Browser|`org.torproject.torbrowser`
|Transmission|`org.m0k.transmission`
|VLC|`org.videolan.vlc`
|Visual Studio Code|`com.microsoft.VSCode`
|VoiceMemos|`com.apple.VoiceMemos`
|VoiceOver Utility|`com.apple.VoiceOverUtility`
|Weather|`com.apple.weather`
|Xcode|`com.apple.dt.Xcode`
|iMovie|`com.apple.iMovieApp`
|iTerm2|`com.googlecode.iterm2`
|kdenlive|`org.kde.Kdenlive`

|===
Loading

0 comments on commit 0d2da42

Please sign in to comment.