Something went wrong. Try again.
Bring Windows XP themes to your KDE Plasma environment! xplasma.hotsocket.fyi
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570// SPDX-License-Identifier: GPL-3.0-or-later// Unit tests for the core's parsing and lookup rules. No test framework:// each CHECK prints on failure and the exit code counts failures.#include "core/classic.h"#include "core/ini.h"#include "core/pe.h"#include "core/render.h"#include "core/schema.h"#include "core/theme.h"#include "core/themefile.h"#include "core/window.h"
#include <limits> // before QtEndian (Qt 5.15.2)
#include <QDir>#include <QElapsedTimer>#include <QFile>#include <QFileInfo>#include <QTextStream>#include <QtEndian>
#include "core/dib.h"#include "core/cursors.h"#include "core/icons.h"
using namespace xpl;
static int failures = 0;#define CHECK(cond) \ do { \ if (!(cond)) { \ ++failures; \ QTextStream(stderr) << "FAIL " << __LINE__ << ": " << #cond << '\n'; \ } \ } while (0)
static QString get(const Ini &ini, const char *sub, const char *cls, const char *part, const char *state, const char *prop){ return ini.lookup(QString::fromLatin1(sub), QString::fromLatin1(cls), QString::fromLatin1(part), QString::fromLatin1(state), QString::fromLatin1(prop)) .value_or(QStringLiteral("<none>"));}
// Test vectors live in tests/core/vectors; build trees sit in build/<mode>-qt<N>/.static QString vectors;
int main(int, char **argv){ vectors = QFileInfo(QString::fromLocal8Bit(argv[0])).absolutePath() + QLatin1String("/../../tests/core/vectors");
// Headers: every piece but the class is optional; a trailing state // belongs to the part, or to the class when there's no part. CHECK(Ini::parseHeader(QStringLiteral("Button")).toString() == QLatin1String("button")); CHECK(Ini::parseHeader(QStringLiteral("Button.PushButton(Hot)")).toString() == QLatin1String("button.pushbutton(hot)")); CHECK(Ini::parseHeader(QStringLiteral("ComboBox(Disabled)")).toString() == QLatin1String("combobox(disabled)")); CHECK(Ini::parseHeader(QStringLiteral("ComboBox(Disabled)")).cls == QLatin1String("combobox")); CHECK(Ini::parseHeader(QStringLiteral("ComboBox(Disabled)")).state == QLatin1String("disabled")); CHECK(Ini::parseHeader(QStringLiteral("TaskBand::Toolbar.Button")).sub == QLatin1String("taskband")); CHECK(Ini::parseHeader(QStringLiteral("TaskBand::Toolbar.Button")).cls == QLatin1String("toolbar")); CHECK(Ini::parseHeader(QStringLiteral(" Start::Button ")).toString() == QLatin1String("start::button"));
const Ini ini = Ini::parseText(QStringLiteral( "; comment\n" "[Globals]\nTextColor=1 1 1\nFont=Tahoma, 8\n" "[Button]\nBorderSize=2\n" "[Button.PushButton]\nTextColor=2 2 2 ; inline comment\nImageCount = 5\n" "[Button.PushButton(Disabled)]\nTextColor=3 3 3\n" "[Button(Disabled)]\nFillColor=9 9 9\n" "[Media::Button.PushButton]\nImageFile=Media\\Button.bmp\n" "[Button.PushButton]\nImageCount=6\n" // duplicate section: merges, last key wins "[Rebar.Band]; a header with a comment is still a header\nImageFile=Band.bmp\n" "[Start::Button]\nImageFile=Start.bmp\n"));
CHECK(get(ini, "", "Button", "PushButton", "", "textcolor") == QLatin1String("2 2 2")); CHECK(get(ini, "", "Button", "PushButton", "", "imagecount") == QLatin1String("6")); CHECK(get(ini, "", "Button", "PushButton", "Disabled", "textcolor") == QLatin1String("3 3 3")); // (part, 0) before (0, 0): Hot has no section of its own. CHECK(get(ini, "", "Button", "PushButton", "Hot", "textcolor") == QLatin1String("2 2 2")); // (0, 0): the class section. CHECK(get(ini, "", "Button", "PushButton", "", "bordersize") == QLatin1String("2")); // Globals end the override chain. CHECK(get(ini, "", "Button", "PushButton", "", "font") == QLatin1String("Tahoma, 8")); CHECK(get(ini, "", "Edit", "", "", "textcolor") == QLatin1String("1 1 1")); // A class-level state section is (0, state): not consulted for a real part. CHECK(get(ini, "", "Button", "PushButton", "Disabled", "fillcolor") == QLatin1String("<none>")); CHECK(get(ini, "", "Button", "", "Disabled", "fillcolor") == QLatin1String("9 9 9")); // Sub::Class overrides Class, which still supplies the rest. CHECK(get(ini, "Media", "Button", "PushButton", "", "imagefile") == QLatin1String("Media\\Button.bmp")); CHECK(get(ini, "Media", "Button", "PushButton", "", "imagecount") == QLatin1String("6")); CHECK(get(ini, "", "Button", "PushButton", "", "imagefile") == QLatin1String("<none>")); // ...and all of a Sub::Class comes first, its class-level section too: // XP draws Start::Button's push button from [Start::Button]. CHECK(get(ini, "Start", "Button", "PushButton", "Hot", "imagefile") == QLatin1String("Start.bmp")); CHECK(get(ini, "Start", "Button", "PushButton", "", "imagecount") == QLatin1String("6")); // A commented header still opens its own section. CHECK(get(ini, "", "Rebar", "Band", "", "imagefile") == QLatin1String("Band.bmp")); CHECK(get(ini, "", "Button", "PushButton", "", "imagefile") == QLatin1String("<none>"));
// Lookups are case-insensitive. CHECK(get(ini, "MEDIA", "button", "PUSHBUTTON", "", "ImageFile") == QLatin1String("Media\\Button.bmp"));
CHECK(Theme::resourceName(QStringLiteral("Royale\\FrameCaption.bmp")) == QLatin1String("ROYALE_FRAMECAPTION_BMP"));
// Garbage never crashes the PE reader. QString error; CHECK(!PeResources::parse(QByteArray("MZ"), &error)); QByteArray junk(4096, '\xff'); junk[0] = 'M'; junk[1] = 'Z'; CHECK(!PeResources::parse(junk, &error)); CHECK(!Theme::fromData(QByteArray(), QString(), &error));
// XP's schema (tmschema.h): names to numbers and back. CHECK(schema::partId(u"Button", u"PushButton") == 1); CHECK(schema::stateId(u"Button", u"PushButton", u"Defaulted") == 5); CHECK(schema::stateId(u"button", u"checkbox", u"MixedDisabled") == 12); CHECK(schema::stateId(u"Scrollbar", u"ArrowBtn", u"RightDisabled") == 16); CHECK(schema::partId(u"Tab", u"Body") == 10); CHECK(schema::partId(u"Window", u"CloseButton") == 18); CHECK(schema::partId(u"Button", u"PushButon") == 0); // typo: unknown CHECK(schema::stateId(u"Button", u"PushButton", u"Hover") == 0); CHECK(schema::partName(u"Toolbar", 4) == QLatin1String("splitbuttondropdown")); CHECK(schema::stateName(u"Tab", u"TabItem", 3) == QLatin1String("selected"));
// A tiny RLE file claiming a gigantic image is refused, not decoded // (found by fuzz-dib: 217 bytes claiming 26886 x 8229 took 11 s). { QFile vector(vectors + QLatin1String("/dib-huge-rle4.bin")); CHECK(vector.open(QIODevice::ReadOnly)); QElapsedTimer timer; timer.start(); CHECK(decodeDib(vector.readAll()).image.isNull()); CHECK(timer.elapsed() < 100); }
// .theme files: XP's ANSI with CRLF, UTF-16 with a BOM, UTF-8; sections // and keys case-insensitive, the last duplicate winning. { const ThemeFile t = ThemeFile::fromBytes("; comment\r\n[Theme]\r\nDisplayName=Caf\xe9 \x80\r\n" "[VisualStyles]\r\nPath=%ResourceDir%\\Themes\\x.msstyles\r\n" "ColorStyle=NormalColor\r\n[visualstyles]\r\ncolorstyle=Metallic\r\n" "junk line\r\n=nokey\r\n"); CHECK(t.value(u"THEME", u"displayname") == QString::fromUtf8("Caf\xc3\xa9 \xe2\x82\xac")); CHECK(t.value(u"VisualStyles", u"ColorStyle") == QLatin1String("Metallic")); CHECK(t.value(u"VisualStyles", u"Path") == QLatin1String("%ResourceDir%\\Themes\\x.msstyles")); CHECK(t.sections() == QStringList({QStringLiteral("Theme"), QStringLiteral("VisualStyles")})); CHECK(!t.contains(u"VisualStyles", u"Size") && t.value(u"Nope", u"x").isEmpty()); // Written back as XP would, and read back the same. CHECK(t.toBytes().startsWith("[Theme]\r\nDisplayName=Caf\xe9 \x80\r\n")); CHECK(ThemeFile::fromBytes(t.toBytes()).value(u"theme", u"displayname") == t.value(u"theme", u"displayname"));
QByteArray utf16("\xff\xfe"); for (const char c : QByteArray("[Theme]\r\nDisplayName=Zune\r\n")) utf16 += QByteArray(1, c) + QByteArray(1, '\0'); CHECK(ThemeFile::fromBytes(utf16).value(u"Theme", u"DisplayName") == QLatin1String("Zune")); CHECK(ThemeFile::fromBytes("[Theme]\nDisplayName=\xe2\x84\xa2\n").value(u"Theme", u"DisplayName") == QString(QChar(0x2122)));
// A value outside Windows-1252 makes the file UTF-16. ThemeFile u; u.setValue(u"Theme", u"DisplayName", QString(QChar(0x3042))); CHECK(u.toBytes().startsWith("\xff\xfe")); CHECK(ThemeFile::fromBytes(u.toBytes()).value(u"Theme", u"DisplayName") == QString(QChar(0x3042))); u.remove(u"theme", u"displayname"); CHECK(!u.contains(u"Theme", u"DisplayName")); u.removeSection(u"THEME"); CHECK(u.sections().isEmpty()); }
// Windows Classic schemes: colours by either spelling, the metrics and // fonts through NONCLIENTMETRICSA / ICONMETRICSA and back. { const ClassicScheme standard; CHECK(standard.colour(u"ButtonFace") == QColor(212, 208, 200)); CHECK(standard.colour(u"btnface") == QColor(212, 208, 200)); CHECK(standard.colour(u"GRADIENTACTIVECAPTION") == QColor(166, 202, 240)); CHECK(ClassicScheme::colourIndex(u"hottracking") == 26 && ClassicScheme::colourIndex(u"nope") == -1); CHECK(standard.metrics.captionFont.points() == 8 && standard.metrics.captionFont.bold());
ClassicScheme s; s.setColour(u"Background", QColor(1, 2, 3)); s.metrics.borderWidth = 3; s.metrics.captionHeight = 25; s.metrics.menuFont = LogFont::fromPoints(QStringLiteral("Microsoft Sans Serif"), 10); s.metrics.captionFont.italic = true; s.icons.horzSpacing = 43; ThemeFile file; s.writeTo(file); CHECK(file.value(u"Control Panel\\Colors", u"Background") == QLatin1String("1 2 3")); const QByteArray ncm = bytesFromDecimal(file.value(u"Metrics", u"NonclientMetrics")); CHECK(ncm.size() == 340 && ncm[0] == char(84) && ncm[1] == char(1) && ncm[4] == 3); CHECK(QByteArray(ncm.constData() + 160 + 28) == "Microsoft Sans Serif"); ClassicScheme back = ClassicScheme::fromThemeFile(ThemeFile::fromBytes(file.toBytes())); back.name = s.name; CHECK(back == s); CHECK(back.metrics.menuFont.points() == 10);
// A .theme with only some colours keeps Windows Standard's for the rest; // truncated or absurd metrics are ignored, not trusted. const ClassicScheme partial = ClassicScheme::fromThemeFile(ThemeFile::fromBytes( "[Control Panel\\Colors]\nWindow=9 9 9\nMenu=1 2\nBogus=1 1 1\n[Metrics]\nNonclientMetrics=84 1 0 0 1\n")); CHECK(partial.colour(u"Window") == QColor(9, 9, 9)); CHECK(partial.colour(u"Menu") == standard.colour(u"Menu")); CHECK(partial.metrics == standard.metrics); QByteArray absurd = ncm; absurd[20] = char(0xff); absurd[21] = char(0xff); // caption height 65535 CHECK(!NonClientMetrics::fromA(absurd)); CHECK(!ClassicScheme::fromSchemeData(QByteArray(100, '\0'))); }
// Icons: a 4bpp DIB with its AND mask, twice its height; a 32bpp one // with alpha (the mask ignored); PNG; garbage. { auto le32 = [](QByteArray &b, int v) { for (int i = 0; i < 4; ++i) b.append(char((v >> (8 * i)) & 0xff)); }; auto le16 = [](QByteArray &b, int v) { b.append(char(v & 0xff)); b.append(char(v >> 8)); }; auto header = [&](int size, int bpp) { QByteArray h; le32(h, 40); le32(h, size); le32(h, size * 2); le16(h, 1); le16(h, bpp); le32(h, 0); le32(h, 0); le32(h, 0); le32(h, 0); le32(h, 0); le32(h, 0); return h; }; // 4bpp 8x8: palette index 1 (red) everywhere, the mask's top-left // pixel set (transparent). Rows are bottom-up, 4-byte aligned. QByteArray four = header(8, 4); for (int i = 0; i < 16; ++i) le32(four, i == 1 ? 0x00ff0000 : 0); for (int y = 0; y < 8; ++y) le32(four, 0x11111111); for (int y = 0; y < 8; ++y) le32(four, y == 7 ? 0x80 : 0); // bottom-up: the last row is the top const QImage a = decodeIconImage(four); CHECK(a.size() == QSize(8, 8)); CHECK(a.pixel(0, 0) == 0); CHECK(a.pixel(1, 0) == qRgb(255, 0, 0)); CHECK(a.pixel(7, 7) == qRgb(255, 0, 0)); QByteArray argb = header(2, 32); for (int i = 0; i < 4; ++i) le32(argb, int(0x80102030u)); le32(argb, 0); le32(argb, 0); // mask const QImage b = decodeIconImage(argb); CHECK(b.size() == QSize(2, 2) && qAlpha(b.pixel(0, 0)) == 0x80); CHECK(decodeIconImage(QByteArray(30, 'x')).isNull()); QByteArray huge = header(8, 4); huge.truncate(40); CHECK(decodeIconImage(huge).isNull()); // claims pixels it doesn't have
// Cursors. A 1bpp 8x8 DIB: black (index 0) everywhere, index 1 // (white) in the top row; the mask set in the top-left 2x2 -- over // white that inverts the screen (black, for a cursor; gone, for an // icon), over black it's transparent. auto mono = [&] { QByteArray d = header(8, 1); le32(d, 0); le32(d, 0x00ffffff); for (int y = 0; y < 8; ++y) le32(d, y == 7 ? 0xff : 0); // bottom-up: the top row is last for (int y = 0; y < 8; ++y) le32(d, y >= 6 ? 0xc0 : 0); return d; }(); CHECK(decodeMaskedImage(mono, true).pixel(0, 0) == qRgb(0, 0, 0)); CHECK(decodeMaskedImage(mono, false).pixel(0, 0) == 0); CHECK(decodeMaskedImage(mono, true).pixel(0, 1) == 0); CHECK(decodeMaskedImage(mono, true).pixel(5, 0) == qRgb(255, 255, 255)); // A .cur holding it, hotspot (3, 4); an .ani of it twice, the second // step at 12 jiffies (200 ms), played in reverse by its "seq ". QByteArray cur; le16(cur, 0); le16(cur, 2); le16(cur, 1); cur.append(char(8)); cur.append(char(8)); cur.append(char(0)); cur.append(char(0)); le16(cur, 3); le16(cur, 4); le32(cur, int(mono.size())); le32(cur, 22); cur += mono; const auto f = decodeCursorFile(cur); CHECK(f && f->image.size() == QSize(8, 8) && f->hotspot == QPoint(3, 4)); auto chunk = [&](const char *id, const QByteArray &body) { QByteArray c(id, 4); le32(c, int(body.size())); c += body; if (body.size() % 2) c.append('\0'); return c; }; QByteArray anih; for (int v : {36, 2, 2, 8, 8, 1, 1, 6, 1}) le32(anih, v); QByteArray rate, seq; le32(rate, 6); le32(rate, 12); le32(seq, 1); le32(seq, 0); QByteArray second = cur; second[10] = 7; // hotspot x 7 const QByteArray body = "ACON" + chunk("anih", anih) + chunk("rate", rate) + chunk("seq ", seq) + chunk("LIST", "fram" + chunk("icon", cur) + chunk("icon", second)); QByteArray ani = "RIFF"; le32(ani, int(body.size())); ani += body; const QList<CursorFrame> frames = decodeCursor(ani); CHECK(frames.size() == 2); CHECK(frames.size() == 2 && frames.at(0).hotspot.x() == 7 && frames.at(0).delayMs == 100); CHECK(frames.size() == 2 && frames.at(1).hotspot.x() == 3 && frames.at(1).delayMs == 200); CHECK(decodeCursor("RIFF\x04\0\0\0ACON").isEmpty()); // Xcursor: header, a TOC entry per frame, then each image chunk. const QByteArray xc = xcursor(frames, 32); CHECK(xc.startsWith("Xcur")); CHECK(xc.size() == 16 + 2 * 12 + 2 * (36 + 8 * 8 * 4)); CHECK(qFromLittleEndian<quint32>(xc.constData() + 12) == 2); const qsizetype first = qFromLittleEndian<quint32>(xc.constData() + 16 + 8); CHECK(qFromLittleEndian<quint32>(xc.constData() + first + 24) == 7); // xhot CHECK(qFromLittleEndian<quint32>(xc.constData() + first + 32) == 100); // delay }
// Tints: the form xplasmarc keeps, and the LCh mapping. { CHECK(Tint().isIdentity()); const auto t = Tint::parse(QStringLiteral(" 50, 1.5 ,-10")); CHECK(t && t->hue == 50 && t->chroma == 1.5 && t->lightness == -10); CHECK(Tint::parse(t->toString()) == t); CHECK(!Tint::parse(QStringLiteral("50,1"))); CHECK(!Tint::parse(QStringLiteral("a,b,c"))); const auto wild = Tint::parse(QStringLiteral("400,9,-99")); // (clamped) CHECK(wild && wild->hue == 180 && wild->chroma == 2 && wild->lightness == -50); auto near = [](QRgb a, QRgb b) { return qAbs(qRed(a) - qRed(b)) <= 1 && qAbs(qGreen(a) - qGreen(b)) <= 1 && qAbs(qBlue(a) - qBlue(b)) <= 1; }; const QRgb lunaBlue = qRgb(0, 84, 227); CHECK(near(Tinter(Tint()).apply(lunaBlue), lunaBlue)); // Greys stay grey and as light, whatever the tint (no colour to turn, // and lightness moves only with colourfulness). Tint strong; strong.hue = 90; strong.chroma = 1.8; strong.lightness = 30; for (QRgb grey : {qRgb(0, 0, 0), qRgb(64, 64, 64), qRgb(128, 128, 128), qRgb(255, 255, 255)}) CHECK(near(Tinter(strong).apply(grey), grey)); // Alpha kept; a turned blue is no longer blue-dominant. Tint turn; turn.hue = 120; const QRgb turned = Tinter(turn).apply(qRgba(0, 84, 227, 77)); CHECK(qAlpha(turned) == 77); CHECK(qBlue(turned) < qRed(turned)); // No colour: a colourfulness of 0 is grey. Tint none; none.chroma = 0; const QRgb flat = Tinter(none).apply(lunaBlue); CHECK(qAbs(qRed(flat) - qGreen(flat)) <= 2 && qAbs(qGreen(flat) - qBlue(flat)) <= 2); // Colour keys untouched in an image. QImage img(2, 1, QImage::Format_ARGB32); img.setPixel(0, 0, qRgb(255, 0, 255)); img.setPixel(1, 0, lunaBlue); Tinter(turn).apply(img, {0x00ff00ffu}); CHECK(img.pixel(0, 0) == qRgb(255, 0, 255)); CHECK(img.pixel(1, 0) != lunaBlue); }
// LCh round trips, and the tint taking one colour to another. { auto close = [](QRgb a, QRgb b, int d) { return qAbs(qRed(a) - qRed(b)) <= d && qAbs(qGreen(a) - qGreen(b)) <= d && qAbs(qBlue(a) - qBlue(b)) <= d; }; for (QRgb c : {qRgb(0, 84, 227), qRgb(74, 153, 73), qRgb(200, 30, 40), qRgb(128, 128, 128), qRgb(255, 255, 255)}) CHECK(close(fromLch(toLch(c)), c, 1)); const Lch beyond{60, 400, 30}; // (no sRGB is that colourful: chroma gives) const Lch kept = toLch(fromLch(beyond)); CHECK(qAbs(kept.l - 60) < 1.5 && qAbs(kept.h - 30) < 3 && kept.c < 400); for (const auto &[from, to] : {std::pair{qRgb(0, 84, 227), qRgb(200, 30, 40)}, std::pair{qRgb(0, 84, 227), qRgb(90, 160, 60)}, std::pair{qRgb(74, 153, 73), qRgb(120, 60, 170)}}) CHECK(close(Tinter(Tint::toward(from, to)).apply(from), to, 3)); CHECK(Tint::toward(qRgb(128, 128, 128), qRgb(200, 30, 40)).hue == 0); // (a grey has no hue to turn) // ...so a near-grey one has the colour laid over: it reaches it; white and black keep. for (const auto &[from, to] : {std::pair{qRgb(128, 128, 128), qRgb(224, 96, 122)}, std::pair{qRgb(65, 76, 90), qRgb(224, 96, 122)}, std::pair{qRgb(196, 197, 210), qRgb(90, 160, 60)}}) { const Tinter laid(Tint::toward(from, to)); CHECK(close(laid.apply(from), to, 4)); CHECK(laid.apply(qRgb(255, 255, 255)) == qRgb(255, 255, 255) && laid.apply(qRgb(0, 0, 0)) == qRgb(0, 0, 0)); } { // Darker, the art's shading keeps its shape: Luna Silver's caption // to a dark teal, a deeper shade of it doesn't sink to black. const Tinter teal(Tint::toward(qRgb(196, 197, 210), qRgb(0, 109, 128))); CHECK(close(teal.apply(qRgb(196, 197, 210)), qRgb(0, 109, 128), 4)); CHECK(toLch(teal.apply(qRgb(140, 141, 152))).l > 25); CHECK(teal.tint().lscale < 1 && TintSpec::parse(QStringLiteral("x: ls=0.5"))->rules.first().tint.lscale == 0.5); } { const auto laid = TintSpec::parse(QStringLiteral("window: h=0 c=1 l=5 a=40 b=-12.5")); CHECK(laid && laid->rules.first().tint.a == 40 && laid->rules.first().tint.b == -12.5); CHECK(laid && TintSpec::parse(laid->toString()) == laid); } }
// Tint specs: rules by section, the most specific winning. { const auto legacy = TintSpec::parse(QStringLiteral("50,1,0")); CHECK(legacy && legacy->base().hue == 50); CHECK(legacy && legacy->forSection(u"start", u"button", u"", u"").first.isIdentity()); CHECK(legacy && legacy->forSection(u"", u"window", u"closebutton", u"hot").first.isIdentity()); CHECK(legacy && legacy->forSection(u"", u"window", u"caption", u"").first.hue == 50); const auto spec = TintSpec::parse( QStringLiteral("*: h=50 c=1 l=0; window: h=10; window.caption(active): h=-30 c=1.5 future=7 wobble; start::button: keep")); CHECK(spec && spec->rules.size() == 4); CHECK(spec && spec->forSection(u"", u"button", u"pushbutton", u"").first.hue == 50); CHECK(spec && spec->forSection(u"", u"window", u"frameleft", u"").first.hue == 10); CHECK(spec && spec->forSection(u"", u"window", u"caption", u"active").first.hue == -30); CHECK(spec && spec->forSection(u"", u"window", u"caption", u"active").first.chroma == 1.5); CHECK(spec && spec->forSection(u"start", u"button", u"", u"").first.isIdentity()); // XP's signal colours keep under a broader rule; a rule naming them turns them. const auto taskbar = TintSpec::parse(QStringLiteral("startpanel: h=80; window.caption: h=80")); CHECK(taskbar && taskbar->forSection(u"", u"startpanel", u"proglist", u"").first.hue == 80); CHECK(taskbar && taskbar->forSection(u"", u"startpanel", u"logoffbuttons", u"").first.isIdentity()); CHECK(taskbar && taskbar->forSection(u"", u"startpanel", u"moreprogramsarrow", u"").first.isIdentity()); CHECK(taskbar && taskbar->forSection(u"", u"window", u"closebutton", u"").first.isIdentity()); const auto named = TintSpec::parse(QStringLiteral("startpanel: h=80; startpanel.logoffbuttons: h=40")); CHECK(named && named->forSection(u"", u"startpanel", u"logoffbuttons", u"").first.hue == 40); CHECK(spec && TintSpec::parse(spec->toString()) == spec); CHECK(spec && spec->withBase(Tint()).forSection(u"", u"button", u"", u"").first.isIdentity()); CHECK(spec && spec->withBase(Tint()).forSection(u"", u"window", u"frameleft", u"").first.hue == 10); CHECK(TintSpec::parse(QString()) && TintSpec::parse(QString())->isIdentity()); CHECK(!TintSpec::parse(QStringLiteral("nonsense"))); }
// A tinted style (Luna, where Setup imported it): colours moved, fonts // not, the Start and Close buttons' art kept, colour keys exact. const QString luna = QDir::homePath() + QLatin1String("/.local/share/xplasma/Windows/Themes/Luna/luna.msstyles"); if (const auto base = QFileInfo::exists(luna) ? Theme::load(luna, QStringLiteral("NORMALBLUE_INI")) : nullptr) { Tint turn; turn.hue = 120; CHECK(Theme::tinted(base, Tint()) == base); const auto tinted = Theme::tinted(base, turn); CHECK(tinted->tint() == TintSpec::uniform(turn)); auto sys = [](const Theme &t, const char *name) { return t.property(u"sysmetrics", u"", u"", QString::fromLatin1(name)).value_or(QString()); }; CHECK(sys(*tinted, "activecaption") != sys(*base, "activecaption")); CHECK(sys(*tinted, "captionfont") == sys(*base, "captionfont")); auto prop = [](const Theme &t, const char *sub, const char *cls, const char *part, const char *name) { return t.property(QString::fromLatin1(cls), QString::fromLatin1(part), u"", QString::fromLatin1(name), QString::fromLatin1(sub)).value_or(QString()); }; CHECK(prop(*tinted, "start", "button", "", "fillcolorhint") == prop(*base, "start", "button", "", "fillcolorhint")); // The art, as the renderer cuts it frame by frame. const PartRef caption{QStringLiteral("window"), schema::partId(u"window", u"caption"), 1, {}}; const PartRef inactive{QStringLiteral("window"), caption.part, 2, {}}; const PartRef close{QStringLiteral("window"), schema::partId(u"window", u"closebutton"), 1, {}}; const PartRef push{QStringLiteral("button"), 1, 1, {}}; auto frameOf = [](const std::shared_ptr<const Theme> &t, const PartRef &ref) { return Renderer(t).stateImage(ref); }; // The close button keeps its red, every opaque pixel of it; only its // corners, the caption's blue let through, turn with the caption. { const QImage before = frameOf(base, close), after = frameOf(tinted, close); bool redKept = !before.isNull() && before.size() == after.size(), cornersTurn = false; for (int y = 0; redKept && y < before.height(); ++y) for (int x = 0; x < before.width(); ++x) { if (qAlpha(before.pixel(x, y)) == 255) redKept = redKept && before.pixel(x, y) == after.pixel(x, y); else cornersTurn = cornersTurn || before.pixel(x, y) != after.pixel(x, y); } CHECK(redKept); CHECK(cornersTurn); } CHECK(!frameOf(base, caption).isNull() && frameOf(tinted, caption) != frameOf(base, caption)); // The Start button's end, in the taskbar's blue, turns with the bar; its green doesn't. { const auto bar = Theme::tinted(base, *TintSpec::parse(QStringLiteral("taskbar: h=120"))); const PartRef start{QStringLiteral("button"), schema::partId(u"button", u"pushbutton"), 1, QStringLiteral("start")}; const QImage before = frameOf(base, start), after = frameOf(bar, start); CHECK(!before.isNull() && before.size() == after.size()); if (!before.isNull() && before.size() == after.size()) { const int y = before.height() / 2; int rim = before.width() - 1; while (rim > 0 && qAlpha(before.pixel(rim, y)) == 0) --rim; CHECK(before.pixel(before.width() / 2, y) == after.pixel(before.width() / 2, y)); CHECK(toLch(before.pixel(rim, y)).h > 240 && before.pixel(rim, y) != after.pixel(rim, y)); // Not with the correction off (an override): one tint, the button's own -- none here. Adjustments off{*TintSpec::parse(QStringLiteral("taskbar: h=120")), {}}; off.overrides.set(QStringLiteral("start::button"), QStringLiteral("xplasmasharededge"), QStringLiteral("none")); CHECK(frameOf(Theme::adjusted(base, off), start) == before); } } CHECK(base->bitmap(prop(*base, "", "window", "caption", "imagefile")).image == tinted->bitmap(prop(*base, "", "window", "caption", "imagefile")).image); // (untinted until cut) // Keyed-out (transparent) pixels stay transparent. int keys = 0, kept = 0; for (const PartRef &ref : {push, caption}) { const QImage before = frameOf(base, ref), after = frameOf(tinted, ref); for (int y = 0; y < before.height(); ++y) for (int x = 0; x < before.width(); ++x) if (qAlpha(before.pixel(x, y)) == 0) { ++keys; kept += qAlpha(after.pixel(x, y)) == 0; } } CHECK(keys == kept); // One part alone: the caption turns, push buttons don't. const auto captionOnly = Theme::tinted(base, *TintSpec::parse(QStringLiteral("window.caption: h=120"))); CHECK(frameOf(captionOnly, caption) != frameOf(base, caption)); CHECK(frameOf(captionOnly, push) == frameOf(base, push)); CHECK(sys(*captionOnly, "activecaption") == sys(*base, "activecaption")); // One state alone: the inactive frame of the same strip turns, the // active one doesn't. const auto inactiveOnly = Theme::tinted(base, *TintSpec::parse(QStringLiteral("window.caption(inactive): h=120"))); CHECK(frameOf(inactiveOnly, caption) == frameOf(base, caption)); CHECK(frameOf(inactiveOnly, inactive) != frameOf(base, inactive)); // Overrides: any property replaced, over the tint; a section the // style hasn't got made for one. Adjustments adj; adj.tint = TintSpec::uniform(turn); adj.overrides.set(QStringLiteral("SysMetrics"), QStringLiteral("Window"), QStringLiteral("255 255 224")); adj.overrides.set(QStringLiteral("sysmetrics"), QStringLiteral("captionbarheight"), QStringLiteral("31")); adj.overrides.set(QStringLiteral("window.caption(active)"), QStringLiteral("textshadowcolor"), QStringLiteral("1 2 3")); const auto overridden = Theme::adjusted(base, adj); CHECK(sys(*overridden, "window") == QLatin1String("255 255 224")); CHECK(sys(*overridden, "captionbarheight") == QLatin1String("31")); CHECK(sys(*overridden, "activecaption") == sys(*tinted, "activecaption")); // (the tint still there) CHECK(overridden->property(u"window", u"caption", u"active", u"textshadowcolor").value_or(QString()) == QLatin1String("1 2 3")); CHECK(ClassicScheme::fromSysMetrics(*overridden).metrics.captionHeight == 31); const auto json = Overrides::parse(adj.overrides.toJson()); CHECK(json && *json == adj.overrides); CHECK(Adjustments::fromMap(adj.toMap()) == adj); CHECK(Overrides::parse(QStringLiteral("not json")) == std::nullopt); adj.overrides.set(QStringLiteral("sysmetrics"), QStringLiteral("window"), QString()); CHECK(adj.overrides.value(QStringLiteral("sysmetrics"), QStringLiteral("window")).isEmpty()); const auto sysOnly = Theme::tinted(base, *TintSpec::parse(QStringLiteral("sysmetrics.activecaption: h=120"))); CHECK(sys(*sysOnly, "activecaption") != sys(*base, "activecaption")); CHECK(sys(*sysOnly, "hilight") == sys(*base, "hilight")); } else { QTextStream(stdout) << "skip: no Luna at " << luna << " (the tinted-style checks)\n"; }
// Caption buttons: SM_CYSIZE - 4 tall, as wide as the close button's // art in proportion, rounded half up (measured on XP: Luna, Aero Vista; // Aero 7.5's 28x17 at 25 is WackyIdeas' 37). { CHECK(styleButtonSize(25, QSize(21, 21)) == QSize(21, 21)); CHECK(styleButtonSize(25, QSize(24, 12)) == QSize(46, 21)); CHECK(styleButtonSize(25, QSize(28, 17)) == QSize(37, 21)); CHECK(styleButtonSize(25, QSize()) == QSize(21, 21)); CHECK(styleButtonSize(35, QSize(21, 21)) == QSize(31, 31)); } // ... and the layout as data: XP's by default, a style's (or xplasmarc's) // XPlasma properties over it; names a build doesn't know passed over. if (QFileInfo::exists(luna)) { const auto base = Theme::load(luna); NonClientMetrics m; m.captionHeight = 25; const Renderer plain(base); const DecorationLayout xp = decorationLayout(m, &plain); CHECK(xp.button == QSize(21, 21) && xp.buttonGap == 2 && xp.inset == QPoint(2, 2) && xp.iconSize == 16); CHECK(xp.right == (QList<CaptionButton>{CaptionButton::Help, CaptionButton::Minimize, CaptionButton::Maximize, CaptionButton::Close})); CHECK(xp.left == QList<CaptionButton>{CaptionButton::Menu} && xp.titleAlign == Qt::AlignLeft && xp.clipped.isEmpty()); Adjustments adj; adj.overrides.set(QStringLiteral("window"), QStringLiteral("xplasmabuttonsleft"), QStringLiteral("close, min, max")); adj.overrides.set(QStringLiteral("window"), QStringLiteral("xplasmabuttonsright"), QStringLiteral("shade, menu")); adj.overrides.set(QStringLiteral("window"), QStringLiteral("xplasmabuttongap"), QStringLiteral("0")); adj.overrides.set(QStringLiteral("window"), QStringLiteral("xplasmabuttoninset"), QStringLiteral("3, 1")); adj.overrides.set(QStringLiteral("window.caption"), QStringLiteral("contentalignment"), QStringLiteral("Center")); adj.overrides.set(QStringLiteral("window.closebutton"), QStringLiteral("xplasmasize"), QStringLiteral("40, 18")); adj.overrides.set(QStringLiteral("window.closebutton"), QStringLiteral("xplasmaclipglyph"), QStringLiteral("true")); const Renderer tweaked(Theme::adjusted(base, adj)); const DecorationLayout t = decorationLayout(m, &tweaked); CHECK(t.left == (QList<CaptionButton>{CaptionButton::Close, CaptionButton::Minimize, CaptionButton::Maximize})); CHECK(t.right == QList<CaptionButton>{CaptionButton::Menu}); CHECK(t.buttonGap == 0 && t.inset == QPoint(3, 1) && t.titleAlign == Qt::AlignHCenter); CHECK(t.size(CaptionButton::Close) == QSize(40, 18) && t.size(CaptionButton::Minimize) == QSize(21, 21)); CHECK(t.clips(CaptionButton::Close) && !t.clips(CaptionButton::Minimize)); }
QTextStream(stdout) << (failures ? "FAILED " : "ok ") << failures << " failure(s)\n"; return failures;}