Skip to content

Build1 publisher2 min readPublished

A row-major index over the flat Vec turns COSMIC's workspace strip into a wrapping 5x5 grid

One optional RON field switches the 5x5 grid on, and the ext-workspace coordinate pipeline the sidebar reads stays stock. The cost is an apt hold on two System76 packages and a rebase at every COSMIC release.

The Engineer · Build desk

Photograph accompanying A row-major index over the flat Vec turns COSMIC's workspace strip into a wrapping 5x5 grid
Photo: dev.to

What happened

  • A developer patched two System76 crates, cosmic-comp at commit bb584aa and cosmic-workspaces 1.0.12, on a branch named cosmic-grid in each repository, pinning both to the versions installed on the machine.
  • The grid is a row-major index over the existing flat Vec<Workspace>, idx = row * cols + col, and login drops the user on the center cell of the 25-cell layout.
  • Turning it on adds one optional field, workspace_grid: Option<(u32, u32)> with #[serde(default)], so cosmic-settings and the applets ignore the key and no other package needed rebuilding.
  • The compositor branch totals 384 insertions and 48 deletions across seven files in two commits on top of the pin.
  • install.sh backs up the stock binaries, installs the patched ones to /usr/bin/ and holds both packages in apt, and rollback.sh puts the originals back in one command.

Compiled by The EngineerSomething wrong?How this is made

Why it matters

  • constraint The apt hold that stops a system update overwriting the patch also stops upstream fixes for cosmic-comp and cosmic-workspaces reaching the machine, so every COSMIC release becomes a rebase decision rather than an install.
  • cost The maintenance bill lands on input handling: 220 of the first commit's 319 insertions are in src/input/actions.rs and src/input/mod.rs, and the animation commit touches both again, so any upstream refactor of that code hits the patch first.
  • capability Grid dimensions are a config tuple, so a 3x3 or a 4x6 needs a config edit and a rebuild of two binaries, with no change to the workspace model.

Four fingers up, and cosmic-comp's input path turns the direction into a delta on the flat Vec: minus cols for up, minus one for left, with each axis wrapping on its own [8]. The natural-scroll convention is preserved exactly, so up/down muscle memory carries over and left/right is additive [8]. The new index goes out through `set_workspace_coordinates`, which emits the ext-workspace protocol `Coordinates` event [6]. cctk surfaces that as `WorkspaceInfo.coordinates`, and cosmic-workspaces draws from it [6]. According to the post, that pipeline is already 2D in stock cosmic-comp, and the grid only changes how the coordinates are computed and rendered [6].

The first commit did not finish the job. dbe7678 added the mode with 319 insertions and 28 deletions across six files, 137 of them in `src/input/actions.rs` [13]. A second commit, 54f7719, animates swipes along the gesture axis instead of the layout axis: 67 insertions, 22 deletions, four files, one of them `src/shell/focus/order.rs` [14].

The layout claim in the post is that "no workspace is ever more than two gestures away" [19]. On a wrapping row of five cells with the cursor at index 2, the farthest cell is two steps away [22]. One swipe moves one axis, and both axes can be two off at once, so the corner cells sit four swipes from the center [23].

The post calls the compositor change "roughly 432 lines of Rust" [15]. That figure is insertions plus deletions, 384 and 48 [20]. Added code across the two repositories comes to 519 lines, counting the 135 insertions in cosmic-workspaces' `src/view/mod.rs` [27]. The post does not give line counts for the follow-up commit that fixed the sidebar build [16].

`install.sh` archives the stock binaries before it writes anything: 27.3 MB of cosmic-comp and 30.2 MB of cosmic-workspaces, 57.5 MB sitting in `stock/` [12][21]. It then runs `apt-mark hold` on both packages so a system update cannot silently overwrite the patched binaries, and `rollback.sh` restores the originals and releases the holds [11]. The overview app is coupled to the patched compositor crate: its `Cargo.toml` carries a `[patch."https://github.com/pop-os/cosmic-comp"]` section [17].

The developer wrote that "The intellectual core of the patch is that a grid is a row-major mapping, not a workspace-model rewrite" [18]. I would take that trade on a compositor I had to keep running. Workspaces are still created on demand and removed when empty, so memory behavior matches stock [10].

What to watch

  • Whether upstream cosmic-comp accepts workspace_grid as an optional config field; a WorkspaceLayout enum variant instead would change what stock readers do with the file.
  • The next cosmic-comp release, and whether the 104 insertions in src/shell/mod.rs rebase cleanly off the bb584aa pin.
  • Whether cosmic-workspaces ships changes to src/view/mod.rs, where the 135-line sidebar patch lands.
Loading claim ledger
Loading source directory links
Loading share composer
Loading topic controls
Loading related stories