diff --git a/Makefile b/Makefile index 8b10c19..279d30c 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,9 @@ QML_FILES := ui/Service.qml ui/BarWidget.qml ui/App.qml ui/compose/RecoveryContr ui/components/BackBar.qml \ ui/components/MouseBack.qml \ ui/components/SettingsPage.qml ui/components/AiSettings.qml \ + ui/theme/Paint.qml ui/theme/ThemeCatalog.qml ui/theme/AppTheme.qml \ + ui/kit/Button.qml ui/kit/TextField.qml ui/kit/Dropdown.qml \ + ui/kit/ToggleSwitch.qml ui/kit/NumberField.qml ui/kit/PanelToolTip.qml \ ui/components/SettingsSidebar.qml \ ui/components/CalendarSettings.qml \ ui/components/CalendarEventComposer.qml \ @@ -171,6 +174,7 @@ test-js: node ui/tests/test_html_tables.js node ui/tests/test_direction.js node ui/tests/test_appearance.js + node ui/tests/test_themes.js node ui/tests/test_model.js node ui/tests/test_icons.js node ui/tests/test_navigation.js diff --git a/app/qml/imports/qs/Commons/Color.qml b/app/qml/imports/qs/Commons/Color.qml index d337a4b..dc976bd 100644 --- a/app/qml/imports/qs/Commons/Color.qml +++ b/app/qml/imports/qs/Commons/Color.qml @@ -81,6 +81,16 @@ QtObject { ? 1 : root.shellTheme.popups["border-alpha"]) } + // The shell's Color exposes a tooltip surface too; a shared UI file that + // passes a tooltip colour would otherwise read undefined here. + readonly property QtObject tooltip: QtObject { + readonly property color background: root.withAlpha( + root.shellColor(root.shellTheme.popups.text, root.background), 0.97) + readonly property color text: root.shellColor(root.shellTheme.popups.text, root.foreground) + readonly property color border: root.withAlpha( + root.shellColor(root.shellTheme.popups.border, root.border), 1) + } + function updateWatches(store, paths) { var i if (watchedStore && typeof watchedStore.watch === "function") { diff --git a/app/qml/imports/qs/Commons/Style.qml b/app/qml/imports/qs/Commons/Style.qml index 929caca..091e299 100644 --- a/app/qml/imports/qs/Commons/Style.qml +++ b/app/qml/imports/qs/Commons/Style.qml @@ -59,7 +59,7 @@ QtObject { controlPaddingY: spacingToken("control-padding-y", 6), inputPaddingY: spacingToken("input-padding-y", 7), controlHeight: spacingToken("control-height", 28), - controlGap: spacingToken("control-gap", 8), + hairline: 1, panelGap: 14, controlGap: spacingToken("control-gap", 8), popupRowHeight: spacingToken("popup-row-height", 28), dropdownWidth: spacingToken("dropdown-width", 240), searchableDropdownWidth: spacingToken("searchable-dropdown-width", 260), @@ -125,4 +125,48 @@ QtObject { function selectedBorderFor(foreground, accent) { return withAlpha(stateColor("selected", foreground, accent, foreground), controlNumber("selected-border-alpha", 1)) } function focusFillFor(foreground, accent) { return withAlpha(stateColor("focus", foreground, accent, stateColor("hover-cursor", foreground, accent, foreground)), controlNumber("focus-fill-alpha", controlNumber("hover-cursor-fill-alpha", 0.08))) } function focusBorderFor(foreground, accent) { return withAlpha(stateColor("focus", foreground, accent, stateColor("hover-cursor", foreground, accent, foreground)), controlNumber("focus-border-alpha", controlNumber("hover-cursor-border-alpha", 0.25))) } + + // The state vocabulary and alphas the shell's Style exposes, which the window's + // Paint singleton delegates to whenever it is not drawing a theme of its own. + // The shell names normal/hover/focus/pressed/selection state colours and the + // composite control helpers; the standalone host answers them from its own + // shell.toml, which is what makes Follow Omarchy the same code on both hosts. + readonly property real normalFillAlpha: controlNumber("normal-fill-alpha", 0.04) + readonly property real hoverFillAlpha: controlNumber("hover-cursor-fill-alpha", 0.08) + readonly property real selectedFillAlpha: controlNumber("selected-fill-alpha", 0.18) + readonly property real pressedFillAlpha: controlNumber("pressed-fill-alpha", 0.22) + readonly property real focusFillAlpha: controlNumber("focus-fill-alpha", hoverFillAlpha) + readonly property real selectionFillAlpha: controlNumber("selection-fill-alpha", 0.35) + readonly property real normalBorderAlpha: controlNumber("normal-border-alpha", 0.4) + readonly property real hoverBorderAlpha: controlNumber("hover-cursor-border-alpha", 0.25) + readonly property real selectedBorderAlpha: controlNumber("selected-border-alpha", 1) + readonly property real focusBorderAlpha: controlNumber("focus-border-alpha", hoverBorderAlpha) + + function normalStateColor(foreground, accent) { return stateColor("normal", foreground, accent, foreground) } + function hoverStateColor(foreground, accent) { return stateColor("hover-cursor", foreground, accent, foreground) } + function focusStateColor(foreground, accent) { return stateColor("focus", foreground, accent, hoverStateColor(foreground, accent)) } + function pressedStateColor(foreground, accent) { return stateColor("pressed", foreground, accent, hoverStateColor(foreground, accent)) } + function selectionStateColor(foreground, accent) { return stateColor("selection", foreground, accent, foreground) } + + function controlFill(focused, hot, foreground, accent) { + if (focused) return focusFillFor(foreground, accent) + if (hot) return hoverFillFor(foreground, accent) + return normalFillFor(foreground, accent) + } + function controlBorder(focused, hot, foreground, accent) { + if (focused) return focusBorderFor(foreground, accent) + if (hot) return hoverBorderFor(foreground, accent) + return normalBorderFor(foreground, accent) + } + function controlBorderWidth(focused, hot) { + if (focused) return focusBorderWidth + if (hot) return hoverBorderWidth + return normalBorderWidth + } + function controlHasWidth(state) { + if (state === "selected") return selectedBorderWidth > 0 + if (state === "hover" || state === "hover-cursor") return hoverBorderWidth > 0 + if (state === "focus") return focusBorderWidth > 0 + return normalBorderWidth > 0 + } } diff --git a/app/qml/imports/qs/Ui/PanelToolTip.qml b/app/qml/imports/qs/Ui/PanelToolTip.qml index c2bd099..451beb1 100644 --- a/app/qml/imports/qs/Ui/PanelToolTip.qml +++ b/app/qml/imports/qs/Ui/PanelToolTip.qml @@ -5,6 +5,12 @@ import qs.Commons as Commons QQC.ToolTip { property string fontFamily: Style.font.family + // The shell's PanelToolTip paints a background, a text colour and a border + // colour of its own; the standalone host uses the platform tooltip's palette. + // They exist here so a caller may pass them either way. + property color panelForeground: Commons.Color.tooltip.text + property color panelBackground: Commons.Color.tooltip.background + property color panelBorder: Commons.Color.tooltip.border delay: Style.tooltipDelay font.family: fontFamily font.pixelSize: Style.font.caption diff --git a/app/qml/imports/qs/Ui/ToggleSwitch.qml b/app/qml/imports/qs/Ui/ToggleSwitch.qml index 7600461..dbbb786 100644 --- a/app/qml/imports/qs/Ui/ToggleSwitch.qml +++ b/app/qml/imports/qs/Ui/ToggleSwitch.qml @@ -14,6 +14,7 @@ Item { property color foreground: Commons.Color.foreground property color accent: Commons.Color.accent signal toggled() + signal hovered(bool isHovered) onCheckedChanged: { if (toggle.checked !== checked) toggle.checked = checked diff --git a/app/tests/qml/tst_standalone_composition.qml b/app/tests/qml/tst_standalone_composition.qml index 40a4c6a..21604ad 100644 --- a/app/tests/qml/tst_standalone_composition.qml +++ b/app/tests/qml/tst_standalone_composition.qml @@ -43,6 +43,34 @@ TestCase { function discoveredCount(id) { return 1 } } + // The shared dialogs on the standalone host's own controls: its button has + // no key handling of its own, so Return reaches a choice only through the + // dialog asking which button holds the focus. + Component { + id: confirmDeleteComponent + Components.ConfirmDeleteDialog { + textColor: Commons.Color.foreground + dimColor: Commons.Color.foreground + dangerColor: Commons.Color.accent + popupBackgroundColor: Commons.Color.background + popupBorderColor: Commons.Color.foreground + panelFontFamily: Style.font.family + } + } + + Component { + id: composeExitComponent + Components.ComposeExitDialog { + textColor: Commons.Color.foreground + dimColor: Commons.Color.foreground + dangerColor: Commons.Color.accent + popupBackgroundColor: Commons.Color.background + popupBorderColor: Commons.Color.foreground + panelFontFamily: Style.font.family + currentDraftKey: "draft-one" + } + } + Component { id: calendarComponent Components.CalendarSettings { @@ -711,6 +739,82 @@ TestCase { compare(JSON.parse(host.files[path]), {width:1000, height:680}) } + function test_delete_dialog_answers_return_on_standalone_buttons() { + var dialog = createTemporaryObject(confirmDeleteComponent, testCase) + verify(dialog) + var answers = [] + dialog.confirmed.connect(function(request) { answers.push(request) }) + + dialog.openFor({kind: "event", name: "Synthetic meeting", event: {googleId: "one"}}) + tryCompare(dialog, "opened", true) + // The buttons live in the popup, which findChild does not walk into. + function named(item, name) { + if (!item) return null + if (item.objectName === name) return item + var kids = item.children || [] + for (var i = 0; i < kids.length; i++) { + var found = named(kids[i], name) + if (found) return found + } + return null + } + var popup = popupOf(dialog) + verify(popup, "the delete question is a Popup") + var confirm = named(popup.contentItem, "delete-confirm") + verify(confirm, "the Delete button") + tryVerify(function() { return confirm.activeFocus }, 2000, "Delete holds the focus") + keyClick(Qt.Key_Return) + compare(answers.length, 1, "Return on the default answers it") + compare(answers[0].event.googleId, "one") + tryCompare(dialog, "opened", false) + + dialog.openFor({kind: "event", name: "Synthetic meeting", event: {googleId: "two"}}) + tryCompare(dialog, "opened", true) + var cancel = named(popup.contentItem, "delete-cancel") + verify(cancel, "the Cancel button") + tryVerify(function() { return confirm.activeFocus }, 2000) + keyClick(Qt.Key_Tab) + verify(cancel.activeFocus, "Tab reaches Cancel") + keyClick(Qt.Key_Return) + tryCompare(dialog, "opened", false) + compare(answers.length, 1, "Return on Cancel deletes nothing") + } + + function test_draft_dialog_answers_return_on_standalone_buttons() { + var dialog = createTemporaryObject(composeExitComponent, testCase) + verify(dialog) + var saved = [] + var discarded = [] + dialog.saveRequested.connect(function(key) { saved.push(key) }) + dialog.discardRequested.connect(function(key) { discarded.push(key) }) + var popup = popupOf(dialog) + verify(popup, "the draft question is a Popup") + var row = popup.contentItem.children[2] + var cancel = row.children[0] + var discard = row.children[1] + var save = row.children[2] + verify(cancel.text === "Cancel" && discard.text === "Discard" && save.text === "Save draft") + + dialog.open() + tryCompare(dialog, "opened", true) + tryVerify(function() { return save.activeFocus }, 2000, "Save draft holds the focus") + keyClick(Qt.Key_Return) + compare(saved, ["draft-one"], "Return on the default saves the draft") + tryCompare(dialog, "opened", false) + + dialog.open() + tryCompare(dialog, "opened", true) + tryVerify(function() { return save.activeFocus }, 2000) + keyClick(Qt.Key_Tab) + verify(cancel.activeFocus, "Tab from Save draft reaches Cancel") + keyClick(Qt.Key_Tab) + verify(discard.activeFocus, "and then Discard") + keyClick(Qt.Key_Return) + compare(discarded, ["draft-one"], "Return on Discard discards") + compare(saved.length, 1) + tryCompare(dialog, "opened", false) + } + function test_shell_persists_settings_and_routes_activation_payload() { var composition = createTemporaryObject(compositionComponent, testCase) verify(composition) diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 9b08664..e2c0f50 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -262,6 +262,8 @@ The same distinction applies to large feature systems. Dock's pure-data layout, The visual exception is explicit. GPUI Component theme tokens, dimensions, cursor styling, animation curves, shadows, radii, and surface appearance do not transfer. Omarchy remains the visual authority. +That authority is reached through one module rather than through the shell's singletons directly. `ui/theme/Paint.qml` is the window's colour authority: with Follow Omarchy selected it delegates to `Commons.Color`, `Style` and `Border` so the window is drawn by exactly the code it was drawn by before, and with a theme selected it resolves the same roles from that theme's `colors.toml`. `ui/theme/Themes.js` holds the rules as pure functions — name validation, theme-directory ordering, TOML parsing, palette fallback — so they are testable without a window, and `ui/theme/ThemeCatalog.qml` lists installed themes with the user's directory taking precedence over the installed one. Geometry, typography, spacing, alpha and border widths are never taken from a picked theme: they stay live from `Style`, so a per-app theme can change colour and nothing else. `ui/kit` wraps the shell controls whose internal state colours come from tokens the shell rendered with the desktop's theme baked in. + ## Commit design Commits should preserve the reasoning that makes an architectural choice safe to change later. The best history in both Omamail and GPUI Component follows a consistent structure. diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 9941640..73eb2c5 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -12,7 +12,7 @@ Omamail is a compact, keyboard-capable desktop mail client. It should feel like - quiet enough for the message to remain primary; - explicit about state without depending on color alone; - predictable under keyboard, pointer, and window resizing; -- native to the active Omarchy theme. +- native to the active Omarchy theme, or to the theme chosen for the window. The screenshots in `preview.png` express the visual baseline: a narrow mailbox rail, a dense list, a generous reader, monospace typography, restrained rules, and controls that appear where their actions belong. @@ -28,6 +28,16 @@ All visual tokens come from the active Omarchy theme: Semantic colors originate in `App.qml` and travel through required component properties. Muted text mixes foreground toward background. Derived fills use the shared `Style` helpers or alpha from an inherited semantic color. +## A theme for this window alone + +The desktop's theme is the default and Follow Omarchy the default choice, but a window may be drawn in any theme installed on the machine. That is a convenience for one purpose: reading mail in a light room, or in a higher-contrast theme than the desktop is set to, without changing the desktop, the bar, or any other window. Omamail is still the shell's client; it is not offering a second desktop. + +Only colours are chosen. Font, spacing, corner radius, border widths, alpha and every other measurement stay the live shell's, so a window drawn in another theme still fits the desktop's grid and responds to the shell's scale — and a theme that changes one role cannot change the layout. A theme that states no urgent colour, or writes an older file without selection, is answered with the nearest role rather than with a missing colour. + +One authority draws the window. `ui/theme/Paint.qml` resolves every colour the app paints, from the desktop's own singletons when Follow Omarchy is selected and from the picked theme's file otherwise. Nothing in the window reads `Commons.Color`, `Style`'s state helpers, or `Border.controlSpec` directly, because the shell renders those from the desktop's theme and they ignore the colour they are handed — a window that asked them for a light theme's foreground would be given the dark desktop's near-white and paint it on white. The bar widget, its popup and desktop notifications are the desktop's own surfaces and keep the desktop's palette, including the unread dot. + +Choosing a theme is not a restart: every binding above the choice reads `Paint`, so a window redraws when it changes. An unreadable, missing or malformed choice falls back to Follow Omarchy rather than failing to open, and the settings file's value is treated as a path segment and validated before it is used as one. + Do not import GPUI Component colors, shadows, radii, typography, sidebar width, or control decoration. A GPUI example may demonstrate an interaction contract; its pixels are not a design token for this application. ## What comes from GPUI and GPUI Component diff --git a/docs/SPEC.md b/docs/SPEC.md index f28968a..a346e4e 100644 --- a/docs/SPEC.md +++ b/docs/SPEC.md @@ -103,8 +103,8 @@ Qt behaviours this design is shaped around. ## Constraints -- Every colour comes from the active Omarchy theme. No hard-coded hex outside - a brand asset. +- Every colour comes from the active Omarchy theme, or from the Omarchy theme + picked for this window alone. No hard-coded hex outside a brand asset. - All parsing, formatting, and decision logic lives in `.pragma library` JS files so it is testable under node without a compositor. - No dependency beyond what Omarchy already ships: `socat`, `secret-tool`, diff --git a/manifest.json b/manifest.json index 95a17f9..dfa2b77 100644 --- a/manifest.json +++ b/manifest.json @@ -41,6 +41,7 @@ "maxMessages": 50, "heavyMessageRendering": "Show plain text first", "contentDirection": "Auto", + "appTheme": "", "defaultQuery": "in:inbox", "notifyNewMail": "On", "oauthPort": 9481, @@ -117,7 +118,12 @@ "key": "aiAgent", "type": "enum", "label": "AI agent", - "options": ["System default", "OpenCode", "Codex", "Claude"], + "options": [ + "System default", + "OpenCode", + "Codex", + "Claude" + ], "defaultValue": "System default", "description": "Agent for new mail chats and calendar suggestions. System default follows Omarchy; unsupported defaults disable AI. Changing the selection starts fresh chats and keeps previous chats read-only. Requires backend API 6." }, diff --git a/tests/test_source.sh b/tests/test_source.sh index 7f6690d..29abee4 100755 --- a/tests/test_source.sh +++ b/tests/test_source.sh @@ -50,6 +50,31 @@ if grep -nE ':\s*"(red|blue|green|white|black|yellow|orange|purple|gray|grey)"' fail "named display colour in QML: use Color.* instead" fi +# 1b. One colour authority for the mail window. +# +# The window can be drawn in an Omarchy theme other than the desktop's, so it +# must take its colours from `theme/Paint`, which delegates to Commons/Style +# exactly when the desktop's theme is followed. Reaching for the shell's own +# singletons gets the desktop theme's hex — Omarchy bakes it into shell.toml's +# [controls] tokens, so Style's helpers ignore the colours they are passed — and +# a window drawn in a light theme on a dark desktop then paints near-white text +# on white. `theme/` and `kit/` are where that delegation lives, and the bar +# envelope, its popup and desktop notifications are the desktop's own surfaces, +# so they are exempt. Everything else in ui/ — including code written later — +# must go through Paint. +colour_offenders=() +for file in "${QML_FILES[@]}"; do + case "$file" in + theme/*|kit/*|bar/*|BarWidget.qml|tests/*) continue ;; + esac + if grep -nE 'Commons\.Color\.|Style\.(normal|hover|selected|pressed|focus|selection)[A-Za-z]*(For|StateColor)\(|Style\.(normal|hover|selected|pressed|focus|selection)[A-Za-z]*Color\b|Border\.controlSpec\(' "$file"; then + colour_offenders+=("$file") + fi +done +if [ "${#colour_offenders[@]}" -gt 0 ]; then + fail "window colour read from Commons/Style/Border: route it through Paint (${colour_offenders[*]})" +fi + # 2. The JS libraries are read by the QML engine, which does not accept ES6. # tests/ is node-only and exempt. for file in "${JS_FILES[@]}"; do @@ -433,7 +458,7 @@ if "calendarBorderColor: root.calendarBorder" not in app: raise SystemExit("test_source.sh: App must pass the system calendar border token") if "calendarTodayBackgroundColor: root.calendarTodayBackground" not in app: raise SystemExit("test_source.sh: App must pass the system Today background token") -if "readonly property color calendarBorder: Style.normalBorderColor" not in app: +if "readonly property color calendarBorder: Paint.normalBorderColor" not in app: raise SystemExit("test_source.sh: calendar borders must originate from the system border token") if "readonly property color calendarTodayBackground: Qt.alpha(root.accent, 0.035)" not in app: raise SystemExit("test_source.sh: Today must use the quieter system accent fill token") @@ -905,7 +930,7 @@ awk ' || fail "the From dropdown must use an outline treatment" awk ' /id: fromButton/ { in_from = 1 } - in_from && /background: Style.normalFillFor\(root.textColor, root.accentColor\)/ { fill = 1 } + in_from && /background: Paint.normalFillFor\(root.textColor, root.accentColor\)/ { fill = 1 } in_from && /verticalPadding: Style.spacing.inputPaddingY/ { padding = 1 } in_from && /^ }/ { exit !(fill && padding) } END { exit !(fill && padding) } @@ -971,8 +996,14 @@ fi # different font must update all three deliberately. font_provenance=app/assets/fonts/NerdFonts-PROVENANCE.md [ -f "../$font_provenance" ] || fail "bundled fonts must record their provenance" +# `shasum` is the macOS name; a Linux box has `sha256sum`. Either answers the +# same question, and the suite runs on both. +hash_file() { + if command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | awk '{print $1}' + else sha256sum "$1" | awk '{print $1}'; fi +} while read -r expected file; do - actual=$(cd .. && shasum -a 256 "$file" | awk '{print $1}') + actual=$(cd .. && hash_file "$file") [ "$actual" = "$expected" ] || fail "$file does not match its reviewed upstream checksum" grep -q "$expected" "../$font_provenance" \ || fail "$file checksum is missing from its shipped provenance" @@ -990,7 +1021,7 @@ mac_icon=app/resources/macos/omamail.icns [ "$(cd .. && wc -c < "$mac_icon")" -eq 111809 ] \ || fail "$mac_icon does not match its reviewed byte size" mac_icon_checksum=bd29ce1e72aa9db37ed5b1cb930956d2d933dc4426e7cea7f1b8baf2edb9262d -actual_mac_icon_checksum=$(cd .. && shasum -a 256 "$mac_icon" | awk '{print $1}') +actual_mac_icon_checksum=$(cd .. && hash_file "$mac_icon") [ "$actual_mac_icon_checksum" = "$mac_icon_checksum" ] \ || fail "$mac_icon does not match its reviewed checksum" grep -q "$mac_icon_checksum" "../$icon_provenance" \ @@ -999,7 +1030,7 @@ grep -q '1277a2cf247b275a15961fb20175420abb5dfc5489acb95313f4f604c09b6e78' "../$ || fail "the macOS icon source checksum is missing from its shipped provenance" windows_icon=app/resources/windows/omamail.ico windows_icon_checksum=2562966adb272711ae0274f7eade7ef2680781bb4405182280a310658752131d -actual_windows_icon_checksum=$(cd .. && shasum -a 256 "$windows_icon" | awk '{print $1}') +actual_windows_icon_checksum=$(cd .. && hash_file "$windows_icon") [ "$actual_windows_icon_checksum" = "$windows_icon_checksum" ] \ || fail "$windows_icon does not match its reviewed checksum" grep -q "$windows_icon_checksum" "../$icon_provenance" \ diff --git a/tests/test_tooltip_text.py b/tests/test_tooltip_text.py index b0719f1..7d06625 100644 --- a/tests/test_tooltip_text.py +++ b/tests/test_tooltip_text.py @@ -1,6 +1,7 @@ """Actual standalone tooltip renders untrusted titles without resource requests.""" import json import os +import re import shutil from pathlib import Path import subprocess @@ -147,7 +148,18 @@ def main(): shutil.copytree(ROOT / "ui/tests/qml/imports/Quickshell", imports / "Quickshell") shutil.copytree(ROOT / "ui/tests/qml/imports/qs", imports / "qs", dirs_exist_ok=True) color = imports / "qs/Commons/Color.qml" - color.write_text(color.read_text().replace("QtObject {", 'QtObject {\n readonly property var popups: ({text: "#eeeeee", background: "#222222", border: "#555555"})', 1)) + # The shared fixture may already declare the popup surface; QML + # rejects a second property of the same name, and an engine that + # refuses to compile the fixture observes no requests at all — an + # empty observer is not evidence that nothing was requested. Supply + # the surface only where the fixture leaves it out. + color_text = color.read_text() + if not re.search(r"property\s+\S+\s+popups\b", color_text): + color_text = color_text.replace( + "QtObject {", + 'QtObject {\n readonly property var popups: ({text: "#eeeeee", background: "#222222", border: "#555555"})', + 1) + color.write_text(color_text) style = imports / "qs/Commons/Style.qml" style.write_text(style.read_text().replace("QtObject {", "QtObject {\n readonly property int tooltipDelay: 400", 1)) source = QML.replace("@STYLE@", json.dumps((ROOT / "app/qml/styles/Omamail").as_uri())) diff --git a/ui/App.qml b/ui/App.qml index 1ed2034..a043c16 100644 --- a/ui/App.qml +++ b/ui/App.qml @@ -22,6 +22,8 @@ import "message/Message.js" as Message import "components" import "compose" import "calendar" +import "theme" +import "kit" Item { id: root @@ -110,17 +112,17 @@ Item { onTriggered: root.saveComposeRecovery() } - readonly property color foreground: Commons.Color.foreground - readonly property color background: Commons.Color.background - readonly property color accent: Commons.Color.accent - readonly property color urgent: Commons.Color.urgent - readonly property color danger: Commons.Color.urgent - readonly property color popupBackground: Commons.Color.popups.background - readonly property color popupBorder: Commons.Color.popups.border + readonly property color foreground: Paint.foreground + readonly property color background: Paint.background + readonly property color accent: Paint.accent + readonly property color urgent: Paint.urgent + readonly property color danger: Paint.urgent + readonly property color popupBackground: Paint.popupBackground + readonly property color popupBorder: Paint.popupBorder // Shared themed border for mail and standalone window chrome. - readonly property color borderColor: Style.normalBorderColor + readonly property color borderColor: Paint.normalBorderColor readonly property int borderWidth: Style.normalBorderWidth - readonly property color calendarBorder: Style.normalBorderColor + readonly property color calendarBorder: Paint.normalBorderColor readonly property color calendarTodayBackground: Qt.alpha(root.accent, 0.035) readonly property int calendarBorderWidth: Style.normalBorderWidth readonly property color dim: Qt.rgba( @@ -1705,7 +1707,7 @@ Item { } foreground: root.assistantOpen ? root.foreground : root.dim bordered: true - selected: root.assistantOpen + chosen: root.assistantOpen focusable: true accent: root.accent fontFamily: root.fontFamily @@ -2491,11 +2493,11 @@ Item { anchors.margins: Style.space(2) radius: Style.cornerRadius color: accountMouse.pressed - ? Style.pressedFillFor(root.foreground, root.accent) + ? Paint.pressedFillFor(root.foreground, root.accent) : (accountControl.selected - ? Style.selectedFillFor(root.foreground, root.accent) + ? Paint.selectedFillFor(root.foreground, root.accent) : (accountMouse.containsMouse - ? Style.hoverFillFor(root.foreground, root.accent) : "transparent")) + ? Paint.hoverFillFor(root.foreground, root.accent) : "transparent")) } Text { diff --git a/ui/BarWidget.qml b/ui/BarWidget.qml index 1bfe934..149d185 100644 --- a/ui/BarWidget.qml +++ b/ui/BarWidget.qml @@ -170,6 +170,9 @@ BarWidget { iconSize: Style.space(12) color: button.glyphColor markColor: Commons.Color.accent + // The bar is the desktop's surface, so its dot stays the desktop's + // accent even when the window is drawn in a theme of its own. + badgeColor: Commons.Color.urgent // The dot is simply whether unread mail is waiting. It used to mean // "something arrived since you last looked", which was a different // question from the one anyone asks of a mail icon, and it could not diff --git a/ui/Service.qml b/ui/Service.qml index 5123eb2..084e9e4 100644 --- a/ui/Service.qml +++ b/ui/Service.qml @@ -27,6 +27,7 @@ import "message/Outbox.js" as Outbox import "message/Html.js" as Html import "message/Direction.js" as Direction import "settings/Appearance.js" as Appearance +import "theme" // Owns each MailAccount and forwards the active mailbox's surface to views. // All accounts poll unread counts; only the active account loads lists/bodies. @@ -50,7 +51,8 @@ Item { property var platform: null property var initialSettings: null readonly property var capabilities: platform && platform.capabilities - ? platform.capabilities : ({ agent: true, tray: true, mailto: true, notifications: true }) + ? platform.capabilities + : ({ agent: true, tray: true, mailto: true, notifications: true, appTheme: true }) readonly property bool standalone: !!platform && platform.standalone === true readonly property bool smokeTest: standalone && Quickshell.env("OMAMAIL_SMOKE_TEST") === "1" @@ -149,17 +151,15 @@ Item { readonly property bool hasTray: capabilities.tray === true readonly property bool hasMailto: capabilities.mailto === true readonly property bool hasNotifications: capabilities.notifications === true - // Only a host that paints its own window has a palette to choose. The - // Omarchy plugin's colours are the shell's, decided in colors.toml. readonly property bool hasAppearance: capabilities.appearance === true readonly property string appearance: Appearance.normalizeMode( settings ? settings.appearance : null) + // The window's own theme; AppTheme owns the rest of it. + readonly property var theme: appThemeChoice + AppTheme { id: appThemeChoice; host: root } readonly property string notificationError: platform && platform.notificationError ? String(platform.notificationError) : "" - readonly property string calendarPalettePath: platform - && platform.calendarPalettePath !== undefined - ? String(platform.calendarPalettePath || "") - : Quickshell.env("HOME") + "/.local/state/omarchy/current/theme/colors.toml" + readonly property string calendarPalettePath: theme.colorsPath // Credential RPC was introduced in API 4. This minimum stays fixed after // release; it is a capability of the connected backend, not release state. readonly property bool backendCanStoreCredentials: backend.ready && backend.apiVersion >= 4 @@ -2585,8 +2585,8 @@ Item { CalendarReminders { service: root pluginDir: root.pluginDir - notificationForeground: Commons.Color.foreground - notificationAccent: Commons.Color.accent + notificationForeground: Paint.notificationForeground + notificationAccent: Paint.notificationAccent } } } @@ -2613,8 +2613,8 @@ Item { return index < accounts.length ? accounts[index] : null } - notificationForeground: Commons.Color.foreground - notificationAccent: Commons.Color.accent + notificationForeground: Paint.notificationForeground + notificationAccent: Paint.notificationAccent pluginDir: root.pluginDir accountId: entry ? entry.id : "" backend: root.backend diff --git a/ui/components/AccountNameField.qml b/ui/components/AccountNameField.qml index 0b586d6..0032dc5 100644 --- a/ui/components/AccountNameField.qml +++ b/ui/components/AccountNameField.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" // The name a mailbox is listed by, asked for where the mailbox is set up // rather than only in the settings list afterwards. Optional: two mailboxes diff --git a/ui/components/AccountRemovalDialog.qml b/ui/components/AccountRemovalDialog.qml index 538d6e8..e17f617 100644 --- a/ui/components/AccountRemovalDialog.qml +++ b/ui/components/AccountRemovalDialog.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls as QQC import qs.Commons import qs.Ui +import "../kit" Item { id: root diff --git a/ui/components/AccountSwitcher.qml b/ui/components/AccountSwitcher.qml index efb9124..7fd110b 100644 --- a/ui/components/AccountSwitcher.qml +++ b/ui/components/AccountSwitcher.qml @@ -4,6 +4,7 @@ import qs.Commons import qs.Ui import "../account/Model.js" as Model import "Menu.js" as Menu +import "../theme" // The list of mailboxes, opened from the user bar. // @@ -203,11 +204,11 @@ Item { implicitHeight: visible ? Style.space(40) : 0 radius: Style.cornerRadius color: root.unifiedActive - ? Style.selectedFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) : (unifiedHover.hovered || hasCursor - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") border.width: hasCursor ? Style.normalBorderWidth : 0 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Rectangle { id: unifiedAvatar @@ -217,7 +218,7 @@ Item { width: Style.space(22) height: width radius: width / 2 - color: Style.selectedFillFor(root.textColor, root.accentColor) + color: Paint.selectedFillFor(root.textColor, root.accentColor) // Not a letter: this row stands for no address, and an initial // taken from one of them would claim it belonged to that mailbox. @@ -315,14 +316,14 @@ Item { implicitHeight: Style.space(40) radius: Style.cornerRadius color: row.inUse - ? Style.selectedFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) : (rowHover.hovered || hasCursor - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") // A border rather than a third fill: the mailbox you are in already // owns the selected one, and the keyboard has to be visible standing // on that row too. border.width: hasCursor ? Style.normalBorderWidth : 0 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Rectangle { id: rowAvatar @@ -332,7 +333,7 @@ Item { width: Style.space(22) height: width radius: width / 2 - color: Style.selectedFillFor(root.textColor, root.accentColor) + color: Paint.selectedFillFor(root.textColor, root.accentColor) Text { anchors.centerIn: parent diff --git a/ui/components/ActionIcon.qml b/ui/components/ActionIcon.qml index cdd4dab..24bfc03 100644 --- a/ui/components/ActionIcon.qml +++ b/ui/components/ActionIcon.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Commons as Commons import "Icons.js" as Icons +import "../theme" // One of the app's icons, by name. // @@ -17,7 +18,7 @@ Item { id: root property string name: "" - property color color: Commons.Color.foreground + property color color: Paint.foreground // Omamail keeps the envelope in the foreground and gives its M the active // theme accent. Provider artwork uses ProviderLogo instead of this mark. property color markColor: color diff --git a/ui/components/AgentPrompt.qml b/ui/components/AgentPrompt.qml index d4af7cc..07eb6e6 100644 --- a/ui/components/AgentPrompt.qml +++ b/ui/components/AgentPrompt.qml @@ -5,6 +5,8 @@ import qs.Ui import "../agent/Agent.js" as Agent import "../agent" as AI import "../agent/ChatText.js" as ChatText +import "../theme" +import "../kit" // A contextual conversation. The system AI streams public output in the // background; applying a suggestion remains an explicit owner action. @@ -494,7 +496,7 @@ FocusScope { Rectangle { anchors.fill: parent visible: parent.userMessage - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Rectangle { anchors.fill: parent color: Qt.rgba(root.textColor.r, root.textColor.g, root.textColor.b, 0.06) @@ -548,7 +550,7 @@ FocusScope { Component.onCompleted: if (queue) queue.watchDelivery(sendId) width: parent.width height: proposalContent.implicitHeight + Style.space(24) - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.color: root.popupBorderColor radius: Style.space(6) Column { @@ -886,7 +888,7 @@ FocusScope { font.family: root.panelFontFamily font.pixelSize: Style.font.bodySmall } - background: Rectangle { color: parent.hovered || (historyList.activeFocus && parent.index === historyList.currentIndex) ? Style.hoverFillFor(root.textColor, root.accentColor) : Style.normalFillFor(root.textColor, root.accentColor) } + background: Rectangle { color: parent.hovered || (historyList.activeFocus && parent.index === historyList.currentIndex) ? Paint.hoverFillFor(root.textColor, root.accentColor) : Paint.normalFillFor(root.textColor, root.accentColor) } onClicked: root.selectHistory(modelData.id) } Text { @@ -929,7 +931,7 @@ FocusScope { font.pixelSize: Style.font.bodySmall elide: Text.ElideRight } - background: Rectangle { color: index === root.commandIndex ? Style.selectedFillFor(root.textColor, root.accentColor) : Style.normalFillFor(root.textColor, root.accentColor) } + background: Rectangle { color: index === root.commandIndex ? Paint.selectedFillFor(root.textColor, root.accentColor) : Paint.normalFillFor(root.textColor, root.accentColor) } onClicked: { field.text = modelData; root.submitCurrent() } } } diff --git a/ui/components/AiSettings.qml b/ui/components/AiSettings.qml index 3f7d7a6..97f531b 100644 --- a/ui/components/AiSettings.qml +++ b/ui/components/AiSettings.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Ui import "../agent/Options.js" as Options +import "../kit" Column { id: root diff --git a/ui/components/AppMenu.qml b/ui/components/AppMenu.qml index 7244cb9..573834a 100644 --- a/ui/components/AppMenu.qml +++ b/ui/components/AppMenu.qml @@ -3,6 +3,7 @@ import QtQuick.Controls as QQC import qs.Commons import qs.Ui import "Menu.js" as Menu +import "../kit" // Links out, plus the handful of actions that have no natural home on screen. Item { diff --git a/ui/components/BackendSetup.qml b/ui/components/BackendSetup.qml index 4a1f107..8421256 100644 --- a/ui/components/BackendSetup.qml +++ b/ui/components/BackendSetup.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" Column { id: root diff --git a/ui/components/CalendarEventComposer.qml b/ui/components/CalendarEventComposer.qml index 1b8d5d7..5cc989d 100644 --- a/ui/components/CalendarEventComposer.qml +++ b/ui/components/CalendarEventComposer.qml @@ -6,6 +6,8 @@ import qs.Ui import "../calendar/Calendar.js" as Calendar import "../compose/Recipients.js" as Recipients import "../backend/Plain.js" as Plain +import "../theme" +import "../kit" Rectangle { id: root @@ -189,10 +191,10 @@ Rectangle { iconSize: Style.font.iconSmall } background: Rectangle { - color: option.popup.opened ? Style.selectedFillFor(root.textColor, root.accentColor) - : Style.normalFillFor(root.textColor, root.accentColor) + color: option.popup.opened ? Paint.selectedFillFor(root.textColor, root.accentColor) + : Paint.normalFillFor(root.textColor, root.accentColor) border.width: Style.normalBorderWidth - border.color: option.popup.opened ? root.accentColor : Style.normalBorderFor(root.textColor, root.accentColor) + border.color: option.popup.opened ? root.accentColor : Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } delegate: QQC.ItemDelegate { @@ -212,7 +214,7 @@ Rectangle { elide: Text.ElideRight } background: Rectangle { - color: optionRow.highlighted ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent" + color: optionRow.highlighted ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent" } } popup: QQC.Popup { @@ -239,7 +241,7 @@ Rectangle { } background: Rectangle { color: root.backgroundColor - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) border.width: Style.normalBorderWidth radius: Style.cornerRadius } @@ -633,11 +635,11 @@ Rectangle { iconSize: Style.font.iconSmall } background: Rectangle { - color: calendarSelector.popup.opened ? Style.selectedFillFor(root.textColor, root.accentColor) - : calendarSelector.hovered ? Style.hoverFillFor(root.textColor, root.accentColor) - : Style.normalFillFor(root.textColor, root.accentColor) + color: calendarSelector.popup.opened ? Paint.selectedFillFor(root.textColor, root.accentColor) + : calendarSelector.hovered ? Paint.hoverFillFor(root.textColor, root.accentColor) + : Paint.normalFillFor(root.textColor, root.accentColor) border.width: Style.normalBorderWidth - border.color: calendarSelector.popup.opened ? root.accentColor : Style.normalBorderFor(root.textColor, root.accentColor) + border.color: calendarSelector.popup.opened ? root.accentColor : Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } delegate: QQC.ItemDelegate { @@ -691,7 +693,7 @@ Rectangle { } } background: Rectangle { - color: calendarOption.highlighted ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent" + color: calendarOption.highlighted ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent" radius: Style.cornerRadius } } @@ -721,7 +723,7 @@ Rectangle { background: Rectangle { color: root.backgroundColor border.width: Style.normalBorderWidth - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } } @@ -770,10 +772,10 @@ Rectangle { onCursorRectangleChanged: Qt.callLater(root.revealDescriptionCursor) onHeightChanged: Qt.callLater(root.revealDescriptionCursor) background: Rectangle { - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: Style.normalBorderWidth border.color: notesField.activeFocus ? root.accentColor - : Style.normalBorderFor(root.textColor, root.accentColor) + : Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } } @@ -922,7 +924,7 @@ Rectangle { dimColor: root.dimColor accentColor: root.accentColor popupBackgroundColor: root.backgroundColor - popupBorderColor: Style.normalBorderFor(root.textColor, root.accentColor) + popupBorderColor: Paint.normalBorderFor(root.textColor, root.accentColor) panelFontFamily: root.panelFontFamily onChosen: function(contact) { root.acceptGuest(contact) } } diff --git a/ui/components/CalendarEventDetail.qml b/ui/components/CalendarEventDetail.qml index f45df6c..bf10514 100644 --- a/ui/components/CalendarEventDetail.qml +++ b/ui/components/CalendarEventDetail.qml @@ -5,6 +5,7 @@ import qs.Commons import qs.Ui import "../calendar/Calendar.js" as Calendar import "../message/Html.js" as Html +import "../theme" Rectangle { id: root @@ -79,7 +80,7 @@ Rectangle { readOnly: true selectByMouse: true textFormat: TextEdit.PlainText - selectionColor: Style.selectionFillFor(root.textColor, root.accentColor) + selectionColor: Paint.selectionFillFor(root.textColor, root.accentColor) selectedTextColor: color } diff --git a/ui/components/CalendarSettings.qml b/ui/components/CalendarSettings.qml index ba1193e..2312f52 100644 --- a/ui/components/CalendarSettings.qml +++ b/ui/components/CalendarSettings.qml @@ -5,6 +5,8 @@ import "../calendar/Sources.js" as Sources import "../calendar/Invitations.js" as Invitations import "../providers/Registry.js" as Provider import "../backend/Plain.js" as Plain +import "../theme" +import "../kit" Column { id: root @@ -167,7 +169,7 @@ Column { width: parent ? parent.width : 0 implicitHeight: Math.max(settingText.implicitHeight, rowControls.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: settingText anchors.left: parent.left @@ -225,7 +227,7 @@ Column { width: parent.width implicitHeight: Math.max(calendarText.implicitHeight, calendarActions.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Button { id: colorButton @@ -240,7 +242,7 @@ Column { horizontalPadding: 0 verticalPadding: 0 background: "transparent" - selected: root.colorEditingId === String(calendarRow.source.id) + chosen: root.colorEditingId === String(calendarRow.source.id) foreground: root.textColor accent: root.accentColor tooltipText: "Change calendar color" @@ -364,7 +366,7 @@ Column { height: width horizontalPadding: 0 verticalPadding: 0 - selected: String(modelData) === String(calendarRow.source.colorKey || "") + chosen: String(modelData) === String(calendarRow.source.colorKey || "") foreground: root.textColor accent: root.accentColor tooltipText: "Use " + modelData @@ -382,7 +384,7 @@ Column { height: width radius: width / 2 color: "transparent" - border.width: parent.selected ? Math.max(1, Style.normalBorderWidth) : 0 + border.width: parent.chosen ? Math.max(1, Style.normalBorderWidth) : 0 border.color: root.textColor Rectangle { objectName: "calendar-color-swatch-" + paletteOption.modelData diff --git a/ui/components/CalendarView.qml b/ui/components/CalendarView.qml index a017f40..7c7dacd 100644 --- a/ui/components/CalendarView.qml +++ b/ui/components/CalendarView.qml @@ -6,6 +6,7 @@ import qs.Commons import "../calendar/Calendar.js" as Calendar import "../backend/Plain.js" as Plain import "../keys/Keymap.js" as Keymap +import "../theme" Item { id: root @@ -550,7 +551,7 @@ Item { } background: Rectangle { color: root.backgroundColor - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } } @@ -1032,9 +1033,9 @@ Item { height: Style.space(64) radius: Style.cornerRadius color: Calendar.eventKey(modelData) === root.selectedEventId - ? Style.selectedFillFor(root.textColor, root.accentColor) - : agendaMouse.containsMouse ? Style.hoverFillFor(root.textColor, root.accentColor) - : Style.normalFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) + : agendaMouse.containsMouse ? Paint.hoverFillFor(root.textColor, root.accentColor) + : Paint.normalFillFor(root.textColor, root.accentColor) Column { anchors.fill: parent anchors.margins: Style.space(8) @@ -1098,7 +1099,7 @@ Item { height: Math.min(Style.space(460), parent.height - Style.space(24), overflowHeading.implicitHeight + overflowEvents.height + padding * 2 + Style.space(10)) color: root.backgroundColor - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius function place() { if (!dayCell) return @@ -1222,7 +1223,7 @@ Item { onHeightChanged: if (opened) place() background: Rectangle { color: root.backgroundColor - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) radius: Style.cornerRadius } contentItem: Column { diff --git a/ui/components/ComposeExitDialog.qml b/ui/components/ComposeExitDialog.qml index c7b06ad..40b44dd 100644 --- a/ui/components/ComposeExitDialog.qml +++ b/ui/components/ComposeExitDialog.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls as QQC import qs.Commons import qs.Ui +import "../kit" Item { id: root diff --git a/ui/components/ComposeView.qml b/ui/components/ComposeView.qml index 3d4b308..1390420 100644 --- a/ui/components/ComposeView.qml +++ b/ui/components/ComposeView.qml @@ -11,6 +11,8 @@ import "../compose/Recipients.js" as Recipients import "../compose/Senders.js" as Senders import "../compose/Spelling.js" as Spelling import "../agent/Agent.js" as Agent +import "../theme" +import "../kit" // Composing takes over the whole content area of the one window rather than // opening a second one: Omarchy's panel mechanism would give an extra window @@ -1425,13 +1427,13 @@ DropArea { text: root.fromEmail foreground: root.textColor accent: root.accentColor - background: Style.normalFillFor(root.textColor, root.accentColor) + background: Paint.normalFillFor(root.textColor, root.accentColor) bordered: true fontFamily: root.panelFontFamily fontSize: Style.font.bodySmall verticalPadding: Style.spacing.inputPaddingY leftAlign: true - selected: fromMenu.opened + chosen: fromMenu.opened enabled: root.canChooseFrom onClicked: root.toggleFromMenu() @@ -1980,9 +1982,9 @@ DropArea { implicitHeight: Style.space(42) radius: Style.cornerRadius color: root.fromEmail.toLowerCase() === String(modelData.email || "").toLowerCase() - ? Style.selectedFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) : (fromHover.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") Column { anchors.left: parent.left @@ -2090,7 +2092,7 @@ DropArea { horizontalAlignment: root.composeAlignment onEffectiveHorizontalAlignmentChanged: Qt.callLater(function() { root.spellingLayoutRevision += 1 }) color: root.textColor - selectionColor: Style.selectionFillFor(root.textColor, root.accentColor) + selectionColor: Paint.selectionFillFor(root.textColor, root.accentColor) selectedTextColor: root.textColor font.family: root.panelFontFamily font.pixelSize: Style.font.bodySmall diff --git a/ui/components/ConfirmDeleteDialog.qml b/ui/components/ConfirmDeleteDialog.qml index 3a7a349..7bce5ba 100644 --- a/ui/components/ConfirmDeleteDialog.qml +++ b/ui/components/ConfirmDeleteDialog.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls as QQC import qs.Commons import qs.Ui +import "../kit" // The one confirmation for destructive writes. A calendar event is gone for // good once the server says so, so it asks first: the opener names the target diff --git a/ui/components/ContactsPicker.qml b/ui/components/ContactsPicker.qml index 7f391ce..77d8fa1 100644 --- a/ui/components/ContactsPicker.qml +++ b/ui/components/ContactsPicker.qml @@ -3,6 +3,8 @@ import QtQuick.Controls as QQC import qs.Commons import qs.Ui import "../compose/Recipients.js" as Recipients +import "../theme" +import "../kit" Item { id: root @@ -155,7 +157,7 @@ Item { implicitHeight: Style.space(44) radius: Style.cornerRadius color: contactHover.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent" + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent" Rectangle { id: avatar @@ -165,7 +167,7 @@ Item { width: Style.space(26) height: width radius: width / 2 - color: Style.selectedFillFor(root.textColor, root.accentColor) + color: Paint.selectedFillFor(root.textColor, root.accentColor) Text { anchors.centerIn: parent diff --git a/ui/components/ConversationRail.qml b/ui/components/ConversationRail.qml index 6e3a17e..c56e551 100644 --- a/ui/components/ConversationRail.qml +++ b/ui/components/ConversationRail.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls import qs.Commons import "../account/Model.js" as Model +import "../theme" // The conversation beside the message, as a timeline down the right edge of the // reader. @@ -190,9 +191,9 @@ Item { height: implicitHeight radius: Style.cornerRadius color: modelData.open - ? Style.selectedFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) : (hover.containsMouse - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") MouseArea { id: hover diff --git a/ui/components/EmlSavedToast.qml b/ui/components/EmlSavedToast.qml index ebbc1ec..8b4ccc7 100644 --- a/ui/components/EmlSavedToast.qml +++ b/ui/components/EmlSavedToast.qml @@ -1,9 +1,10 @@ import QtQuick import Quickshell import qs.Commons -import qs.Commons as Commons import qs.Ui import "../account/MessageActions.js" as MessageActions +import "../theme" +import "../kit" // Says that a Save as .eml finished, and where the file went. The status line // says it too, but a caption at the window's edge was easy to miss for a file @@ -17,9 +18,9 @@ Rectangle { // seven, because App.qml sits against the repository's file-size ceiling. required property var app readonly property var service: app ? app.service : null - readonly property color textColor: app ? app.foreground : Commons.Color.foreground + readonly property color textColor: app ? app.foreground : Paint.foreground readonly property color dimColor: app ? app.dim : textColor - readonly property color accentColor: app ? app.accent : Commons.Color.accent + readonly property color accentColor: app ? app.accent : Paint.accent readonly property color popupBackgroundColor: app ? app.popupBackground : Qt.rgba(0, 0, 0, 1) readonly property color popupBorderColor: app ? app.popupBorder : textColor readonly property string panelFontFamily: app ? app.fontFamily : Style.font.family diff --git a/ui/components/EventSuggestionCard.qml b/ui/components/EventSuggestionCard.qml index 416c095..e73b9d8 100644 --- a/ui/components/EventSuggestionCard.qml +++ b/ui/components/EventSuggestionCard.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Ui import "../agent/Agent.js" as Agent +import "../theme" // What the agent found in the message: one row per event — what, when, // where — with Add and Dismiss. Add opens the calendar's composer with the @@ -33,7 +34,7 @@ Rectangle { implicitHeight: visible ? column.implicitHeight + Style.space(24) : 0 height: implicitHeight radius: Style.cornerRadius - color: Style.hoverFillFor(root.textColor, root.accentColor) + color: Paint.hoverFillFor(root.textColor, root.accentColor) border.width: 1 border.color: root.dimmerColor diff --git a/ui/components/GmailIcon.qml b/ui/components/GmailIcon.qml index 430aa3b..3510a8c 100644 --- a/ui/components/GmailIcon.qml +++ b/ui/components/GmailIcon.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Commons as Commons import qs.Ui +import "../theme" // The mark, drawn rather than rasterised from an SVG: the bar slot is about // 16px and Qt's SVG renderer smears strokes at that size. @@ -13,9 +14,9 @@ Item { id: root property real iconSize: Style.font.icon - property color color: Commons.Color.foreground + property color color: Paint.foreground property color markColor: color - property color badgeColor: Commons.Color.urgent + property color badgeColor: Paint.urgent // A dot, not a count: the bar says "something arrived", the tooltip says // how much, and the window says what. property bool dot: false @@ -103,6 +104,6 @@ Item { anchors.rightMargin: -parent.width * 0.06 anchors.top: parent.top anchors.topMargin: -parent.height * 0.04 - borderSpec: Border.flat(Commons.Color.popups.background, 1) + borderSpec: Border.flat(Paint.popupBackground, 1) } } diff --git a/ui/components/HeySetupPage.qml b/ui/components/HeySetupPage.qml index 085b8f5..9f7ef5e 100644 --- a/ui/components/HeySetupPage.qml +++ b/ui/components/HeySetupPage.qml @@ -2,6 +2,8 @@ import QtQuick import qs.Commons import qs.Ui import "../providers/Registry.js" as Provider +import "../theme" +import "../kit" // Connecting a HEY mailbox, which is a program and a button. // @@ -98,9 +100,9 @@ Column { width: parent.width implicitHeight: commandText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) TextEdit { id: commandText @@ -115,7 +117,7 @@ Column { wrapMode: TextEdit.WrapAnywhere color: root.textColor selectedTextColor: root.textColor - selectionColor: Style.selectedFillFor(root.textColor, root.accentColor) + selectionColor: Paint.selectedFillFor(root.textColor, root.accentColor) font.family: root.panelFontFamily font.pixelSize: Style.font.bodySmall } diff --git a/ui/components/IconButton.qml b/ui/components/IconButton.qml index dd4c1d6..eaf718a 100644 --- a/ui/components/IconButton.qml +++ b/ui/components/IconButton.qml @@ -2,6 +2,8 @@ import QtQuick import qs.Commons import qs.Commons as Commons import qs.Ui +import "../theme" +import "../kit" // A drawn icon on the kit's shared hover/cursor surface. qs.Ui's // PanelActionButton takes a font glyph, and this app's icons are Canvas paths, @@ -11,9 +13,9 @@ Item { property string iconName: "" property string tooltipText: "" - property color foreground: Commons.Color.foreground + property color foreground: Paint.foreground property color hoverColor: foreground - property color accent: Commons.Color.accent + property color accent: Paint.accent property bool filled: false property bool hasCursor: false // Held down for as long as a menu this button opened is on screen. A trigger @@ -69,9 +71,9 @@ Item { anchors.fill: parent anchors.margins: root.visualInset radius: Style.cornerRadius - color: mouse.pressed ? Style.pressedFillFor(root.foreground, root.accent) - : (root.selected ? Style.selectedFillFor(root.foreground, root.accent) - : (root.hot ? Style.hoverFillFor(root.foreground, root.accent) : "transparent")) + color: mouse.pressed ? Paint.pressedFillFor(root.foreground, root.accent) + : (root.selected ? Paint.selectedFillFor(root.foreground, root.accent) + : (root.hot ? Paint.hoverFillFor(root.foreground, root.accent) : "transparent")) } ActionIcon { diff --git a/ui/components/IconTextButton.qml b/ui/components/IconTextButton.qml index 5baed50..7c359ea 100644 --- a/ui/components/IconTextButton.qml +++ b/ui/components/IconTextButton.qml @@ -2,6 +2,8 @@ import QtQuick import qs.Commons import qs.Commons as Commons import qs.Ui +import "../theme" +import "../kit" // A bordered button carrying a drawn icon beside its label. // @@ -15,8 +17,8 @@ Rectangle { property string iconName: "" property string text: "" property string tooltipText: "" - property color foreground: Commons.Color.foreground - property color accent: Commons.Color.accent + property color foreground: Paint.foreground + property color accent: Paint.accent property bool bordered: true // Reserve the normal border but leave the field clear until interaction. property bool outline: false @@ -50,15 +52,15 @@ Rectangle { : Style.spacing.controlHeight radius: Style.cornerRadius opacity: enabled ? 1.0 : 0.4 - color: mouse.pressed ? Style.pressedFillFor(root.foreground, root.accent) - : (root.selected ? Style.selectedFillFor(root.foreground, root.accent) - : (hot ? Style.hoverFillFor(root.foreground, root.accent) + color: mouse.pressed ? Paint.pressedFillFor(root.foreground, root.accent) + : (root.selected ? Paint.selectedFillFor(root.foreground, root.accent) + : (hot ? Paint.hoverFillFor(root.foreground, root.accent) : (bordered && !ghost && !outline - ? Style.normalFillFor(root.foreground, root.accent) : "transparent"))) + ? Paint.normalFillFor(root.foreground, root.accent) : "transparent"))) border.width: (ghost ? root.selected : (bordered || hot || root.selected)) ? Style.normalBorderWidth : 0 border.color: hot || root.selected - ? Style.hoverBorderFor(root.foreground, root.accent) - : Style.normalBorderFor(root.foreground, root.accent) + ? Paint.hoverBorderFor(root.foreground, root.accent) + : Paint.normalBorderFor(root.foreground, root.accent) Row { id: row diff --git a/ui/components/ImapSetupPage.qml b/ui/components/ImapSetupPage.qml index c1043b4..f59b38e 100644 --- a/ui/components/ImapSetupPage.qml +++ b/ui/components/ImapSetupPage.qml @@ -4,6 +4,8 @@ import qs.Ui import "../providers/ImapProtocol.js" as Imap import "../account/Accounts.js" as Accounts import "../account/Aliases.js" as Aliases +import "../theme" +import "../kit" // Connecting an ordinary mailbox: an address, a password, and — only if the // guess was wrong — the servers. @@ -204,9 +206,9 @@ Column { visible: root.toolsMissing implicitHeight: missingText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: missingText @@ -275,9 +277,9 @@ Column { visible: root.suggestion.note !== "" implicitHeight: noteColumn.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Column { id: noteColumn diff --git a/ui/components/InviteCard.qml b/ui/components/InviteCard.qml index 2d7aec3..4c2267c 100644 --- a/ui/components/InviteCard.qml +++ b/ui/components/InviteCard.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Ui import "../message/Calendar.js" as Calendar +import "../theme" // The meeting inside the message, drawn as the thing it is. // @@ -47,9 +48,9 @@ Rectangle { visible: !!invite implicitHeight: visible ? column.implicitHeight + Style.space(24) : 0 radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Column { id: column diff --git a/ui/components/JmapSetupPage.qml b/ui/components/JmapSetupPage.qml index a34e7a7..9b8c754 100644 --- a/ui/components/JmapSetupPage.qml +++ b/ui/components/JmapSetupPage.qml @@ -3,6 +3,8 @@ import qs.Commons import qs.Ui import "../providers/JmapProtocol.js" as Jmap import "../account/Accounts.js" as Accounts +import "../theme" +import "../kit" // Connecting a mailbox on a server that speaks JMAP: an address, a secret, and // — only if the address does not lead anywhere — the server. @@ -182,9 +184,9 @@ Column { visible: root.toolsMissing implicitHeight: missingText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: missingText @@ -238,9 +240,9 @@ Column { width: parent.width implicitHeight: noteText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: noteText @@ -416,9 +418,9 @@ Column { // The same surface every other note on this page draws on, with the // sentence in the danger colour rather than the box: colour alone never // carries state here, and the words are what says what happened. - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: rejectedText diff --git a/ui/components/KeyHints.qml b/ui/components/KeyHints.qml index 80814e1..ca56725 100644 --- a/ui/components/KeyHints.qml +++ b/ui/components/KeyHints.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Ui import "../keys/Keymap.js" as Keymap +import "../theme" // What the keyboard offers from wherever you are standing. // @@ -39,7 +40,7 @@ Row { radius: Style.cornerRadius // Fill only. An outline as well made these read as buttons you could // press, which drew far more attention than a hint deserves. - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Text { id: cap diff --git a/ui/components/LabelMovePicker.qml b/ui/components/LabelMovePicker.qml index 9b128a0..a64d337 100644 --- a/ui/components/LabelMovePicker.qml +++ b/ui/components/LabelMovePicker.qml @@ -5,6 +5,7 @@ import qs.Commons import qs.Ui import "../account/Model.js" as Model import "Menu.js" as Menu +import "../theme" // Where a label goes: the top level, or under another label. The rows are // `Model.labelMoveTargets` — not the label itself, nothing beneath it, not @@ -119,9 +120,9 @@ Item { implicitHeight: Style.spacing.popupRowHeight radius: Style.cornerRadius color: rowHover.hovered || hasCursor - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent" + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent" border.width: hasCursor ? Style.normalBorderWidth : 0 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) ActionIcon { id: rowIcon diff --git a/ui/components/LabelPicker.qml b/ui/components/LabelPicker.qml index ddc024e..f76e8b6 100644 --- a/ui/components/LabelPicker.qml +++ b/ui/components/LabelPicker.qml @@ -3,6 +3,8 @@ import QtQuick.Controls as QQC import qs.Commons import qs.Ui import "../account/Model.js" as Model +import "../theme" +import "../kit" // Where a message goes when it leaves the inbox with somewhere to be. // @@ -184,9 +186,9 @@ Item { implicitHeight: Style.space(34) radius: Style.cornerRadius color: labelRow.hasCursor || rowHover.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent" + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent" border.width: labelRow.hasCursor ? Style.normalBorderWidth : 0 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) // A child steps in under its parent, and is named by its own // leaf; a match to typed letters shows its whole path, flat. diff --git a/ui/components/LinkLabel.qml b/ui/components/LinkLabel.qml index 96f9304..bd2ff33 100644 --- a/ui/components/LinkLabel.qml +++ b/ui/components/LinkLabel.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" // One word or phrase inside a line of text that is a link out of the window. // diff --git a/ui/components/M365SetupPage.qml b/ui/components/M365SetupPage.qml index 31add6c..768099c 100644 --- a/ui/components/M365SetupPage.qml +++ b/ui/components/M365SetupPage.qml @@ -3,6 +3,8 @@ import qs.Commons import qs.Ui import "../providers/M365Protocol.js" as M365 import "../account/Accounts.js" as Accounts +import "../theme" +import "../kit" // A work or school mailbox on Microsoft 365: an address, the Application (client) // ID of an app registered once in Microsoft Entra, and one code. @@ -110,9 +112,9 @@ Column { visible: root.backendProblem !== "" && !root.signedIn implicitHeight: missingText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: missingText @@ -271,9 +273,9 @@ Column { visible: root.busy && !!root.auth && root.auth.userCode !== "" implicitHeight: deviceColumn.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Column { id: deviceColumn diff --git a/ui/components/MailboxSidebar.qml b/ui/components/MailboxSidebar.qml index a362603..85d3f50 100644 --- a/ui/components/MailboxSidebar.qml +++ b/ui/components/MailboxSidebar.qml @@ -4,6 +4,8 @@ import qs.Commons import qs.Ui import "../account/Model.js" as Model import "../providers/Registry.js" as Provider +import "../theme" +import "../kit" // The left column: the mailboxes this account's provider has, then whatever // labels or folders the server reported, A to Z. @@ -212,8 +214,8 @@ Item { implicitHeight: Style.space(28) radius: Style.cornerRadius color: entry.selected - ? Style.selectedFillFor(root.textColor, root.accentColor) - : (hover.hovered ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.selectedFillFor(root.textColor, root.accentColor) + : (hover.hovered ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") ActionIcon { id: glyph @@ -268,7 +270,7 @@ Item { // This names a shortcut; it is not another selected state layered over // the selected mailbox row. The lighter normal fill stays legible on // dark themes without becoming a stack of grey tabs on Lupine. - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Text { anchors.centerIn: parent diff --git a/ui/components/MailboxTabs.qml b/ui/components/MailboxTabs.qml index 2273564..5cc5f7f 100644 --- a/ui/components/MailboxTabs.qml +++ b/ui/components/MailboxTabs.qml @@ -3,6 +3,8 @@ import QtQuick.Controls as QQC import qs.Commons import qs.Ui import "../account/Model.js" as Model +import "../theme" +import "../kit" // The mailboxes, as one row of chips. What they are depends on the provider — // Gmail's are searches, so "Unread" and "All mail" sit next to "Inbox" without @@ -77,7 +79,7 @@ Flickable { radius: Style.cornerRadius color: "transparent" border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Row { id: chips @@ -115,7 +117,7 @@ Flickable { : segment.modelData.label foreground: root.textColor bordered: false - selected: root.current === segment.modelData.key + chosen: root.current === segment.modelData.key hasCursor: root.cursorIndex === segment.index fontSize: Style.font.bodySmall onClicked: root.selected(segment.modelData.key) diff --git a/ui/components/MessageList.qml b/ui/components/MessageList.qml index ac22f34..06ba888 100644 --- a/ui/components/MessageList.qml +++ b/ui/components/MessageList.qml @@ -4,6 +4,7 @@ import qs.Ui import "../account/Model.js" as Model import "../account/Unified.js" as Unified import "../agent/Agent.js" as Agent +import "../kit" // The message list. A Repeater in a Column rather than a ListView because the // panel already owns one Flickable and nesting a second scroller inside it diff --git a/ui/components/MessageReader.qml b/ui/components/MessageReader.qml index 0327b6c..477c740 100644 --- a/ui/components/MessageReader.qml +++ b/ui/components/MessageReader.qml @@ -7,6 +7,8 @@ import "../message/Html.js" as Html import "../message/Message.js" as Mail import "../message/Mailto.js" as Mailto import "../account/Model.js" as Model +import "../theme" +import "../kit" // The right column. The body goes through Qt's own rich text engine — a real // HTML renderer, not a browser — after Html.sanitize has removed what Qt would @@ -751,7 +753,7 @@ Item { direction: root.bodyDirection }), root.bodySource === "html")) color: root.textColor - selectionColor: Style.selectionFillFor(root.textColor, root.accentColor) + selectionColor: Paint.selectionFillFor(root.textColor, root.accentColor) selectedTextColor: root.textColor font.family: root.panelFontFamily // Body text, where the chrome around it is bodySmall: this is the one @@ -857,7 +859,7 @@ Item { fontSize: Style.font.caption horizontalPadding: Style.space(6) verticalPadding: Style.space(3) - selected: root.attachmentsExpanded + chosen: root.attachmentsExpanded onClicked: root.attachmentsExpanded = !root.attachmentsExpanded } @@ -1080,7 +1082,7 @@ Item { radius: Style.cornerRadius color: "transparent" border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Row { id: modeSegments @@ -1141,7 +1143,7 @@ Item { } } - // One of the three ways of reading a message. `selected` is the window's + // One of the three ways of reading a message. `chosen` is the window's // choice rather than what is on screen: a message too heavy to draw the // chosen way says so in its own notice, and a picker that quietly moved to // the mode it fell back to would leave nothing saying the choice still @@ -1152,9 +1154,9 @@ Item { // Nothing to choose between where there is no markup: the text is then the // message rather than one reading of it. visible: root.hasHtml - selected: root.bodyMode === mode + chosen: root.bodyMode === mode bordered: false - foreground: selected ? root.textColor : root.dimColor + foreground: chosen ? root.textColor : root.dimColor accent: root.accentColor fontFamily: root.panelFontFamily fontSize: Style.font.caption diff --git a/ui/components/MessageRow.qml b/ui/components/MessageRow.qml index 91998c6..7046cd4 100644 --- a/ui/components/MessageRow.qml +++ b/ui/components/MessageRow.qml @@ -4,6 +4,8 @@ import qs.Ui import "../message/Direction.js" as Direction import "../account/Model.js" as Model import "../keys/Keymap.js" as Keymap +import "../theme" +import "../kit" // One message in the list. Unread is carried by weight and by the dot on the // left, never by colour alone — the accent is a theme value that some themes @@ -105,8 +107,8 @@ Rectangle { radius: Style.cornerRadius // The checkbox identifies bulk selection independently of the reader fill. color: selected || hasCursor || checked - ? Style.selectedFillFor(textColor, accentColor) - : (hot ? Style.hoverFillFor(textColor, accentColor) : "transparent") + ? Paint.selectedFillFor(textColor, accentColor) + : (hot ? Paint.hoverFillFor(textColor, accentColor) : "transparent") MouseArea { id: mouse @@ -349,20 +351,20 @@ Rectangle { width: Style.space(12) height: width radius: 0 - color: checkMouse.pressed ? Style.pressedFillFor(root.textColor, root.accentColor) - : (root.checked ? Style.selectedFillFor(root.textColor, root.accentColor) - : (checkMouse.containsMouse ? Style.hoverFillFor(root.textColor, root.accentColor) + color: checkMouse.pressed ? Paint.pressedFillFor(root.textColor, root.accentColor) + : (root.checked ? Paint.selectedFillFor(root.textColor, root.accentColor) + : (checkMouse.containsMouse ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent")) borderSpec: root.checked - ? Border.controlSpec("selected", root.textColor, root.accentColor) - : Border.controlSpec("normal", root.textColor, root.accentColor) + ? Paint.controlSpec("selected", root.textColor, root.accentColor) + : Paint.controlSpec("normal", root.textColor, root.accentColor) ActionIcon { anchors.centerIn: parent visible: root.checked name: "check" iconSize: Math.round(checkBox.height * 0.85) - color: Style.selectedStateColor(root.textColor, root.accentColor) + color: Paint.selectedStateColor(root.textColor, root.accentColor) } } diff --git a/ui/components/NamePrompt.qml b/ui/components/NamePrompt.qml index 2114d71..433fcb8 100644 --- a/ui/components/NamePrompt.qml +++ b/ui/components/NamePrompt.qml @@ -2,6 +2,7 @@ import QtQuick import QtQuick.Controls as QQC import qs.Commons import qs.Ui +import "../kit" // One name, asked for: a new label's, or a label's new one. A small modal // popup rather than a page, because the answer is a word and the place it diff --git a/ui/components/OutlookSetupPage.qml b/ui/components/OutlookSetupPage.qml index 7145b2d..3b2ec6e 100644 --- a/ui/components/OutlookSetupPage.qml +++ b/ui/components/OutlookSetupPage.qml @@ -4,6 +4,8 @@ import qs.Ui import "../providers/Outlook.js" as Outlook import "../providers/MicrosoftOAuth.js" as Microsoft import "../account/Accounts.js" as Accounts +import "../theme" +import "../kit" // Outlook.com and Hotmail use Microsoft OAuth. The app registration is a // public client: its ID is configuration, not a secret, and the account @@ -182,9 +184,9 @@ Column { visible: root.toolsMissing implicitHeight: missingText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: missingText @@ -416,9 +418,9 @@ Column { visible: root.busy && root.auth && root.auth.userCode !== "" implicitHeight: deviceColumn.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Column { id: deviceColumn diff --git a/ui/components/ProviderHero.qml b/ui/components/ProviderHero.qml index 17a8117..a7a118d 100644 --- a/ui/components/ProviderHero.qml +++ b/ui/components/ProviderHero.qml @@ -3,6 +3,7 @@ import qs.Commons import qs.Ui import "../providers/Registry.js" as Provider import "../account/Model.js" as Model +import "../kit" // What a setup page opens with: the service's own mark, its name, and one line // saying what connecting it involves. diff --git a/ui/components/ProviderLogo.qml b/ui/components/ProviderLogo.qml index 4e21d98..a589e5d 100644 --- a/ui/components/ProviderLogo.qml +++ b/ui/components/ProviderLogo.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Commons as Commons import qs.Ui +import "../theme" // The mark of the service a setup page is about. // @@ -30,7 +31,7 @@ Item { // and no brand this could put a name to. Left empty where a missing mark // should simply take no room. property string fallbackIcon: "" - property color fallbackColor: Commons.Color.foreground + property color fallbackColor: Paint.foreground readonly property bool present: logo !== "" || fallbackIcon !== "" readonly property bool drawn: logo !== "" diff --git a/ui/components/ProviderPicker.qml b/ui/components/ProviderPicker.qml index effa4d4..afc6e86 100644 --- a/ui/components/ProviderPicker.qml +++ b/ui/components/ProviderPicker.qml @@ -2,6 +2,7 @@ import QtQuick import qs.Commons import qs.Ui import "../providers/Registry.js" as Provider +import "../theme" // Which kind of mailbox is being added, asked once and before anything else. // @@ -66,10 +67,10 @@ Column { implicitHeight: Math.max(cardText.implicitHeight, cardMark.height) + Style.space(24) radius: Style.cornerRadius color: card.connectable && hover.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) - : Style.normalFillFor(root.textColor, root.accentColor) + ? Paint.hoverFillFor(root.textColor, root.accentColor) + : Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) // Not greyed out with a literal colour — the theme owns those. Reduced // opacity says "not available" without inventing a grey that some // themes render as ordinary body text. diff --git a/ui/components/ReaderNotice.qml b/ui/components/ReaderNotice.qml index 30620db..117867c 100644 --- a/ui/components/ReaderNotice.qml +++ b/ui/components/ReaderNotice.qml @@ -2,6 +2,8 @@ import QtQuick import QtQuick.Controls import qs.Commons import qs.Ui +import "../theme" +import "../kit" // A line above the message saying why it does not look the way the sender // meant it to, and offering the one thing that would change that. @@ -28,9 +30,9 @@ Rectangle { implicitHeight: Style.space(30) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Text { anchors.left: parent.left diff --git a/ui/components/RecipientSuggestions.qml b/ui/components/RecipientSuggestions.qml index 191234d..a99be26 100644 --- a/ui/components/RecipientSuggestions.qml +++ b/ui/components/RecipientSuggestions.qml @@ -1,5 +1,6 @@ import QtQuick import qs.Commons +import "../theme" Rectangle { id: root @@ -65,9 +66,9 @@ Rectangle { height: Style.space(40) radius: Style.cornerRadius color: root.currentIndex === suggestion.index - ? Style.selectedFillFor(root.textColor, root.accentColor) + ? Paint.selectedFillFor(root.textColor, root.accentColor) : (suggestionHover.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") Column { anchors.left: parent.left diff --git a/ui/components/SearchBar.qml b/ui/components/SearchBar.qml index 15acc9e..7352b11 100644 --- a/ui/components/SearchBar.qml +++ b/ui/components/SearchBar.qml @@ -1,6 +1,8 @@ import QtQuick import qs.Commons import qs.Ui +import "../theme" +import "../kit" // Gmail's own operator syntax goes straight through — `from:`, `has:attachment`, // `older_than:7d`. Translating it would only take away what people already know. @@ -70,8 +72,8 @@ Item { background: Rectangle { radius: Style.cornerRadius color: field.activeFocus || field.hovered - ? Style.hoverFillFor(root.textColor, root.accentColor) - : Style.normalFillFor(root.textColor, root.accentColor) + ? Paint.hoverFillFor(root.textColor, root.accentColor) + : Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 // A divider's weight, not a control's. The kit's control border is what // made this the loudest thing in a row of dim icons; the rail's edge is @@ -79,7 +81,7 @@ Item { // itself, which is what a field nobody uses on most visits should be. // Focus still gets the real border, because then it is saying something. border.color: field.activeFocus - ? Style.hoverBorderFor(root.textColor, root.accentColor) + ? Paint.hoverBorderFor(root.textColor, root.accentColor) : Qt.rgba(root.textColor.r, root.textColor.g, root.textColor.b, 0.12) } } diff --git a/ui/components/SenderNameField.qml b/ui/components/SenderNameField.qml index de8f4a9..a4237af 100644 --- a/ui/components/SenderNameField.qml +++ b/ui/components/SenderNameField.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" // The name recipients see beside this mailbox's address, asked for where the // mailbox is set up so its first message is not sent nameless. Only on the diff --git a/ui/components/SettingsPage.qml b/ui/components/SettingsPage.qml index 8aebfe4..8319b24 100644 --- a/ui/components/SettingsPage.qml +++ b/ui/components/SettingsPage.qml @@ -7,6 +7,8 @@ import "../settings/Appearance.js" as Appearance import "../compose/Spelling.js" as Spelling import "../message/Html.js" as Html import "../account/Accounts.js" as Accounts +import "../theme" +import "../kit" // Where mailboxes are managed. // @@ -48,6 +50,8 @@ Column { // is a component with its own heading, so its top stands in. readonly property var sections: { var values = [{ key: "backend", title: "Mail backend", y: backendSetup.y }] + if (root.service && root.appThemeChoice && root.appThemeChoice.enabled === true) + values.push({ key: "appTheme", title: "Appearance", y: appThemeHeading.y }) if (!root.service || root.service.hasTray !== false) values.push({ key: "bar", title: "Bar", y: barHeading.y }) if (root.service && root.service.hasMailto === true) @@ -273,8 +277,20 @@ Column { if (visible && service && typeof service.refreshDefaultMailClient === "function") service.refreshDefaultMailClient() } - onServiceChanged: refreshDefaultMailClient() - onVisibleChanged: refreshDefaultMailClient() + // The installed themes can change from a terminal while the window is open, + // and the list is what the picker offers, so ask whenever the page comes + // into view. + function refreshThemes() { + if (visible && service && service.theme) service.theme.refresh() + } + onServiceChanged: { + refreshDefaultMailClient() + refreshThemes() + } + onVisibleChanged: { + refreshDefaultMailClient() + refreshThemes() + } Component.onCompleted: { refreshDefaultMailClient() renderSignaturePreview() @@ -307,10 +323,88 @@ Column { font.bold: true } + // ----------------------------------------------------- theme (plugin) + // + // The plugin window's colours are the shell's, so it chooses an Omarchy theme + // of its own instead: Follow Omarchy, or any theme installed on the machine. + // The desktop itself is never changed. The standalone window has no Omarchy + // theme to offer and keeps its System/Light/Dark choice below. + + // A host without a theme choice at all is a host whose service has none: the + // row is absent rather than empty. + readonly property var appThemeChoice: root.service && root.service.theme + ? root.service.theme : null + readonly property bool showsAppTheme: !!root.appThemeChoice && root.appThemeChoice.enabled === true + + Text { + id: appThemeHeading + visible: root.showsAppTheme + text: "APPEARANCE" + color: root.dimColor + font.family: root.panelFontFamily + font.pixelSize: Style.font.caption + font.letterSpacing: 1 + } + + Rectangle { + objectName: "app-theme-settings" + visible: root.showsAppTheme + width: parent.width + implicitHeight: Math.max(appThemeText.implicitHeight, appThemePicker.implicitHeight) + + Style.space(16) + radius: Style.cornerRadius + color: Paint.normalFillFor(root.textColor, root.accentColor) + + Column { + id: appThemeText + anchors.left: parent.left + anchors.leftMargin: Style.space(12) + anchors.right: appThemePicker.left + anchors.rightMargin: Style.space(10) + anchors.verticalCenter: parent.verticalCenter + spacing: Style.space(2) + + Text { + width: parent.width + text: "Theme" + color: root.textColor + font.family: root.panelFontFamily + font.pixelSize: Style.font.bodySmall + textFormat: Text.PlainText + } + + Text { + width: parent.width + text: "Follow Omarchy draws this window in the desktop's theme. Any other choice recolours this window only." + color: root.dimColor + font.family: root.panelFontFamily + font.pixelSize: Style.font.caption + wrapMode: Text.WordWrap + textFormat: Text.PlainText + } + } + + Dropdown { + id: appThemePicker + objectName: "app-theme-picker" + anchors.right: parent.right + anchors.rightMargin: Style.space(10) + anchors.verticalCenter: parent.verticalCenter + width: Style.space(220) + showLabel: false + value: root.appThemeChoice ? root.appThemeChoice.selected : "" + options: root.appThemeChoice ? root.appThemeChoice.options : [] + foreground: root.textColor + accent: root.accentColor + fontFamily: root.panelFontFamily + onChanged: function(next) { if (root.appThemeChoice) root.appThemeChoice.choose(next) } + } + } + // ------------------------------------------------------------ appearance // - // Standalone only. The plugin's palette is the shell's, and the row would - // have nothing to change. + // Standalone only: the plugin window picks an Omarchy theme of its own in the + // row above, and this one would have nothing to change. Text { id: appearanceHeading @@ -329,7 +423,7 @@ Column { implicitHeight: Math.max(appearanceText.implicitHeight, appearanceTrack.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: appearanceText @@ -369,7 +463,7 @@ Column { radius: Style.cornerRadius color: "transparent" border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Row { id: appearanceSegments @@ -401,7 +495,7 @@ Column { implicitHeight: Math.max(barIconText.implicitHeight, barIconSwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: barIconText @@ -486,7 +580,7 @@ Column { implicitHeight: Math.max(mailClientText.implicitHeight, mailClientButton.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) readonly property bool isDefault: !!root.service && root.service.defaultMailClient === "default" @@ -568,7 +662,7 @@ Column { implicitHeight: Math.max(imagesText.implicitHeight, imagesSwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: imagesText @@ -619,7 +713,7 @@ Column { implicitHeight: Math.max(heavyText.implicitHeight, heavySwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: heavyText @@ -666,7 +760,7 @@ Column { implicitHeight: Math.max(directionText.implicitHeight, directionTrack.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: directionText @@ -711,7 +805,7 @@ Column { radius: Style.cornerRadius color: "transparent" border.width: 1 - border.color: Style.normalBorderFor(root.textColor, root.accentColor) + border.color: Paint.normalBorderFor(root.textColor, root.accentColor) Row { id: directionSegments @@ -750,7 +844,7 @@ Column { implicitHeight: Math.max(suggestText.implicitHeight, suggestSwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: suggestText @@ -840,7 +934,7 @@ Column { implicitHeight: Math.max(spellingText.implicitHeight, spellingSwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: spellingText @@ -975,7 +1069,7 @@ Column { implicitHeight: Math.max(notifyText.implicitHeight, notifySwitch.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: notifyText @@ -1045,7 +1139,7 @@ Column { implicitHeight: Math.max(undoText.implicitHeight, undoSeconds.implicitHeight) + Style.space(16) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: undoText @@ -1132,7 +1226,7 @@ Column { implicitHeight: Math.max(signatureEdit.implicitHeight, Style.space(56)) + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) // The padding is part of the field visually, so it is part of its click // target too. Kept behind the editor so clicks on text still place the @@ -1152,7 +1246,7 @@ Column { wrapMode: TextEdit.Wrap textFormat: TextEdit.PlainText color: root.textColor - selectionColor: Style.selectionFillFor(root.textColor, root.accentColor) + selectionColor: Paint.selectionFillFor(root.textColor, root.accentColor) selectedTextColor: root.textColor font.family: root.panelFontFamily font.pixelSize: Style.font.bodySmall @@ -1228,7 +1322,7 @@ Column { visible: root.selectedSignatureHtml !== "" implicitHeight: Math.min(Style.space(220), signaturePreview.implicitHeight + Style.space(20)) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) clip: true TextEdit { @@ -1424,7 +1518,7 @@ Column { // signature section names the mailbox it signs — and the row answers // no click, so marking it borrowed the switcher's "you are here, click // another" fill for a row that switches nothing. - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) Column { id: rowText @@ -1613,9 +1707,9 @@ Column { required property string mode property bool firstSegment: false objectName: "appearance-" + mode.toLowerCase() - selected: !!root.service && root.service.appearance === mode + chosen: !!root.service && root.service.appearance === mode bordered: false - foreground: selected ? root.textColor : root.dimColor + foreground: chosen ? root.textColor : root.dimColor accent: root.accentColor fontFamily: root.panelFontFamily fontSize: Style.font.caption @@ -1635,9 +1729,9 @@ Column { component DirectionButton: Button { required property string mode property bool firstSegment: false - selected: !!root.service && root.service.contentDirection === mode + chosen: !!root.service && root.service.contentDirection === mode bordered: false - foreground: selected ? root.textColor : root.dimColor + foreground: chosen ? root.textColor : root.dimColor accent: root.accentColor fontFamily: root.panelFontFamily fontSize: Style.font.caption diff --git a/ui/components/SettingsSidebar.qml b/ui/components/SettingsSidebar.qml index afb1ec4..7c9bac7 100644 --- a/ui/components/SettingsSidebar.qml +++ b/ui/components/SettingsSidebar.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../theme" // The rail beside the settings page: its section names, one highlighted. // @@ -42,8 +43,8 @@ Column { implicitHeight: Style.space(28) radius: Style.cornerRadius color: entry.selected - ? Style.selectedFillFor(root.textColor, root.accentColor) - : (hover.hovered ? Style.hoverFillFor(root.textColor, root.accentColor) : "transparent") + ? Paint.selectedFillFor(root.textColor, root.accentColor) + : (hover.hovered ? Paint.hoverFillFor(root.textColor, root.accentColor) : "transparent") Text { anchors.left: parent.left diff --git a/ui/components/SetupPage.qml b/ui/components/SetupPage.qml index 1007f25..1239c0a 100644 --- a/ui/components/SetupPage.qml +++ b/ui/components/SetupPage.qml @@ -2,6 +2,8 @@ import QtQuick import qs.Commons import qs.Ui import "../providers/Registry.js" as Provider +import "../theme" +import "../kit" // Connecting a mailbox, as two steps instead of a wall of instructions. // @@ -123,9 +125,9 @@ Column { visible: root.toolsMissing implicitHeight: missingText.implicitHeight + Style.space(20) radius: Style.cornerRadius - color: Style.normalFillFor(root.textColor, root.accentColor) + color: Paint.normalFillFor(root.textColor, root.accentColor) border.width: 1 - border.color: Style.hoverBorderFor(root.textColor, root.accentColor) + border.color: Paint.hoverBorderFor(root.textColor, root.accentColor) Text { id: missingText diff --git a/ui/components/SwitcherSearch.qml b/ui/components/SwitcherSearch.qml index 9434a79..d3fede7 100644 --- a/ui/components/SwitcherSearch.qml +++ b/ui/components/SwitcherSearch.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" // The line at the top of a switcher that typing goes into. Letters narrow // the rows to the ones they name; the arrows, or Ctrl with J, K, N or P, diff --git a/ui/components/UndoSendToast.qml b/ui/components/UndoSendToast.qml index 9fc1a3b..cb1a3f3 100644 --- a/ui/components/UndoSendToast.qml +++ b/ui/components/UndoSendToast.qml @@ -1,6 +1,7 @@ import QtQuick import qs.Commons import qs.Ui +import "../kit" Rectangle { id: root diff --git a/ui/kit/Button.qml b/ui/kit/Button.qml new file mode 100644 index 0000000..a816904 --- /dev/null +++ b/ui/kit/Button.qml @@ -0,0 +1,260 @@ +import QtQuick +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's Button, drawn in the window's own theme. +// +// Three things are re-pointed. The fill comes from Paint, because the kit reads +// its state colours from Style's `[controls]` tokens — which Omarchy renders +// with the desktop theme's hex baked in, so a passed foreground is ignored. The +// border and the tooltip come from Paint for the same reason. And a chosen +// button keeps the shell's non-colour indication: its label stays bold. +// +// The shell derives that weight from `selected`, which also recolours the label +// from those same baked tokens and keeps that colour private. So with a theme +// picked the label the base would draw is not asked for, and one in the +// window's colour is drawn here instead: same font, same weight, same geometry, +// in the caller's colour. The base still paints the fill, the border, the press +// and the tooltip, and still owns the click, hover and focus contract. +// +// In Follow Omarchy none of that happens: `selected` is `chosen`, the base +// draws its own label, and the button is the shell's button. +// +// The wrapper is a focus scope around the base, so focus given to either is +// focus on both: callers that ask `button.activeFocus` — the dialogs that turn +// Return into a click, because the standalone host's button does not — get the +// answer they got when the button was the shell's own. +FocusScope { + id: root + + // The shell's public surface. `background` and `fontSize` stay unset so a + // host's own default — the two hosts disagree on both — still applies. + property string text: "" + property string tooltipText: "" + property bool chosen: false + property bool hasCursor: false + property bool focusable: false + property bool bordered: false + property color foreground: Paint.active ? Paint.foreground : Commons.Color.foreground + property color accent: Paint.active ? Paint.accent : Commons.Color.accent + property var background: undefined + property var fontSize: undefined + property string fontFamily: Style.font.family + property real horizontalPadding: Style.spacing.controlPaddingX + property real verticalPadding: Style.spacing.controlPaddingY + property bool leftAlign: false + + signal clicked() + signal hovered(bool isHovered) + + // The shell derives the chosen state's weight from `selected`, so it stays on + // in both modes: a chosen button is bold either way. + property bool selected: root.chosen + + readonly property bool themed: Paint.active + readonly property bool hot: base.hot === true + readonly property bool pressing: base.pressing === true + readonly property real effectiveFontSize: root.fontSize !== undefined + ? root.fontSize : Style.font.body + readonly property color effectiveBackground: root.background !== undefined + ? root.background : "transparent" + + // The colours the shell's button publishes, for the callers that read them. + // They are the base's own values, whichever mode it is in. + readonly property alias color: base.color + readonly property var border: base.border + readonly property var borderSpec: base.borderSpec + readonly property color tooltipBackground: base.tooltipBackground !== undefined + ? base.tooltipBackground : Commons.Color.tooltip.background + readonly property color tooltipForeground: base.tooltipForeground !== undefined + ? base.tooltipForeground : Commons.Color.tooltip.text + readonly property color tooltipBorder: base.tooltipBorder !== undefined + ? base.tooltipBorder : Commons.Color.tooltip.border + + // Whether the base publishes a tooltip palette at all: the shell's button + // does, the standalone host's does not. The answer is asked once, when the + // base exists, because a conditional binding whose `when` re-reads the very + // property it writes reports a binding loop — and every themed button in a + // window would report one. + property bool basePublishesTooltip: false + + Component.onCompleted: root.basePublishesTooltip = base.tooltipBackground !== undefined + && base.tooltipForeground !== undefined && base.tooltipBorder !== undefined + + // Geometry while themed, measured from the text that is actually drawn: the + // base's own implicit size is measured from the label it is asked not to draw. + // The widest border any visual state paints is reserved, so a themed button + // keeps its neighbours still as it is hovered and focused. + readonly property real borderReserve: Math.max( + root.focusable ? Paint.focusBorderWidth : 0, + Paint.hoverBorderWidth, + root.bordered || root.chosen ? Paint.normalBorderWidth : 0) + readonly property real labelRoom: Math.max(0, + root.width - root.horizontalPadding * 2 - root.borderReserve * 2) + + implicitWidth: root.themed + ? labelMetrics.advanceWidth + root.horizontalPadding * 2 + root.borderReserve * 2 + : base.implicitWidth + implicitHeight: root.themed + ? labelMetrics.height + root.verticalPadding * 2 + root.borderReserve * 2 + : base.implicitHeight + + TextMetrics { + id: labelMetrics + font.family: root.fontFamily + font.pixelSize: root.effectiveFontSize + font.bold: root.chosen + text: root.text + } + + ShellUi.Button { + id: base + anchors.fill: parent + enabled: root.enabled + + // The label is the wrapper's while themed, so the weight a chosen button is + // owed does not depend on the base's selected colour. + text: root.themed ? "" : root.text + + tooltipText: root.tooltipText + selected: root.selected + hasCursor: root.hasCursor + focusable: root.focusable + bordered: root.bordered + foreground: root.foreground + accent: root.accent + fontFamily: root.fontFamily + horizontalPadding: root.horizontalPadding + verticalPadding: root.verticalPadding + leftAlign: root.leftAlign + + // Inside the wrapper's scope the base is the item that holds the focus, + // and the Tab stop is still the base's own, as it was before the wrapper: + // its key handling, its focus ring and the dialogs that walk Tab + // themselves all see the button they saw then. + focus: true + + onClicked: root.clicked() + onHovered: function(isHovered) { root.hovered(isHovered) } + + // The kit's own MouseArea is private, so a passive handler watches the same + // press to know when to paint the pressed fill. + readonly property bool pressing: press.pressed + + TapHandler { + id: press + acceptedButtons: Qt.LeftButton | Qt.RightButton + } + } + + // A caller that names either of these is obeyed; one that does not keeps the + // host's own default. + Binding { + target: base + property: "background" + when: root.background !== undefined + restoreMode: Binding.RestoreBindingOrValue + value: root.background + } + + Binding { + target: base + property: "fontSize" + when: root.fontSize !== undefined + restoreMode: Binding.RestoreBindingOrValue + value: root.fontSize + } + + // A Tab stop wherever the host's own button is one, and callers ask the + // wrapper so; landing on the scope puts the focus on the base inside it. + // The shell's button is its own stop. The standalone host's is not: its + // stop is the control inside it, which is already in the chain, and a + // second stop here would make Tab land on each button twice. + activeFocusOnTab: root.focusable && base.activeFocusOnTab === true + + Binding { + target: base + property: "color" + when: Paint.active + restoreMode: Binding.RestoreBindingOrValue + // The kit's own ladder, in its own order: pressed, focus, hover, chosen, + // then whatever background the caller set. + value: base.pressing ? Paint.pressedFillFor(root.foreground, root.accent) + : (root.focusable && base.activeFocus ? Paint.focusFillFor(root.foreground, root.accent) + : (root.hot ? Paint.hoverFillFor(root.foreground, root.accent) + : (root.chosen ? Paint.selectedFillFor(root.foreground, root.accent) + : root.effectiveBackground))) + } + + // The label, in the window's colour and at the weight the chosen state keeps. + Text { + visible: root.themed + anchors.horizontalCenter: root.leftAlign ? undefined : parent.horizontalCenter + anchors.left: root.leftAlign ? parent.left : undefined + anchors.leftMargin: root.leftAlign ? root.horizontalPadding + root.borderReserve : 0 + anchors.verticalCenter: parent.verticalCenter + text: root.text + textFormat: Text.PlainText + color: root.foreground + font.family: root.fontFamily + font.pixelSize: root.effectiveFontSize + font.bold: root.chosen + width: Math.min(implicitWidth, root.labelRoom) + elide: Text.ElideRight + } + + // The border is one of the places the shell's `[controls]` tokens reach, so a + // picked theme supplies its own spec: the same geometry the live Style asks + // for, in the theme's colour. The state ladder and the rule that a plain + // button is borderless at rest are the shell's own. + readonly property string themedBorderState: { + if (root.focusable && base.activeFocus) return "focus" + if (base.hot) return "hover" + if (root.selected) return Paint.selectedBorderWidth > 0 ? "selected" + : (root.bordered ? "normal" : "none") + return root.bordered ? "normal" : "none" + } + + Binding { + target: base + property: "borderSpec" + when: Paint.active + restoreMode: Binding.RestoreBindingOrValue + // A Binding evaluates its value even while `when` is false, and the + // standalone host's Border has no `none()`: only a themed window asks. + value: !Paint.active ? null + : (root.themedBorderState === "none" ? Border.none() + : Paint.controlSpec(root.themedBorderState, root.foreground, root.accent)) + } + + // The tooltip's palette is published by the shell's button and baked from the + // same tokens, so it belongs to the window like everything else. + Binding { + target: base + property: "tooltipBackground" + when: Paint.active && root.basePublishesTooltip + restoreMode: Binding.RestoreBindingOrValue + value: Paint.tooltipBackground + } + + Binding { + target: base + property: "tooltipForeground" + when: Paint.active && root.basePublishesTooltip + restoreMode: Binding.RestoreBindingOrValue + value: Paint.tooltipText + } + + Binding { + target: base + property: "tooltipBorder" + when: Paint.active && root.basePublishesTooltip + restoreMode: Binding.RestoreBindingOrValue + value: Paint.tooltipBorder + } + + Accessible.role: Accessible.Button + Accessible.name: root.text !== "" ? root.text : root.tooltipText +} diff --git a/ui/kit/Dropdown.qml b/ui/kit/Dropdown.qml new file mode 100644 index 0000000..864a7d4 --- /dev/null +++ b/ui/kit/Dropdown.qml @@ -0,0 +1,320 @@ +import QtQuick +import QtQuick.Controls as QQC +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's Dropdown, drawn in the window's own theme. +// +// The kit paints the trigger's fill, its border and the row a keyboard cursor +// or pointer sits on from Style's `[controls]` tokens, which carry the desktop +// theme's hex — so nothing a caller passes reaches them. While a theme is +// picked the base is kept for what it is good at (its options, its value, its +// keyboard and pointer contract) and drawn at zero opacity and inert, and the +// same trigger and popup are drawn here from the base's public state. +// +// With Follow Omarchy none of that happens: the base is the dropdown, at full +// opacity, with its own popup. +Item { + id: root + + property string label: "" + property string value: "" + property var options: [] + + property color foreground: Paint.active ? Paint.popupText : Commons.Color.popups.text + property color background: Paint.active ? Paint.popupBackground : Commons.Color.popups.background + property color popupBorder: Paint.active ? Paint.popupBorder : Commons.Color.popups.border + property color accent: Paint.active ? Paint.accent : Commons.Color.accent + property string fontFamily: Style.font.family + property int rowHeight: Style.spacing.controlHeight + property int popupRowHeight: Style.spacing.popupRowHeight + property bool showLabel: true + property bool hasCursor: false + + readonly property bool themed: Paint.active + readonly property bool popupOpen: root.themed ? themedPopup.opened : base.popupOpen === true + // An open popup is not the same as an operable one: its rows only answer keys + // while the list holds the keyboard. Stated here so a caller can wait for the + // popup it just opened to be ready instead of guessing how long that takes. + readonly property bool popupHasFocus: root.themed && themedPopup.opened && optionList.activeFocus + + function open() { + if (root.themed) themedPopup.open() + else if (typeof base.open === "function") base.open() + } + function close() { + if (root.themed) themedPopup.close() + else if (typeof base.close === "function") base.close() + } + function toggle() { + if (root.themed) { + if (themedPopup.opened) themedPopup.close() + else themedPopup.open() + } else if (typeof base.toggle === "function") base.toggle() + } + + signal changed(string value) + signal hovered(bool isHovered) + + function optionValue(option) { + return (option && typeof option === "object") ? String(option.value) : String(option) + } + function optionLabel(option) { + return (option && typeof option === "object") ? String(option.label) : String(option) + } + function currentLabel() { + for (var i = 0; i < root.options.length; i++) { + if (root.optionValue(root.options[i]) === root.value) return root.optionLabel(root.options[i]) + } + return root.value + } + + implicitWidth: base.implicitWidth + implicitHeight: base.implicitHeight + + // A theme picked while the shell's popup is open would leave it drawn in the + // desktop's colours; closing it is the only honest answer. The base is also + // handed the value the window holds again, because choosing a row made it + // assign its own and stop following the wrapper: without this the trigger + // would still read the theme that was just left behind. + onThemedChanged: { + if (!root.themed) themedPopup.close() + base.value = root.value + } + + // The caller owns `value`, and the base is kept in step with it explicitly: + // its own row selection assigns the property directly, which is what severs + // a declarative binding. + Binding { + target: base + property: "value" + value: root.value + restoreMode: Binding.RestoreBindingOrValue + } + + ShellUi.Dropdown { + id: base + anchors.fill: parent + opacity: root.themed ? 0 : 1 + enabled: !root.themed + label: root.label + options: root.options + foreground: root.foreground + background: root.background + popupBorder: root.popupBorder + accent: root.accent + fontFamily: root.fontFamily + rowHeight: root.rowHeight + popupRowHeight: root.popupRowHeight + showLabel: root.showLabel + hasCursor: root.hasCursor + onChanged: function(next) { root.changed(next) } + onHovered: function(isHovered) { root.hovered(isHovered) } + } + + Column { + visible: root.themed + width: parent.width + spacing: Style.spacing.labelGap + + Text { + id: themedLabel + visible: root.showLabel && root.label !== "" + width: parent.width + textFormat: Text.PlainText + text: root.label + color: Qt.darker(root.foreground, 1.4) + font.family: root.fontFamily + font.pixelSize: Style.font.caption + font.bold: true + elide: Text.ElideRight + } + + Rectangle { + id: themedTrigger + width: parent.width + height: root.rowHeight + radius: Style.cornerRadius + + readonly property bool focused: themedTrigger.activeFocus + readonly property bool hot: themedHover.hovered || root.hasCursor + + color: Paint.controlFill(themedTrigger.focused, themedTrigger.hot, root.foreground, root.accent) + border.width: Paint.controlBorderWidth(themedTrigger.focused, themedTrigger.hot) + border.color: themedTrigger.focused + ? Paint.focusBorderFor(root.foreground, root.accent) + : (themedTrigger.hot + ? Paint.hoverBorderFor(root.foreground, root.accent) + : Paint.normalBorderFor(root.foreground, root.accent)) + + activeFocusOnTab: true + + HoverHandler { + id: themedHover + onHoveredChanged: root.hovered(hovered) + } + + Keys.onPressed: function(event) { + if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter + || event.key === Qt.Key_Space || event.key === Qt.Key_Down) { + if (themedPopup.opened) themedPopup.close() + else themedPopup.open() + event.accepted = true + } else if (event.key === Qt.Key_Escape && themedPopup.opened) { + themedPopup.close() + event.accepted = true + } + } + + Text { + textFormat: Text.PlainText + anchors.left: parent.left + anchors.right: themedChevron.left + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: themedTrigger.border.width + Style.spacing.controlPaddingX + anchors.rightMargin: themedTrigger.border.width + Style.spacing.md + text: root.currentLabel() + color: root.foreground + font.family: root.fontFamily + font.pixelSize: Style.font.body + elide: Text.ElideRight + } + + Text { + id: themedChevron + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.rightMargin: themedTrigger.border.width + Style.spacing.controlGap + text: "󰅀" + color: Qt.darker(root.foreground, 1.2) + font.family: root.fontFamily + font.pixelSize: Style.font.body + } + + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: { + themedTrigger.forceActiveFocus() + if (themedPopup.opened) themedPopup.close() + else themedPopup.open() + } + } + + QQC.Popup { + id: themedPopup + x: 0 + y: themedTrigger.height + Style.spacing.xxs + width: themedTrigger.width + implicitHeight: Math.min(root.options.length * root.popupRowHeight + + Math.max(0, root.options.length - 1) * Style.spacing.labelGap + Style.spacing.xxs, + root.popupRowHeight * 8 + 7 * Style.spacing.labelGap + Style.spacing.xxs) + padding: Style.spacing.hairline + leftPadding: Style.spacing.hairline * 2 + rightPadding: Style.spacing.hairline * 2 + topPadding: Style.spacing.hairline * 2 + bottomPadding: Style.spacing.hairline * 2 + focus: true + + background: Rectangle { + color: root.background + radius: Style.cornerRadius + border.width: Paint.normalBorderWidth + border.color: root.popupBorder + } + + onOpened: { + optionList.currentIndex = Math.max(0, optionList.indexOfValue(root.value)) + optionList.forceActiveFocus() + } + + // An open popup that has lost the keyboard cannot be used: its rows + // ignore keys and the trigger behind it answers them instead, so the + // first Return closes the popup without choosing anything. Take the + // keyboard back while the rows are the thing on screen. + onActiveFocusChanged: if (opened && !optionList.activeFocus) optionList.forceActiveFocus() + + contentItem: ListView { + id: optionList + spacing: Style.spacing.labelGap + + Keys.priority: Keys.BeforeItem + Keys.onPressed: function(event) { + if (event.key === Qt.Key_Escape) { + themedPopup.close() + event.accepted = true + } else if (event.key === Qt.Key_Down || event.text === "j") { + optionList.currentIndex = Math.min(root.options.length - 1, optionList.currentIndex + 1) + event.accepted = true + } else if (event.key === Qt.Key_Up || event.text === "k") { + optionList.currentIndex = Math.max(0, optionList.currentIndex - 1) + event.accepted = true + } else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { + optionList.selectCurrent() + event.accepted = true + } + } + implicitHeight: contentHeight + clip: true + boundsBehavior: Flickable.StopAtBounds + model: root.options + currentIndex: -1 + + function indexOfValue(wanted) { + for (var i = 0; i < root.options.length; i++) { + if (root.optionValue(root.options[i]) === wanted) return i + } + return -1 + } + + function selectCurrent() { + if (currentIndex < 0 || currentIndex >= root.options.length) return + var next = root.optionValue(root.options[currentIndex]) + // Both values move together: the wrapper's for its caller, and the + // base's so the trigger it draws in Follow mode never shows the + // theme that was just left. + root.value = next + base.value = next + root.changed(next) + themedPopup.close() + } + + delegate: Rectangle { + required property var modelData + required property int index + width: optionList.width + height: root.popupRowHeight + color: index === optionList.currentIndex + ? Paint.hoverFillFor(root.foreground, root.accent) + : "transparent" + + Text { + textFormat: Text.PlainText + anchors.left: parent.left + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + anchors.leftMargin: Style.spacing.controlPaddingX + anchors.rightMargin: Style.spacing.controlPaddingX + text: root.optionLabel(modelData) + color: index === optionList.currentIndex + ? Paint.hoverStateColor(root.foreground, root.accent) : root.foreground + font.family: root.fontFamily + font.pixelSize: Style.font.body + elide: Text.ElideRight + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onPositionChanged: optionList.currentIndex = parent.index + onClicked: optionList.selectCurrent() + } + } + } + } + } + } +} diff --git a/ui/kit/NumberField.qml b/ui/kit/NumberField.qml new file mode 100644 index 0000000..a509c5f --- /dev/null +++ b/ui/kit/NumberField.qml @@ -0,0 +1,55 @@ +import QtQuick +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's NumberField, drawn in the window's own theme. +// +// The label and the value are the base's, in the base's colours; the one part +// it paints from Style's baked state tokens is the spin box's own background. +// The base publishes that box as `field`, so a theme picked here replaces its +// background with an equivalent surface and leaves the stepper, the editing, +// the validation and the keyboard behaviour alone. +ShellUi.NumberField { + id: root + + foreground: Paint.active ? Paint.foreground : Commons.Color.foreground + accent: Paint.active ? Paint.accent : Commons.Color.accent + + // Only used with a theme picked. + readonly property bool focusedField: root.field !== undefined && root.field !== null + ? root.field.activeFocus : false + + readonly property Item themeBackground: Rectangle { + color: Paint.controlFill(root.focusedField, false, root.foreground, root.accent) + radius: Style.cornerRadius + border.width: Paint.controlBorderWidth(root.focusedField, false) + border.color: root.focusedField + ? Paint.focusBorderFor(root.foreground, root.accent) + : Paint.normalBorderFor(root.foreground, root.accent) + } + + // A host whose NumberField publishes no `field` keeps its own background; + // the rest — label, value, geometry — is already the window's colours. + Binding { + target: root.field !== undefined && root.field !== null ? root.field : root + property: "background" + when: Paint.active && root.field !== undefined && root.field !== null + restoreMode: Binding.RestoreBindingOrValue + value: root.themeBackground + } + + // The text the spin box is edited in is the base's own item, and the tint on + // a selection is taken from Style's baked `[controls]` tokens. While a theme + // is picked the tint is the window's; with Follow Omarchy the base's own + // binding is put back. + Binding { + target: root.field !== undefined && root.field !== null ? root.field.contentItem : root + property: "selectionColor" + when: Paint.active && root.field !== undefined && root.field !== null + && root.field.contentItem !== undefined && root.field.contentItem !== null + restoreMode: Binding.RestoreBindingOrValue + value: Paint.selectionFillFor(root.foreground, root.accent) + } +} diff --git a/ui/kit/PanelToolTip.qml b/ui/kit/PanelToolTip.qml new file mode 100644 index 0000000..8c6c65b --- /dev/null +++ b/ui/kit/PanelToolTip.qml @@ -0,0 +1,16 @@ +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's PanelToolTip, drawn in the window's own theme. +// +// A tooltip paints itself from a background colour, a text colour and a border +// colour, all of which the kit already exposes. They are simply passed on here. +// With Follow Omarchy they are the values the control defaults to, so the kit's +// own surface spec still applies and the tooltip is the shell's tooltip. +ShellUi.PanelToolTip { + panelForeground: Paint.active ? Paint.tooltipText : Commons.Color.tooltip.text + panelBackground: Paint.active ? Paint.tooltipBackground : Commons.Color.tooltip.background + panelBorder: Paint.active ? Paint.tooltipBorder : Commons.Color.tooltip.border +} diff --git a/ui/kit/TextField.qml b/ui/kit/TextField.qml new file mode 100644 index 0000000..cc16e63 --- /dev/null +++ b/ui/kit/TextField.qml @@ -0,0 +1,53 @@ +import QtQuick +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's TextField, drawn in the window's own theme. +// +// The field's foreground, accent and selection tint are public and are simply +// passed on. Its background is a BorderSurface painted from Style's state +// tokens, and those carry the desktop theme's hex — so with a theme picked the +// wrapper paints an equivalent surface itself. Padding, focus behaviour, +// editing and selection are the base's: only the two colours of the rectangle +// behind the text are ours. +ShellUi.TextField { + id: root + + foreground: Paint.active ? Paint.foreground : Commons.Color.foreground + accent: Paint.active ? Paint.accent : Commons.Color.accent + + readonly property bool themed: Paint.active + + // Only meaningful with a theme picked; with Follow Omarchy the base's own + // background, selection tint and placeholder colour are untouched. + readonly property Item themeBackground: Rectangle { + color: Paint.controlFill(root.activeFocus, root.hovered || root.hasCursor, root.foreground, root.accent) + radius: Style.cornerRadius + border.width: Paint.controlBorderWidth(root.activeFocus, root.hovered || root.hasCursor) + border.color: root.activeFocus ? Paint.focusBorderFor(root.foreground, root.accent) + : (root.hovered || root.hasCursor ? Paint.hoverBorderFor(root.foreground, root.accent) + : Paint.normalBorderFor(root.foreground, root.accent)) + } + + Binding { + target: root + property: "background" + when: Paint.active + restoreMode: Binding.RestoreBindingOrValue + value: root.themeBackground + } + + // The kit's own tint is the selected fill from those same baked tokens. + Binding { + target: root + property: "selectionTint" + when: Paint.active && root.selectionTint !== undefined + restoreMode: Binding.RestoreBindingOrValue + value: Paint.selectionFillFor(root.foreground, root.accent) + } + + // A placeholder is a hint, not content: the base dims the foreground, which + // follows the window already. Nothing to do here in either mode. +} diff --git a/ui/kit/ToggleSwitch.qml b/ui/kit/ToggleSwitch.qml new file mode 100644 index 0000000..fe1b803 --- /dev/null +++ b/ui/kit/ToggleSwitch.qml @@ -0,0 +1,105 @@ +import QtQuick +import qs.Commons +import qs.Commons as Commons +import qs.Ui as ShellUi +import "../theme" + +// The shell's ToggleSwitch, drawn in the window's own theme. +// +// The switch paints its track and knob on internal children, so no property of +// the base reaches them. The base stays in place for what it owns — the click, +// hover, cursor and keyboard contract, and the `checked` value — and while a +// theme is picked it is drawn at zero opacity, with an equivalent track and +// knob drawn here from the same public state. With Follow Omarchy this is the +// kit's switch unchanged, drawn by the kit. +Item { + id: root + + property bool checked: false + property bool busy: false + // Off when the surrounding row owns the click, as in the kit's own Toggle. + property bool interactive: true + property bool hasCursor: false + property bool cursorRing: root.interactive + property color foreground: Paint.active ? Paint.foreground : Commons.Color.foreground + property color accent: Paint.active ? Paint.accent : Commons.Color.accent + + signal toggled() + signal hovered(bool isHovered) + + readonly property bool hot: base.hot === true || base.hasCursor || base.containsMouse === true + readonly property bool themed: Paint.active + + // The kit's geometry, read where it exists and derived the same way where the + // host's control is a simpler one. + readonly property int trackHeight: base.trackHeight !== undefined + ? base.trackHeight : Math.max(22, Math.round(Style.spacing.controlHeight * 0.55)) + readonly property int trackWidth: base.trackWidth !== undefined + ? base.trackWidth : Math.round(trackHeight * 1.9) + readonly property int knobSize: base.knobSize !== undefined + ? base.knobSize : Math.max(6, Math.round(trackHeight * 0.72)) + readonly property int knobInset: base.knobInset !== undefined + ? base.knobInset : Math.max(1, Math.round((trackHeight - knobSize) / 2)) + readonly property int ringPad: base.cursorPad !== undefined ? base.cursorPad : Style.space(6) + readonly property bool rounded: base.rounded !== undefined ? base.rounded : Style.cornerRadius > 0 + + implicitWidth: base.implicitWidth + implicitHeight: base.implicitHeight + + ShellUi.ToggleSwitch { + id: base + anchors.centerIn: parent + // Not `visible: false`: an invisible item takes no input, and this one is + // the switch's whole input surface. + opacity: Paint.active ? 0 : 1 + checked: root.checked + busy: root.busy + interactive: root.interactive + hasCursor: root.hasCursor + cursorRing: root.cursorRing + foreground: root.foreground + accent: root.accent + onToggled: root.toggled() + onHovered: function(isHovered) { root.hovered(isHovered) } + } + + Rectangle { + id: themedRing + visible: root.themed && root.cursorRing && root.hot + anchors.centerIn: parent + width: root.trackWidth + root.ringPad * 2 + height: root.trackHeight + root.ringPad * 2 + radius: Style.cornerRadius + color: "transparent" + border.width: Paint.normalBorderWidth + border.color: Paint.hoverBorderFor(root.foreground, root.accent) + } + + Rectangle { + id: themedTrack + visible: root.themed + anchors.centerIn: parent + width: root.trackWidth + height: root.trackHeight + radius: root.rounded ? height / 2 : 0 + color: root.checked + ? Paint.selectedFillFor(root.foreground, root.accent) + : Paint.normalFillFor(root.foreground, root.accent) + border.width: root.checked ? Paint.selectedBorderWidth : Paint.normalBorderWidth + border.color: root.checked + ? Paint.selectedBorderFor(root.foreground, root.accent) + : Paint.normalBorderFor(root.foreground, root.accent) + + Rectangle { + id: themedKnob + width: root.knobSize + height: root.knobSize + radius: root.rounded ? height / 2 : 0 + x: root.checked ? themedTrack.width - width - root.knobInset : root.knobInset + anchors.verticalCenter: parent.verticalCenter + color: root.checked + ? Paint.selectedStateColor(root.foreground, root.accent) + : Qt.darker(root.foreground, 1.25) + } + } +} diff --git a/ui/kit/qmldir b/ui/kit/qmldir new file mode 100644 index 0000000..244fb03 --- /dev/null +++ b/ui/kit/qmldir @@ -0,0 +1,6 @@ +Button 1.0 Button.qml +Dropdown 1.0 Dropdown.qml +NumberField 1.0 NumberField.qml +PanelToolTip 1.0 PanelToolTip.qml +TextField 1.0 TextField.qml +ToggleSwitch 1.0 ToggleSwitch.qml diff --git a/ui/settings/Settings.js b/ui/settings/Settings.js index c17cf76..37490b4 100644 --- a/ui/settings/Settings.js +++ b/ui/settings/Settings.js @@ -9,6 +9,7 @@ var DEFAULTS = ({ heavyMessageRendering: Html.HEAVY_MESSAGE_RENDERING_DEFAULT, contentDirection: Direction.MODE_DEFAULT, appearance: Appearance.MODE_DEFAULT, + appTheme: "", defaultQuery: "in:inbox", notifyNewMail: "On", oauthPort: 9481, diff --git a/ui/tests/qml/imports/Quickshell/Io/FileView.qml b/ui/tests/qml/imports/Quickshell/Io/FileView.qml index 40af1a6..6434cfb 100644 --- a/ui/tests/qml/imports/Quickshell/Io/FileView.qml +++ b/ui/tests/qml/imports/Quickshell/Io/FileView.qml @@ -1,15 +1,43 @@ import QtQuick +import Quickshell +// With no store this is the old stub: a file that never loads. A test that +// sets Quickshell.fileStore gets a FileView that reads it, announces each +// result the way the shell's does, and reports a watched change. QtObject { + id: root property string path: "" property bool watchChanges: false property bool printErrors: false property bool atomicWrites: false + property var store: Quickshell.fileStore + property string _text: "" signal loaded() signal fileChanged() signal loadFailed() - function reload() {} - function text() { return "" } + function reload() { + if (!store) return + var result = path !== "" && typeof store.read === "function" ? (store.read(path) || ({})) : ({}) + if (result.ok !== true) { + _text = "" + loadFailed() + return + } + _text = String(result.text || "") + loaded() + } + function text() { return _text } function setText(_value) {} + + onPathChanged: reload() + onStoreChanged: reload() + + property Connections storeConnections: Connections { + target: root.store + ignoreUnknownSignals: true + function onChanged(changedPath) { + if (root.watchChanges && String(changedPath) === root.path) root.fileChanged() + } + } } diff --git a/ui/tests/qml/imports/Quickshell/Quickshell.qml b/ui/tests/qml/imports/Quickshell/Quickshell.qml index 461683b..755d6a0 100644 --- a/ui/tests/qml/imports/Quickshell/Quickshell.qml +++ b/ui/tests/qml/imports/Quickshell/Quickshell.qml @@ -3,6 +3,9 @@ import QtQuick QtObject { property var notifications: [] + // A test that reads files through FileView supplies a store; none is the + // stub's old behaviour, a file that never loads. + property var fileStore: null signal notificationActivated(string accountId, string messageId) function env(name) { return "" } property var detachedCommands: [] diff --git a/ui/tests/qml/imports/qs/Commons/Border.qml b/ui/tests/qml/imports/qs/Commons/Border.qml index 243ab00..94aff94 100644 --- a/ui/tests/qml/imports/qs/Commons/Border.qml +++ b/ui/tests/qml/imports/qs/Commons/Border.qml @@ -1,9 +1,58 @@ pragma Singleton import QtQuick +// A stand-in for the shell's border factory. A spec is `color` plus +// `widths.top/right/bottom/left`, and the code that draws with it reads both — +// so a stub that returned a plain `width` would let a kit component pass here +// and fail in the shell. QtObject { - function controlSpec(state, foreground, _accent) { - return ({ color: foreground, width: state === "selected" ? 0 : 1 }) + function parseWidthSpec(width) { + var size = width === undefined ? 0 : width + return { top: size, right: size, bottom: size, left: size } } - function flat(color, width) { return ({ color: color, width: width }) } + + function flat(color, width) { + return { + color: color || "transparent", + widths: parseWidthSpec(width), + gradient: { colors: [], angle: 0, enabled: false }, + } + } + + function none() { return flat("transparent", 0) } + + function controlWidths(state) { + if (state === "none") return parseWidthSpec(0) + if (state === "focus") return parseWidthSpec(Style.focusBorderWidth) + if (state === "hover" || state === "hot") return parseWidthSpec(Style.hoverBorderWidth) + if (state === "selected") return parseWidthSpec(Style.selectedBorderWidth) + return parseWidthSpec(Style.normalBorderWidth) + } + + function controlSpec(state, foreground, _accent, _urgent) { + return { + color: foreground, + widths: controlWidths(state), + gradient: { colors: [], angle: 0, enabled: false }, + } + } + + function controlHasWidth(state) { return controlWidths(state).top > 0 } + + function localOrSurfaceSpec(_section, _token, localColor, defaultColor, fallbackWidth) { + return flat(localColor === undefined ? defaultColor : localColor, fallbackWidth) + } + + function withWidth(spec, width) { + if (!spec) return none() + return { color: spec.color, gradient: spec.gradient, widths: parseWidthSpec(width) } + } + + function isNone(spec) { return !spec || !spec.widths || spec.widths.top <= 0 } + function top(spec) { return spec && spec.widths ? spec.widths.top : 0 } + function right(spec) { return spec && spec.widths ? spec.widths.right : 0 } + function bottom(spec) { return spec && spec.widths ? spec.widths.bottom : 0 } + function left(spec) { return spec && spec.widths ? spec.widths.left : 0 } + function uniformWidth(spec) { return spec && spec.widths ? spec.widths.top : 0 } + function color(spec) { return spec ? spec.color : "transparent" } } diff --git a/ui/tests/qml/imports/qs/Commons/Color.qml b/ui/tests/qml/imports/qs/Commons/Color.qml index 40e87fd..10d4c4f 100644 --- a/ui/tests/qml/imports/qs/Commons/Color.qml +++ b/ui/tests/qml/imports/qs/Commons/Color.qml @@ -2,6 +2,22 @@ pragma Singleton import QtQuick QtObject { + // The desktop's palette. Distinctive values, so a test can tell a colour the + // window drew from its own theme from one it took from the desktop. property color foreground: Qt.rgba(1, 1, 1, 1) - readonly property color accent: Qt.rgba(1, 0.5, 0, 1) + property color background: Qt.rgba(0, 0, 0, 1) + property color accent: Qt.rgba(1, 0.5, 0, 1) + property color urgent: Qt.rgba(0.8, 0.2, 0.2, 1) + property color muted: Qt.rgba(0.5, 0.5, 0.5, 1) + + readonly property QtObject popups: QtObject { + readonly property color background: Qt.rgba(0.06, 0.06, 0.06, 1) + readonly property color text: Qt.rgba(0.93, 0.93, 0.93, 1) + readonly property color border: Qt.rgba(0.27, 0.27, 0.27, 1) + } + readonly property QtObject tooltip: QtObject { + readonly property color background: Qt.rgba(0.06, 0.06, 0.06, 0.97) + readonly property color text: Qt.rgba(0.93, 0.93, 0.93, 1) + readonly property color border: Qt.rgba(0.93, 0.93, 0.93, 1) + } } diff --git a/ui/tests/qml/imports/qs/Commons/Style.qml b/ui/tests/qml/imports/qs/Commons/Style.qml index be10627..e312f7a 100644 --- a/ui/tests/qml/imports/qs/Commons/Style.qml +++ b/ui/tests/qml/imports/qs/Commons/Style.qml @@ -4,16 +4,37 @@ import QtQuick QtObject { readonly property real cornerRadius: 2 readonly property real normalBorderWidth: 1 + readonly property real hoverBorderWidth: 1 + readonly property real selectedBorderWidth: 0 + readonly property real focusBorderWidth: 1 + + // The alphas and widths the window keeps from the live shell style even when + // it draws in a theme of its own. + readonly property real normalFillAlpha: 0.04 + readonly property real hoverFillAlpha: 0.08 + readonly property real selectedFillAlpha: 0.18 + readonly property real pressedFillAlpha: 0.22 + readonly property real focusFillAlpha: 0.08 + readonly property real selectionFillAlpha: 0.35 + property real normalBorderAlpha: 0.4 + property real hoverBorderAlpha: 0.25 + property real selectedBorderAlpha: 1.0 + property real focusBorderAlpha: 0.25 + readonly property var font: ({ family: "monospace", title: 22, heading: 18, body: 14, bodySmall: 13, caption: 11, - icon: 16, iconSmall: 14 + icon: 16, iconSmall: 14, iconLarge: 18, subtitle: 15, display: 24, displayLarge: 28 }) // `popupRowHeight` is the shell's 28. A stub without it gave every plain // menu row a height of zero, so a click on "Manage accounts..." fell through // the popup to whatever the window had underneath. readonly property var spacing: ({ controlPaddingX: 8, controlPaddingY: 5, inputPaddingY: 5, - controlHeight: 30, controlGap: 6, sm: 3, md: 6, popupRowHeight: 28 + controlHeight: 30, hairline: 1, panelGap: 14, controlGap: 6, sm: 3, md: 6, popupRowHeight: 28, + huge: 18, xxs: 2, xs: 2, lg: 8, xl: 10, xxl: 12, xxxl: 14, + labelGap: 4, dropdownWidth: 240, popupPadding: 14, panelPadding: 18, + rowGap: 8, rowPaddingX: 12, numberFieldWidth: 120, + searchableDropdownWidth: 260, searchablePopupMinHeight: 220 }) // The shell's own `space` is `round(px * scale)`, and the rounding is the @@ -28,12 +49,56 @@ QtObject { var n = Number(value) * spacingScale return n <= 0 ? 0 : Math.max(1, Math.round(n)) } - function hoverFillFor(_foreground, accent) { return accent } - function selectedFillFor(_foreground, accent) { return accent } - function selectedStateColor(foreground, _accent) { return foreground } - function selectionFillFor(_foreground, accent) { return accent } - function pressedFillFor(_foreground, accent) { return accent } - function normalFillFor(_foreground, _accent) { return "transparent" } - function normalBorderFor(foreground, _accent) { return foreground } - function hoverBorderFor(_foreground, accent) { return accent } + + // The real shell renders shell.toml with the desktop theme's hex baked into + // [controls], so every state helper ignores the colours it is handed and + // answers with the desktop's. A test that has to detect that defect turns it + // on here; with it off — as it is for every other test — the helpers answer + // with what they were given. + property bool bakedStateColors: false + property color bakedForeground: Qt.rgba(1, 1, 1, 1) + + function baked(alpha) { + return Qt.rgba(bakedForeground.r, bakedForeground.g, bakedForeground.b, alpha) + } + + function normalFillFor(_foreground, _accent) { return bakedStateColors ? baked(normalFillAlpha) : "transparent" } + function hoverFillFor(_foreground, accent) { return bakedStateColors ? baked(hoverFillAlpha) : accent } + function selectedFillFor(_foreground, accent) { return bakedStateColors ? baked(selectedFillAlpha) : accent } + function pressedFillFor(_foreground, accent) { return bakedStateColors ? baked(pressedFillAlpha) : accent } + function focusFillFor(_foreground, accent) { return bakedStateColors ? baked(focusFillAlpha) : accent } + function selectionFillFor(_foreground, accent) { return bakedStateColors ? baked(selectionFillAlpha) : accent } + function normalBorderFor(foreground, _accent) { return bakedStateColors ? baked(normalBorderAlpha) : foreground } + function hoverBorderFor(_foreground, accent) { return bakedStateColors ? baked(hoverBorderAlpha) : accent } + function selectedBorderFor(foreground, _accent) { return bakedStateColors ? baked(selectedBorderAlpha) : foreground } + function focusBorderFor(_foreground, accent) { return bakedStateColors ? baked(focusBorderAlpha) : accent } + + function normalStateColor(foreground, _accent) { return bakedStateColors ? bakedForeground : foreground } + function hoverStateColor(foreground, accent) { return bakedStateColors ? bakedForeground : (accent || foreground) } + function focusStateColor(foreground, accent) { return bakedStateColors ? bakedForeground : (accent || foreground) } + function pressedStateColor(foreground, accent) { return bakedStateColors ? bakedForeground : (accent || foreground) } + function selectedStateColor(foreground, _accent) { return bakedStateColors ? bakedForeground : foreground } + function selectionStateColor(foreground, _accent) { return bakedStateColors ? bakedForeground : foreground } + + function controlFill(focused, hot, foreground, accent) { + if (focused) return focusFillFor(foreground, accent) + if (hot) return hoverFillFor(foreground, accent) + return normalFillFor(foreground, accent) + } + function controlBorder(focused, hot, foreground, accent) { + if (focused) return focusBorderFor(foreground, accent) + if (hot) return hoverBorderFor(foreground, accent) + return normalBorderFor(foreground, accent) + } + function controlBorderWidth(focused, hot) { + if (focused) return focusBorderWidth + if (hot) return hoverBorderWidth + return normalBorderWidth + } + function controlHasWidth(state) { + if (state === "selected") return selectedBorderWidth > 0 + if (state === "hover" || state === "hover-cursor") return hoverBorderWidth > 0 + if (state === "focus") return focusBorderWidth > 0 + return normalBorderWidth > 0 + } } diff --git a/ui/tests/qml/imports/qs/Ui/Button.qml b/ui/tests/qml/imports/qs/Ui/Button.qml index 3645a18..8f6487d 100644 --- a/ui/tests/qml/imports/qs/Ui/Button.qml +++ b/ui/tests/qml/imports/qs/Ui/Button.qml @@ -1,33 +1,62 @@ import QtQuick +import QtQuick.Controls +import qs.Commons +import qs.Commons as Commons +// A stand-in for the shell's button. It keeps the public surface the kit's +// Button reaches for — including the tooltip palette and `borderSpec`, which +// the real control publishes and paints — because a property the real +// component has and this one does not is a component that will not +// instantiate here and does instantiate in the shell. Rectangle { + id: root + property string text: "" - // The kit's Button renders one when it is set; a stub only has to accept it, - // because a property the real component has and this one does not is a - // component that will not instantiate here and does instantiate in the shell. + property string iconText: "" property string tooltipText: "" - property color foreground: Qt.rgba(1, 1, 1, 1) - property color accent: Qt.rgba(1, 0.5, 0, 1) - property color background: "transparent" - property bool bordered: false + property bool selected: false + property bool active: false property bool hasCursor: false - readonly property bool hot: hasCursor || mouseArea.containsMouse - property bool leftAlign: false property bool focusable: false - activeFocusOnTab: focusable - Keys.onReturnPressed: if (focusable) clicked() - Keys.onEnterPressed: if (focusable) clicked() - Keys.onSpacePressed: if (focusable) clicked() + property bool bordered: false + + property color foreground: Commons.Color.foreground + property color background: "transparent" + property color accent: Commons.Color.accent + + property color tooltipBackground: Commons.Color.tooltip.background + property color tooltipForeground: Commons.Color.tooltip.text + property color tooltipBorder: Commons.Color.tooltip.border + + // The shell draws its border from a spec; the stub keeps the same shape so a + // caller that replaces the spec is drawn with, not just accepted. + property var borderSpec: Commons.Border.controlSpec( + root.selected ? "selected" : (root.bordered ? "normal" : "none"), foreground, accent) + property string fontFamily: "monospace" property real fontSize: 13 property real horizontalPadding: 8 property real verticalPadding: 5 + property bool leftAlign: false + + readonly property bool hot: hasCursor || mouseArea.containsMouse + signal clicked() signal hovered(bool isHovered) + + color: background + // The shell's surface is Rectangle-compatible and drives its own `border` + // from the spec, so callers read `border.color` there. + border.width: root.borderSpec && root.borderSpec.widths ? root.borderSpec.widths.top : 0 + border.color: root.borderSpec ? root.borderSpec.color : "transparent" + activeFocusOnTab: focusable + Keys.onReturnPressed: if (focusable) clicked() + Keys.onEnterPressed: if (focusable) clicked() + Keys.onSpacePressed: if (focusable) clicked() + implicitWidth: Math.max(40, label.implicitWidth + horizontalPadding * 2) implicitHeight: label.implicitHeight + verticalPadding * 2 - color: background Text { id: label @@ -36,11 +65,32 @@ Rectangle { color: parent.foreground font.family: parent.fontFamily font.pixelSize: parent.fontSize + font.bold: parent.selected } MouseArea { id: mouseArea anchors.fill: parent - onClicked: parent.clicked() + hoverEnabled: true + onContainsMouseChanged: root.hovered(containsMouse) + onClicked: root.clicked() + } + + ToolTip { + id: tip + objectName: "button-tooltip" + visible: root.tooltipText !== "" && mouseArea.containsMouse + text: root.tooltipText + background: Rectangle { + color: root.tooltipBackground + border.width: 1 + border.color: root.tooltipBorder + } + contentItem: Text { + text: tip.text + color: root.tooltipForeground + font.family: root.fontFamily + font.pixelSize: root.fontSize + } } } diff --git a/ui/tests/qml/imports/qs/Ui/Dropdown.qml b/ui/tests/qml/imports/qs/Ui/Dropdown.qml index fe60046..35c57f3 100644 --- a/ui/tests/qml/imports/qs/Ui/Dropdown.qml +++ b/ui/tests/qml/imports/qs/Ui/Dropdown.qml @@ -1,23 +1,109 @@ import QtQuick +import QtQuick.Controls as Controls +import qs.Commons +// A stand-in for the shell's dropdown. The kit's Dropdown keeps the shell's +// control for Follow Omarchy, so the stub has to select a row the way the shell +// does: it assigns its own `value` when a row is chosen, which severs whatever +// binding the caller had, and it reports the choice through `changed`. Item { + id: root + property string label: "" property string value: "" property var options: [] - property color foreground: "transparent" - property color background: "transparent" - property color popupBorder: "transparent" - property color accent: "transparent" - property string fontFamily: "" + property color foreground: Commons.Color.popups.text + property color background: Commons.Color.popups.background + property color popupBorder: Commons.Color.popups.border + property color accent: Commons.Color.accent + property string fontFamily: "monospace" property int rowHeight: 36 - property int popupRowHeight: 36 + property int popupRowHeight: 28 property bool showLabel: true property bool hasCursor: false - readonly property bool popupOpen: false + + readonly property bool popupOpen: popup.opened + readonly property int currentIndex: indexOf(root.value) signal changed(string value) signal hovered(bool isHovered) implicitWidth: 240 implicitHeight: rowHeight + + function indexOf(choice) { + for (var i = 0; i < root.options.length; i++) + if (String(root.options[i].value) === String(choice)) return i + return 0 + } + function currentLabel() { + return String(root.options[root.indexOf(root.value)].label) + } + function open() { popup.open() } + function close() { popup.close() } + function choose(index) { + if (index < 0 || index >= root.options.length) return + var next = String(root.options[index].value) + root.value = next + root.changed(next) + } + + Rectangle { + anchors.fill: parent + color: root.background + Text { + anchors.left: parent.left + anchors.leftMargin: 8 + anchors.verticalCenter: parent.verticalCenter + text: root.showLabel ? String(root.options[root.indexOf(root.value)].label) : "" + color: root.foreground + font.family: root.fontFamily + } + } + + TapHandler { onTapped: root.open() } + + Controls.Popup { + id: popup + parent: Controls.Overlay.overlay + x: 0 + y: 0 + width: root.width + height: Math.min(root.options.length * root.popupRowHeight, 320) + modal: true + focus: true + property int cursor: 0 + + onOpened: { cursor = root.currentIndex; list.forceActiveFocus() } + + background: Rectangle { + color: root.background + border.width: 1 + border.color: root.popupBorder + } + + ListView { + id: list + anchors.fill: parent + focus: true + model: root.options + Keys.onDownPressed: popup.cursor = Math.min(popup.cursor + 1, root.options.length - 1) + Keys.onUpPressed: popup.cursor = Math.max(popup.cursor - 1, 0) + Keys.onReturnPressed: { root.choose(popup.cursor); popup.close() } + Keys.onEnterPressed: { root.choose(popup.cursor); popup.close() } + Keys.onEscapePressed: popup.close() + delegate: Item { + height: root.popupRowHeight + width: ListView.view.width + Text { + anchors.left: parent.left + anchors.leftMargin: 8 + anchors.verticalCenter: parent.verticalCenter + text: modelData.label + color: root.foreground + font.family: root.fontFamily + } + } + } + } } diff --git a/ui/tests/qml/imports/qs/Ui/NumberField.qml b/ui/tests/qml/imports/qs/Ui/NumberField.qml index 6fb4e8d..c272091 100644 --- a/ui/tests/qml/imports/qs/Ui/NumberField.qml +++ b/ui/tests/qml/imports/qs/Ui/NumberField.qml @@ -1,6 +1,9 @@ import QtQuick +import QtQuick.Controls as QQC + +Column { + id: root -Item { property string label: "" property int value: 0 property int from: 0 @@ -11,5 +14,19 @@ Item { property string fontFamily: "monospace" property real fontSize: 13 property real fieldWidth: 80 + // The shell's NumberField exposes the spin box it composes, and a caller that + // replaces that box's background needs it to be the same shape here. + property alias field: spin signal modified(int value) + + QQC.SpinBox { + id: spin + width: root.fieldWidth + from: root.from + to: root.to + stepSize: root.stepSize + value: root.value + editable: true + onValueModified: root.modified(value) + } } diff --git a/ui/tests/qml/imports/qs/Ui/PanelToolTip.qml b/ui/tests/qml/imports/qs/Ui/PanelToolTip.qml index 40fd48e..4126892 100644 --- a/ui/tests/qml/imports/qs/Ui/PanelToolTip.qml +++ b/ui/tests/qml/imports/qs/Ui/PanelToolTip.qml @@ -3,4 +3,9 @@ import QtQuick Item { property string text: "" property string fontFamily: "monospace" + // The shell's PanelToolTip paints itself in these; a stub only has to accept + // them so a caller can pass a colour either way. + property color panelForeground: "transparent" + property color panelBackground: "transparent" + property color panelBorder: "transparent" } diff --git a/ui/tests/qml/imports/qs/Ui/ToggleSwitch.qml b/ui/tests/qml/imports/qs/Ui/ToggleSwitch.qml index d7b71da..2179dfd 100644 --- a/ui/tests/qml/imports/qs/Ui/ToggleSwitch.qml +++ b/ui/tests/qml/imports/qs/Ui/ToggleSwitch.qml @@ -11,4 +11,5 @@ Item { property color foreground: "transparent" property color accent: "transparent" signal toggled() + signal hovered(bool isHovered) } diff --git a/ui/tests/qml/tst_app_theme.qml b/ui/tests/qml/tst_app_theme.qml new file mode 100644 index 0000000..d5a221c --- /dev/null +++ b/ui/tests/qml/tst_app_theme.qml @@ -0,0 +1,995 @@ +import QtQuick 2.15 +import QtTest 1.3 +import qs.Commons +import qs.Commons as Commons +import "../../theme" +import "../../kit" as Kit +import "../../components" as Components +import "../../bar" as Bar +import "../../calendar/Palette.js" as CalendarPalette + +// The window's own theme. +// +// The defect this test exists for is invisible in a stub that honours the +// colours it is handed: the real shell renders shell.toml with the desktop +// theme's hex baked into `[controls]`, so Style's helpers ignore their +// arguments and answer with the desktop's foreground. A window drawn in a light +// theme on a dark desktop then paints near-white text on a near-white surface. +// +// So the stub Style is told to behave the way the shell does, the desktop is a +// distinctly neutral palette (white on black), and the picked theme is a light +// one whose foreground is blue-grey. Every colour in it is therefore +// distinguishable from every colour blended out of the desktop's: the theme's +// are not neutral, the desktop's are. +Item { + id: scene + width: 720 + height: 1200 + + readonly property string lightTheme: [ + 'mode = "light"', + 'foreground = "#4c4f69"', + 'background = "#eff1f5"', + 'accent = "#8839ef"', + 'red = "#d20f39"', + 'muted = "#8c8fa1"', + 'selection = "#ccd0da"', + ].join("\n") + + readonly property string darkTheme: [ + 'mode = "dark"', + 'foreground = "#cdd6f4"', + 'background = "#1e1e2e"', + 'accent = "#89b4fa"', + 'red = "#f38ba8"', + 'muted = "#6c7086"', + 'selection = "#45475a"', + ].join("\n") + + Component.onCompleted: { + // The real shell behaves this way by construction — its shell.toml has the + // desktop theme's hex baked in — so the stub is told to. Running this file + // against the real shell instead (a supplied theme state and + // `-import /usr/share/omarchy/shell`) needs neither switch. + if (Style.bakedStateColors !== undefined) { + Style.bakedStateColors = true + Style.bakedForeground = Commons.Color.foreground + } + } + + // Paint reads a theme through FileView. The test supplies the file's text and + // runs the same parse → resolve → rebuild path the window runs when it opens + // a theme, so everything below the file read is production code. + function pickTheme(name) { + Paint.available = true + Paint.themeName = name + Paint.themeDir = "/themes/" + name + Paint.colorsText = name === "fixture-dark" ? scene.darkTheme : scene.lightTheme + Paint.shellText = "" + Paint.rebuild() + } + + // The stored setting, and the one path a picker's change takes: the window + // stores it, then draws with it. + property string persistedTheme: "" + function changeTheme(next) { + scene.persistedTheme = next + // The window stores the choice and the picker reads it back, which is what + // the settings service does around this row. + themePicker.value = next + if (next === "") scene.followOmarchy() + else scene.pickTheme(next) + } + + // The first item below `item` whose text is `label`, so a test can read the + // weight or colour of the label a person actually sees. + function textItemFor(item, label) { + if (item.text !== undefined && String(item.text) === label && item.font !== undefined + && item.visible !== false) return item + var kids = item.children || [] + for (var i = 0; i < kids.length; i++) { + var found = scene.textItemFor(kids[i], label) + if (found !== null) return found + } + return null + } + + // The first object below `item` that publishes a tooltip with `label`. + function tooltipItemFor(item, label) { + if (item.contentItem !== undefined && item.text !== undefined + && String(item.text) === label) return item + var kids = item.children || [] + for (var i = 0; i < kids.length; i++) { + var found = scene.tooltipItemFor(kids[i], label) + if (found !== null) return found + } + return null + } + + function followOmarchy() { + Paint.available = true + Paint.themeName = "" + Paint.themeDir = "" + Paint.colorsText = "" + Paint.shellText = "" + Paint.rebuild() + } + + // Every colour a visible item paints — its own fill and its border's — with + // the item it came from, so a failure names the thing that painted it. A + // subtree at zero opacity is the base control a wrapper hides while it draws + // its own copy. + function paintedColours(item, found, trail) { + if (!item) return found + if (item.visible === false || item.opacity <= 0.01) return found + var where = (trail === undefined ? "" : trail) + "/" + + (item.objectName !== "" && item.objectName !== undefined ? item.objectName : String(item)) + if (item.color !== undefined && item.color !== null && typeof item.color === "object") { + found.push({ where: where, colour: item.color }) + } + // A Rectangle's pen defaults to an opaque black at width 1 whether or not + // anything asked for a border, and Qt draws nothing while that pen is + // unset. An unset pen is therefore exactly this colour, and the theme's are + // never opaque black. + if (item.border && item.border.width > 0 && typeof item.border.color === "object" + && String(item.border.color) !== "#000000") { + found.push({ where: where + ".border", colour: item.border.color }) + } + var kids = item.children || [] + for (var i = 0; i < kids.length; i++) paintedColours(kids[i], found, where) + return found + } + + // White and black are both neutral, so every alpha variant and every + // darkening of the desktop's foreground or background is neutral too. The + // picked theme states none: its roles are tinted greys, a purple accent and a + // red urgent colour. + function isDesktopNeutral(colour) { + if (colour.a <= 0.02) return false + return Math.abs(colour.r - colour.g) < 0.01 && Math.abs(colour.g - colour.b) < 0.01 + } + + function neutralColours(item) { + var found = paintedColours(item, []) + var out = [] + for (var i = 0; i < found.length; i++) { + if (isDesktopNeutral(found[i].colour)) out.push(found[i].where + " " + String(found[i].colour)) + } + return out + } + + function paintColour(list, wanted) { + for (var i = 0; i < list.length; i++) { + if (String(list[i].colour) === String(wanted)) return true + } + return false + } + + // One window's worth of surfaces: App's semantic colours as a composed + // panel, and every kit control Omamail uses, through the wrappers. + Column { + id: surface + x: 8 + y: 8 + width: parent.width - 16 + spacing: 6 + + Rectangle { + objectName: "window-surface" + width: surface.width + height: 24 + color: Paint.background + + Text { + objectName: "window-heading" + text: "Inbox" + color: Paint.foreground + font.family: Style.font.family + } + } + + Rectangle { + id: card + objectName: "card" + width: surface.width + height: 28 + radius: Style.cornerRadius + color: Paint.normalFillFor(Paint.foreground, Paint.accent) + border.width: Paint.normalBorderWidth + border.color: Paint.normalBorderFor(Paint.foreground, Paint.accent) + + Text { + text: "A card" + color: Paint.foreground + font.family: Style.font.family + } + } + + Kit.Button { + objectName: "kit-button" + text: "Archive" + chosen: true + foreground: Paint.foreground + accent: Paint.accent + } + + Kit.TextField { + objectName: "kit-field" + width: surface.width + text: "hello" + foreground: Paint.foreground + accent: Paint.accent + } + + Kit.ToggleSwitch { + objectName: "kit-toggle" + checked: true + foreground: Paint.foreground + accent: Paint.accent + } + + Kit.Dropdown { + objectName: "kit-dropdown" + width: surface.width + value: "one" + options: [{ value: "one", label: "One" }, { value: "two", label: "Two" }] + foreground: Paint.popupText + background: Paint.popupBackground + popupBorder: Paint.popupBorder + accent: Paint.accent + fontFamily: Style.font.family + } + + Components.IconButton { + objectName: "icon-button" + iconName: "archive" + tooltipText: "Archive" + } + + Components.IconTextButton { + objectName: "icon-text-button" + iconName: "check" + text: "Save" + } + + Components.ReaderNotice { + objectName: "reader-notice" + textColor: Paint.foreground + dimColor: Paint.muted + accentColor: Paint.accent + panelFontFamily: Style.font.family + text: "Remote images are blocked." + } + } + + Components.MessageRow { + id: messageRow + objectName: "message-row" + x: 8 + y: surface.y + surface.height + 8 + width: parent.width - 16 + summary: ({ + id: "1", subject: "Quarterly report", from: "Ada ", + snippet: "The numbers are attached.", time: "09:12", unread: true, + starred: false, subjectDirection: "", sourceLabel: "" + }) + textColor: Paint.foreground + accentColor: Paint.accent + dimColor: Paint.muted + panelFontFamily: Style.font.family + } + + // The bar's own preview keeps the desktop's palette; the window beside it does + // not. It is given the desktop's colours, as BarWidget gives it. + Bar.BarPreview { + id: barPreview + objectName: "bar-preview" + x: 8 + y: messageRow.y + messageRow.height + 8 + width: 300 + messages: [] + events: [] + textColor: Commons.Color.popups.text + backgroundColor: Commons.Color.popups.background + accentColor: Commons.Color.accent + dimColor: Qt.rgba(Commons.Color.popups.text.r, Commons.Color.popups.text.g, Commons.Color.popups.text.b, 0.62) + panelFontFamily: Style.font.family + } + + // The NumberField is asserted through the one part of it the wrapper owns — + // its spin box's background — because the rest of a spin box is platform + // chrome in any host. + Kit.NumberField { + id: numberField + objectName: "kit-number" + x: 8 + y: barPreview.y + barPreview.height + 8 + label: "Snooze (minutes)" + value: 5 + foreground: Paint.foreground + accent: Paint.accent + } + + // The window's own picker, and a bordered action with a tooltip: the two + // surfaces whose colours and weight this feature is judged by. + Kit.Dropdown { + id: themePicker + objectName: "theme-picker" + x: 8; y: 780 + width: 320 + showLabel: false + value: scene.persistedTheme + options: [ + { value: "", label: "Follow Omarchy" }, + { value: "fixture-light", label: "Fixture Light" }, + { value: "fixture-dark", label: "Fixture Dark" } + ] + foreground: Paint.popupText + background: Paint.popupBackground + popupBorder: Paint.popupBorder + accent: Paint.accent + fontFamily: Style.font.family + onChanged: function(next) { scene.changeTheme(next) } + } + + Kit.Button { + id: borderedButton + objectName: "bordered-button" + x: 8; y: 830 + width: 260; height: 40 + text: "Archive" + tooltipText: "Move to archive" + bordered: true + foreground: Paint.foreground + accent: Paint.accent + } + + // The real mailbox row: a chosen tab is marked by its weight, not only by a + // fill, so a theme must not take that away. + Components.MailboxTabs { + id: mailboxTabs + objectName: "mailbox-tabs" + x: 8; y: 890 + width: 500 + textColor: Paint.foreground + accentColor: Paint.accent + panelFontFamily: Style.font.family + current: "inbox" + allMailboxes: [ + { key: "inbox", label: "Inbox" }, + { key: "unread", label: "Unread" } + ] + } + + // The real calendar colour picker, with the controller shape it reads. + QtObject { + id: calendarController + property var availableSources: ({ version: 1, sources: [ + { id: "one", kind: "google", name: "Work", colorKey: CalendarPalette.keys()[4], enabled: true } + ] }) + property bool savingSource: false + property bool discoveringCalendars: false + property string discoveringAccountId: "" + property var reminderPolicy: null + property string defaultId: "" + property int colorCalls: 0 + function setSourceColor(id, key) { calendarController.colorCalls += 1 } + function setSourceEnabled(id, on) {} + function removeCalendar(id) {} + function setDefaultCalendar(id) {} + function setRemindersEnabled(on) {} + function setSnoozeMinutes(minutes) {} + function addCalDavCalendar(source, password) {} + function discoverCalendars(accountId, choice) {} + function saveInvitations(on) {} + } + + QtObject { + id: calendarServiceStub + property bool unifiedCalendarView: false + property bool calendarRemindersEnabled: true + property int calendarSnoozeMinutes: 5 + property string calendarReminderError: "" + property var accountSummaries: [] + property var settings: ({}) + property var auth: null + property bool backendCanDiscoverCalendars: true + property bool backendCanGoogleCalendars: true + property bool backendCanSaveInvitations: true + property bool alwaysShowImages: false + property bool alwaysRenderHeavyMessages: false + property int undoSendSeconds: 10 + function persistSetting(name, value) { var next = {}; next[name] = value; calendarServiceStub.settings = next } + function setUnifiedCalendarView(value) {} + } + + Components.CalendarSettings { + id: calendarSettings + objectName: "calendar-settings" + x: 8; y: 980 + width: 520 + service: calendarServiceStub + controller: calendarController + textColor: Paint.foreground + dimColor: Paint.muted + accentColor: Paint.accent + urgentColor: Paint.urgent + panelFontFamily: Style.font.family + } + + // The real settings page around the real picker row. + QtObject { + id: settingsThemeStub + property bool enabled: true + property string selected: scene.persistedTheme + property var options: [ + { value: "", label: "Follow Omarchy" }, + { value: "fixture-light", label: "Fixture Light" }, + { value: "fixture-dark", label: "Fixture Dark" } + ] + property int refreshes: 0 + function refresh() { settingsThemeStub.refreshes += 1 } + function choose(name) { scene.changeTheme(name) } + } + + QtObject { + id: settingsServiceStub + property var theme: settingsThemeStub + property bool hasAppearance: false + property string appearance: "system" + property bool hasTray: true + property bool hasMailto: true + property bool hasNotifications: true + property bool hasAgent: false + property var accountSummaries: [] + property var accountSignatures: [] + property string activeAccountId: "" + property var backend: null + property var backendRuntime: null + property var auth: null + property bool backendCanNameSender: false + property bool backendCanSuggestEvents: false + property bool alwaysShowImages: false + property bool alwaysRenderHeavyMessages: false + property bool notifyNewMail: true + property bool suggestEvents: false + property bool showBarIcon: true + property string contentDirection: "auto" + property int undoSendSeconds: 10 + property string defaultMailClient: "" + property bool defaultMailClientBusy: false + property string defaultMailClientError: "" + property string diagnoseError: "" + property bool diagnosing: false + property string notificationError: "" + function persistSetting(name, value) {} + function refreshDefaultMailClient() {} + function setDefaultMailClient() {} + function setAccountLabel() {} + function setAccountSenderName() {} + function setAccountSignature() {} + function setAccountSignatureHtml() {} + function setAppearance() {} + function setContentDirection() {} + function setAlwaysShowImages() {} + function setAlwaysRenderHeavyMessages() {} + function setNotifyNewMail() {} + function setSuggestEvents() {} + function setUndoSendSeconds() {} + function setShowBarIcon() {} + function chooseFiles() {} + } + + // The two views a person spends the day in, and the two the review asked to + // see drawn: the real message list and the real composer, with the smallest + // services they will start against. Off screen, below the settings page, + // where they cost the walk above nothing and still paint. + QtObject { + id: listServiceStub + property var messages: [ + ({ id: "1:INBOX", threadId: "", from: { email: "ada@example.org", display: "Ada" }, + subject: "Quarterly report", snippet: "The numbers are attached.", time: "09:12", + date: "", unread: true, starred: false, inInbox: true, labelIds: ["INBOX"] }), + ({ id: "2:INBOX", threadId: "", from: { email: "bob@example.net", display: "Bob" }, + subject: "Lunch", snippet: "Thursday?", time: "08:40", + date: "", unread: false, starred: false, inInbox: true, labelIds: ["INBOX"] }) + ] + property bool hasMore: false + property bool listLoading: false + property bool listLoaded: true + property string searchQuery: "" + property string selectedId: "" + property bool canArchive: true + property string contentDirection: "auto" + property var agentJobs: ({}) + property var agentAttentionByMessage: ({}) + function loadMore() {} + } + + Components.MessageList { + id: messageList + objectName: "real-message-list" + x: 1500; y: 1900 + width: 700 + height: 320 + service: listServiceStub + textColor: Paint.foreground + accentColor: Paint.accent + dimColor: scene.dim + urgentColor: Paint.urgent + panelFontFamily: Style.font.family + } + + QtObject { + id: composeServiceStub + property string activeAccountId: "ada@example.org" + property string accountEmail: "ada@example.org" + property var backend: null + property var recipientContacts: [] + property var sendAsAliases: [] + property var sendIdentities: [] + property var senderSources: [] + property var accountSignatures: [{ id: "ada@example.org", email: "ada@example.org", signature: "Ada" }] + property var attachments: [] + property string selectedId: "" + property string contentDirection: "auto" + property bool alwaysShowImages: false + property bool alwaysRenderHeavyMessages: false + property int undoSendSeconds: 10 + function signatureFor(id) { return "Ada\nada.example.org" } + function cachePath(kind) { return "/tmp/omamail-theme-test-" + kind } + function refreshRecipientContacts() {} + function loadAttachments(id, list, callback) { if (callback) callback([]) } + function send(fields) { return true } + function fail(result, message) {} + function sendAgentProposal(id, fields) { return false } + function accountEmailFor(id) { return String(id || "ada@example.org") } + } + + // The composer is a DropArea, and a DropArea fills its parent whatever + // geometry it is given: it is put in a frame of its own so it covers that + // frame and not the whole scene. + Item { + id: composeFrame + x: 1500; y: 2240 + width: 700 + height: 620 + + Components.ComposeView { + id: composeView + objectName: "real-compose-view" + anchors.fill: parent + service: composeServiceStub + opened: true + textColor: Paint.foreground + backgroundColor: Paint.background + accentColor: Paint.accent + dimColor: scene.dim + dimmerColor: scene.dimmer + errorColor: Paint.urgent + popupBackgroundColor: Paint.popupBackground + popupBorderColor: Paint.popupBorder + panelFontFamily: Style.font.family + } + } + + // The sidebar's secondary text blends foreground toward background, as the + // window does; the header and rows above use the same recipe. + readonly property color dim: Qt.rgba( + Paint.foreground.r * 0.68 + Paint.background.r * 0.32, + Paint.foreground.g * 0.68 + Paint.background.g * 0.32, + Paint.foreground.b * 0.68 + Paint.background.b * 0.32, 1) + readonly property color dimmer: Qt.rgba( + Paint.foreground.r * 0.45 + Paint.background.r * 0.55, + Paint.foreground.g * 0.45 + Paint.background.g * 0.55, + Paint.foreground.b * 0.45 + Paint.background.b * 0.55, 1) + + Components.SettingsPage { + id: settingsPage + objectName: "real-settings-page" + x: 1500; y: 0 + width: 700 + height: 1800 + service: settingsServiceStub + calendarController: calendarController + textColor: Paint.foreground + dimColor: Paint.muted + accentColor: Paint.accent + urgentColor: Paint.urgent + panelFontFamily: Style.font.family + } + + TestCase { + name: "AppTheme" + when: windowShown + + function init() { + scene.followOmarchy() + } + + // The core defect: a picked light theme on a dark desktop must not paint a + // single desktop colour. + function test_a_picked_theme_leaves_no_desktop_colour() { + scene.pickTheme("fixture-light") + verify(Paint.active, "the theme was read") + verify(!Paint.following, "a theme is picked") + + var neutral = scene.neutralColours(surface) + compare(neutral.length, 0, "the window paints only the theme's colours, not the desktop's: " + + neutral.join(", ")) + var rowNeutral = scene.neutralColours(messageRow) + compare(rowNeutral.length, 0, "a message row paints only the theme's colours: " + rowNeutral.join(", ")) + + // And it is drawing with the picked palette, not with nothing at all. + compare(String(Paint.foreground), "#4c4f69") + compare(String(Paint.background), "#eff1f5") + compare(String(Paint.accent), "#8839ef") + // The kit's own helpers, which the shell's baked tokens broke, follow it. + verify(!scene.isDesktopNeutral(Paint.hoverFillFor(Paint.foreground, Paint.accent))) + verify(!scene.isDesktopNeutral(Paint.selectedStateColor(Paint.foreground, Paint.accent))) + compare(String(Paint.selectedStateColor(Paint.foreground, Paint.accent)), "#4c4f69") + } + + // Follow Omarchy is not merely "not themed": it is the desktop's window, + // drawn from the same colours as before this feature existed. + function test_follow_omarchy_draws_the_desktop_palette() { + verify(!Paint.active, "nothing is picked") + + var painted = scene.paintedColours(surface, []) + verify(painted.length > 0, "the tree paints something") + verify(scene.paintColour(painted, Commons.Color.foreground), + "a followed window paints the desktop's foreground") + verify(scene.paintColour(painted, Qt.rgba(1, 1, 1, 1)) || scene.paintColour(painted, Qt.rgba(0, 0, 0, 1)), + "and one of the desktop's own colours") + // The helper delegation is exact, not approximate: these are the shell's + // own answers, from the tokens the desktop baked. + compare(String(Paint.hoverFillFor(Commons.Color.foreground, Commons.Color.accent)), + String(Style.hoverFillFor(Commons.Color.foreground, Commons.Color.accent))) + compare(String(Paint.normalBorderFor(Commons.Color.foreground, Commons.Color.accent)), + String(Style.normalBorderFor(Commons.Color.foreground, Commons.Color.accent))) + compare(String(Paint.popupBorder), String(Commons.Color.popups.border)) + } + + // Picking applies live and unpicking restores the original bindings — the + // promise a dropdown that takes effect without a restart is making. + function test_switching_back_and_forth_restores_the_bindings() { + scene.followOmarchy() + var desktopBorder = String(card.border.color) + var desktopAccent = String(Paint.accent) + + scene.pickTheme("fixture-light") + verify(String(card.border.color) !== desktopBorder, + "the card's border followed the picked theme") + + scene.followOmarchy() + compare(String(card.border.color), desktopBorder, + "following again restores the card's border") + compare(String(Paint.accent), desktopAccent) + compare(String(Paint.popupBorder), String(Commons.Color.popups.border)) + } + + // A settings file is not a trusted theme name. Anything unusable is Follow + // Omarchy, never an error state and never a path. + function test_an_invalid_stored_theme_falls_back() { + Paint.available = true + Paint.themeName = "../../etc/passwd" + compare(Paint.selected, "", "a traversing name is not a theme") + // Even if a directory was handed over with it, there is no theme to read. + Paint.themeDir = "/themes/../../etc/passwd" + Paint.colorsText = "" + Paint.shellText = "" + Paint.rebuild() + verify(!Paint.active, "an unreadable theme is Follow Omarchy") + compare(String(Paint.foreground), String(Commons.Color.foreground)) + + Paint.themeName = ".hidden" + compare(Paint.selected, "") + Paint.themeName = "not installed" + compare(Paint.selected, "") + } + + // The picker: Follow Omarchy first, then every installed theme by the name + // a person reads, with the user's copy of a name winning over the installed + // one. + function test_the_picker_lists_user_and_system_themes() { + var catalog = Qt.createQmlObject('import "../../theme"; ThemeCatalog {}', scene) + catalog.roots = ["/home/u/.config/omarchy/themes", "/usr/share/omarchy/themes"] + var found = catalog.parse([ + "/usr/share/omarchy/themes/nord/colors.toml", + "/usr/share/omarchy/themes/catppuccin-latte/colors.toml", + "/home/u/.config/omarchy/themes/nord/colors.toml", + "/usr/share/omarchy/themes/../colors.toml", + ].join("\n")) + catalog.userThemes = found.user + catalog.systemThemes = found.system + + compare(catalog.options[0].value, "", "Follow Omarchy is the first choice") + compare(catalog.options[0].label, "Follow Omarchy") + compare(catalog.options.length, 3, "one entry per name, plus the default") + compare(catalog.options[1].label, "Catppuccin Latte") + compare(catalog.options[2].label, "Nord") + compare(catalog.directoryFor("nord"), "/home/u/.config/omarchy/themes/nord", + "the user's copy of a name wins") + compare(catalog.directoryFor("catppuccin-latte"), "/usr/share/omarchy/themes/catppuccin-latte") + compare(catalog.directoryFor(""), "", "Follow Omarchy has no directory") + compare(catalog.directoryFor(".."), "") + catalog.destroy() + } + + // The bar is the desktop's surface. Picking a theme for the window must not + // reach it. + function test_the_bar_keeps_the_desktop_palette() { + var before = scene.paintedColours(barPreview, []) + verify(before.length > 0, "the bar preview paints something") + scene.pickTheme("fixture-light") + var after = scene.paintedColours(barPreview, []) + compare(after.length, before.length) + for (var i = 0; i < before.length; i++) { + compare(String(after[i].colour), String(before[i].colour), + "bar colour at " + before[i].where + " did not change") + } + // Nothing in the bar came from the picked theme: its lines are the + // desktop's, at the desktop's alphas. + for (var j = 0; j < after.length; j++) verify(scene.isDesktopNeutral(after[j].colour), + "the bar paints a desktop colour at " + after[j].where) + } + + // The one part of the spin box the wrapper replaces, and the only part of it + // that came from the shell's baked tokens. + function test_number_field_background_follows_the_theme() { + // The wrapper replaces the box's background rather than recolouring it, so + // each state has to be read from the box afresh. + scene.followOmarchy() + verify(numberField.field.background !== null, "the spin box has a background") + var shellsBackground = String(numberField.field.background.color) + + scene.pickTheme("fixture-light") + compare(String(numberField.field.background.color), + String(Paint.normalFillFor(Paint.foreground, Paint.accent)), + "the box is drawn in the picked theme's own fill") + verify(!scene.isDesktopNeutral(numberField.field.background.border.color), + "its border is the window's, not the desktop's") + + scene.followOmarchy() + compare(String(numberField.field.background.color), shellsBackground, + "following again leaves the box the shell drew") + } + + // ------------------------------------------------------------ the picker + // + // Follow -> a light theme -> Follow again -> a dark one, through the kit's + // own dropdown. The shell's control assigns its own value when a row is + // chosen, so the label a person reads is asserted separately from the + // value the window stores. + // + // Each step waits for the state it is about to drive rather than for a + // number of milliseconds. A popup that reports itself open is not yet + // necessarily the thing the keyboard reaches, and this suite runs every + // file in one process, so a fixed delay is a guess that can land early and + // make the picker look broken when it is only late. + function test_picker_round_trip() { + scene.followOmarchy() + scene.persistedTheme = "" + wait(50) + compare(themePicker.currentLabel(), "Follow Omarchy") + verify(!Paint.active, "nothing is picked") + + themePicker.open() + tryVerify(function() { return themePicker.popupOpen }, 2000, + "the picker's popup opened") + keyClick(Qt.Key_Down); keyClick(Qt.Key_Return) + tryVerify(function() { return Paint.active }, 2000, "a theme was picked") + compare(scene.persistedTheme, "fixture-light") + compare(themePicker.currentLabel(), "Fixture Light") + + themePicker.open() + tryVerify(function() { return themePicker.popupHasFocus }, 2000, + "the themed popup's list holds the keyboard") + keyClick(Qt.Key_Up); keyClick(Qt.Key_Return) + tryVerify(function() { return !Paint.active }, 2000, "Follow Omarchy was picked again" + + " (popup open: " + themePicker.popupOpen + ", picker value: \"" + themePicker.value + + "\", label: \"" + themePicker.currentLabel() + "\")") + compare(scene.persistedTheme, "") + compare(themePicker.value, "") + compare(themePicker.currentLabel(), "Follow Omarchy", + "the picker reads the setting the window stored") + compare(String(themePicker.children[0].value), "", + "and the shell's own trigger was put in step with it") + compare(themePicker.children[0].currentLabel(), "Follow Omarchy") + + themePicker.open() + tryVerify(function() { return themePicker.popupOpen }, 2000, + "the picker opens again after following") + keyClick(Qt.Key_Down); keyClick(Qt.Key_Down); keyClick(Qt.Key_Return) + tryVerify(function() { return Paint.active }, 2000, "a later selection still works") + compare(scene.persistedTheme, "fixture-dark") + compare(themePicker.currentLabel(), "Fixture Dark") + compare(String(Paint.background), "#1e1e2e") + } + + // The real settings page: its Appearance row is the picker, and its popup + // is opened while a theme is picked. + function test_the_real_settings_page_opens_the_picker() { + scene.pickTheme("fixture-light"); wait(50) + var picker = findChild(settingsPage, "app-theme-picker") + verify(picker !== null, "the real settings page offers the theme picker") + picker.open(); wait(60) + verify(picker.popupOpen, "the picker's popup opens in a picked theme") + picker.close(); wait(20) + verify(!picker.popupOpen) + } + + // The two views people spend the day in — the real list and the real + // composer, not stand-ins for them. While following, the desktop's colours + // are what they paint; with a theme picked, none of them may be. The first + // half is what makes the second mean anything. + function test_the_real_mail_list_and_composer_follow_the_picked_theme() { + scene.followOmarchy(); wait(80) + var following = scene.neutralColours(messageList) + verify(following.length > 0, + "following leaves the list on the desktop's palette") + + scene.pickTheme("fixture-light") + // An opened composer with a draft in it. An empty one shows Qt's own + // placeholder grey, which belongs to neither palette. + var toField = findChild(composeView, "compose-to-field") + var subjectField = findChild(composeView, "compose-subject-field") + verify(toField !== null && subjectField !== null, "the composer offers its fields") + toField.text = "ada@example.org" + subjectField.text = "Quarterly report" + wait(80) + + var listNeutral = scene.neutralColours(messageList) + compare(listNeutral.length, 0, + "the message list paints only the window's colours: " + listNeutral.join(", ")) + var composeNeutral = scene.neutralColours(composeView) + compare(composeNeutral.length, 0, + "the composer paints only the window's colours: " + composeNeutral.join(", ")) + compare(String(Paint.background), "#eff1f5", "and it is a picked theme being drawn") + } + + // A chosen control keeps its non-colour indication: the current mailbox + // stays bold, and the chosen calendar colour keeps its ring. + function test_chosen_mailbox_keeps_its_bold_label() { + scene.pickTheme("fixture-light"); wait(50) + var label = scene.textItemFor(mailboxTabs, "Inbox") + verify(label !== null, "the current mailbox draws its label") + verify(label.font.bold, "a chosen mailbox stays bold while a theme is picked") + + scene.followOmarchy(); wait(50) + var followed = scene.textItemFor(mailboxTabs, "Inbox") + verify(followed !== null && followed.font.bold, "and stays bold while following") + } + + function test_chosen_calendar_colour_keeps_its_ring() { + var colorButton = findChild(calendarSettings, "calendar-source-color") + verify(colorButton !== null, "the calendar row offers a colour") + colorButton.forceActiveFocus(); keyClick(Qt.Key_Return); wait(50) + var swatch = findChild(calendarSettings, "calendar-color-swatch-blue") + verify(swatch !== null, "the palette shows the chosen colour") + var ring = swatch.parent + verify(ring.border.width > 0, "the chosen colour is ringed while following") + + scene.pickTheme("fixture-light"); wait(50) + verify(swatch.parent.border.width > 0, "and keeps its ring while a theme is picked") + } + + // ------------------------------------------------- borders and tooltips + function test_button_border_and_tooltip_follow_the_picked_theme() { + scene.followOmarchy(); wait(50) + var shellBorder = String(borderedButton.border.color) + var shellTip = String(borderedButton.tooltipForeground) + scene.pickTheme("fixture-light"); wait(50) + compare(String(borderedButton.border.color), + String(Paint.normalBorderFor(Paint.foreground, Paint.accent))) + compare(String(borderedButton.tooltipForeground), String(Paint.tooltipText)) + compare(String(borderedButton.tooltipBackground), String(Paint.tooltipBackground)) + + scene.followOmarchy(); wait(50) + compare(String(borderedButton.border.color), shellBorder, + "following again leaves the shell's own border") + compare(String(borderedButton.tooltipForeground), shellTip, + "and the shell's own tooltip palette") + } + + function test_open_tooltip_uses_the_window_palette() { + scene.pickTheme("fixture-light"); wait(50) + mouseMove(borderedButton, borderedButton.width / 2, borderedButton.height / 2); wait(600) + var tip = findChild(borderedButton, "button-tooltip") + verify(tip !== null, "the tooltip is the shell's own") + verify(tip.visible, "hovering the button opens its tooltip") + compare(String(tip.contentItem.color), String(Paint.tooltipText)) + } + + function test_number_field_selection_follows_the_theme() { + scene.followOmarchy(); wait(50) + var shellSelection = String(numberField.field.contentItem.selectionColor) + scene.pickTheme("fixture-light"); wait(50) + numberField.field.contentItem.forceActiveFocus() + numberField.field.contentItem.selectAll(); wait(50) + compare(String(numberField.field.contentItem.selectionColor), + String(Paint.selectionFillFor(Paint.foreground, Paint.accent))) + + scene.followOmarchy(); wait(50) + compare(String(numberField.field.contentItem.selectionColor), shellSelection, + "following again restores the shell's own selection tint") + } + + // ------------------------------------------------------- palette edges + function test_a_palette_without_a_usable_foreground_falls_back() { + Paint.available = true + Paint.themeName = "broken" + Paint.themeDir = "/themes/broken" + Paint.colorsText = 'background = "#eff1f5"\nforeground = "garbage"\n' + Paint.shellText = "" + Paint.rebuild(); wait(20) + verify(!Paint.active, "a theme with no usable foreground is not drawn with") + compare(String(Paint.foreground), String(Commons.Color.foreground)) + compare(String(Paint.background), String(Commons.Color.background)) + } + + function test_the_roles_a_theme_leaves_out_are_filled() { + Paint.available = true + Paint.themeName = "sparse" + Paint.themeDir = "/themes/sparse" + Paint.colorsText = 'foreground = "#4c4f69"\nbackground = "#eff1f5"\n' + Paint.shellText = "" + Paint.rebuild(); wait(20) + verify(Paint.active, "a drawable palette is a theme") + compare(String(Paint.accent), "#4c4f69", "the accent falls back to the foreground") + compare(String(Paint.urgent), "#4c4f69", "and so does the urgent colour") + } + + function test_a_valid_theme_that_reloads_broken_falls_back() { + scene.pickTheme("fixture-light"); wait(20) + verify(Paint.active) + // The file on disk lost its foreground while the window was open. + Paint.colorsText = 'background = "#eff1f5"\nforeground = "garbage"\n' + Paint.rebuild(); wait(20) + verify(!Paint.active, "an incomplete reload is Follow Omarchy") + compare(String(Paint.background), String(Commons.Color.background)) + compare(String(Paint.foreground), String(Commons.Color.foreground)) + } + + function test_colors_toml_active_border_reaches_the_popup() { + Paint.available = true + Paint.themeName = "border" + Paint.themeDir = "/themes/border" + Paint.colorsText = [ + 'foreground = "#4c4f69"', + 'background = "#eff1f5"', + 'accent = "#8839ef"', + 'hyprland_active_border = "#123456 #654321 45deg"', + ].join("\n") + Paint.shellText = "" + Paint.rebuild(); wait(20) + compare(String(Paint.popupBorder), "#123456", + "the popup takes the first colour of the active border") + } + + function test_control_spec_keeps_the_live_alpha_and_geometry() { + scene.pickTheme("fixture-light"); wait(20) + var spec = Paint.controlSpec("normal", Paint.foreground, Paint.accent) + compare(String(spec.color), String(Paint.normalBorderFor(Paint.foreground, Paint.accent)), + "the stock alpha is the live one") + compare(spec.widths.top, Style.normalBorderWidth) + var previous = Style.normalBorderAlpha + Style.normalBorderAlpha = 0.7 + var stronger = Paint.controlSpec("normal", Paint.foreground, Paint.accent) + compare(stronger.color.a.toFixed(2), "0.70", "a non-default alpha is kept") + Style.normalBorderAlpha = previous + } + + // The colour walk, with the picker's popup open and a tooltip on screen: + // neither may paint a desktop colour. + function test_the_walk_with_an_open_popup_and_tooltip() { + scene.pickTheme("fixture-light"); wait(50) + themePicker.open(); wait(60) + mouseMove(borderedButton, borderedButton.width / 2, borderedButton.height / 2); wait(600) + var neutral = scene.neutralColours(surface) + themePicker.close() + compare(neutral.length, 0, "with a popup and a tooltip open the window still paints only its own colours: " + + neutral.join(", ")) + } + } +} diff --git a/ui/tests/qml/tst_app_theme_files.qml b/ui/tests/qml/tst_app_theme_files.qml new file mode 100644 index 0000000..1d21ec2 --- /dev/null +++ b/ui/tests/qml/tst_app_theme_files.qml @@ -0,0 +1,137 @@ +import QtQuick 2.15 +import QtTest 1.3 +import Quickshell +import "../../theme" + +// The theme choice as the window makes it: a stored setting, the catalog's +// answer for where that theme lives, and Paint opening the files there. Nothing +// here hands Paint a palette or asks it to reload; if a choice does not end +// with its file read, the window is drawn in no theme at all. +Item { + id: scene + width: 200 + height: 200 + + QtObject { + id: store + property var files: ({}) + property var reads: [] + signal changed(string path) + function read(path) { + var key = String(path) + reads = reads.concat([key]) + if (!Object.prototype.hasOwnProperty.call(files, key)) return ({ ok: false, text: "", error: "missing" }) + return ({ ok: true, text: String(files[key]), error: "" }) + } + function watch(path, enabled) {} + } + + QtObject { + id: pluginHost + property var capabilities: ({ appTheme: true }) + property var settings: ({ appTheme: "" }) + property var platform: null + function persistSetting(key, value) { + var next = ({}) + for (var name in settings) next[name] = settings[name] + next[key] = value + settings = next + } + } + + QtObject { + id: standalonePlatform + property string calendarPalettePath: "" + } + + QtObject { + id: standaloneHost + property var capabilities: ({ appTheme: false }) + property var settings: ({ appTheme: "alpha" }) + property var platform: standalonePlatform + function persistSetting(key, value) {} + } + + AppTheme { id: chooser; host: pluginHost } + + // Every AppTheme drives the one Paint, so the standalone host's is made only + // for the test that asks about it. + Component { + id: standaloneComponent + AppTheme { host: standaloneHost } + } + + TestCase { + name: "AppThemeFiles" + when: windowShown + + function initTestCase() { + store.files = ({ + "/themes/alpha/colors.toml": 'foreground = "#4c4f69"\nbackground = "#eff1f5"\naccent = "#8839ef"\n', + "/themes/beta/colors.toml": 'foreground = "#cdd6f4"\nbackground = "#1e1e2e"\naccent = "#89b4fa"\n' + }) + Quickshell.fileStore = store + // What the catalog's `find` prints for these two themes. + var found = chooser.catalog.parse("/themes/alpha/colors.toml\n/themes/beta/colors.toml\n") + chooser.catalog.userThemes = found.user + chooser.catalog.systemThemes = found.system + compare(chooser.catalog.directoryFor("alpha"), "/themes/alpha") + } + + function cleanupTestCase() { + chooser.choose("") + Quickshell.fileStore = null + } + + function expectTheme(name, background) { + tryVerify(function() { return Paint.active && String(Paint.background) === background }, 2000, + name + " is drawn from its file (active: " + Paint.active + ", file: \"" + + Paint.colorsFile.path + "\", background: " + Paint.background + ")") + compare(Paint.colorsFile.path, "/themes/" + name + "/colors.toml") + compare(chooser.colorsPath, "/themes/" + name + "/colors.toml", + "the calendar reads the theme the window is drawn in") + } + + function expectFollowing() { + tryVerify(function() { return !Paint.active }, 2000, "Follow Omarchy draws the desktop") + compare(Paint.colorsFile.path, "") + compare(Paint.shellFile.path, "") + } + + // Follow, a theme, Follow, another theme, and straight across. + function test_each_choice_ends_with_its_file_read() { + chooser.choose("") + expectFollowing() + chooser.choose("alpha") + expectTheme("alpha", "#eff1f5") + chooser.choose("") + expectFollowing() + chooser.choose("beta") + expectTheme("beta", "#1e1e2e") + chooser.choose("alpha") + expectTheme("alpha", "#eff1f5") + chooser.choose("") + expectFollowing() + } + + // The palette file a host gets when nothing is picked: the desktop's when + // the host names none, and nothing when the host says "" — the standalone + // window, which has no desktop palette and must not read one. + function test_an_empty_host_palette_path_stays_empty() { + var standaloneChoice = createTemporaryObject(standaloneComponent, scene) + verify(standaloneChoice) + compare(standaloneChoice.colorsPath, "", "an explicit empty path is an answer") + standaloneChoice.destroy() + wait(0) + // Hand Paint back to the plugin's choice. + pluginHost.capabilities = ({ appTheme: false }) + pluginHost.capabilities = ({ appTheme: true }) + chooser.choose("beta") + expectTheme("beta", "#1e1e2e") + chooser.choose("") + expectFollowing() + verify(String(chooser.colorsPath).endsWith("/.local/state/omarchy/current/theme/colors.toml"), + "a host that names no palette gets the desktop's: " + chooser.colorsPath) + } + } +} diff --git a/ui/tests/qml/tst_kit_tab_chain.qml b/ui/tests/qml/tst_kit_tab_chain.qml new file mode 100644 index 0000000..f840000 --- /dev/null +++ b/ui/tests/qml/tst_kit_tab_chain.qml @@ -0,0 +1,33 @@ +import QtQuick +import QtTest +import "../../kit" as Kit + +// Tab and Shift+Tab through plain wrapped buttons, where nothing but Qt's own +// focus chain handles the key: each button is one stop, in order, both ways. +// A wrapper that was a second stop around the shell's button would make Tab +// land on every button twice. (The standalone host's own button does not walk +// plain Tab under the test runner even unwrapped; its dialogs are covered by +// the standalone composition tests, which drive Tab the way the dialogs do.) +Item { + id: scene + width: 300; height: 100 + Row { + Kit.Button { id: first; objectName: "first"; text: "First"; focusable: true } + Kit.Button { id: second; objectName: "second"; text: "Second"; focusable: true } + Kit.Button { id: third; objectName: "third"; text: "Third"; focusable: true } + } + TestCase { + name: "KitTabChain" + when: windowShown + function test_tab_and_backtab_walk_each_button_once() { + // Where the stop is differs by host (the shell's button is its own; the + // standalone host's is the control inside it). Where Tab lands does not. + first.forceActiveFocus() + verify(first.activeFocus, "focus given to a button is focus on it") + keyClick(Qt.Key_Tab); verify(second.activeFocus, "Tab: first -> second") + keyClick(Qt.Key_Tab); verify(third.activeFocus, "Tab: second -> third") + keyClick(Qt.Key_Backtab, Qt.ShiftModifier); verify(second.activeFocus, "Backtab: third -> second") + keyClick(Qt.Key_Backtab, Qt.ShiftModifier); verify(first.activeFocus, "Backtab: second -> first") + } + } +} diff --git a/ui/tests/test_themes.js b/ui/tests/test_themes.js new file mode 100644 index 0000000..da14e3f --- /dev/null +++ b/ui/tests/test_themes.js @@ -0,0 +1,272 @@ +const assert = require("assert") +const { load, deepEqual } = require("./load") + +const themes = load("theme/Themes.js") + +// ---------------------------------------------------------------- names +// +// A theme name becomes a path segment under a theme directory, so it is the +// one string in this feature a settings file can use to reach somewhere else. +// Everything that is not a plain name is Follow Omarchy. +assert.strictEqual(themes.FOLLOW, "") +assert.strictEqual(themes.validName("nord"), true) +assert.strictEqual(themes.validName("catppuccin-latte"), true) +assert.strictEqual(themes.validName("retro-82"), true) +assert.strictEqual(themes.validName("a.b_c-1"), true) +assert.strictEqual(themes.validName(""), false) +assert.strictEqual(themes.validName("."), false) +assert.strictEqual(themes.validName(".."), false) +assert.strictEqual(themes.validName("../../etc/passwd"), false) +assert.strictEqual(themes.validName("a/b"), false) +assert.strictEqual(themes.validName("a\\b"), false) +assert.strictEqual(themes.validName(".hidden"), false) +assert.strictEqual(themes.validName("-rf"), false) +assert.strictEqual(themes.validName("n ord"), false) +assert.strictEqual(themes.validName("nord\nrm -rf /"), false) +assert.strictEqual(themes.validName("nord\0"), false) +assert.strictEqual(themes.validName("a".repeat(65)), false) +assert.strictEqual(themes.validName(null), false) +assert.strictEqual(themes.validName(undefined), false) +assert.strictEqual(themes.validName(42), false) + +assert.strictEqual(themes.normalizeName("nord"), "nord") +assert.strictEqual(themes.normalizeName(" nord "), "nord") +assert.strictEqual(themes.normalizeName("Nord"), "Nord") +assert.strictEqual(themes.normalizeName("../../x"), "") +assert.strictEqual(themes.normalizeName(""), "") +assert.strictEqual(themes.normalizeName(null), "") +assert.strictEqual(themes.normalizeName(undefined), "") +assert.strictEqual(themes.normalizeName(7), "") + +// The picker shows the name a person would say, from the name a directory has. +assert.strictEqual(themes.displayName("catppuccin-latte"), "Catppuccin Latte") +assert.strictEqual(themes.displayName("retro-82"), "Retro 82") +assert.strictEqual(themes.displayName("nord"), "Nord") +assert.strictEqual(themes.displayName("flexoki_light"), "Flexoki Light") +assert.strictEqual(themes.displayName("osaka.jade"), "Osaka Jade") +assert.strictEqual(themes.displayName(""), "") + +// ------------------------------------------------------------ colors.toml +// +// A current Omarchy theme states its roles outright. +const modern = themes.parseColors([ + 'mode = "dark"', + '', + 'accent = "#89b4fa"', + 'selection = "#45475a"', + 'muted = "#585b70"', + '', + 'background = "#1e1e2e"', + 'foreground = "#cdd6f4"', + '', + 'red = "#f38ba8"', +].join("\n")) +deepEqual(modern, { + foreground: "#cdd6f4", background: "#1e1e2e", accent: "#89b4fa", + urgent: "#f38ba8", muted: "#585b70", selection: "#45475a", + mode: "dark", light: false, hyprlandActiveBorder: "", +}) + +// An older theme has only the sixteen terminal colours; the same four +// fallbacks the shell's Color.loadColors uses fill the roles in. +const legacy = themes.parseColors([ + 'color0 = "#101010"', + 'color1 = "#cc3333"', + 'color4 = "#3355ff"', + 'color7 = "#e0e0e0"', + 'color8 = "#707070"', +].join("\n")) +deepEqual(legacy, { + foreground: "#e0e0e0", background: "#101010", accent: "#3355ff", + urgent: "#cc3333", muted: "#707070", selection: "#707070", + mode: "dark", light: false, hyprlandActiveBorder: "", +}) + +// No muted colour means the foreground, and no accent means color4 — an +// explicit accent is not overwritten by a color4 that appears later. +const sparse = themes.parseColors([ + 'foreground = "#ffffff"', + 'background = "#000000"', + 'color4 = "#123456"', +].join("\n")) +assert.strictEqual(sparse.accent, "#123456") +assert.strictEqual(sparse.muted, "#ffffff") + +// Comments, inline comments, unquoted values, unknown keys and malformed +// lines are tolerated; a second reading of a key wins, as it does in the +// shell's own loader. +const messy = themes.parseColors([ + '# a comment', + 'foreground = "#eeeeee" # trailing', + 'background=#111111', + 'mode = "light"', + 'selection = "#45475a"', + 'not a line at all', + 'foreground = "#zzzzzz"', + 'foreground = "#dddddd"', +].join("\n")) +assert.strictEqual(messy.foreground, "#dddddd") +assert.strictEqual(messy.background, "#111111") +assert.strictEqual(messy.mode, "light") +assert.strictEqual(messy.light, true) + +// A file with no usable colour is not a theme: null, so the stored name +// falls back to Follow Omarchy instead of becoming an error state. +assert.strictEqual(themes.parseColors(""), null) +assert.strictEqual(themes.parseColors(undefined), null) +assert.strictEqual(themes.parseColors('mode = "dark"\n'), null) + +// A theme that cannot be drawn is not a theme. Foreground text on a +// background surface is the whole of what a window needs, and a file that +// states only one of the two used to be accepted with an empty role, which +// paints black text on black or nothing at all. +assert.strictEqual(themes.parseColors('background = "#eff1f5"\nforeground = "garbage"\n'), null) +assert.strictEqual(themes.parseColors('foreground = "#4c4f69"\nbackground = "garbage"\n'), null) +assert.strictEqual(themes.parseColors('color7 = "#e0e0e0"\n'), null) + +// The roles a theme leaves out are filled deliberately, never left empty. +const noAccent = themes.parseColors('foreground = "#4c4f69"\nbackground = "#eff1f5"\n') +assert.strictEqual(noAccent.accent, "#4c4f69") +assert.strictEqual(noAccent.urgent, "#4c4f69") +const noUrgent = themes.parseColors([ + 'foreground = "#4c4f69"', + 'background = "#eff1f5"', + 'accent = "#8839ef"', +].join("\n")) +assert.strictEqual(noUrgent.urgent, "#8839ef") +assert.strictEqual(noUrgent.selection, noUrgent.muted) + +// colors.toml's Hyprland active border is what the stock template puts behind +// a popup when the theme ships no shell.toml of its own; only its first colour +// can be drawn on a single-colour surface. +const hypr = themes.parseColors([ + 'foreground = "#4c4f69"', + 'background = "#eff1f5"', + 'accent = "#8839ef"', + 'hyprland_active_border = "#123456 #654321 45deg"', +].join("\n")) +assert.strictEqual(hypr.hyprlandActiveBorder, "#123456") +assert.strictEqual(themes.resolveTheme(hypr, "").popups.border, "#123456") +// A theme's own shell.toml still decides the popup border when it states one. +assert.strictEqual(themes.resolveTheme(hypr, '[popups]\nborder = "accent"\n').popups.border, "#8839ef") +// Without either, the accent is what the template falls back to. +assert.strictEqual(themes.resolveTheme(themes.parseColors([ + 'foreground = "#4c4f69"', 'background = "#eff1f5"', 'accent = "#8839ef"', +].join("\n")), "").popups.border, "#8839ef") + +// A theme that does not state its mode is read from its background. +const inferred = themes.parseColors('foreground = "#4c4f69"\nbackground = "#eff1f5"\n') +assert.strictEqual(inferred.mode, "light") +assert.strictEqual(inferred.light, true) + +// ------------------------------------------------------------ gradients +assert.strictEqual(themes.firstColorToken("#89b4fa #8ba4f0 45deg"), "#89b4fa") +assert.strictEqual(themes.firstColorToken("45deg #89b4fa #8ba4f0"), "#89b4fa") +assert.strictEqual(themes.firstColorToken("#89b4fa"), "#89b4fa") +assert.strictEqual(themes.firstColorToken(""), "") + +// ------------------------------------------------------------- surfaces +const light = themes.parseColors([ + 'mode = "light"', + 'foreground = "#4c4f69"', + 'background = "#eff1f5"', + 'accent = "#8839ef"', + 'red = "#d20f39"', + 'muted = "#8c8fa1"', +].join("\n")) + +// A theme that ships no shell.toml gets the stock template's meaning. +const stock = themes.resolveTheme(light, "") +assert.strictEqual(stock.palette.foreground, "#4c4f69") +assert.strictEqual(stock.popups.background, "#eff1f5") +assert.strictEqual(stock.popups.text, "#4c4f69") +assert.strictEqual(stock.popups.border, "#8839ef") +assert.strictEqual(stock.popups.backgroundAlpha, 1) +assert.strictEqual(stock.tooltip.background, "#eff1f5") +assert.strictEqual(stock.tooltip.text, "#4c4f69") +assert.strictEqual(stock.tooltip.border, "#4c4f69") +assert.strictEqual(stock.tooltip.backgroundAlpha, 0.97) +// Control colours stay tokens, because a caller's own foreground is what a +// role means. That is what makes a themed control follow the window. +assert.strictEqual(stock.controls.normal.color, "foreground") +assert.strictEqual(stock.controls.hover.color, "foreground") +assert.strictEqual(stock.controls.selected.color, "foreground") +assert.strictEqual(stock.controls.pressed.color, "foreground") +assert.strictEqual(stock.controls.selection.color, "foreground") +assert.strictEqual(stock.controls.normal.border, "foreground") +assert.strictEqual(stock.controls.selected.border, "foreground") + +// A theme that ships its own shell.toml is obeyed: role names resolve +// against the picked palette, hex is taken as written, and a popup border +// naming the Hyprland gradient becomes its first colour. +const shipped = themes.resolveTheme(light, [ + '[hyprland]', + 'active-border = "#8839ef #7297ff 45deg"', + '[controls]', + 'normal-color = "accent"', + 'hover-cursor-color = "#ff0000"', + '[popups]', + 'background = "foreground"', + 'border = "hyprland.active-border"', + 'background-alpha = 0.95', + '[tooltip]', + 'text = "accent"', +].join("\n")) +assert.strictEqual(shipped.popups.border, "#8839ef") +assert.strictEqual(shipped.popups.background, "#4c4f69") +assert.strictEqual(shipped.popups.backgroundAlpha, 0.95) +assert.strictEqual(shipped.tooltip.text, "#8839ef") +assert.strictEqual(shipped.controls.normal.color, "accent") +assert.strictEqual(shipped.controls.hover.color, "#ff0000") + +// A popup border with no gradient and no hex falls back to the accent. +const noBorder = themes.resolveTheme(light, [ + '[popups]', + 'border = "transparent"', +].join("\n")) +assert.strictEqual(noBorder.popups.border, "transparent") +assert.strictEqual(themes.resolveTheme(light, '[popups]\nborder = "nonsense"\n').popups.border, "#8839ef") + +// Tokens a caller passes a colour for resolve at call time. +assert.strictEqual(themes.resolveToken("foreground", light), "#4c4f69") +assert.strictEqual(themes.resolveToken("text", light), "#4c4f69") +assert.strictEqual(themes.resolveToken("accent", light), "#8839ef") +assert.strictEqual(themes.resolveToken("urgent", light), "#d20f39") +assert.strictEqual(themes.resolveToken("background", light), "#eff1f5") +assert.strictEqual(themes.resolveToken("#ff0000", light), "#ff0000") +assert.strictEqual(themes.resolveToken("transparent", light), "transparent") +assert.strictEqual(themes.resolveToken("nonsense", light), "") + +// ---------------------------------------------------------------- roots +// +// The user's own theme wins over the installed one of the same name, and +// OMARCHY_PATH is honoured when it is set — which it often is not inside the +// plugin's own environment. +deepEqual(themes.themeRoots("/home/u", "/opt/omarchy"), [ + "/home/u/.config/omarchy/themes", + "/opt/omarchy/themes", + "/home/u/.local/share/omarchy/themes", + "/usr/share/omarchy/themes", +]) +deepEqual(themes.themeRoots("/home/u", ""), [ + "/home/u/.config/omarchy/themes", + "/home/u/.local/share/omarchy/themes", + "/usr/share/omarchy/themes", +]) +deepEqual(themes.themeRoots("", ""), ["/usr/share/omarchy/themes"]) + +deepEqual(themes.mergeEntries( + [{ name: "nord", dir: "/home/u/.config/omarchy/themes/nord" }], + [ + { name: "nord", dir: "/usr/share/omarchy/themes/nord" }, + { name: "catppuccin-latte", dir: "/usr/share/omarchy/themes/catppuccin-latte" }, + ]), [ + { name: "catppuccin-latte", label: "Catppuccin Latte", dir: "/usr/share/omarchy/themes/catppuccin-latte", user: false }, + { name: "nord", label: "Nord", dir: "/home/u/.config/omarchy/themes/nord", user: true }, +]) + +// A directory whose name is not a theme name is not offered. +deepEqual(themes.mergeEntries([{ name: "..", dir: "/x" }, { name: "", dir: "/y" }], []), []) +deepEqual(themes.mergeEntries(undefined, undefined), []) + +console.log("test_themes.js ok") diff --git a/ui/theme/AppTheme.qml b/ui/theme/AppTheme.qml new file mode 100644 index 0000000..6a2d532 --- /dev/null +++ b/ui/theme/AppTheme.qml @@ -0,0 +1,89 @@ +import QtQuick +import Quickshell +import "Themes.js" as Themes + +// The window's own theme choice. +// +// Everything the rest of the window asks about it lives here, so the window's +// service does not carry it: the catalog the settings row lists, the directory +// Paint reads, and the palette file the parts that read colours from a file +// use. A theme name is untrusted — it comes from a settings file, and only a +// plain path segment that names an installed theme is anything but Follow +// Omarchy. +Item { + id: root + + // Nothing is drawn here: the object exists to hold the window's theme choice. + visible: false + + // The window's service: where the stored setting, the desktop's palette file + // and the capability to pick a theme at all come from. Only the Omarchy + // plugin has an Omarchy theme to offer; the standalone host has its own + // appearance setting and its own palettes. + property var host: null + + readonly property bool enabled: host !== null && host.capabilities.appTheme === true + readonly property var settings: host !== null ? host.settings : null + readonly property string selected: Themes.normalizeName(settings ? settings.appTheme : null) + + // The palette file this host would use with no theme picked. A host that + // names one is obeyed, and an empty name is an answer: the standalone host + // says "" because it has no desktop palette to read. Only a host that names + // nothing gets the desktop's current theme. + readonly property string desktopColorsPath: host !== null && host.platform + && host.platform.calendarPalettePath !== undefined + ? String(host.platform.calendarPalettePath || "") + : Quickshell.env("HOME") + "/.local/state/omarchy/current/theme/colors.toml" + + // Every installed Omarchy theme, with the user's copy of a name first. Only a + // host that can pick a theme reads the directories: the scan is a process, + // and the standalone window never asks for one. + // Declared as a property, because a plain object has no default property to + // hold a child. + readonly property ThemeCatalog catalog: ThemeCatalog { + objectName: "theme-catalog" + } + readonly property var options: catalog.options + readonly property string directory: root.enabled ? catalog.directoryFor(root.selected) : "" + + // Where the window draws from, for the parts of the app that read a palette + // out of a file rather than out of Paint. + readonly property string colorsPath: Paint.active && Paint.themeDir !== "" + ? Paint.themeDir + "/colors.toml" + : root.desktopColorsPath + + function refresh() { + if (root.enabled) catalog.refresh() + } + + // What a stored setting is allowed to become: a name that is installed or + // Follow Omarchy, never an error state. + function choose(value) { + if (root.host !== null) root.host.persistSetting("appTheme", Themes.normalizeName(value)) + } + + onEnabledChanged: root.refresh() + onSelectedChanged: if (root.enabled && root.selected !== Themes.FOLLOW) root.refresh() + // A theme picked before this window opened needs its directory resolved + // before the first paint; settings that arrive later go through storedValue. + Component.onCompleted: Qt.callLater(root.refresh) + + Binding { + target: Paint + property: "available" + value: root.enabled + restoreMode: Binding.RestoreNone + } + Binding { + target: Paint + property: "themeName" + value: root.selected + restoreMode: Binding.RestoreNone + } + Binding { + target: Paint + property: "themeDir" + value: root.directory + restoreMode: Binding.RestoreNone + } +} diff --git a/ui/theme/Paint.qml b/ui/theme/Paint.qml new file mode 100644 index 0000000..c97f407 --- /dev/null +++ b/ui/theme/Paint.qml @@ -0,0 +1,334 @@ +pragma Singleton +import QtQuick +import Quickshell +import Quickshell.Io +import qs.Commons +import qs.Commons as Commons +import "Themes.js" as Themes + +// One colour authority for the mail window. +// +// The shell's own `Commons.Color` is shared with the bar beside the window, so +// it can never be the place a per-app theme is applied. Neither can the shell's +// state helpers: Omarchy renders shell.toml with the desktop theme's hex baked +// into `[controls]`, so `Style.hoverFillFor(fg, accent)` ignores the colours it +// is given and returns the desktop's. Every colour the window paints therefore +// comes from here instead, and here is exactly two behaviours: +// +// Follow Omarchy — every colour and every helper delegates to +// `Commons.Color`, `Style` and `Border` with the same arguments. Not +// "similar": the same call, so the window is pixel-identical to the build +// before this existed. +// +// A picked theme — the same helpers, resolved against that theme's own +// palette. Alphas, border widths, spacing, fonts and corner radius still come +// from the live `Style`: they are the user's shell-wide values, they are +// identical across the stock themes, and a window that changed them would +// stop matching the bar and the rest of the desktop. +// +// Surfaces that are deliberately not the window's — the bar envelope, its +// unread popup, desktop notifications — are named at the bottom and never +// change with the picked theme. + +QtObject { + id: root + + // Whether a per-app theme can apply at all. Only the Omarchy plugin has an + // Omarchy theme to pick from; the standalone host has its own appearance + // setting and its own palettes. + property bool available: false + + // The picked theme's directory name. "" is Follow Omarchy, and anything a + // settings file could not name is normalised to "": an invalid answer is the + // default, never an error state. + property string themeName: "" + // Where that theme lives, resolved by ThemeCatalog — the one place that + // reads a theme directory listing. Untrusted like the name: this singleton + // re-validates by reading the file and falling back if it is not a theme. + property string themeDir: "" + + // The resolved theme (palette, popup and tooltip surfaces, control tokens), + // or null while following Omarchy or while a picked theme is unreadable. + property var theme: null + + readonly property string selected: Themes.normalizeName(themeName) + readonly property bool following: selected === Themes.FOLLOW + readonly property bool active: available && theme !== null && themeDir !== "" + + property string colorsText: "" + property string shellText: "" + + // Every input is read from its own plain property here, never from + // `selected`: the change handlers below can run before that derived binding + // has caught up, and a reload that saw the old name would settle on a valid + // theme without ever opening its files. Read this way, whichever input + // arrives last reloads with all of them. + function reload() { + root.theme = null + root.colorsText = "" + root.shellText = "" + if (root.available && Themes.normalizeName(root.themeName) !== Themes.FOLLOW + && root.themeDir !== "") { + // The theme was just cleared, so the files are read again even when the + // path is the one already open: the name and the directory can arrive + // in either order, and the second to arrive must not leave the window + // with no theme because the path it computes did not change. + var colorsPath = root.themeDir + "/colors.toml" + var shellPath = root.themeDir + "/shell.toml" + if (colorsFile.path === colorsPath) colorsFile.reload() + else colorsFile.path = colorsPath + if (shellFile.path === shellPath) shellFile.reload() + else shellFile.path = shellPath + } else { + colorsFile.path = "" + shellFile.path = "" + } + } + + function rebuild() { + var palette = Themes.parseColors(root.colorsText) + root.theme = palette === null ? null : Themes.resolveTheme(palette, root.shellText) + } + + onAvailableChanged: reload() + onThemeNameChanged: reload() + onThemeDirChanged: reload() + + // The picked theme's own files, watched, so editing a theme while the window + // stands recolours it the way the shell would. + property FileView colorsFile: FileView { + id: colorsFile + watchChanges: true + printErrors: false + onLoaded: { + root.colorsText = text() + root.rebuild() + } + onLoadFailed: { + root.colorsText = "" + root.rebuild() + } + onFileChanged: reload() + } + + property FileView shellFile: FileView { + id: shellFile + watchChanges: true + printErrors: false + onLoaded: { + root.shellText = text() + root.rebuild() + } + // A theme that ships no shell.toml is a theme with the template's defaults, + // not a broken theme. + onLoadFailed: { + root.shellText = "" + root.rebuild() + } + onFileChanged: reload() + } + + // --------------------------------------------------------------- palette + // + // The window's semantic colours. Every one of them is a role App.qml passes + // down as a required property, or the bar's own colour when following. + + readonly property color foreground: active ? theme.palette.foreground : Commons.Color.foreground + readonly property color background: active ? theme.palette.background : Commons.Color.background + readonly property color accent: active ? theme.palette.accent : Commons.Color.accent + readonly property color urgent: active ? theme.palette.urgent : Commons.Color.urgent + readonly property color muted: active ? theme.palette.muted : desktopMuted + readonly property color selectionColor: active ? theme.palette.selection : desktopMuted + + readonly property color popupBackground: active + ? Qt.alpha(theme.popups.background, theme.popups.backgroundAlpha) : Commons.Color.popups.background + readonly property color popupBorder: active + ? Qt.alpha(theme.popups.border, theme.popups.borderAlpha) : Commons.Color.popups.border + readonly property color popupText: active ? theme.popups.text : Commons.Color.popups.text + + readonly property color tooltipBackground: active + ? Qt.alpha(theme.tooltip.background, theme.tooltip.backgroundAlpha) : Commons.Color.tooltip.background + readonly property color tooltipBorder: active ? theme.tooltip.border : Commons.Color.tooltip.border + readonly property color tooltipText: active ? theme.tooltip.text : Commons.Color.tooltip.text + + // Not every host's Color has a muted role; the shell's does. + readonly property color desktopMuted: Commons.Color.muted !== undefined + ? Commons.Color.muted : Commons.Color.foreground + + // -------------------------------------------------------------- surfaces + // + // Colours that are not the window's own. The bar envelope, its popup and the + // desktop's notifications belong to the desktop theme however the window is + // drawn, so they are named here once rather than reached for from + // Commons.Color at each use. + + readonly property color desktopForeground: Commons.Color.foreground + readonly property color desktopBackground: Commons.Color.background + readonly property color desktopAccent: Commons.Color.accent + readonly property color barForeground: Commons.Color.foreground + readonly property color barPopupBackground: Commons.Color.popups.background + readonly property color barPopupText: Commons.Color.popups.text + readonly property color notificationForeground: Commons.Color.foreground + readonly property color notificationAccent: Commons.Color.accent + + // ------------------------------------------------------- state colours + // + // The same vocabulary the shell's Style uses: normal, hover-cursor, focus, + // selected, pressed, selection. A role token is resolved with the colours the + // caller passed — that is what makes a control follow the surface it is drawn + // on — while a hex a theme pinned is used as written. + + function paletteFor(foreground, accent, urgent) { + return { + foreground: foreground || root.foreground, + accent: accent || root.accent, + urgent: urgent || root.urgent, + background: root.background, + muted: root.muted, + selection: root.selectionColor, + } + } + + function stateColor(token, foreground, accent, urgent, fallback) { + if (!active) return fallback || foreground || root.foreground + var colour = Themes.resolveToken(token, paletteFor(foreground, accent, urgent)) + return colour !== "" ? colour : (fallback || foreground || root.foreground) + } + + function normalStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.normal.color, foreground, accent, urgent, root.foreground) + : Style.normalStateColor(foreground, accent, urgent) + } + function hoverStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.hover.color, foreground, accent, urgent, root.foreground) + : Style.hoverStateColor(foreground, accent, urgent) + } + function focusStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.focus.color, foreground, accent, urgent, root.foreground) + : Style.focusStateColor(foreground, accent, urgent) + } + function selectedStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.selected.color, foreground, accent, urgent, root.foreground) + : Style.selectedStateColor(foreground, accent, urgent) + } + function pressedStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.pressed.color, foreground, accent, urgent, root.foreground) + : Style.pressedStateColor(foreground, accent, urgent) + } + function selectionStateColor(foreground, accent, urgent) { + return active ? stateColor(theme.controls.selection.color, foreground, accent, urgent, root.foreground) + : Style.selectionStateColor(foreground, accent, urgent) + } + + function normalFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(normalStateColor(foreground, accent, urgent), Style.normalFillAlpha) + : Style.normalFillFor(foreground, accent, urgent) + } + function hoverFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(hoverStateColor(foreground, accent, urgent), Style.hoverFillAlpha) + : Style.hoverFillFor(foreground, accent, urgent) + } + function selectedFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(selectedStateColor(foreground, accent, urgent), Style.selectedFillAlpha) + : Style.selectedFillFor(foreground, accent, urgent) + } + function pressedFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(pressedStateColor(foreground, accent, urgent), Style.pressedFillAlpha) + : Style.pressedFillFor(foreground, accent, urgent) + } + function focusFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(focusStateColor(foreground, accent, urgent), Style.focusFillAlpha) + : Style.focusFillFor(foreground, accent, urgent) + } + function selectionFillFor(foreground, accent, urgent) { + return active ? Qt.alpha(selectionStateColor(foreground, accent, urgent), Style.selectionFillAlpha) + : Style.selectionFillFor(foreground, accent, urgent) + } + + function normalBorderFor(foreground, accent, urgent) { + return active ? Qt.alpha(normalStateColor(foreground, accent, urgent), Style.normalBorderAlpha) + : Style.normalBorderFor(foreground, accent, urgent) + } + function hoverBorderFor(foreground, accent, urgent) { + return active ? Qt.alpha(hoverStateColor(foreground, accent, urgent), Style.hoverBorderAlpha) + : Style.hoverBorderFor(foreground, accent, urgent) + } + function selectedBorderFor(foreground, accent, urgent) { + return active ? Qt.alpha(selectedStateColor(foreground, accent, urgent), Style.selectedBorderAlpha) + : Style.selectedBorderFor(foreground, accent, urgent) + } + function focusBorderFor(foreground, accent, urgent) { + return active ? Qt.alpha(focusStateColor(foreground, accent, urgent), Style.focusBorderAlpha) + : Style.focusBorderFor(foreground, accent, urgent) + } + + readonly property color normalFill: normalFillFor(foreground, accent, urgent) + readonly property color hoverFill: hoverFillFor(foreground, accent, urgent) + readonly property color selectedFill: selectedFillFor(foreground, accent, urgent) + readonly property color pressedFill: pressedFillFor(foreground, accent, urgent) + readonly property color selectionFill: selectionFillFor(foreground, accent, urgent) + readonly property color normalBorderColor: normalBorderFor(foreground, accent, urgent) + readonly property color hoverBorderColor: hoverBorderFor(foreground, accent, urgent) + readonly property color selectedBorderColor: selectedBorderFor(foreground, accent, urgent) + readonly property color focusBorderColor: focusBorderFor(foreground, accent, urgent) + // The shell's own selectedAccentFill, spelled out: it is the accent at the + // selected fill's alpha, and there is no per-theme colour of its own to use. + readonly property color selectedAccentFill: Qt.alpha(active ? accent : Commons.Color.accent, + Style.selectedFillAlpha) + + // Composite helpers for the focus > hover > normal ladder every form control + // paints, so a caller cannot pick a state the theme does not have. + function controlFill(focused, hot, foreground, accent) { + if (active) { + if (focused) return focusFillFor(foreground, accent) + if (hot) return hoverFillFor(foreground, accent) + return normalFillFor(foreground, accent) + } + return Style.controlFill(focused, hot, foreground, accent) + } + + function controlBorder(focused, hot, foreground, accent) { + if (active) { + if (focused) return focusBorderFor(foreground, accent) + if (hot) return hoverBorderFor(foreground, accent) + return normalBorderFor(foreground, accent) + } + return Style.controlBorder(focused, hot, foreground, accent) + } + + function controlBorderWidth(focused, hot) { + return active ? (focused ? focusBorderWidth : (hot ? hoverBorderWidth : normalBorderWidth)) + : Style.controlBorderWidth(focused, hot) + } + + readonly property int normalBorderWidth: Style.normalBorderWidth + readonly property int hoverBorderWidth: Style.hoverBorderWidth + readonly property int selectedBorderWidth: Style.selectedBorderWidth + readonly property int focusBorderWidth: Style.focusBorderWidth + + // A border spec in the shape `Border.controlSpec` returns, which is what a + // BorderSurface renders. The geometry and the state's live border alpha come + // from the shell's own spec — they are the user's shell-wide values — and + // only the colour itself is the theme's. + function controlSpec(state, foreground, accent, urgent) { + if (!active) return Border.controlSpec(state, foreground, accent, urgent) + var name = state === "hover" || state === "hot" ? "hover" : String(state || "normal") + var tokens = theme.controls[name] !== undefined ? theme.controls[name] : theme.controls.normal + var colour = stateColor(tokens.border || tokens.color, foreground, accent, urgent, root.foreground) + var alpha = name === "focus" ? Style.focusBorderAlpha + : name === "hover" ? Style.hoverBorderAlpha + : name === "selected" ? Style.selectedBorderAlpha + : Style.normalBorderAlpha + var shell = Border.controlSpec(state, foreground, accent, urgent) + return { + color: Qt.alpha(colour, alpha), + widths: shell.widths, + gradient: { colors: [], angle: 0, enabled: false }, + } + } + + function controlHasWidth(state) { + return active ? controlBorderWidth(state === "focus", state === "hover" || state === "hot") > 0 + : Border.controlHasWidth(state) + } +} diff --git a/ui/theme/ThemeCatalog.qml b/ui/theme/ThemeCatalog.qml new file mode 100644 index 0000000..a9082cc --- /dev/null +++ b/ui/theme/ThemeCatalog.qml @@ -0,0 +1,124 @@ +import QtQuick +import Quickshell +import Quickshell.Io +import "Themes.js" as Themes + +// The installed Omarchy themes, and where each one lives. +// +// A theme is a directory with a colors.toml in it. Omarchy's own +// bin/omarchy-theme-dir prefers the user's copy in ~/.config/omarchy/themes +// over the installed one of the same name; this keeps that rule and offers the +// merged list to the Settings row, and the winning directory to Paint. +// +// Reading the directories rather than asking a program keeps the answer honest +// when OMARCHY_PATH is unset — which it is inside a plugin's environment — and +// avoids handing a settings value to anything that takes options. The scan is +// one `find` with a fixed argv: no shell, no user text in a command string, and +// nothing it can do but list the files asked for. Names are still validated +// before they are used as a path segment, because a directory listing is not +// trusted input either. +QtObject { + id: root + + // The roots to scan, most specific first. Defaults to Omarchy's own order; + // tests set it outright. + property var roots: Themes.themeRoots(Quickshell.env("HOME"), Quickshell.env("OMARCHY_PATH")) + + // Whether a scan has finished at least once, so a caller can tell "no themes" + // from "not asked yet". + property bool scanned: false + + property var userThemes: [] + property var systemThemes: [] + + // Everything installed, one entry per name, sorted by the name a person + // reads. `user` says the user's copy won. + readonly property var installed: Themes.mergeEntries(userThemes, systemThemes) + + // The picker's options: Follow Omarchy first, then every installed theme by + // display name. A value is the directory name, which is what gets stored. + readonly property var options: { + var list = [{ value: Themes.FOLLOW, label: "Follow Omarchy" }] + var entries = installed + for (var i = 0; i < entries.length; i++) list.push({ value: entries[i].name, label: entries[i].label }) + return list + } + + // Where a theme lives, "" when it is not installed. + function directoryFor(name) { + var wanted = Themes.normalizeName(name) + if (wanted === Themes.FOLLOW) return "" + var entries = installed + for (var i = 0; i < entries.length; i++) if (entries[i].name === wanted) return entries[i].dir + return "" + } + + function labelFor(name) { + var wanted = Themes.normalizeName(name) + if (wanted === Themes.FOLLOW) return "Follow Omarchy" + var entries = installed + for (var i = 0; i < entries.length; i++) if (entries[i].name === wanted) return entries[i].label + return Themes.displayName(wanted) + } + + function scanCommand() { + var command = ["find"] + var wanted = [] + for (var i = 0; i < roots.length; i++) { + var path = String(roots[i] || "") + // An absolute path that cannot be read as an option. Roots come from the + // environment or a test, not from a settings file, but find would still + // read a "-x" as one. + if (path.charAt(0) !== "/") continue + wanted.push(path) + } + if (wanted.length === 0) return [] + command = command.concat(wanted) + // themes//colors.toml, one level under each root: exactly the shape + // of an Omarchy theme, and nothing deeper. + return command.concat(["-mindepth", "2", "-maxdepth", "2", "-name", "colors.toml", "-type", "f"]) + } + + // find prints one path per line. Each is a theme: the directory is the path + // without colors.toml, and its name is the last segment. + function parse(output) { + var lines = String(output === undefined || output === null ? "" : output).split("\n") + var user = [] + var system = [] + var userRoot = roots.length > 0 ? String(roots[0] || "") + "/" : "" + for (var i = 0; i < lines.length; i++) { + var line = lines[i].replace(/^\s+|\s+$/g, "") + if (line.length <= 11 || line.substring(line.length - 11) !== "colors.toml") continue + var dir = line.substring(0, line.length - 11).replace(/\/$/, "") + var slash = dir.lastIndexOf("/") + var name = slash >= 0 ? dir.substring(slash + 1) : dir + if (!Themes.validName(name)) continue + var entry = { name: name, dir: dir } + if (userRoot !== "" && line.indexOf(userRoot) === 0) user.push(entry) + else system.push(entry) + } + return { user: user, system: system } + } + + function refresh() { + var command = scanCommand() + if (command.length === 0) return + scan.command = command + scan.running = false + scan.running = true + } + + property Process scan: Process { + id: scan + running: false + stdout: StdioCollector { + waitForEnd: true + onStreamFinished: { + var found = root.parse(text) + root.userThemes = found.user + root.systemThemes = found.system + root.scanned = true + } + } + } +} diff --git a/ui/theme/Themes.js b/ui/theme/Themes.js new file mode 100644 index 0000000..2954e3b --- /dev/null +++ b/ui/theme/Themes.js @@ -0,0 +1,361 @@ +.pragma library + +// What an Omarchy theme is, as rules rather than as files. +// +// The window can be drawn in a theme other than the desktop's, so it needs the +// same four foundational roles the shell reads from colors.toml, the same +// fallbacks for a theme that only has terminal colours, and the surface and +// control tokens Omarchy bakes from default/themed/shell.toml.tpl. None of +// that needs the shell, a window or a file handle: this module takes the text +// of a theme's files and answers with colours, so the node tests and +// `Paint.qml` run exactly the same rules. +// +// The one thing this module deliberately does not decide is when a colour is +// used: control colours stay tokens ("foreground", or a hex a theme pinned) +// because `foreground` means the foreground of the surface asking, which is +// what lets a themed control follow the window it is drawn in. + +// The name that means "the desktop's theme". It is the empty string because +// that is what an absent setting reads as, and a theme may not be named it. +var FOLLOW = "" +var MAX_NAME_LENGTH = 64 + +// A theme name is a single path segment under a theme directory. Anything +// that could reach outside one — a separator, a parent reference, a leading +// dot, a leading dash for a program that takes options — is not a name. +function validName(name) { + if (typeof name !== "string") return false + if (name.length === 0 || name.length > MAX_NAME_LENGTH) return false + if (name.indexOf("..") >= 0) return false + return /^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name) +} + +// A stored setting is untrusted: whatever it says, an unusable value is +// Follow Omarchy rather than an error the window has to report. Only a string +// can name a theme; a number or an object in a settings file is not one. +function normalizeName(value) { + if (typeof value !== "string") return FOLLOW + var text = value.replace(/^\s+|\s+$/g, "") + return validName(text) ? text : FOLLOW +} + +// "catppuccin-latte" is a directory; "Catppuccin Latte" is what a person +// calls it. Digits are left alone, so "retro-82" keeps its number. +function displayName(slug) { + var parts = String(slug || "").split(/[-_.]+/) + var words = [] + for (var i = 0; i < parts.length; i++) { + var part = parts[i] + if (part.length === 0) continue + words.push(part.charAt(0).toUpperCase() + part.substring(1)) + } + return words.join(" ") +} + +// A border token may be a Hyprland-style gradient — colours and an angle in +// one string. A colour-only consumer, such as a native rectangle border, +// takes the first colour. +function firstColorToken(value) { + var parts = String(value === undefined || value === null ? "" : value) + .replace(/^\s+|\s+$/g, "") + .split(/\s+/) + for (var i = 0; i < parts.length; i++) { + if (parts[i].length === 0) continue + if (/^-?\d+(?:\.\d+)?deg$/.test(parts[i])) continue + return parts[i] + } + return "" +} + +function parseNumber(value, fallback) { + var text = String(value === undefined || value === null ? "" : value).replace(/^\s+|\s+$/g, "") + if (text === "") return fallback + var n = Number(text) + if (!isFinite(n)) return fallback + return Math.max(0, Math.min(1, n)) +} + +function channel(value) { + var c = value / 255 + return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4) +} + +// Whether a background is light, for a theme whose colors.toml does not say. +// Only used to describe the palette; nothing takes a decision from it. +function luminance(hex) { + var m = String(hex || "").match(/^#([0-9A-Fa-f]{6})$/) + if (!m) return 0 + var h = m[1] + return 0.2126 * channel(parseInt(h.substr(0, 2), 16)) + + 0.7152 * channel(parseInt(h.substr(2, 2), 16)) + + 0.0722 * channel(parseInt(h.substr(4, 2), 16)) +} + +var COLOR_LINE = /^\s*([A-Za-z0-9_-]+)\s*=\s*["']?(#[0-9A-Fa-f]{6})/ +var MODE_LINE = /^\s*mode\s*=\s*["']?(light|dark)\b/i + +// colors.toml into the four roles the window draws with, plus muted and the +// mode. The fallbacks are the shell's own: an older theme states only +// color0/color4/color7/color8, and a theme states its own accent or color4 is +// what "accent" meant. +// +// Returns null when the text states no usable colour at all — that is a +// broken or absent theme file, and the caller falls back to Follow Omarchy. +function parseColors(raw) { + var text = String(raw === undefined || raw === null ? "" : raw) + var out = { + foreground: "", background: "", accent: "", urgent: "", muted: "", + selection: "", mode: "", light: false, hyprlandActiveBorder: "", + } + var color0 = "", color4 = "", color7 = "", color8 = "" + var foundAccent = false, foundMuted = false, foundBackground = false, foundForeground = false + var lines = text.split("\n") + for (var i = 0; i < lines.length; i++) { + var mode = lines[i].match(MODE_LINE) + if (mode) out.mode = mode[1].toLowerCase() + var match = lines[i].match(COLOR_LINE) + if (!match) continue + var key = match[1] + var hex = match[2].toLowerCase() + if (key === "foreground") { out.foreground = hex; foundForeground = true } + else if (key === "background") { out.background = hex; foundBackground = true } + else if (key === "accent") { out.accent = hex; foundAccent = true } + else if (key === "muted") { out.muted = hex; foundMuted = true } + else if (key === "selection") out.selection = hex + else if (key === "color0") color0 = hex + else if (key === "color4") color4 = hex + else if (key === "color7") color7 = hex + else if (key === "color8") color8 = hex + else if (key === "red" || key === "color1") out.urgent = hex + // The active border is a Hyprland gradient; only its first colour can be + // drawn on a single-colour surface, and the shell's own template uses it as + // the popup border when a theme ships no shell.toml of its own. + else if (key === "hyprland_active_border") out.hyprlandActiveBorder = hex + } + if (!foundBackground) out.background = color0 + if (!foundForeground) out.foreground = color7 + if (!foundAccent) out.accent = color4 + // A theme has to be drawable before it may be used: foreground text on a + // background surface. A file that states neither, or only one of the two, is + // not a theme, and the caller falls back to Follow Omarchy. + if (out.foreground === "" || out.background === "") return null + // The remaining roles are optional in a theme, so they are filled + // deliberately rather than left empty: an accent the theme did not state is + // its foreground, as the shell's own accent falls back to its foreground, and + // an urgent colour is its accent. A caller that paints one of them therefore + // always has a real colour to paint. + if (out.accent === "") out.accent = out.foreground + if (out.urgent === "") out.urgent = out.accent + if (!foundMuted || out.muted === "") out.muted = color8 !== "" ? color8 : out.foreground + if (out.selection === "") out.selection = out.muted + if (out.mode === "") out.mode = luminance(out.background) > 0.5 ? "light" : "dark" + out.light = out.mode === "light" + return out +} + +// shell.toml into "section.key" values, the way Commons.Color.parseShell +// does: quoted strings, bare numbers, bare width lists and bare role names, +// with inline comments tolerated. Only the readers below decide what a value +// means. +function parseShell(raw) { + var parsed = ({}) + var text = String(raw === undefined || raw === null ? "" : raw) + if (text === "") return parsed + var lines = text.split("\n") + var section = "" + for (var i = 0; i < lines.length; i++) { + var line = lines[i].replace(/^\s+|\s+$/g, "") + if (line === "" || line.charAt(0) === "#") continue + var sectionMatch = line.match(/^\[([A-Za-z0-9_-]+)\]\s*(#.*)?$/) + if (sectionMatch) { section = sectionMatch[1]; continue } + var stringKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*["']([^"']+)["']\s*(#.*)?$/) + var numKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*(-?\d+(?:\.\d+)?)\s*(#.*)?$/) + var bareKv = line.match(/^([A-Za-z0-9_-]+)\s*=\s*([A-Za-z][A-Za-z0-9_-]*)\s*(#.*)?$/) + var kv = stringKv || numKv || bareKv + if (!kv || section === "") continue + parsed[section + "." + kv[1]] = kv[2] + } + return parsed +} + +// A role token against a palette. "" for anything the palette does not name, +// so a caller can fall back rather than paint black. +function resolveToken(token, palette) { + var role = String(token === undefined || token === null ? "" : token) + .replace(/^\s+|\s+$/g, "").toLowerCase() + var p = palette || ({}) + if (role === "foreground" || role === "text") return p.foreground || "" + if (role === "background") return p.background || "" + if (role === "accent") return p.accent || "" + if (role === "urgent" || role === "danger") return p.urgent || "" + if (role === "muted") return p.muted || "" + if (role === "selection") return p.selection || "" + if (role === "transparent") return "transparent" + if (/^#[0-9A-Fa-f]{3}$/.test(role) || /^#[0-9A-Fa-f]{6}$/.test(role)) return role + return "" +} + +// A theme's own shell.toml may point at another token ("hyprland.active-border") +// rather than state a colour. This follows that one hop — and only one kind of +// hop, a section.key that the same file defines — so a theme can describe its +// popup border in terms of the gradient it already states. +function followToken(value, shell) { + var s = String(value === undefined || value === null ? "" : value).replace(/^\s+|\s+$/g, "") + var seen = ({}) + while (/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(s) && !seen[s]) { + seen[s] = true + var next = shell[s] + if (next === undefined || next === null) break + s = String(next).replace(/^\s+|\s+$/g, "") + } + return s +} + +// A surface colour: the theme's token when it states one, the role it means, +// or `fallback` when the theme is silent. Gradients reduce to their first +// colour, which is what a single-colour surface can honour. +function surfaceColor(rawValue, shell, palette, fallback) { + var value = followToken(rawValue, shell) + var token = firstColorToken(value) + var colour = resolveToken(token, palette) + if (colour !== "") return colour + return resolveToken(fallback, palette) +} + +var CONTROL_DEFAULTS = { + normal: "foreground", + hover: "foreground", + focus: "foreground", + selected: "foreground", +} + +function controlKey(shell, key) { + var value = shell["controls." + key] + if (value === undefined || value === null || String(value) === "") value = shell["style." + key] + if (value === undefined || value === null) return "" + return String(value).replace(/^\s+|\s+$/g, "") +} + +function controlTokens(shell) { + var normal = { + color: controlKey(shell, "normal-color") || CONTROL_DEFAULTS.normal, + border: controlKey(shell, "normal-border"), + } + var hover = { + color: controlKey(shell, "hover-cursor-color") || CONTROL_DEFAULTS.hover, + border: controlKey(shell, "hover-cursor-border"), + } + var focus = { + color: controlKey(shell, "focus-color") || hover.color, + border: controlKey(shell, "focus-border"), + } + var selected = { + color: controlKey(shell, "selected-color") || CONTROL_DEFAULTS.selected, + border: controlKey(shell, "selected-border"), + } + var pressed = { + color: controlKey(shell, "pressed-color") || hover.color, + } + var selection = { + color: controlKey(shell, "selection-color") || CONTROL_DEFAULTS.selected, + } + // A border with no colour of its own follows the state's own colour, as the + // shell's own Border.controlSpec does. + if (normal.border === "") normal.border = normal.color + if (hover.border === "") hover.border = hover.color + if (focus.border === "") focus.border = focus.color + if (selected.border === "") selected.border = selected.color + return { normal: normal, hover: hover, focus: focus, selected: selected, + pressed: pressed, selection: selection } +} + +// A complete theme: the palette, the surfaces whose colour does not depend on +// a caller, and the control tokens a caller resolves with its own colours. +// +// Alphas, border widths, spacing, fonts and corner radius are not here on +// purpose. They come from the live Style — they are the user's shell-wide +// values, identical across the stock themes, and a window that changed them +// would stop matching the bar beside it. + +// A popup border. The theme's own shell.toml wins; without one, the stock +// template asks for the Hyprland active border, which colors.toml states as a +// gradient — a single-colour surface takes its first colour — and the accent is +// what the template falls back to when the theme states neither. +function popupBorder(shell, palette) { + if (shell["popups.border"] !== undefined) { + return surfaceColor(shell["popups.border"], shell, palette, "accent") + } + var override = palette && palette.hyprlandActiveBorder !== undefined + ? resolveToken(palette.hyprlandActiveBorder, palette) : "" + if (override !== "") return override + return resolveToken("accent", palette) +} + +function resolveTheme(palette, shellRaw) { + var colours = palette || parseColors("") + var shell = parseShell(shellRaw) + return { + palette: colours, + popups: { + background: surfaceColor(shell["popups.background"], shell, colours, "background"), + text: surfaceColor(shell["popups.text"], shell, colours, "foreground"), + border: popupBorder(shell, colours), + backgroundAlpha: parseNumber(shell["popups.background-alpha"], 1), + borderAlpha: parseNumber(shell["popups.border-alpha"], 1), + }, + tooltip: { + background: surfaceColor(shell["tooltip.background"], shell, colours, "background"), + text: surfaceColor(shell["tooltip.text"], shell, colours, "foreground"), + border: surfaceColor(shell["tooltip.border"], shell, colours, "foreground"), + backgroundAlpha: parseNumber(shell["tooltip.background-alpha"], 0.97), + }, + controls: controlTokens(shell), + } +} + +// Where a theme directory may live, most specific first. The user's own themes +// win over the installed ones, the same rule bin/omarchy-theme-dir applies. +// OMARCHY_PATH is often unset inside a plugin's environment, so the two +// installation paths follow it. +function themeRoots(home, omarchyPath) { + var h = String(home === undefined || home === null ? "" : home).replace(/\/+$/, "") + var base = String(omarchyPath === undefined || omarchyPath === null ? "" : omarchyPath) + .replace(/\/+$/, "") + var roots = [] + if (h !== "") roots.push(h + "/.config/omarchy/themes") + if (base !== "") roots.push(base + "/themes") + if (h !== "") roots.push(h + "/.local/share/omarchy/themes") + roots.push("/usr/share/omarchy/themes") + return roots +} + +// One list from the two roots: the user's copy of a name replaces the +// installed one, so picking "nord" picks the theme the user edited. Sorted by +// the name a person reads rather than by the directory spelling. +function mergeEntries(userEntries, systemEntries) { + var seen = ({}) + var out = [] + var roots = [userEntries || [], systemEntries || []] + for (var r = 0; r < roots.length; r++) { + var entries = roots[r] + for (var i = 0; i < entries.length; i++) { + var entry = entries[i] + var name = String(entry && entry.name !== undefined ? entry.name : "") + if (!validName(name) || seen[name]) continue + seen[name] = true + out.push({ + name: name, + label: displayName(name), + dir: String(entry.dir === undefined || entry.dir === null ? "" : entry.dir), + user: r === 0, + }) + } + } + out.sort(function(a, b) { + var left = a.label.toLowerCase() + var right = b.label.toLowerCase() + if (left === right) return 0 + return left < right ? -1 : 1 + }) + return out +} diff --git a/ui/theme/qmldir b/ui/theme/qmldir new file mode 100644 index 0000000..0a5f0f4 --- /dev/null +++ b/ui/theme/qmldir @@ -0,0 +1,3 @@ +singleton Paint 1.0 Paint.qml +ThemeCatalog 1.0 ThemeCatalog.qml +AppTheme 1.0 AppTheme.qml