Add unified Xresources theme engine, Default.xth export, and xthemes manager plugin

This commit is contained in:
Luxferre committed 2026-10-21 20:36:27 +03:00
1 parent f615c6ddbe
commit a31595070c
60 files changed
+3692 -419

No files matched your search

+50 -60
View File
@@ -130,33 +130,19 @@ int runContactsApp(int argc, char** argv) {
PangoContext* pangoCtx = pango_font_map_create_context(fontMap);
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
PangoFontDescription* descMain =
pango_font_description_from_string("Fira Code, DejaVuSansM Nerd Font 15px");
pango_layout_set_font_description(layoutMain, descMain);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoFontDescription* descSmall =
pango_font_description_from_string("Fira Code, DejaVuSansM Nerd Font 12px");
pango_layout_set_font_description(layoutSmall, descSmall);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PangoFontDescription* descIcon =
pango_font_description_from_string("DejaVuSansM Nerd Font, Fira Code 16px");
pango_layout_set_font_description(layoutIcon, descIcon);
auto allocColor = [&](const char* hex) {
XftColor col{};
XftColorAllocName(dpy, visual, cmap, hex, &col);
return col;
};
XftColor colWhite = allocColor("#ffffff");
XftColor colLight = allocColor("#dddddd");
XftColor colMuted = allocColor("#999999");
XftColor colYellow = allocColor("#f4d03f");
XftColor colGreen = allocColor("#2ecc71");
XftColor colBlue = allocColor("#5dade2");
XftColor colRed = allocColor("#e74c3c");
PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
XftColor& colYellow = theme.colYellow;
XftColor& colGreen = theme.colGreen;
XftColor& colBlue = theme.colBlue;
XftColor& colRed = theme.colRed;
ContactBook book;
std::vector<ContactEntry> filtered;
@@ -277,9 +263,9 @@ int runContactsApp(int argc, char** argv) {
const std::string& rightLabel,
XftColor* centerCol = nullptr) {
int sbY = kWinHeight - kSoftbarH;
XSetForeground(dpy, gc, 0x181818);
XSetForeground(dpy, gc, theme.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, kSoftbarH);
XSetForeground(dpy, gc, 0x444444);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, 1);
if (!leftLabel.empty()) {
@@ -298,14 +284,14 @@ int runContactsApp(int argc, char** argv) {
};
auto render = [&]() {
XSetForeground(dpy, gc, 0x222222);
XSetForeground(dpy, gc, theme.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kWinHeight);
if (mode == ViewMode::List || mode == ViewMode::Options) {
// Header bar with live search / count
XSetForeground(dpy, gc, 0x1c1c1c);
XSetForeground(dpy, gc, theme.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kHeaderH);
XSetForeground(dpy, gc, 0x444444);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
if (searchQuery.empty()) {
@@ -347,10 +333,10 @@ int runContactsApp(int argc, char** argv) {
bool isSel = (idx == selected);
XSetForeground(dpy, gc,
isSel ? 0x005577 : ((i % 2 == 0) ? 0x282828 : 0x2e2e2e));
isSel ? theme.spec.selBg : ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
@@ -367,7 +353,7 @@ int runContactsApp(int argc, char** argv) {
int sbH = std::max(16, (kListH * kVisibleRows) / total);
int sbY = kListY +
((kListH - sbH) * scrollOffset) / (total - kVisibleRows);
XSetForeground(dpy, gc, 0x666666);
XSetForeground(dpy, gc, theme.spec.divider);
XFillRectangle(dpy, pix, gc, kWinWidth - 3, sbY, 3, sbH);
}
}
@@ -394,18 +380,18 @@ int runContactsApp(int argc, char** argv) {
int menuRowH = 34;
int menuH = optCount * menuRowH + 4;
int menuY = kWinHeight - kSoftbarH - menuH;
XSetForeground(dpy, gc, 0x181818);
XSetForeground(dpy, gc, theme.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 8, menuY, kWinWidth - 16, menuH);
XSetForeground(dpy, gc, 0x005577);
XSetForeground(dpy, gc, theme.spec.selBg);
XDrawRectangle(dpy, pix, gc, 8, menuY, kWinWidth - 17, menuH - 1);
for (int i = 0; i < optCount; ++i) {
int ry = menuY + 2 + i * menuRowH;
bool isSel = (i == optionSelected);
if (isSel) {
XSetForeground(dpy, gc, 0x005577);
XSetForeground(dpy, gc, theme.spec.selBg);
XFillRectangle(dpy, pix, gc, 10, ry, kWinWidth - 20, menuRowH);
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 10, ry, 4, menuRowH);
}
XftColor* icCol = (i == 5) ? &colRed : (isSel ? &colYellow : &colGreen);
@@ -424,11 +410,11 @@ int runContactsApp(int argc, char** argv) {
c = filtered[selected];
}
constexpr int kCardH = 56;
XSetForeground(dpy, gc, 0x1b3b4b);
XSetForeground(dpy, gc, theme.spec.bgInputFocus);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kCardH);
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, 0, 4, kCardH);
XSetForeground(dpy, gc, 0x005577);
XSetForeground(dpy, gc, theme.spec.selBg);
XFillRectangle(dpy, pix, gc, 0, kCardH - 2, kWinWidth, 2);
drawPango(layoutIcon, &colYellow, 10, 6, 24, kIconUser);
@@ -469,10 +455,10 @@ int runContactsApp(int argc, char** argv) {
bool isSel = (idx == detailSelected);
XSetForeground(dpy, gc,
isSel ? 0x005577 : ((i % 2 == 0) ? 0x282828 : 0x2e2e2e));
isSel ? theme.spec.selBg : ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
XftColor* icCol =
@@ -485,9 +471,9 @@ int runContactsApp(int argc, char** argv) {
drawSoftbar("Edit", "Select", "Back", &colGreen);
} else if (mode == ViewMode::Edit) {
XSetForeground(dpy, gc, 0x1c1c1c);
XSetForeground(dpy, gc, theme.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kHeaderH);
XSetForeground(dpy, gc, 0x444444);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
drawPango(layoutIcon, &colGreen, 8, 0, kHeaderH,
@@ -505,9 +491,9 @@ int runContactsApp(int argc, char** argv) {
// Field 0: Name box (y = 44..108)
auto drawFieldBox = [&](int y, int h, bool active, const char* label,
const std::string& val, const char* placeholder) {
XSetForeground(dpy, gc, active ? 0x1b3b4b : 0x2a2a2a);
XSetForeground(dpy, gc, active ? theme.spec.bgInputFocus : theme.spec.bgButton);
XFillRectangle(dpy, pix, gc, 6, y, kWinWidth - 12, h);
XSetForeground(dpy, gc, active ? 0xf4d03f : 0x444444);
XSetForeground(dpy, gc, active ? theme.spec.accent : theme.spec.border);
XDrawRectangle(dpy, pix, gc, 6, y, kWinWidth - 13, h - 1);
drawPango(layoutSmall, active ? &colYellow : &colMuted, 12, y + 3, 18,
label);
@@ -533,10 +519,10 @@ int runContactsApp(int argc, char** argv) {
// Button Row 2: Pick from Recent Numbers (y = 168..208)
auto drawBtnRow = [&](int y, int h, bool active, const char* icon,
const char* label, XftColor* icCol) {
XSetForeground(dpy, gc, active ? 0x005577 : 0x2c2c2c);
XSetForeground(dpy, gc, active ? theme.spec.selBg : theme.spec.bgButton);
XFillRectangle(dpy, pix, gc, 6, y, kWinWidth - 12, h);
if (active) {
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 6, y, 4, h);
}
drawPango(layoutIcon, active ? &colYellow : icCol, 14, y, h, icon);
@@ -555,9 +541,9 @@ int runContactsApp(int argc, char** argv) {
drawSoftbar("Save", (editField >= 2) ? "Select" : "Next",
canClearChar ? "Clear" : "Cancel", &colGreen);
} else if (mode == ViewMode::PickRecent) {
XSetForeground(dpy, gc, 0x1c1c1c);
XSetForeground(dpy, gc, theme.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kHeaderH);
XSetForeground(dpy, gc, 0x444444);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, kHeaderH - 1, kWinWidth, 1);
drawPango(layoutIcon, &colBlue, 8, 0, kHeaderH, kIconClock);
drawPango(layoutMain, &colWhite, 32, 0, kHeaderH, "Recent Numbers", 200);
@@ -579,10 +565,10 @@ int runContactsApp(int argc, char** argv) {
int rowH = nextRy - ry;
bool isSel = (idx == recentSelected);
XSetForeground(dpy, gc,
isSel ? 0x005577 : ((i % 2 == 0) ? 0x282828 : 0x2e2e2e));
isSel ? theme.spec.selBg : ((i % 2 == 0) ? theme.spec.bgAltEven : theme.spec.bgAltOdd));
XFillRectangle(dpy, pix, gc, 0, ry, kWinWidth, rowH);
if (isSel) {
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 0, ry, 4, rowH);
}
drawPango(layoutIcon, isSel ? &colYellow : &colGreen, 10, ry, rowH,
@@ -593,7 +579,7 @@ int runContactsApp(int argc, char** argv) {
}
drawSoftbar("Use", "Select", "Back", &colGreen);
} else if (mode == ViewMode::ConfirmDelete) {
XSetForeground(dpy, gc, 0x1c1c1c);
XSetForeground(dpy, gc, theme.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kHeaderH);
drawPango(layoutIcon, &colRed, 8, 0, kHeaderH, kIconTrash);
drawPango(layoutMain, &colWhite, 32, 0, kHeaderH, "Delete Contact?", 200);
@@ -609,10 +595,10 @@ int runContactsApp(int argc, char** argv) {
for (int i = 0; i < 2; ++i) {
int ry = 130 + i * 50;
bool isSel = (i == confirmSelected);
XSetForeground(dpy, gc, isSel ? 0x005577 : 0x2c2c2c);
XSetForeground(dpy, gc, isSel ? theme.spec.selBg : theme.spec.bgButton);
XFillRectangle(dpy, pix, gc, 8, ry, kWinWidth - 16, 44);
if (isSel) {
XSetForeground(dpy, gc, 0xf4d03f);
XSetForeground(dpy, gc, theme.spec.accent);
XFillRectangle(dpy, pix, gc, 8, ry, 4, 44);
}
drawPango(layoutIcon, (i == 1) ? &colRed : &colGreen, 16, ry, 44,
@@ -691,6 +677,9 @@ int runContactsApp(int argc, char** argv) {
auto showWindow = [&](const std::string& arg) {
closeOtherPlugins("contacts");
bool themeChanged = theme.checkAndReload(
dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
bool openNewMode = (arg.rfind("new:", 0) == 0);
std::string prefill = openNewMode ? arg.substr(4) : "";
@@ -703,7 +692,7 @@ int runContactsApp(int argc, char** argv) {
zeroHeld = false;
visible = true;
XMapRaised(dpy, win);
if (!openNewMode) {
if (!openNewMode && !themeChanged) {
XCopyArea(dpy, pix, win, gc, 0, 0, kWinWidth, kWinHeight, 0, 0);
}
for (int i = 0; i < 20; ++i) {
@@ -717,8 +706,8 @@ int runContactsApp(int argc, char** argv) {
if (openNewMode) {
beginNewContact(prefill);
render();
} else if (reloaded || mode != ViewMode::List || !searchQuery.empty() ||
selected != 0) {
} else if (reloaded || themeChanged || mode != ViewMode::List ||
!searchQuery.empty() || selected != 0) {
mode = ViewMode::List;
searchQuery.clear();
selected = 0;
@@ -918,6 +907,10 @@ int runContactsApp(int argc, char** argv) {
} else {
showWindow("");
}
} else if (cmd == "RELOAD_THEME") {
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall,
layoutIcon, nullptr, win);
render();
} else if (cmd == "OPEN") {
showWindow("");
} else if (cmd.rfind("OPEN ", 0) == 0) {
@@ -1443,9 +1436,6 @@ int runContactsApp(int argc, char** argv) {
::unlink(getPluginFifoPath("contacts").c_str());
::unlink(daemonPidPath.c_str());
pango_font_description_free(descIcon);
pango_font_description_free(descSmall);
pango_font_description_free(descMain);
g_object_unref(layoutIcon);
g_object_unref(layoutSmall);
g_object_unref(layoutMain);