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

This commit is contained in:
Luxferre
2026-10-21 20:36:27 +03:00
parent f615c6ddbe
commit a31595070c
60 changed files with 3692 additions and 419 deletions
+23 -32
View File
@@ -15,6 +15,7 @@
#include <pango/pangoxft.h>
#include "../sxmo-dwm/dwm_plugin.h"
#include "../dwm-plugins/theme.h"
#include <algorithm>
#include <cmath>
@@ -532,31 +533,17 @@ static int xdrawer_run_main(int argc, char** argv) {
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
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* 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);
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);
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("#aaaaaa");
XftColor colYellow = allocColor("#f4d03f");
XftColor colGreen = allocColor("#2ecc71");
bananarchy::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;
PhoneController controller;
size_t selected = 0;
@@ -591,7 +578,7 @@ static int xdrawer_run_main(int argc, char** argv) {
};
auto render = [&]() {
XSetForeground(dpy, gc, 0x222222);
XSetForeground(dpy, gc, theme.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kWinHeight);
const auto& items = controller.items();
@@ -601,11 +588,11 @@ static int xdrawer_run_main(int argc, char** argv) {
int rowH = nextRy - ry;
bool isSel = (i == selected);
XSetForeground(dpy, gc, isSel ? 0x005577 : ((i % 2 == 0) ? 0x282828 : 0x2e2e2e));
XSetForeground(dpy, gc, 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);
}
@@ -635,19 +622,19 @@ static int xdrawer_run_main(int argc, char** argv) {
int barH = 12;
int barY = ry + (rowH - barH) / 2;
XSetForeground(dpy, gc, 0x161616);
XSetForeground(dpy, gc, theme.spec.bgOverlay);
XFillRectangle(dpy, pix, gc, barX, barY, barW, barH);
XSetForeground(dpy, gc, isSel ? 0xdddddd : 0x555555);
XSetForeground(dpy, gc, isSel ? theme.spec.fgMain : theme.spec.border);
XDrawRectangle(dpy, pix, gc, barX, barY, barW - 1, barH - 1);
int fillW = ((barW - 2) * pct) / 100;
if (fillW > 0) {
XSetForeground(dpy, gc, isSel ? 0xf4d03f : 0x3498db);
XSetForeground(dpy, gc, isSel ? theme.spec.accent : theme.spec.info);
XFillRectangle(dpy, pix, gc, barX + 1, barY + 1, fillW, barH - 2);
}
int knobX = barX + std::clamp(fillW - 2, 0, barW - 5);
XSetForeground(dpy, gc, 0xffffff);
XSetForeground(dpy, gc, theme.spec.fgBright);
XFillRectangle(dpy, pix, gc, knobX, barY - 2, 5, barH + 4);
char pctBuf[16];
@@ -727,6 +714,9 @@ static int xdrawer_run_main(int argc, char** argv) {
closeOtherPlugin("xsms.pid", "/tmp/dwm_plugin_sms.fifo");
closeOtherPlugin("xfiles.pid", "/tmp/dwm_plugin_files.fifo");
closeOtherPlugin("xcamera.pid", "/tmp/dwm_plugin_camera.fifo");
closeOtherPlugin("xthemes.pid", "/tmp/dwm_plugin_themes.fifo");
theme.checkAndReload(dpy, screen, visual, cmap, layoutMain, layoutSmall,
layoutIcon, nullptr, win);
openStartMs = nowMs();
startupIgnoreUntilMs = openStartMs + 180;
initialKeysReleased = (querySoftkeysDown(dpy) == 0);
@@ -802,6 +792,10 @@ static int xdrawer_run_main(int argc, char** argv) {
showWindow();
} else if (cmd == "CLOSE") {
hideWindow(false);
} else if (cmd == "RELOAD_THEME") {
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall,
layoutIcon, nullptr, win);
render();
}
}
}
@@ -928,9 +922,6 @@ static int xdrawer_run_main(int argc, char** argv) {
::unlink(fifoPath.c_str());
::unlink(daemonPidPath.c_str());
pango_font_description_free(descSmall);
pango_font_description_free(descIcon);
pango_font_description_free(descMain);
g_object_unref(layoutSmall);
g_object_unref(layoutIcon);
g_object_unref(layoutMain);