From 9b50e8c0f77ddb61e1a8c96b3c492e3b7ae0ad56 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 11 Nov 2026 23:04:26 +0100 Subject: [PATCH 1/3] Read slide theme colors the way the window does The window accepted bare, single-quoted and annotated colors in a theme's colors.toml, but the slides and the colors recorded by choosing a theme only took double-quoted ones, so such a theme styled Hype's window and left the slides on the defaults. Both now read through one function. Co-Authored-By: Claude Opus 5.5 --- src/apptheme.cpp | 29 ++++++++++++++++++----------- src/apptheme.h | 5 +++++ src/deck.cpp | 27 +++++++-------------------- tests/tests.cpp | 18 ++++++++++++++++++ 4 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/apptheme.cpp b/src/apptheme.cpp index 8d61bc6..33b8c10 100644 --- a/src/apptheme.cpp +++ b/src/apptheme.cpp @@ -19,6 +19,21 @@ static QColor contrastInk(const QColor &color) { .0722 * linear(color.blueF()); return luminance > .179 ? QColor("#111111") : QColor("#ffffff"); } +QMap readThemeColors(const QString &path) { + QMap colors; + QFile file(path); + if (path.isEmpty() || !file.open(QIODevice::ReadOnly)) + return colors; + // Quoted or bare hex with an optional note. Quotes must pair; comments need no gap. + static const QRegularExpression entry( + R"re(^\s*([a-z_]+)\s*=\s*(["']?)(#[0-9a-fA-F]{6})\2\s*(?:#.*)?\s*$)re"); + while (!file.atEnd()) { + const auto match = entry.match(QString::fromUtf8(file.readLine())); + if (match.hasMatch()) + colors[match.captured(1)] = match.captured(3); + } + return colors; +} AppTheme::AppTheme(QObject *parent) : AppTheme(qEnvironmentVariable("XDG_STATE_HOME", QDir::homePath() + "/.local/state") + "/omarchy/current", @@ -35,17 +50,9 @@ AppTheme::AppTheme(const QString ¤tDirectory, QObject *parent) void AppTheme::reload() { const QString theme = m_currentDirectory + "/theme", path = theme + "/colors.toml"; QMap values; - QFile file(path); - if (file.open(QIODevice::ReadOnly)) { - // Quoted or bare hex with an optional note. Quotes must pair; comments need no gap. - const QRegularExpression entry( - R"re(^\s*([a-z_]+)\s*=\s*(["']?)(#[0-9a-fA-F]{6})\2\s*(?:#.*)?\s*$)re"); - while (!file.atEnd()) { - const auto match = entry.match(QString::fromUtf8(file.readLine())); - if (match.hasMatch()) - values[match.captured(1)] = QColor(match.captured(3)); - } - } + const auto written = readThemeColors(path); + for (auto it = written.begin(); it != written.end(); ++it) + values[it.key()] = QColor(it.value()); const QColor bg = values.value("background", QColor("#1a1b26")); const QColor fg = values.value("foreground", QColor("#c0caf5")); const QColor accent = values.value("accent", QColor("#7aa2f7")); diff --git a/src/apptheme.h b/src/apptheme.h index c5080eb..be78aff 100644 --- a/src/apptheme.h +++ b/src/apptheme.h @@ -1,9 +1,14 @@ #pragma once #include +#include #include #include #include +// The hex colors in an Omarchy colors.toml by key, as written, quoted or bare, +// with or without a trailing note. +QMap readThemeColors(const QString &path); + class AppTheme : public QObject { Q_OBJECT Q_PROPERTY(QVariantMap colors READ colors NOTIFY changed) diff --git a/src/deck.cpp b/src/deck.cpp index ce55a64..ff8f29e 100644 --- a/src/deck.cpp +++ b/src/deck.cpp @@ -1,4 +1,5 @@ #include "deck.h" +#include "apptheme.h" #include "budget.h" #include "animationexport.h" #include "filedialog.h" @@ -553,16 +554,9 @@ QVariantMap Deck::palette() const { {"background", "#1a1b26"}, {"foreground", "#c0caf5"}, {"accent", "#7aa2f7"}, {"green", "#9ece6a"}, {"red", "#f7768e"}, {"yellow", "#e0af68"}, {"magenta", "#bb9af7"}, {"cyan", "#7dcfff"}, {"dark_foreground", "#787c99"}}; - QFile f(m_themes.value(themeName())); - if (f.open(QIODevice::ReadOnly)) { - QRegularExpression re("^([a-z_]+)\\s*=\\s*\"(#[0-9a-fA-F]{6})\"", - QRegularExpression::MultilineOption); - auto matches = re.globalMatch(QString::fromUtf8(f.readAll())); - while (matches.hasNext()) { - auto m = matches.next(); - colors[m.captured(1)] = m.captured(2); - } - } + const auto installed = readThemeColors(m_themes.value(themeName())); + for (auto it = installed.begin(); it != installed.end(); ++it) + colors[it.key()] = it.value(); for (const auto &key : colors.keys()) { QString v = scalar(m_parsed.header, "color_" + key); if (QColor(v).isValid()) @@ -581,16 +575,9 @@ void Deck::chooseTheme(const QString &name) { // Remove old palette before reading the newly selected installed theme. header.remove( QRegularExpression("^color_[a-z_]+:[^\\n]*\\n", QRegularExpression::MultilineOption)); - QFile file(m_themes.value(name)); - if (file.open(QIODevice::ReadOnly)) { - QRegularExpression re("^([a-z_]+)\\s*=\\s*\"(#[0-9a-fA-F]{6})\"", - QRegularExpression::MultilineOption); - auto matches = re.globalMatch(QString::fromUtf8(file.readAll())); - while (matches.hasNext()) { - auto m = matches.next(); - header = setScalar(header, "color_" + m.captured(1), m.captured(2)); - } - } + const auto installed = readThemeColors(m_themes.value(name)); + for (auto it = installed.begin(); it != installed.end(); ++it) + header = setScalar(header, "color_" + it.key(), it.value()); replaceHeader(header); } QStringList Deck::mediaPositions() const { return ::mediaPositions(); } diff --git a/tests/tests.cpp b/tests/tests.cpp index 15ece15..894f542 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -204,6 +204,24 @@ static void write(const QString &path, const QString &content) { qPrintable(value)); } } + void slidesReadThemeColorFormats() { + QTemporaryDir omarchy; + const QByteArray previous = qgetenv("OMARCHY_PATH"); + const auto restore = qScopeGuard([&] { qputenv("OMARCHY_PATH", previous); }); + qputenv("OMARCHY_PATH", omarchy.path().toUtf8()); + QVERIFY(QDir().mkpath(omarchy.filePath("themes/hype-formats"))); + write(omarchy.filePath("themes/hype-formats/colors.toml"), + "background = #101020\nforeground = '#eeeeee' # note\naccent = \"#7788ff\"\n"); + Deck named; + named.editSource("---\ntheme: hype-formats\n---\n\n# One\n"); + QCOMPARE(named.background(), QColor("#101020")); + QCOMPARE(named.foreground(), QColor("#eeeeee")); + Deck chosen; + chosen.chooseTheme("hype-formats"); + QVERIFY(chosen.source().contains("color_background: \"#101020\"")); + QVERIFY(chosen.source().contains("color_foreground: \"#eeeeee\"")); + QCOMPARE(chosen.accent(), QColor("#7788ff")); + } void followsDesktopTheme() { QTemporaryDir files; const QString current = files.path() + "/current"; From 3c03f9c44d3bb1c424b87a721f6c7dd447c670c7 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:05:13 +0100 Subject: [PATCH 2/3] Unset OMARCHY_PATH after the theme test when it was unset before Restoring it as an empty string would point later tests at /themes. Co-Authored-By: Claude Opus 5.5 --- tests/tests.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/tests.cpp b/tests/tests.cpp index 894f542..13c7bb5 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -206,8 +206,12 @@ static void write(const QString &path, const QString &content) { } void slidesReadThemeColorFormats() { QTemporaryDir omarchy; + const bool wasSet = qEnvironmentVariableIsSet("OMARCHY_PATH"); const QByteArray previous = qgetenv("OMARCHY_PATH"); - const auto restore = qScopeGuard([&] { qputenv("OMARCHY_PATH", previous); }); + const auto restore = qScopeGuard([&] { + if (wasSet) qputenv("OMARCHY_PATH", previous); + else qunsetenv("OMARCHY_PATH"); + }); qputenv("OMARCHY_PATH", omarchy.path().toUtf8()); QVERIFY(QDir().mkpath(omarchy.filePath("themes/hype-formats"))); write(omarchy.filePath("themes/hype-formats/colors.toml"), From 058588504ae1b28697de2be8b36c51edeb5dc7c6 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:20:04 +0100 Subject: [PATCH 3/3] Record a chosen theme's colors in the order the theme lists them A map sorted them by name, which reordered every color line in the front matter on a theme change. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex --- src/apptheme.cpp | 11 +++++------ src/apptheme.h | 9 +++++---- src/deck.cpp | 10 ++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/apptheme.cpp b/src/apptheme.cpp index 33b8c10..4222510 100644 --- a/src/apptheme.cpp +++ b/src/apptheme.cpp @@ -19,8 +19,8 @@ static QColor contrastInk(const QColor &color) { .0722 * linear(color.blueF()); return luminance > .179 ? QColor("#111111") : QColor("#ffffff"); } -QMap readThemeColors(const QString &path) { - QMap colors; +QList> readThemeColors(const QString &path) { + QList> colors; QFile file(path); if (path.isEmpty() || !file.open(QIODevice::ReadOnly)) return colors; @@ -30,7 +30,7 @@ QMap readThemeColors(const QString &path) { while (!file.atEnd()) { const auto match = entry.match(QString::fromUtf8(file.readLine())); if (match.hasMatch()) - colors[match.captured(1)] = match.captured(3); + colors.append({match.captured(1), match.captured(3)}); } return colors; } @@ -50,9 +50,8 @@ AppTheme::AppTheme(const QString ¤tDirectory, QObject *parent) void AppTheme::reload() { const QString theme = m_currentDirectory + "/theme", path = theme + "/colors.toml"; QMap values; - const auto written = readThemeColors(path); - for (auto it = written.begin(); it != written.end(); ++it) - values[it.key()] = QColor(it.value()); + for (const auto &[key, value] : readThemeColors(path)) + values[key] = QColor(value); const QColor bg = values.value("background", QColor("#1a1b26")); const QColor fg = values.value("foreground", QColor("#c0caf5")); const QColor accent = values.value("accent", QColor("#7aa2f7")); diff --git a/src/apptheme.h b/src/apptheme.h index be78aff..5b4e517 100644 --- a/src/apptheme.h +++ b/src/apptheme.h @@ -1,13 +1,14 @@ #pragma once #include -#include +#include #include +#include #include #include -// The hex colors in an Omarchy colors.toml by key, as written, quoted or bare, -// with or without a trailing note. -QMap readThemeColors(const QString &path); +// The hex colors in an Omarchy colors.toml in file order, as written, quoted +// or bare, with or without a trailing note. +QList> readThemeColors(const QString &path); class AppTheme : public QObject { Q_OBJECT diff --git a/src/deck.cpp b/src/deck.cpp index ff8f29e..79daf5c 100644 --- a/src/deck.cpp +++ b/src/deck.cpp @@ -554,9 +554,8 @@ QVariantMap Deck::palette() const { {"background", "#1a1b26"}, {"foreground", "#c0caf5"}, {"accent", "#7aa2f7"}, {"green", "#9ece6a"}, {"red", "#f7768e"}, {"yellow", "#e0af68"}, {"magenta", "#bb9af7"}, {"cyan", "#7dcfff"}, {"dark_foreground", "#787c99"}}; - const auto installed = readThemeColors(m_themes.value(themeName())); - for (auto it = installed.begin(); it != installed.end(); ++it) - colors[it.key()] = it.value(); + for (const auto &[key, value] : readThemeColors(m_themes.value(themeName()))) + colors[key] = value; for (const auto &key : colors.keys()) { QString v = scalar(m_parsed.header, "color_" + key); if (QColor(v).isValid()) @@ -575,9 +574,8 @@ void Deck::chooseTheme(const QString &name) { // Remove old palette before reading the newly selected installed theme. header.remove( QRegularExpression("^color_[a-z_]+:[^\\n]*\\n", QRegularExpression::MultilineOption)); - const auto installed = readThemeColors(m_themes.value(name)); - for (auto it = installed.begin(); it != installed.end(); ++it) - header = setScalar(header, "color_" + it.key(), it.value()); + for (const auto &[key, value] : readThemeColors(m_themes.value(name))) + header = setScalar(header, "color_" + key, value); replaceHeader(header); } QStringList Deck::mediaPositions() const { return ::mediaPositions(); }