Skip to content

Commit

Permalink
JSON config for keybinds (#1011)
Browse files Browse the repository at this point in the history
Adds a declarative way to specify keybinds in Whim. This required some updates to handle string parsing of keybinds. 

There is brief documentation on usage in the `Customize` section of the docs.
  • Loading branch information
dalyIsaac authored Sep 8, 2024
1 parent b57db6a commit e3eab8e
Show file tree
Hide file tree
Showing 28 changed files with 1,304 additions and 270 deletions.
16 changes: 13 additions & 3 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@
"version": "3.2404.2",
"commands": [
"xstyler"
]
],
"rollForward": false
},
"csharpier": {
"version": "0.29.1",
"commands": [
"dotnet-csharpier"
]
],
"rollForward": false
},
"docfx": {
"version": "2.77.0",
"commands": [
"docfx"
]
],
"rollForward": false
},
"corvus.json.jsonschema.typegeneratortool": {
"version": "3.1.1",
"commands": [
"generatejsonschematypes"
],
"rollForward": false
}
}
}
4 changes: 4 additions & 0 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Build schema
run: |
.\scripts\Generate-SourceFromSchema.ps1
- name: Build
run: |
msbuild Whim.sln `
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/docs_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ jobs:
run: |
dotnet tool restore
- name: Build schema
run: |
.\scripts\Generate-SourceFromSchema.ps1
- name: Run docfx
run: dotnet docfx .\docs\docfx.json
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Build schema
run: |
.\scripts\Generate-SourceFromSchema.ps1
- name: Build
run: |
msbuild Whim.sln `
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -361,3 +361,6 @@ bin/whim-install.exe
# docfx
api
_site

