Overhaul icons: bundled Lucide symbolics, soft tiles, mixer app icon, container host icons
This commit is contained in:
1 parent
b1f0965e02
commit
011dab35a2
47 files changed
+970
-158
No files matched your search
+36
-2
@@ -110,6 +110,9 @@ extern "C" fn ffi_image_new(icon : Bytes, size : Int32) -> Widget = "mm_gtk_imag
|
||||
#borrow(icon)
|
||||
extern "C" fn ffi_image_set_icon(img : Widget, icon : Bytes) = "mm_gtk_image_set_icon"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_image_set_pixel_size(img : Widget, size : Int32) = "mm_gtk_image_set_pixel_size"
|
||||
|
||||
///|
|
||||
#borrow(name)
|
||||
extern "C" fn ffi_has_icon(name : Bytes) -> Int32 = "mm_gtk_has_icon"
|
||||
@@ -169,6 +172,10 @@ extern "C" fn ffi_set_margins(w : Widget, m : Int32) = "mm_gtk_widget_set_margin
|
||||
#borrow(cls)
|
||||
extern "C" fn ffi_add_css_class(w : Widget, cls : Bytes) = "mm_gtk_widget_add_css_class"
|
||||
|
||||
///|
|
||||
#borrow(cls)
|
||||
extern "C" fn ffi_remove_css_class(w : Widget, cls : Bytes) = "mm_gtk_widget_remove_css_class"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_set_visible(w : Widget, v : Int32) = "mm_gtk_widget_set_visible"
|
||||
|
||||
@@ -178,6 +185,12 @@ extern "C" fn ffi_set_sensitive(w : Widget, v : Int32) = "mm_gtk_widget_set_sens
|
||||
///|
|
||||
extern "C" fn ffi_set_valign_center(w : Widget) = "mm_gtk_widget_set_valign_center"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_set_halign_center(w : Widget) = "mm_gtk_widget_set_halign_center"
|
||||
|
||||
///|
|
||||
extern "C" fn ffi_set_vexpand(w : Widget, v : Int32) = "mm_gtk_widget_set_vexpand"
|
||||
|
||||
///|
|
||||
#borrow(path)
|
||||
extern "C" fn ffi_save_png(w : Widget, path : Bytes) -> Int32 = "mm_gtk_save_png"
|
||||
@@ -460,6 +473,11 @@ pub fn Widget::set_icon(self : Widget, icon : String) -> Unit {
|
||||
ffi_image_set_icon(self, cstr(icon))
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_pixel_size(self : Widget, size : Int32) -> Unit {
|
||||
ffi_image_set_pixel_size(self, size)
|
||||
}
|
||||
|
||||
///|
|
||||
/// A slider from 0 to `max` with a mark at `norm`. Returns (widget, tag).
|
||||
pub fn scale(
|
||||
@@ -549,6 +567,11 @@ pub fn Widget::add_css_class(self : Widget, cls : String) -> Unit {
|
||||
ffi_add_css_class(self, cstr(cls))
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::remove_css_class(self : Widget, cls : String) -> Unit {
|
||||
ffi_remove_css_class(self, cstr(cls))
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_visible(self : Widget, v : Bool) -> Unit {
|
||||
ffi_set_visible(self, int(v))
|
||||
@@ -564,6 +587,16 @@ pub fn Widget::set_valign_center(self : Widget) -> Unit {
|
||||
ffi_set_valign_center(self)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_halign_center(self : Widget) -> Unit {
|
||||
ffi_set_halign_center(self)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Widget::set_vexpand(self : Widget, v : Bool) -> Unit {
|
||||
ffi_set_vexpand(self, int(v))
|
||||
}
|
||||
|
||||
///|
|
||||
/// Render the widget offscreen to a PNG file (for headless screenshots).
|
||||
pub fn Widget::save_png(self : Widget, path : String) -> Bool {
|
||||
@@ -585,8 +618,9 @@ pub fn app_icon(key : String) -> String {
|
||||
|
||||
///|
|
||||
/// First entry of an icon chain (see @model.device_icon_chain) that the theme
|
||||
/// has. "app:<key>" entries are looked up in the .desktop files. The last
|
||||
/// entry is returned if nothing matches, so the result is never empty.
|
||||
/// has or that resolves on disk. "app:<key>" entries are looked up in the
|
||||
/// .desktop files (and may resolve to a theme icon name or "file:<path>").
|
||||
/// The last entry is returned if nothing matches, so the result is never empty.
|
||||
pub fn resolve_icon(chain : Array[String]) -> String {
|
||||
for name in chain {
|
||||
if name.has_prefix("app:") {
|
||||
|
||||
+127
-17
@@ -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
|
||||
|
||||
@@ -71,22 +71,26 @@ pub fn Widget::append(Self, Self) -> Unit
|
||||
pub fn Widget::append_page(Self, Self, String, icon? : String) -> Unit
|
||||
pub fn Widget::present(Self) -> Unit
|
||||
pub fn Widget::remove(Self, Self) -> Unit
|
||||
pub fn Widget::remove_css_class(Self, String) -> Unit
|
||||
pub fn Widget::reorder_after(Self, Self, Self?) -> Unit
|
||||
pub fn Widget::save_png(Self, String) -> Bool
|
||||
pub fn Widget::set_active(Self, Bool) -> Unit
|
||||
pub fn Widget::set_button_icon(Self, String) -> Unit
|
||||
pub fn Widget::set_child(Self, Self) -> Unit
|
||||
pub fn Widget::set_halign_center(Self) -> Unit
|
||||
pub fn Widget::set_hexpand(Self, Bool) -> Unit
|
||||
pub fn Widget::set_icon(Self, String) -> Unit
|
||||
pub fn Widget::set_items(Self, Array[String], Int32) -> Unit
|
||||
pub fn Widget::set_level(Self, Double) -> Unit
|
||||
pub fn Widget::set_margins(Self, Int32) -> Unit
|
||||
pub fn Widget::set_page(Self, Int32) -> Unit
|
||||
pub fn Widget::set_pixel_size(Self, Int32) -> Unit
|
||||
pub fn Widget::set_sensitive(Self, Bool) -> Unit
|
||||
pub fn Widget::set_text(Self, String) -> Unit
|
||||
pub fn Widget::set_tooltip(Self, String) -> Unit
|
||||
pub fn Widget::set_valign_center(Self) -> Unit
|
||||
pub fn Widget::set_value(Self, Double) -> Unit
|
||||
pub fn Widget::set_vexpand(Self, Bool) -> Unit
|
||||
pub fn Widget::set_visible(Self, Bool) -> Unit
|
||||
pub fn Widget::set_width_chars(Self, Int32) -> Unit
|
||||
pub fn Widget::value(Self) -> Double
|
||||
|
||||
Reference in new issue
Block a user