diff --git a/crates/tunal-theme/src/lib.rs b/crates/tunal-theme/src/lib.rs index 5428f56..320b527 100644 --- a/crates/tunal-theme/src/lib.rs +++ b/crates/tunal-theme/src/lib.rs @@ -3,8 +3,8 @@ mod palette; mod portal; -pub use palette::{FALLBACK_SEED, Palette, Palettes}; -pub use portal::{read, watch}; +pub use palette::{FALLBACK_SEED, Palette, Palettes, Style}; +pub use portal::{pick_color, read, watch}; /// Accent colour as the portal reports it: sRGB components in `0.0..=1.0`. #[derive(Debug, Clone, Copy, PartialEq)] diff --git a/crates/tunal-theme/src/palette.rs b/crates/tunal-theme/src/palette.rs index 3ff3ae1..26af84b 100644 --- a/crates/tunal-theme/src/palette.rs +++ b/crates/tunal-theme/src/palette.rs @@ -1,6 +1,6 @@ -//! Light and dark Material 3 schemes from a seed colour (`material-colors`, tonal spot). +//! Light and dark Material 3 schemes from a seed colour (`material-colors`). -use material_colors::{color::Rgb, scheme::Scheme, theme::ThemeBuilder}; +use material_colors::{color::Rgb, dynamic_color::Variant, scheme::Scheme, theme::ThemeBuilder}; /// Seed used when the desktop sets no accent (`0xRRGGBB`, a muted blue; D-022). pub const FALLBACK_SEED: u32 = 0x3F6FB5; @@ -58,6 +58,17 @@ palette!( scrim, ); +/// How colourful a scheme is. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +pub enum Style { + #[default] + TonalSpot, + Vibrant, + Expressive, + Neutral, + Monochrome, +} + /// Both schemes for one seed. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Palettes { @@ -68,7 +79,18 @@ pub struct Palettes { impl Palettes { /// Tonal-spot schemes for `seed` (`0xRRGGBB`; any alpha byte is ignored). pub fn from_seed(seed: u32) -> Self { + Self::styled(seed, Style::TonalSpot) + } + + pub fn styled(seed: u32, style: Style) -> Self { let schemes = ThemeBuilder::with_source(Rgb::from_u32(seed)) + .variant(match style { + Style::TonalSpot => Variant::TonalSpot, + Style::Vibrant => Variant::Vibrant, + Style::Expressive => Variant::Expressive, + Style::Neutral => Variant::Neutral, + Style::Monochrome => Variant::Monochrome, + }) .build() .schemes; Self { diff --git a/crates/tunal-theme/src/portal.rs b/crates/tunal-theme/src/portal.rs index 32cfa6e..f88921e 100644 --- a/crates/tunal-theme/src/portal.rs +++ b/crates/tunal-theme/src/portal.rs @@ -1,10 +1,11 @@ -//! `org.freedesktop.portal.Settings` over the session bus (zbus blocking API). +//! `org.freedesktop.portal.Settings` and the screen colour picker over the session bus (zbus blocking API). +use std::collections::HashMap; use std::thread::{self, JoinHandle}; use zbus::blocking::{Connection, Proxy, proxy::Builder}; use zbus::proxy::CacheProperties; -use zbus::zvariant::{OwnedValue, Value}; +use zbus::zvariant::{OwnedObjectPath, OwnedValue, Value}; use crate::{Accent, Appearance, ColorScheme}; @@ -63,6 +64,47 @@ fn watch_loop(on_change: impl Fn(Appearance)) -> zbus::Result<()> { Ok(()) } +/// Lets the user pick a colour from the screen (the Screenshot portal) and waits for it: +/// `Ok(None)` when they cancel. Blocks; call it off the UI thread. +pub fn pick_color() -> zbus::Result> { + const TOKEN: &str = "tunal_pick_color"; + let conn = Connection::session()?; + let sender = conn + .unique_name() + .map(|n| n.trim_start_matches(':').replace('.', "_")) + .unwrap_or_default(); + // Subscribe at the path the request will have, so a quick answer is not lost. + let request: Proxy = Builder::new(&conn) + .destination("org.freedesktop.portal.Desktop")? + .path(format!( + "/org/freedesktop/portal/desktop/request/{sender}/{TOKEN}" + ))? + .interface("org.freedesktop.portal.Request")? + .cache_properties(CacheProperties::No) + .build()?; + let mut responses = request.receive_signal("Response")?; + let options = HashMap::from([("handle_token", Value::from(TOKEN))]); + let portal = Proxy::new( + &conn, + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.portal.Screenshot", + )?; + let _: OwnedObjectPath = portal.call("PickColor", &("", options))?; + let Some(msg) = responses.next() else { + return Ok(None); + }; + let (code, results) = msg + .body() + .deserialize::<(u32, HashMap)>()?; + // 0 picked, 1 cancelled, 2 ended some other way. + match code { + 0 => Ok(results.get("color").and_then(parse_accent).map(|c| c.rgb())), + 1 => Ok(None), + _ => Err(zbus::Error::Failure("the colour picker failed".into())), + } +} + fn connect() -> zbus::Result> { let conn = Connection::session()?; Builder::new(&conn) diff --git a/crates/tunal/src/config.rs b/crates/tunal/src/config.rs index e5b5957..5c0c91d 100644 --- a/crates/tunal/src/config.rs +++ b/crates/tunal/src/config.rs @@ -101,6 +101,28 @@ pub enum Motion { Full, } +/// Light or dark colours. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum Scheme { + #[default] + System, + Light, + Dark, +} + +/// How colourful the palette is. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "lowercase")] +pub enum ColorStyle { + #[default] + Tonal, + Vibrant, + Expressive, + Neutral, + Monochrome, +} + /// How modified dates read: "3 hours ago" turning into a date, or always date and time. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] @@ -210,6 +232,12 @@ pub struct Settings { pub sort: Sort, pub sort_descending: bool, pub group: Group, + pub scheme: Scheme, + /// The seed colour of the palette (`#rrggbb`); empty follows the desktop accent. + pub palette: String, + pub color_style: ColorStyle, + /// Cookie and clover containers behind icons; off draws the plain icon. + pub icon_shapes: bool, pub motion: Motion, pub date_style: DateStyle, pub clock: Clock, @@ -254,6 +282,10 @@ impl Default for Settings { sort: Sort::Name, sort_descending: false, group: Group::None, + scheme: Scheme::System, + palette: String::new(), + color_style: ColorStyle::Tonal, + icon_shapes: true, motion: Motion::System, date_style: DateStyle::Relative, clock: Clock::H12, diff --git a/crates/tunal/src/settings.rs b/crates/tunal/src/settings.rs index 018471d..474d445 100644 --- a/crates/tunal/src/settings.rs +++ b/crates/tunal/src/settings.rs @@ -9,14 +9,14 @@ use slint::{ComponentHandle, ModelRc, VecModel}; use crate::actions::{Action, Actions}; use crate::config::{ - self, Click, Clock, DateStyle, EmptyDouble, Executables, FrameUnit, Group, MiddleEmpty, - MiddleItem, Motion, SideButtons, Sort, View, + self, Click, Clock, ColorStyle, DateStyle, EmptyDouble, Executables, FrameUnit, Group, + MiddleEmpty, MiddleItem, Motion, Scheme, SideButtons, Sort, View, }; use crate::folder::format; use crate::keymap::{Chord, Command}; use crate::menus::{Context, SEPARATOR}; use crate::shell::Shell; -use crate::{EditRow, KeyRow, MainWindow, SettingsData, theme_bridge}; +use crate::{ColorPicks, EditRow, KeyRow, MainWindow, SettingsData, Theme, theme_bridge}; pub struct SettingsUi { me: Weak, @@ -53,6 +53,7 @@ impl SettingsUi { }); let cfg = config::load::("settings"); theme_bridge::set_motion(ui, cfg.motion); + theme_bridge::set_colors_from(ui, &cfg); format::set_dates(cfg.date_style, cfg.clock); settings.bind(ui); let shell = Rc::downgrade(shell); @@ -81,6 +82,10 @@ impl SettingsUi { sort: cfg.sort as i32, sort_descending: cfg.sort_descending, group: cfg.group as i32, + scheme: cfg.scheme as i32, + palette: cfg.palette.as_str().into(), + color_style: cfg.color_style as i32, + icon_shapes: cfg.icon_shapes, motion: cfg.motion as i32, date_style: cfg.date_style as i32, clock: cfg.clock as i32, @@ -107,7 +112,10 @@ impl SettingsUi { let Some(ui) = self.ui.upgrade() else { return; }; - ui.set_settings(Self::data(&config::load("settings"))); + let cfg: config::Settings = config::load("settings"); + ui.set_settings(Self::data(&cfg)); + ui.global::().set_message("".into()); + Self::show_swatches(&ui, &cfg); ui.set_menu_contexts(ModelRc::new(VecModel::from( Context::ALL .iter() @@ -119,6 +127,56 @@ impl SettingsUi { self.stop_recording(); } + fn show_swatches(ui: &MainWindow, cfg: &config::Settings) { + let dark = ui.global::().get_dark(); + let picks = ui.global::(); + picks.set_swatches(ModelRc::new(VecModel::from(theme_bridge::swatches( + cfg, dark, + )))); + } + + /// Takes `text` as the palette's seed when it is a `#rrggbb` colour. + fn set_palette(&self, text: &str) { + let Some(ui) = self.ui.upgrade() else { + return; + }; + let picks = ui.global::(); + let Some(seed) = theme_bridge::parse_hex(text) else { + picks.set_message("Use six hex digits, such as #3f6fb5.".into()); + return; + }; + picks.set_message("".into()); + let mut data = ui.get_settings(); + data.palette = format!("#{seed:06x}").into(); + ui.set_settings(data.clone()); + self.changed(data); + } + + /// Picks a colour from the screen; the desktop draws the picker. + fn pick_color(&self) { + let Some(ui) = self.ui.upgrade() else { + return; + }; + ui.global::().set_picking(true); + ui.global::().set_message("".into()); + let weak = self.ui.clone(); + std::thread::spawn(move || { + let picked = tunal_theme::pick_color(); + let _ = weak.upgrade_in_event_loop(move |ui| { + let picks = ui.global::(); + picks.set_picking(false); + match picked { + Ok(Some(seed)) => picks.invoke_accepted(format!("#{seed:06x}").into()), + Ok(None) => {} + Err(e) => { + eprintln!("tunal: colour picker: {e}"); + picks.set_message("This desktop has no colour picker.".into()); + } + } + }); + }); + } + fn changed(&self, data: SettingsData) { let mut cfg: config::Settings = config::load("settings"); cfg.restore_session = data.restore_session; @@ -130,6 +188,17 @@ impl SettingsUi { cfg.sort_descending = data.sort_descending; cfg.group = [Group::None, Group::Type, Group::Modified, Group::Size] [data.group.clamp(0, 3) as usize]; + cfg.scheme = + [Scheme::System, Scheme::Light, Scheme::Dark][data.scheme.clamp(0, 2) as usize]; + cfg.palette = data.palette.into(); + cfg.color_style = [ + ColorStyle::Tonal, + ColorStyle::Vibrant, + ColorStyle::Expressive, + ColorStyle::Neutral, + ColorStyle::Monochrome, + ][data.color_style.clamp(0, 4) as usize]; + cfg.icon_shapes = data.icon_shapes; cfg.motion = [Motion::System, Motion::Reduce, Motion::Full][data.motion.clamp(0, 2) as usize]; cfg.date_style = @@ -172,6 +241,8 @@ impl SettingsUi { if let Some(ui) = self.ui.upgrade() { cfg.show_sidebar = ui.get_show_sidebar(); theme_bridge::set_motion(&ui, cfg.motion); + theme_bridge::set_colors_from(&ui, &cfg); + Self::show_swatches(&ui, &cfg); } config::store("settings", &cfg); format::set_dates(cfg.date_style, cfg.clock); @@ -428,6 +499,19 @@ impl SettingsUi { }); }}; } + let picks = ui.global::(); + let me = self.me.clone(); + picks.on_accepted(move |text| { + if let Some(s) = me.upgrade() { + s.set_palette(&text); + } + }); + let me = self.me.clone(); + picks.on_pick(move || { + if let Some(s) = me.upgrade() { + s.pick_color(); + } + }); on!(on_settings_opening, |s| s.opening()); on!(on_settings_changed, |s, data| s.changed(data)); on!(on_menu_context_selected, |s, i| s diff --git a/crates/tunal/src/theme_bridge.rs b/crates/tunal/src/theme_bridge.rs index 9e6aa54..2713163 100644 --- a/crates/tunal/src/theme_bridge.rs +++ b/crates/tunal/src/theme_bridge.rs @@ -1,12 +1,13 @@ //! Feeds the desktop appearance (and agent overrides) into the Slint `Theme` and `MotionPrefs`. +use std::cell::{Cell, RefCell}; use std::sync::atomic::{AtomicBool, AtomicU8, Ordering}; use slint::{Color, ComponentHandle}; -use tunal_theme::{Appearance, ColorScheme, Palette, Palettes}; +use tunal_theme::{Appearance, ColorScheme, Palette, Palettes, Style}; use crate::config; -use crate::{Gallery, MainWindow, MotionPrefs, Shapes, Theme, shapes}; +use crate::{Gallery, MainWindow, MotionPrefs, Shapes, Swatch, Theme, shapes}; /// Overrides for agents and screenshots: `TUNAL_SEED=#rrggbb`, `TUNAL_SCHEME=light|dark`, /// `TUNAL_REDUCED_MOTION=1`. Unset or invalid values leave the portal value in place. @@ -21,8 +22,7 @@ impl Overrides { pub fn from_env() -> Self { let var = |name| std::env::var(name).ok().filter(|v: &String| !v.is_empty()); let seed = var("TUNAL_SEED").and_then(|v| { - let hex = v.strip_prefix('#').filter(|h| h.len() == 6); - let seed = hex.and_then(|h| u32::from_str_radix(h, 16).ok()); + let seed = parse_hex(&v); if seed.is_none() { eprintln!("tunal: ignoring TUNAL_SEED={v:?}, expected #rrggbb"); } @@ -45,6 +45,85 @@ impl Overrides { } } +/// `#rrggbb` (the `#` may be missing) as `0xRRGGBB`. +pub fn parse_hex(text: &str) -> Option { + let hex = text.trim().trim_start_matches('#'); + (hex.len() == 6 && hex.bytes().all(|b| b.is_ascii_hexdigit())) + .then(|| u32::from_str_radix(hex, 16).ok()) + .flatten() +} + +/// The colour choices of the settings. +#[derive(Clone, Copy, Default)] +struct Colors { + seed: Option, + scheme: Option, + style: Style, +} + +// UI thread only: the settings' colours, and what the desktop last said so a change of +// either gives the right palette at once. +thread_local! { + static COLORS: Cell = Cell::default(); + static DESKTOP: RefCell> = const { RefCell::new(None) }; +} + +/// Applies the colour settings now. +pub fn set_colors_from(ui: &impl Themed, cfg: &config::Settings) { + COLORS.set(Colors { + seed: parse_hex(&cfg.palette), + scheme: match cfg.scheme { + config::Scheme::System => None, + config::Scheme::Light => Some(ColorScheme::Light), + config::Scheme::Dark => Some(ColorScheme::Dark), + }, + style: match cfg.color_style { + config::ColorStyle::Tonal => Style::TonalSpot, + config::ColorStyle::Vibrant => Style::Vibrant, + config::ColorStyle::Expressive => Style::Expressive, + config::ColorStyle::Neutral => Style::Neutral, + config::ColorStyle::Monochrome => Style::Monochrome, + }, + }); + ui.theme().set_icon_shapes(cfg.icon_shapes); + // Before `start` there is nothing to repaint; it applies these itself. + if let Some((appearance, overrides)) = DESKTOP.with_borrow(|d| *d) { + apply(ui, &appearance, overrides); + } +} + +/// The seeds the settings offer, round the colour wheel. +const PRESETS: [u32; 10] = [ + 0x6750A4, 0x3F51B5, 0x0061A4, 0x006A6A, 0x386A20, 0x6C5F00, 0x8B5000, 0xB3261E, 0x984061, + 0x8E4585, +]; + +/// The palette choices as the settings draw them: the desktop's accent (empty seed), the +/// presets, and the chosen colour when it is none of these. +pub fn swatches(cfg: &config::Settings, dark: bool) -> Vec { + let style = COLORS.get().style; + let swatch = |name: String, seed: u32| { + let palettes = Palettes::styled(seed, style); + let palette = if dark { palettes.dark } else { palettes.light }; + Swatch { + seed: name.into(), + top: Color::from_argb_encoded(palette.primary), + left: Color::from_argb_encoded(palette.secondary_container), + right: Color::from_argb_encoded(palette.tertiary), + } + }; + let desktop = DESKTOP.with_borrow(|d| d.map_or(tunal_theme::FALLBACK_SEED, |(a, _)| a.seed())); + let custom = parse_hex(&cfg.palette).filter(|seed| !PRESETS.contains(seed)); + std::iter::once(swatch(String::new(), desktop)) + .chain( + PRESETS + .into_iter() + .chain(custom) + .map(|seed| swatch(format!("#{seed:06x}"), seed)), + ) + .collect() +} + /// The Motion choice of the settings (0 follow the system, 1 reduce, 2 never reduce) and what /// the desktop last said, so a change of either gives the right flag at once. static MOTION: AtomicU8 = AtomicU8::new(0); @@ -100,9 +179,17 @@ pub fn start(ui: &impl Themed, overrides: Overrides) { } pub fn apply(ui: &impl Themed, appearance: &Appearance, overrides: Overrides) { - let seed = overrides.seed.unwrap_or_else(|| appearance.seed()); - let scheme = overrides.scheme.unwrap_or(appearance.scheme); - let palettes = Palettes::from_seed(seed); + DESKTOP.set(Some((*appearance, overrides))); + let colors = COLORS.get(); + let seed = overrides + .seed + .or(colors.seed) + .unwrap_or_else(|| appearance.seed()); + let scheme = overrides + .scheme + .or(colors.scheme) + .unwrap_or(appearance.scheme); + let palettes = Palettes::styled(seed, colors.style); let palette = match scheme { ColorScheme::Light => palettes.light, ColorScheme::Dark => palettes.dark, diff --git a/crates/tunal/ui/app.slint b/crates/tunal/ui/app.slint index af32e4a..ca152cb 100644 --- a/crates/tunal/ui/app.slint +++ b/crates/tunal/ui/app.slint @@ -34,6 +34,7 @@ import { SecretPromptDialog, SecretPromptData } from "dialogs/secret-prompt.slin import { Dnd, DropAction, DropMenu, DropTarget } from "components/drop-menu.slint"; export { Theme, Shapes, ShapeKind, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow } +export { ColorPicks, Swatch } from "dialogs/appearance-page.slint"; export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo, SettingsData, EditRow } export { PlayerData, FolderActions, ViewKeys, KeyRow, ConnectionData, HostKeyData, SecretPromptData } export { PropertiesInfo, PropRow, AppRow, IconChoice, Dnd, DropAction, DropTarget, TagEditorData, TagField, TagLookupData, ReleaseRow, MapRow } diff --git a/crates/tunal/ui/components/list-row.slint b/crates/tunal/ui/components/list-row.slint index f73be2d..b9d6d01 100644 --- a/crates/tunal/ui/components/list-row.slint +++ b/crates/tunal/ui/components/list-row.slint @@ -85,6 +85,7 @@ export component ListRow inherits StateLayer { Shape { size: root.shape-size; + plain: !Theme.icon-shapes; shape: root.shape; active-shape: root.active-shape; active: root.selected; diff --git a/crates/tunal/ui/components/shape.slint b/crates/tunal/ui/components/shape.slint index fb43bee..ac2b86d 100644 --- a/crates/tunal/ui/components/shape.slint +++ b/crates/tunal/ui/components/shape.slint @@ -51,6 +51,8 @@ export component Shape { in property size: 40px; // Glyph size as a share of the container. in property glyph-ratio: 0.55; + // No container: the icon alone, larger. + in property plain; // 0 = `shape`, 1 = `active-shape`. property t: root.active ? 1 : 0; @@ -66,7 +68,7 @@ export component Shape { // a margin round the 100-unit outline: the software renderer cuts a path flat where it // meets its element's left and right edges. property side: min(root.width, root.height); - Path { + if !root.plain: Path { width: root.side * (1 + 2 * Theme.shape-margin); height: self.width; x: (root.width - self.width) / 2; @@ -86,7 +88,7 @@ export component Shape { if root.has-picture: Image { x: (root.width - self.width) / 2; y: (root.height - self.height) / 2; - width: root.size * root.glyph-ratio * 1.3; + width: root.plain ? root.size * 0.9 : root.size * root.glyph-ratio * 1.3; height: self.width; source: root.picture; image-fit: contain; @@ -96,8 +98,8 @@ export component Shape { x: (root.width - self.width) / 2; y: (root.height - self.height) / 2; glyph: root.glyph; - size: root.size * root.glyph-ratio; - color: root.glyph-color; + size: root.size * (root.plain ? 0.75 : root.glyph-ratio); + color: root.plain && root.active ? Theme.on-secondary-container : root.glyph-color; } // Overlays such as a link badge. diff --git a/crates/tunal/ui/dialogs/appearance-page.slint b/crates/tunal/ui/dialogs/appearance-page.slint new file mode 100644 index 0000000..e4b1cab --- /dev/null +++ b/crates/tunal/ui/dialogs/appearance-page.slint @@ -0,0 +1,179 @@ +import { Theme } from "../theme.slint"; +import { Motion } from "../motion.slint"; +import { Button, ButtonKind } from "../components/button.slint"; +import { StateLayer } from "../components/state-layer.slint"; +import { Switch } from "../components/switch.slint"; +import { TextField } from "../components/text-field.slint"; +import { ChoiceSetting, Setting } from "setting-rows.slint"; + +// A palette to choose: its seed (empty: the desktop's accent) and three of its colours. +export struct Swatch { + seed: string, + top: color, + left: color, + right: color, +} + +// The palette choices and the colour picker (settings.rs). +export global ColorPicks { + in property <[Swatch]> swatches; + in property message; + // The desktop's colour picker is open. + in property picking; + callback accepted(text: string); + callback pick(); +} + +component SwatchButton inherits StateLayer { + in property swatch; + in property selected; + + width: Theme.swatch + 2 * Theme.space-1; + height: self.width; + border-radius: Theme.corner-full(self.height); + border-width: root.selected ? Theme.swatch-ring : 0; + border-color: Theme.primary; + tint: Theme.on-surface; + squeeze: Motion.squeeze-small; + tooltip: root.swatch.seed == "" ? "Desktop accent" : root.swatch.seed; + accessible-role: radio-button; + accessible-label: root.tooltip; + accessible-checked: root.selected; + accessible-action-default => { + self.activate(); + } + + Rectangle { + property side: Theme.swatch - (root.selected ? Theme.space-1 : 0px); + x: (root.width - self.width) / 2; + y: (root.height - self.height) / 2; + width: self.side; + height: self.side; + animate side { + duration: Motion.time(Motion.short4); + easing: Motion.standard; + } + + Path { + viewbox-width: 100; + viewbox-height: 100; + fill: root.swatch.top; + commands: "M 0 50 A 50 50 0 0 1 100 50 Z"; + } + + Path { + viewbox-width: 100; + viewbox-height: 100; + fill: root.swatch.left; + commands: "M 0 50 A 50 50 0 0 0 50 100 L 50 50 Z"; + } + + Path { + viewbox-width: 100; + viewbox-height: 100; + fill: root.swatch.right; + commands: "M 100 50 A 50 50 0 0 1 50 100 L 50 50 Z"; + } + } +} + +// Colours, icon containers and animations. +export component AppearancePage inherits VerticalLayout { + in property scheme; + in property palette; + in property color-style; + in property icon-shapes; + in property motion; + callback scheme-picked(int); + callback palette-picked(string); + callback style-picked(int); + callback shapes-toggled(bool); + callback motion-picked(int); + + alignment: start; + + ChoiceSetting { + title: "Theme"; + names: ["Follow the system", "Light", "Dark"]; + current: root.scheme; + picked(i) => { + root.scheme-picked(i); + } + } + + Setting { + title: "Palette"; + hint: "The first one is the desktop's accent."; + Button { + text: ColorPicks.picking ? "Picking…" : "Pick…"; + icon: "\u{e3b8}"; + kind: ButtonKind.tonal; + enabled: !ColorPicks.picking; + clicked => { + ColorPicks.pick(); + } + } + } + + HorizontalLayout { + alignment: start; + spacing: Theme.hairline; + + for swatch in ColorPicks.swatches: SwatchButton { + swatch: swatch; + selected: swatch.seed == root.palette; + clicked => { + root.palette-picked(swatch.seed); + } + } + } + + HorizontalLayout { + alignment: start; + padding-top: Theme.space-2; + + TextField { + width: 220px; + label: "Your own colour"; + placeholder: "#3f6fb5"; + property seed: root.palette; + text: self.seed; + changed seed => { + self.text = self.seed; + } + error: ColorPicks.message; + accepted(text) => { + ColorPicks.accepted(text); + } + } + } + + ChoiceSetting { + title: "Colour style"; + names: ["Tonal", "Vibrant", "Expressive", "Neutral", "Mono"]; + current: root.color-style; + picked(i) => { + root.style-picked(i); + } + } + + Setting { + title: "Shapes behind icons"; + hint: "The cookie and clover cutouts. Off shows just the icon."; + Switch { + checked: root.icon-shapes; + changed checked => { + root.shapes-toggled(self.checked); + } + } + } + + ChoiceSetting { + title: "Animations"; + names: ["Follow the system", "Always reduce", "Never reduce"]; + current: root.motion; + picked(i) => { + root.motion-picked(i); + } + } +} diff --git a/crates/tunal/ui/dialogs/settings.slint b/crates/tunal/ui/dialogs/settings.slint index 35bdf11..45d5bdb 100644 --- a/crates/tunal/ui/dialogs/settings.slint +++ b/crates/tunal/ui/dialogs/settings.slint @@ -8,6 +8,7 @@ import { Switch } from "../components/switch.slint"; import { Icons } from "../components/icon.slint"; import { MenuEditor, EditRow } from "menu-editor.slint"; import { ChoiceSetting, Setting, Stepper } from "setting-rows.slint"; +import { AppearancePage } from "appearance-page.slint"; import { MousePage } from "mouse-page.slint"; import { ShortcutEditor, KeyRow } from "shortcut-editor.slint"; @@ -23,6 +24,11 @@ export struct SettingsData { sort: int, sort-descending: bool, group: int, + // Appearance page: indexes into its choices, and the palette's seed (empty: the desktop's). + scheme: int, + palette: string, + color-style: int, + icon-shapes: bool, motion: int, // 0 relative, 1 absolute. date-style: int, @@ -82,8 +88,8 @@ export component SettingsDialog inherits Dialog { callback menu-reset(); callback closed(); - property <[string]> pages: ["General", "View", "Previews", "Motion", "Network", "Context menus", "Mouse", "Shortcuts"]; - property <[string]> glyphs: ["\u{e8b8}", "\u{e8f4}", "\u{e3f4}", "\u{e037}", "\u{e2bd}", "\u{e5d4}", "\u{e323}", "\u{e312}"]; + property <[string]> pages: ["General", "View", "Previews", "Appearance", "Network", "Context menus", "Mouse", "Shortcuts"]; + property <[string]> glyphs: ["\u{e8b8}", "\u{e8f4}", "\u{e3f4}", "\u{e40a}", "\u{e2bd}", "\u{e5d4}", "\u{e323}", "\u{e312}"]; title: "Settings"; dialog-width: 780px; @@ -324,25 +330,31 @@ export component SettingsDialog inherits Dialog { } } - if root.page == 3: VerticalLayout { - alignment: start; - - ChoiceSetting { - title: "Animations"; - names: ["Follow the system", "Always reduce", "Never reduce"]; - current: root.data.motion; - picked(i) => { - root.data.motion = i; - root.changed(root.data); - } + if root.page == 3: AppearancePage { + scheme: root.data.scheme; + palette: root.data.palette; + color-style: root.data.color-style; + icon-shapes: root.data.icon-shapes; + motion: root.data.motion; + scheme-picked(i) => { + root.data.scheme = i; + root.changed(root.data); } - - Text { - text: "Reduced motion makes menus, dialogs and lists change at once."; - color: Theme.on-surface-variant; - font-size: Theme.body-small.size; - font-weight: Theme.body-small.weight; - wrap: word-wrap; + palette-picked(seed) => { + root.data.palette = seed; + root.changed(root.data); + } + style-picked(i) => { + root.data.color-style = i; + root.changed(root.data); + } + shapes-toggled(on) => { + root.data.icon-shapes = on; + root.changed(root.data); + } + motion-picked(i) => { + root.data.motion = i; + root.changed(root.data); } } diff --git a/crates/tunal/ui/shell/player-bar.slint b/crates/tunal/ui/shell/player-bar.slint index accf266..16abbda 100644 --- a/crates/tunal/ui/shell/player-bar.slint +++ b/crates/tunal/ui/shell/player-bar.slint @@ -315,6 +315,7 @@ export component PlayerBar inherits Rectangle { alignment: center; Shape { size: root.cover-size; + plain: !Theme.icon-shapes; shape: ShapeKind.cookie9; fill: Theme.tertiary-container; glyph: Icons.music-note; diff --git a/crates/tunal/ui/theme.slint b/crates/tunal/ui/theme.slint index 1115546..20011c1 100644 --- a/crates/tunal/ui/theme.slint +++ b/crates/tunal/ui/theme.slint @@ -8,6 +8,8 @@ export struct TypeStyle { export global Theme { in-out property dark; + // Cookie and clover containers behind entry icons (a setting); off draws the plain icon. + in-out property icon-shapes: true; // Material 3 colour roles (tonal spot scheme from the portal accent). in-out property primary; @@ -58,6 +60,9 @@ export global Theme { out property corner-menu-item: 10px; // Degrees a shaped container turns while it morphs to its active shape. out property shape-morph-turn: 20; + // Palette swatch in the settings, its ring when chosen. + out property swatch: 36px; + out property swatch-ring: 2px; // Room round a shape's outline inside its path, as a share of its size. out property shape-margin: 0.1; // Degrees a dialog's header shape turns through while the dialog opens. diff --git a/crates/tunal/ui/views/grid-view.slint b/crates/tunal/ui/views/grid-view.slint index 705685a..181a3fd 100644 --- a/crates/tunal/ui/views/grid-view.slint +++ b/crates/tunal/ui/views/grid-view.slint @@ -109,6 +109,7 @@ component GridCell inherits StateLayer { x: (parent.width - self.width) / 2; y: (parent.height - self.height) / 2; size: root.icon; + plain: !Theme.icon-shapes; shape: FileShapes.shape(root.entry.shape-glyph); active-shape: FileShapes.active-shape(root.entry.shape-glyph); active: root.entry.selected; diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index 42acd54..e2a1fb2 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -287,5 +287,10 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done, - Not done: nothing run against the real `~/.local` or `/usr`; the installed copy at `/usr/bin/tunal` and the polkit policy are for the user. - How to install: `bash scripts/install.sh`, then the printed `sudo install` line. +## Colour settings and plain icons (user request) +- Done: Settings → Appearance (was Motion): theme system/light/dark, palette swatches (desktop accent + 10 seeds + own hex colour), Pick… (`tunal_theme::pick_color`, Screenshot portal), colour style (tonal/vibrant/expressive/neutral/mono), "Shapes behind icons" (`Theme.icon-shapes`, `Shape.plain`: rows, grid, sidebar, player cover), animations. Release binary rebuilt: it predated the wavy seek bar and the ffmpeg fallback. +- Verified: clippy on tunal + tunal-theme, fmt, release build, two PNGs (settings page; Opus file in the playing bar with plain icons and a green palette). +- Not done: no test run (user: save credits); Pick… not tried live. + ## Later -