# Whim.Yaml generated files
src/Whim.Yaml/Generated/
3 changes: 3 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Corvus.Json.ExtendedTypes" Version="3.1.1" />
<PackageVersion Include="DotNext" Version="5.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Scripting" Version="4.10.0" />
<PackageVersion Include="Microsoft.Win32.SystemEvents" Version="8.0.0" />
Expand All @@ -15,6 +16,8 @@
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.7" />
<PackageVersion Include="Yaml2JsonNode" Version="2.1.1" />
<PackageVersion Include="YamlDotNet" Version="16.1.0" />
</ItemGroup>
<!-- Test dependencies -->
<ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions Whim.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Updater", "src\Whim.Up
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Updater.Tests", "src\Whim.Updater.Tests\Whim.Updater.Tests.csproj", "{741677F5-5C83-474E-83B7-08F7A84DE11D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Yaml", "src\Whim.Yaml\Whim.Yaml.csproj", "{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Whim.Yaml.Tests", "src\Whim.Yaml.Tests\Whim.Yaml.Tests.csproj", "{9FCA57D6-246D-45CE-AA45-76658EFF849C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -387,6 +391,30 @@ Global
{741677F5-5C83-474E-83B7-08F7A84DE11D}.Release|arm64.Build.0 = Release|arm64
{741677F5-5C83-474E-83B7-08F7A84DE11D}.Release|x64.ActiveCfg = Release|x64
{741677F5-5C83-474E-83B7-08F7A84DE11D}.Release|x64.Build.0 = Release|x64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|arm64.ActiveCfg = Debug|arm64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|arm64.Build.0 = Debug|arm64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|x64.ActiveCfg = Debug|x64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Debug|x64.Build.0 = Debug|x64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|Any CPU.Build.0 = Release|Any CPU
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|arm64.ActiveCfg = Release|arm64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|arm64.Build.0 = Release|arm64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|x64.ActiveCfg = Release|x64
{87B4F4D9-352D-46F5-920F-262E2D7FC7FC}.Release|x64.Build.0 = Release|x64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|arm64.ActiveCfg = Debug|arm64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|arm64.Build.0 = Debug|arm64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|x64.ActiveCfg = Debug|x64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Debug|x64.Build.0 = Debug|x64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|Any CPU.Build.0 = Release|Any CPU
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|arm64.ActiveCfg = Release|arm64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|arm64.Build.0 = Release|arm64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|x64.ActiveCfg = Release|x64
{9FCA57D6-246D-45CE-AA45-76658EFF849C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
109 changes: 109 additions & 0 deletions docs/docs/customize/yaml.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# YAML Configuration (WIP)

Whim is in the process of adding YAML configuration support - this is being tracked in [#1009](https://github.com/dalyIsaac/Whim/issues/1009). This has been implemented in the `Whim.Yaml` plugin.

## Setup

Whim looks for a `whim.config.yaml` or `whim.config.json` file in the root of your `.whim` directory. If it finds one, it will use that file to configure Whim.

Add to your `whim.config.csx`:

```csharp
// ...previous references
// NOTE: Replace WHIM_PATH with the path to your Whim installation
#r "WHIM_PATH\plugins\Whim.Yaml\Whim.Yaml.dll"

using System;
// ...usings...
using Whim.Yaml;

// ...
void DoConfig(IContext context)
{
// Make sure to place this at the top of your config
YamlLoader.Load(context);
}
```

## Schema

The schema for the YAML and JSON configuration is available [here](https://raw.githubusercontent.com/dalyIsaac/Whim/main/src/Whim.Yaml/schema.json).

To use the schema in your YAML file, add the following line at the top of your file:

```yaml
# yaml-language-server: $schema=https://raw.githubusercontent.com/dalyIsaac/Whim/main/src/Whim.Yaml/schema.json
```

To use the schema in your JSON file, add the following line at the top of your file:

```json
{
"$schema": "https://raw.githubusercontent.com/dalyIsaac/Whim/main/src/Whim.Yaml/schema.json",
...
}
```

## Keybinds

The keybinds configuration has a list of bindings that you can use to bind commands to key combinations.

### Bindings

A key modifier is a key that is pressed in combination with another key to perform a specific action. The `bindings` property is a list of keybinds that map a command to a key combination.

Key modifiers can be any of the following:

- `Ctrl`
- `Control`
- `LCtrl`
- `LControl`
- `RCtrl`
- `RControl`
- `Shift`
- `LShift`
- `RShift`
- `Alt`
- `LAlt`
- `RAlt`
- `Win`
- `LWin`
- `RWin`

The associated key for each modifier can be any of the <xref:Windows.Win32.UI.Input.KeyboardAndMouse.VIRTUAL_KEY>s.

### Unify Key Modifiers

To treat key modifiers like `LWin` and `RWin` the same, set `unify_key_modifiers` to `true`.

### 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
keybind: LCtrl+LShift+LAlt+K

- command: whim.core.focus_previous_monitor
keybind: LCtrl+LShift+LAlt+J

- command: whim.custom.next_layout_engine
keybind: LCtrl+LShift+LAlt+L

- command: whim.core.cycle_layout_engine.next
keybind: LCtrl+LShift+LAlt+L

- command: whim.core.cycle_layout_engine.previous
keybind: LCtrl+LShift+LAlt+Win+L

- command: whim.command_palette.find_focus_window
keybind: Win+LCtrl+F

- command: whim.core.exit_whim
keybind: Win+LCtrl+Q

unify_key_modifiers: true
```
1 change: 1 addition & 0 deletions docs/docs/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ items:
- href: customize/logging.md
- href: customize/styling.md
- href: customize/snippets.md
- href: customize/yaml.md

- name: Plugins
- href: plugins/bar.md
Expand Down
12 changes: 12 additions & 0 deletions scripts/Generate-SourceFromSchema.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Write-Host "Generating source from schema..."

$schemaPath = ".\src\Whim.Yaml\schema.json"
$outputPath = ".\src\Whim.Yaml\Generated"

New-Item $outputPath -ItemType Directory | Out-Null

dotnet tool run generatejsonschematypes `
$schemaPath `
--rootNamespace Whim.Yaml `
--useSchema Draft7 `
--outputPath $outputPath
1 change: 0 additions & 1 deletion src/Whim.FocusIndicator/FocusIndicatorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ protected virtual void Dispose(bool disposing)
_cancellationTokenSource.Dispose();
_focusIndicatorWindow?.Dispose();
_focusIndicatorWindow?.Close();
_task?.Dispose();
_context.Store.WindowEvents.WindowFocused -= WindowEvents_WindowFocused;
_context.Store.MonitorEvents.MonitorsChanged -= MonitorEvents_MonitorsChanged;
}
Expand Down
Loading

0 comments on commit e3eab8e

Please sign in to comment.