Skip to content

Commit

Permalink
Global Hotkey Docs (#1548)
Browse files Browse the repository at this point in the history
Adds the following changes:
- renames "key:globalhotkey" to "app:globalhotkey"
- adds globalhostkey documentation (especially in regard to what keys are allowed)
- improves the algorithm that converts electron keybindings from wave keybindings
- fixes some regexp problems
  • Loading branch information
oneirocosm authored Dec 17, 2024
1 parent 801034c commit dbc2be1
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 9 deletions.
42 changes: 42 additions & 0 deletions docs/docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ wsh editconfig

| Key Name | Type | Function |
| ------------------------------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| app:globalhotkey | string | A systemwide keybinding to open your most recent wave window. This is a set of key names separated by `:`. For more info, see [Customizable Systemwide Global Hotkey](#customizable-systemwide-global-hotkey) |
| ai:preset | string | the default AI preset to use |
| ai:baseurl | string | Set the AI Base Url (must be OpenAI compatible) |
| ai:apitoken | string | your AI api token |
Expand Down Expand Up @@ -190,3 +191,44 @@ wsh editconfig termthemes.json
| background | CSS color | | | background color (default when no color code is applied), must have alpha channel (#rrggbbaa) if you want the terminal to be transparent |
| cursorAccent | CSS color | | | color for cursor |
| selectionBackground | CSS color | | | background color for selected text |

### Customizable Systemwide Global Hotkey

Wave allows settings a custom global hotkey to open your most recent window from anywhere in your computer. This has the name `"app:globalhotkey"` in the `settings.json` file and takes the form of a series of key names separated by the `:` character. We support the following key names:

- `Ctrl`
- `Cmd`
- `Shift`
- `Alt`
- `Option`
- `Meta`
- `Super`
- Digits (non-numpad) represented by `c{Digit0}` through `c{Digit9}`
- Letters `a` though `z`
- F keys `F1` through `F20`
- Soft keys `Soft1` through `Soft4`. These are essentially the same as `F21` through `F24`.
- Space represented as a literal space &nbsp;<code>&nbsp;</code>
- `Enter` (This is labeled as return on Mac)
- `Tab`
- `CapsLock`
- `NumLock`
- `Backspace` (This is labeled as delete on Mac)
- `Delete`
- `Insert`
- The arrow keys `ArrowUp`, `ArrowDown`, `ArrowLeft`, and `ArrowRight`
- `Home`
- `End`
- `PageUp`
- `PageDown`
- `Esc`
- Volume controls `AudioVolumeUp`, `AudioVolumeDown`, `AudioVolumeMute`
- Media controls `MediaTrackNext`, `MediaTrackPrevious`, `MediaPlayPause`, and `MediaStop`
- `PrintScreen`
- Numpad keys represented by `c{Numpad0}` through `c{Numpad9}`
- The numpad decimal represented by `Decimal`
- The numpad plus/add represented by `Add`
- The numpad minus/subtract represented by `Subtract`
- The numpad star/multiply represented by `Multiply`
- The numpad slash/divide represented by `Divide`

As an example, to set the key to the combination of Control, Option, and the letter E, you would configure it to `"Ctrl:Opt:e"`.
4 changes: 4 additions & 0 deletions docs/docs/keybindings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ replace "Cmd" with "Alt" (note that "Ctrl" is "Ctrl" on both Mac, Windows, and L
| ---------------- | ------------- |
| <Kbd k="Cmd:l"/> | Clear AI Chat |

## Customizeable Systemwide Global Hotkey

Wave allows setting a custom global hotkey to focus your most recent window from anywhere in your computer. For more information on this, see [the config docs](./config#customizable-systemwide-global-hotkey).

</PlatformProvider>
66 changes: 66 additions & 0 deletions emain/emain-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ export function ensureBoundsAreVisible(bounds: electron.Rectangle): electron.Rec
export function waveKeyToElectronKey(waveKey: string): string {
const waveParts = waveKey.split(":");
const electronParts: Array<string> = waveParts.map((part: string) => {
const digitRegexpMatch = new RegExp("^c{Digit([0-9])}$").exec(part);
const numpadRegexpMatch = new RegExp("^c{Numpad([0-9])}$").exec(part);
const lowercaseCharMatch = new RegExp("^([a-z])$").exec(part);
if (part == "ArrowUp") {
return "Up";
}
Expand All @@ -182,6 +185,69 @@ export function waveKeyToElectronKey(waveKey: string): string {
if (part == "ArrowRight") {
return "Right";
}
if (part == "Soft1") {
return "F21";
}
if (part == "Soft2") {
return "F22";
}
if (part == "Soft3") {
return "F23";
}
if (part == "Soft4") {
return "F24";
}
if (part == " ") {
return "Space";
}
if (part == "CapsLock") {
return "Capslock";
}
if (part == "NumLock") {
return "Numlock";
}
if (part == "ScrollLock") {
return "Scrolllock";
}
if (part == "AudioVolumeUp") {
return "VolumeUp";
}
if (part == "AudioVolumeDown") {
return "VolumeDown";
}
if (part == "AudioVolumeMute") {
return "VolumeMute";
}
if (part == "MediaTrackNext") {
return "MediaNextTrack";
}
if (part == "MediaTrackPrevious") {
return "MediaPreviousTrack";
}
if (part == "Decimal") {
return "numdec";
}
if (part == "Add") {
return "numadd";
}
if (part == "Subtract") {
return "numsub";
}
if (part == "Multiply") {
return "nummult";
}
if (part == "Divide") {
return "numdiv";
}
if (digitRegexpMatch && digitRegexpMatch.length > 1) {
return digitRegexpMatch[1];
}
if (numpadRegexpMatch && numpadRegexpMatch.length > 1) {
return `num${numpadRegexpMatch[1]}`;
}
if (lowercaseCharMatch && lowercaseCharMatch.length > 1) {
return lowercaseCharMatch[1].toUpperCase();
}

return part;
});
Expand Down
2 changes: 1 addition & 1 deletion emain/emain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ async function appMain() {
fireAndForget(createNewWaveWindow);
}
});
const rawGlobalHotKey = launchSettings?.["key:globalhotkey"];
const rawGlobalHotKey = launchSettings?.["app:globalhotkey"];
if (rawGlobalHotKey) {
registerGlobalHotkey(rawGlobalHotKey);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/types/gotypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ declare global {

// wconfig.SettingsType
type SettingsType = {
"app:*"?: boolean;
"app:globalhotkey"?: string;
"ai:*"?: boolean;
"ai:preset"?: string;
"ai:apitype"?: string;
Expand Down Expand Up @@ -674,8 +676,6 @@ declare global {
"window:magnifiedblocksize"?: number;
"window:magnifiedblockblurprimarypx"?: number;
"window:magnifiedblockblursecondarypx"?: number;
"key:*"?: boolean;
"key:globalhotkey"?: string;
"telemetry:*"?: boolean;
"telemetry:enabled"?: boolean;
"conn:*"?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions pkg/wconfig/metaconsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
package wconfig

const (
ConfigKey_AppClear = "app:*"
ConfigKey_AppGlobalHotkey = "app:globalhotkey"

ConfigKey_AiClear = "ai:*"
ConfigKey_AiPreset = "ai:preset"
ConfigKey_AiApiType = "ai:apitype"
Expand Down Expand Up @@ -75,9 +78,6 @@ const (
ConfigKey_WindowMagnifiedBlockBlurPrimaryPx = "window:magnifiedblockblurprimarypx"
ConfigKey_WindowMagnifiedBlockBlurSecondaryPx = "window:magnifiedblockblursecondarypx"

ConfigKey_KeyClear = "key:*"
ConfigKey_KeyGlobalHotkey = "key:globalhotkey"

ConfigKey_TelemetryClear = "telemetry:*"
ConfigKey_TelemetryEnabled = "telemetry:enabled"

Expand Down
6 changes: 3 additions & 3 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const AnySchema = `
`

type SettingsType struct {
AppClear bool `json:"app:*,omitempty"`
AppGlobalHotkey string `json:"app:globalhotkey,omitempty"`

AiClear bool `json:"ai:*,omitempty"`
AiPreset string `json:"ai:preset,omitempty"`
AiApiType string `json:"ai:apitype,omitempty"`
Expand Down Expand Up @@ -102,9 +105,6 @@ type SettingsType struct {
WindowMagnifiedBlockBlurPrimaryPx *int64 `json:"window:magnifiedblockblurprimarypx,omitempty"`
WindowMagnifiedBlockBlurSecondaryPx *int64 `json:"window:magnifiedblockblursecondarypx,omitempty"`

KeyClear bool `json:"key:*,omitempty"`
KeyGlobalHotkey string `json:"key:globalhotkey,omitempty"`

TelemetryClear bool `json:"telemetry:*,omitempty"`
TelemetryEnabled bool `json:"telemetry:enabled,omitempty"`

Expand Down

0 comments on commit dbc2be1

Please sign in to comment.