Skip to content

feat: WindowRules Workspace Assignment#2214

Open
karlskewes wants to merge 3 commits into
pop-os:masterfrom
karlskewes:workspace-pinning
Open

feat: WindowRules Workspace Assignment#2214
karlskewes wants to merge 3 commits into
pop-os:masterfrom
karlskewes:workspace-pinning

Conversation

@karlskewes

@karlskewes karlskewes commented Mar 20, 2026

Copy link
Copy Markdown

Related issues

Feature

Extend WindowRules enabling launching applications on specific workspaces instead of the current active workspace.

Requires: pop-os/cosmic-settings-daemon#137

How to use

Get Application ID and Title:

Deprecated but works, see: pop-os/cosmic-protocols#70 (comment)

$ nix-shell -p wayland pkg-config

[nix-shell:~/path/to/cosmic-protocols]$  cargo run --example toplevel-list
     Running `target/debug/examples/toplevel-list`
Toplevel ObjectId(zcosmic_toplevel_handle_v1@4278190080)
	Title: Some("cargo run --example toplevel-list")
	App ID: Some("kitty")
	States: [Activated]
	Outputs: []
	Workspaces: []
Toplevel ObjectId(zcosmic_toplevel_handle_v1@4278190082)
	Title: Some("Some webpage — Mozilla Firefox")
	App ID: Some("firefox")
	States: []
	Outputs: []
	Workspaces: []

Pin workspaces using UI or via file:

$ cat ~/.config/cosmic/com.system76.CosmicComp/v1/pinned_workspaces 
[
    (
        output: (
            name: "eDP-1",
            edid: None,
        ),
        tiling_enabled: true,
        id: Some("11f90a5"),
    ),
    (
        output: (
            name: "eDP-1",
            edid: None,
        ),
        tiling_enabled: true,
        id: Some("b382cb"),
    ),
]

Define Workspace Assignment configuration file with matching id's, regex supported:

$ cat ~/.config/cosmic/com.system76.CosmicSettings.WindowRules/v1/workspace_assignment_custom
[
  (
    enabled: true,
    appid: "kitty",
    title: ".*",
    workspace_id: "11f90a5"
  ),
  (
    enabled: true,
    appid: "firefox",
    title: ".*",
    workspace_id: "b382cb"
  )
]

Disable the window rule by setting enabled: false.

Behaviours

  1. Workspaces are NOT created if the assigned workspace ID doesn't exist. A warning will be logged and the window will be launched on the current active workspace as if the assignment didn't exist.
    For example, if workspaces a and b exist but the application config pins to c, then workspace c will NOT be added.
    2026-03-20T21:37:45.920671Z WARN cosmic_comp::shell: Assigned workspace id not found: foobar1
  2. Active workspace does NOT change if the window is launched on a different workspace. For example, on workspace b, launch Firefox pinned to c, active workspace stays on b.
  3. workspace_assignment_custom is auto-reloaded when the file changes however existing windows are not moved if the assigned workspace id was changed.
  4. Declarative workspace_id's: Can define in pinned_workspaces. Doesn't reload but does load on login. Can use custom workspace_id String values, e.g: terminal, browser, work.
  5. In practice, workspaces need to be pinned as workspace.id's are created with a random generator when using UI to pin.
    • there's no code for reloading this file (I could add if desired). Changes to the file take effect on next login.
    $ cat ~/.config/cosmic/com.system76.CosmicComp/v1/pinned_workspaces
    [
     (
         output: (
             name: "eDP-1",
             edid: None,
         ),
         tiling_enabled: true,
         id: Some("11f90a5"),
     ),
     (
         output: (
             name: "eDP-1",
             edid: None,
         ),
         tiling_enabled: true,
         id: Some("b382cb"),
     ),
    ]   

Testing

flake.nix -> nix develop

When rebased onto: #2219 and using pop-os/cosmic-settings-daemon#138

# enter dev environment
nix develop

v ~/.config/cosmic/com.system76.CosmicSettings.WindowRules/v1/workspace_assignment_custom

COSMIC_COMP=winnit cargo run

# active workspace is the first pinned one
WAYLAND_DISPLAY=2 kitty & # launches on active
WAYLAND_DISPLAY=2 firefox & # launches on workspace in background (not active)
WAYLAND_DISPLAY=wayland-2 cosmic-ext-calculator # launches on active

flake.nix -> nix build

When rebased onto: #2219 and using pop-os/cosmic-settings-daemon#138

# build cosmic-comp
nix build

Can't run the resulting binary because of missing dependencies/version clashes.

NixOS package overlay

  1. Patching the NixOS package source with fork and branch.
  2. Build and install.
  3. Use appropriate config file.
  4. Launch applications and observe they are autostarted on workspaces other than the current active workspace.

UI Component

Whilst the configuration file support in this PR is sufficient for my use case, I saw mention of UI support for a similar feature in: #1292 (comment)

