Better icons: device/app icon chains, volume icons, app icon (#2)
CI / check (push) Successful in 10s
CI / native (push) Successful in 1m10s

This commit was merged in pull request #2.
This commit is contained in:
nandi committed 2026-11-23 01:07:41 +00:00
1 parent f08f241edb
commit 02b08cb471
21 files changed
+658 -70

No files matched your search

+51 -3
View File
@@ -77,8 +77,13 @@ extern "C" fn ffi_scrolled_new(child : Widget) -> Widget = "mm_gtk_scrolled_new"
extern "C" fn ffi_notebook_new(tag : Int32) -> Widget = "mm_gtk_notebook_new"
///|
#borrow(label)
extern "C" fn ffi_notebook_append(nb : Widget, child : Widget, label : Bytes) = "mm_gtk_notebook_append"
#borrow(label, icon)
extern "C" fn ffi_notebook_append(
nb : Widget,
child : Widget,
label : Bytes,
icon : Bytes,
) = "mm_gtk_notebook_append"
///|
extern "C" fn ffi_notebook_set_page(nb : Widget, i : Int32) = "mm_gtk_notebook_set_page"
@@ -105,6 +110,14 @@ 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"
///|
#borrow(name)
extern "C" fn ffi_has_icon(name : Bytes) -> Int32 = "mm_gtk_has_icon"
///|
#borrow(key)
extern "C" fn ffi_app_icon(key : Bytes) -> Bytes = "mm_gtk_app_icon"
///|
extern "C" fn ffi_scale_new(max : Double, norm : Double, tag : Int32) -> Widget = "mm_gtk_scale_new"
@@ -345,8 +358,9 @@ pub fn Widget::append_page(
self : Widget,
child : Widget,
label : String,
icon~ : String = "",
) -> Unit {
ffi_notebook_append(self, child, cstr(label))
ffi_notebook_append(self, child, cstr(label), cstr(icon))
}
///|
@@ -493,3 +507,37 @@ pub fn Widget::set_valign_center(self : Widget) -> Unit {
pub fn Widget::save_png(self : Widget, path : String) -> Bool {
ffi_save_png(self, cstr(path)) != 0
}
///|
/// Does the current icon theme have this icon?
pub fn has_icon(name : String) -> Bool {
ffi_has_icon(cstr(name)) != 0
}
///|
/// Icon of the installed application matching `key` (desktop id, binary or
/// name) per its .desktop file, "" if there is none or the theme lacks it.
pub fn app_icon(key : String) -> String {
@utf8.decode_lossy(ffi_app_icon(cstr(key)))
}
///|
/// 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.
pub fn resolve_icon(chain : Array[String]) -> String {
for name in chain {
if name.has_prefix("app:") {
let icon = app_icon(name[4:].to_owned())
if icon != "" {
return icon
}
} else if has_icon(name) {
return name
}
}
match chain.last() {
Some(n) => n
None => "image-missing"
}
}