Add unified Xresources theme engine, Default.xth export, and xthemes manager plugin
This commit is contained in:
1 parent
f615c6ddbe
commit
a31595070c
60 files changed
+3692
-419
No files matched your search
@@ -198,10 +198,12 @@ int runCameraApp(int argc, char** argv) {
|
||||
Visual* visual = DefaultVisual(dpy, screen);
|
||||
Colormap cmap = DefaultColormap(dpy, screen);
|
||||
|
||||
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
|
||||
|
||||
XSetWindowAttributes swa {};
|
||||
swa.override_redirect = True;
|
||||
swa.background_pixel = 0x181818;
|
||||
swa.border_pixel = 0x005577;
|
||||
swa.background_pixel = initSpec.bgMain;
|
||||
swa.border_pixel = initSpec.selBg;
|
||||
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
VisibilityChangeMask | StructureNotifyMask;
|
||||
|
||||
@@ -223,37 +225,18 @@ int runCameraApp(int argc, char** argv) {
|
||||
GC gc = XCreateGC(dpy, pix, 0, nullptr);
|
||||
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
|
||||
|
||||
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* 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 pt;
|
||||
pt.init(dpy, screen, visual, cmap, win);
|
||||
auto& layoutMain = pt.layoutMain;
|
||||
auto& layoutSmall = pt.layoutSmall;
|
||||
auto& layoutIcon = pt.layoutIcon;
|
||||
auto& colWhite = pt.colWhite;
|
||||
auto& colLight = pt.colLight;
|
||||
auto& colMuted = pt.colMuted;
|
||||
auto& colYellow = pt.colYellow;
|
||||
auto& colGreen = pt.colGreen;
|
||||
auto& colBlue = pt.colBlue;
|
||||
auto& colRed = pt.colRed;
|
||||
|
||||
std::vector<uint32_t> vfFront(kVfW * kVfH, 0x101010);
|
||||
std::vector<uint32_t> vfBack(kVfW * kVfH, 0x101010);
|
||||
@@ -524,9 +507,9 @@ int runCameraApp(int argc, char** argv) {
|
||||
const std::string& centerLabel,
|
||||
const std::string& rightLabel) {
|
||||
const int barY = kWinHeight - 26;
|
||||
XSetForeground(dpy, gc, 0x141414);
|
||||
XSetForeground(dpy, gc, pt.spec.bgFooter);
|
||||
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
|
||||
XSetForeground(dpy, gc, 0x2d2d2d);
|
||||
XSetForeground(dpy, gc, pt.spec.divider);
|
||||
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
|
||||
|
||||
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
|
||||
@@ -549,14 +532,15 @@ int runCameraApp(int argc, char** argv) {
|
||||
|
||||
auto drawUI = [&]() {
|
||||
if (!visible) return;
|
||||
pt.checkAndReload();
|
||||
int64_t tNow = nowMs();
|
||||
|
||||
XSetForeground(dpy, gc, 0x181818);
|
||||
XSetForeground(dpy, gc, pt.spec.bgMain);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, kWinHeight);
|
||||
|
||||
if (mode == ViewMode::Viewfinder) {
|
||||
// Top status bar (28px)
|
||||
XSetForeground(dpy, gc, 0x141414);
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 28);
|
||||
drawPango(layoutIcon, &colGreen, 6, 0, 28, kIconCamera);
|
||||
drawPango(layoutMain, &colWhite, 28, 0, 28, "800x600", 85);
|
||||
@@ -590,7 +574,7 @@ int runCameraApp(int argc, char** argv) {
|
||||
drawPango(layoutSmall, &colLight, 16, vfY + 78, 24, errMsg, 208);
|
||||
} else {
|
||||
// Subtle framing reticle in center of viewfinder
|
||||
XSetForeground(dpy, gc, 0x0088bb);
|
||||
XSetForeground(dpy, gc, pt.spec.accentAlt);
|
||||
int cx = kWinWidth / 2;
|
||||
int cy = vfY + kVfH / 2;
|
||||
XDrawLine(dpy, pix, gc, cx - 10, cy, cx - 3, cy);
|
||||
@@ -600,14 +584,14 @@ int runCameraApp(int argc, char** argv) {
|
||||
}
|
||||
|
||||
if (tNow < shutterFlashUntilMs) {
|
||||
XSetForeground(dpy, gc, 0xffffff);
|
||||
XSetForeground(dpy, gc, pt.spec.fgBright);
|
||||
XDrawRectangle(dpy, pix, gc, 0, vfY, kVfW - 1, kVfH - 1);
|
||||
XDrawRectangle(dpy, pix, gc, 1, vfY + 1, kVfW - 3, kVfH - 3);
|
||||
}
|
||||
|
||||
if (countdownActive) {
|
||||
int remSec = std::max(1, static_cast<int>((countdownTargetMs - tNow + 999) / 1000));
|
||||
XSetForeground(dpy, gc, 0x005577);
|
||||
XSetForeground(dpy, gc, pt.spec.selBg);
|
||||
XFillRectangle(dpy, pix, gc, 78, vfY + 66, 84, 44);
|
||||
drawPango(layoutMain, &colWhite, 92, vfY + 66, 44,
|
||||
"Timer: " + std::to_string(remSec));
|
||||
@@ -615,31 +599,34 @@ int runCameraApp(int argc, char** argv) {
|
||||
|
||||
// Camera control strip (y = 208..270, 62px)
|
||||
const int ctlY = 208;
|
||||
XSetForeground(dpy, gc, 0x1e1e1e);
|
||||
XSetForeground(dpy, gc, pt.spec.bgAltOdd);
|
||||
XFillRectangle(dpy, pix, gc, 0, ctlY, kWinWidth, 62);
|
||||
XSetForeground(dpy, gc, 0x333333);
|
||||
XSetForeground(dpy, gc, pt.spec.border);
|
||||
XDrawLine(dpy, pix, gc, 0, ctlY, kWinWidth, ctlY);
|
||||
|
||||
// Pill 1: Flash (* or 1)
|
||||
XSetForeground(dpy, gc, fl ? 0x004466 : 0x282828);
|
||||
XSetForeground(dpy, gc, fl ? pt.spec.bgInputFocus : pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 6, ctlY + 5, 110, 24);
|
||||
drawPango(layoutSmall, fl ? &colYellow : &colLight, 10, ctlY + 5, 24,
|
||||
std::string("[*] Flash:") + (fl ? "ON" : "OFF"), 102);
|
||||
|
||||
// Pill 2: Torch (0 or 2)
|
||||
XSetForeground(dpy, gc, torchOn ? 0x004466 : 0x282828);
|
||||
XSetForeground(dpy, gc,
|
||||
torchOn ? pt.spec.bgInputFocus : pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 124, ctlY + 5, 110, 24);
|
||||
drawPango(layoutSmall, torchOn ? &colYellow : &colLight, 128, ctlY + 5,
|
||||
24, std::string("[0] Torch:") + (torchOn ? "ON" : "OFF"), 102);
|
||||
|
||||
// Pill 3: Zoom (Up/Dn)
|
||||
XSetForeground(dpy, gc, zf > 1 ? 0x004466 : 0x282828);
|
||||
XSetForeground(dpy, gc,
|
||||
zf > 1 ? pt.spec.bgInputFocus : pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 6, ctlY + 33, 110, 24);
|
||||
drawPango(layoutSmall, &colBlue, 10, ctlY + 33, 24,
|
||||
"[U/D] Zoom:" + std::to_string(zf) + "x", 102);
|
||||
|
||||
// Pill 4: Timer (# or 3)
|
||||
XSetForeground(dpy, gc, timerEnabled ? 0x004466 : 0x282828);
|
||||
XSetForeground(dpy, gc,
|
||||
timerEnabled ? pt.spec.bgInputFocus : pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 124, ctlY + 33, 110, 24);
|
||||
drawPango(layoutSmall, timerEnabled ? &colYellow : &colLight, 128,
|
||||
ctlY + 33, 24,
|
||||
@@ -648,7 +635,7 @@ int runCameraApp(int argc, char** argv) {
|
||||
drawSoftkeyBar("Gallery", "SNAP", "Close");
|
||||
|
||||
} else if (mode == ViewMode::Gallery) {
|
||||
XSetForeground(dpy, gc, 0x141414);
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 28);
|
||||
drawPango(layoutIcon, &colBlue, 6, 0, 28, kIconImage);
|
||||
drawPango(layoutMain, &colWhite, 28, 0, 28, "Gallery", 110);
|
||||
@@ -684,7 +671,7 @@ int runCameraApp(int argc, char** argv) {
|
||||
|
||||
} else if (mode == ViewMode::ConfirmDelete && !photos.empty()) {
|
||||
const auto& pe = photos[selectedPhoto];
|
||||
XSetForeground(dpy, gc, 0x161616);
|
||||
XSetForeground(dpy, gc, pt.spec.bgHeader);
|
||||
XFillRectangle(dpy, pix, gc, 0, 0, kWinWidth, 36);
|
||||
drawPango(layoutIcon, &colRed, 8, 0, 36, kIconTrash);
|
||||
drawPango(layoutMain, &colWhite, 30, 0, 36, "Delete Photo?", 200);
|
||||
@@ -696,8 +683,10 @@ int runCameraApp(int argc, char** argv) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int ry = 156 + i * 40;
|
||||
bool isSel = (confirmSelected == i);
|
||||
XSetForeground(dpy, gc,
|
||||
isSel ? (i == 1 ? 0x922b21 : 0x005577) : 0x2a2a2a);
|
||||
XSetForeground(
|
||||
dpy, gc,
|
||||
isSel ? (i == 1 ? pt.spec.dangerBg : pt.spec.selBg)
|
||||
: pt.spec.bgButton);
|
||||
XFillRectangle(dpy, pix, gc, 16, ry, kWinWidth - 32, 34);
|
||||
drawPango(layoutMain, &colWhite, 28, ry, 34,
|
||||
i == 0 ? "No, Keep Photo" : "Yes, Delete Photo", 184);
|
||||
@@ -708,9 +697,9 @@ int runCameraApp(int argc, char** argv) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(frameMutex);
|
||||
if (!statusBanner.empty() && tNow < statusBannerUntilMs) {
|
||||
XSetForeground(dpy, gc, 0x102535);
|
||||
XSetForeground(dpy, gc, pt.spec.bgToast);
|
||||
XFillRectangle(dpy, pix, gc, 8, 174, kWinWidth - 16, 28);
|
||||
XSetForeground(dpy, gc, 0x2ecc71);
|
||||
XSetForeground(dpy, gc, pt.spec.success);
|
||||
XDrawRectangle(dpy, pix, gc, 8, 174, kWinWidth - 17, 27);
|
||||
drawPango(layoutSmall, &colWhite, 14, 174, 28, statusBanner,
|
||||
kWinWidth - 28);
|
||||
@@ -814,6 +803,9 @@ int runCameraApp(int argc, char** argv) {
|
||||
for (const auto& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "NOP") {
|
||||
continue;
|
||||
} else if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
if (visible) drawUI();
|
||||
} else if (cmd == "CLOSE") {
|
||||
hideWindow();
|
||||
} else if (cmd == "OPEN") {
|
||||
@@ -993,7 +985,10 @@ int runCameraApp(int argc, char** argv) {
|
||||
if (pr > 0) {
|
||||
if (fifoIdx >= 0 && (pfds[fifoIdx].revents & POLLIN)) {
|
||||
for (const auto& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "CLOSE") {
|
||||
if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
if (visible) drawUI();
|
||||
} else if (cmd == "CLOSE") {
|
||||
hideWindow();
|
||||
} else if (cmd == "OPEN") {
|
||||
showWindow("");
|
||||
|
||||
Reference in new issue
Block a user