There will be UI to do this from cosmic-settings and the tiling applet eventually.

Could that be this? pop-os/cosmic-settings#438

Something I could pickup next perhaps. Or other window rules.

Note to reviewers

This is my first contribution to Cosmic and I may have misunderstood or completely missed project structure/styling or other conventions. Please let me know and I'll rework accordingly. Thank you!

  • "workspace assignment" naming chosen based off i3wm:
    assign [class="<application_class>"] <workspace_number>
  • separate file path/to/WindowRules/workspace_assignment_custom because it appears to be convention to have a file per feature, rather than a catch all ../WindowRules/window_rules with features: sticky, tiling exceptions, workspace assignment, etc
  • left workspace_assignment_defaults free for implementation if required.

AI Disclosure

No AI generated code in the development of this PR.

  • I have disclosed use of any AI generated code in my commit messages.
    • If you are using an LLM, and do not fully understand the changes it is making to the code base, do not create a PR.
    • In our experience, AI generated code often results in overly complex code that lacks enough context for a proper fix or feature inclusion. This results in considerably longer code reviews. Due to this, AI authored or partially authored PRs may be closed without comment.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

@karlskewes karlskewes force-pushed the workspace-pinning branch 3 times, most recently from dea7d43 to 8198d24 Compare March 23, 2026 20:55
@karlskewes karlskewes marked this pull request as ready for review March 23, 2026 20:57
@karlskewes karlskewes force-pushed the workspace-pinning branch 8 times, most recently from 69a1fd3 to ba1e37d Compare March 29, 2026 23:27
@karlskewes

Copy link
Copy Markdown
Author

Removed formatting commit, reduced Cargo changes and rebased.

@karlskewes karlskewes force-pushed the workspace-pinning branch 2 times, most recently from 3e1640f to 13259ed Compare April 12, 2026 20:05
estin added a commit to estin/cos-cli that referenced this pull request Apr 16, 2026
@karlskewes karlskewes force-pushed the workspace-pinning branch 2 times, most recently from d4087fc to e4db93b Compare May 11, 2026 21:50
@karlskewes

Copy link
Copy Markdown
Author
  1. Running this full time per: karlskewes/nixos@6d3a2d5
  2. I use custom defined workspace names, terminal, chat, browser.
  3. Corrected the PR description appid & title mixup in workspace_assignment_custom.
$ nix-shell -p wayland pkg-config

[nix-shell:~/src/github.com/karlskewes/cosmic-protocols]$ cargo run --example toplevel-list
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/toplevel-list`
Toplevel ObjectId(zcosmic_toplevel_handle_v1@4278190080)
	Title: Some("cargo run --example toplevel-list")
	App ID: Some("kitty")
	States: [Activated]
	Outputs: []
	Workspaces: []
Toplevel ObjectId(zcosmic_toplevel_handle_v1@4278190081)
	Title: Some("feat: WindowRules Workspace Assignment by karlskewes · Pull Request #2214 · pop-os/cosmic-comp — Mozilla Firefox")
	App ID: Some("firefox")
	States: []
	Outputs: []
	Workspaces: []

Workspace Assignments are a new feature enabling applications to be
consistently launched automatically onto a specific workspace ID.

This commit enables loading assignments from a new location on disk:
`com.system76.CosmicSettings.WindowRules/v1/workspace_assignment_custom`

For example:
```sh
$ cat $HOME/.config/cosmic/com.system76.CosmicSettings.WindowRules/v1/workspace_assignment_custom
[
  (
    enabled: true,
    appid: ".*",
    title: ".*kitty.*",
    workspace_id: "11f90a5"
  ),
  (
    enabled: true,
    appid: ".*",
    title: ".*firefox.*",
    workspace_id: "b382cb"
  )
]
```

This file is also watched for changes which invoke a reload of current
assignments.

Default (CosmicDE defined) assignments are not currently supported but
code and filenames have been chosen to avoid a conflict with the
standard naming.
Start application/window on workspace if it exists.
In practice, pinned workspaces with workspace id's matching the
workspace assignment id are required.

Behaviours:
1. If the assigned workspace doesn't exist then the window is launched
   on the current active workspace. This was the behaviour before this
   commit.
2. If the assigned workspace does exist, then the window is launched on
   the workspace but the workspace is not made active. On a single
   screen this may result in the window launching silently onto
   a "background workspace".
Switch to pinned revision when merged.
@karlskewes karlskewes force-pushed the workspace-pinning branch from e4db93b to ffcec17 Compare June 4, 2026 21:01
@karlskewes

Copy link
Copy Markdown
Author

When #2427 lands I will rework this to match on workspace names instead.

Assign to first matching workspace name (assuming duplicates could exist?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make it possible to let auto started applications start on a specific workspace [Feature Request] Assign application to workspace like i3wm

1 participant