2026-11-22 10:49:59 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
#include "gemui.h"
|
|
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
2026-11-22 22:31:41 +02:00
|
|
|
#include <locale.h>
|
2026-11-22 10:49:59 +02:00
|
|
|
#include <pango/pangocairo.h>
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/un.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
#include <X11/Xresource.h>
|
|
|
|
|
#include <X11/Xutil.h>
|
2026-11-22 15:49:38 +02:00
|
|
|
#include <X11/cursorfont.h>
|
2026-11-22 10:49:59 +02:00
|
|
|
#include <cairo/cairo-xlib.h>
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int fd;
|
|
|
|
|
gemui_fd_cb cb;
|
|
|
|
|
void *ud;
|
|
|
|
|
} gemui_fd_slot_t;
|
|
|
|
|
|
|
|
|
|
struct gemui_app {
|
|
|
|
|
Display *dpy;
|
|
|
|
|
int screen;
|
|
|
|
|
Window root;
|
|
|
|
|
Window win;
|
|
|
|
|
Pixmap backbuf;
|
|
|
|
|
GC gc;
|
|
|
|
|
int bw;
|
|
|
|
|
int bh;
|
|
|
|
|
int w;
|
|
|
|
|
int h;
|
|
|
|
|
Atom wm_delete;
|
|
|
|
|
Atom net_wm_name;
|
|
|
|
|
Atom utf8_string;
|
|
|
|
|
Atom net_wm_state;
|
|
|
|
|
Atom net_wm_state_fs;
|
|
|
|
|
XIM xim;
|
|
|
|
|
XIC xic;
|
|
|
|
|
bool fullscreen_override;
|
|
|
|
|
bool mapped;
|
|
|
|
|
bool need_redraw;
|
|
|
|
|
bool running;
|
|
|
|
|
int exit_code;
|
|
|
|
|
gemui_theme_t theme;
|
|
|
|
|
gemui_handlers_t handlers;
|
|
|
|
|
void *userdata;
|
|
|
|
|
gemui_hit_t hits[GEMUI_MAX_HITS];
|
|
|
|
|
int num_hits;
|
|
|
|
|
gemui_fd_slot_t fds[GEMUI_MAX_FDS];
|
|
|
|
|
int num_fds;
|
|
|
|
|
int timer_ms;
|
|
|
|
|
uint64_t next_timer_ms;
|
|
|
|
|
gemui_timer_cb timer_cb;
|
|
|
|
|
void *timer_ud;
|
|
|
|
|
char toast_msg[256];
|
|
|
|
|
uint64_t toast_until_ms;
|
|
|
|
|
bool ptr_down;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int g_sig_pipe[2] = {-1, -1};
|
|
|
|
|
|
|
|
|
|
static void gemui_sigusr1_handler(int sig) {
|
|
|
|
|
(void)sig;
|
|
|
|
|
if (g_sig_pipe[1] >= 0) {
|
|
|
|
|
int saved = errno;
|
|
|
|
|
char b = 'T';
|
|
|
|
|
ssize_t unused = write(g_sig_pipe[1], &b, 1);
|
|
|
|
|
(void)unused;
|
|
|
|
|
errno = saved;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint64_t gemui_now_ms(void) {
|
|
|
|
|
struct timespec ts;
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
|
return (uint64_t)ts.tv_sec * 1000ULL + (uint64_t)(ts.tv_nsec / 1000000L);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gemui_init_sigpipe(void) {
|
|
|
|
|
if (g_sig_pipe[0] >= 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (pipe(g_sig_pipe) == 0) {
|
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
|
int fl = fcntl(g_sig_pipe[i], F_GETFL, 0);
|
|
|
|
|
if (fl >= 0) {
|
|
|
|
|
fcntl(g_sig_pipe[i], F_SETFL, fl | O_NONBLOCK);
|
|
|
|
|
}
|
|
|
|
|
int fdfl = fcntl(g_sig_pipe[i], F_GETFD, 0);
|
|
|
|
|
if (fdfl >= 0) {
|
|
|
|
|
fcntl(g_sig_pipe[i], F_SETFD, fdfl | FD_CLOEXEC);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
struct sigaction sa;
|
|
|
|
|
memset(&sa, 0, sizeof(sa));
|
|
|
|
|
sa.sa_handler = gemui_sigusr1_handler;
|
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
|
sigaction(SIGUSR1, &sa, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int hex_val(char c) {
|
|
|
|
|
if (c >= '0' && c <= '9') return c - '0';
|
|
|
|
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
|
|
|
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool gemui_color_parse(const char *hex, gemui_color_t *out) {
|
|
|
|
|
if (!hex || !out) return false;
|
|
|
|
|
while (*hex == ' ' || *hex == '\t') hex++;
|
|
|
|
|
if (*hex == '#') hex++;
|
|
|
|
|
size_t n = strlen(hex);
|
|
|
|
|
if (n < 6) return false;
|
|
|
|
|
int vals[6];
|
|
|
|
|
for (int i = 0; i < 6; i++) {
|
|
|
|
|
vals[i] = hex_val(hex[i]);
|
|
|
|
|
if (vals[i] < 0) return false;
|
|
|
|
|
}
|
|
|
|
|
uint8_t r = (uint8_t)((vals[0] << 4) | vals[1]);
|
|
|
|
|
uint8_t g = (uint8_t)((vals[2] << 4) | vals[3]);
|
|
|
|
|
uint8_t b = (uint8_t)((vals[4] << 4) | vals[5]);
|
|
|
|
|
out->r = r / 255.0;
|
|
|
|
|
out->g = g / 255.0;
|
|
|
|
|
out->b = b / 255.0;
|
|
|
|
|
out->a = 1.0;
|
|
|
|
|
out->argb = 0xff000000U | ((uint32_t)r << 16) | ((uint32_t)g << 8) | (uint32_t)b;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_theme_defaults(gemui_theme_t *t) {
|
|
|
|
|
memset(t, 0, sizeof(*t));
|
|
|
|
|
snprintf(t->name, sizeof(t->name), "GeminuxHelio");
|
|
|
|
|
snprintf(t->font_face, sizeof(t->font_face), "Fira Code");
|
|
|
|
|
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "DejaVuSansM Nerd Font");
|
2026-11-22 15:49:38 +02:00
|
|
|
t->base_font_size = 32;
|
|
|
|
|
t->dpi = 192;
|
2026-11-22 10:49:59 +02:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gemui_apply_xrm_db(XrmDatabase db, gemui_theme_t *t) {
|
|
|
|
|
if (!db) return;
|
|
|
|
|
char *type = NULL;
|
|
|
|
|
XrmValue val;
|
|
|
|
|
|
|
|
|
|
struct {
|
|
|
|
|
const char *key;
|
|
|
|
|
gemui_color_t *dst;
|
|
|
|
|
} colors[] = {
|
|
|
|
|
{ "theme.bgMain", &t->bg_main },
|
|
|
|
|
{ "theme.bgBar", &t->bg_bar },
|
|
|
|
|
{ "theme.bgHeader", &t->bg_header },
|
|
|
|
|
{ "theme.bgFooter", &t->bg_footer },
|
|
|
|
|
{ "theme.bgOverlay", &t->bg_overlay },
|
|
|
|
|
{ "theme.bgAltEven", &t->bg_alt_even },
|
|
|
|
|
{ "theme.bgAltOdd", &t->bg_alt_odd },
|
|
|
|
|
{ "theme.bgInput", &t->bg_input },
|
|
|
|
|
{ "theme.bgInputFocus", &t->bg_input_focus },
|
|
|
|
|
{ "theme.bgButton", &t->bg_button },
|
|
|
|
|
{ "theme.bgSearch", &t->bg_search },
|
|
|
|
|
{ "theme.bgBubbleIn", &t->bg_bubble_in },
|
|
|
|
|
{ "theme.bgBubbleOut", &t->bg_bubble_out },
|
|
|
|
|
{ "theme.bgToast", &t->bg_toast },
|
|
|
|
|
{ "theme.fgMain", &t->fg_main },
|
|
|
|
|
{ "theme.fgBright", &t->fg_bright },
|
|
|
|
|
{ "theme.fgMuted", &t->fg_muted },
|
|
|
|
|
{ "theme.selBg", &t->sel_bg },
|
|
|
|
|
{ "theme.selFg", &t->sel_fg },
|
|
|
|
|
{ "theme.accent", &t->accent },
|
|
|
|
|
{ "theme.accentAlt", &t->accent_alt },
|
|
|
|
|
{ "theme.highlight", &t->highlight },
|
|
|
|
|
{ "theme.border", &t->border },
|
|
|
|
|
{ "theme.divider", &t->divider },
|
|
|
|
|
{ "theme.success", &t->success },
|
|
|
|
|
{ "theme.info", &t->info },
|
|
|
|
|
{ "theme.warning", &t->warning },
|
|
|
|
|
{ "theme.danger", &t->danger },
|
|
|
|
|
{ "theme.dangerBg", &t->danger_bg },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < sizeof(colors) / sizeof(colors[0]); i++) {
|
|
|
|
|
if (XrmGetResource(db, colors[i].key, "Theme.Color", &type, &val) && val.addr) {
|
|
|
|
|
gemui_color_parse(val.addr, colors[i].dst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (XrmGetResource(db, "theme.name", "Theme.Name", &type, &val) && val.addr) {
|
|
|
|
|
snprintf(t->name, sizeof(t->name), "%s", val.addr);
|
|
|
|
|
}
|
|
|
|
|
if (XrmGetResource(db, "theme.fontFace", "Theme.FontFace", &type, &val) && val.addr) {
|
|
|
|
|
snprintf(t->font_face, sizeof(t->font_face), "%s", val.addr);
|
|
|
|
|
}
|
|
|
|
|
if (XrmGetResource(db, "theme.iconFontFace", "Theme.IconFontFace", &type, &val) && val.addr) {
|
|
|
|
|
snprintf(t->icon_font_face, sizeof(t->icon_font_face), "%s", val.addr);
|
|
|
|
|
}
|
|
|
|
|
if (XrmGetResource(db, "theme.baseFontSize", "Theme.BaseFontSize", &type, &val) && val.addr) {
|
|
|
|
|
int sz = atoi(val.addr);
|
2026-11-22 15:49:38 +02:00
|
|
|
if (sz >= 10 && sz <= 64) t->base_font_size = sz;
|
2026-11-22 10:49:59 +02:00
|
|
|
}
|
|
|
|
|
if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &val) && val.addr) {
|
|
|
|
|
int d = atoi(val.addr);
|
|
|
|
|
if (d >= 72 && d <= 480) t->dpi = d;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool gemui_theme_load_file(const char *path, gemui_theme_t *out) {
|
|
|
|
|
if (!path || !out) return false;
|
|
|
|
|
XrmInitialize();
|
|
|
|
|
gemui_theme_defaults(out);
|
|
|
|
|
XrmDatabase db = XrmGetFileDatabase(path);
|
|
|
|
|
if (!db) return false;
|
|
|
|
|
gemui_apply_xrm_db(db, out);
|
|
|
|
|
XrmDestroyDatabase(db);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_theme_reload(gemui_app_t *app) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
XrmInitialize();
|
|
|
|
|
gemui_theme_defaults(&app->theme);
|
|
|
|
|
|
|
|
|
|
const char *xrm_str = XResourceManagerString(app->dpy);
|
|
|
|
|
if (xrm_str) {
|
|
|
|
|
XrmDatabase mem_db = XrmGetStringDatabase(xrm_str);
|
|
|
|
|
if (mem_db) {
|
|
|
|
|
gemui_apply_xrm_db(mem_db, &app->theme);
|
|
|
|
|
XrmDestroyDatabase(mem_db);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *home = getenv("HOME");
|
|
|
|
|
char path[512];
|
|
|
|
|
if (home && home[0]) {
|
|
|
|
|
snprintf(path, sizeof(path), "%s/.Xresources", home);
|
|
|
|
|
XrmDatabase fdb = XrmGetFileDatabase(path);
|
|
|
|
|
if (!fdb) {
|
|
|
|
|
fdb = XrmGetFileDatabase("/etc/skel/.Xresources");
|
|
|
|
|
}
|
|
|
|
|
if (fdb) {
|
|
|
|
|
gemui_apply_xrm_db(fdb, &app->theme);
|
|
|
|
|
XrmDestroyDatabase(fdb);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
XrmDatabase fdb = XrmGetFileDatabase("/etc/skel/.Xresources");
|
|
|
|
|
if (fdb) {
|
|
|
|
|
gemui_apply_xrm_db(fdb, &app->theme);
|
|
|
|
|
XrmDestroyDatabase(fdb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gemui_ensure_backbuf(gemui_app_t *app) {
|
|
|
|
|
if (app->w <= 0 || app->h <= 0) return;
|
|
|
|
|
if (app->backbuf && app->bw == app->w && app->bh == app->h) return;
|
|
|
|
|
if (app->backbuf) {
|
|
|
|
|
XFreePixmap(app->dpy, app->backbuf);
|
|
|
|
|
app->backbuf = 0;
|
|
|
|
|
}
|
|
|
|
|
app->backbuf = XCreatePixmap(app->dpy, app->win, (unsigned int)app->w,
|
|
|
|
|
(unsigned int)app->h,
|
|
|
|
|
(unsigned int)DefaultDepth(app->dpy, app->screen));
|
|
|
|
|
app->bw = app->w;
|
|
|
|
|
app->bh = app->h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gemui_app_t *gemui_create(const char *res_name, const char *title,
|
|
|
|
|
int w, int h, bool fullscreen_override) {
|
2026-11-22 22:31:41 +02:00
|
|
|
setlocale(LC_CTYPE, "");
|
|
|
|
|
XSetLocaleModifiers("");
|
2026-11-22 10:49:59 +02:00
|
|
|
gemui_init_sigpipe();
|
|
|
|
|
Display *dpy = XOpenDisplay(NULL);
|
|
|
|
|
if (!dpy) {
|
|
|
|
|
fprintf(stderr, "gemui: cannot open X11 display\n");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gemui_app_t *app = calloc(1, sizeof(*app));
|
|
|
|
|
if (!app) {
|
|
|
|
|
XCloseDisplay(dpy);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app->dpy = dpy;
|
|
|
|
|
app->screen = DefaultScreen(dpy);
|
|
|
|
|
app->root = RootWindow(dpy, app->screen);
|
|
|
|
|
app->fullscreen_override = fullscreen_override;
|
|
|
|
|
|
|
|
|
|
int sw = DisplayWidth(dpy, app->screen);
|
|
|
|
|
int sh = DisplayHeight(dpy, app->screen);
|
|
|
|
|
if (fullscreen_override || w <= 0) w = sw;
|
|
|
|
|
if (fullscreen_override || h <= 0) h = sh;
|
|
|
|
|
app->w = w;
|
|
|
|
|
app->h = h;
|
|
|
|
|
|
|
|
|
|
gemui_theme_reload(app);
|
|
|
|
|
|
|
|
|
|
XSetWindowAttributes swa;
|
|
|
|
|
memset(&swa, 0, sizeof(swa));
|
|
|
|
|
swa.background_pixel = BlackPixel(dpy, app->screen);
|
|
|
|
|
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |
|
|
|
|
|
ButtonReleaseMask | PointerMotionMask |
|
|
|
|
|
StructureNotifyMask | FocusChangeMask;
|
|
|
|
|
if (fullscreen_override) {
|
|
|
|
|
swa.override_redirect = True;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long mask = CWBackPixel | CWEventMask | (fullscreen_override ? CWOverrideRedirect : 0);
|
|
|
|
|
app->win = XCreateWindow(dpy, app->root, 0, 0, (unsigned int)w, (unsigned int)h, 0,
|
|
|
|
|
CopyFromParent, InputOutput, CopyFromParent, mask, &swa);
|
2026-11-22 15:49:38 +02:00
|
|
|
{
|
|
|
|
|
Cursor cur = XCreateFontCursor(dpy, XC_left_ptr);
|
|
|
|
|
if (cur != None) {
|
|
|
|
|
XDefineCursor(dpy, app->win, cur);
|
|
|
|
|
XFreeCursor(dpy, cur);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
app->gc = XCreateGC(dpy, app->win, 0, NULL);
|
|
|
|
|
|
|
|
|
|
XClassHint *ch = XAllocClassHint();
|
|
|
|
|
if (ch) {
|
|
|
|
|
ch->res_name = (char *)(res_name ? res_name : "geminux-app");
|
|
|
|
|
ch->res_class = (char *)(res_name ? res_name : "geminux-app");
|
|
|
|
|
XSetClassHint(dpy, app->win, ch);
|
|
|
|
|
XFree(ch);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app->wm_delete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
|
|
|
|
app->net_wm_name = XInternAtom(dpy, "_NET_WM_NAME", False);
|
|
|
|
|
app->utf8_string = XInternAtom(dpy, "UTF8_STRING", False);
|
|
|
|
|
app->net_wm_state = XInternAtom(dpy, "_NET_WM_STATE", False);
|
|
|
|
|
app->net_wm_state_fs = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
|
|
|
|
|
XSetWMProtocols(dpy, app->win, &app->wm_delete, 1);
|
|
|
|
|
|
|
|
|
|
if (fullscreen_override) {
|
|
|
|
|
XChangeProperty(dpy, app->win, app->net_wm_state, XA_ATOM, 32,
|
|
|
|
|
PropModeReplace, (unsigned char *)&app->net_wm_state_fs, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gemui_set_title(app, title ? title : "Geminux");
|
|
|
|
|
|
|
|
|
|
app->xim = XOpenIM(dpy, NULL, NULL, NULL);
|
|
|
|
|
if (app->xim) {
|
|
|
|
|
app->xic = XCreateIC(app->xim, XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
|
|
|
|
XNClientWindow, app->win, XNFocusWindow, app->win, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XMapRaised(dpy, app->win);
|
|
|
|
|
if (fullscreen_override) {
|
|
|
|
|
XMoveResizeWindow(dpy, app->win, 0, 0, (unsigned int)sw, (unsigned int)sh);
|
|
|
|
|
XSetInputFocus(dpy, app->win, RevertToPointerRoot, CurrentTime);
|
|
|
|
|
}
|
|
|
|
|
XFlush(dpy);
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
return app;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_destroy(gemui_app_t *app) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
if (app->xic) XDestroyIC(app->xic);
|
|
|
|
|
if (app->xim) XCloseIM(app->xim);
|
|
|
|
|
if (app->backbuf) XFreePixmap(app->dpy, app->backbuf);
|
|
|
|
|
if (app->gc) XFreeGC(app->dpy, app->gc);
|
|
|
|
|
if (app->win) XDestroyWindow(app->dpy, app->win);
|
|
|
|
|
if (app->dpy) XCloseDisplay(app->dpy);
|
|
|
|
|
free(app);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_set_handlers(gemui_app_t *app, const gemui_handlers_t *h, void *userdata) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
if (h) app->handlers = *h;
|
|
|
|
|
app->userdata = userdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_set_title(gemui_app_t *app, const char *title) {
|
|
|
|
|
if (!app || !title) return;
|
|
|
|
|
XStoreName(app->dpy, app->win, title);
|
|
|
|
|
XChangeProperty(app->dpy, app->win, app->net_wm_name, app->utf8_string, 8,
|
|
|
|
|
PropModeReplace, (const unsigned char *)title, (int)strlen(title));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Display *gemui_display(const gemui_app_t *app) { return app ? app->dpy : NULL; }
|
|
|
|
|
Window gemui_window(const gemui_app_t *app) { return app ? app->win : 0; }
|
|
|
|
|
const gemui_theme_t *gemui_theme(const gemui_app_t *app) { return app ? &app->theme : NULL; }
|
|
|
|
|
int gemui_width(const gemui_app_t *app) { return app ? app->w : 0; }
|
|
|
|
|
int gemui_height(const gemui_app_t *app) { return app ? app->h : 0; }
|
|
|
|
|
|
|
|
|
|
int gemui_scale_px(const gemui_app_t *app, int logical_px) {
|
2026-11-22 15:49:38 +02:00
|
|
|
int dpi = app ? app->theme.dpi : 180;
|
2026-11-22 10:49:59 +02:00
|
|
|
return (logical_px * dpi + 48) / 96;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata) {
|
|
|
|
|
if (!app || fd < 0 || app->num_fds >= GEMUI_MAX_FDS) return -1;
|
|
|
|
|
for (int i = 0; i < app->num_fds; i++) {
|
|
|
|
|
if (app->fds[i].fd == fd) {
|
|
|
|
|
app->fds[i].cb = cb;
|
|
|
|
|
app->fds[i].ud = userdata;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
app->fds[app->num_fds].fd = fd;
|
|
|
|
|
app->fds[app->num_fds].cb = cb;
|
|
|
|
|
app->fds[app->num_fds].ud = userdata;
|
|
|
|
|
app->num_fds++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_del_fd(gemui_app_t *app, int fd) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
for (int i = 0; i < app->num_fds; i++) {
|
|
|
|
|
if (app->fds[i].fd == fd) {
|
|
|
|
|
app->fds[i] = app->fds[app->num_fds - 1];
|
|
|
|
|
app->num_fds--;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_set_timer_ms(gemui_app_t *app, int interval_ms, gemui_timer_cb cb, void *userdata) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
app->timer_ms = interval_ms;
|
|
|
|
|
app->timer_cb = cb;
|
|
|
|
|
app->timer_ud = userdata;
|
|
|
|
|
app->next_timer_ms = (interval_ms > 0) ? (gemui_now_ms() + (uint64_t)interval_ms) : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_request_redraw(gemui_app_t *app) {
|
|
|
|
|
if (app) app->need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_show_toast(gemui_app_t *app, const char *msg, int duration_ms) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
if (!msg || !msg[0]) {
|
|
|
|
|
app->toast_msg[0] = '\0';
|
|
|
|
|
app->toast_until_ms = 0;
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(app->toast_msg, sizeof(app->toast_msg), "%s", msg);
|
|
|
|
|
app->toast_until_ms = gemui_now_ms() + (uint64_t)(duration_ms > 0 ? duration_ms : 2200);
|
|
|
|
|
}
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_quit(gemui_app_t *app, int code) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
app->exit_code = code;
|
|
|
|
|
app->running = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool gemui_grab_input(gemui_app_t *app) {
|
|
|
|
|
if (!app) return false;
|
|
|
|
|
bool ok_kbd = XGrabKeyboard(app->dpy, app->win, True, GrabModeAsync,
|
|
|
|
|
GrabModeAsync, CurrentTime) == GrabSuccess;
|
|
|
|
|
XGrabPointer(app->dpy, app->win, True,
|
|
|
|
|
ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
|
|
|
|
|
GrabModeAsync, GrabModeAsync, app->win, None, CurrentTime);
|
|
|
|
|
XSetInputFocus(app->dpy, app->win, RevertToPointerRoot, CurrentTime);
|
|
|
|
|
XFlush(app->dpy);
|
|
|
|
|
return ok_kbd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_ungrab_input(gemui_app_t *app) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
XUngrabKeyboard(app->dpy, CurrentTime);
|
|
|
|
|
XUngrabPointer(app->dpy, CurrentTime);
|
|
|
|
|
XFlush(app->dpy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_hits_clear(gemui_app_t *app) {
|
|
|
|
|
if (app) app->num_hits = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_hit_add(gemui_app_t *app, gemui_rect_t r, int id, int val) {
|
|
|
|
|
if (!app || app->num_hits >= GEMUI_MAX_HITS) return;
|
|
|
|
|
app->hits[app->num_hits].r = r;
|
|
|
|
|
app->hits[app->num_hits].id = id;
|
|
|
|
|
app->hits[app->num_hits].val = val;
|
|
|
|
|
app->num_hits++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const gemui_hit_t *gemui_hit_test(const gemui_app_t *app, int x, int y) {
|
|
|
|
|
if (!app) return NULL;
|
|
|
|
|
for (int i = app->num_hits - 1; i >= 0; i--) {
|
|
|
|
|
gemui_rect_t r = app->hits[i].r;
|
|
|
|
|
if (x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h) {
|
|
|
|
|
return &app->hits[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gemui_render_frame(gemui_app_t *app) {
|
|
|
|
|
if (!app || !app->need_redraw || app->w <= 0 || app->h <= 0) return;
|
|
|
|
|
gemui_ensure_backbuf(app);
|
|
|
|
|
if (!app->backbuf) return;
|
|
|
|
|
|
|
|
|
|
cairo_surface_t *surf = cairo_xlib_surface_create(
|
|
|
|
|
app->dpy, app->backbuf, DefaultVisual(app->dpy, app->screen), app->w, app->h);
|
|
|
|
|
cairo_t *cr = cairo_create(surf);
|
|
|
|
|
|
|
|
|
|
gemui_hits_clear(app);
|
|
|
|
|
gemui_fill_rect(cr, (gemui_rect_t){0, 0, app->w, app->h}, app->theme.bg_main);
|
|
|
|
|
if (app->handlers.on_draw) {
|
|
|
|
|
app->handlers.on_draw(app, cr, app->w, app->h, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
gemui_draw_toast(app, cr);
|
|
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
|
cairo_surface_flush(surf);
|
|
|
|
|
cairo_surface_destroy(surf);
|
|
|
|
|
|
|
|
|
|
XCopyArea(app->dpy, app->backbuf, app->win, app->gc, 0, 0,
|
|
|
|
|
(unsigned int)app->w, (unsigned int)app->h, 0, 0);
|
|
|
|
|
XFlush(app->dpy);
|
|
|
|
|
app->need_redraw = false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 22:31:41 +02:00
|
|
|
void gemui_flush_draw(gemui_app_t *app) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
gemui_render_frame(app);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 10:49:59 +02:00
|
|
|
static void gemui_handle_x_events(gemui_app_t *app) {
|
|
|
|
|
while (XPending(app->dpy) > 0 && app->running) {
|
|
|
|
|
XEvent ev;
|
|
|
|
|
XNextEvent(app->dpy, &ev);
|
|
|
|
|
if (XFilterEvent(&ev, None)) continue;
|
|
|
|
|
|
|
|
|
|
switch (ev.type) {
|
|
|
|
|
case Expose:
|
|
|
|
|
if (ev.xexpose.count == 0) app->need_redraw = true;
|
|
|
|
|
break;
|
|
|
|
|
case ConfigureNotify:
|
|
|
|
|
if (ev.xconfigure.width != app->w || ev.xconfigure.height != app->h) {
|
|
|
|
|
app->w = ev.xconfigure.width;
|
|
|
|
|
app->h = ev.xconfigure.height;
|
|
|
|
|
if (app->handlers.on_resize) {
|
|
|
|
|
app->handlers.on_resize(app, app->w, app->h, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ClientMessage:
|
|
|
|
|
if ((Atom)ev.xclient.data.l[0] == app->wm_delete) {
|
|
|
|
|
gemui_quit(app, 0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case KeyPress: {
|
|
|
|
|
char buf[64] = {0};
|
|
|
|
|
KeySym ks = NoSymbol;
|
|
|
|
|
Status st = 0;
|
|
|
|
|
int len = 0;
|
|
|
|
|
if (app->xic) {
|
|
|
|
|
len = Xutf8LookupString(app->xic, &ev.xkey, buf, (int)sizeof(buf) - 1, &ks, &st);
|
|
|
|
|
} else {
|
|
|
|
|
len = XLookupString(&ev.xkey, buf, (int)sizeof(buf) - 1, &ks, NULL);
|
|
|
|
|
}
|
|
|
|
|
if (len < 0) len = 0;
|
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
/* Ignore bare control characters like Ctrl+C/Backspace inside utf8 text buffer */
|
|
|
|
|
if (len > 0 && ((unsigned char)buf[0] < 0x20 || buf[0] == 0x7f)) {
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
}
|
|
|
|
|
if (app->handlers.on_key) {
|
|
|
|
|
app->handlers.on_key(app, ks, ev.xkey.state, buf, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ButtonPress:
|
|
|
|
|
if (ev.xbutton.button == Button4) {
|
|
|
|
|
if (app->handlers.on_ptr) {
|
|
|
|
|
app->handlers.on_ptr(app, GEMUI_PTR_SCROLL_UP, ev.xbutton.x, ev.xbutton.y,
|
|
|
|
|
ev.xbutton.button, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
} else if (ev.xbutton.button == Button5) {
|
|
|
|
|
if (app->handlers.on_ptr) {
|
|
|
|
|
app->handlers.on_ptr(app, GEMUI_PTR_SCROLL_DOWN, ev.xbutton.x, ev.xbutton.y,
|
|
|
|
|
ev.xbutton.button, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
app->ptr_down = true;
|
|
|
|
|
if (app->handlers.on_ptr) {
|
|
|
|
|
app->handlers.on_ptr(app, GEMUI_PTR_DOWN, ev.xbutton.x, ev.xbutton.y,
|
|
|
|
|
ev.xbutton.button, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MotionNotify:
|
|
|
|
|
if (app->ptr_down && app->handlers.on_ptr) {
|
|
|
|
|
app->handlers.on_ptr(app, GEMUI_PTR_MOVE, ev.xmotion.x, ev.xmotion.y,
|
|
|
|
|
0, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case ButtonRelease:
|
|
|
|
|
if (ev.xbutton.button != Button4 && ev.xbutton.button != Button5) {
|
|
|
|
|
app->ptr_down = false;
|
|
|
|
|
if (app->handlers.on_ptr) {
|
|
|
|
|
app->handlers.on_ptr(app, GEMUI_PTR_UP, ev.xbutton.x, ev.xbutton.y,
|
|
|
|
|
ev.xbutton.button, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_run(gemui_app_t *app) {
|
|
|
|
|
if (!app) return 1;
|
|
|
|
|
app->running = true;
|
|
|
|
|
int xfd = ConnectionNumber(app->dpy);
|
|
|
|
|
|
|
|
|
|
while (app->running) {
|
|
|
|
|
gemui_handle_x_events(app);
|
|
|
|
|
if (!app->running) break;
|
|
|
|
|
|
|
|
|
|
uint64_t now = gemui_now_ms();
|
|
|
|
|
if (app->toast_until_ms && now >= app->toast_until_ms) {
|
|
|
|
|
app->toast_msg[0] = '\0';
|
|
|
|
|
app->toast_until_ms = 0;
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
if (app->timer_ms > 0 && app->timer_cb && now >= app->next_timer_ms) {
|
|
|
|
|
app->next_timer_ms = now + (uint64_t)app->timer_ms;
|
|
|
|
|
app->timer_cb(app, app->timer_ud);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (app->need_redraw) {
|
|
|
|
|
gemui_render_frame(app);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int timeout_ms = -1;
|
|
|
|
|
now = gemui_now_ms();
|
|
|
|
|
if (app->timer_ms > 0 && app->timer_cb) {
|
|
|
|
|
int rem = (app->next_timer_ms > now) ? (int)(app->next_timer_ms - now) : 0;
|
|
|
|
|
timeout_ms = rem;
|
|
|
|
|
}
|
|
|
|
|
if (app->toast_until_ms > 0) {
|
|
|
|
|
int rem = (app->toast_until_ms > now) ? (int)(app->toast_until_ms - now) : 0;
|
|
|
|
|
if (timeout_ms < 0 || rem < timeout_ms) timeout_ms = rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct pollfd pfds[2 + GEMUI_MAX_FDS];
|
|
|
|
|
nfds_t nfds = 0;
|
|
|
|
|
pfds[nfds].fd = xfd;
|
|
|
|
|
pfds[nfds].events = POLLIN;
|
|
|
|
|
pfds[nfds].revents = 0;
|
|
|
|
|
nfds++;
|
|
|
|
|
|
|
|
|
|
int sig_idx = -1;
|
|
|
|
|
if (g_sig_pipe[0] >= 0) {
|
|
|
|
|
sig_idx = (int)nfds;
|
|
|
|
|
pfds[nfds].fd = g_sig_pipe[0];
|
|
|
|
|
pfds[nfds].events = POLLIN;
|
|
|
|
|
pfds[nfds].revents = 0;
|
|
|
|
|
nfds++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int extra_start = (int)nfds;
|
|
|
|
|
for (int i = 0; i < app->num_fds; i++) {
|
|
|
|
|
pfds[nfds].fd = app->fds[i].fd;
|
|
|
|
|
pfds[nfds].events = POLLIN;
|
|
|
|
|
pfds[nfds].revents = 0;
|
|
|
|
|
nfds++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (XPending(app->dpy) > 0) continue;
|
|
|
|
|
|
|
|
|
|
int rc = poll(pfds, nfds, timeout_ms);
|
|
|
|
|
if (rc < 0 && errno == EINTR) continue;
|
|
|
|
|
|
|
|
|
|
if (sig_idx >= 0 && (pfds[sig_idx].revents & POLLIN)) {
|
|
|
|
|
char drain[32];
|
|
|
|
|
while (read(g_sig_pipe[0], drain, sizeof(drain)) > 0) {}
|
|
|
|
|
gemui_theme_reload(app);
|
|
|
|
|
if (app->handlers.on_theme) {
|
|
|
|
|
app->handlers.on_theme(app, app->userdata);
|
|
|
|
|
}
|
|
|
|
|
app->need_redraw = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < app->num_fds; i++) {
|
|
|
|
|
int idx = extra_start + i;
|
|
|
|
|
if (idx < (int)nfds && (pfds[idx].revents & (POLLIN | POLLHUP | POLLERR))) {
|
|
|
|
|
if (app->fds[i].cb) {
|
|
|
|
|
app->fds[i].cb(app, app->fds[i].fd, app->fds[i].ud);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return app->exit_code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_set_source(cairo_t *cr, gemui_color_t c) {
|
|
|
|
|
cairo_set_source_rgba(cr, c.r, c.g, c.b, c.a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_rounded_rect(cairo_t *cr, gemui_rect_t r, double rad) {
|
|
|
|
|
if (rad <= 0.0) {
|
|
|
|
|
cairo_rectangle(cr, r.x, r.y, r.w, r.h);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (rad > r.w / 2.0) rad = r.w / 2.0;
|
|
|
|
|
if (rad > r.h / 2.0) rad = r.h / 2.0;
|
|
|
|
|
const double pi = 3.14159265358979323846;
|
|
|
|
|
cairo_new_sub_path(cr);
|
|
|
|
|
cairo_arc(cr, r.x + r.w - rad, r.y + rad, rad, -pi / 2.0, 0.0);
|
|
|
|
|
cairo_arc(cr, r.x + r.w - rad, r.y + r.h - rad, rad, 0.0, pi / 2.0);
|
|
|
|
|
cairo_arc(cr, r.x + rad, r.y + r.h - rad, rad, pi / 2.0, pi);
|
|
|
|
|
cairo_arc(cr, r.x + rad, r.y + rad, rad, pi, 3.0 * pi / 2.0);
|
|
|
|
|
cairo_close_path(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_fill_rect(cairo_t *cr, gemui_rect_t r, gemui_color_t c) {
|
|
|
|
|
gemui_set_source(cr, c);
|
|
|
|
|
cairo_rectangle(cr, r.x, r.y, r.w, r.h);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_fill_round(cairo_t *cr, gemui_rect_t r, double radius, gemui_color_t c) {
|
|
|
|
|
gemui_set_source(cr, c);
|
|
|
|
|
gemui_rounded_rect(cr, r, radius);
|
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_stroke_round(cairo_t *cr, gemui_rect_t r, double radius, double lw, gemui_color_t c) {
|
|
|
|
|
gemui_set_source(cr, c);
|
|
|
|
|
cairo_set_line_width(cr, lw);
|
|
|
|
|
gemui_rounded_rect(cr, r, radius);
|
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int gemui_draw_pango(cairo_t *cr, const char *face, int px_size,
|
|
|
|
|
gemui_rect_t r, const char *text, bool bold,
|
|
|
|
|
int align, gemui_color_t c) {
|
|
|
|
|
if (!text || !text[0] || r.w <= 4 || r.h <= 4) return 0;
|
|
|
|
|
PangoLayout *layout = pango_cairo_create_layout(cr);
|
|
|
|
|
char desc_str[160];
|
|
|
|
|
snprintf(desc_str, sizeof(desc_str), "%s%s %dpx",
|
|
|
|
|
face && face[0] ? face : "Fira Code",
|
|
|
|
|
bold ? " Bold" : "",
|
|
|
|
|
px_size > 8 ? px_size : 14);
|
|
|
|
|
PangoFontDescription *desc = pango_font_description_from_string(desc_str);
|
|
|
|
|
pango_layout_set_font_description(layout, desc);
|
|
|
|
|
pango_layout_set_width(layout, r.w * PANGO_SCALE);
|
|
|
|
|
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
|
|
|
|
|
pango_layout_set_single_paragraph_mode(layout, True);
|
|
|
|
|
if (align == GEMUI_ALIGN_CENTER) {
|
|
|
|
|
pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
|
|
|
|
|
} else if (align == GEMUI_ALIGN_RIGHT) {
|
|
|
|
|
pango_layout_set_alignment(layout, PANGO_ALIGN_RIGHT);
|
|
|
|
|
} else {
|
|
|
|
|
pango_layout_set_alignment(layout, PANGO_ALIGN_LEFT);
|
|
|
|
|
}
|
|
|
|
|
pango_layout_set_text(layout, text, -1);
|
|
|
|
|
|
|
|
|
|
int tw = 0, th = 0;
|
|
|
|
|
pango_layout_get_pixel_size(layout, &tw, &th);
|
|
|
|
|
int dy = r.y + (r.h - th) / 2;
|
|
|
|
|
gemui_set_source(cr, c);
|
|
|
|
|
cairo_move_to(cr, r.x, dy);
|
|
|
|
|
pango_cairo_show_layout(cr, layout);
|
|
|
|
|
|
|
|
|
|
pango_font_description_free(desc);
|
|
|
|
|
g_object_unref(layout);
|
|
|
|
|
return tw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_draw_text(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
|
|
|
|
|
const char *text, int pt_delta, bool bold, int align, gemui_color_t c) {
|
2026-11-22 15:49:38 +02:00
|
|
|
int px = (t ? t->base_font_size : 28) + pt_delta;
|
2026-11-22 10:49:59 +02:00
|
|
|
char fam[200];
|
|
|
|
|
snprintf(fam, sizeof(fam), "%s, %s",
|
|
|
|
|
(t && t->font_face[0]) ? t->font_face : "Fira Code",
|
|
|
|
|
(t && t->icon_font_face[0]) ? t->icon_font_face : "DejaVuSansM Nerd Font");
|
|
|
|
|
return gemui_draw_pango(cr, fam, px, r, text, bold, align, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_draw_icon(cairo_t *cr, const gemui_theme_t *t, gemui_rect_t r,
|
|
|
|
|
const char *icon_utf8, int pt_delta, int align, gemui_color_t c) {
|
2026-11-22 15:49:38 +02:00
|
|
|
int px = (t ? t->base_font_size : 28) + pt_delta;
|
2026-11-22 10:49:59 +02:00
|
|
|
const char *iface = (t && t->icon_font_face[0]) ? t->icon_font_face : "DejaVuSansM Nerd Font";
|
|
|
|
|
return gemui_draw_pango(cr, iface, px, r, icon_utf8, false, align, c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_header(gemui_app_t *app, cairo_t *cr, const char *icon,
|
|
|
|
|
const char *title, const char *right_badge) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
2026-11-22 15:49:38 +02:00
|
|
|
int hh = 76;
|
2026-11-22 10:49:59 +02:00
|
|
|
gemui_fill_rect(cr, (gemui_rect_t){0, 0, app->w, hh}, t->bg_header);
|
|
|
|
|
gemui_fill_rect(cr, (gemui_rect_t){0, hh - 2, app->w, 2}, t->divider);
|
|
|
|
|
|
|
|
|
|
int x = 20;
|
|
|
|
|
if (icon && icon[0]) {
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_draw_icon(cr, t, (gemui_rect_t){x, 6, 52, hh - 12}, icon, 6, GEMUI_ALIGN_CENTER, t->accent);
|
|
|
|
|
x += 56;
|
2026-11-22 10:49:59 +02:00
|
|
|
}
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){x, 6, app->w - x - 420, hh - 12},
|
2026-11-22 10:49:59 +02:00
|
|
|
title ? title : "", 4, true, GEMUI_ALIGN_LEFT, t->fg_bright);
|
|
|
|
|
|
|
|
|
|
if (right_badge && right_badge[0]) {
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t br = {app->w - 400, 12, 380, hh - 24};
|
|
|
|
|
gemui_fill_round(cr, br, 12, t->bg_overlay);
|
|
|
|
|
gemui_stroke_round(cr, br, 12, 1.5, t->border);
|
2026-11-22 10:49:59 +02:00
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){br.x + 12, br.y, br.w - 24, br.h},
|
|
|
|
|
right_badge, -2, false, GEMUI_ALIGN_CENTER, t->fg_main);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_button(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
|
|
|
|
const char *label, int hit_id, int hit_val,
|
|
|
|
|
bool primary, bool active, bool focused) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
|
|
|
|
gemui_color_t bg = active ? t->sel_bg : (primary ? t->accent : t->bg_button);
|
|
|
|
|
gemui_color_t fg = (active || primary) ? t->sel_fg : t->fg_bright;
|
|
|
|
|
gemui_color_t bd = focused ? t->highlight : (active ? t->sel_bg : t->border);
|
|
|
|
|
|
|
|
|
|
gemui_fill_round(cr, r, 10, bg);
|
|
|
|
|
gemui_stroke_round(cr, r, 10, focused ? 3.0 : 1.5, bd);
|
|
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + 10, r.y + 2, r.w - 20, r.h - 4},
|
|
|
|
|
label ? label : "", 0, primary || active, GEMUI_ALIGN_CENTER, fg);
|
|
|
|
|
if (hit_id >= 0) {
|
|
|
|
|
gemui_hit_add(app, r, hit_id, hit_val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_toggle(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
|
|
|
|
const char *label, bool on, int hit_id, int hit_val, bool focused) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
|
|
|
|
gemui_fill_round(cr, r, 10, t->bg_alt_even);
|
|
|
|
|
gemui_stroke_round(cr, r, 10, focused ? 3.0 : 1.5, focused ? t->highlight : t->border);
|
|
|
|
|
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + 16, r.y, r.w - 144, r.h},
|
2026-11-22 10:49:59 +02:00
|
|
|
label ? label : "", 0, false, GEMUI_ALIGN_LEFT, t->fg_main);
|
|
|
|
|
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t pill = {r.x + r.w - 114, r.y + (r.h - 44) / 2, 96, 44};
|
|
|
|
|
gemui_fill_round(cr, pill, 22, on ? t->success : t->bg_overlay);
|
|
|
|
|
gemui_stroke_round(cr, pill, 22, 1.5, on ? t->success : t->border);
|
2026-11-22 10:49:59 +02:00
|
|
|
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t knob = {on ? (pill.x + pill.w - 40) : (pill.x + 4), pill.y + 4, 36, 36};
|
|
|
|
|
gemui_fill_round(cr, knob, 18, t->fg_bright);
|
2026-11-22 10:49:59 +02:00
|
|
|
if (hit_id >= 0) {
|
|
|
|
|
gemui_hit_add(app, r, hit_id, hit_val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_slider(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
|
|
|
|
const char *label, double norm_val, const char *val_text,
|
|
|
|
|
int hit_id, int hit_val, bool focused) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
|
|
|
|
if (norm_val < 0.0) norm_val = 0.0;
|
|
|
|
|
if (norm_val > 1.0) norm_val = 1.0;
|
|
|
|
|
|
|
|
|
|
gemui_fill_round(cr, r, 10, t->bg_alt_even);
|
|
|
|
|
gemui_stroke_round(cr, r, 10, focused ? 3.0 : 1.5, focused ? t->highlight : t->border);
|
|
|
|
|
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + 16, r.y + 8, r.w / 2, 40},
|
2026-11-22 10:49:59 +02:00
|
|
|
label ? label : "", -1, true, GEMUI_ALIGN_LEFT, t->fg_bright);
|
|
|
|
|
if (val_text && val_text[0]) {
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + r.w / 2, r.y + 8, r.w / 2 - 16, 40},
|
2026-11-22 10:49:59 +02:00
|
|
|
val_text, -1, false, GEMUI_ALIGN_RIGHT, t->accent);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t track = {r.x + 18, r.y + r.h - 24, r.w - 36, 14};
|
|
|
|
|
gemui_fill_round(cr, track, 7, t->bg_overlay);
|
2026-11-22 10:49:59 +02:00
|
|
|
int fw = (int)(track.w * norm_val);
|
|
|
|
|
if (fw > 0) {
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_fill_round(cr, (gemui_rect_t){track.x, track.y, fw, track.h}, 7, t->accent);
|
2026-11-22 10:49:59 +02:00
|
|
|
}
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t knob = {track.x + fw - 14, track.y - 7, 28, 28};
|
|
|
|
|
gemui_fill_round(cr, knob, 14, t->fg_bright);
|
2026-11-22 10:49:59 +02:00
|
|
|
if (hit_id >= 0) {
|
|
|
|
|
gemui_hit_add(app, r, hit_id, hit_val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_input(gemui_app_t *app, cairo_t *cr, gemui_rect_t r,
|
|
|
|
|
const char *placeholder, const char *text, bool mask_bullets,
|
|
|
|
|
bool focused, int hit_id, int hit_val) {
|
|
|
|
|
if (!app) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
|
|
|
|
gemui_fill_round(cr, r, 10, focused ? t->bg_input_focus : t->bg_input);
|
|
|
|
|
gemui_stroke_round(cr, r, 10, focused ? 2.5 : 1.5, focused ? t->accent : t->border);
|
|
|
|
|
|
|
|
|
|
char display[512];
|
|
|
|
|
bool empty = (!text || !text[0]);
|
|
|
|
|
if (empty) {
|
|
|
|
|
snprintf(display, sizeof(display), "%s", placeholder ? placeholder : "");
|
|
|
|
|
} else if (mask_bullets) {
|
|
|
|
|
size_t len = strlen(text);
|
|
|
|
|
if (len > 48) len = 48;
|
|
|
|
|
for (size_t i = 0; i < len; i++) display[i] = '*';
|
2026-11-22 22:31:41 +02:00
|
|
|
if (focused && len + 1 < sizeof(display)) display[len++] = '_';
|
2026-11-22 10:49:59 +02:00
|
|
|
display[len] = '\0';
|
|
|
|
|
} else {
|
|
|
|
|
snprintf(display, sizeof(display), "%s%s", text, focused ? "_" : "");
|
|
|
|
|
}
|
|
|
|
|
if (empty && focused && mask_bullets) {
|
|
|
|
|
snprintf(display, sizeof(display), "%s", placeholder ? placeholder : "_");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + 14, r.y + 2, r.w - 28, r.h - 4},
|
|
|
|
|
display, 0, false, GEMUI_ALIGN_LEFT, empty ? t->fg_muted : t->fg_bright);
|
|
|
|
|
if (hit_id >= 0) {
|
|
|
|
|
gemui_hit_add(app, r, hit_id, hit_val);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_draw_toast(gemui_app_t *app, cairo_t *cr) {
|
|
|
|
|
if (!app || !app->toast_msg[0]) return;
|
|
|
|
|
const gemui_theme_t *t = &app->theme;
|
2026-11-22 15:49:38 +02:00
|
|
|
int tw = 820;
|
2026-11-22 10:49:59 +02:00
|
|
|
if (tw > app->w - 80) tw = app->w - 80;
|
2026-11-22 15:49:38 +02:00
|
|
|
gemui_rect_t r = {(app->w - tw) / 2, app->h - 104, tw, 68};
|
2026-11-22 10:49:59 +02:00
|
|
|
gemui_fill_round(cr, r, 12, t->bg_toast);
|
|
|
|
|
gemui_stroke_round(cr, r, 12, 2.0, t->accent);
|
|
|
|
|
gemui_draw_text(cr, t, (gemui_rect_t){r.x + 16, r.y + 4, r.w - 32, r.h - 8},
|
|
|
|
|
app->toast_msg, -1, true, GEMUI_ALIGN_CENTER, t->fg_bright);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_unix_cmd(const char *sock_path, const char *cmd, char *resp, size_t resp_sz) {
|
|
|
|
|
if (!sock_path || !cmd) return -1;
|
|
|
|
|
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
|
|
|
if (fd < 0) return -1;
|
|
|
|
|
|
|
|
|
|
struct timeval tv = {1, 0};
|
|
|
|
|
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
|
|
|
|
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
|
|
|
|
|
|
|
|
|
|
struct sockaddr_un addr;
|
|
|
|
|
memset(&addr, 0, sizeof(addr));
|
|
|
|
|
addr.sun_family = AF_UNIX;
|
|
|
|
|
snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", sock_path);
|
|
|
|
|
|
|
|
|
|
if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
size_t len = strlen(cmd);
|
|
|
|
|
if (write(fd, cmd, len) < 0 || (len == 0 || cmd[len - 1] != '\n' ? write(fd, "\n", 1) < 0 : 0)) {
|
|
|
|
|
close(fd);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
shutdown(fd, SHUT_WR);
|
|
|
|
|
if (resp && resp_sz > 0) {
|
|
|
|
|
size_t off = 0;
|
|
|
|
|
while (off + 1 < resp_sz) {
|
|
|
|
|
ssize_t n = read(fd, resp + off, resp_sz - 1 - off);
|
|
|
|
|
if (n <= 0) break;
|
|
|
|
|
off += (size_t)n;
|
|
|
|
|
}
|
|
|
|
|
resp[off] = '\0';
|
|
|
|
|
}
|
|
|
|
|
close(fd);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int gemui_read_file_line(const char *path, char *buf, size_t sz) {
|
|
|
|
|
if (!path || !buf || sz == 0) return -1;
|
|
|
|
|
FILE *f = fopen(path, "r");
|
|
|
|
|
if (!f) return -1;
|
|
|
|
|
if (!fgets(buf, (int)sz, f)) {
|
|
|
|
|
fclose(f);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
fclose(f);
|
|
|
|
|
size_t n = strlen(buf);
|
|
|
|
|
while (n > 0 && (buf[n - 1] == '\n' || buf[n - 1] == '\r')) {
|
|
|
|
|
buf[--n] = '\0';
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 22:31:41 +02:00
|
|
|
int gemui_run_cmd_timeout(const char *const argv[], char *out, size_t out_sz, int timeout_ms) {
|
2026-11-22 10:49:59 +02:00
|
|
|
if (!argv || !argv[0]) return -1;
|
|
|
|
|
int pfd[2];
|
|
|
|
|
if (pipe(pfd) < 0) return -1;
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
|
if (pid < 0) {
|
|
|
|
|
close(pfd[0]);
|
|
|
|
|
close(pfd[1]);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (pid == 0) {
|
2026-11-22 22:31:41 +02:00
|
|
|
setpgid(0, 0);
|
|
|
|
|
int devnull = open("/dev/null", O_RDONLY);
|
|
|
|
|
if (devnull >= 0) {
|
|
|
|
|
dup2(devnull, STDIN_FILENO);
|
|
|
|
|
if (devnull > 2) close(devnull);
|
|
|
|
|
} else {
|
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
close(pfd[0]);
|
|
|
|
|
dup2(pfd[1], STDOUT_FILENO);
|
|
|
|
|
dup2(pfd[1], STDERR_FILENO);
|
2026-11-22 22:31:41 +02:00
|
|
|
if (pfd[1] > 2) close(pfd[1]);
|
2026-11-22 10:49:59 +02:00
|
|
|
execvp(argv[0], (char *const *)argv);
|
|
|
|
|
_exit(127);
|
|
|
|
|
}
|
|
|
|
|
close(pfd[1]);
|
2026-11-22 22:31:41 +02:00
|
|
|
int fl = fcntl(pfd[0], F_GETFL, 0);
|
|
|
|
|
if (fl >= 0) fcntl(pfd[0], F_SETFL, fl | O_NONBLOCK);
|
|
|
|
|
|
2026-11-22 10:49:59 +02:00
|
|
|
size_t off = 0;
|
2026-11-22 22:31:41 +02:00
|
|
|
char tmp[512];
|
|
|
|
|
uint64_t deadline = (timeout_ms > 0) ? (gemui_now_ms() + (uint64_t)timeout_ms) : UINT64_MAX;
|
|
|
|
|
bool timed_out = false;
|
|
|
|
|
bool eof = false;
|
|
|
|
|
|
|
|
|
|
while (!eof) {
|
|
|
|
|
int wait_ms = -1;
|
|
|
|
|
if (timeout_ms > 0) {
|
|
|
|
|
uint64_t now = gemui_now_ms();
|
|
|
|
|
if (now >= deadline) {
|
|
|
|
|
timed_out = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
uint64_t rem = deadline - now;
|
|
|
|
|
wait_ms = rem > 60000ULL ? 60000 : (int)rem;
|
|
|
|
|
}
|
|
|
|
|
struct pollfd pf = { .fd = pfd[0], .events = POLLIN | POLLHUP };
|
|
|
|
|
int pr = poll(&pf, 1, wait_ms);
|
|
|
|
|
if (pr < 0) {
|
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (pr == 0) {
|
|
|
|
|
timed_out = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
while (1) {
|
|
|
|
|
ssize_t n = read(pfd[0], tmp, sizeof(tmp));
|
|
|
|
|
if (n > 0) {
|
|
|
|
|
if (out && off + 1 < out_sz) {
|
|
|
|
|
size_t cp = (size_t)n;
|
|
|
|
|
if (cp > out_sz - 1 - off) cp = out_sz - 1 - off;
|
|
|
|
|
memcpy(out + off, tmp, cp);
|
|
|
|
|
off += cp;
|
|
|
|
|
}
|
|
|
|
|
} else if (n == 0) {
|
|
|
|
|
eof = true;
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) break;
|
|
|
|
|
eof = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (out && out_sz > 0) out[off] = '\0';
|
|
|
|
|
close(pfd[0]);
|
2026-11-22 22:31:41 +02:00
|
|
|
if (timed_out) {
|
|
|
|
|
kill(-pid, SIGKILL);
|
|
|
|
|
kill(pid, SIGKILL);
|
|
|
|
|
}
|
2026-11-22 10:49:59 +02:00
|
|
|
int status = 0;
|
2026-11-22 22:31:41 +02:00
|
|
|
while (waitpid(pid, &status, 0) < 0) {
|
|
|
|
|
if (errno != EINTR) return timed_out ? 124 : -1;
|
|
|
|
|
}
|
|
|
|
|
if (timed_out) return 124;
|
2026-11-22 10:49:59 +02:00
|
|
|
return WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 22:31:41 +02:00
|
|
|
int gemui_run_cmd_capture(const char *const argv[], char *out, size_t out_sz) {
|
|
|
|
|
return gemui_run_cmd_timeout(argv, out, out_sz, 2500);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-22 10:49:59 +02:00
|
|
|
int gemui_spawn_detached(const char *const argv[]) {
|
|
|
|
|
if (!argv || !argv[0]) return -1;
|
|
|
|
|
pid_t pid = fork();
|
|
|
|
|
if (pid < 0) return -1;
|
|
|
|
|
if (pid == 0) {
|
|
|
|
|
setsid();
|
|
|
|
|
pid_t pid2 = fork();
|
|
|
|
|
if (pid2 == 0) {
|
|
|
|
|
int devnull = open("/dev/null", O_RDWR);
|
|
|
|
|
if (devnull >= 0) {
|
|
|
|
|
dup2(devnull, STDIN_FILENO);
|
|
|
|
|
dup2(devnull, STDOUT_FILENO);
|
|
|
|
|
dup2(devnull, STDERR_FILENO);
|
|
|
|
|
if (devnull > 2) close(devnull);
|
|
|
|
|
}
|
|
|
|
|
execvp(argv[0], (char *const *)argv);
|
|
|
|
|
_exit(127);
|
|
|
|
|
}
|
|
|
|
|
_exit(0);
|
|
|
|
|
}
|
|
|
|
|
int status = 0;
|
|
|
|
|
waitpid(pid, &status, 0);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void gemui_utf8_pop_char(char *buf) {
|
|
|
|
|
if (!buf) return;
|
|
|
|
|
size_t len = strlen(buf);
|
|
|
|
|
while (len > 0) {
|
|
|
|
|
len--;
|
|
|
|
|
unsigned char ch = (unsigned char)buf[len];
|
|
|
|
|
buf[len] = '\0';
|
|
|
|
|
if ((ch & 0xc0) != 0x80) break;
|
|
|
|
|
}
|
|
|
|
|
}
|