Overhaul icons: bundled Lucide symbolics, soft tiles, mixer app icon, container host icons
CI / check (pull_request) Successful in 10s
CI / native (pull_request) Successful in 1m15s

This commit is contained in:
Sprite committed 2026-11-23 05:35:32 +00:00
1 parent b1f0965e02
commit 011dab35a2
47 files changed
+970 -158

No files matched your search

+127 -17
View File
@@ -43,6 +43,48 @@ MOONBIT_FFI_EXPORT void mm_gtk_set_handler(mm_gcall_t call, void *closure) {
g_closure = closure;
}
static void add_icon_search_path_if_new(GtkIconTheme *theme, const char *dir) {
if (!dir || !*dir)
return;
char **paths = gtk_icon_theme_get_search_path(theme);
int found = 0;
for (char **p = paths; p && *p; p++) {
if (strcmp(*p, dir) == 0) {
found = 1;
break;
}
}
g_strfreev(paths);
if (!found)
gtk_icon_theme_add_search_path(theme, dir);
}
static char *resolve_icon_file_path(const char *path) {
if (!path || !*path)
return NULL;
if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
return g_strdup(path);
static const struct {
const char *host_prefix;
const char *container_prefix;
} remaps[] = {
{"/usr/share/pixmaps/", "/run/moonmix/host/usr/pixmaps/"},
{"/usr/share/icons/", "/run/moonmix/host/usr/icons/"},
{"/var/lib/flatpak/exports/share/icons/",
"/run/moonmix/host/flatpak-sys/icons/"},
};
for (size_t i = 0; i < sizeof(remaps) / sizeof(remaps[0]); i++) {
if (g_str_has_prefix(path, remaps[i].host_prefix)) {
const char *rest = path + strlen(remaps[i].host_prefix);
char *mapped = g_strconcat(remaps[i].container_prefix, rest, NULL);
if (g_file_test(mapped, G_FILE_TEST_IS_REGULAR))
return mapped;
g_free(mapped);
}
}
return NULL;
}
MOONBIT_FFI_EXPORT int32_t mm_gtk_init(void) {
/* The Wayland app id comes from the program name; match the .desktop file
* so the compositor shows the app icon. */
@@ -54,41 +96,72 @@ MOONBIT_FFI_EXPORT int32_t mm_gtk_init(void) {
const char *icon_theme = g_getenv("MOONMIX_ICON_THEME");
if (icon_theme && *icon_theme)
g_object_set(gtk_settings_get_default(), "gtk-icon-theme-name", icon_theme, NULL);
/* Let an uninstalled checkout find data/icons/hicolor/... too:
* $MOONMIX_ICON_DIR, then ./data/icons. */
/* Let an uninstalled checkout and standard local/container prefixes find
* bundled moonmix-* icons and host pixmaps. */
GtkIconTheme *theme = gtk_icon_theme_get_for_display(gdk_display_get_default());
const char *dir = g_getenv("MOONMIX_ICON_DIR");
if (dir && *dir)
gtk_icon_theme_add_search_path(theme, dir);
gtk_icon_theme_add_search_path(theme, "data/icons");
add_icon_search_path_if_new(theme, g_getenv("MOONMIX_ICON_DIR"));
add_icon_search_path_if_new(theme, "data/icons");
char *user_icons = g_build_filename(g_get_user_data_dir(), "icons", NULL);
add_icon_search_path_if_new(theme, user_icons);
g_free(user_icons);
add_icon_search_path_if_new(theme, "/usr/local/share/icons");
if (g_file_test("/run/moonmix/host/usr/pixmaps", G_FILE_TEST_IS_DIR))
add_icon_search_path_if_new(theme, "/run/moonmix/host/usr/pixmaps");
gtk_window_set_default_icon_name("org.latha.moonmix");
return 1;
}
/* 1 if the icon theme has `name`. */
/* 1 if the icon theme has `name` or a "file:<path>" icon exists. */
MOONBIT_FFI_EXPORT int32_t mm_gtk_has_icon(moonbit_bytes_t name) {
const char *n = s(name);
if (!n || !*n)
return 0;
if (g_str_has_prefix(n, "file:")) {
char *resolved = resolve_icon_file_path(n + 5);
int ok = resolved != NULL;
g_free(resolved);
return ok;
}
GdkDisplay *d = gdk_display_get_default();
if (!d)
return 0;
return gtk_icon_theme_has_icon(gtk_icon_theme_get_for_display(d), s(name));
return gtk_icon_theme_has_icon(gtk_icon_theme_get_for_display(d), n);
}
static int theme_icon_of(GAppInfo *info, GtkIconTheme *theme, char **out) {
GIcon *icon = g_app_info_get_icon(info);
if (icon && G_IS_THEMED_ICON(icon)) {
if (!icon)
return 0;
if (G_IS_THEMED_ICON(icon)) {
const char *const *names = g_themed_icon_get_names(G_THEMED_ICON(icon));
for (int i = 0; names && names[i]; i++)
if (gtk_icon_theme_has_icon(theme, names[i])) {
*out = g_strdup(names[i]);
return 1;
/* Prefer full-colour non-symbolic icons before falling back to -symbolic. */
for (int pass = 0; pass < 2; pass++) {
for (int i = 0; names && names[i]; i++) {
int is_sym = g_str_has_suffix(names[i], "-symbolic");
if ((pass == 0) == !is_sym &&
gtk_icon_theme_has_icon(theme, names[i])) {
*out = g_strdup(names[i]);
return 1;
}
}
}
} else if (G_IS_FILE_ICON(icon)) {
GFile *f = g_file_icon_get_file(G_FILE_ICON(icon));
char *path = f ? g_file_get_path(f) : NULL;
char *resolved = resolve_icon_file_path(path);
g_free(path);
if (resolved) {
*out = g_strconcat("file:", resolved, NULL);
g_free(resolved);
return 1;
}
}
return 0;
}
/* Look an application up in the installed .desktop files by desktop id
* ("org.mozilla.firefox"), executable basename ("firefox") or display name
* ("Firefox"), and return its icon name if the theme has it. "" if none. */
* ("Firefox"), and return its icon name (or "file:<path>") if available. "" if none. */
MOONBIT_FFI_EXPORT moonbit_bytes_t mm_gtk_app_icon(moonbit_bytes_t key) {
const char *k = s(key);
char *found = NULL;
@@ -120,7 +193,7 @@ MOONBIT_FFI_EXPORT moonbit_bytes_t mm_gtk_app_icon(moonbit_bytes_t key) {
}
}
size_t n = found ? strlen(found) : 0;
moonbit_bytes_t out = moonbit_make_bytes(n + 1, 0);
moonbit_bytes_t out = moonbit_make_bytes((int32_t)n, 0);
if (found)
memcpy(out, found, n);
g_free(found);
@@ -481,16 +554,40 @@ MOONBIT_FFI_EXPORT void mm_gtk_label_set_width_chars(GtkWidget *l,
gtk_label_set_xalign(GTK_LABEL(l), 1.0f);
}
static void image_apply_icon(GtkImage *img, const char *icon) {
if (!icon || !*icon) {
gtk_image_clear(img);
return;
}
if (g_str_has_prefix(icon, "file:")) {
char *resolved = resolve_icon_file_path(icon + 5);
if (resolved) {
gtk_image_set_from_file(img, resolved);
g_free(resolved);
} else {
gtk_image_set_from_file(img, icon + 5);
}
} else {
gtk_image_set_from_icon_name(img, icon);
}
}
MOONBIT_FFI_EXPORT GtkWidget *mm_gtk_image_new(moonbit_bytes_t icon,
int32_t size) {
GtkWidget *img = gtk_image_new_from_icon_name(s(icon));
GtkWidget *img = gtk_image_new();
image_apply_icon(GTK_IMAGE(img), s(icon));
gtk_image_set_pixel_size(GTK_IMAGE(img), size);
return img;
}
MOONBIT_FFI_EXPORT void mm_gtk_image_set_icon(GtkWidget *img,
moonbit_bytes_t icon) {
gtk_image_set_from_icon_name(GTK_IMAGE(img), s(icon));
image_apply_icon(GTK_IMAGE(img), s(icon));
}
MOONBIT_FFI_EXPORT void mm_gtk_image_set_pixel_size(GtkWidget *img,
int32_t size) {
gtk_image_set_pixel_size(GTK_IMAGE(img), size);
}
static void on_value_changed(GtkRange *r, gpointer d) {
@@ -642,6 +739,11 @@ MOONBIT_FFI_EXPORT void mm_gtk_widget_add_css_class(GtkWidget *w,
gtk_widget_add_css_class(w, s(cls));
}
MOONBIT_FFI_EXPORT void mm_gtk_widget_remove_css_class(GtkWidget *w,
moonbit_bytes_t cls) {
gtk_widget_remove_css_class(w, s(cls));
}
MOONBIT_FFI_EXPORT void mm_gtk_widget_set_visible(GtkWidget *w, int32_t v) {
gtk_widget_set_visible(w, v != 0);
}
@@ -654,6 +756,14 @@ MOONBIT_FFI_EXPORT void mm_gtk_widget_set_valign_center(GtkWidget *w) {
gtk_widget_set_valign(w, GTK_ALIGN_CENTER);
}
MOONBIT_FFI_EXPORT void mm_gtk_widget_set_halign_center(GtkWidget *w) {
gtk_widget_set_halign(w, GTK_ALIGN_CENTER);
}
MOONBIT_FFI_EXPORT void mm_gtk_widget_set_vexpand(GtkWidget *w, int32_t v) {
gtk_widget_set_vexpand(w, v != 0);
}
/* ---- headless screenshots ------------------------------------------------ */
/* Render a realized widget (usually the window) to a PNG via GSK, without