Backport WM/dmenu xerror & UTF-8 fixes, add wallpaper manager, and set Anodized default
- wm,dmenu: backport ANODE a92e196 fixes for xerror recursion guards, non-fatal RENDER error suppression, bounded getservertime() polling, pointer ungrab/AsyncBoth/GrabModeAsync grab safety, FC_COLOR=FcFalse substitution, and UTF-8 sanitization + Pango ellipsization in drw.c - wallpaper: port native X11 + Cairo wallpaper engine (geminux-wallpaper.h, geminux-wallpaper-x11.h) with pure-C gdk-pixbuf/PNG/JPEG/WebP/magick decoding, Wallpaper tab + CLI in geminux-themes, geminux-apply-wallpaper helper, and session/theme/HDMI/launcher hooks - theme: set Anodized as default theme in /etc/skel/.Xresources and compiled-in/script fallbacks across libgemui, dwm, dmenu, st, webarchy, geminux-sync-gtk-theme, and geminux-sync-dunst-theme - verify: extend check-rebuild.sh and test-theme-dunst-sync.py, prune stale skel theme artifacts in apply-geminux-overlay.sh, and rebuild prebuilt binaries
This commit is contained in:
1 parent
6fcc263256
commit
09c1e2ad36
32 files changed
+2852
-304
No files matched your search
@@ -9,9 +9,9 @@ static const char *fonts[] = {
|
||||
static const char *prompt = NULL;
|
||||
static const char *colors[SchemeLast][2] = {
|
||||
/* fg bg */
|
||||
[SchemeNorm] = { "#e6e1cf", "#0b0e14" },
|
||||
[SchemeSel] = { "#ffffff", "#2b5278" },
|
||||
[SchemeOut] = { "#ffffff", "#243040" },
|
||||
[SchemeNorm] = { "#e4e8ee", "#12151a" },
|
||||
[SchemeSel] = { "#f5f7fa", "#38414f" },
|
||||
[SchemeOut] = { "#cfd6e0", "#191e27" },
|
||||
};
|
||||
static unsigned int lines = 12;
|
||||
static unsigned int lineheight = 82;
|
||||
|
||||
@@ -64,6 +64,34 @@ static char xres_font[256] = "";
|
||||
static char *dyn_colors[SchemeLast][2] = { {NULL, NULL}, {NULL, NULL}, {NULL, NULL} };
|
||||
static Cursor vpointer = None, bpointer = None;
|
||||
static int pointer_hidden = 0, xi_opcode = -1, xfixes_ok = 0;
|
||||
static int dmenu_render_opcode = -1;
|
||||
static int (*dmenu_xerror_prev)(Display *, XErrorEvent *) = NULL;
|
||||
|
||||
static int dmenu_xerror(Display *disp, XErrorEvent *ee) {
|
||||
if (ee->error_code == BadWindow || ee->error_code == BadDrawable)
|
||||
return 0;
|
||||
if (dmenu_render_opcode > 0 && ee->request_code == dmenu_render_opcode) {
|
||||
static unsigned int render_err_logged = 0;
|
||||
if (render_err_logged < 8) {
|
||||
render_err_logged++;
|
||||
fprintf(stderr, "dmenu: ignoring non-fatal RENDER error: minor=%d, error=%d\n",
|
||||
ee->minor_code, ee->error_code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
static int in_xerror = 0;
|
||||
if (in_xerror) return 0;
|
||||
in_xerror = 1;
|
||||
if (dmenu_xerror_prev && dmenu_xerror_prev != dmenu_xerror) {
|
||||
int rc = dmenu_xerror_prev(disp, ee);
|
||||
in_xerror = 0;
|
||||
return rc;
|
||||
}
|
||||
in_xerror = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#include "config.h"
|
||||
|
||||
@@ -964,6 +992,14 @@ int main(int argc, char *argv[]) {
|
||||
fputs("warning: no locale support\n", stderr);
|
||||
if (!(dpy = XOpenDisplay(NULL)))
|
||||
die("cannot open display");
|
||||
{
|
||||
int (*prev_err)(Display *, XErrorEvent *) = XSetErrorHandler(dmenu_xerror);
|
||||
if (prev_err && prev_err != dmenu_xerror)
|
||||
dmenu_xerror_prev = prev_err;
|
||||
int rev = 0, rerr = 0;
|
||||
if (!XQueryExtension(dpy, "RENDER", &dmenu_render_opcode, &rev, &rerr))
|
||||
dmenu_render_opcode = -1;
|
||||
}
|
||||
screen = DefaultScreen(dpy);
|
||||
root = RootWindow(dpy, screen);
|
||||
|
||||
|
||||
+141
-35
@@ -1,9 +1,11 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Pango + HarfBuzz + Xft drawing backend for Geminux dmenu */
|
||||
#include <hb.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
@@ -12,6 +14,84 @@
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef FC_COLOR
|
||||
static void drw_fc_substitute(FcPattern *pattern, gpointer data) {
|
||||
(void)data;
|
||||
FcPatternDel(pattern, FC_COLOR);
|
||||
FcPatternAddBool(pattern, FC_COLOR, FcFalse);
|
||||
}
|
||||
#endif
|
||||
|
||||
static size_t drw_sanitize_utf8(char *dst, size_t dst_sz, const char *src, size_t src_len) {
|
||||
if (!dst || dst_sz == 0) return 0;
|
||||
if (!src) {
|
||||
dst[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
size_t i = 0, o = 0;
|
||||
while (i < src_len && o + 1 < dst_sz) {
|
||||
unsigned char c = (unsigned char)src[i];
|
||||
if (c == '\0') break;
|
||||
if (c < 0x80) {
|
||||
dst[o++] = (char)c;
|
||||
i++;
|
||||
} else if (c >= 0xC2 && c <= 0xDF) {
|
||||
if (i + 1 < src_len && ((unsigned char)src[i + 1] & 0xC0) == 0x80) {
|
||||
if (o + 2 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = src[i + 1];
|
||||
i += 2;
|
||||
} else {
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
}
|
||||
} else if (c >= 0xE0 && c <= 0xEF) {
|
||||
if (i + 2 < src_len) {
|
||||
unsigned char c1 = (unsigned char)src[i + 1];
|
||||
unsigned char c2 = (unsigned char)src[i + 2];
|
||||
int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80);
|
||||
if (ok && c == 0xE0 && c1 < 0xA0) ok = 0;
|
||||
if (ok && c == 0xED && c1 > 0x9F) ok = 0;
|
||||
if (ok) {
|
||||
if (o + 3 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = (char)c1;
|
||||
dst[o++] = (char)c2;
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
} else if (c >= 0xF0 && c <= 0xF4) {
|
||||
if (i + 3 < src_len) {
|
||||
unsigned char c1 = (unsigned char)src[i + 1];
|
||||
unsigned char c2 = (unsigned char)src[i + 2];
|
||||
unsigned char c3 = (unsigned char)src[i + 3];
|
||||
int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80);
|
||||
if (ok && c == 0xF0 && c1 < 0x90) ok = 0;
|
||||
if (ok && c == 0xF4 && c1 > 0x8F) ok = 0;
|
||||
if (ok) {
|
||||
if (o + 4 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = (char)c1;
|
||||
dst[o++] = (char)c2;
|
||||
dst[o++] = (char)c3;
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
} else {
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
dst[o] = '\0';
|
||||
return o;
|
||||
}
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
drw->dpy = dpy;
|
||||
@@ -54,6 +134,14 @@ Fnt *drw_fontset_create(Drw *drw, const char *fonts[], size_t fontcount) {
|
||||
|
||||
fnt->dpy = drw->dpy;
|
||||
fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
|
||||
#ifdef FC_COLOR
|
||||
#if PANGO_VERSION_CHECK(1, 48, 0)
|
||||
pango_fc_font_map_set_default_substitute(PANGO_FC_FONT_MAP(fnt->fontmap),
|
||||
drw_fc_substitute, NULL, NULL);
|
||||
#else
|
||||
pango_xft_set_default_substitute(drw->dpy, drw->screen, drw_fc_substitute, NULL, NULL);
|
||||
#endif
|
||||
#endif
|
||||
fnt->context = pango_font_map_create_context(fnt->fontmap);
|
||||
fnt->desc = pango_font_description_from_string(spec);
|
||||
pango_context_set_font_description(fnt->context, fnt->desc);
|
||||
@@ -119,14 +207,14 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
int orig_x = x;
|
||||
unsigned int orig_w = w;
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
unsigned int ew = 0, eh = 0;
|
||||
XftDraw *d = NULL;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~0;
|
||||
w = ~0U;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
@@ -137,32 +225,36 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
w = (w > lpad) ? (w - lpad) : 0;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||
memcpy(buf, text, len);
|
||||
buf[len] = '\0';
|
||||
size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, strlen(text));
|
||||
|
||||
if (len > 0 && w > 0) {
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
while (len > 3 && ew > w) {
|
||||
len--;
|
||||
while (len > 0 && (buf[len] & 0xc0) == 0x80) len--;
|
||||
if (len >= 3) memcpy(buf + len - 3, "...", 3);
|
||||
buf[len] = '\0';
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
if (slen > 0 && w > 0) {
|
||||
if (!render) {
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)slen, &ew, &eh);
|
||||
x += (int)ew;
|
||||
} else if (d) {
|
||||
PangoLayout *layout = drw->fonts->layout;
|
||||
PangoRectangle r;
|
||||
int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE))
|
||||
? (INT_MAX / PANGO_SCALE) : (int)w;
|
||||
pango_layout_set_single_paragraph_mode(layout, TRUE);
|
||||
pango_layout_set_width(layout, max_w * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
pango_layout_set_text(layout, buf, (int)slen);
|
||||
pango_layout_get_extents(layout, NULL, &r);
|
||||
ew = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
eh = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (eh == 0) eh = drw->fonts->h;
|
||||
if (ew <= w || w >= 12) {
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
}
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_single_paragraph_mode(layout, FALSE);
|
||||
x += (int)ew;
|
||||
}
|
||||
if (ew > w) {
|
||||
len = 0;
|
||||
buf[0] = '\0';
|
||||
}
|
||||
if (render && d) {
|
||||
pango_layout_set_text(drw->fonts->layout, buf, -1);
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
drw->fonts->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
}
|
||||
x += (int)ew;
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
@@ -173,13 +265,11 @@ int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
const char *text, int textlen, int align) {
|
||||
char buf[1024];
|
||||
if (!drw || !drw->scheme || !drw->fonts || !text) return x;
|
||||
int len = textlen < (int)sizeof(buf) - 1 ? textlen : (int)sizeof(buf) - 1;
|
||||
if (len < 0) len = 0;
|
||||
memcpy(buf, text, (size_t)len);
|
||||
buf[len] = '\0';
|
||||
if (textlen < 0) textlen = 0;
|
||||
size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)textlen);
|
||||
|
||||
unsigned int ew = 0, eh = 0;
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)len, &ew, &eh);
|
||||
drw_font_getexts(drw->fonts, buf, (unsigned int)slen, &ew, &eh);
|
||||
int dx = (align == AlignR && ew < w) ? x + (int)(w - ew) : x;
|
||||
int ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
@@ -187,11 +277,22 @@ int drw_text_align(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
XftDraw *d = XftDrawCreate(drw->dpy, drw->drawable,
|
||||
DefaultVisual(drw->dpy, drw->screen),
|
||||
DefaultColormap(drw->dpy, drw->screen));
|
||||
pango_layout_set_text(drw->fonts->layout, buf, len);
|
||||
PangoLayout *layout = drw->fonts->layout;
|
||||
pango_layout_set_single_paragraph_mode(layout, TRUE);
|
||||
if (w > 0) {
|
||||
int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE))
|
||||
? (INT_MAX / PANGO_SCALE) : (int)w;
|
||||
pango_layout_set_width(layout, max_w * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
}
|
||||
pango_layout_set_text(layout, buf, (int)slen);
|
||||
pango_xft_render_layout(d, &drw->scheme[ColFg],
|
||||
drw->fonts->layout, dx * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
layout, dx * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_single_paragraph_mode(layout, FALSE);
|
||||
XftDrawDestroy(d);
|
||||
return dx + (int)ew;
|
||||
return dx + (int)(ew < w ? ew : w);
|
||||
}
|
||||
|
||||
void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) {
|
||||
@@ -209,13 +310,18 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text) {
|
||||
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
|
||||
unsigned int *w, unsigned int *h) {
|
||||
char buf[1024];
|
||||
PangoRectangle r;
|
||||
if (!font || !text) {
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
return;
|
||||
}
|
||||
pango_layout_set_text(font->layout, text, (int)len);
|
||||
size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)len);
|
||||
pango_layout_set_single_paragraph_mode(font->layout, FALSE);
|
||||
pango_layout_set_width(font->layout, -1);
|
||||
pango_layout_set_ellipsize(font->layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_text(font->layout, buf, (int)slen);
|
||||
pango_layout_get_extents(font->layout, NULL, &r);
|
||||
if (w) *w = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (h) *h = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
|
||||
@@ -13,12 +13,12 @@ static const unsigned int systrayspacing = 8;
|
||||
static const int systraypinningfailfirst = 1;
|
||||
static const int showsystray = 1;
|
||||
static const char *font = "Fira Code, DejaVuSansM Nerd Font 38px";
|
||||
static char normbgcolor[64] = "#0b0e14";
|
||||
static char normbordercolor[64] = "#283444";
|
||||
static char normfgcolor[64] = "#e6e1cf";
|
||||
static char selbgcolor[64] = "#2b5278";
|
||||
static char selbordercolor[64] = "#59c2ff";
|
||||
static char selfgcolor[64] = "#ffffff";
|
||||
static char normbgcolor[64] = "#0e1014";
|
||||
static char normbordercolor[64] = "#2d3440";
|
||||
static char normfgcolor[64] = "#e4e8ee";
|
||||
static char selbgcolor[64] = "#38414f";
|
||||
static char selbordercolor[64] = "#cfd6e0";
|
||||
static char selfgcolor[64] = "#f5f7fa";
|
||||
static char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
|
||||
|
||||
+127
-31
@@ -1,8 +1,10 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
/* Pango + HarfBuzz + Xft drawing backend for Geminux DWM */
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <fontconfig/fontconfig.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xft/Xft.h>
|
||||
#include <pango/pango.h>
|
||||
@@ -11,6 +13,84 @@
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef FC_COLOR
|
||||
static void drw_fc_substitute(FcPattern *pattern, gpointer data) {
|
||||
(void)data;
|
||||
FcPatternDel(pattern, FC_COLOR);
|
||||
FcPatternAddBool(pattern, FC_COLOR, FcFalse);
|
||||
}
|
||||
#endif
|
||||
|
||||
static size_t drw_sanitize_utf8(char *dst, size_t dst_sz, const char *src, size_t src_len) {
|
||||
if (!dst || dst_sz == 0) return 0;
|
||||
if (!src) {
|
||||
dst[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
size_t i = 0, o = 0;
|
||||
while (i < src_len && o + 1 < dst_sz) {
|
||||
unsigned char c = (unsigned char)src[i];
|
||||
if (c == '\0') break;
|
||||
if (c < 0x80) {
|
||||
dst[o++] = (char)c;
|
||||
i++;
|
||||
} else if (c >= 0xC2 && c <= 0xDF) {
|
||||
if (i + 1 < src_len && ((unsigned char)src[i + 1] & 0xC0) == 0x80) {
|
||||
if (o + 2 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = src[i + 1];
|
||||
i += 2;
|
||||
} else {
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
}
|
||||
} else if (c >= 0xE0 && c <= 0xEF) {
|
||||
if (i + 2 < src_len) {
|
||||
unsigned char c1 = (unsigned char)src[i + 1];
|
||||
unsigned char c2 = (unsigned char)src[i + 2];
|
||||
int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80);
|
||||
if (ok && c == 0xE0 && c1 < 0xA0) ok = 0;
|
||||
if (ok && c == 0xED && c1 > 0x9F) ok = 0;
|
||||
if (ok) {
|
||||
if (o + 3 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = (char)c1;
|
||||
dst[o++] = (char)c2;
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
} else if (c >= 0xF0 && c <= 0xF4) {
|
||||
if (i + 3 < src_len) {
|
||||
unsigned char c1 = (unsigned char)src[i + 1];
|
||||
unsigned char c2 = (unsigned char)src[i + 2];
|
||||
unsigned char c3 = (unsigned char)src[i + 3];
|
||||
int ok = ((c1 & 0xC0) == 0x80 && (c2 & 0xC0) == 0x80 && (c3 & 0xC0) == 0x80);
|
||||
if (ok && c == 0xF0 && c1 < 0x90) ok = 0;
|
||||
if (ok && c == 0xF4 && c1 > 0x8F) ok = 0;
|
||||
if (ok) {
|
||||
if (o + 4 >= dst_sz) break;
|
||||
dst[o++] = (char)c;
|
||||
dst[o++] = (char)c1;
|
||||
dst[o++] = (char)c2;
|
||||
dst[o++] = (char)c3;
|
||||
i += 4;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
} else {
|
||||
dst[o++] = '?';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
dst[o] = '\0';
|
||||
return o;
|
||||
}
|
||||
|
||||
Drw *drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) {
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
drw->dpy = dpy;
|
||||
@@ -49,6 +129,14 @@ Fnt *drw_font_create(Drw *drw, const char font[]) {
|
||||
|
||||
fnt->dpy = drw->dpy;
|
||||
fnt->fontmap = pango_xft_get_font_map(drw->dpy, drw->screen);
|
||||
#ifdef FC_COLOR
|
||||
#if PANGO_VERSION_CHECK(1, 48, 0)
|
||||
pango_fc_font_map_set_default_substitute(PANGO_FC_FONT_MAP(fnt->fontmap),
|
||||
drw_fc_substitute, NULL, NULL);
|
||||
#else
|
||||
pango_xft_set_default_substitute(drw->dpy, drw->screen, drw_fc_substitute, NULL, NULL);
|
||||
#endif
|
||||
#endif
|
||||
fnt->context = pango_font_map_create_context(fnt->fontmap);
|
||||
fnt->desc = pango_font_description_from_string(font && font[0] ? font : "Fira Code 18px");
|
||||
pango_context_set_font_description(fnt->context, fnt->desc);
|
||||
@@ -114,14 +202,14 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
int orig_x = x;
|
||||
unsigned int orig_w = w;
|
||||
int ty, render = x || y || w || h;
|
||||
unsigned int ew, eh;
|
||||
unsigned int ew = 0, eh = 0;
|
||||
XftDraw *d = NULL;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->font)
|
||||
return 0;
|
||||
|
||||
if (!render) {
|
||||
w = ~0;
|
||||
w = ~0U;
|
||||
} else {
|
||||
XSetForeground(drw->dpy, drw->gc, drw->scheme[invert ? ColFg : ColBg].pixel);
|
||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||
@@ -132,38 +220,41 @@ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h,
|
||||
w = (w > lpad) ? (w - lpad) : 0;
|
||||
}
|
||||
|
||||
size_t len = strlen(text);
|
||||
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
|
||||
memcpy(buf, text, len);
|
||||
buf[len] = '\0';
|
||||
size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, strlen(text));
|
||||
|
||||
if (len > 0 && w > 0) {
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
|
||||
while (len > 3 && ew > w) {
|
||||
len--;
|
||||
while (len > 0 && (buf[len] & 0xc0) == 0x80) len--;
|
||||
if (len >= 3) memcpy(buf + len - 3, "...", 3);
|
||||
buf[len] = '\0';
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)len, &ew, &eh, markup);
|
||||
}
|
||||
if (ew > w) {
|
||||
len = 0;
|
||||
buf[0] = '\0';
|
||||
}
|
||||
|
||||
if (render && d) {
|
||||
if (slen > 0 && w > 0) {
|
||||
if (!render) {
|
||||
drw_font_getexts(drw->font, buf, (unsigned int)slen, &ew, &eh, markup);
|
||||
x += (int)ew;
|
||||
} else if (d) {
|
||||
PangoLayout *layout = drw->font->layout;
|
||||
PangoRectangle r;
|
||||
int max_w = (w > (unsigned int)(INT_MAX / PANGO_SCALE))
|
||||
? (INT_MAX / PANGO_SCALE) : (int)w;
|
||||
pango_layout_set_single_paragraph_mode(layout, TRUE);
|
||||
pango_layout_set_width(layout, max_w * PANGO_SCALE);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
||||
if (markup)
|
||||
pango_layout_set_markup(drw->font->layout, buf, -1);
|
||||
pango_layout_set_markup(layout, buf, (int)slen);
|
||||
else
|
||||
pango_layout_set_text(drw->font->layout, buf, -1);
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
drw->font->layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
pango_layout_set_text(layout, buf, (int)slen);
|
||||
pango_layout_get_extents(layout, NULL, &r);
|
||||
ew = (unsigned int)((r.width + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
eh = (unsigned int)((r.height + PANGO_SCALE - 1) / PANGO_SCALE);
|
||||
if (eh == 0) eh = drw->font->h;
|
||||
if (ew <= w || w >= 12) {
|
||||
ty = y + (int)(h - eh) / 2;
|
||||
if (ty < y) ty = y;
|
||||
pango_xft_render_layout(d, &drw->scheme[invert ? ColBg : ColFg],
|
||||
layout, x * PANGO_SCALE, ty * PANGO_SCALE);
|
||||
}
|
||||
pango_layout_set_width(layout, -1);
|
||||
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
|
||||
pango_layout_set_single_paragraph_mode(layout, FALSE);
|
||||
if (markup)
|
||||
pango_layout_set_attributes(drw->font->layout, NULL);
|
||||
pango_layout_set_attributes(layout, NULL);
|
||||
x += (int)ew;
|
||||
}
|
||||
x += (int)ew;
|
||||
}
|
||||
|
||||
if (d) XftDrawDestroy(d);
|
||||
@@ -185,16 +276,21 @@ unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup) {
|
||||
|
||||
void drw_font_getexts(Fnt *font, const char *text, unsigned int len,
|
||||
unsigned int *w, unsigned int *h, Bool markup) {
|
||||
char buf[1024];
|
||||
PangoRectangle r;
|
||||
if (!font || !text) {
|
||||
if (w) *w = 0;
|
||||
if (h) *h = 0;
|
||||
return;
|
||||
}
|
||||
size_t slen = drw_sanitize_utf8(buf, sizeof(buf), text, (size_t)len);
|
||||
pango_layout_set_single_paragraph_mode(font->layout, FALSE);
|
||||
pango_layout_set_width(font->layout, -1);
|
||||
pango_layout_set_ellipsize(font->layout, PANGO_ELLIPSIZE_NONE);
|
||||
if (markup)
|
||||
pango_layout_set_markup(font->layout, text, (int)len);
|
||||
pango_layout_set_markup(font->layout, buf, (int)slen);
|
||||
else
|
||||
pango_layout_set_text(font->layout, text, (int)len);
|
||||
pango_layout_set_text(font->layout, buf, (int)slen);
|
||||
pango_layout_get_extents(font->layout, NULL, &r);
|
||||
if (markup)
|
||||
pango_layout_set_attributes(font->layout, NULL);
|
||||
|
||||
+60
-9
@@ -308,6 +308,7 @@ static char stext[512];
|
||||
static char xres_font[256] = "";
|
||||
static int screen;
|
||||
static int sw, sh;
|
||||
static int render_opcode = -1;
|
||||
static int bh;
|
||||
static int lrpad;
|
||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
@@ -505,6 +506,8 @@ static void buttonpress(XEvent *e) {
|
||||
restack(selmon);
|
||||
XAllowEvents(dpy, ReplayPointer, CurrentTime);
|
||||
click = ClkClientWin;
|
||||
} else {
|
||||
XAllowEvents(dpy, AsyncBoth, CurrentTime);
|
||||
}
|
||||
for (i = 0; i < LENGTH(buttons); i++) {
|
||||
if (click == buttons[i].click && buttons[i].func &&
|
||||
@@ -516,7 +519,9 @@ static void buttonpress(XEvent *e) {
|
||||
}
|
||||
|
||||
static void checkotherwm(void) {
|
||||
xerrorxlib = XSetErrorHandler(xerrorstart);
|
||||
int (*prev_err)(Display *, XErrorEvent *) = XSetErrorHandler(xerrorstart);
|
||||
if (prev_err && prev_err != xerror)
|
||||
xerrorxlib = prev_err;
|
||||
XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
|
||||
XSync(dpy, False);
|
||||
XSetErrorHandler(xerror);
|
||||
@@ -1075,12 +1080,30 @@ static int extracteventtime(const XEvent *e, Time *out) {
|
||||
|
||||
static Time getservertime(Window w) {
|
||||
XEvent ev;
|
||||
Time ts = CurrentTime;
|
||||
struct pollfd pfd = { .fd = ConnectionNumber(dpy), .events = POLLIN };
|
||||
unsigned long long deadline = now_ms() + 200ULL;
|
||||
|
||||
while (XCheckTypedWindowEvent(dpy, w, PropertyNotify, &ev)) ;
|
||||
XSelectInput(dpy, w, PropertyChangeMask);
|
||||
XChangeProperty(dpy, w, netatom[NetWMName], utf8string, 8,
|
||||
PropModeAppend, (unsigned char *)"", 0);
|
||||
XWindowEvent(dpy, w, PropertyChangeMask, &ev);
|
||||
XFlush(dpy);
|
||||
|
||||
for (;;) {
|
||||
XEventsQueued(dpy, QueuedAfterReading);
|
||||
if (XCheckTypedWindowEvent(dpy, w, PropertyNotify, &ev)) {
|
||||
ts = ev.xproperty.time;
|
||||
break;
|
||||
}
|
||||
unsigned long long now = now_ms();
|
||||
if (now >= deadline) break;
|
||||
int rem = (int)(deadline - now);
|
||||
if (poll(&pfd, 1, rem) < 0 && errno != EINTR) break;
|
||||
}
|
||||
|
||||
XSelectInput(dpy, w, 0);
|
||||
return ev.xproperty.time;
|
||||
return ts;
|
||||
}
|
||||
|
||||
static Time getfocustime(void) {
|
||||
@@ -1291,10 +1314,10 @@ static void grabbuttons(Client *c, int focused) {
|
||||
if (buttons[i].click == ClkClientWin) {
|
||||
for (j = 0; j < LENGTH(modifiers); j++) {
|
||||
XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j],
|
||||
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None);
|
||||
if (buttons[i].mask & Mod4Mask) {
|
||||
XGrabButton(dpy, buttons[i].button, buttons[i].mask | Mod5Mask | modifiers[j],
|
||||
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
|
||||
c->win, False, BUTTONMASK, GrabModeAsync, GrabModeAsync, None, None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1868,7 +1891,10 @@ static void movemouse(const Arg *arg) {
|
||||
if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
|
||||
None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess)
|
||||
return;
|
||||
if (!getrootptr(&x, &y)) return;
|
||||
if (!getrootptr(&x, &y)) {
|
||||
XUngrabPointer(dpy, CurrentTime);
|
||||
return;
|
||||
}
|
||||
do {
|
||||
XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
|
||||
switch (ev.type) {
|
||||
@@ -2343,6 +2369,11 @@ static void setup(void) {
|
||||
sw = DisplayWidth(dpy, screen);
|
||||
sh = DisplayHeight(dpy, screen);
|
||||
root = RootWindow(dpy, screen);
|
||||
{
|
||||
int rev = 0, rerr = 0;
|
||||
if (!XQueryExtension(dpy, "RENDER", &render_opcode, &rev, &rerr))
|
||||
render_opcode = -1;
|
||||
}
|
||||
drw = drw_create(dpy, screen, root, (unsigned int)sw, (unsigned int)sh);
|
||||
dwmfont = drw_font_create(drw, font);
|
||||
drw_setfont(drw, dwmfont);
|
||||
@@ -3230,9 +3261,29 @@ static int xerror(Display *dpy, XErrorEvent *ee) {
|
||||
(ee->request_code == X_GrabKey && ee->error_code == BadAccess) ||
|
||||
(ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
|
||||
return 0;
|
||||
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
|
||||
ee->request_code, ee->error_code);
|
||||
return xerrorxlib(dpy, ee);
|
||||
if (render_opcode > 0 && ee->request_code == render_opcode) {
|
||||
static unsigned int render_err_logged = 0;
|
||||
if (render_err_logged < 8) {
|
||||
render_err_logged++;
|
||||
fprintf(stderr, "dwm: ignoring non-fatal RENDER error: minor=%d, error=%d\n",
|
||||
ee->minor_code, ee->error_code);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
static int in_xerror = 0;
|
||||
if (in_xerror) return 0;
|
||||
in_xerror = 1;
|
||||
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
|
||||
ee->request_code, ee->error_code);
|
||||
if (xerrorxlib && xerrorxlib != xerror) {
|
||||
int rc = xerrorxlib(dpy, ee);
|
||||
in_xerror = 0;
|
||||
return rc;
|
||||
}
|
||||
in_xerror = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int xerrordummy(Display *dpy, XErrorEvent *ee) {
|
||||
|
||||
@@ -38,8 +38,8 @@ geminux-net: geminux-net.c geminux-wifi-list.h geminux-bt-list.h ../geminux-daem
|
||||
geminux-audio: geminux-audio.c geminux-audio-parse.h ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||
|
||||
geminux-themes: geminux-themes.c geminux-xth.h ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS) -lm
|
||||
geminux-themes: geminux-themes.c geminux-xth.h geminux-wallpaper.h geminux-wallpaper-x11.h ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -DHAVE_LIBJPEG=1 -DHAVE_LIBWEBP=1 -o $@ $< $(LIBS) -lXrandr -lXinerama -ljpeg -lwebp -lm
|
||||
|
||||
geminux-%: geminux-%.c ../libgemui/gemui.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||
|
||||
@@ -58,6 +58,22 @@ enum {
|
||||
WORK_BT_REM,
|
||||
};
|
||||
|
||||
static void reapply_saved_wallpaper(void) {
|
||||
const char *xdg = getenv("XDG_CONFIG_HOME");
|
||||
const char *home = getenv("HOME");
|
||||
char conf[560];
|
||||
if (xdg && xdg[0]) {
|
||||
snprintf(conf, sizeof(conf), "%s/geminux/wallpaper.conf", xdg);
|
||||
} else {
|
||||
snprintf(conf, sizeof(conf), "%s/.config/geminux/wallpaper.conf",
|
||||
(home && home[0]) ? home : "/home/user");
|
||||
}
|
||||
if (access(conf, R_OK) == 0) {
|
||||
const char *wpv[] = {"geminux-apply-wallpaper", "--restore", NULL};
|
||||
gemui_spawn_detached(wpv);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char col1[128];
|
||||
char col2[96];
|
||||
@@ -1662,6 +1678,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
const char *argv[] = {"xrandr", "--output", "HDMI-1", st->hdmi_on ? "--off" : "--auto", NULL};
|
||||
gemui_run_cmd_timeout(argv, NULL, 0, 2000);
|
||||
st->hdmi_on = !st->hdmi_on;
|
||||
reapply_saved_wallpaper();
|
||||
refresh_tab(st);
|
||||
}
|
||||
} else if (hit->id == HIT_ACTION) {
|
||||
@@ -1700,6 +1717,7 @@ static void on_ptr(gemui_app_t *app, int type, int x, int y, unsigned int btn, v
|
||||
} else if (hit->val == 4) {
|
||||
const char *argv[] = {"xrandr", "--output", "HDMI-1", "--same-as", "DSI-1", NULL};
|
||||
gemui_run_cmd_timeout(argv, NULL, 0, 2000);
|
||||
reapply_saved_wallpaper();
|
||||
refresh_tab(st);
|
||||
}
|
||||
}
|
||||
|
||||
+1062
-59
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,758 @@
|
||||
/*
|
||||
* Geminux X11 + Cairo image loader & native root Pixmap wallpaper engine.
|
||||
* Included by src/geminux-apps/geminux-themes.c (uses pure-C gdk-pixbuf dlopen,
|
||||
* Cairo PNG, libjpeg, libwebp, or ImageMagick fallback).
|
||||
*/
|
||||
#ifndef GEMINUX_WALLPAPER_X11_H
|
||||
#define GEMINUX_WALLPAPER_X11_H
|
||||
|
||||
#include "geminux-wallpaper.h"
|
||||
#include "../libgemui/gemui.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xresource.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
#include <cairo/cairo.h>
|
||||
#include <cairo/cairo-xlib.h>
|
||||
|
||||
#ifdef HAVE_LIBJPEG
|
||||
#include <jpeglib.h>
|
||||
#include <setjmp.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBWEBP
|
||||
#include <webp/decode.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
} geminux_wp_mon_t;
|
||||
|
||||
static inline bool geminux_wp_have_cmd(const char *cmd) {
|
||||
if (!cmd || !cmd[0]) return false;
|
||||
if (strchr(cmd, '/')) return access(cmd, X_OK) == 0;
|
||||
const char *path_env = getenv("PATH");
|
||||
if (!path_env || !path_env[0]) return false;
|
||||
|
||||
const char *p = path_env;
|
||||
while (*p) {
|
||||
const char *colon = strchr(p, ':');
|
||||
size_t dlen = colon ? (size_t)(colon - p) : strlen(p);
|
||||
char cand[768];
|
||||
if (dlen == 0) {
|
||||
snprintf(cand, sizeof(cand), "./%s", cmd);
|
||||
} else if (dlen < sizeof(cand) - 2) {
|
||||
memcpy(cand, p, dlen);
|
||||
if (cand[dlen - 1] == '/') cand[dlen] = '\0';
|
||||
else {
|
||||
cand[dlen] = '/';
|
||||
cand[dlen + 1] = '\0';
|
||||
}
|
||||
size_t cur = strlen(cand);
|
||||
snprintf(cand + cur, sizeof(cand) - cur, "%s", cmd);
|
||||
} else {
|
||||
cand[0] = '\0';
|
||||
}
|
||||
if (cand[0] && access(cand, X_OK) == 0) return true;
|
||||
if (!colon) break;
|
||||
p = colon + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_rgba_to_cairo(const unsigned char *px,
|
||||
int w, int h,
|
||||
int nc, int stride) {
|
||||
if (!px || w <= 0 || h <= 0 || (nc != 3 && nc != 4) || stride < w * nc) return NULL;
|
||||
cairo_surface_t *surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
|
||||
if (!surf || cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) {
|
||||
if (surf) cairo_surface_destroy(surf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cairo_surface_flush(surf);
|
||||
unsigned char *dst_data = cairo_image_surface_get_data(surf);
|
||||
int dst_stride = cairo_image_surface_get_stride(surf);
|
||||
|
||||
for (int y = 0; y < h; y++) {
|
||||
const unsigned char *sp = px + (size_t)y * (size_t)stride;
|
||||
uint32_t *dp = (uint32_t *)(dst_data + (size_t)y * (size_t)dst_stride);
|
||||
for (int x = 0; x < w; x++) {
|
||||
uint32_t r = sp[0];
|
||||
uint32_t g = sp[1];
|
||||
uint32_t b = sp[2];
|
||||
uint32_t a = (nc == 4) ? sp[3] : 255U;
|
||||
if (a == 0U) {
|
||||
dp[x] = 0U;
|
||||
} else if (a == 255U) {
|
||||
dp[x] = (255U << 24) | (r << 16) | (g << 8) | b;
|
||||
} else {
|
||||
uint32_t pr = (r * a + 127U) / 255U;
|
||||
uint32_t pg = (g * a + 127U) / 255U;
|
||||
uint32_t pb_c = (b * a + 127U) / 255U;
|
||||
dp[x] = (a << 24) | (pr << 16) | (pg << 8) | pb_c;
|
||||
}
|
||||
sp += nc;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_surface_mark_dirty(surf);
|
||||
return surf;
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_try_cairo_png(const char *path) {
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return NULL;
|
||||
unsigned char sig[8];
|
||||
size_t nr = fread(sig, 1, sizeof(sig), f);
|
||||
fclose(f);
|
||||
if (nr != 8) return NULL;
|
||||
static const unsigned char PNG_SIG[8] = {0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'};
|
||||
if (memcmp(sig, PNG_SIG, 8) != 0) return NULL;
|
||||
|
||||
cairo_surface_t *s = cairo_image_surface_create_from_png(path);
|
||||
if (!s || cairo_surface_status(s) != CAIRO_STATUS_SUCCESS ||
|
||||
cairo_image_surface_get_width(s) <= 0 || cairo_image_surface_get_height(s) <= 0) {
|
||||
if (s) cairo_surface_destroy(s);
|
||||
return NULL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
typedef void *(*geminux_gp_new_fn)(const char *, void **);
|
||||
typedef void *(*geminux_gp_orient_fn)(void *);
|
||||
typedef int (*geminux_gp_int_fn)(const void *);
|
||||
typedef const unsigned char *(*geminux_gp_pixels_fn)(const void *);
|
||||
typedef void (*geminux_gp_unref_fn)(void *);
|
||||
|
||||
static inline void geminux_wp_dlsym_copy(void *dst_fn_ptr, void *handle, const char *sym) {
|
||||
void *p = handle ? dlsym(handle, sym) : NULL;
|
||||
memcpy(dst_fn_ptr, &p, sizeof(p));
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_try_gdk_pixbuf(const char *path) {
|
||||
static int init_state = 0; /* 0=uninit, 1=ready, -1=unavailable */
|
||||
static geminux_gp_new_fn fn_new = NULL;
|
||||
static geminux_gp_orient_fn fn_orient = NULL;
|
||||
static geminux_gp_int_fn fn_w = NULL;
|
||||
static geminux_gp_int_fn fn_h = NULL;
|
||||
static geminux_gp_int_fn fn_nc = NULL;
|
||||
static geminux_gp_int_fn fn_bps = NULL;
|
||||
static geminux_gp_int_fn fn_stride = NULL;
|
||||
static geminux_gp_pixels_fn fn_pixels = NULL;
|
||||
static geminux_gp_unref_fn fn_unref = NULL;
|
||||
|
||||
if (init_state == 0) {
|
||||
void *pb_dl = dlopen("libgdk_pixbuf-2.0.so.0", RTLD_LAZY);
|
||||
if (!pb_dl) {
|
||||
init_state = -1;
|
||||
return NULL;
|
||||
}
|
||||
void *gobj_dl = dlopen("libgobject-2.0.so.0", RTLD_LAZY);
|
||||
geminux_wp_dlsym_copy(&fn_new, pb_dl, "gdk_pixbuf_new_from_file");
|
||||
geminux_wp_dlsym_copy(&fn_orient, pb_dl, "gdk_pixbuf_apply_embedded_orientation");
|
||||
geminux_wp_dlsym_copy(&fn_w, pb_dl, "gdk_pixbuf_get_width");
|
||||
geminux_wp_dlsym_copy(&fn_h, pb_dl, "gdk_pixbuf_get_height");
|
||||
geminux_wp_dlsym_copy(&fn_nc, pb_dl, "gdk_pixbuf_get_n_channels");
|
||||
geminux_wp_dlsym_copy(&fn_bps, pb_dl, "gdk_pixbuf_get_bits_per_sample");
|
||||
geminux_wp_dlsym_copy(&fn_stride, pb_dl, "gdk_pixbuf_get_rowstride");
|
||||
geminux_wp_dlsym_copy(&fn_pixels, pb_dl, "gdk_pixbuf_read_pixels");
|
||||
geminux_wp_dlsym_copy(&fn_unref, pb_dl, "g_object_unref");
|
||||
if (!fn_unref && gobj_dl) {
|
||||
geminux_wp_dlsym_copy(&fn_unref, gobj_dl, "g_object_unref");
|
||||
}
|
||||
if (!fn_new || !fn_w || !fn_h || !fn_nc || !fn_bps || !fn_stride || !fn_pixels || !fn_unref) {
|
||||
if (gobj_dl) dlclose(gobj_dl);
|
||||
dlclose(pb_dl);
|
||||
init_state = -1;
|
||||
return NULL;
|
||||
}
|
||||
init_state = 1;
|
||||
}
|
||||
if (init_state < 0) return NULL;
|
||||
|
||||
void *pb = fn_new(path, NULL);
|
||||
if (!pb) return NULL;
|
||||
if (fn_orient) {
|
||||
void *ori = fn_orient(pb);
|
||||
if (ori) {
|
||||
fn_unref(pb);
|
||||
pb = ori;
|
||||
}
|
||||
}
|
||||
|
||||
int w = fn_w(pb);
|
||||
int h = fn_h(pb);
|
||||
int nc = fn_nc(pb);
|
||||
int bps = fn_bps(pb);
|
||||
int stride = fn_stride(pb);
|
||||
const unsigned char *px = fn_pixels(pb);
|
||||
|
||||
cairo_surface_t *surf = (bps == 8) ? geminux_wp_rgba_to_cairo(px, w, h, nc, stride) : NULL;
|
||||
fn_unref(pb);
|
||||
return surf;
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBJPEG
|
||||
typedef struct {
|
||||
struct jpeg_error_mgr pub;
|
||||
jmp_buf setjmp_buf;
|
||||
} geminux_wp_jpeg_err_t;
|
||||
|
||||
static void geminux_wp_jpeg_error_exit(j_common_ptr cinfo) {
|
||||
geminux_wp_jpeg_err_t *jerr = (geminux_wp_jpeg_err_t *)cinfo->err;
|
||||
longjmp(jerr->setjmp_buf, 1);
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_try_libjpeg(const char *path) {
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return NULL;
|
||||
unsigned char magic[2];
|
||||
size_t nr = fread(magic, 1, sizeof(magic), f);
|
||||
rewind(f);
|
||||
if (nr != 2 || magic[0] != 0xff || magic[1] != 0xd8) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
geminux_wp_jpeg_err_t jerr;
|
||||
cairo_surface_t *volatile surf = NULL;
|
||||
unsigned char *volatile row_buf = NULL;
|
||||
|
||||
cinfo.err = jpeg_std_error(&jerr.pub);
|
||||
jerr.pub.error_exit = geminux_wp_jpeg_error_exit;
|
||||
if (setjmp(jerr.setjmp_buf)) {
|
||||
free(row_buf);
|
||||
if (surf) cairo_surface_destroy(surf);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jpeg_create_decompress(&cinfo);
|
||||
jpeg_stdio_src(&cinfo, f);
|
||||
jpeg_read_header(&cinfo, TRUE);
|
||||
cinfo.out_color_space = JCS_RGB;
|
||||
jpeg_start_decompress(&cinfo);
|
||||
|
||||
int w = (int)cinfo.output_width;
|
||||
int h = (int)cinfo.output_height;
|
||||
int nc = (int)cinfo.output_components;
|
||||
if (w <= 0 || h <= 0 || nc != 3) {
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
|
||||
if (cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS) {
|
||||
cairo_surface_destroy(surf);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
row_buf = malloc((size_t)w * 3U);
|
||||
if (!row_buf) {
|
||||
cairo_surface_destroy(surf);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cairo_surface_flush(surf);
|
||||
unsigned char *dst_data = cairo_image_surface_get_data(surf);
|
||||
int dst_stride = cairo_image_surface_get_stride(surf);
|
||||
|
||||
while (cinfo.output_scanline < cinfo.output_height) {
|
||||
int y = (int)cinfo.output_scanline;
|
||||
JSAMPROW ptr = row_buf;
|
||||
jpeg_read_scanlines(&cinfo, &ptr, 1);
|
||||
uint32_t *dp = (uint32_t *)(dst_data + (size_t)y * (size_t)dst_stride);
|
||||
for (int x = 0; x < w; x++) {
|
||||
uint32_t r = row_buf[x * 3];
|
||||
uint32_t g = row_buf[x * 3 + 1];
|
||||
uint32_t b = row_buf[x * 3 + 2];
|
||||
dp[x] = (255U << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
}
|
||||
|
||||
cairo_surface_mark_dirty(surf);
|
||||
free(row_buf);
|
||||
jpeg_finish_decompress(&cinfo);
|
||||
jpeg_destroy_decompress(&cinfo);
|
||||
fclose(f);
|
||||
return surf;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LIBWEBP
|
||||
static inline cairo_surface_t *geminux_wp_try_libwebp(const char *path) {
|
||||
FILE *f = fopen(path, "rb");
|
||||
if (!f) return NULL;
|
||||
unsigned char hdr[12];
|
||||
size_t nr = fread(hdr, 1, sizeof(hdr), f);
|
||||
if (nr != sizeof(hdr) || memcmp(hdr, "RIFF", 4) != 0 || memcmp(hdr + 8, "WEBP", 4) != 0) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct stat sb;
|
||||
if (fstat(fileno(f), &sb) != 0 || !S_ISREG(sb.st_mode) ||
|
||||
sb.st_size <= 12 || (uint64_t)sb.st_size > 64ULL * 1024ULL * 1024ULL) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t fsz = (size_t)sb.st_size;
|
||||
uint8_t *raw = malloc(fsz);
|
||||
if (!raw) {
|
||||
fclose(f);
|
||||
return NULL;
|
||||
}
|
||||
rewind(f);
|
||||
size_t got = fread(raw, 1, fsz, f);
|
||||
fclose(f);
|
||||
if (got != fsz) {
|
||||
free(raw);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int w = 0, h = 0;
|
||||
uint8_t *rgba = WebPDecodeRGBA(raw, fsz, &w, &h);
|
||||
free(raw);
|
||||
if (!rgba) return NULL;
|
||||
|
||||
cairo_surface_t *surf = geminux_wp_rgba_to_cairo(rgba, w, h, 4, w * 4);
|
||||
WebPFree(rgba);
|
||||
return surf;
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_try_magick_fallback(const char *path) {
|
||||
const char *cmd = geminux_wp_have_cmd("magick") ? "magick"
|
||||
: (geminux_wp_have_cmd("convert") ? "convert" : NULL);
|
||||
if (!cmd) return NULL;
|
||||
|
||||
const char *tmpdir = getenv("TMPDIR");
|
||||
if (!tmpdir || !tmpdir[0]) tmpdir = "/tmp";
|
||||
char tmpl[320];
|
||||
snprintf(tmpl, sizeof(tmpl), "%.*s/geminux-wp-XXXXXX", (int)(sizeof(tmpl) - 24), tmpdir);
|
||||
int fd = mkstemp(tmpl);
|
||||
if (fd < 0) return NULL;
|
||||
close(fd);
|
||||
|
||||
char out_spec[336];
|
||||
snprintf(out_spec, sizeof(out_spec), "png:%s", tmpl);
|
||||
const char *av[] = {cmd, path, out_spec, NULL};
|
||||
cairo_surface_t *s = NULL;
|
||||
if (gemui_run_cmd_timeout(av, NULL, 0, 8000) == 0) {
|
||||
s = geminux_wp_try_cairo_png(tmpl);
|
||||
}
|
||||
unlink(tmpl);
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_load_surface(const char *path,
|
||||
int *out_orig_w,
|
||||
int *out_orig_h) {
|
||||
if (out_orig_w) *out_orig_w = 0;
|
||||
if (out_orig_h) *out_orig_h = 0;
|
||||
if (!path || !path[0]) return NULL;
|
||||
|
||||
struct stat sb;
|
||||
if (stat(path, &sb) != 0 || !S_ISREG(sb.st_mode)) return NULL;
|
||||
|
||||
cairo_surface_t *s = geminux_wp_try_gdk_pixbuf(path);
|
||||
if (!s) s = geminux_wp_try_cairo_png(path);
|
||||
#ifdef HAVE_LIBJPEG
|
||||
if (!s) s = geminux_wp_try_libjpeg(path);
|
||||
#endif
|
||||
#ifdef HAVE_LIBWEBP
|
||||
if (!s) s = geminux_wp_try_libwebp(path);
|
||||
#endif
|
||||
if (!s) s = geminux_wp_try_magick_fallback(path);
|
||||
|
||||
if (s) {
|
||||
if (out_orig_w) *out_orig_w = cairo_image_surface_get_width(s);
|
||||
if (out_orig_h) *out_orig_h = cairo_image_surface_get_height(s);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline cairo_surface_t *geminux_wp_make_preview_surface(const char *path,
|
||||
int max_w, int max_h,
|
||||
int *out_orig_w,
|
||||
int *out_orig_h) {
|
||||
int ow = 0, oh = 0;
|
||||
cairo_surface_t *full = geminux_wp_load_surface(path, &ow, &oh);
|
||||
if (out_orig_w) *out_orig_w = ow;
|
||||
if (out_orig_h) *out_orig_h = oh;
|
||||
if (!full || ow <= 0 || oh <= 0) return full;
|
||||
|
||||
if (max_w <= 0 || max_h <= 0 || (ow <= max_w && oh <= max_h)) {
|
||||
return full;
|
||||
}
|
||||
|
||||
double sx = (double)max_w / (double)ow;
|
||||
double sy = (double)max_h / (double)oh;
|
||||
double sc = (sx < sy) ? sx : sy;
|
||||
int tw = (int)((double)ow * sc + 0.5);
|
||||
int th = (int)((double)oh * sc + 0.5);
|
||||
if (tw < 1) tw = 1;
|
||||
if (th < 1) th = 1;
|
||||
|
||||
cairo_surface_t *thumb = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, tw, th);
|
||||
if (cairo_surface_status(thumb) != CAIRO_STATUS_SUCCESS) {
|
||||
cairo_surface_destroy(thumb);
|
||||
return full;
|
||||
}
|
||||
cairo_t *cr = cairo_create(thumb);
|
||||
cairo_scale(cr, (double)tw / (double)ow, (double)th / (double)oh);
|
||||
cairo_set_source_surface(cr, full, 0.0, 0.0);
|
||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST);
|
||||
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD);
|
||||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(full);
|
||||
return thumb;
|
||||
}
|
||||
|
||||
static inline void geminux_wp_render_onto_cairo(cairo_t *cr,
|
||||
double rx, double ry,
|
||||
double rw, double rh,
|
||||
const geminux_wp_cfg_t *cfg,
|
||||
cairo_surface_t *img,
|
||||
const char *resolved_bg_hex) {
|
||||
if (!cr || rw <= 0.0 || rh <= 0.0) return;
|
||||
|
||||
int r = 8, g = 9, b = 11;
|
||||
if (!geminux_wp_parse_hex(resolved_bg_hex, &r, &g, &b)) {
|
||||
r = 8; g = 9; b = 11;
|
||||
}
|
||||
|
||||
cairo_save(cr);
|
||||
cairo_rectangle(cr, rx, ry, rw, rh);
|
||||
cairo_clip(cr);
|
||||
|
||||
cairo_set_source_rgb(cr, (double)r / 255.0, (double)g / 255.0, (double)b / 255.0);
|
||||
cairo_paint(cr);
|
||||
|
||||
if (cfg && cfg->type == GEMINUX_WP_IMAGE && img &&
|
||||
cairo_surface_status(img) == CAIRO_STATUS_SUCCESS) {
|
||||
int iw = cairo_image_surface_get_width(img);
|
||||
int ih = cairo_image_surface_get_height(img);
|
||||
if (iw > 0 && ih > 0) {
|
||||
if (cfg->mode == GEMINUX_WP_TILE) {
|
||||
cairo_translate(cr, rx, ry);
|
||||
cairo_set_source_surface(cr, img, 0.0, 0.0);
|
||||
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
|
||||
cairo_paint(cr);
|
||||
} else {
|
||||
double dx = 0.0, dy = 0.0, dw = 0.0, dh = 0.0;
|
||||
geminux_wp_calc_placement(iw, ih, (int)(rw + 0.5), (int)(rh + 0.5),
|
||||
cfg->mode, &dx, &dy, &dw, &dh);
|
||||
if (dw > 0.0 && dh > 0.0) {
|
||||
cairo_rectangle(cr, rx + dx, ry + dy, dw, dh);
|
||||
cairo_clip(cr);
|
||||
cairo_translate(cr, rx + dx, ry + dy);
|
||||
cairo_scale(cr, dw / (double)iw, dh / (double)ih);
|
||||
cairo_set_source_surface(cr, img, 0.0, 0.0);
|
||||
cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_BEST);
|
||||
cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_PAD);
|
||||
cairo_paint(cr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_restore(cr);
|
||||
}
|
||||
|
||||
static inline void geminux_wp_read_theme_bg(Display *dpy_opt, char *out_hex, size_t sz) {
|
||||
if (!out_hex || sz == 0) return;
|
||||
snprintf(out_hex, sz, "#08090b");
|
||||
|
||||
Display *dpy = dpy_opt ? dpy_opt : XOpenDisplay(NULL);
|
||||
bool found = false;
|
||||
if (dpy) {
|
||||
XrmInitialize();
|
||||
char *prop_rms = NULL;
|
||||
const char *rms = NULL;
|
||||
Atom actual_type = None;
|
||||
int actual_fmt = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *prop_data = NULL;
|
||||
Window root = DefaultRootWindow(dpy);
|
||||
if (XGetWindowProperty(dpy, root, XA_RESOURCE_MANAGER, 0, 1024L * 1024L, False, XA_STRING,
|
||||
&actual_type, &actual_fmt, &nitems, &bytes_after, &prop_data) == Success) {
|
||||
if (prop_data && actual_fmt == 8 && nitems > 0) {
|
||||
prop_rms = (char *)prop_data;
|
||||
rms = prop_rms;
|
||||
} else if (prop_data) {
|
||||
XFree(prop_data);
|
||||
}
|
||||
}
|
||||
if (!rms || !rms[0]) {
|
||||
rms = XResourceManagerString(dpy);
|
||||
}
|
||||
if (rms && rms[0]) {
|
||||
XrmDatabase db = XrmGetStringDatabase(rms);
|
||||
if (db) {
|
||||
char *rtype = NULL;
|
||||
XrmValue rval;
|
||||
if (XrmGetResource(db, "theme.bgMain", "Theme.BgMain", &rtype, &rval) && rval.addr) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (geminux_wp_parse_hex(rval.addr, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, out_hex, sz);
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
XrmDestroyDatabase(db);
|
||||
}
|
||||
}
|
||||
if (prop_rms) XFree(prop_rms);
|
||||
if (!dpy_opt) XCloseDisplay(dpy);
|
||||
}
|
||||
|
||||
if (found) return;
|
||||
|
||||
const char *home = getenv("HOME");
|
||||
if (!home || !home[0]) return;
|
||||
char xpath[640];
|
||||
snprintf(xpath, sizeof(xpath), "%s/.Xresources", home);
|
||||
FILE *f = fopen(xpath, "r");
|
||||
if (!f) return;
|
||||
|
||||
char line[512];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
const char *p = line;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
if (strncmp(p, "theme.bgMain:", 13) == 0) {
|
||||
p += 13;
|
||||
while (*p == ' ' || *p == '\t') p++;
|
||||
char tok[32];
|
||||
size_t ti = 0;
|
||||
while (p[ti] && !isspace((unsigned char)p[ti]) && ti + 1 < sizeof(tok)) {
|
||||
tok[ti] = p[ti];
|
||||
ti++;
|
||||
}
|
||||
tok[ti] = '\0';
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (geminux_wp_parse_hex(tok, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, out_hex, sz);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static inline int geminux_wp_noop_xerr(Display *d, XErrorEvent *e) {
|
||||
(void)d;
|
||||
(void)e;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int geminux_wp_query_monitors(Display *dpy, Window root, int sw, int sh,
|
||||
geminux_wp_mon_t *out, int max_out) {
|
||||
int n = 0;
|
||||
XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root);
|
||||
if (!res) res = XRRGetScreenResources(dpy, root);
|
||||
if (res) {
|
||||
RRCrtc seen_crtcs[16];
|
||||
int n_seen = 0;
|
||||
for (int i = 0; i < res->noutput && n < max_out; i++) {
|
||||
XRROutputInfo *oi = XRRGetOutputInfo(dpy, res, res->outputs[i]);
|
||||
if (!oi) continue;
|
||||
if (oi->connection == RR_Connected && oi->crtc != None) {
|
||||
bool dup = false;
|
||||
for (int s = 0; s < n_seen; s++) {
|
||||
if (seen_crtcs[s] == oi->crtc) { dup = true; break; }
|
||||
}
|
||||
if (!dup && n_seen < 16) {
|
||||
seen_crtcs[n_seen++] = oi->crtc;
|
||||
XRRCrtcInfo *ci = XRRGetCrtcInfo(dpy, res, oi->crtc);
|
||||
if (ci) {
|
||||
if (ci->width > 0 && ci->height > 0) {
|
||||
out[n].x = ci->x;
|
||||
out[n].y = ci->y;
|
||||
out[n].w = (int)ci->width;
|
||||
out[n].h = (int)ci->height;
|
||||
n++;
|
||||
}
|
||||
XRRFreeCrtcInfo(ci);
|
||||
}
|
||||
}
|
||||
}
|
||||
XRRFreeOutputInfo(oi);
|
||||
}
|
||||
XRRFreeScreenResources(res);
|
||||
}
|
||||
|
||||
if (n <= 0 && XineramaIsActive(dpy)) {
|
||||
int nx = 0;
|
||||
XineramaScreenInfo *xs = XineramaQueryScreens(dpy, &nx);
|
||||
if (xs) {
|
||||
for (int i = 0; i < nx && n < max_out; i++) {
|
||||
if (xs[i].width > 0 && xs[i].height > 0) {
|
||||
out[n].x = xs[i].x_org;
|
||||
out[n].y = xs[i].y_org;
|
||||
out[n].w = xs[i].width;
|
||||
out[n].h = xs[i].height;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
XFree(xs);
|
||||
}
|
||||
}
|
||||
|
||||
if (n <= 0 && max_out > 0) {
|
||||
out[0].x = 0;
|
||||
out[0].y = 0;
|
||||
out[0].w = sw;
|
||||
out[0].h = sh;
|
||||
n = 1;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_read_root_pmap(Display *dpy, Window root, Atom prop, unsigned long *out_id) {
|
||||
Atom actual_type = None;
|
||||
int actual_fmt = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *data = NULL;
|
||||
bool ok = false;
|
||||
|
||||
if (XGetWindowProperty(dpy, root, prop, 0, 1, False, XA_PIXMAP,
|
||||
&actual_type, &actual_fmt, &nitems, &bytes_after, &data) == Success) {
|
||||
if (actual_type == XA_PIXMAP && actual_fmt == 32 && nitems == 1 && data) {
|
||||
unsigned long val = 0;
|
||||
memcpy(&val, data, sizeof(unsigned long));
|
||||
if (val != 0UL) {
|
||||
*out_id = val;
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
if (data) XFree(data);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_apply_x11(const geminux_wp_cfg_t *cfg,
|
||||
const char *theme_bg_hex,
|
||||
char *err_buf, size_t err_sz) {
|
||||
if (err_buf && err_sz > 0) err_buf[0] = '\0';
|
||||
if (!cfg) {
|
||||
if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Invalid wallpaper config");
|
||||
return false;
|
||||
}
|
||||
|
||||
char bg_hex[16];
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (cfg->use_theme_bg && theme_bg_hex && geminux_wp_parse_hex(theme_bg_hex, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, bg_hex, sizeof(bg_hex));
|
||||
} else if (geminux_wp_parse_hex(cfg->color, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, bg_hex, sizeof(bg_hex));
|
||||
} else {
|
||||
snprintf(bg_hex, sizeof(bg_hex), "#08090b");
|
||||
}
|
||||
|
||||
cairo_surface_t *img = NULL;
|
||||
if (cfg->type == GEMINUX_WP_IMAGE) {
|
||||
img = geminux_wp_load_surface(cfg->path, NULL, NULL);
|
||||
if (!img) {
|
||||
if (err_buf && err_sz > 0) {
|
||||
snprintf(err_buf, err_sz, "Unable to load image: %.180s",
|
||||
cfg->path[0] ? cfg->path : "(no file selected)");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* Dedicated Display connection so RetainPermanent never affects libgemui's main Display */
|
||||
Display *wdpy = XOpenDisplay(NULL);
|
||||
if (!wdpy) {
|
||||
if (img) cairo_surface_destroy(img);
|
||||
if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Failed to open X11 display");
|
||||
return false;
|
||||
}
|
||||
|
||||
int scr = DefaultScreen(wdpy);
|
||||
Window root = RootWindow(wdpy, scr);
|
||||
int sw = DisplayWidth(wdpy, scr);
|
||||
int sh = DisplayHeight(wdpy, scr);
|
||||
if (sw <= 0 || sh <= 0) {
|
||||
if (img) cairo_surface_destroy(img);
|
||||
XCloseDisplay(wdpy);
|
||||
if (err_buf && err_sz > 0) snprintf(err_buf, err_sz, "Invalid X11 screen dimensions");
|
||||
return false;
|
||||
}
|
||||
|
||||
geminux_wp_mon_t mons[16];
|
||||
int n_mons = geminux_wp_query_monitors(wdpy, root, sw, sh, mons, 16);
|
||||
|
||||
Pixmap pmap = XCreatePixmap(wdpy, root, (unsigned int)sw, (unsigned int)sh,
|
||||
(unsigned int)DefaultDepth(wdpy, scr));
|
||||
cairo_surface_t *xsurf = cairo_xlib_surface_create(wdpy, pmap, DefaultVisual(wdpy, scr), sw, sh);
|
||||
cairo_t *cr = cairo_create(xsurf);
|
||||
|
||||
geminux_wp_cfg_t fill_only;
|
||||
geminux_wp_cfg_init(&fill_only);
|
||||
fill_only.type = GEMINUX_WP_SOLID;
|
||||
fill_only.use_theme_bg = false;
|
||||
geminux_wp_render_onto_cairo(cr, 0.0, 0.0, (double)sw, (double)sh, &fill_only, NULL, bg_hex);
|
||||
|
||||
if (cfg->type == GEMINUX_WP_IMAGE) {
|
||||
if (cfg->mode == GEMINUX_WP_SPAN || cfg->mode == GEMINUX_WP_TILE) {
|
||||
geminux_wp_render_onto_cairo(cr, 0.0, 0.0, (double)sw, (double)sh, cfg, img, bg_hex);
|
||||
} else {
|
||||
for (int i = 0; i < n_mons; i++) {
|
||||
geminux_wp_render_onto_cairo(cr, (double)mons[i].x, (double)mons[i].y,
|
||||
(double)mons[i].w, (double)mons[i].h,
|
||||
cfg, img, bg_hex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_flush(xsurf);
|
||||
cairo_surface_destroy(xsurf);
|
||||
if (img) cairo_surface_destroy(img);
|
||||
|
||||
Atom a_xroot = XInternAtom(wdpy, "_XROOTPMAP_ID", False);
|
||||
Atom a_eset = XInternAtom(wdpy, "ESETROOT_PMAP_ID", False);
|
||||
|
||||
XGrabServer(wdpy);
|
||||
unsigned long old_xroot = 0, old_eset = 0;
|
||||
if (geminux_wp_read_root_pmap(wdpy, root, a_xroot, &old_xroot) &&
|
||||
geminux_wp_read_root_pmap(wdpy, root, a_eset, &old_eset) &&
|
||||
old_xroot == old_eset && old_xroot != (unsigned long)pmap) {
|
||||
XErrorHandler prev = XSetErrorHandler(geminux_wp_noop_xerr);
|
||||
XKillClient(wdpy, (XID)old_xroot);
|
||||
XSync(wdpy, False);
|
||||
XSetErrorHandler(prev);
|
||||
}
|
||||
|
||||
unsigned long pval = (unsigned long)pmap;
|
||||
XSetWindowBackgroundPixmap(wdpy, root, pmap);
|
||||
XChangeProperty(wdpy, root, a_xroot, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pval, 1);
|
||||
XChangeProperty(wdpy, root, a_eset, XA_PIXMAP, 32, PropModeReplace, (unsigned char *)&pval, 1);
|
||||
XClearWindow(wdpy, root);
|
||||
XUngrabServer(wdpy);
|
||||
XSync(wdpy, False);
|
||||
|
||||
XSetCloseDownMode(wdpy, RetainPermanent);
|
||||
XCloseDisplay(wdpy);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* GEMINUX_WALLPAPER_X11_H */
|
||||
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Geminux Wallpaper configuration, image filtering, and placement geometry helpers.
|
||||
* Pure C11/POSIX with zero X11 or Cairo dependencies for unit-testability.
|
||||
*/
|
||||
#ifndef GEMINUX_WALLPAPER_H
|
||||
#define GEMINUX_WALLPAPER_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef enum {
|
||||
GEMINUX_WP_IMAGE = 0,
|
||||
GEMINUX_WP_SOLID = 1
|
||||
} geminux_wp_type_t;
|
||||
|
||||
typedef enum {
|
||||
GEMINUX_WP_FILL = 0,
|
||||
GEMINUX_WP_FIT = 1,
|
||||
GEMINUX_WP_CENTER = 2,
|
||||
GEMINUX_WP_TILE = 3,
|
||||
GEMINUX_WP_STRETCH = 4,
|
||||
GEMINUX_WP_SPAN = 5,
|
||||
GEMINUX_WP_MODE_COUNT = 6
|
||||
} geminux_wp_mode_t;
|
||||
|
||||
typedef struct {
|
||||
geminux_wp_type_t type;
|
||||
geminux_wp_mode_t mode;
|
||||
char path[768];
|
||||
char color[16];
|
||||
bool use_theme_bg;
|
||||
} geminux_wp_cfg_t;
|
||||
|
||||
static inline bool geminux_wp_ci_eq(const char *a, const char *b) {
|
||||
if (!a || !b) return false;
|
||||
while (*a && *b) {
|
||||
if (tolower((unsigned char)*a) != tolower((unsigned char)*b)) return false;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return *a == '\0' && *b == '\0';
|
||||
}
|
||||
|
||||
static inline void geminux_wp_cfg_init(geminux_wp_cfg_t *cfg) {
|
||||
if (!cfg) return;
|
||||
memset(cfg, 0, sizeof(*cfg));
|
||||
cfg->type = GEMINUX_WP_IMAGE;
|
||||
cfg->mode = GEMINUX_WP_FILL;
|
||||
snprintf(cfg->color, sizeof(cfg->color), "#08090b");
|
||||
cfg->use_theme_bg = true;
|
||||
}
|
||||
|
||||
static inline const char *geminux_wp_mode_name(geminux_wp_mode_t m) {
|
||||
switch (m) {
|
||||
case GEMINUX_WP_FILL: return "fill";
|
||||
case GEMINUX_WP_FIT: return "fit";
|
||||
case GEMINUX_WP_CENTER: return "center";
|
||||
case GEMINUX_WP_TILE: return "tile";
|
||||
case GEMINUX_WP_STRETCH: return "stretch";
|
||||
case GEMINUX_WP_SPAN: return "span";
|
||||
default: return "fill";
|
||||
}
|
||||
}
|
||||
|
||||
static inline const char *geminux_wp_mode_label(geminux_wp_mode_t m) {
|
||||
switch (m) {
|
||||
case GEMINUX_WP_FILL: return "Fill";
|
||||
case GEMINUX_WP_FIT: return "Fit";
|
||||
case GEMINUX_WP_CENTER: return "Center";
|
||||
case GEMINUX_WP_TILE: return "Tile";
|
||||
case GEMINUX_WP_STRETCH: return "Stretch";
|
||||
case GEMINUX_WP_SPAN: return "Span";
|
||||
default: return "Fill";
|
||||
}
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_mode_parse(const char *s, geminux_wp_mode_t *out) {
|
||||
if (!s || !s[0]) return false;
|
||||
geminux_wp_mode_t m;
|
||||
if (geminux_wp_ci_eq(s, "fill") || geminux_wp_ci_eq(s, "zoom")) m = GEMINUX_WP_FILL;
|
||||
else if (geminux_wp_ci_eq(s, "fit") || geminux_wp_ci_eq(s, "max")) m = GEMINUX_WP_FIT;
|
||||
else if (geminux_wp_ci_eq(s, "center") || geminux_wp_ci_eq(s, "centered")) m = GEMINUX_WP_CENTER;
|
||||
else if (geminux_wp_ci_eq(s, "tile") || geminux_wp_ci_eq(s, "tiled")) m = GEMINUX_WP_TILE;
|
||||
else if (geminux_wp_ci_eq(s, "stretch") || geminux_wp_ci_eq(s, "scale")) m = GEMINUX_WP_STRETCH;
|
||||
else if (geminux_wp_ci_eq(s, "span")) m = GEMINUX_WP_SPAN;
|
||||
else return false;
|
||||
if (out) *out = m;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline int geminux_wp_hex_digit(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;
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_parse_hex(const char *s, int *r, int *g, int *b) {
|
||||
if (!s) return false;
|
||||
if (s[0] == '#') s++;
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (geminux_wp_hex_digit(s[i]) < 0) return false;
|
||||
}
|
||||
if (s[6] != '\0') return false;
|
||||
int rv = (geminux_wp_hex_digit(s[0]) << 4) | geminux_wp_hex_digit(s[1]);
|
||||
int gv = (geminux_wp_hex_digit(s[2]) << 4) | geminux_wp_hex_digit(s[3]);
|
||||
int bv = (geminux_wp_hex_digit(s[4]) << 4) | geminux_wp_hex_digit(s[5]);
|
||||
if (r) *r = rv;
|
||||
if (g) *g = gv;
|
||||
if (b) *b = bv;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void geminux_wp_format_hex(int r, int g, int b, char *out, size_t sz) {
|
||||
if (!out || sz == 0) return;
|
||||
if (r < 0) r = 0; else if (r > 255) r = 255;
|
||||
if (g < 0) g = 0; else if (g > 255) g = 255;
|
||||
if (b < 0) b = 0; else if (b > 255) b = 255;
|
||||
snprintf(out, sz, "#%02x%02x%02x", r, g, b);
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_is_image_name(const char *name) {
|
||||
if (!name || !name[0]) return false;
|
||||
const char *slash = strrchr(name, '/');
|
||||
const char *base = slash ? (slash + 1) : name;
|
||||
const char *dot = strrchr(base, '.');
|
||||
if (!dot || dot == base || dot[1] == '\0') return false;
|
||||
const char *ext = dot + 1;
|
||||
static const char *const EXTS[] = {
|
||||
"png", "jpg", "jpeg", "webp", "bmp", "gif",
|
||||
"tif", "tiff", "svg", "pnm", "ppm", "pgm", "xbm", "xpm"
|
||||
};
|
||||
for (size_t i = 0; i < sizeof(EXTS) / sizeof(EXTS[0]); i++) {
|
||||
if (geminux_wp_ci_eq(ext, EXTS[i])) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void geminux_wp_calc_placement(int img_w, int img_h, int dst_w, int dst_h,
|
||||
geminux_wp_mode_t mode,
|
||||
double *out_x, double *out_y,
|
||||
double *out_w, double *out_h) {
|
||||
double x = 0.0, y = 0.0, w = 0.0, h = 0.0;
|
||||
if (img_w > 0 && img_h > 0 && dst_w > 0 && dst_h > 0) {
|
||||
double sx = (double)dst_w / (double)img_w;
|
||||
double sy = (double)dst_h / (double)img_h;
|
||||
switch (mode) {
|
||||
case GEMINUX_WP_FILL:
|
||||
case GEMINUX_WP_SPAN: {
|
||||
double s = (sx > sy) ? sx : sy;
|
||||
w = (double)img_w * s;
|
||||
h = (double)img_h * s;
|
||||
x = ((double)dst_w - w) * 0.5;
|
||||
y = ((double)dst_h - h) * 0.5;
|
||||
break;
|
||||
}
|
||||
case GEMINUX_WP_FIT: {
|
||||
double s = (sx < sy) ? sx : sy;
|
||||
w = (double)img_w * s;
|
||||
h = (double)img_h * s;
|
||||
x = ((double)dst_w - w) * 0.5;
|
||||
y = ((double)dst_h - h) * 0.5;
|
||||
break;
|
||||
}
|
||||
case GEMINUX_WP_CENTER:
|
||||
w = (double)img_w;
|
||||
h = (double)img_h;
|
||||
x = ((double)dst_w - w) * 0.5;
|
||||
y = ((double)dst_h - h) * 0.5;
|
||||
break;
|
||||
case GEMINUX_WP_STRETCH:
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
w = (double)dst_w;
|
||||
h = (double)dst_h;
|
||||
break;
|
||||
case GEMINUX_WP_TILE:
|
||||
default:
|
||||
x = 0.0;
|
||||
y = 0.0;
|
||||
w = (double)img_w;
|
||||
h = (double)img_h;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (out_x) *out_x = x;
|
||||
if (out_y) *out_y = y;
|
||||
if (out_w) *out_w = w;
|
||||
if (out_h) *out_h = h;
|
||||
}
|
||||
|
||||
static inline void geminux_wp_mkdir_p(const char *dir) {
|
||||
if (!dir || !dir[0]) return;
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof(tmp), "%.*s", (int)(sizeof(tmp) - 1), dir);
|
||||
size_t len = strlen(tmp);
|
||||
if (len > 1 && tmp[len - 1] == '/') tmp[len - 1] = '\0';
|
||||
for (char *p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = '\0';
|
||||
mkdir(tmp, 0755);
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
mkdir(tmp, 0755);
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_cfg_load(const char *conf_path, geminux_wp_cfg_t *cfg) {
|
||||
if (!cfg) return false;
|
||||
geminux_wp_cfg_init(cfg);
|
||||
if (!conf_path || !conf_path[0]) return false;
|
||||
|
||||
FILE *f = fopen(conf_path, "r");
|
||||
if (!f) return false;
|
||||
|
||||
char line[1024];
|
||||
while (fgets(line, sizeof(line), f)) {
|
||||
size_t n = strlen(line);
|
||||
while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r')) line[--n] = '\0';
|
||||
if (line[0] == '\0' || line[0] == '#') continue;
|
||||
|
||||
if (strncmp(line, "TYPE=", 5) == 0) {
|
||||
const char *v = line + 5;
|
||||
if (geminux_wp_ci_eq(v, "solid")) cfg->type = GEMINUX_WP_SOLID;
|
||||
else if (geminux_wp_ci_eq(v, "image")) cfg->type = GEMINUX_WP_IMAGE;
|
||||
} else if (strncmp(line, "PATH=", 5) == 0) {
|
||||
snprintf(cfg->path, sizeof(cfg->path), "%.*s", (int)(sizeof(cfg->path) - 1), line + 5);
|
||||
} else if (strncmp(line, "MODE=", 5) == 0) {
|
||||
geminux_wp_mode_t pm = GEMINUX_WP_FILL;
|
||||
if (geminux_wp_mode_parse(line + 5, &pm)) cfg->mode = pm;
|
||||
} else if (strncmp(line, "COLOR=", 6) == 0) {
|
||||
int r = 0, g = 0, b = 0;
|
||||
if (geminux_wp_parse_hex(line + 6, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, cfg->color, sizeof(cfg->color));
|
||||
}
|
||||
} else if (strncmp(line, "USE_THEME_BG=", 13) == 0) {
|
||||
cfg->use_theme_bg = (line[13] == '1');
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool geminux_wp_cfg_save(const char *conf_path, const geminux_wp_cfg_t *cfg) {
|
||||
if (!conf_path || !conf_path[0] || !cfg) return false;
|
||||
|
||||
const char *slash = strrchr(conf_path, '/');
|
||||
if (slash && slash > conf_path) {
|
||||
char pdir[1024];
|
||||
size_t dlen = (size_t)(slash - conf_path);
|
||||
if (dlen >= sizeof(pdir)) dlen = sizeof(pdir) - 1;
|
||||
memcpy(pdir, conf_path, dlen);
|
||||
pdir[dlen] = '\0';
|
||||
geminux_wp_mkdir_p(pdir);
|
||||
}
|
||||
|
||||
char clean_path[768];
|
||||
size_t pi = 0;
|
||||
for (size_t i = 0; cfg->path[i] && pi + 1 < sizeof(clean_path); i++) {
|
||||
if (cfg->path[i] != '\n' && cfg->path[i] != '\r') clean_path[pi++] = cfg->path[i];
|
||||
}
|
||||
clean_path[pi] = '\0';
|
||||
|
||||
char hex[16];
|
||||
int r = 8, g = 9, b = 11;
|
||||
if (geminux_wp_parse_hex(cfg->color, &r, &g, &b)) {
|
||||
geminux_wp_format_hex(r, g, b, hex, sizeof(hex));
|
||||
} else {
|
||||
snprintf(hex, sizeof(hex), "#08090b");
|
||||
}
|
||||
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof(tmp), "%.*s.tmp.%ld", (int)(sizeof(tmp) - 32), conf_path, (long)getpid());
|
||||
FILE *f = fopen(tmp, "w");
|
||||
if (!f) return false;
|
||||
|
||||
fprintf(f, "# Geminux wallpaper configuration\n");
|
||||
fprintf(f, "TYPE=%s\n", cfg->type == GEMINUX_WP_SOLID ? "solid" : "image");
|
||||
fprintf(f, "PATH=%s\n", clean_path);
|
||||
fprintf(f, "MODE=%s\n", geminux_wp_mode_name(cfg->mode));
|
||||
fprintf(f, "COLOR=%s\n", hex);
|
||||
fprintf(f, "USE_THEME_BG=%d\n", cfg->use_theme_bg ? 1 : 0);
|
||||
|
||||
if (fflush(f) != 0) {
|
||||
fclose(f);
|
||||
remove(tmp);
|
||||
return false;
|
||||
}
|
||||
fclose(f);
|
||||
if (rename(tmp, conf_path) != 0) {
|
||||
remove(tmp);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* GEMINUX_WALLPAPER_H */
|
||||
+30
-30
@@ -150,40 +150,40 @@ bool gemui_color_parse(const char *hex, gemui_color_t *out) {
|
||||
|
||||
void gemui_theme_defaults(gemui_theme_t *t) {
|
||||
memset(t, 0, sizeof(*t));
|
||||
snprintf(t->name, sizeof(t->name), "GeminuxHelio");
|
||||
snprintf(t->name, sizeof(t->name), "Anodized");
|
||||
snprintf(t->font_face, sizeof(t->font_face), "Fira Code");
|
||||
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "DejaVuSansM Nerd Font");
|
||||
t->base_font_size = 32;
|
||||
t->dpi = 192;
|
||||
gemui_color_parse("#11141a", &t->bg_main);
|
||||
gemui_color_parse("#161b23", &t->bg_bar);
|
||||
gemui_color_parse("#1b212b", &t->bg_header);
|
||||
gemui_color_parse("#141922", &t->bg_footer);
|
||||
gemui_color_parse("#18202c", &t->bg_overlay);
|
||||
gemui_color_parse("#1a202a", &t->bg_alt_even);
|
||||
gemui_color_parse("#1e2531", &t->bg_alt_odd);
|
||||
gemui_color_parse("#212936", &t->bg_input);
|
||||
gemui_color_parse("#273244", &t->bg_input_focus);
|
||||
gemui_color_parse("#232b38", &t->bg_button);
|
||||
gemui_color_parse("#202835", &t->bg_search);
|
||||
gemui_color_parse("#222b3a", &t->bg_bubble_in);
|
||||
gemui_color_parse("#1f3a52", &t->bg_bubble_out);
|
||||
gemui_color_parse("#233044", &t->bg_toast);
|
||||
gemui_color_parse("#d8dee9", &t->fg_main);
|
||||
gemui_color_parse("#eceff4", &t->fg_bright);
|
||||
gemui_color_parse("#8a95a8", &t->fg_muted);
|
||||
gemui_color_parse("#2f6feb", &t->sel_bg);
|
||||
gemui_color_parse("#ffffff", &t->sel_fg);
|
||||
gemui_color_parse("#58a6ff", &t->accent);
|
||||
gemui_color_parse("#79c0ff", &t->accent_alt);
|
||||
gemui_color_parse("#d2a8ff", &t->highlight);
|
||||
gemui_color_parse("#30394a", &t->border);
|
||||
gemui_color_parse("#262f3e", &t->divider);
|
||||
gemui_color_parse("#3fb950", &t->success);
|
||||
gemui_color_parse("#58a6ff", &t->info);
|
||||
gemui_color_parse("#d29922", &t->warning);
|
||||
gemui_color_parse("#f85149", &t->danger);
|
||||
gemui_color_parse("#4d1c20", &t->danger_bg);
|
||||
gemui_color_parse("#08090b", &t->bg_main);
|
||||
gemui_color_parse("#0e1014", &t->bg_bar);
|
||||
gemui_color_parse("#12151a", &t->bg_header);
|
||||
gemui_color_parse("#0b0d11", &t->bg_footer);
|
||||
gemui_color_parse("#171b22", &t->bg_overlay);
|
||||
gemui_color_parse("#101318", &t->bg_alt_even);
|
||||
gemui_color_parse("#14181f", &t->bg_alt_odd);
|
||||
gemui_color_parse("#161a21", &t->bg_input);
|
||||
gemui_color_parse("#1e232c", &t->bg_input_focus);
|
||||
gemui_color_parse("#1c212a", &t->bg_button);
|
||||
gemui_color_parse("#191e27", &t->bg_search);
|
||||
gemui_color_parse("#181d25", &t->bg_bubble_in);
|
||||
gemui_color_parse("#252c38", &t->bg_bubble_out);
|
||||
gemui_color_parse("#1c222b", &t->bg_toast);
|
||||
gemui_color_parse("#e4e8ee", &t->fg_main);
|
||||
gemui_color_parse("#f5f7fa", &t->fg_bright);
|
||||
gemui_color_parse("#89929f", &t->fg_muted);
|
||||
gemui_color_parse("#38414f", &t->sel_bg);
|
||||
gemui_color_parse("#f5f7fa", &t->sel_fg);
|
||||
gemui_color_parse("#cfd6e0", &t->accent);
|
||||
gemui_color_parse("#e5eaf0", &t->accent_alt);
|
||||
gemui_color_parse("#e2bc72", &t->highlight);
|
||||
gemui_color_parse("#2d3440", &t->border);
|
||||
gemui_color_parse("#20252f", &t->divider);
|
||||
gemui_color_parse("#79cf9c", &t->success);
|
||||
gemui_color_parse("#9eb3c8", &t->info);
|
||||
gemui_color_parse("#e2bc72", &t->warning);
|
||||
gemui_color_parse("#e07a7a", &t->danger);
|
||||
gemui_color_parse("#3f1d20", &t->danger_bg);
|
||||
}
|
||||
|
||||
static void gemui_apply_xrm_db(XrmDatabase db, gemui_theme_t *t) {
|
||||
|
||||
+20
-20
@@ -96,32 +96,32 @@ unsigned int tabspaces = 8;
|
||||
/* Terminal colors (16 first used in escape sequence) */
|
||||
static const char *colorname[] = {
|
||||
/* 8 normal colors */
|
||||
"black",
|
||||
"red3",
|
||||
"green3",
|
||||
"yellow3",
|
||||
"blue2",
|
||||
"magenta3",
|
||||
"cyan3",
|
||||
"gray90",
|
||||
"#08090b",
|
||||
"#d97878",
|
||||
"#79cf9c",
|
||||
"#e2bc72",
|
||||
"#8ba6c4",
|
||||
"#b39bc8",
|
||||
"#84b8be",
|
||||
"#d5dce4",
|
||||
|
||||
/* 8 bright colors */
|
||||
"gray50",
|
||||
"red",
|
||||
"green",
|
||||
"yellow",
|
||||
"#5c5cff",
|
||||
"magenta",
|
||||
"cyan",
|
||||
"white",
|
||||
"#5b6370",
|
||||
"#eb9494",
|
||||
"#96deb3",
|
||||
"#edd092",
|
||||
"#a6bdd6",
|
||||
"#cab5dc",
|
||||
"#a2cdd2",
|
||||
"#f5f7fa",
|
||||
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
"#08090b",
|
||||
"#e4e8ee",
|
||||
"#cfd6e0",
|
||||
"#08090b",
|
||||
};
|
||||
|
||||
|
||||
|
||||
+22
-22
@@ -321,28 +321,28 @@ static const UaPreset kUaPresets[] = {
|
||||
};
|
||||
|
||||
struct XresTheme {
|
||||
std::string name = "GeminuxHelio";
|
||||
std::string name = "Anodized";
|
||||
std::string fontFace = "Fira Code, Noto Sans";
|
||||
std::string bgMain = "#0f1419";
|
||||
std::string bgBar = "#0b0e14";
|
||||
std::string bgHeader = "#131922";
|
||||
std::string bgOverlay = "#161d26";
|
||||
std::string bgAltEven = "#121820";
|
||||
std::string bgAltOdd = "#18202a";
|
||||
std::string bgInput = "#0b0e14";
|
||||
std::string bgInputFocus = "#1b2838";
|
||||
std::string bgButton = "#1d2633";
|
||||
std::string fgMain = "#e6e1cf";
|
||||
std::string fgBright = "#ffffff";
|
||||
std::string fgMuted = "#7b8898";
|
||||
std::string selBg = "#2b5278";
|
||||
std::string selFg = "#ffffff";
|
||||
std::string accent = "#59c2ff";
|
||||
std::string accentAlt = "#ffb454";
|
||||
std::string border = "#283444";
|
||||
std::string divider = "#364559";
|
||||
std::string danger = "#f07178";
|
||||
std::string dangerBg = "#4c1d24";
|
||||
std::string bgMain = "#08090b";
|
||||
std::string bgBar = "#0e1014";
|
||||
std::string bgHeader = "#12151a";
|
||||
std::string bgOverlay = "#171b22";
|
||||
std::string bgAltEven = "#101318";
|
||||
std::string bgAltOdd = "#14181f";
|
||||
std::string bgInput = "#161a21";
|
||||
std::string bgInputFocus = "#1e232c";
|
||||
std::string bgButton = "#1c212a";
|
||||
std::string fgMain = "#e4e8ee";
|
||||
std::string fgBright = "#f5f7fa";
|
||||
std::string fgMuted = "#89929f";
|
||||
std::string selBg = "#38414f";
|
||||
std::string selFg = "#f5f7fa";
|
||||
std::string accent = "#cfd6e0";
|
||||
std::string accentAlt = "#e5eaf0";
|
||||
std::string border = "#2d3440";
|
||||
std::string divider = "#20252f";
|
||||
std::string danger = "#e07a7a";
|
||||
std::string dangerBg = "#3f1d20";
|
||||
};
|
||||
|
||||
XresTheme loadXresourcesTheme() {
|
||||
@@ -508,7 +508,7 @@ std::string sanitizeGtkThemeSuffix(const std::string& raw) {
|
||||
out.push_back(static_cast<char>(ch));
|
||||
}
|
||||
}
|
||||
return out.empty() ? "GeminuxHelio" : out;
|
||||
return out.empty() ? "Anodized" : out;
|
||||
}
|
||||
|
||||
void applyGtkThemeCss(BrowserApp* app) {
|
||||
|
||||
Reference in new issue
Block a user