Add NeoUI 240x320 UI SDK, migrate all GUI plugins, add Yabasic FFI wrapper and fix camera rotation

This commit is contained in:
Luxferre committed 2026-10-26 19:11:58 +02:00
1 parent 1f9138f0c6
commit c137feee0e
59 files changed
+5932 -2128

No files matched your search

+15 -69
View File
@@ -75,52 +75,24 @@ int calllog_run_main(int argc, char** argv) {
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGINT, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xcalllog", "XCallLog", "Call Log")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XSetWindowAttributes swa{};
swa.override_redirect = True;
swa.background_pixel = 0x222222;
swa.border_pixel = 0x005577;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask | VisibilityChangeMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch{};
char resName[] = "xcalllog";
char resClass[] = "XCallLog";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Call Log");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
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);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutSmall = neo.layoutSmall;
PangoLayout* layoutIcon = neo.layoutIcon;
PluginTheme& theme = neo.theme;
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
@@ -250,27 +222,11 @@ int calllog_run_main(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
int ty = y + (h - logical.height) / 2;
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
return logical.width;
return neo.pangoWidth(layout, text);
};
constexpr int kHeaderH = 34;
@@ -1136,16 +1092,6 @@ int calllog_run_main(int argc, char** argv) {
}
::unlink(getPluginFifoPath("calllog").c_str());
::unlink(daemonPidPath.c_str());
g_object_unref(layoutIcon);
g_object_unref(layoutSmall);
g_object_unref(layoutMain);
g_object_unref(pangoCtx);
XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+16 -71
View File
@@ -389,53 +389,25 @@ int callscreen_run_main(int argc, char** argv) {
saChld.sa_flags = SA_NOCLDSTOP;
sigaction(SIGCHLD, &saChld, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xcallscreen", "XCallScreen", "Call Screen")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XSetWindowAttributes swa{};
swa.override_redirect = True;
swa.background_pixel = 0x222222;
swa.border_pixel = 0x005577;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask | VisibilityChangeMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch{};
char resName[] = "xcallscreen";
char resClass[] = "XCallScreen";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Call Screen");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
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* layoutNum = pango_layout_new(pangoCtx);
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
layoutNum, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PangoLayout* layoutNum = neo.layoutNum;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutSmall = neo.layoutSmall;
PangoLayout* layoutIcon = neo.layoutIcon;
PluginTheme& theme = neo.theme;
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
@@ -736,27 +708,11 @@ int callscreen_run_main(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
int ty = y + (h - logical.height) / 2;
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
return logical.width;
return neo.pangoWidth(layout, text);
};
constexpr int kHeaderH = 116;
@@ -1819,17 +1775,6 @@ int callscreen_run_main(int argc, char** argv) {
}
::unlink(getPluginFifoPath("callscreen").c_str());
::unlink(daemonPidPath.c_str());
g_object_unref(layoutIcon);
g_object_unref(layoutSmall);
g_object_unref(layoutMain);
g_object_unref(layoutNum);
g_object_unref(pangoCtx);
XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+29 -89
View File
@@ -116,30 +116,31 @@ std::vector<PhotoEntry> listSavedPhotos() {
void saveZoomedRgb24AsJpeg(const std::string& path,
const uint8_t* src800x600,
int zoomFactor) {
if (zoomFactor <= 1) {
saveRgb24AsJpeg(path, src800x600, kCamW, kCamH, 92);
return;
}
// Rotate 90 degrees clockwise from raw 800x600 sensor into upright 600x800
constexpr int kOutW = kCamH; // 600
constexpr int kOutH = kCamW; // 800
zoomFactor = std::clamp(zoomFactor, 1, 4);
int cropW = kCamW / zoomFactor;
int cropH = kCamH / zoomFactor;
int startX = (kCamW - cropW) / 2;
int startY = (kCamH - cropH) / 2;
int cropRotW = kOutW / zoomFactor;
int cropRotH = kOutH / zoomFactor;
int startRotX = (kOutW - cropRotW) / 2;
int startRotY = (kOutH - cropRotH) / 2;
std::vector<uint8_t> zoomed(kCamFrameBytes);
for (int dy = 0; dy < kCamH; ++dy) {
int sy = startY + (dy * cropH) / kCamH;
const uint8_t* srow = src800x600 + static_cast<size_t>(sy) * kCamW * 3;
uint8_t* drow = zoomed.data() + static_cast<size_t>(dy) * kCamW * 3;
for (int dx = 0; dx < kCamW; ++dx) {
int sx = startX + (dx * cropW) / kCamW;
const uint8_t* px = srow + sx * 3;
std::vector<uint8_t> rotated(kCamFrameBytes);
for (int dy = 0; dy < kOutH; ++dy) {
int rotY = std::clamp(startRotY + (dy * cropRotH) / kOutH, 0, kCamW - 1);
int sx = rotY;
uint8_t* drow = rotated.data() + static_cast<size_t>(dy) * kOutW * 3;
for (int dx = 0; dx < kOutW; ++dx) {
int rotX = std::clamp(startRotX + (dx * cropRotW) / kOutW, 0, kCamH - 1);
int sy = (kCamH - 1) - rotX;
const uint8_t* px =
src800x600 + (static_cast<size_t>(sy) * kCamW + sx) * 3;
drow[dx * 3 + 0] = px[0];
drow[dx * 3 + 1] = px[1];
drow[dx * 3 + 2] = px[2];
}
}
saveRgb24AsJpeg(path, zoomed.data(), kCamW, kCamH, 92);
saveRgb24AsJpeg(path, rotated.data(), kOutW, kOutH, 92);
}
int runCameraApp(int argc, char** argv) {
@@ -184,8 +185,8 @@ int runCameraApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xcamera", "XCamera", "Camera")) {
if (fifoFd >= 0) ::close(fifoFd);
if (vfPipe[0] >= 0) ::close(vfPipe[0]);
if (vfPipe[1] >= 0) ::close(vfPipe[1]);
@@ -193,40 +194,13 @@ int runCameraApp(int argc, char** argv) {
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xcamera";
char resClass[] = "XCamera";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Camera");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
@@ -487,47 +461,13 @@ int runCameraApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, centerLabel.c_str(),
static_cast<int>(centerLabel.size()));
int cw = 0, chh = 0;
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
centerLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, rightLabel.c_str(),
static_cast<int>(rightLabel.size()));
int rw = 0, rhh = 0;
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto drawUI = [&]() {
+16 -89
View File
@@ -96,53 +96,24 @@ int runContactsApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xcontacts", "XContacts", "Contacts")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XSetWindowAttributes swa{};
swa.override_redirect = True;
swa.background_pixel = 0x222222;
swa.border_pixel = 0x005577;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch{};
char resName[] = "xcontacts";
char resClass[] = "XContacts";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Contacts");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
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);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutSmall = neo.layoutSmall;
PangoLayout* layoutIcon = neo.layoutIcon;
PluginTheme& theme = neo.theme;
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
@@ -243,27 +214,11 @@ int runContactsApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
int ty = y + (h - logical.height) / 2;
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
return logical.width;
return neo.pangoWidth(layout, text);
};
constexpr int kHeaderH = 38;
@@ -276,25 +231,7 @@ int runContactsApp(int argc, char** argv) {
const std::string& centerLabel,
const std::string& rightLabel,
XftColor* centerCol = nullptr) {
int sbY = kWinHeight - kSoftbarH;
XSetForeground(dpy, gc, theme.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, kSoftbarH);
XSetForeground(dpy, gc, theme.spec.border);
XFillRectangle(dpy, pix, gc, 0, sbY, kWinWidth, 1);
if (!leftLabel.empty()) {
drawPango(layoutMain, &colLight, 6, sbY + 1, kSoftbarH - 1, leftLabel);
}
if (!centerLabel.empty()) {
int cw = pangoWidth(layoutMain, centerLabel);
drawPango(layoutMain, centerCol ? centerCol : &colGreen,
(kWinWidth - cw) / 2, sbY + 1, kSoftbarH - 1, centerLabel);
}
if (!rightLabel.empty()) {
int rw = pangoWidth(layoutMain, rightLabel);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, sbY + 1,
kSoftbarH - 1, rightLabel);
}
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, centerCol, kSoftbarH);
};
auto render = [&]() {
@@ -1794,16 +1731,6 @@ int runContactsApp(int argc, char** argv) {
}
::unlink(getPluginFifoPath("contacts").c_str());
::unlink(daemonPidPath.c_str());
g_object_unref(layoutIcon);
g_object_unref(layoutSmall);
g_object_unref(layoutMain);
g_object_unref(pangoCtx);
XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+17 -71
View File
@@ -66,53 +66,26 @@ int dialer_run_main(int argc, char** argv) {
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGINT, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xdialer", "XDialer", "Dialer")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XSetWindowAttributes swa{};
swa.override_redirect = True;
swa.background_pixel = 0x222222;
swa.border_pixel = 0x005577;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask | VisibilityChangeMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch{};
char resName[] = "xdialer";
char resClass[] = "XDialer";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Dialer");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
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* layoutNum = pango_layout_new(pangoCtx);
PangoLayout* layoutMain = pango_layout_new(pangoCtx);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
layoutNum, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
XftDraw* xftDraw = neo.xftDraw;
PangoLayout* layoutNum = neo.layoutNum;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutSmall = neo.layoutSmall;
PangoLayout* layoutIcon = neo.layoutIcon;
PluginTheme& theme = neo.theme;
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
@@ -206,27 +179,11 @@ int dialer_run_main(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
int ty = y + (h - logical.height) / 2;
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
return logical.width;
return neo.pangoWidth(layout, text);
};
constexpr int kHeaderH = 56;
@@ -989,17 +946,6 @@ int dialer_run_main(int argc, char** argv) {
}
::unlink(getPluginFifoPath("dialer").c_str());
::unlink(daemonPidPath.c_str());
g_object_unref(layoutIcon);
g_object_unref(layoutSmall);
g_object_unref(layoutMain);
g_object_unref(layoutNum);
g_object_unref(pangoCtx);
XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+11 -72
View File
@@ -320,47 +320,20 @@ int runFilesApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xfiles", "XFiles", "Files")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xfiles";
char resClass[] = "XFiles";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Files");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
@@ -899,47 +872,13 @@ int runFilesApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, centerLabel.c_str(),
static_cast<int>(centerLabel.size()));
int cw = 0, chh = 0;
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
centerLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, rightLabel.c_str(),
static_cast<int>(rightLabel.size()));
int rw = 0, rhh = 0;
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto drawUI = [&]() {
+4 -336
View File
@@ -1,341 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-only
// Thin compatibility header forwarding to NeoUI (src/neoui/neoui.h)
#ifndef DWM_PLUGINS_MEDIA_UTILS_H
#define DWM_PLUGINS_MEDIA_UTILS_H
#include <algorithm>
#include <cctype>
#include <csetjmp>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include <jpeglib.h>
#include <png.h>
#include <sys/wait.h>
#include <unistd.h>
namespace bananarchy {
struct JpegErrMgr {
struct jpeg_error_mgr pub;
jmp_buf setjmpBuf;
};
inline void jpegErrorExit(j_common_ptr cinfo) {
JpegErrMgr* myerr = reinterpret_cast<JpegErrMgr*>(cinfo->err);
longjmp(myerr->setjmpBuf, 1);
}
inline bool saveRgb24AsJpeg(const std::string& path,
const uint8_t* rgb,
int width,
int height,
int quality = 92) {
if (!rgb || width <= 0 || height <= 0) {
return false;
}
FILE* fp = std::fopen(path.c_str(), "wb");
if (!fp) {
return false;
}
struct jpeg_compress_struct cinfo {};
JpegErrMgr jerr {};
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = jpegErrorExit;
if (setjmp(jerr.setjmpBuf)) {
jpeg_destroy_compress(&cinfo);
std::fclose(fp);
return false;
}
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, fp);
cinfo.image_width = static_cast<JDIMENSION>(width);
cinfo.image_height = static_cast<JDIMENSION>(height);
cinfo.input_components = 3;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);
int rowStride = width * 3;
while (cinfo.next_scanline < cinfo.image_height) {
JSAMPROW rowPtr =
const_cast<JSAMPROW>(rgb + cinfo.next_scanline * rowStride);
jpeg_write_scanlines(&cinfo, &rowPtr, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
std::fclose(fp);
return true;
}
inline bool loadJpegRgb24(const std::string& path,
std::vector<uint8_t>* outRgb,
int* outW,
int* outH) {
FILE* fp = std::fopen(path.c_str(), "rb");
if (!fp) {
return false;
}
struct jpeg_decompress_struct cinfo {};
JpegErrMgr jerr {};
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = jpegErrorExit;
if (setjmp(jerr.setjmpBuf)) {
jpeg_destroy_decompress(&cinfo);
std::fclose(fp);
return false;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, fp);
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) {
jpeg_destroy_decompress(&cinfo);
std::fclose(fp);
return false;
}
// Use libjpeg fast DCT downscaling for large images so decoding is instant
if (cinfo.image_width > 960 || cinfo.image_height > 960) {
cinfo.scale_num = 1;
cinfo.scale_denom = 2;
}
cinfo.out_color_space = JCS_RGB;
jpeg_start_decompress(&cinfo);
int w = static_cast<int>(cinfo.output_width);
int h = static_cast<int>(cinfo.output_height);
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
jpeg_destroy_decompress(&cinfo);
std::fclose(fp);
return false;
}
outRgb->resize(static_cast<size_t>(w) * h * 3);
int rowStride = w * 3;
while (cinfo.output_scanline < cinfo.output_height) {
JSAMPROW rowPtr = outRgb->data() + cinfo.output_scanline * rowStride;
jpeg_read_scanlines(&cinfo, &rowPtr, 1);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
std::fclose(fp);
*outW = w;
*outH = h;
return true;
}
inline bool loadPngRgb24(const std::string& path,
std::vector<uint8_t>* outRgb,
int* outW,
int* outH) {
png_image image {};
image.version = PNG_IMAGE_VERSION;
if (!png_image_begin_read_from_file(&image, path.c_str())) {
return false;
}
image.format = PNG_FORMAT_RGB;
int w = static_cast<int>(image.width);
int h = static_cast<int>(image.height);
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
png_image_free(&image);
return false;
}
outRgb->resize(PNG_IMAGE_SIZE(image));
if (!png_image_finish_read(&image, nullptr, outRgb->data(), 0, nullptr)) {
png_image_free(&image);
return false;
}
png_image_free(&image);
*outW = w;
*outH = h;
return true;
}
inline bool loadFfmpegImageRgb24(const std::string& path,
std::vector<uint8_t>* outRgb,
int* outW,
int* outH) {
int pipefd[2];
if (::pipe(pipefd) != 0) {
return false;
}
pid_t pid = ::fork();
if (pid < 0) {
::close(pipefd[0]);
::close(pipefd[1]);
return false;
}
if (pid == 0) {
::close(pipefd[0]);
::dup2(pipefd[1], STDOUT_FILENO);
if (pipefd[1] != STDOUT_FILENO) ::close(pipefd[1]);
int devnull = ::open("/dev/null", O_RDWR);
if (devnull >= 0) {
::dup2(devnull, STDIN_FILENO);
::dup2(devnull, STDERR_FILENO);
if (devnull > 2) ::close(devnull);
}
::execlp("ffmpeg", "ffmpeg", "-v", "error", "-i", path.c_str(),
"-frames:v", "1", "-f", "image2pipe", "-vcodec", "png", "-",
static_cast<char*>(nullptr));
::_exit(127);
}
::close(pipefd[1]);
std::vector<uint8_t> pngBuf;
uint8_t chunk[4096];
ssize_t n = 0;
while ((n = ::read(pipefd[0], chunk, sizeof(chunk))) > 0) {
if (pngBuf.size() + static_cast<size_t>(n) > 16 * 1024 * 1024) break;
pngBuf.insert(pngBuf.end(), chunk, chunk + n);
}
::close(pipefd[0]);
int status = 0;
::waitpid(pid, &status, 0);
if (pngBuf.empty()) {
return false;
}
png_image image {};
image.version = PNG_IMAGE_VERSION;
if (!png_image_begin_read_from_memory(&image, pngBuf.data(), pngBuf.size())) {
return false;
}
image.format = PNG_FORMAT_RGB;
int w = static_cast<int>(image.width);
int h = static_cast<int>(image.height);
if (w <= 0 || h <= 0 || w > 8192 || h > 8192) {
png_image_free(&image);
return false;
}
outRgb->resize(PNG_IMAGE_SIZE(image));
if (!png_image_finish_read(&image, nullptr, outRgb->data(), 0, nullptr)) {
png_image_free(&image);
return false;
}
png_image_free(&image);
*outW = w;
*outH = h;
return true;
}
inline bool loadImageRgb24(const std::string& path,
std::vector<uint8_t>* outRgb,
int* outW,
int* outH) {
std::string low = path;
for (char& c : low) {
c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
}
if (low.size() >= 4 && low.substr(low.size() - 4) == ".png") {
if (loadPngRgb24(path, outRgb, outW, outH)) {
return true;
}
}
if (loadJpegRgb24(path, outRgb, outW, outH)) {
return true;
}
if (loadPngRgb24(path, outRgb, outW, outH)) {
return true;
}
if (loadFfmpegImageRgb24(path, outRgb, outW, outH)) {
return true;
}
return false;
}
inline void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb,
int srcW,
int srcH,
uint32_t* dstBgrx,
int canvasW,
int canvasH,
uint32_t bgPixel = 0x111111) {
for (int i = 0; i < canvasW * canvasH; ++i) {
dstBgrx[i] = bgPixel;
}
if (!srcRgb || srcW <= 0 || srcH <= 0 || canvasW <= 0 || canvasH <= 0) {
return;
}
int drawW = canvasW;
int drawH = (srcH * canvasW) / srcW;
if (drawH > canvasH) {
drawH = canvasH;
drawW = (srcW * canvasH) / srcH;
}
drawW = std::max(1, drawW);
drawH = std::max(1, drawH);
int offX = (canvasW - drawW) / 2;
int offY = (canvasH - drawH) / 2;
for (int dy = 0; dy < drawH; ++dy) {
int sy = std::min(srcH - 1, (dy * srcH) / drawH);
const uint8_t* srow = srcRgb + static_cast<size_t>(sy) * srcW * 3;
uint32_t* drow = dstBgrx + static_cast<size_t>(offY + dy) * canvasW + offX;
for (int dx = 0; dx < drawW; ++dx) {
int sx = std::min(srcW - 1, (dx * srcW) / drawW);
const uint8_t* px = srow + sx * 3;
drow[dx] = (static_cast<uint32_t>(px[0]) << 16) |
(static_cast<uint32_t>(px[1]) << 8) |
static_cast<uint32_t>(px[2]);
}
}
}
inline void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
uint32_t* dstBgrx,
int zoomFactor = 1) {
if (!srcRgb || !dstBgrx) {
return;
}
zoomFactor = std::clamp(zoomFactor, 1, 4);
int cropW = 800 / zoomFactor;
int cropH = 600 / zoomFactor;
int startX = (800 - cropW) / 2;
int startY = (600 - cropH) / 2;
for (int dy = 0; dy < 180; ++dy) {
int sy = startY + (dy * cropH) / 180;
const uint8_t* srow = srcRgb + static_cast<size_t>(sy) * 800 * 3;
uint32_t* drow = dstBgrx + static_cast<size_t>(dy) * 240;
for (int dx = 0; dx < 240; ++dx) {
int sx = startX + (dx * cropW) / 240;
const uint8_t* px = srow + sx * 3;
drow[dx] = (static_cast<uint32_t>(px[0]) << 16) |
(static_cast<uint32_t>(px[1]) << 8) |
static_cast<uint32_t>(px[2]);
}
}
}
inline std::string formatFileSize(off_t bytes) {
char buf[32];
if (bytes >= 1024LL * 1024LL * 1024LL) {
std::snprintf(buf, sizeof(buf), "%.1fG",
static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0));
} else if (bytes >= 1024LL * 1024LL) {
std::snprintf(buf, sizeof(buf), "%.1fM",
static_cast<double>(bytes) / (1024.0 * 1024.0));
} else if (bytes >= 1024LL) {
std::snprintf(buf, sizeof(buf), "%.1fK",
static_cast<double>(bytes) / 1024.0);
} else {
std::snprintf(buf, sizeof(buf), "%lldB", static_cast<long long>(bytes));
}
return buf;
}
} // namespace bananarchy
#include "../neoui/neoui.h"
#endif // DWM_PLUGINS_MEDIA_UTILS_H
+11 -67
View File
@@ -503,48 +503,19 @@ int runModemApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xmodem", "XModem", "Modem & SIM")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xmodem";
char resClass[] = "XModem";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Modem & SIM");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
Display* dpy = neo.dpy;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
XftDraw* xftDraw = neo.xftDraw;
PluginTheme& pt = neo.theme;
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
@@ -693,44 +664,17 @@ int runModemApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) -> int {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoTextWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
return tw;
return neo.pangoWidth(layout, text);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
int cw = pangoTextWidth(layoutMain, centerLabel);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26, centerLabel);
int rw = pangoTextWidth(layoutMain, rightLabel);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto drawSignalBars = [&](int x, int y, int pct) {
+13 -70
View File
@@ -321,51 +321,21 @@ int runMusicApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xmusic", "XMusic", "Music",
kWinX, kWinY, kWinWidth, kWinHeight)) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xmusic";
char resClass[] = "XMusic";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Music");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
Display* dpy = neo.dpy;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = neo.layoutMain;
auto& layoutSmall = neo.layoutSmall;
auto& layoutIcon = neo.layoutIcon;
auto& colWhite = pt.colWhite;
auto& colLight = pt.colLight;
auto& colMuted = pt.colMuted;
@@ -884,35 +854,13 @@ int runMusicApp(int argc, char** argv) {
int h, const std::string& text, int maxW = -1,
int align = 0) {
if (text.empty()) return;
pango_layout_set_text(layout, text.c_str(), -1);
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int tx = x;
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
int ty = y + (h - th) / 2;
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW, align);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& midLabel,
const std::string& rightLabel) {
int barY = kWinHeight - 24;
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
XSetForeground(dpy, gc, pt.spec.border);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
};
auto render = [&]() {
@@ -1568,11 +1516,6 @@ int runMusicApp(int argc, char** argv) {
stopMpvDaemon();
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
if (xftDraw) XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+14 -76
View File
@@ -374,51 +374,21 @@ int runNetworksApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xnetworks", "XNetworks", "Networks & Bluetooth",
kWinX, kWinY, kWinWidth, kWinHeight)) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xnetworks";
char resClass[] = "XNetworks";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Networks & Bluetooth");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
Display* dpy = neo.dpy;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = neo.layoutMain;
auto& layoutSmall = neo.layoutSmall;
auto& layoutIcon = neo.layoutIcon;
auto& colWhite = pt.colWhite;
auto& colLight = pt.colLight;
auto& colMuted = pt.colMuted;
@@ -587,44 +557,17 @@ int runNetworksApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) -> int {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoTextWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
return tw;
return neo.pangoWidth(layout, text);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
int cw = pangoTextWidth(layoutMain, centerLabel);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26, centerLabel);
int rw = pangoTextWidth(layoutMain, rightLabel);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto render = [&]() {
@@ -1524,11 +1467,6 @@ int runNetworksApp(int argc, char** argv) {
hideWindow();
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
XftDrawDestroy(xftDraw);
XFreePixmap(dpy, pix);
XFreeGC(dpy, gc);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
-101
View File
@@ -2726,107 +2726,6 @@ inline constexpr const char* kMultiTapPunct1 =
inline constexpr const char* kMultiTapStar =
"*#+-=_/\\|~`@$%^&()[]{}<>'\".,!?:;";
inline std::string formatMultiTapBar(const std::string& prefix,
const char* table, int activeIdx,
bool makeUpper,
int maxItems = 7,
size_t maxChars = 21) {
if (!table || !table[0]) return "";
int total = static_cast<int>(std::strlen(table));
if (total <= 0) return "";
activeIdx = std::clamp(activeIdx, 0, total - 1);
std::vector<std::string> labels;
labels.reserve(total);
for (int i = 0; i < total; ++i) {
char c = table[i];
if (c == ' ') {
labels.push_back("SPC");
} else if (c == '\n') {
labels.push_back("NL");
} else if (c == '\t') {
labels.push_back("TAB");
} else {
if (makeUpper && std::isalpha(static_cast<unsigned char>(c))) {
c = static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
}
labels.push_back(std::string(1, c));
}
}
int halfWin = std::max(1, maxItems / 2);
int start = std::max(0, activeIdx - halfWin);
int end = start;
size_t width = 0;
int count = 0;
while (start <= activeIdx) {
width = 0;
count = 0;
end = start;
while (end < total && count < maxItems) {
size_t iw = labels[end].size() + 2;
if (count > 0 && width + iw > maxChars) break;
width += iw;
++end;
++count;
}
if (activeIdx < end) break;
++start;
}
while (start > 0 && count < maxItems) {
size_t iw = labels[start - 1].size() + 2;
if (width + iw > maxChars) break;
--start;
width += iw;
++count;
}
std::string out = prefix;
out += (start > 0) ? "<" : " ";
for (int i = start; i < end; ++i) {
if (i == activeIdx) {
out += "[" + labels[i] + "]";
} else {
out += " " + labels[i] + " ";
}
}
if (end < total) {
out += ">";
}
return out;
}
inline std::string tailFitPangoText(PangoLayout* layout,
const std::string& text,
int maxWidthPx) {
if (!layout || text.empty() || maxWidthPx <= 0) return text;
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
int w = 0, h = 0;
pango_layout_get_pixel_size(layout, &w, &h);
if (w <= maxWidthPx) return text;
size_t pos = 0;
while (pos < text.size()) {
pos++;
while (pos < text.size() &&
(static_cast<unsigned char>(text[pos]) & 0xC0) == 0x80) {
pos++;
}
std::string candidate = ".." + text.substr(pos);
pango_layout_set_text(layout, candidate.c_str(),
static_cast<int>(candidate.size()));
pango_layout_get_pixel_size(layout, &w, &h);
if (w <= maxWidthPx) {
return candidate;
}
}
return text;
}
} // namespace bananarchy
#endif // DWM_PLUGINS_PHONE_DATA_H
+12 -74
View File
@@ -247,11 +247,6 @@ void saveRingSettings(const RingSettings& s) {
runAsyncCmd("sxmo_hook_statusbar.sh audio >/dev/null 2>&1");
}
std::string formatFileSize(off_t bytes) {
if (bytes < 1024) return std::to_string(bytes) + " B";
return std::to_string((bytes + 512) / 1024) + " KB";
}
int runRingtonesApp(int argc, char** argv) {
gRunning = 1;
std::setlocale(LC_ALL, "");
@@ -283,50 +278,20 @@ int runRingtonesApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xringtones", "XRingtones", "Ringtones",
kWinX, kWinY, kWinWidth, kWinHeight)) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xringtones";
char resClass[] = "XRingtones";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Ringtones");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
Display* dpy = neo.dpy;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = neo.layoutMain;
auto& layoutSmall = neo.layoutSmall;
auto& colWhite = pt.colWhite;
auto& colLight = pt.colLight;
auto& colMuted = pt.colMuted;
@@ -448,35 +413,13 @@ int runRingtonesApp(int argc, char** argv) {
int h, const std::string& text, int maxW = -1,
int align = 0) {
if (text.empty()) return;
pango_layout_set_text(layout, text.c_str(), -1);
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int tx = x;
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
int ty = y + (h - th) / 2;
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW, align);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& midLabel,
const std::string& rightLabel) {
int barY = kWinHeight - 24;
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
XSetForeground(dpy, gc, pt.spec.border);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
};
auto render = [&]() {
@@ -913,11 +856,6 @@ int runRingtonesApp(int argc, char** argv) {
hideWindow();
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
if (xftDraw) XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+10 -72
View File
@@ -118,8 +118,8 @@ int runSmsApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xsms", "XSms", "Messages")) {
if (fifoFd >= 0) ::close(fifoFd);
if (notifyPipe[0] >= 0) ::close(notifyPipe[0]);
if (notifyPipe[1] >= 0) ::close(notifyPipe[1]);
@@ -127,40 +127,12 @@ int runSmsApp(int argc, char** argv) {
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec = loadThemeSpec(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xsms";
char resClass[] = "XSms";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Messages");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
Display* dpy = neo.dpy;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
XftDraw* xftDraw = neo.xftDraw;
PluginTheme& pt = neo.theme;
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
auto& layoutIcon = pt.layoutIcon;
@@ -464,47 +436,13 @@ int runSmsApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, centerLabel.c_str(),
static_cast<int>(centerLabel.size()));
int cw = 0, chh = 0;
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
centerLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, rightLabel.c_str(),
static_cast<int>(rightLabel.size()));
int rw = 0, rhh = 0;
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto drawUI = [&]() {
+4 -631
View File
@@ -1,636 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-only
// Thin compatibility header forwarding to NeoUI (src/neoui/neoui.h)
#ifndef DWM_PLUGINS_THEME_H
#define DWM_PLUGINS_THEME_H
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <pango/pango.h>
#include <pango/pangoxft.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <sstream>
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <unordered_map>
namespace bananarchy {
inline std::string themeTrim(const std::string& s) {
size_t b = 0;
while (b < s.size() && std::isspace(static_cast<unsigned char>(s[b]))) {
++b;
}
size_t e = s.size();
while (e > b && std::isspace(static_cast<unsigned char>(s[e - 1]))) {
--e;
}
if (e >= b + 2 &&
((s[b] == '"' && s[e - 1] == '"') || (s[b] == '\'' && s[e - 1] == '\''))) {
return s.substr(b + 1, e - b - 2);
}
return s.substr(b, e - b);
}
inline int themeHexNibble(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'a' && c <= 'f') return 10 + (c - 'a');
if (c >= 'A' && c <= 'F') return 10 + (c - 'A');
return -1;
}
inline bool parseHexRgb(const std::string& raw, uint32_t* outRgb) {
std::string s = themeTrim(raw);
if (s.rfind("0x", 0) == 0 || s.rfind("0X", 0) == 0) {
s = "#" + s.substr(2);
}
if (s.size() == 7 && s[0] == '#') {
uint32_t v = 0;
for (int i = 1; i < 7; ++i) {
int n = themeHexNibble(s[i]);
if (n < 0) return false;
v = (v << 4) | static_cast<uint32_t>(n);
}
*outRgb = v;
return true;
}
if (s.size() == 4 && s[0] == '#') {
int r = themeHexNibble(s[1]);
int g = themeHexNibble(s[2]);
int b = themeHexNibble(s[3]);
if (r < 0 || g < 0 || b < 0) return false;
*outRgb = static_cast<uint32_t>(((r * 17) << 16) | ((g * 17) << 8) | (b * 17));
return true;
}
return false;
}
inline std::string formatHexRgb(uint32_t rgb) {
char buf[16];
std::snprintf(buf, sizeof(buf), "#%06x", static_cast<unsigned int>(rgb & 0xffffffu));
return buf;
}
inline uint32_t adjustRgb(uint32_t rgb, int delta) {
int r = std::clamp(static_cast<int>((rgb >> 16) & 0xff) + delta, 0, 255);
int g = std::clamp(static_cast<int>((rgb >> 8) & 0xff) + delta, 0, 255);
int b = std::clamp(static_cast<int>(rgb & 0xff) + delta, 0, 255);
return static_cast<uint32_t>((r << 16) | (g << 8) | b);
}
inline uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct) {
int w2 = std::clamp(weight2Pct, 0, 100);
int w1 = 100 - w2;
int r = (((c1 >> 16) & 0xff) * w1 + ((c2 >> 16) & 0xff) * w2) / 100;
int g = (((c1 >> 8) & 0xff) * w1 + ((c2 >> 8) & 0xff) * w2) / 100;
int b = ((c1 & 0xff) * w1 + (c2 & 0xff) * w2) / 100;
return static_cast<uint32_t>((std::clamp(r, 0, 255) << 16) |
(std::clamp(g, 0, 255) << 8) |
std::clamp(b, 0, 255));
}
inline std::string getHomeDirPath() {
const char* h = std::getenv("HOME");
return (h && h[0]) ? h : "/home/user";
}
inline std::string getXresourcesPath() {
return getHomeDirPath() + "/.Xresources";
}
inline std::string getThemesDirPath() {
return getHomeDirPath() + "/.xthemes";
}
struct ThemeSpec {
std::string name = "Default";
std::string fontFace = "Fira Code";
std::string iconFontFace = "DejaVuSansM Nerd Font";
int baseFontSize = 15;
// Core colors (24-bit RGB)
uint32_t bgMain = 0x222222;
uint32_t bgBar = 0x222222;
uint32_t bgHeader = 0x1c1c1c;
uint32_t bgFooter = 0x181818;
uint32_t bgOverlay = 0x161616;
uint32_t bgAltEven = 0x282828;
uint32_t bgAltOdd = 0x2e2e2e;
uint32_t bgInput = 0x1a1a1a;
uint32_t bgInputFocus = 0x1b3b4b;
uint32_t bgButton = 0x2a2a2a;
uint32_t bgSearch = 0x383838;
uint32_t bgBubbleIn = 0x262d32;
uint32_t bgBubbleOut = 0x1f2d38;
uint32_t bgToast = 0x102535;
uint32_t fgMain = 0xdddddd;
uint32_t fgBright = 0xffffff;
uint32_t fgMuted = 0x999999;
uint32_t selBg = 0x005577;
uint32_t selFg = 0xffffff;
uint32_t accent = 0xf4d03f;
uint32_t accentAlt = 0x0088bb;
uint32_t highlight = 0xffc978;
uint32_t border = 0x444444;
uint32_t divider = 0x666666;
uint32_t success = 0x2ecc71;
uint32_t info = 0x5dade2;
uint32_t warning = 0xe67e22;
uint32_t danger = 0xe74c3c;
uint32_t dangerBg = 0x922b21;
int sizeSmall() const {
return std::max(8, static_cast<int>(std::lround(baseFontSize * 12.0 / 15.0)));
}
int sizeMain() const {
return std::clamp(baseFontSize, 10, 24);
}
int sizeIcon() const {
return std::max(10, static_cast<int>(std::lround(baseFontSize * 16.0 / 15.0)));
}
int sizeLarge() const {
return std::max(11, static_cast<int>(std::lround(baseFontSize * 18.0 / 15.0)));
}
std::string pangoMainFontStr() const {
return fontFace + ", " + iconFontFace + " " + std::to_string(sizeMain()) + "px";
}
std::string pangoSmallFontStr() const {
return fontFace + ", " + iconFontFace + " " + std::to_string(sizeSmall()) + "px";
}
std::string pangoIconFontStr() const {
return iconFontFace + ", " + fontFace + " " + std::to_string(sizeIcon()) + "px";
}
std::string pangoLargeBoldFontStr() const {
return fontFace + ", " + iconFontFace + " Bold " + std::to_string(sizeLarge()) + "px";
}
std::string xftFontStr(int pxSize) const {
return fontFace + ":pixelsize=" + std::to_string(pxSize) +
":style=Regular:antialias=true:autohint=true";
}
std::string xftIconFontStr(int pxSize) const {
return iconFontFace + ":pixelsize=" + std::to_string(pxSize) +
":style=Regular:antialias=true:autohint=true";
}
void recomputeDerivedFromCore() {
int luma = (((bgMain >> 16) & 0xff) * 299 +
((bgMain >> 8) & 0xff) * 587 +
(bgMain & 0xff) * 114) / 1000;
int dir = (luma > 140) ? -1 : 1;
bgBar = bgMain;
bgHeader = adjustRgb(bgMain, -dir * 6);
bgFooter = adjustRgb(bgMain, -dir * 10);
bgOverlay = adjustRgb(bgMain, -dir * 12);
bgAltEven = adjustRgb(bgMain, dir * 6);
bgAltOdd = adjustRgb(bgMain, dir * 12);
bgInput = adjustRgb(bgMain, -dir * 8);
bgInputFocus = blendRgb(bgMain, selBg, 40);
bgButton = adjustRgb(bgMain, dir * 8);
bgSearch = adjustRgb(bgMain, dir * 22);
bgBubbleIn = blendRgb(bgMain, success, 14);
bgBubbleOut = blendRgb(bgMain, selBg, 26);
bgToast = blendRgb(bgOverlay, selBg, 35);
int fgLuma = (((fgMain >> 16) & 0xff) * 299 +
((fgMain >> 8) & 0xff) * 587 +
(fgMain & 0xff) * 114) / 1000;
fgBright = (fgLuma > 128) ? 0xffffff : 0x000000;
fgMuted = blendRgb(fgMain, bgMain, 45);
accentAlt = adjustRgb(selBg, 48);
highlight = blendRgb(accent, 0xffffff, 30);
border = adjustRgb(bgMain, dir * 34);
divider = adjustRgb(bgMain, dir * 68);
}
void parseFromMap(const std::unordered_map<std::string, std::string>& kv) {
auto getStr = [&](const char* k1, const char* k2 = nullptr,
const char* k3 = nullptr) -> std::string {
auto it = kv.find(k1);
if (it != kv.end() && !it->second.empty()) return it->second;
if (k2) {
it = kv.find(k2);
if (it != kv.end() && !it->second.empty()) return it->second;
}
if (k3) {
it = kv.find(k3);
if (it != kv.end() && !it->second.empty()) return it->second;
}
return "";
};
std::string nm = getStr("theme.name", "*themeName");
if (!nm.empty()) name = nm;
std::string ff = getStr("theme.fontFace", "*fontFace");
if (!ff.empty()) {
fontFace = ff;
} else {
std::string dwmFont = getStr("dwm.font");
if (!dwmFont.empty()) {
size_t comma = dwmFont.find(',');
if (comma != std::string::npos) {
fontFace = themeTrim(dwmFont.substr(0, comma));
}
}
}
std::string iff = getStr("theme.iconFontFace", "*iconFontFace");
if (!iff.empty()) iconFontFace = iff;
std::string bfs = getStr("theme.baseFontSize", "*baseFontSize");
if (!bfs.empty()) {
int sz = std::atoi(bfs.c_str());
if (sz >= 10 && sz <= 24) baseFontSize = sz;
} else {
std::string dwmFont = getStr("dwm.font");
size_t pxPos = dwmFont.rfind("px");
if (pxPos != std::string::npos && pxPos > 0) {
size_t sp = pxPos;
while (sp > 0 && std::isdigit(static_cast<unsigned char>(dwmFont[sp - 1]))) {
--sp;
}
if (sp < pxPos) {
int sz = std::atoi(dwmFont.substr(sp, pxPos - sp).c_str());
if (sz >= 10 && sz <= 24) baseFontSize = sz;
}
}
}
auto getCol = [&](uint32_t* dst, const char* k1, const char* k2 = nullptr,
const char* k3 = nullptr) -> bool {
std::string s = getStr(k1, k2, k3);
if (s.empty()) return false;
uint32_t v = 0;
if (parseHexRgb(s, &v)) {
*dst = v;
return true;
}
return false;
};
bool hasCoreBg = getCol(&bgMain, "theme.bgMain", "*background", "dmenu.background");
bool hasCoreFg = getCol(&fgMain, "theme.fgMain", "*foreground", "dwm.normfgcolor");
bool hasSelBg = getCol(&selBg, "theme.selBg", "dmenu.selbackground", "dwm.selbgcolor");
bool hasSelFg = getCol(&selFg, "theme.selFg", "dmenu.selforeground", "dwm.selfgcolor");
bool hasAccent = getCol(&accent, "theme.accent", "*accentColor", "st.cursorColor");
(void)hasCoreBg;
(void)hasCoreFg;
(void)hasSelBg;
(void)hasSelFg;
(void)hasAccent;
// Derive defaults from core colors first, then override with any explicit tokens
recomputeDerivedFromCore();
getCol(&bgBar, "theme.bgBar", "dwm.background", "dwm.normbgcolor");
getCol(&bgHeader, "theme.bgHeader", "dmenu.background", "st.background");
getCol(&bgFooter, "theme.bgFooter");
getCol(&bgOverlay, "theme.bgOverlay");
getCol(&bgAltEven, "theme.bgAltEven");
getCol(&bgAltOdd, "theme.bgAltOdd");
getCol(&bgInput, "theme.bgInput");
getCol(&bgInputFocus, "theme.bgInputFocus");
getCol(&bgButton, "theme.bgButton");
getCol(&bgSearch, "theme.bgSearch", "dmenu.outbackground");
getCol(&bgBubbleIn, "theme.bgBubbleIn");
getCol(&bgBubbleOut, "theme.bgBubbleOut");
getCol(&bgToast, "theme.bgToast");
getCol(&fgBright, "theme.fgBright", "dmenu.selforeground");
getCol(&fgMuted, "theme.fgMuted");
getCol(&accentAlt, "theme.accentAlt");
getCol(&highlight, "theme.highlight", "dmenu.highlight");
getCol(&border, "theme.border", "dwm.border", "dwm.normbordercolor");
getCol(&divider, "theme.divider");
getCol(&success, "theme.success");
getCol(&info, "theme.info");
getCol(&warning, "theme.warning");
getCol(&danger, "theme.danger");
getCol(&dangerBg, "theme.dangerBg");
}
static void parseLinesIntoMap(const std::string& content,
std::unordered_map<std::string, std::string>& kv) {
std::istringstream ss(content);
std::string line;
while (std::getline(ss, line)) {
std::string t = themeTrim(line);
if (t.empty() || t[0] == '!' || t[0] == '#') continue;
size_t colon = t.find(':');
if (colon == std::string::npos) continue;
std::string key = themeTrim(t.substr(0, colon));
std::string val = themeTrim(t.substr(colon + 1));
if (!key.empty() && !val.empty()) {
kv[key] = val;
}
}
}
bool loadFromFile(const std::string& path) {
std::ifstream in(path);
if (!in.is_open()) return false;
std::ostringstream ss;
ss << in.rdbuf();
std::unordered_map<std::string, std::string> kv;
parseLinesIntoMap(ss.str(), kv);
parseFromMap(kv);
return true;
}
void loadActive(Display* dpy, int screen) {
std::unordered_map<std::string, std::string> kv;
if (dpy) {
Atom actualType = None;
int actualFormat = 0;
unsigned long nitems = 0, bytesAfter = 0;
unsigned char* prop = nullptr;
if (XGetWindowProperty(dpy, RootWindow(dpy, screen), XA_RESOURCE_MANAGER,
0L, 65536L, False, XA_STRING, &actualType,
&actualFormat, &nitems, &bytesAfter,
&prop) == Success &&
prop) {
if (actualType == XA_STRING && actualFormat == 8 && nitems > 0) {
std::string resStr(reinterpret_cast<char*>(prop), nitems);
parseLinesIntoMap(resStr, kv);
}
XFree(prop);
}
}
// Also read ~/.Xresources so direct file edits always take effect
std::ifstream in(getXresourcesPath());
if (in.is_open()) {
std::ostringstream ss;
ss << in.rdbuf();
parseLinesIntoMap(ss.str(), kv);
}
if (!kv.empty()) {
parseFromMap(kv);
}
}
std::string serializeXresources() const {
std::ostringstream out;
out << "! Space to setup configversion\n";
out << "! configversion: 7bff124b2de16292fe6e7a7e5d3322ae\n";
out << "! Bananarchy Unified Theme: " << name << "\n\n";
out << "theme.name: " << name << "\n";
out << "theme.fontFace: " << fontFace << "\n";
out << "theme.iconFontFace: " << iconFontFace << "\n";
out << "theme.baseFontSize: " << sizeMain() << "\n\n";
out << "theme.bgMain: " << formatHexRgb(bgMain) << "\n";
out << "theme.bgBar: " << formatHexRgb(bgBar) << "\n";
out << "theme.bgHeader: " << formatHexRgb(bgHeader) << "\n";
out << "theme.bgFooter: " << formatHexRgb(bgFooter) << "\n";
out << "theme.bgOverlay: " << formatHexRgb(bgOverlay) << "\n";
out << "theme.bgAltEven: " << formatHexRgb(bgAltEven) << "\n";
out << "theme.bgAltOdd: " << formatHexRgb(bgAltOdd) << "\n";
out << "theme.bgInput: " << formatHexRgb(bgInput) << "\n";
out << "theme.bgInputFocus: " << formatHexRgb(bgInputFocus) << "\n";
out << "theme.bgButton: " << formatHexRgb(bgButton) << "\n";
out << "theme.bgSearch: " << formatHexRgb(bgSearch) << "\n";
out << "theme.bgBubbleIn: " << formatHexRgb(bgBubbleIn) << "\n";
out << "theme.bgBubbleOut: " << formatHexRgb(bgBubbleOut) << "\n";
out << "theme.bgToast: " << formatHexRgb(bgToast) << "\n\n";
out << "theme.fgMain: " << formatHexRgb(fgMain) << "\n";
out << "theme.fgBright: " << formatHexRgb(fgBright) << "\n";
out << "theme.fgMuted: " << formatHexRgb(fgMuted) << "\n\n";
out << "theme.selBg: " << formatHexRgb(selBg) << "\n";
out << "theme.selFg: " << formatHexRgb(selFg) << "\n";
out << "theme.accent: " << formatHexRgb(accent) << "\n";
out << "theme.accentAlt: " << formatHexRgb(accentAlt) << "\n";
out << "theme.highlight: " << formatHexRgb(highlight) << "\n";
out << "theme.border: " << formatHexRgb(border) << "\n";
out << "theme.divider: " << formatHexRgb(divider) << "\n\n";
out << "theme.success: " << formatHexRgb(success) << "\n";
out << "theme.info: " << formatHexRgb(info) << "\n";
out << "theme.warning: " << formatHexRgb(warning) << "\n";
out << "theme.danger: " << formatHexRgb(danger) << "\n";
out << "theme.dangerBg: " << formatHexRgb(dangerBg) << "\n\n";
out << "dmenu.font: " << xftFontStr(sizeLarge()) << "\n";
out << "dmenu.background: " << formatHexRgb(bgHeader) << "\n";
out << "dmenu.foreground: " << formatHexRgb(fgBright) << "\n";
out << "dmenu.selbackground: " << formatHexRgb(selBg) << "\n";
out << "dmenu.selforeground: " << formatHexRgb(selFg) << "\n";
out << "dmenu.outbackground: " << formatHexRgb(bgSearch) << "\n";
out << "dmenu.outforeground: " << formatHexRgb(fgBright) << "\n";
out << "dmenu.highlight: " << formatHexRgb(highlight) << "\n\n";
out << "dwm.font: " << pangoMainFontStr() << "\n";
out << "dwm.background: " << formatHexRgb(bgBar) << "\n";
out << "dwm.foreground: " << formatHexRgb(fgMain) << "\n";
out << "dwm.border: " << formatHexRgb(border) << "\n";
out << "dwm.selbackground: " << formatHexRgb(selBg) << "\n";
out << "dwm.selforeground: " << formatHexRgb(selFg) << "\n";
out << "dwm.selborder: " << formatHexRgb(selBg) << "\n";
out << "dwm.normbgcolor: " << formatHexRgb(bgBar) << "\n";
out << "dwm.normbordercolor: " << formatHexRgb(border) << "\n";
out << "dwm.normfgcolor: " << formatHexRgb(fgMain) << "\n";
out << "dwm.selbgcolor: " << formatHexRgb(selBg) << "\n";
out << "dwm.selbordercolor: " << formatHexRgb(selBg) << "\n";
out << "dwm.selfgcolor: " << formatHexRgb(selFg) << "\n\n";
out << "st.font: " << xftFontStr(sizeLarge()) << "\n";
out << "st.termname: xterm-256color\n";
out << "st.background: " << formatHexRgb(bgHeader) << "\n";
out << "st.foreground: " << formatHexRgb(fgMain) << "\n";
out << "st.cursorColor: " << formatHexRgb(accent) << "\n\n";
out << "svkbd.font: " << fontFace << ":pixelsize=" << sizeSmall() << "\n";
return out.str();
}
bool saveToFile(const std::string& path) const {
std::ofstream out(path, std::ios::trunc);
if (!out.is_open()) return false;
out << serializeXresources();
return true;
}
};
inline ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0) {
ThemeSpec spec;
spec.loadActive(dpy, screen);
return spec;
}
struct PluginTheme {
ThemeSpec spec;
time_t lastXresMtime = -1;
off_t lastXresSize = -1;
bool colorsAllocated = false;
Display* dpy_ = nullptr;
int screen_ = 0;
Visual* visual_ = nullptr;
Colormap cmap_ = 0;
Window win_ = None;
PangoContext* pangoCtx = nullptr;
PangoLayout* layoutMain = nullptr;
PangoLayout* layoutSmall = nullptr;
PangoLayout* layoutIcon = nullptr;
PangoLayout* layoutNum = nullptr;
XftColor colWhite{};
XftColor colLight{};
XftColor colMuted{};
XftColor colYellow{};
XftColor colGreen{};
XftColor colBlue{};
XftColor colOrange{};
XftColor colRed{};
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
XftColor* dst) {
std::string hex = formatHexRgb(rgb);
XftColorAllocName(dpy, visual, cmap, hex.c_str(), dst);
}
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
Window win = None) {
dpy_ = dpy;
screen_ = screen;
visual_ = visual;
cmap_ = cmap;
win_ = win;
if (!pangoCtx && dpy) {
PangoFontMap* fontMap = pango_xft_get_font_map(dpy, screen);
pangoCtx = pango_font_map_create_context(fontMap);
layoutMain = pango_layout_new(pangoCtx);
layoutSmall = pango_layout_new(pangoCtx);
layoutIcon = pango_layout_new(pangoCtx);
layoutNum = pango_layout_new(pangoCtx);
}
reload();
}
void reload() {
if (dpy_ && visual_) {
load(dpy_, screen_, visual_, cmap_, layoutMain, layoutSmall, layoutIcon,
layoutNum, win_);
}
}
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
PangoLayout* lMain = nullptr,
PangoLayout* lSmall = nullptr,
PangoLayout* lIcon = nullptr,
PangoLayout* lNum = nullptr,
Window win = None) {
dpy_ = dpy;
screen_ = screen;
visual_ = visual;
cmap_ = cmap;
if (win != None) win_ = win;
if (lMain) layoutMain = lMain;
if (lSmall) layoutSmall = lSmall;
if (lIcon) layoutIcon = lIcon;
if (lNum) layoutNum = lNum;
struct stat st {};
if (::stat(getXresourcesPath().c_str(), &st) == 0) {
lastXresMtime = st.st_mtim.tv_sec;
lastXresSize = st.st_size;
}
spec = ThemeSpec{};
spec.loadActive(dpy, screen);
if (colorsAllocated) {
XftColorFree(dpy, visual, cmap, &colWhite);
XftColorFree(dpy, visual, cmap, &colLight);
XftColorFree(dpy, visual, cmap, &colMuted);
XftColorFree(dpy, visual, cmap, &colYellow);
XftColorFree(dpy, visual, cmap, &colGreen);
XftColorFree(dpy, visual, cmap, &colBlue);
XftColorFree(dpy, visual, cmap, &colOrange);
XftColorFree(dpy, visual, cmap, &colRed);
}
allocXft(dpy, visual, cmap, spec.fgBright, &colWhite);
allocXft(dpy, visual, cmap, spec.fgMain, &colLight);
allocXft(dpy, visual, cmap, spec.fgMuted, &colMuted);
allocXft(dpy, visual, cmap, spec.accent, &colYellow);
allocXft(dpy, visual, cmap, spec.success, &colGreen);
allocXft(dpy, visual, cmap, spec.info, &colBlue);
allocXft(dpy, visual, cmap, spec.warning, &colOrange);
allocXft(dpy, visual, cmap, spec.danger, &colRed);
colorsAllocated = true;
if (layoutMain) {
PangoFontDescription* d =
pango_font_description_from_string(spec.pangoMainFontStr().c_str());
pango_layout_set_font_description(layoutMain, d);
pango_font_description_free(d);
}
if (layoutSmall) {
PangoFontDescription* d =
pango_font_description_from_string(spec.pangoSmallFontStr().c_str());
pango_layout_set_font_description(layoutSmall, d);
pango_font_description_free(d);
}
if (layoutIcon) {
PangoFontDescription* d =
pango_font_description_from_string(spec.pangoIconFontStr().c_str());
pango_layout_set_font_description(layoutIcon, d);
pango_font_description_free(d);
}
if (layoutNum) {
PangoFontDescription* d = pango_font_description_from_string(
spec.pangoLargeBoldFontStr().c_str());
pango_layout_set_font_description(layoutNum, d);
pango_font_description_free(d);
}
if (win_ != None) {
XSetWindowBackground(dpy, win_, spec.bgMain);
XSetWindowBorder(dpy, win_, spec.selBg);
}
}
bool checkAndReload() {
if (!dpy_ || !visual_) return false;
return checkAndReload(dpy_, screen_, visual_, cmap_, layoutMain,
layoutSmall, layoutIcon, layoutNum, win_);
}
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
PangoLayout* lMain = nullptr,
PangoLayout* lSmall = nullptr,
PangoLayout* lIcon = nullptr,
PangoLayout* lNum = nullptr,
Window win = None) {
struct stat st {};
if (::stat(getXresourcesPath().c_str(), &st) == 0) {
if (st.st_mtim.tv_sec != lastXresMtime || st.st_size != lastXresSize) {
load(dpy, screen, visual, cmap, lMain, lSmall, lIcon, lNum, win);
return true;
}
}
return false;
}
};
} // namespace bananarchy
#include "../neoui/neoui.h"
#endif // DWM_PLUGINS_THEME_H
+15 -80
View File
@@ -315,55 +315,24 @@ int runThemesApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xthemes", "XThemes", "Themes")) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xthemes";
char resClass[] = "XThemes";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Themes");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
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);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PluginTheme pt;
pt.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutSmall = neo.layoutSmall;
PangoLayout* layoutIcon = neo.layoutIcon;
PluginTheme& pt = neo.theme;
auto& colWhite = pt.colWhite;
auto& colLight = pt.colLight;
auto& colMuted = pt.colMuted;
@@ -530,20 +499,7 @@ int runThemesApp(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int dy = y + std::max(0, (h - th) / 2);
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
dy * PANGO_SCALE);
return tw;
return neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto drawSwatch = [&](int x, int y, int w, int h, unsigned long color) {
@@ -556,28 +512,7 @@ int runThemesApp(int argc, char** argv) {
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel) {
const int barY = kWinHeight - 26;
XSetForeground(dpy, gc, pt.spec.bgFooter);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 26);
XSetForeground(dpy, gc, pt.spec.divider);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutMain, &colBlue, 6, barY, 26, leftLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, centerLabel.c_str(),
static_cast<int>(centerLabel.size()));
int cw = 0, chh = 0;
pango_layout_get_pixel_size(layoutMain, &cw, &chh);
drawPango(layoutMain, &colWhite, (kWinWidth - cw) / 2, barY, 26,
centerLabel);
pango_layout_set_width(layoutMain, -1);
pango_layout_set_text(layoutMain, rightLabel.c_str(),
static_cast<int>(rightLabel.size()));
int rw = 0, rhh = 0;
pango_layout_get_pixel_size(layoutMain, &rw, &rhh);
drawPango(layoutMain, &colLight, kWinWidth - rw - 6, barY, 26, rightLabel);
neo.drawSoftbar(leftLabel, centerLabel, rightLabel, &colWhite);
};
auto drawUI = [&]() {
+14 -69
View File
@@ -221,50 +221,22 @@ int runWallpapersApp(int argc, char** argv) {
sigaction(SIGINT, &sa, nullptr);
sigaction(SIGTERM, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
NeoWindow neo;
if (!neo.create("xwallpapers", "XWallpapers", "Wallpapers",
kWinX, kWinY, kWinWidth, kWinHeight)) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
ThemeSpec initSpec;
initSpec.loadActive(dpy, screen);
XSetWindowAttributes swa {};
swa.override_redirect = True;
swa.background_pixel = initSpec.bgMain;
swa.border_pixel = initSpec.selBg;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
VisibilityChangeMask | StructureNotifyMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch {};
char resName[] = "xwallpapers";
char resClass[] = "XWallpapers";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "Wallpapers");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight,
DefaultDepth(dpy, screen));
GC gc = XCreateGC(dpy, pix, 0, nullptr);
XftDraw* xftDraw = XftDrawCreate(dpy, pix, visual, cmap);
PluginTheme pt;
pt.init(dpy, screen, visual, cmap, win);
auto& layoutMain = pt.layoutMain;
auto& layoutSmall = pt.layoutSmall;
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PluginTheme& pt = neo.theme;
auto& layoutMain = neo.layoutMain;
auto& layoutSmall = neo.layoutSmall;
auto& colWhite = pt.colWhite;
auto& colLight = pt.colLight;
auto& colMuted = pt.colMuted;
@@ -355,35 +327,13 @@ int runWallpapersApp(int argc, char** argv) {
int h, const std::string& text, int maxW = -1,
int align = 0) {
if (text.empty()) return;
pango_layout_set_text(layout, text.c_str(), -1);
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
}
int tw = 0, th = 0;
pango_layout_get_pixel_size(layout, &tw, &th);
int tx = x;
if (align == 1 && maxW > 0) tx = x + (maxW - tw) / 2;
else if (align == 2 && maxW > 0) tx = x + maxW - tw;
int ty = y + (h - th) / 2;
pango_xft_render_layout(xftDraw, color, layout, tx * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW, align);
};
auto drawSoftkeyBar = [&](const std::string& leftLabel,
const std::string& midLabel,
const std::string& rightLabel) {
int barY = kWinHeight - 24;
XSetForeground(dpy, gc, pt.spec.bgHeader);
XFillRectangle(dpy, pix, gc, 0, barY, kWinWidth, 24);
XSetForeground(dpy, gc, pt.spec.border);
XDrawLine(dpy, pix, gc, 0, barY, kWinWidth, barY);
drawPango(layoutSmall, &colLight, 6, barY, 24, leftLabel, 76, 0);
drawPango(layoutMain, &colYellow, 82, barY, 24, midLabel, 76, 1);
drawPango(layoutSmall, &colLight, 158, barY, 24, rightLabel, 76, 2);
neo.drawSoftbar(leftLabel, midLabel, rightLabel, &colYellow, 24);
};
auto render = [&]() {
@@ -737,11 +687,6 @@ int runWallpapersApp(int argc, char** argv) {
}
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
if (xftDraw) XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}
+3044
View File
File diff suppressed because it is too large. Load diff
+575
View File
@@ -0,0 +1,575 @@
// SPDX-License-Identifier: GPL-2.0-only
// NeoUI - Bananarchy 240x320 X11 + Pango/Xft + .Xresources/.xth UI SDK
// Provides both a C-compatible FFI (libneoui.so) and C++20 SDK classes.
// Note: Every extern "C" function returns int, uint32_t, or const char* (never
// void) so that FFI callers such as Yabasic frnfn_call / frnfn_call$ work
// directly without void-return limitations.
#ifndef BANANARCHY_NEOUI_H
#define BANANARCHY_NEOUI_H
#include <stdint.h>
#ifdef __cplusplus
#include <X11/Xatom.h>
#include <X11/Xft/Xft.h>
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <X11/Xutil.h>
#include <pango/pango.h>
#include <pango/pangoxft.h>
#include <string>
#include <unordered_map>
#include <vector>
extern "C" {
#endif
// Standard Bananarchy 240x320 QVGA geometry constants
enum NeoGeometry {
NEO_SCREEN_W = 240,
NEO_SCREEN_H = 320,
NEO_TOPBAR_H = 24,
NEO_WIN_X = 0,
NEO_WIN_Y = 24,
NEO_WIN_W = 240,
NEO_WIN_H = 296,
NEO_HEADER_H = 34,
NEO_SOFTBAR_H = 26
};
// Theme color token IDs for neoui_color(color_id)
enum NeoColorId {
NEO_COLOR_BG_MAIN = 0,
NEO_COLOR_BG_BAR = 1,
NEO_COLOR_BG_HEADER = 2,
NEO_COLOR_BG_FOOTER = 3,
NEO_COLOR_BG_OVERLAY = 4,
NEO_COLOR_BG_ALT_EVEN = 5,
NEO_COLOR_BG_ALT_ODD = 6,
NEO_COLOR_BG_INPUT = 7,
NEO_COLOR_BG_INPUT_FOCUS = 8,
NEO_COLOR_BG_BUTTON = 9,
NEO_COLOR_BG_SEARCH = 10,
NEO_COLOR_BG_BUBBLE_IN = 11,
NEO_COLOR_BG_BUBBLE_OUT = 12,
NEO_COLOR_BG_TOAST = 13,
NEO_COLOR_FG_MAIN = 14,
NEO_COLOR_FG_BRIGHT = 15,
NEO_COLOR_FG_MUTED = 16,
NEO_COLOR_SEL_BG = 17,
NEO_COLOR_SEL_FG = 18,
NEO_COLOR_ACCENT = 19,
NEO_COLOR_ACCENT_ALT = 20,
NEO_COLOR_HIGHLIGHT = 21,
NEO_COLOR_BORDER = 22,
NEO_COLOR_DIVIDER = 23,
NEO_COLOR_SUCCESS = 24,
NEO_COLOR_INFO = 25,
NEO_COLOR_WARNING = 26,
NEO_COLOR_DANGER = 27,
NEO_COLOR_DANGER_BG = 28
};
// Proportional Pango font roles
enum NeoFontRole {
NEO_FONT_SMALL = 0,
NEO_FONT_MAIN = 1,
NEO_FONT_ICON = 2,
NEO_FONT_LARGE = 3
};
// Semantic Xft text color roles
enum NeoTextColor {
NEO_TEXT_WHITE = 0,
NEO_TEXT_LIGHT = 1,
NEO_TEXT_MUTED = 2,
NEO_TEXT_YELLOW = 3,
NEO_TEXT_GREEN = 4,
NEO_TEXT_BLUE = 5,
NEO_TEXT_ORANGE = 6,
NEO_TEXT_RED = 7
};
// Event types returned by neoui_poll_event(timeout_ms)
enum NeoEventType {
NEO_EV_NONE = 0,
NEO_EV_EXPOSE = 1,
NEO_EV_KEY_PRESS = 2,
NEO_EV_KEY_RELEASE = 3,
NEO_EV_SOFTKEY_LEFT = 4,
NEO_EV_SOFTKEY_RIGHT = 5,
NEO_EV_SOFTKEY_CHORD = 6,
NEO_EV_FIFO_CMD = 7,
NEO_EV_THEME_RELOAD = 8,
NEO_EV_CLOSE_REQ = 9
};
// Logical keypad key codes returned by neoui_event_key()
enum NeoKey {
NEO_KEY_NONE = 0,
NEO_KEY_UP = 1,
NEO_KEY_DOWN = 2,
NEO_KEY_LEFT = 3,
NEO_KEY_RIGHT = 4,
NEO_KEY_OK = 5,
NEO_KEY_BACK = 6,
NEO_KEY_CALL = 7,
NEO_KEY_END = 8,
NEO_KEY_SOFT_LEFT = 9,
NEO_KEY_SOFT_RIGHT = 10,
NEO_KEY_SPACE = 32,
NEO_KEY_HASH = 35,
NEO_KEY_STAR = 42,
NEO_KEY_PLUS = 43,
NEO_KEY_0 = 48,
NEO_KEY_1 = 49,
NEO_KEY_2 = 50,
NEO_KEY_3 = 51,
NEO_KEY_4 = 52,
NEO_KEY_5 = 53,
NEO_KEY_6 = 54,
NEO_KEY_7 = 55,
NEO_KEY_8 = 56,
NEO_KEY_9 = 57
};
// Multi-tap input modes
enum NeoInputMode {
NEO_INPUT_ABC_TITLE = 0,
NEO_INPUT_ABC_LOWER = 1,
NEO_INPUT_ABC_UPPER = 2,
NEO_INPUT_123 = 3,
NEO_INPUT_SYM = 4
};
// Image scaling modes for neoui_draw_image_file
enum NeoScaleMode {
NEO_SCALE_FIT = 0,
NEO_SCALE_FILL = 1,
NEO_SCALE_STRETCH = 2
};
// Opaque C context handle
typedef struct NeoContext NeoContext;
// ---------------------------------------------------------------------------
// 1. Window & Daemon Lifecycle
// ---------------------------------------------------------------------------
int neoui_init(const char* app_name, int preload_mode);
int neoui_init_ex(const char* app_name, const char* res_name,
const char* res_class, const char* win_title,
int x, int y, int w, int h,
int override_redirect, int preload_mode);
int neoui_shutdown(void);
int neoui_show(void);
int neoui_hide(void);
int neoui_is_visible(void);
int neoui_raise_and_grab(void);
int neoui_ungrab(void);
int neoui_width(void);
int neoui_height(void);
int neoui_begin_frame(void);
int neoui_end_frame(void);
int neoui_flush(void);
// ---------------------------------------------------------------------------
// 2. Unified .Xresources / .xth Theme & Icon Resolution
// ---------------------------------------------------------------------------
int neoui_reload_theme(void);
int neoui_check_reload_theme(void);
int neoui_apply_theme_file(const char* xth_path);
int neoui_broadcast_theme_reload(const char* skip_plugin);
const char* neoui_theme_name(void);
const char* neoui_font_face(void);
const char* neoui_icon_font_face(void);
int neoui_base_font_size(void);
int neoui_font_size(int font_role);
uint32_t neoui_color(int color_id);
uint32_t neoui_adjust_rgb(uint32_t rgb, int delta);
uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct);
uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb);
const char* neoui_format_hex_rgb(uint32_t rgb);
const char* neoui_icon(const char* icon_name);
// ---------------------------------------------------------------------------
// 3. Drawing Primitives & Text Rendering
// ---------------------------------------------------------------------------
int neoui_clear(uint32_t rgb);
int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb);
int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb);
int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb);
int neoui_set_clip(int x, int y, int w, int h);
int neoui_reset_clip(void);
int neoui_draw_text(int font_role, int color_role, int x, int y, int h,
const char* text, int max_w);
int neoui_draw_text_centered(int font_role, int color_role, int x, int y,
int w, int h, const char* text);
int neoui_draw_text_right(int font_role, int color_role, int right_x, int y,
int h, const char* text, int max_w);
int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y,
int w, int h, const char* text, int scroll_line);
int neoui_text_width(int font_role, const char* text);
const char* neoui_tail_fit_text(int font_role, const char* text, int max_w);
int neoui_draw_image_file(const char* path, int x, int y, int w, int h,
int scale_mode);
// ---------------------------------------------------------------------------
// 4. Standardized OS Shell UI Components (Widgets)
// ---------------------------------------------------------------------------
int neoui_draw_header(const char* icon_str, int icon_color_role,
const char* title, const char* right_badge);
int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role,
const char* title, int title_color_role,
const char* right_badge, int right_color_role);
int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h);
int neoui_draw_softkeys(const char* left_label, const char* center_label,
const char* right_label);
int neoui_draw_softkeys_ex(const char* left_label, const char* center_label,
const char* right_label, int center_color_role);
int neoui_draw_list_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* title, const char* subtitle,
const char* right_text);
int neoui_draw_slider_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* label, int pct, const char* value_text);
int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* label, int is_on,
const char* state_text);
int neoui_draw_button(int x, int y, int w, int h, int is_selected,
int is_danger, const char* icon_str, const char* label);
int neoui_draw_input_box(int x, int y, int w, int h, int is_focused,
const char* label, const char* value,
const char* placeholder, int password_mask);
int neoui_draw_progress_bar(int x, int y, int w, int h, int pct,
uint32_t fill_rgb);
int neoui_draw_scrollbar(int x, int y, int h, int total_items,
int visible_items, int scroll_offset);
int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str,
int icon_color_role, const char* title);
int neoui_draw_confirm_dialog(const char* title, const char* line1,
const char* line2, const char* no_label,
const char* yes_label, int selected_yes);
int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons,
int selected_idx, int max_visible_rows);
int neoui_draw_toast(const char* message);
int neoui_show_toast(const char* message, int duration_ms);
int neoui_clear_toast(void);
// ---------------------------------------------------------------------------
// 5. Event Loop, Keypad & Multi-Tap Input Management
// ---------------------------------------------------------------------------
int neoui_poll_event(int timeout_ms);
int neoui_event_key(void);
int neoui_event_keycode(void);
int neoui_event_keysym(void);
const char* neoui_event_command(void);
int neoui_set_chord_xdrawer(int enabled);
int neoui_input_reset(const char* initial_text);
int neoui_input_set_text(const char* text);
const char* neoui_input_get_text(void);
int neoui_input_set_mode(int mode);
int neoui_input_get_mode(void);
int neoui_input_cycle_mode(void);
const char* neoui_input_mode_badge(void);
int neoui_input_feed_key(int neo_key);
int neoui_input_commit_tap(void);
int neoui_input_backspace(void);
int neoui_input_is_tap_active(void);
const char* neoui_input_candidate_bar(const char* idle_hint);
int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint);
// ---------------------------------------------------------------------------
// 6. System & IPC Utilities
// ---------------------------------------------------------------------------
int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd);
int neoui_vibrate(int duration_ms);
int neoui_now_ms(void);
#ifdef __cplusplus
} // extern "C"
namespace bananarchy {
std::string themeTrim(const std::string& s);
int themeHexNibble(char c);
bool parseHexRgb(const std::string& raw, uint32_t* outRgb);
std::string formatHexRgb(uint32_t rgb);
uint32_t adjustRgb(uint32_t rgb, int delta);
uint32_t blendRgb(uint32_t c1, uint32_t c2, int weight2Pct);
std::string getHomeDirPath();
std::string getXresourcesPath();
std::string getThemesDirPath();
struct ThemeSpec {
std::string name = "Default";
std::string fontFace = "Fira Code";
std::string iconFontFace = "DejaVuSansM Nerd Font";
int baseFontSize = 15;
uint32_t bgMain = 0x222222;
uint32_t bgBar = 0x222222;
uint32_t bgHeader = 0x1c1c1c;
uint32_t bgFooter = 0x181818;
uint32_t bgOverlay = 0x161616;
uint32_t bgAltEven = 0x282828;
uint32_t bgAltOdd = 0x2e2e2e;
uint32_t bgInput = 0x1a1a1a;
uint32_t bgInputFocus = 0x1b3b4b;
uint32_t bgButton = 0x2a2a2a;
uint32_t bgSearch = 0x383838;
uint32_t bgBubbleIn = 0x262d32;
uint32_t bgBubbleOut = 0x1f2d38;
uint32_t bgToast = 0x102535;
uint32_t fgMain = 0xdddddd;
uint32_t fgBright = 0xffffff;
uint32_t fgMuted = 0x999999;
uint32_t selBg = 0x005577;
uint32_t selFg = 0xffffff;
uint32_t accent = 0xf4d03f;
uint32_t accentAlt = 0x0088bb;
uint32_t highlight = 0xffc978;
uint32_t border = 0x444444;
uint32_t divider = 0x666666;
uint32_t success = 0x2ecc71;
uint32_t info = 0x5dade2;
uint32_t warning = 0xe67e22;
uint32_t danger = 0xe74c3c;
uint32_t dangerBg = 0x922b21;
int sizeSmall() const;
int sizeMain() const;
int sizeIcon() const;
int sizeLarge() const;
std::string pangoMainFontStr() const;
std::string pangoSmallFontStr() const;
std::string pangoIconFontStr() const;
std::string pangoLargeBoldFontStr() const;
std::string xftFontStr(int pxSize) const;
std::string xftIconFontStr(int pxSize) const;
void recomputeDerivedFromCore();
void parseFromMap(const std::unordered_map<std::string, std::string>& kv);
static void parseLinesIntoMap(
const std::string& content,
std::unordered_map<std::string, std::string>& kv);
bool loadFromFile(const std::string& path);
void loadActive(Display* dpy, int screen);
std::string serializeXresources() const;
bool saveToFile(const std::string& path) const;
uint32_t colorById(int colorId) const;
};
ThemeSpec loadThemeSpec(Display* dpy = nullptr, int screen = 0);
struct PluginTheme {
ThemeSpec spec;
time_t lastXresMtime = -1;
off_t lastXresSize = -1;
bool colorsAllocated = false;
Display* dpy_ = nullptr;
int screen_ = 0;
Visual* visual_ = nullptr;
Colormap cmap_ = 0;
Window win_ = None;
PangoContext* pangoCtx = nullptr;
PangoLayout* layoutMain = nullptr;
PangoLayout* layoutSmall = nullptr;
PangoLayout* layoutIcon = nullptr;
PangoLayout* layoutNum = nullptr;
XftColor colWhite{};
XftColor colLight{};
XftColor colMuted{};
XftColor colYellow{};
XftColor colGreen{};
XftColor colBlue{};
XftColor colOrange{};
XftColor colRed{};
void allocXft(Display* dpy, Visual* visual, Colormap cmap, uint32_t rgb,
XftColor* dst);
void init(Display* dpy, int screen, Visual* visual, Colormap cmap,
Window win = None);
void reload();
void load(Display* dpy, int screen, Visual* visual, Colormap cmap,
PangoLayout* lMain = nullptr, PangoLayout* lSmall = nullptr,
PangoLayout* lIcon = nullptr, PangoLayout* lNum = nullptr,
Window win = None);
bool checkAndReload();
bool checkAndReload(Display* dpy, int screen, Visual* visual, Colormap cmap,
PangoLayout* lMain = nullptr,
PangoLayout* lSmall = nullptr,
PangoLayout* lIcon = nullptr,
PangoLayout* lNum = nullptr,
Window win = None);
XftColor* colorByRole(int role);
PangoLayout* layoutByRole(int role);
};
// Shared Pango rendering & layout helpers in libneoui.so
int neoDrawPango(XftDraw* xftDraw, PangoLayout* layout, XftColor* color,
int x, int y, int h, const std::string& text,
int maxW = -1, int align = 0);
int neoPangoWidth(PangoLayout* layout, const std::string& text);
void neoDrawSoftbar(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
PluginTheme& theme, int winW, int winH, int softbarH,
const std::string& leftLabel,
const std::string& centerLabel,
const std::string& rightLabel,
XftColor* centerCol = nullptr);
void neoDrawScrollbar(Display* dpy, Pixmap pix, GC gc, const PluginTheme& theme,
int x, int y, int h, int totalItems, int visibleItems,
int scrollOffset);
void neoDrawToast(Display* dpy, Pixmap pix, GC gc, XftDraw* xftDraw,
PluginTheme& theme, int winW, int winH, int softbarH,
const std::string& msg);
std::string formatMultiTapBar(const std::string& prefix, const char* table,
int activeIdx, bool makeUpper, int maxItems = 7,
size_t maxChars = 21);
std::string tailFitPangoText(PangoLayout* layout, const std::string& text,
int maxWidthPx);
// Shared image & media helpers in libneoui.so
bool saveRgb24AsJpeg(const std::string& path, const uint8_t* rgb, int width,
int height, int quality = 92);
bool loadJpegRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
int* outW, int* outH);
bool loadPngRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
int* outW, int* outH);
bool loadFfmpegImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
int* outW, int* outH);
bool loadImageRgb24(const std::string& path, std::vector<uint8_t>* outRgb,
int* outW, int* outH);
void scaleRgb24ToBgrxCanvas(const uint8_t* srcRgb, int srcW, int srcH,
uint32_t* dstBgrx, int canvasW, int canvasH,
uint32_t bgPixel = 0x111111,
int scaleMode = NEO_SCALE_FIT);
void downscaleViewfinder800x600To240x180(const uint8_t* srcRgb,
uint32_t* dstBgrx,
int zoomFactor = 1);
std::string formatFileSize(off_t bytes);
// High-level C++ RAII Window + Theme + Offscreen Pixmap + Pango Context
class NeoWindow {
public:
Display* dpy = nullptr;
int screen = 0;
Window root = None;
Visual* visual = nullptr;
Colormap cmap = 0;
Window win = None;
Pixmap pix = None;
GC gc = nullptr;
XftDraw* xftDraw = nullptr;
PangoContext* pangoCtx = nullptr;
PangoLayout* layoutMain = nullptr;
PangoLayout* layoutSmall = nullptr;
PangoLayout* layoutIcon = nullptr;
PangoLayout* layoutNum = nullptr;
PluginTheme theme;
int x = NEO_WIN_X;
int y = NEO_WIN_Y;
int width = NEO_WIN_W;
int height = NEO_WIN_H;
NeoWindow() = default;
~NeoWindow();
NeoWindow(const NeoWindow&) = delete;
NeoWindow& operator=(const NeoWindow&) = delete;
bool create(const char* resName, const char* resClass, const char* title,
int winX = NEO_WIN_X, int winY = NEO_WIN_Y,
int winW = NEO_WIN_W, int winH = NEO_WIN_H,
bool overrideRedirect = true,
long eventMask = ExposureMask | KeyPressMask | KeyReleaseMask |
ButtonPressMask | VisibilityChangeMask |
StructureNotifyMask);
void destroy();
void bindAsActiveContext();
int drawPango(PangoLayout* layout, XftColor* color, int px, int py, int ph,
const std::string& text, int maxW = -1, int align = 0) {
return neoDrawPango(xftDraw, layout, color, px, py, ph, text, maxW, align);
}
int pangoWidth(PangoLayout* layout, const std::string& text) {
return neoPangoWidth(layout, text);
}
void drawSoftbar(const std::string& leftLabel, const std::string& centerLabel,
const std::string& rightLabel, XftColor* centerCol = nullptr,
int softbarH = NEO_SOFTBAR_H) {
neoDrawSoftbar(dpy, pix, gc, xftDraw, theme, width, height, softbarH,
leftLabel, centerLabel, rightLabel, centerCol);
}
void drawScrollbar(int sx, int sy, int sh, int totalItems, int visibleItems,
int scrollOffset) {
neoDrawScrollbar(dpy, pix, gc, theme, sx, sy, sh, totalItems, visibleItems,
scrollOffset);
}
void drawToast(const std::string& msg, int softbarH = NEO_SOFTBAR_H) {
neoDrawToast(dpy, pix, gc, xftDraw, theme, width, height, softbarH, msg);
}
void clearBg() {
if (dpy && pix != None && gc) {
XSetForeground(dpy, gc, theme.spec.bgMain);
XFillRectangle(dpy, pix, gc, 0, 0, width, height);
}
}
void present() {
if (dpy && pix != None && win != None && gc) {
XCopyArea(dpy, pix, win, gc, 0, 0, width, height, 0, 0);
XFlush(dpy);
}
}
bool checkReloadTheme() {
return theme.checkAndReload(dpy, screen, visual, cmap, layoutMain,
layoutSmall, layoutIcon, layoutNum, win);
}
void reloadTheme() {
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
layoutNum, win);
}
};
} // namespace bananarchy
#endif // __cplusplus
#endif // BANANARCHY_NEOUI_H
+16 -68
View File
@@ -675,51 +675,25 @@ static int xdrawer_run_main(int argc, char** argv) {
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGINT, &sa, nullptr);
Display* dpy = XOpenDisplay(nullptr);
if (!dpy) {
bananarchy::NeoWindow neo;
if (!neo.create("xdrawer", "XDrawer", "XDrawer", kWinX, kWinY, kWinWidth,
kWinHeight, true)) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(daemonPidPath.c_str());
return 1;
}
int screen = DefaultScreen(dpy);
Window root = RootWindow(dpy, screen);
Visual* visual = DefaultVisual(dpy, screen);
Colormap cmap = DefaultColormap(dpy, screen);
XSetWindowAttributes swa{};
swa.override_redirect = True;
swa.background_pixel = 0x222222;
swa.border_pixel = 0xf4d03f;
swa.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask |
StructureNotifyMask | VisibilityChangeMask;
Window win = XCreateWindow(
dpy, root, kWinX, kWinY, kWinWidth, kWinHeight, 0,
DefaultDepth(dpy, screen), CopyFromParent, visual,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask, &swa);
XClassHint ch{};
char resName[] = "xdrawer";
char resClass[] = "XDrawer";
ch.res_name = resName;
ch.res_class = resClass;
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, "XDrawer");
Pixmap pix = XCreatePixmap(dpy, win, kWinWidth, kWinHeight, DefaultDepth(dpy, screen));
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);
PangoLayout* layoutIcon = pango_layout_new(pangoCtx);
PangoLayout* layoutSmall = pango_layout_new(pangoCtx);
bananarchy::PluginTheme theme;
theme.load(dpy, screen, visual, cmap, layoutMain, layoutSmall, layoutIcon,
nullptr, win);
Display* dpy = neo.dpy;
int screen = neo.screen;
Visual* visual = neo.visual;
Colormap cmap = neo.cmap;
Window win = neo.win;
Pixmap pix = neo.pix;
GC gc = neo.gc;
PangoLayout* layoutMain = neo.layoutMain;
PangoLayout* layoutIcon = neo.layoutIcon;
PangoLayout* layoutSmall = neo.layoutSmall;
bananarchy::PluginTheme& theme = neo.theme;
XftColor& colWhite = theme.colWhite;
XftColor& colLight = theme.colLight;
XftColor& colMuted = theme.colMuted;
@@ -735,27 +709,11 @@ static int xdrawer_run_main(int argc, char** argv) {
auto drawPango = [&](PangoLayout* layout, XftColor* color, int x, int y, int h,
const std::string& text, int maxW = -1) {
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
if (maxW > 0) {
pango_layout_set_width(layout, maxW * PANGO_SCALE);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
} else {
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
}
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
int ty = y + (h - logical.height) / 2;
pango_xft_render_layout(xftDraw, color, layout, x * PANGO_SCALE,
ty * PANGO_SCALE);
neo.drawPango(layout, color, x, y, h, text, maxW);
};
auto pangoWidth = [&](PangoLayout* layout, const std::string& text) -> int {
pango_layout_set_width(layout, -1);
pango_layout_set_text(layout, text.c_str(), static_cast<int>(text.size()));
PangoRectangle ink{}, logical{};
pango_layout_get_pixel_extents(layout, &ink, &logical);
return logical.width;
return neo.pangoWidth(layout, text);
};
auto render = [&]() {
@@ -1153,16 +1111,6 @@ static int xdrawer_run_main(int argc, char** argv) {
if (fifoFd >= 0) ::close(fifoFd);
::unlink(fifoPath.c_str());
::unlink(daemonPidPath.c_str());
g_object_unref(layoutSmall);
g_object_unref(layoutIcon);
g_object_unref(layoutMain);
g_object_unref(pangoCtx);
XftDrawDestroy(xftDraw);
XFreeGC(dpy, gc);
XFreePixmap(dpy, pix);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return 0;
}