[PR #1491] refactor(ring): stop exposing Ring internals #1428

Open
opened 2026-01-05 14:55:15 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/LGUG2Z/komorebi/pull/1491
Author: @JustForFun88
Created: 6/21/2025
Status: 🔄 Open

Base: masterHead: refactor_ring


📝 Commits (1)

  • f9ea220 Stop exposing Ring internals

📊 Changes

20 files changed (+683 additions, -611 deletions)

View changed files

📝 komorebi-bar/src/bar.rs (+3 -3)
📝 komorebi-bar/src/main.rs (+9 -18)
📝 komorebi-bar/src/widgets/komorebi.rs (+5 -6)
📝 komorebi-gui/src/main.rs (+1 -1)
📝 komorebi/src/border_manager/mod.rs (+8 -11)
📝 komorebi/src/container.rs (+8 -7)
📝 komorebi/src/lib.rs (+0 -1)
komorebi/src/lockable_sequence.rs (+0 -357)
📝 komorebi/src/monitor.rs (+2 -3)
📝 komorebi/src/monitor_reconciliator/mod.rs (+7 -9)
📝 komorebi/src/process_command.rs (+23 -24)
📝 komorebi/src/process_event.rs (+1 -6)
📝 komorebi/src/ring.rs (+502 -20)
📝 komorebi/src/stackbar_manager/mod.rs (+1 -1)
📝 komorebi/src/stackbar_manager/stackbar.rs (+2 -2)
📝 komorebi/src/static_config.rs (+6 -6)
📝 komorebi/src/transparency_manager.rs (+5 -5)
📝 komorebi/src/window_manager.rs (+77 -94)
📝 komorebi/src/windows_api.rs (+13 -20)
📝 komorebi/src/workspace.rs (+10 -17)

📄 Description

Summary

This PR hides the internals of the Ring<T> type and reworks its API. Direct access to the internal VecDeque<T> is removed, so interaction with Ring now happens only through its methods, making it easier and safer to use.

All lock-respecting insert/remove/swap logic is implemented directly on Ring and the separate LockableSequence trait removed.

The new API is more ergonomic and expressive for common patterns. As a result, although many new methods were added to Ring in komorebi/src/ring.rs, the total code size increased only slightly, since many typical iterator chains are now replaced by single method calls.

Motivation

  • Prevents accidental misuse by hiding internal collections and providing a clear, uniform API.
  • Enables future refactoring or switching to another implementation without breaking external code.

Usability Improvements

  • Consistent Access: Field and accessor now always return Ring, eliminating confusion between types (e.g., &monitor.workspaces vs monitor.workspaces()).

    // Before: different types, easy to misuse
    &monitor.workspaces     // &Ring<Workspace>
    monitor.workspaces()    // &VecDeque<Workspace>
    
    // After: always &Ring<Workspace>
    &monitor.workspaces
    monitor.workspaces()
    
  • Ergonomic usage: The new API is more ergonomic and expressive for common patterns

    monitors.indexed()            // replaces monitors.elements().iter().enumerate()
    monitors.position(..)         // replaces monitors.elements().iter().position(..)
    ws.floating_windows().any(..) // replaces ws.floating_windows().iter().any(..)
    

Tests

Tested on Windows 11.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/LGUG2Z/komorebi/pull/1491 **Author:** [@JustForFun88](https://github.com/JustForFun88) **Created:** 6/21/2025 **Status:** 🔄 Open **Base:** `master` ← **Head:** `refactor_ring` --- ### 📝 Commits (1) - [`f9ea220`](https://github.com/LGUG2Z/komorebi/commit/f9ea220ccbeddc515279bcf5e6b8ee25a20ab9f2) Stop exposing Ring internals ### 📊 Changes **20 files changed** (+683 additions, -611 deletions) <details> <summary>View changed files</summary> 📝 `komorebi-bar/src/bar.rs` (+3 -3) 📝 `komorebi-bar/src/main.rs` (+9 -18) 📝 `komorebi-bar/src/widgets/komorebi.rs` (+5 -6) 📝 `komorebi-gui/src/main.rs` (+1 -1) 📝 `komorebi/src/border_manager/mod.rs` (+8 -11) 📝 `komorebi/src/container.rs` (+8 -7) 📝 `komorebi/src/lib.rs` (+0 -1) ➖ `komorebi/src/lockable_sequence.rs` (+0 -357) 📝 `komorebi/src/monitor.rs` (+2 -3) 📝 `komorebi/src/monitor_reconciliator/mod.rs` (+7 -9) 📝 `komorebi/src/process_command.rs` (+23 -24) 📝 `komorebi/src/process_event.rs` (+1 -6) 📝 `komorebi/src/ring.rs` (+502 -20) 📝 `komorebi/src/stackbar_manager/mod.rs` (+1 -1) 📝 `komorebi/src/stackbar_manager/stackbar.rs` (+2 -2) 📝 `komorebi/src/static_config.rs` (+6 -6) 📝 `komorebi/src/transparency_manager.rs` (+5 -5) 📝 `komorebi/src/window_manager.rs` (+77 -94) 📝 `komorebi/src/windows_api.rs` (+13 -20) 📝 `komorebi/src/workspace.rs` (+10 -17) </details> ### 📄 Description ## Summary This PR hides the internals of the `Ring<T>` type and reworks its API. Direct access to the internal `VecDeque<T>` is removed, so interaction with `Ring` now happens only through its methods, making it easier and safer to use. All lock-respecting insert/remove/swap logic is implemented directly on `Ring` and the separate `LockableSequence` trait removed. The new API is more ergonomic and expressive for common patterns. As a result, although many new methods were added to `Ring` in `komorebi/src/ring.rs`, the total code size increased only slightly, since many typical iterator chains are now replaced by single method calls. ## Motivation - Prevents accidental misuse by hiding internal collections and providing a clear, uniform API. - Enables future refactoring or switching to another implementation without breaking external code. ### Usability Improvements - **Consistent Access:** Field and accessor now always return `Ring`, eliminating confusion between types (e.g., `&monitor.workspaces` vs `monitor.workspaces()`). ```rust // Before: different types, easy to misuse &monitor.workspaces // &Ring<Workspace> monitor.workspaces() // &VecDeque<Workspace> // After: always &Ring<Workspace> &monitor.workspaces monitor.workspaces() ``` - **Ergonomic usage:** The new API is more ergonomic and expressive for common patterns ```rust monitors.indexed() // replaces monitors.elements().iter().enumerate() monitors.position(..) // replaces monitors.elements().iter().position(..) ws.floating_windows().any(..) // replaces ws.floating_windows().iter().any(..) ``` ## Tests Tested on Windows 11. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-01-05 14:55:15 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#1428