feat(wm): workspace rules

A workspace rule sends the windows of an application to a workspace: an initial
rule once, when komorebi first sees the window, and a permanent rule every time,
so that a window the user takes away goes back. A rule is a rule on the window's
executable, class, title or path, with a monitor and a workspace index, or the
name of a workspace. It comes from komorebi.json (workspace_rules and
initial_workspace_rules of a workspace, made again from the file each time it is
read) or from komorebic (workspace-rule, initial-workspace-rule, their named
forms, and the commands that clear and enforce them).

The window manager looks at the rules before it handles each event about a
window it manages, and again when the configuration is loaded, so the windows
that were open when the daemon started are sent too. A window that leaves the
workspace in front is taken out of the layout and hidden, as the back of a stack
is, and it is put on the desktop of its new workspace, which is what it comes
back to and is tiled on when that workspace is shown. A window that moves
between workspaces that are not in front is put on the desktop of its new
workspace as well. A floating window that goes to another monitor is moved onto
it, and a workspace that does not exist yet is made.
This commit is contained in:
LGUG2Z committed 2026-10-28 07:20:37 -07:00
1 parent c6874ff5db
commit efcc90d279
33 files changed
+1694 -14

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
```text
Remove all application association rules for all workspaces
Usage: clear-all-workspace-rules
Options:
-h, --help
Print help
```
+14
View File
@@ -0,0 +1,14 @@
```text
Remove all application association rules for a named workspace
Usage: clear-named-workspace-rules <WORKSPACE>
Arguments:
<WORKSPACE>
Name of a workspace
Options:
-h, --help
Print help
```
+17
View File
@@ -0,0 +1,17 @@
```text
Remove all application association rules for a workspace by monitor and workspace index
Usage: clear-workspace-rules <MONITOR> <WORKSPACE>
Arguments:
<MONITOR>
Monitor index (zero-indexed)
<WORKSPACE>
Workspace index on the specified monitor (zero-indexed)
Options:
-h, --help
Print help
```
+10
View File
@@ -0,0 +1,10 @@
```text
Enforce all workspace rules, including initial workspace rules that have already been applied
Usage: enforce-workspace-rules
Options:
-h, --help
Print help
```
+24
View File
@@ -0,0 +1,24 @@
```text
Add a rule to associate an application with a named workspace on first show
Usage: initial-named-workspace-rule <IDENTIFIER> <ID> <WORKSPACE>
Arguments:
<IDENTIFIER>
Possible values:
- exe: Executable name
- class: Role or subrole
- title: Window title
- path: Executable path
<ID>
Identifier as a string
<WORKSPACE>
Name of a workspace
Options:
-h, --help
Print help (see a summary with '-h')
```
+27
View File
@@ -0,0 +1,27 @@
```text
Add a rule to associate an application with a workspace on first show
Usage: initial-workspace-rule <IDENTIFIER> <ID> <MONITOR> <WORKSPACE>
Arguments:
<IDENTIFIER>
Possible values:
- exe: Executable name
- class: Role or subrole
- title: Window title
- path: Executable path
<ID>
Identifier as a string
<MONITOR>
Monitor index (zero-indexed)
<WORKSPACE>
Workspace index on the specified monitor (zero-indexed)
Options:
-h, --help
Print help (see a summary with '-h')
```
+24
View File
@@ -0,0 +1,24 @@
```text
Add a rule to associate an application with a named workspace
Usage: named-workspace-rule <IDENTIFIER> <ID> <WORKSPACE>
Arguments:
<IDENTIFIER>
Possible values:
- exe: Executable name
- class: Role or subrole
- title: Window title
- path: Executable path
<ID>
Identifier as a string
<WORKSPACE>
Name of a workspace
Options:
-h, --help
Print help (see a summary with '-h')
```
+27
View File
@@ -0,0 +1,27 @@
```text
Add a rule to associate an application with a workspace
Usage: workspace-rule <IDENTIFIER> <ID> <MONITOR> <WORKSPACE>
Arguments:
<IDENTIFIER>
Possible values:
- exe: Executable name
- class: Role or subrole
- title: Window title
- path: Executable path
<ID>
Identifier as a string
<MONITOR>
Monitor index (zero-indexed)
<WORKSPACE>
Workspace index on the specified monitor (zero-indexed)
Options:
-h, --help
Print help (see a summary with '-h')
```
+29 -1
View File
@@ -683,6 +683,21 @@ defaults. A **rule** is an entry of one of the process-wide lists. A workspace's
`layout_rules`, `work_area_offset_rules` and `window_container_behaviour_rules` are fields of the
[`Workspace`], which [`Workspace::update`] reads each time it tiles.
A workspace's `workspace_rules` and `initial_workspace_rules` are not fields of the window manager
but entries of [`WORKSPACE_MATCHING_RULES`], which [`StaticConfig::postload`] and
[`StaticConfig::reload`] empty and fill from the file, and the messages `WorkspaceRule`,
`InitialWorkspaceRule` and their named forms add to. [`WindowManager::enforce_workspace_rules`] reads
them: for each window in view (the top of each container, and the floating windows) that a rule
matches, on a workspace other than the rule's, it makes an operation, takes the window out of its
workspace (and hides it when that is the focused one), puts it in the target (making the workspace
if it is not there, and taking a floating window to the target's monitor), tiles the focused
workspace again if the window left it, and has each target monitor put its windows on the desktops
of their workspaces
([`Monitor::assign_windows_to_workspaces`]). `handle_event` calls it before every event about a
window it manages, and `postload`, `reload` and `EnforceWorkspaceRules` call it too. An `initial_only`
rule moves a window once: the window id goes into [`WindowManager::already_moved_window_handles`],
which `EnforceWorkspaceRules` empties and a destroy removes the id from.
`ReplaceConfiguration` is the third way in: [`WindowManager::process_command`] checks that the file
reads as a [`StaticConfig`], pauses the old window manager and brings back the windows it hid
([`WindowManager::restore_all_windows`]), makes a new window manager from the file
@@ -721,6 +736,10 @@ goes the other way, for `GenerateStaticConfig`.
| `schema.json` and `schema.asc.json` are what the Rust types print | Nix check `schema-fresh`, and a test that compares them with `komorebic`'s output | `schema-fresh`, `the_schema_files_of_the_repository_are_what_the_subcommands_print` | `just jsonschema` |
| The options the module is typed with are made from the committed schema | the hash of `schema.json` in the first line of `nix/komorebi-options.nix`, compared by `schema-fresh` | `schema-fresh` | `just nixgen` |
| The example, in Nix and in JSON, follows the schema, and says the same in both | Nix check `nix-options-validation`: the options evaluated against the Nix example, both examples checked with `check-jsonschema`, and one contained in the other | `nix-options-validation` | none |
| A window a workspace rule names ends on its workspace, and on that workspace's desktop once the workspace is shown | framework path: [`WindowManager::enforce_workspace_rules`] moves it in the model, and has the target monitor put it on the desktop | `a_rule_sends_the_window_of_an_application_to_its_workspace`, `a_window_a_rule_moves_between_workspaces_that_are_out_of_view_is_put_on_the_new_desktop`, `vm-workspace-rules` | none |
| A window a workspace rule takes off the workspace in front is out of sight until its workspace is shown | framework path: [`WindowManager::enforce_workspace_rules`] hides it, and showing the workspace restores it | `a_rule_sends_the_window_of_an_application_to_its_workspace`, `vm-workspace-rules` | none |
| An initial rule sends a window once, a permanent one every time | framework path: the window ids an initial rule has sent are in [`WindowManager::already_moved_window_handles`] until the window closes | `an_initial_rule_moves_a_window_once_and_a_permanent_one_every_time`, `vm-workspace-rules` | `komorebic enforce-workspace-rules` forgets them |
| The rules of the configuration are the file's, and the windows that are open follow them | framework path: [`StaticConfig::postload`] and [`StaticConfig::reload`] empty the list, fill it from the file and enforce it | `the_rules_of_komorebi_json_send_the_windows_that_are_open_and_come_out_in_the_generated_file`, `vm-workspace-rules` | none |
| Replacing the configuration with a file that does not read leaves the window manager as it was | framework path: the arm reads the file as a [`StaticConfig`] before it makes anything | `replacing_the_configuration_makes_the_window_manager_again_from_the_new_file` | none |
| Replacing the configuration leaves no window hidden | framework path: the arm brings back the windows the old window manager hid ([`WindowManager::restore_all_windows`]) before the new one reads the desktop | `replacing_the_configuration_makes_the_window_manager_again_from_the_new_file` | none |
| `quickstart` never writes over a file without being told to | framework path: every file goes through `write_file_with_prompt`, which keeps the file unless the answer is `y` or `yes` | `quickstart_writes_the_example_files_and_asks_before_it_overwrites_one` | none |
@@ -1037,7 +1056,9 @@ A window is shown, and ends up on a tile:
[`komorebi/tests/config_parity.rs`](../../komorebi/tests/config_parity.rs) the files of other
platforms and the example, which load;
[`komorebi/tests/replace_configuration.rs`](../../komorebi/tests/replace_configuration.rs)
the `ReplaceConfiguration` message; [`komorebi/tests/schemas.rs`](../../komorebi/tests/schemas.rs) the schemas the daemon answers
the `ReplaceConfiguration` message;
[`komorebi/tests/workspace_rules.rs`](../../komorebi/tests/workspace_rules.rs) the workspace
rules; [`komorebi/tests/schemas.rs`](../../komorebi/tests/schemas.rs) the schemas the daemon answers
with; [`schema.json`](../../schema.json), [`schema.asc.json`](../../schema.asc.json) and
[`nix/komorebi-options.nix`](../../nix/komorebi-options.nix), which are generated;
[`nix/tests/default.nix`](../../nix/tests/default.nix) and
@@ -1111,6 +1132,9 @@ A window is shown, and ends up on a tile:
a stack hides, the behavior of new windows and the float override, against the fake;
[`nix/tests/vm/suites/stacks`](../../nix/tests/vm/suites/stacks/test.py), the same in a real
KWin, with the parking desktop, a crash and a stop.
- [`nix/tests/vm/suites/workspace-rules`](../../nix/tests/vm/suites/workspace-rules/test.py):
workspace rules sending windows to other workspaces of a real KWin, out of sight on the parking
desktop until the workspace is shown.
- [`nix/tests/vm/suites/workspace-switch`](../../nix/tests/vm/suites/workspace-switch/test.py):
workspaces as a real KWin's desktops, switched by `komorebic` and by KWin;
[`nix/tests/vm/suites/kwin-contract`](../../nix/tests/vm/suites/kwin-contract/test.py), the
@@ -1128,6 +1152,10 @@ A window is shown, and ends up on a tile:
[`StaticConfig::reload`]: ../../komorebi/src/static_config.rs
[`Workspace::load_static_config`]: ../../komorebi/src/workspace.rs
[`HOME_DIR`]: ../../komorebi/src/lib.rs
[`WORKSPACE_MATCHING_RULES`]: ../../komorebi/src/lib.rs
[`WindowManager::enforce_workspace_rules`]: ../../komorebi/src/window_manager.rs
[`WindowManager::already_moved_window_handles`]: ../../komorebi/src/window_manager.rs
[`Monitor::assign_windows_to_workspaces`]: ../../komorebi/src/monitor.rs
[`LAYOUT_DEFAULTS`]: ../../komorebi/src/lib.rs
[`IGNORE_IDENTIFIERS`]: ../../komorebi/src/lib.rs
[`MANAGE_IDENTIFIERS`]: ../../komorebi/src/lib.rs
+8 -1
View File
@@ -27,7 +27,14 @@ different layout. This page has the file as it is:
"workspaces": [
{
"name": "I",
"layout": "BSP"
"layout": "BSP",
"initial_workspace_rules": [
// {
// "kind": "Exe",
// "id": "firefox",
// "matching_strategy": "Equals"
// }
]
},
{
"name": "II",
+3 -1
View File
@@ -49,7 +49,9 @@ and keep parts of a monitor free of them.
[Rules](usage/rules.md) explains how to keep an application out of the layout, always tile it, or
float its windows.
[Workspaces](usage/workspaces.md) explains how each monitor shows one of its workspaces, which
are KWin's virtual desktops, and how to show another or move a window to one.
are KWin's virtual desktops, and how to show another or move a window to one, and
[Workspace rules](usage/workspace-rules.md) how to have the windows of an application go to a
workspace by themselves.
[Configuration](usage/configuration.md) explains `komorebi.json`, where komorebi looks for it and
how it is reloaded when it changes, [Example configurations](example-configurations.md) has one to
start from, and [Application specific configuration](usage/application-specific-configuration.md)
+8 -1
View File
@@ -14,7 +14,14 @@
"workspaces": [
{
"name": "I",
"layout": "BSP"
"layout": "BSP",
"initial_workspace_rules": [
// {
// "kind": "Exe",
// "id": "firefox",
// "matching_strategy": "Equals"
// }
]
},
{
"name": "II",
+7 -2
View File
@@ -45,7 +45,9 @@ it is.
[`komorebic generate-static-config`](../cli/generate-static-config.md) prints the settings the
daemon has now as a `komorebi.json`: a way to start a file from a setup arrived at with commands.
The rules (`ignore_rules`, `manage_rules` and `floating_applications`) are not in what it prints.
The rules (`ignore_rules`, `manage_rules` and `floating_applications`) are not in what it prints;
the `workspace_rules` and `initial_workspace_rules` of the workspaces that were loaded from a file
are.
## One file for every platform
@@ -103,7 +105,8 @@ Each is a list of rules, which [Rules](rules.md) explains. A rule is an object w
`Contains`, `Regex`, or one of the four that negate them: `DoesNotEqual`, `DoesNotStartWith`,
`DoesNotEndWith` and `DoesNotContain`), or a list of such objects, all of which have to match.
Rules in the file add to the ones the daemon has: a rule that is taken out of the file stays
until the daemon restarts.
until the daemon restarts. The exception is a workspace's `workspace_rules` and
`initial_workspace_rules`, which the file gives again each time it is read.
### Monitors and workspaces
@@ -130,6 +133,8 @@ named for it. A workspace has these keys:
| `tile` | see below | Whether the workspace tiles its windows |
| `layout_flip` | none | The axis the layout is mirrored on: `Horizontal`, `Vertical` or `HorizontalAndVertical` |
| `layout_options` | none | Options of the layout, such as `column_ratios` and `scrolling` |
| `workspace_rules` | none | Rules for the windows that always go to this workspace ([Workspace rules](workspace-rules.md)) |
| `initial_workspace_rules` | none | Rules for the windows that go to this workspace when komorebi first sees them |
| `layout_rules` | none | `{ "3": "Columns" }`: the layout the workspace has once it has 3 containers or more |
| `layout_options_rules` | none | The same, for the layout options |
| `container_padding`, `workspace_padding` | the default | The padding of this workspace |
+83
View File
@@ -0,0 +1,83 @@
# Workspace rules
A workspace rule sends the windows of an application to a workspace. It is a [rule](rules.md)
(`exe`, `class`, `title` or `path`) with a place: the index of a monitor and of a workspace, or
the name of a workspace. There are two kinds:
- an **initial** rule sends a window once, when komorebi first sees it: after that the window
stays wherever you put it;
- a **permanent** rule sends the windows of the application there every time, so that a window
you take away from that workspace goes back.
The windows are sent when a window opens or is focused, when the configuration is loaded, and when
you ask for it: komorebi looks at the rules at each event about a window it manages, before it
handles it. A window that
opens is in a workspace only after its own event has been handled, so it is sent by the next
event, which is the activation KWin reports a moment later.
Only the windows in view are looked at: the one on top of each container, and the floating
windows. A window that is on its workspace already is left alone. A workspace that does not
exist yet is made, with the ones before it. When the window is on the workspace in front, it
leaves it and is hidden (it is put on the parking desktop, as the back of a stack is), and the
workspace is tiled again without it; either way, it goes to the virtual desktop of its new
workspace, so it is out of view until that workspace is shown, which brings it back and tiles it.
A floating window that goes to another monitor is moved onto that monitor.
## In komorebi.json
A workspace has `workspace_rules` and `initial_workspace_rules`, each a list of
[rules](configuration.md#rules) like the ones in `ignore_rules`:
```json
{
"monitors": [
{
"workspaces": [
{ "name": "web", "layout": "BSP" },
{
"name": "code",
"layout": "BSP",
"initial_workspace_rules": [
{ "kind": "Exe", "id": "kate", "matching_strategy": "Equals" }
],
"workspace_rules": [
{ "kind": "Class", "id": "org.kde.konsole", "matching_strategy": "Equals" }
]
}
]
}
]
}
```
The rules are made again from the file each time it is read, so a rule taken out of the file is
gone, and so are the ones `komorebic` added. The windows that are open are sent where the file
says when it has been read.
## With komorebic
[`initial-workspace-rule`](../cli/initial-workspace-rule.md) and
[`workspace-rule`](../cli/workspace-rule.md) take what the rule names (`exe`, `class`, `title` or
`path`), its text, and the index of the monitor and of the workspace;
[`initial-named-workspace-rule`](../cli/initial-named-workspace-rule.md) and
[`named-workspace-rule`](../cli/named-workspace-rule.md) take the name of the workspace instead,
and add no rule when no workspace has the name. A rule given this way matches a title or a class
that starts or ends with what it names, and an executable or a path that is exactly what it names.
A rule that is there already is not added again.
```sh
komorebic initial-workspace-rule exe kate 0 1
komorebic workspace-rule class org.kde.konsole 0 1
komorebic named-workspace-rule exe thunderbird mail
```
[`enforce-workspace-rules`](../cli/enforce-workspace-rules.md) forgets which windows the initial
rules have sent and looks at the rules again, so that every window of an application goes to the
workspace its initial rule gives. The three clear commands take rules away:
[`clear-workspace-rules`](../cli/clear-workspace-rules.md) by monitor and workspace index,
[`clear-named-workspace-rules`](../cli/clear-named-workspace-rules.md) by name, and
[`clear-all-workspace-rules`](../cli/clear-all-workspace-rules.md) all of them. The first two
also take away the rules of every other workspace of the monitor they are given, and of every
other monitor's workspace with the same index, because of how they pick the rules to keep. Which
rules the daemon has is in the `workspace_rules` of
[`komorebic global-state`](../cli/global-state.md).