Skip to content

Commit

Permalink
Routers and Filters (#1013)
Browse files Browse the repository at this point in the history
Adds a declarative way to specify routers and filters. This also includes fixes to the release deployment and docs generation.
  • Loading branch information
dalyIsaac authored Sep 9, 2024
1 parent 1a05ff9 commit 808369f
Show file tree
Hide file tree
Showing 12 changed files with 778 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docs_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ jobs:
run: |
dotnet tool restore
- name: Build schema
run: |
.\scripts\Generate-SourceFromSchema.ps1
- run: dotnet tool update -g docfx
- run: docfx docs/docfx.json

Expand Down
133 changes: 132 additions & 1 deletion docs/docs/customize/yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ To treat key modifiers like `LWin` and `RWin` the same, set `unify_key_modifiers
### Keybinds Example

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/dalyIsaac/Whim/main/src/Whim.Yaml/schema.json
keybinds:
entries:
- command: whim.core.focus_next_monitor
Expand All @@ -107,3 +106,135 @@ keybinds:

unify_key_modifiers: true
```
## Filters
By default, Whim ignores a built-in list of windows that are known to cause problems with dynamic tiling window manager. Behind the scenes, Whim automatically updates the built-in list of ignored windows based on a subset of the rules from the community-driven [collection of application rules](https://github.com/LGUG2Z/komorebi-application-specific-configuration) managed by komorebi.
### Custom Filtering Behavior
The filters configuration tells Whim to ignore windows that match the specified criteria.
You can filter windows by:
- `window_class`
- `process_file_name`
- `title`
- `title_regex`

### Window Class Filter

For example, to filter out Chromium windows with the class `Chrome_WidgetWin_1`, add the following to your configuration:

```yaml
filters:
entries:
- filter_type: window_class
value: Chrome_WidgetWin_1
```

### Process File Name Filter

For example, to filter out windows with the process file name `explorer.exe`, add the following to your configuration:

```yaml
filters:
entries:
- filter_type: process_file_name
value: explorer.exe
```

### Title Filter

For example, to filter out windows with the title `Untitled - Notepad`, add the following to your configuration:

```yaml
filters:
entries:
- filter_type: title
value: Untitled - Notepad
```

### Title Match Filter

For example, to filter out windows with the title that matches the regex `^Untitled - Notepad$`, add the following to your configuration:

```yaml
filters:
entries:
- filter_type: title_regex
value: ^Untitled - Notepad$
```

## Routers

The routers configuration tells Whim to route windows that match the specified criteria to the first workspace with name `workspace_name`.

### Default Routing Behavior

To customize the default window routing behavior, you can use the `routing_behavior` property. The default routing behavior is `route_to_launched_workspace`.

The available routing behaviors are:

- `route_to_launched_workspace`
- `route_to_active_workspace`
- `route_to_last_tracked_active_workspace`

### Custom Routing Behavior

You can also define custom routing behavior by specifying a list of routing entries. Each routing entry has a `router_type`, `value`, and `workspace_name`.

The available router types are:

- `window_class`
- `process_file_name`
- `title`
- `title_regex`

#### Window Class Router

For example, to route Chromium windows with the class `Chrome_WidgetWin_1` to the workspace `web`, add the following to your configuration:

```yaml
routers:
entries:
- router_type: window_class
value: Chrome_WidgetWin_1
workspace_name: web
```

#### Process File Name Router

For example, to route windows with the process file name `explorer.exe` to the workspace `file_explorer`, add the following to your configuration:

```yaml
routers:
entries:
- router_type: process_file_name
value: explorer.exe
workspace_name: file_explorer
```

#### Title Router

For example, to route windows with the title `Untitled - Notepad` to the workspace `notepad`, add the following to your configuration:

```yaml
routers:
entries:
- router_type: title
value: Untitled - Notepad
workspace_name: notepad
```

#### Title Match Router

For example, to route windows with the title that matches the regex `^Untitled - Notepad$` to the workspace `notepad`, add the following to your configuration:

```yaml
routers:
entries:
- router_type: title_regex
value: ^Untitled - Notepad$
workspace_name: notepad
```
54 changes: 53 additions & 1 deletion scripts/Generate-SourceFromSchema.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,63 @@ Write-Host "Generating source from schema..."

$schemaPath = ".\src\Whim.Yaml\schema.json"
$outputPath = ".\src\Whim.Yaml\Generated"
$metadataPath = "$outputPath\metadata.json"
$now = Get-Date
if ($env:CI) {
$gitSha = $env:GITHUB_SHA
}
else {
$gitSha = (git rev-parse HEAD)
}

New-Item $outputPath -ItemType Directory | Out-Null
function Test-Regenerate {
param (
[string]$schemaPath = ".\src\Whim.Yaml\schema.json",
[string]$outputPath = ".\src\Whim.Yaml\Generated"
)

if (!(Test-Path $outputPath)) {
Write-Host "Output directory does not exist, generating..."
New-Item $outputPath -ItemType Directory
return $true
}

Write-Host "Output directory exists..."

if ((Test-Path $schemaPath) -eq $false) {
Write-Host "Schema file does not exist, skipping..."
return $false
}

$metadata = Get-Content $metadataPath | ConvertFrom-Json
if ($metadata.gitRef -ne $gitSha) {
Write-Host "Git ref has changed since last generation, regenerating..."
return $true
}

$schemaLastWriteTime = (Get-Item $schemaPath).LastWriteTime
if ($metadata.lastWriteTime -lt $schemaLastWriteTime) {
Write-Host "Schema has changed since last generation, regenerating..."
return $true
}

Write-Host "Schema has not changed since last generation, skipping..."
return $false
}

if (!(Test-Regenerate -schemaPath $schemaPath -outputPath $outputPath)) {
Write-Host "Skipping generation..."
return
}

dotnet tool run generatejsonschematypes `
$schemaPath `
--rootNamespace Whim.Yaml `
--useSchema Draft7 `
--outputPath $outputPath

# If not in CI, write metadata file
if ($null -eq $env:CI) {
Write-Host "Writing metadata file..."
@{ gitRef = $gitSha; lastWriteTime = $now } | ConvertTo-Json | Set-Content $metadataPath
}
Loading

0 comments on commit 808369f

Please sign in to comment.