Initial standalone libgemui repository
This commit is contained in:
commit
fab6a60459
9 files changed
+3889
No files matched your search
@@ -0,0 +1,4 @@
|
||||
build/
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
@@ -0,0 +1,110 @@
|
||||
# GemUI UI Toolkit
|
||||
# Strict POSIX-compatible Makefile.
|
||||
|
||||
.POSIX:
|
||||
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
CC = cc
|
||||
AR = ar
|
||||
PKG_CONFIG = pkg-config
|
||||
CFLAGS = -O2
|
||||
LDFLAGS =
|
||||
VERSION = 1.0.0
|
||||
ANODE_PREFIX = $(PREFIX)
|
||||
|
||||
PKG_DEPS = x11 xext xft xinerama xrandr cairo pangocairo pango harfbuzz fontconfig freetype2
|
||||
|
||||
all: shared static build/gemui.pc
|
||||
|
||||
shared: build/libgemui.so
|
||||
|
||||
static: build/libgemui.a
|
||||
|
||||
help:
|
||||
@printf 'libgemui build & install targets:\n'
|
||||
@printf ' make Build build/libgemui.so, build/libgemui.a, and build/gemui.pc\n'
|
||||
@printf ' make shared Build shared library (build/libgemui.so)\n'
|
||||
@printf ' make static Build static archive (build/libgemui.a)\n'
|
||||
@printf ' make rebuild Clean and rebuild all targets\n'
|
||||
@printf ' make clean Remove build/ directory\n'
|
||||
@printf ' make install Install headers, shared/static libraries, and gemui.pc\n'
|
||||
@printf ' make uninstall Remove installed libgemui files\n'
|
||||
@printf '\nOptions:\n'
|
||||
@printf ' PREFIX=%-18s Install prefix\n' "$(PREFIX)"
|
||||
@printf ' ANODE_PREFIX=%-12s Fallback ANODE theme prefix\n' "$(ANODE_PREFIX)"
|
||||
@printf ' DESTDIR=%-17s Staging directory\n' "$(DESTDIR)"
|
||||
@printf ' CC=%-22s C compiler\n' "$(CC)"
|
||||
@printf ' AR=%-22s Archiver\n' "$(AR)"
|
||||
@printf ' PKG_CONFIG=%-14s pkg-config command\n' "$(PKG_CONFIG)"
|
||||
@printf ' CFLAGS=%-18s Compiler flags\n' "$(CFLAGS)"
|
||||
@printf ' LDFLAGS=%-17s Linker flags\n' "$(LDFLAGS)"
|
||||
|
||||
rebuild:
|
||||
$(MAKE) clean
|
||||
$(MAKE) PREFIX="$(PREFIX)" ANODE_PREFIX="$(ANODE_PREFIX)" CC="$(CC)" AR="$(AR)" PKG_CONFIG="$(PKG_CONFIG)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" VERSION="$(VERSION)" all
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
|
||||
build/flags.sh: Makefile
|
||||
@mkdir -p build
|
||||
@set -e; \
|
||||
pc_path="$(PREFIX)/lib/pkgconfig"; \
|
||||
if [ -n "$${PKG_CONFIG_PATH:-}" ]; then pc_path="$$pc_path:$$PKG_CONFIG_PATH"; fi; \
|
||||
for dir in /usr/local/lib/pkgconfig /usr/local/libdata/pkgconfig /usr/pkg/lib/pkgconfig /usr/lib/pkgconfig /usr/share/pkgconfig; do \
|
||||
if [ -d "$$dir" ]; then pc_path="$$pc_path:$$dir"; fi; \
|
||||
done; \
|
||||
for mod in $(PKG_DEPS); do \
|
||||
if ! PKG_CONFIG_PATH="$$pc_path" $(PKG_CONFIG) --exists "$$mod" 2>/dev/null; then \
|
||||
printf 'libgemui: error: required pkg-config module "%s" not found\n' "$$mod" >&2; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
done; \
|
||||
gemui_cflags=$$(PKG_CONFIG_PATH="$$pc_path" $(PKG_CONFIG) --cflags $(PKG_DEPS)); \
|
||||
gemui_libs=$$(PKG_CONFIG_PATH="$$pc_path" $(PKG_CONFIG) --libs $(PKG_DEPS)); \
|
||||
case " $$gemui_libs " in \
|
||||
*" -lm "*) ;; \
|
||||
*) gemui_libs="$$gemui_libs -lm" ;; \
|
||||
esac; \
|
||||
printf "GEMUI_CFLAGS='%s'\nGEMUI_LIBS='%s'\n" "$$gemui_cflags" "$$gemui_libs" > build/flags.sh.tmp; \
|
||||
mv -f build/flags.sh.tmp build/flags.sh
|
||||
|
||||
build/gemui.o: gemui.c gemui.h gemui_internal.h gemui_scale.h build/flags.sh
|
||||
@mkdir -p build
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -fPIC -I. -DANODE_PREFIX="\"$(ANODE_PREFIX)\"" $$GEMUI_CFLAGS -c gemui.c -o build/gemui.o
|
||||
|
||||
build/gemui_filedialog.o: gemui_filedialog.c gemui.h gemui_internal.h build/flags.sh
|
||||
@mkdir -p build
|
||||
. ./build/flags.sh && $(CC) $(CFLAGS) -std=c11 -Wall -Wextra -fPIC -I. $$GEMUI_CFLAGS -c gemui_filedialog.c -o build/gemui_filedialog.o
|
||||
|
||||
build/libgemui.so: build/gemui.o build/gemui_filedialog.o build/flags.sh
|
||||
. ./build/flags.sh && $(CC) -shared -Wl,-soname,libgemui.so -o build/libgemui.so build/gemui.o build/gemui_filedialog.o $(LDFLAGS) $$GEMUI_LIBS
|
||||
|
||||
build/libgemui.a: build/gemui.o build/gemui_filedialog.o
|
||||
rm -f build/libgemui.a
|
||||
$(AR) rcs build/libgemui.a build/gemui.o build/gemui_filedialog.o
|
||||
|
||||
build/gemui.pc: gemui.pc.in Makefile
|
||||
@mkdir -p build
|
||||
sed "s|@PREFIX@|$(PREFIX)|g; s|@VERSION@|$(VERSION)|g" gemui.pc.in > build/gemui.pc
|
||||
|
||||
install: all
|
||||
mkdir -p "$(DESTDIR)$(PREFIX)/lib/pkgconfig" "$(DESTDIR)$(PREFIX)/include"
|
||||
cp -f build/libgemui.so "$(DESTDIR)$(PREFIX)/lib/libgemui.so"
|
||||
chmod 755 "$(DESTDIR)$(PREFIX)/lib/libgemui.so"
|
||||
cp -f build/libgemui.a "$(DESTDIR)$(PREFIX)/lib/libgemui.a"
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/lib/libgemui.a"
|
||||
cp -f gemui.h "$(DESTDIR)$(PREFIX)/include/gemui.h"
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/include/gemui.h"
|
||||
cp -f build/gemui.pc "$(DESTDIR)$(PREFIX)/lib/pkgconfig/gemui.pc"
|
||||
chmod 644 "$(DESTDIR)$(PREFIX)/lib/pkgconfig/gemui.pc"
|
||||
|
||||
uninstall:
|
||||
rm -f \
|
||||
"$(DESTDIR)$(PREFIX)/lib/libgemui.so" \
|
||||
"$(DESTDIR)$(PREFIX)/lib/libgemui.a" \
|
||||
"$(DESTDIR)$(PREFIX)/include/gemui.h" \
|
||||
"$(DESTDIR)$(PREFIX)/lib/pkgconfig/gemui.pc"
|
||||
|
||||
.PHONY: all shared static help rebuild clean install uninstall
|
||||
@@ -0,0 +1,49 @@
|
||||
# libgemui
|
||||
|
||||
`libgemui` is a lightweight C11 X11, Cairo, and Pango/HarfBuzz UI toolkit designed for the ANODE desktop environment and standalone X11 utilities. It can be built as either a shared library (`libgemui.so`) or a static archive (`libgemui.a`) with live `.Xresources` / `.xth` theming and fractional DPI scaling.
|
||||
|
||||
## Features
|
||||
|
||||
- **Double-buffered X11 + Cairo + Pango rendering**: Smooth redraws with XRandR/Xinerama monitor awareness, Pango/HarfBuzz font fallback (`theme.fontFace` + `theme.iconFontFace`), and automatic luminance-aware dark/light control contrast.
|
||||
- **Fractional DPI scaling & touch sizing**: Reads `Xft.dpi`, `theme.scale` / `anode.scale`, `theme.touchMode` / `anode.touchMode`, `~/.Xresources`, root `XA_RESOURCE_MANAGER`, `GEMUI_SCALE` / `ANODE_SCALE`, and primary monitor EDID DPI (`0.50x` to `4.00x`), with live theme reload via `SIGUSR1` or property updates.
|
||||
- **Standalone theming fallback**: Ships built-in `Anodized` theme defaults so applications work cleanly on any X11 desktop even when no ANODE theme files or `.Xresources` entries are present.
|
||||
- **Immediate-mode helpers & hit tracking**: Rect/rounded primitives, text/icon drawing, headers, buttons, toggles, sliders, text inputs, toasts, clipboard retrieval (`gemui_clipboard_get`), non-blocking `poll()` loop for X11 + custom fds + timers, and optional `WM_DELETE_WINDOW` interception (`gemui_set_close_handler`).
|
||||
- **Standardized File Open / Save dialog**: Built-in modal directory browser (`gemui_open_file_dialog`, `gemui_save_file_dialog`, `gemui_file_dialog_run`) with extension filters, dotfile toggle, UTF-8 filename input, overwrite confirmation, and automatic compact scaling down to tiny screens (`<= 320x360`).
|
||||
|
||||
## Dependencies
|
||||
|
||||
- POSIX `make`, C11 compiler (`cc`), `ar`, and `pkg-config`
|
||||
- X11, Cairo, Pango, HarfBuzz, Fontconfig, and FreeType development libraries:
|
||||
`x11`, `xext`, `xft`, `xinerama`, `xrandr`, `cairo`, `pangocairo`, `pango`, `harfbuzz`, `fontconfig`, `freetype2`
|
||||
|
||||
## Build & Install
|
||||
|
||||
```sh
|
||||
make # Build build/libgemui.so, build/libgemui.a, and build/gemui.pc
|
||||
sudo make install # Install libraries, gemui.h, and gemui.pc (default PREFIX=/usr/local)
|
||||
```
|
||||
|
||||
Targets and options:
|
||||
|
||||
- `make shared` / `make static`: Build only `build/libgemui.so` or `build/libgemui.a`.
|
||||
- `make rebuild` / `make clean` / `make help`: Clean rebuild or inspect build variables (`PREFIX`, `ANODE_PREFIX`, `DESTDIR`, `CC`, `AR`, `CFLAGS`, `LDFLAGS`).
|
||||
|
||||
### Using as a Git Submodule / Static Library
|
||||
|
||||
When embedding `libgemui` in another repository:
|
||||
|
||||
```sh
|
||||
make static
|
||||
```
|
||||
|
||||
Compile with `-I<path-to-libgemui>` (`#include <gemui.h>`) and link `<path-to-libgemui>/build/libgemui.a` followed by:
|
||||
|
||||
```sh
|
||||
pkg-config --libs x11 xext xft xinerama xrandr cairo pangocairo pango harfbuzz fontconfig freetype2
|
||||
```
|
||||
|
||||
and `-lm`.
|
||||
|
||||
## Credits
|
||||
|
||||
Created by Luxferre in 2026, released into the public domain with no warranties.
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* GemUI Toolkit (libgemui)
|
||||
* Pure C11 X11 + Cairo + Pango/HarfBuzz UI library with live .Xresources theming and fractional DPI scaling.
|
||||
*/
|
||||
#ifndef GEMUI_H
|
||||
#define GEMUI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GEMUI_ALIGN_LEFT 0
|
||||
#define GEMUI_ALIGN_CENTER 1
|
||||
#define GEMUI_ALIGN_RIGHT 2
|
||||
|
||||
#define GEMUI_PTR_DOWN 0
|
||||
#define GEMUI_PTR_MOVE 1
|
||||
#define GEMUI_PTR_UP 2
|
||||
#define GEMUI_PTR_SCROLL_UP 3
|
||||
#define GEMUI_PTR_SCROLL_DOWN 4
|
||||
|
||||
#define GEMUI_MAX_HITS 256
|
||||
#define GEMUI_MAX_FDS 16
|
||||
|
||||
typedef struct {
|
||||
double r;
|
||||
double g;
|
||||
double b;
|
||||
double a;
|
||||
uint32_t argb;
|
||||
} gemui_color_t;
|
||||
|
||||
typedef struct {
|
||||
int x;
|
||||
int y;
|
||||
int w;
|
||||
int h;
|
||||
} gemui_rect_t;
|
||||
|
||||
typedef struct {
|
||||
gemui_rect_t r;
|
||||
int id;
|
||||
int val;
|
||||
} gemui_hit_t;
|
||||
|
||||
typedef struct {
|
||||
char name[64];
|
||||
char font_face[96];
|
||||
char icon_font_face[96];
|
||||
int base_font_size;
|
||||
int dpi;
|
||||
double scale;
|
||||
bool touch_mode;
|
||||
gemui_color_t bg_main;
|
||||
gemui_color_t bg_bar;
|
||||
gemui_color_t bg_header;
|
||||
gemui_color_t bg_footer;
|
||||
gemui_color_t bg_overlay;
|
||||
gemui_color_t bg_alt_even;
|
||||
gemui_color_t bg_alt_odd;
|
||||
gemui_color_t bg_input;
|
||||
gemui_color_t bg_input_focus;
|
||||
gemui_color_t bg_button;
|
||||
gemui_color_t bg_search;
|
||||
gemui_color_t bg_bubble_in;
|
||||
gemui_color_t bg_bubble_out;
|
||||
gemui_color_t bg_toast;
|
||||
gemui_color_t fg_main;
|
||||
gemui_color_t fg_bright;
|
||||
gemui_color_t fg_muted;
|
||||
gemui_color_t sel_bg;
|
||||
gemui_color_t sel_fg;
|
||||
gemui_color_t accent;
|
||||
gemui_color_t accent_alt;
|
||||
gemui_color_t highlight;
|
||||
gemui_color_t border;
|
||||
gemui_color_t divider;
|
||||
gemui_color_t success;
|
||||
gemui_color_t info;
|
||||
gemui_color_t warning;
|
||||
gemui_color_t danger;
|
||||
gemui_color_t danger_bg;
|
||||
} gemui_theme_t;
|
||||
|
||||
typedef struct gemui_app gemui_app_t;
|
||||
|
||||
typedef void (*gemui_fd_cb)(gemui_app_t *app, int fd, void *ud);
|
||||
typedef void (*gemui_timer_cb)(gemui_app_t *app, void *ud);
|
||||
typedef bool (*gemui_close_cb)(gemui_app_t *app, void *ud);
|
||||
|
||||
typedef struct {
|
||||
void (*on_draw)(gemui_app_t *app, cairo_t *cr, int w, int h, void *ud);
|
||||
void (*on_key)(gemui_app_t *app, KeySym ks, unsigned int state, const char *utf8, void *ud);
|
||||
void (*on_ptr)(gemui_app_t *app, int type, int x, int y, unsigned int btn, void *ud);
|
||||
void (*on_theme)(gemui_app_t *app, void *ud);
|
||||
void (*on_resize)(gemui_app_t *app, int w, int h, void *ud);
|
||||
} gemui_handlers_t;
|
||||
|
||||
bool gemui_color_parse(const char *hex, gemui_color_t *out);
|
||||
void gemui_theme_defaults(gemui_theme_t *t);
|
||||
bool gemui_theme_load_file(const char *path, gemui_theme_t *out);
|
||||
void gemui_theme_reload(gemui_app_t *app);
|
||||
|
||||
gemui_app_t *gemui_create(const char *res_name, const char *title,
|
||||
int w, int h, bool fullscreen_override);
|
||||
void gemui_destroy(gemui_app_t *app);
|
||||
void gemui_set_handlers(gemui_app_t *app, const gemui_handlers_t *h, void *userdata);
|
||||
void gemui_set_title(gemui_app_t *app, const char *title);
|
||||
Display *gemui_display(const gemui_app_t *app);
|
||||
Window gemui_window(const gemui_app_t *app);
|
||||
const gemui_theme_t *gemui_theme(const gemui_app_t *app);
|
||||
int gemui_width(const gemui_app_t *app);
|
||||
int gemui_height(const gemui_app_t *app);
|
||||
gemui_rect_t gemui_primary_monitor_rect(const gemui_app_t *app);
|
||||
bool gemui_clipboard_get(gemui_app_t *app, char *out, size_t out_sz);
|
||||
double gemui_scale(const gemui_app_t *app);
|
||||
bool gemui_touch_mode(const gemui_app_t *app);
|
||||
int gemui_scale_px(const gemui_app_t *app, int logical_px);
|
||||
int gemui_touch_row_px(const gemui_app_t *app, int logical_px);
|
||||
|
||||
int gemui_add_fd(gemui_app_t *app, int fd, gemui_fd_cb cb, void *userdata);
|
||||
void gemui_del_fd(gemui_app_t *app, int fd);
|
||||
void gemui_set_timer_ms(gemui_app_t *app, int interval_ms, gemui_timer_cb cb, void *userdata);
|
||||
void gemui_set_close_handler(gemui_app_t *app, gemui_close_cb cb, void *userdata);
|
||||
void gemui_request_redraw(gemui_app_t *app);
|
||||
void gemui_flush_draw(gemui_app_t *app);
|
||||
void gemui_show_toast(gemui_app_t *app, const char *msg, int duration_ms);
|
||||
int gemui_run(gemui_app_t *app);
|
||||
void gemui_quit(gemui_app_t *app, int code);
|
||||
bool gemui_grab_input(gemui_app_t *app);
|
||||
void gemui_ungrab_input(gemui_app_t *app);
|
||||
|
||||
void gemui_hits_clear(gemui_app_t *app);
|
||||
void gemui_hit_add(gemui_app_t *app, gemui_rect_t r, int id, int val);
|
||||
const gemui_hit_t *gemui_hit_test(const gemui_app_t *app, int x, int y);
|
||||
|
||||
void gemui_set_source(cairo_t *cr, gemui_color_t c);
|
||||
void gemui_rounded_rect(cairo_t *cr, gemui_rect_t r, double radius);
|
||||
void gemui_fill_rect(cairo_t *cr, gemui_rect_t r, gemui_color_t c);
|
||||
void gemui_fill_round(cairo_t *cr, gemui_rect_t r, double radius, gemui_color_t c);
|
||||
void gemui_stroke_round(cairo_t *cr, gemui_rect_t r, double radius, double lw, gemui_color_t c);
|
||||
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);
|
||||
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);
|
||||
void gemui_draw_header(gemui_app_t *app, cairo_t *cr, const char *icon,
|
||||
const char *title, const char *right_badge);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
void gemui_draw_toast(gemui_app_t *app, cairo_t *cr);
|
||||
|
||||
int gemui_unix_cmd(const char *sock_path, const char *cmd, char *resp, size_t resp_sz);
|
||||
int gemui_read_file_line(const char *path, char *buf, size_t sz);
|
||||
int gemui_run_cmd_timeout(const char *const argv[], char *out, size_t out_sz, int timeout_ms);
|
||||
int gemui_run_cmd_capture(const char *const argv[], char *out, size_t out_sz);
|
||||
int gemui_spawn_detached(const char *const argv[]);
|
||||
void gemui_utf8_pop_char(char *buf);
|
||||
|
||||
/* Standardized modal file Open / Save dialog */
|
||||
typedef enum {
|
||||
GEMUI_FILE_OPEN = 0,
|
||||
GEMUI_FILE_SAVE = 1
|
||||
} gemui_file_dialog_mode_t;
|
||||
|
||||
typedef void (*gemui_file_dialog_cb)(gemui_app_t *app, bool accepted,
|
||||
const char *path, void *userdata);
|
||||
|
||||
typedef struct {
|
||||
gemui_file_dialog_mode_t mode;
|
||||
const char *title; /* optional title ("Open File" / "Save File") */
|
||||
const char *initial_dir; /* optional starting dir (supports ~, else cwd) */
|
||||
const char *initial_name; /* optional initial filename for Save mode */
|
||||
const char *filter_exts; /* optional comma/semicolon list, e.g. ".htab,.csv" */
|
||||
const char *default_ext; /* optional extension appended on Save if missing */
|
||||
const char *ok_label; /* optional confirm button label ("Open" / "Save") */
|
||||
bool show_hidden; /* initial dotfiles visibility (default false) */
|
||||
bool no_confirm_overwrite; /* false (default) prompts before Save overwrite */
|
||||
} gemui_file_dialog_opts_t;
|
||||
|
||||
bool gemui_file_dialog_open(gemui_app_t *app, const gemui_file_dialog_opts_t *opts,
|
||||
gemui_file_dialog_cb cb, void *userdata);
|
||||
bool gemui_open_file_dialog(gemui_app_t *app, const char *title,
|
||||
const char *initial_dir, const char *filter_exts,
|
||||
gemui_file_dialog_cb cb, void *userdata);
|
||||
bool gemui_save_file_dialog(gemui_app_t *app, const char *title,
|
||||
const char *initial_dir, const char *initial_name,
|
||||
const char *filter_exts, const char *default_ext,
|
||||
gemui_file_dialog_cb cb, void *userdata);
|
||||
bool gemui_file_dialog_active(const gemui_app_t *app);
|
||||
void gemui_file_dialog_close(gemui_app_t *app);
|
||||
|
||||
/* Standalone modal convenience runner: opens a temporary GemUI window for the
|
||||
* file dialog, runs until the user confirms or cancels, writes chosen path into
|
||||
* out_path (NUL-terminated), and returns true if accepted. */
|
||||
bool gemui_file_dialog_run(const char *app_id, const gemui_file_dialog_opts_t *opts,
|
||||
char *out_path, size_t out_path_sz);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GEMUI_H */
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
prefix=@PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/lib
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: gemui
|
||||
Description: GemUI lightweight X11 + Cairo + Pango/HarfBuzz UI toolkit
|
||||
Version: @VERSION@
|
||||
Requires.private: x11 xext xft xinerama xrandr cairo pangocairo pango harfbuzz fontconfig freetype2
|
||||
Libs: -L${libdir} -Wl,-rpath,${libdir} -lgemui -lm
|
||||
Cflags: -I${includedir}
|
||||
+1515
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,25 @@
|
||||
#ifndef GEMUI_INTERNAL_H
|
||||
#define GEMUI_INTERNAL_H
|
||||
|
||||
#include <cairo.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "gemui.h"
|
||||
|
||||
struct gemui_file_dialog;
|
||||
|
||||
/* Internal bridges implemented in gemui.c for modular widgets */
|
||||
struct gemui_file_dialog **gemui_internal_fdlg_ptr(gemui_app_t *app);
|
||||
const struct gemui_file_dialog *gemui_internal_fdlg_cptr(const gemui_app_t *app);
|
||||
int gemui_internal_draw_pango_px(gemui_app_t *app, cairo_t *cr, int px_size,
|
||||
gemui_rect_t r, const char *text, bool bold,
|
||||
int align, gemui_color_t c);
|
||||
|
||||
/* Modal file dialog hooks implemented in gemui_filedialog.c */
|
||||
void gemui_fdlg_destroy(gemui_app_t *app);
|
||||
void gemui_fdlg_draw(gemui_app_t *app, cairo_t *cr, int w, int h);
|
||||
void gemui_fdlg_handle_key(gemui_app_t *app, KeySym ks, unsigned int state,
|
||||
const char *utf8);
|
||||
void gemui_fdlg_handle_ptr(gemui_app_t *app, int ev, int x, int y,
|
||||
unsigned int button);
|
||||
|
||||
#endif /* GEMUI_INTERNAL_H */
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* GemUI Fractional DPI Scaling & Xresources Helpers
|
||||
*/
|
||||
#ifndef GEMUI_SCALE_H
|
||||
#define GEMUI_SCALE_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xresource.h>
|
||||
|
||||
static inline double gemui_clamp_scale(double s) {
|
||||
if (s < 0.5) return 0.5;
|
||||
if (s > 4.0) return 4.0;
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline double gemui_clamp_dpi(double d) {
|
||||
if (d < 48.0) return 48.0;
|
||||
if (d > 384.0) return 384.0;
|
||||
return d;
|
||||
}
|
||||
|
||||
static inline double gemui_scale_from_dpi(double dpi) {
|
||||
if (dpi <= 1.0) return 1.0;
|
||||
return gemui_clamp_scale(dpi / 96.0);
|
||||
}
|
||||
|
||||
static inline int gemui_scale_px_val(int logical_px, double scale) {
|
||||
if (logical_px <= 0) return 0;
|
||||
double s = gemui_clamp_scale(scale);
|
||||
int v = (int)floor((double)logical_px * s + 0.5);
|
||||
return v < 1 ? 1 : v;
|
||||
}
|
||||
|
||||
static inline int gemui_parse_positive_double(const char *s, double *out) {
|
||||
if (!s || !s[0] || !out) return 0;
|
||||
char *end = NULL;
|
||||
double v = strtod(s, &end);
|
||||
if (end == s || v <= 0.0) return 0;
|
||||
*out = v;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int gemui_parse_bool_str(const char *s, int defval) {
|
||||
if (!s || !s[0]) return defval;
|
||||
if (s[0] == '1' || s[0] == 'y' || s[0] == 'Y' || s[0] == 't' || s[0] == 'T') return 1;
|
||||
if (s[0] == '0' || s[0] == 'n' || s[0] == 'N' || s[0] == 'f' || s[0] == 'F') return 0;
|
||||
return defval;
|
||||
}
|
||||
|
||||
static inline double gemui_detect_edid_dpi(Display *dpy) {
|
||||
if (!dpy) return 96.0;
|
||||
int scr = DefaultScreen(dpy);
|
||||
int pw = DisplayWidth(dpy, scr);
|
||||
int mm = DisplayWidthMM(dpy, scr);
|
||||
if (pw > 0 && mm > 20) {
|
||||
double dpi = (double)pw * 25.4 / (double)mm;
|
||||
if (dpi >= 72.0 && dpi <= 384.0) {
|
||||
return dpi;
|
||||
}
|
||||
}
|
||||
return 96.0;
|
||||
}
|
||||
|
||||
static inline XrmDatabase gemui_open_xres_db(Display *dpy) {
|
||||
XrmInitialize();
|
||||
XrmDatabase db = NULL;
|
||||
const char *override = getenv("GEMUI_XRESOURCES");
|
||||
if (!override || !override[0]) override = getenv("ANODE_XRESOURCES");
|
||||
if (override && override[0]) {
|
||||
db = XrmGetFileDatabase(override);
|
||||
if (db) return db;
|
||||
}
|
||||
|
||||
const char *home = getenv("HOME");
|
||||
if (home && home[0]) {
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/.Xresources", home);
|
||||
db = XrmGetFileDatabase(path);
|
||||
}
|
||||
|
||||
if (dpy) {
|
||||
Atom actual_type = None;
|
||||
int actual_format = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *prop = NULL;
|
||||
XrmDatabase mdb = NULL;
|
||||
/* Always query root XA_RESOURCE_MANAGER directly; XResourceManagerString(dpy)
|
||||
caches the startup string in Xlib and misses live xrdb updates. */
|
||||
if (XGetWindowProperty(dpy, DefaultRootWindow(dpy), XA_RESOURCE_MANAGER,
|
||||
0L, 262144L, False, XA_STRING, &actual_type,
|
||||
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
|
||||
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0) {
|
||||
char *buf = (char *)malloc(nitems + 1);
|
||||
if (buf) {
|
||||
memcpy(buf, prop, nitems);
|
||||
buf[nitems] = '\0';
|
||||
mdb = XrmGetStringDatabase(buf);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
XFree(prop);
|
||||
}
|
||||
if (mdb) {
|
||||
if (db) {
|
||||
XrmMergeDatabases(mdb, &db);
|
||||
} else {
|
||||
db = mdb;
|
||||
}
|
||||
}
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
static inline void gemui_read_xres_scale_from_db(XrmDatabase db, Display *dpy,
|
||||
double *dpi_out, double *scale_out,
|
||||
int *touch_out) {
|
||||
double dpi = 0.0;
|
||||
double scale = 0.0;
|
||||
int touch = 0;
|
||||
int have_dpi = 0;
|
||||
int have_scale = 0;
|
||||
|
||||
if (db) {
|
||||
char *type = NULL;
|
||||
XrmValue val;
|
||||
double v = 0.0;
|
||||
if (XrmGetResource(db, "Xft.dpi", "Xft.Dpi", &type, &val) && val.addr &&
|
||||
gemui_parse_positive_double(val.addr, &v)) {
|
||||
dpi = gemui_clamp_dpi(v);
|
||||
have_dpi = 1;
|
||||
}
|
||||
if ((XrmGetResource(db, "anode.scale", "Anode.Scale", &type, &val) && val.addr &&
|
||||
gemui_parse_positive_double(val.addr, &v)) ||
|
||||
(XrmGetResource(db, "theme.scale", "Theme.Scale", &type, &val) && val.addr &&
|
||||
gemui_parse_positive_double(val.addr, &v))) {
|
||||
scale = gemui_clamp_scale(v);
|
||||
have_scale = 1;
|
||||
}
|
||||
if ((XrmGetResource(db, "anode.touchMode", "Anode.TouchMode", &type, &val) && val.addr) ||
|
||||
(XrmGetResource(db, "theme.touchMode", "Theme.TouchMode", &type, &val) && val.addr)) {
|
||||
touch = gemui_parse_bool_str(val.addr, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (!have_scale && !have_dpi) {
|
||||
double env_s = 0.0;
|
||||
const char *env_str = getenv("GEMUI_SCALE");
|
||||
if (!env_str || !env_str[0]) env_str = getenv("ANODE_SCALE");
|
||||
if (gemui_parse_positive_double(env_str, &env_s)) {
|
||||
scale = gemui_clamp_scale(env_s);
|
||||
dpi = 96.0 * scale;
|
||||
} else {
|
||||
dpi = gemui_detect_edid_dpi(dpy);
|
||||
if (dpi >= 84.0 && dpi <= 108.0) dpi = 96.0;
|
||||
scale = gemui_scale_from_dpi(dpi);
|
||||
}
|
||||
} else if (have_scale && !have_dpi) {
|
||||
dpi = gemui_clamp_dpi(96.0 * scale);
|
||||
} else if (have_dpi && !have_scale) {
|
||||
scale = gemui_scale_from_dpi(dpi);
|
||||
}
|
||||
|
||||
if (dpi_out) *dpi_out = dpi;
|
||||
if (scale_out) *scale_out = scale;
|
||||
if (touch_out) *touch_out = touch;
|
||||
}
|
||||
|
||||
#endif /* GEMUI_SCALE_H */
|
||||
Reference in new issue
Block a user