header_bar: add WindowControlsPosition (macOS-style left controls)

Adds a new public enum `WindowControlsPosition { Start, End }` and a
matching field on `HeaderBar`, allowing window controls (close / minimize
/ maximize) to be packed on the start side of the headerbar (macOS
style, icon order close → minimize → maximize) instead of the default
end side (Linux / GNOME style, minimize → maximize → close).

Wiring:
- `crate::widget::WindowControlsPosition` re-exported alongside
  `HeaderBar`.
- `HeaderBar::controls_position(Option<WindowControlsPosition>)` setter;
  when left unset, falls back to `crate::config::window_controls_position()`
  (reads `CosmicTk.window_controls_position`), mirroring how `density`
  falls back to `header_size()`.
- New `CosmicTk.window_controls_position` field with default `End` for
  backwards compatibility; serde-friendly enum so existing configs keep
  working via `#[serde(default)]` semantics.

Tested with cosmic-yoterm, cosmic-settings, cosmic-edit, cosmic-files
rebuilt against this libcosmic via a local `[patch]` override. Config
changes picked up live through the existing cosmic-config subscription.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lionel DARNIS 2026-04-22 15:08:12 +02:00
parent b4a8fd65e6
commit afff77bbfe
3 changed files with 94 additions and 24 deletions

View file

@ -4,6 +4,7 @@
//! Configurations available to libcosmic applications.
use crate::cosmic_theme::Density;
use crate::widget::WindowControlsPosition;
use cosmic_config::cosmic_config_derive::CosmicConfigEntry;
use cosmic_config::{Config, CosmicConfigEntry};
use serde::{Deserialize, Serialize};
@ -67,6 +68,12 @@ pub fn header_size() -> Density {
COSMIC_TK.read().unwrap().header_size
}
/// Position of the window control buttons (close / minimize / maximize).
#[allow(clippy::missing_panics_doc)]
pub fn window_controls_position() -> WindowControlsPosition {
COSMIC_TK.read().unwrap().window_controls_position
}
/// Interface density.
#[allow(clippy::missing_panics_doc)]
pub fn interface_density() -> Density {
@ -109,6 +116,10 @@ pub struct CosmicTk {
/// Mono font family
pub monospace_font: FontConfig,
/// Side on which window control buttons (close / minimize / maximize)
/// are placed. `End` = right (Linux / GNOME), `Start` = left (macOS).
pub window_controls_position: WindowControlsPosition,
}
impl Default for CosmicTk {
@ -132,6 +143,7 @@ impl Default for CosmicTk {
stretch: iced::font::Stretch::Normal,
style: iced::font::Style::Normal,
},
window_controls_position: WindowControlsPosition::default(),
}
}
}