[CODE] move Window related global state into case specific windows, and common window logic into a Window trait #307

Closed
opened 2026-01-05 14:49:38 +01:00 by adam · 0 comments
Owner

Originally created by @raggi on GitHub (Mar 3, 2024).

I started a demo of the outcome for discussion here: 8f6d2bf22c

The general idea here is a few things:

  • Move from lazy static to OnceLock for global state
  • Add accessors around the OnceLocks to make them easy to call (e.g. border_window())
  • Fold related accessors into the OnceLock container, with internal synchronization
    • e.g. border width becomes a locked property inside Border
  • Centralize other logical state where appropriate into these new objects where appropriate
    • e.g. Border hide/show becomes a single property controlled by methods in Border's impl.
  • Centralize the callbacks as well
    • e.g. The border paint callback moves from windows_callbacks.rs into border.rs.

In the above example with Border done this way, border becomes almost freestanding, it could move into a module or crate with minimal further dependency flattening.

This leads to the next step though:

  • Migrate much of the Window code into a Window trait that depends on a hwnd() -> HWND accessor
  • Hidden and Border can now impl Window, just overriding hwnd() to return their internal field, and have the richness of all the associated functions.

These can be done step-by-step, rather than all at once.

Originally created by @raggi on GitHub (Mar 3, 2024). I started a demo of the outcome for discussion here: https://github.com/raggi/komorebi/commit/8f6d2bf22c76ec0bc0062d5250ef02bc5ca5899d The general idea here is a few things: - Move from lazy static to OnceLock for global state - Add accessors around the OnceLocks to make them easy to call (e.g. `border_window()`) - Fold related accessors into the OnceLock container, with internal synchronization - e.g. border width becomes a locked property inside Border - Centralize other logical state where appropriate into these new objects where appropriate - e.g. Border hide/show becomes a single property controlled by methods in Border's impl. - Centralize the callbacks as well - e.g. The border paint callback moves from windows_callbacks.rs into border.rs. In the above example with Border done this way, border becomes almost freestanding, it could move into a module or crate with minimal further dependency flattening. This leads to the next step though: - Migrate much of the Window code into a Window trait that depends on a `hwnd() -> HWND` accessor - Hidden and Border can now impl Window, just overriding hwnd() to return their internal field, and have the richness of all the associated functions. These can be done step-by-step, rather than all at once.
adam closed this issue 2026-01-05 14:49:38 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#307