toml-config: add named actions
This commit is contained in:
parent
8552c5f1eb
commit
3100773ae0
15 changed files with 587 additions and 4 deletions
|
|
@ -18,6 +18,11 @@
|
|||
"description": "The value should be the name of a `simple` action. See the description of that\nvariant for more details.\n\n- Example:\n\n ```toml\n [shortcuts]\n alt-q = \"quit\"\n ```\n",
|
||||
"$ref": "#/$defs/SimpleActionName"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "The value should be the name of a `named` action, prefixed with the `$` character.\n\nThis is the same as using the `named` action with the `$` removed.\n\n- Example:\n\n ```toml\n [actions]\n q = \"quit\"\n\n [shortcuts]\n alt-q = \"$q\"\n ```\n",
|
||||
"pattern": "^\\$.*$"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"description": "A list of actions to execute in sequence.\n\n- Example:\n\n ```toml\n [shortcuts]\n alt-q = [\n { type = \"exec\", exec = [\"notify-send\", \"exiting\"] },\n \"quit\",\n ]\n ```\n",
|
||||
|
|
@ -46,6 +51,23 @@
|
|||
"cmd"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "A named action that was defined via the top-level `actions` table or a\n`define-action` action. These are usually written as plain strings with a `$`\nprefix.\n\n- Example 1:\n\n ```toml\n [actions]\n my-action = \"quit\"\n\n [shortcuts]\n alt-q = { type = \"named\", name = \"my-action\" }\n ```\n\n- Example 2:\n\n ```toml\n [shortcuts]\n alt-q = [\n { type = \"define-action\", name = \"my-action\", action = \"quit\" },\n { type = \"named\", name = \"my-action\" },\n ]\n ```\n",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "named"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The named action to execute."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"name"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "A list of actions to execute in sequence. These are usually written as plain\narrays instead.\n\n- Example 1:\n\n ```toml\n [shortcuts]\n alt-q = { type = \"multi\", actions = [\"quit\", \"quit\"] }\n ```\n\n- Example 2:\n\n ```toml\n [shortcuts]\n alt-q = [\"quit\", \"quit\"]\n ```\n",
|
||||
"type": "object",
|
||||
|
|
@ -418,6 +440,45 @@
|
|||
"type",
|
||||
"dev"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Defines a name for an action. Usually you would define these by using the\ntop-level `actions` table. This action can be used to re-define actions.\n\n- Example:\n\n ```toml\n [actions]\n a1 = \"quit\"\n a2 = \"$a1\"\n\n [shortcuts]\n alt-q = [\n { type = \"define-action\", name = \"a2\", action = [] },\n \"$2\", # does nothing\n ]\n ```\n",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "define-action"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the action."
|
||||
},
|
||||
"action": {
|
||||
"description": "The action to execute.",
|
||||
"$ref": "#/$defs/Action"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"name",
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Removes a named action.\n",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "undefine-action"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "The name of the action."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"name"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -640,6 +701,19 @@
|
|||
"float": {
|
||||
"description": "Configures the settings of floating windows.\n\n- Example:\n\n ```toml\n [float]\n show-pin-icon = true\n ```\n",
|
||||
"$ref": "#/$defs/Float"
|
||||
},
|
||||
"actions": {
|
||||
"description": "Named actions.\n\nNamed actions can be used everywhere an action can be used. This can be used to\navoid repeating the same action multiple times.\n\n- Example:\n\n ```toml\n actions.switch-to-1 = [\n { type = \"show-workspace\", name = \"1\" },\n { type = \"define-action\", name = \"switch-to-next\", action = \"$switch-to-2\" },\n ]\n actions.switch-to-2 = [\n { type = \"show-workspace\", name = \"2\" },\n { type = \"define-action\", name = \"switch-to-next\", action = \"$switch-to-3\" },\n ]\n actions.switch-to-3 = [\n { type = \"show-workspace\", name = \"3\" },\n { type = \"define-action\", name = \"switch-to-next\", action = \"$switch-to-1\" },\n ]\n actions.switch-to-next = \"$switch-to-1\"\n\n [shortcuts]\n alt-x = \"$switch-to-next\"\n ```\n",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"description": "",
|
||||
"$ref": "#/$defs/Action"
|
||||
}
|
||||
},
|
||||
"max-action-depth": {
|
||||
"type": "integer",
|
||||
"description": "The maximum call depth of named actions. This setting prevents infinite recursion\nwhen using named actions. Setting this value to 0 or less disables named actions\ncompletely. The default is `16`.\n",
|
||||
"minimum": 0.0
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
|
|
|
|||
|
|
@ -57,6 +57,24 @@ variant for more details.
|
|||
|
||||
The value should be a [SimpleActionName](#types-SimpleActionName).
|
||||
|
||||
#### A string
|
||||
|
||||
The value should be the name of a `named` action, prefixed with the `$` character.
|
||||
|
||||
This is the same as using the `named` action with the `$` removed.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
q = "quit"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = "$q"
|
||||
```
|
||||
|
||||
The string should match the following regular expression: `^\$.*$`
|
||||
|
||||
#### An array
|
||||
|
||||
A list of actions to execute in sequence.
|
||||
|
|
@ -106,6 +124,40 @@ This table is a tagged union. The variant is determined by the `type` field. It
|
|||
|
||||
The value of this field should be a [SimpleActionName](#types-SimpleActionName).
|
||||
|
||||
- `named`:
|
||||
|
||||
A named action that was defined via the top-level `actions` table or a
|
||||
`define-action` action. These are usually written as plain strings with a `$`
|
||||
prefix.
|
||||
|
||||
- Example 1:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
my-action = "quit"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = { type = "named", name = "my-action" }
|
||||
```
|
||||
|
||||
- Example 2:
|
||||
|
||||
```toml
|
||||
[shortcuts]
|
||||
alt-q = [
|
||||
{ type = "define-action", name = "my-action", action = "quit" },
|
||||
{ type = "named", name = "my-action" },
|
||||
]
|
||||
```
|
||||
|
||||
The table has the following fields:
|
||||
|
||||
- `name` (required):
|
||||
|
||||
The named action to execute.
|
||||
|
||||
The value of this field should be a string.
|
||||
|
||||
- `multi`:
|
||||
|
||||
A list of actions to execute in sequence. These are usually written as plain
|
||||
|
|
@ -574,6 +626,51 @@ This table is a tagged union. The variant is determined by the `type` field. It
|
|||
|
||||
The value of this field should be a [DrmDeviceMatch](#types-DrmDeviceMatch).
|
||||
|
||||
- `define-action`:
|
||||
|
||||
Defines a name for an action. Usually you would define these by using the
|
||||
top-level `actions` table. This action can be used to re-define actions.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
a1 = "quit"
|
||||
a2 = "$a1"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = [
|
||||
{ type = "define-action", name = "a2", action = [] },
|
||||
"$2", # does nothing
|
||||
]
|
||||
```
|
||||
|
||||
The table has the following fields:
|
||||
|
||||
- `name` (required):
|
||||
|
||||
The name of the action.
|
||||
|
||||
The value of this field should be a string.
|
||||
|
||||
- `action` (required):
|
||||
|
||||
The action to execute.
|
||||
|
||||
The value of this field should be a [Action](#types-Action).
|
||||
|
||||
- `undefine-action`:
|
||||
|
||||
Removes a named action.
|
||||
|
||||
The table has the following fields:
|
||||
|
||||
- `name` (required):
|
||||
|
||||
The name of the action.
|
||||
|
||||
The value of this field should be a string.
|
||||
|
||||
|
||||
<a name="types-Brightness"></a>
|
||||
### `Brightness`
|
||||
|
|
@ -1278,6 +1375,48 @@ The table has the following fields:
|
|||
|
||||
The value of this field should be a [Float](#types-Float).
|
||||
|
||||
- `actions` (optional):
|
||||
|
||||
Named actions.
|
||||
|
||||
Named actions can be used everywhere an action can be used. This can be used to
|
||||
avoid repeating the same action multiple times.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
actions.switch-to-1 = [
|
||||
{ type = "show-workspace", name = "1" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-2" },
|
||||
]
|
||||
actions.switch-to-2 = [
|
||||
{ type = "show-workspace", name = "2" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-3" },
|
||||
]
|
||||
actions.switch-to-3 = [
|
||||
{ type = "show-workspace", name = "3" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-1" },
|
||||
]
|
||||
actions.switch-to-next = "$switch-to-1"
|
||||
|
||||
[shortcuts]
|
||||
alt-x = "$switch-to-next"
|
||||
```
|
||||
|
||||
The value of this field should be a table whose values are [Actions](#types-Action).
|
||||
|
||||
- `max-action-depth` (optional):
|
||||
|
||||
The maximum call depth of named actions. This setting prevents infinite recursion
|
||||
when using named actions. Setting this value to 0 or less disables named actions
|
||||
completely. The default is `16`.
|
||||
|
||||
The value of this field should be a number.
|
||||
|
||||
The numbers should be integers.
|
||||
|
||||
The numbers should be greater than or equal to 0.
|
||||
|
||||
|
||||
<a name="types-Connector"></a>
|
||||
### `Connector`
|
||||
|
|
|
|||
|
|
@ -89,6 +89,22 @@ Action:
|
|||
[shortcuts]
|
||||
alt-q = "quit"
|
||||
```
|
||||
- kind: string
|
||||
pattern: "^\\$.*$"
|
||||
description: |
|
||||
The value should be the name of a `named` action, prefixed with the `$` character.
|
||||
|
||||
This is the same as using the `named` action with the `$` removed.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
q = "quit"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = "$q"
|
||||
```
|
||||
- kind: array
|
||||
items:
|
||||
ref: Action
|
||||
|
|
@ -130,6 +146,36 @@ Action:
|
|||
description: The simple action to execute.
|
||||
required: true
|
||||
ref: SimpleActionName
|
||||
named:
|
||||
description: |
|
||||
A named action that was defined via the top-level `actions` table or a
|
||||
`define-action` action. These are usually written as plain strings with a `$`
|
||||
prefix.
|
||||
|
||||
- Example 1:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
my-action = "quit"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = { type = "named", name = "my-action" }
|
||||
```
|
||||
|
||||
- Example 2:
|
||||
|
||||
```toml
|
||||
[shortcuts]
|
||||
alt-q = [
|
||||
{ type = "define-action", name = "my-action", action = "quit" },
|
||||
{ type = "named", name = "my-action" },
|
||||
]
|
||||
```
|
||||
fields:
|
||||
name:
|
||||
kind: string
|
||||
description: The named action to execute.
|
||||
required: true
|
||||
multi:
|
||||
description: |
|
||||
A list of actions to execute in sequence. These are usually written as plain
|
||||
|
|
@ -521,6 +567,41 @@ Action:
|
|||
The first matching device is used.
|
||||
required: true
|
||||
ref: DrmDeviceMatch
|
||||
define-action:
|
||||
description: |
|
||||
Defines a name for an action. Usually you would define these by using the
|
||||
top-level `actions` table. This action can be used to re-define actions.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
[actions]
|
||||
a1 = "quit"
|
||||
a2 = "$a1"
|
||||
|
||||
[shortcuts]
|
||||
alt-q = [
|
||||
{ type = "define-action", name = "a2", action = [] },
|
||||
"$2", # does nothing
|
||||
]
|
||||
```
|
||||
fields:
|
||||
name:
|
||||
kind: string
|
||||
description: The name of the action.
|
||||
required: true
|
||||
action:
|
||||
description: The action to execute.
|
||||
required: true
|
||||
ref: Action
|
||||
undefine-action:
|
||||
description: |
|
||||
Removes a named action.
|
||||
fields:
|
||||
name:
|
||||
kind: string
|
||||
description: The name of the action.
|
||||
required: true
|
||||
|
||||
|
||||
Exec:
|
||||
|
|
@ -2350,6 +2431,46 @@ Config:
|
|||
[float]
|
||||
show-pin-icon = true
|
||||
```
|
||||
actions:
|
||||
kind: map
|
||||
values:
|
||||
ref: Action
|
||||
required: false
|
||||
description: |
|
||||
Named actions.
|
||||
|
||||
Named actions can be used everywhere an action can be used. This can be used to
|
||||
avoid repeating the same action multiple times.
|
||||
|
||||
- Example:
|
||||
|
||||
```toml
|
||||
actions.switch-to-1 = [
|
||||
{ type = "show-workspace", name = "1" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-2" },
|
||||
]
|
||||
actions.switch-to-2 = [
|
||||
{ type = "show-workspace", name = "2" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-3" },
|
||||
]
|
||||
actions.switch-to-3 = [
|
||||
{ type = "show-workspace", name = "3" },
|
||||
{ type = "define-action", name = "switch-to-next", action = "$switch-to-1" },
|
||||
]
|
||||
actions.switch-to-next = "$switch-to-1"
|
||||
|
||||
[shortcuts]
|
||||
alt-x = "$switch-to-next"
|
||||
```
|
||||
max-action-depth:
|
||||
kind: number
|
||||
integer_only: true
|
||||
minimum: 0
|
||||
required: false
|
||||
description: |
|
||||
The maximum call depth of named actions. This setting prevents infinite recursion
|
||||
when using named actions. Setting this value to 0 or less disables named actions
|
||||
completely. The default is `16`.
|
||||
|
||||
|
||||
Idle:
|
||||
|
|
|
|||
|
|
@ -159,6 +159,8 @@ fn create_string_spec(description: &str, spec: &StringSpec) -> Value {
|
|||
if let Some(values) = &spec.values {
|
||||
let strings: Vec<_> = values.iter().map(|v| &v.value.value).collect();
|
||||
res.insert("enum".into(), json!(strings));
|
||||
} else if let Some(pattern) = &spec.pattern {
|
||||
res.insert("pattern".into(), json!(pattern));
|
||||
}
|
||||
res.into()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,6 +230,12 @@ fn write_string_spec(buf: &mut Vec<u8>, spec: &StringSpec, pad: &str) -> Result<
|
|||
writeln!(buf)?;
|
||||
}
|
||||
writeln!(buf)?;
|
||||
} else if let Some(pattern) = &spec.pattern {
|
||||
writeln!(
|
||||
buf,
|
||||
"{pad}The string should match the following regular expression: `{pattern}`"
|
||||
)?;
|
||||
writeln!(buf)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ pub enum RefOrSpec<T> {
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StringSpec {
|
||||
pub pattern: Option<String>,
|
||||
pub values: Option<Vec<Described<StringSpecValue>>>,
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue