Better icons: device/app icon chains, volume icons, app icon #2
No files matched your search
@@ -117,12 +117,41 @@ To install it for your user:
|
|||||||
```sh
|
```sh
|
||||||
install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe ~/.local/bin/moonmix
|
install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe ~/.local/bin/moonmix
|
||||||
install -Dm644 data/org.latha.moonmix.desktop ~/.local/share/applications/org.latha.moonmix.desktop
|
install -Dm644 data/org.latha.moonmix.desktop ~/.local/share/applications/org.latha.moonmix.desktop
|
||||||
|
install -Dm644 data/icons/hicolor/scalable/apps/org.latha.moonmix.svg ~/.local/share/icons/hicolor/scalable/apps/org.latha.moonmix.svg
|
||||||
|
install -Dm644 data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg ~/.local/share/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg
|
||||||
|
gtk-update-icon-cache -f -t ~/.local/share/icons/hicolor # optional
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The app icon is `org.latha.moonmix` (a speaker with a volume slider), shipped
|
||||||
|
as scalable and symbolic SVGs under `data/icons/hicolor/`. The window uses it
|
||||||
|
as its icon and the program name is `org.latha.moonmix`, which matches the
|
||||||
|
`.desktop` file so Wayland shells show it too. Run from a checkout, moonmix
|
||||||
|
also searches `./data/icons` and `$MOONMIX_ICON_DIR`.
|
||||||
|
|
||||||
|
### Icons
|
||||||
|
|
||||||
|
Everything else uses the desktop's icon theme (Adwaita, Breeze, Papirus...
|
||||||
|
any theme with the standard freedesktop names; install `adwaita-icon-theme`
|
||||||
|
if icons are missing). The names are chosen in `model/icons.mbt` and tested
|
||||||
|
with `moon test`; the GTK layer only asks the theme `has_icon`:
|
||||||
|
|
||||||
|
- **Devices**: the device's own `device.icon-name` / `node.icon-name`, then
|
||||||
|
`device.form-factor` (headphone, headset, speaker, microphone, webcam,
|
||||||
|
handset, tv, hdmi...), HDMI/webcam/Bluetooth/USB hints, then the direction
|
||||||
|
(speakers or microphone), then `audio-card-symbolic` and
|
||||||
|
`audio-x-generic-symbolic`. Symbolic variants are tried first so they follow
|
||||||
|
the theme's foreground colour. `image-missing` is the very last resort.
|
||||||
|
- **Streams**: `application.icon-name` / `media.icon-name`, then the app's
|
||||||
|
launcher icon found in the installed `.desktop` files (by
|
||||||
|
`pipewire.access.portal.app_id`, `application.process.binary` or
|
||||||
|
`application.name`), then `application-x-executable-symbolic`.
|
||||||
|
- **Mute button**: `audio-volume-high/medium/low/muted-symbolic` following the
|
||||||
|
volume and mute state. Row icons are 32 px, button and tab icons 16 px.
|
||||||
|
|
||||||
Pkg-config flags: moon does not expand `$(pkg-config ...)` in `moon.pkg`
|
Pkg-config flags: moon does not expand `$(pkg-config ...)` in `moon.pkg`
|
||||||
link options. Instead, the packages point `link.native.stub-cc` and `cc` at
|
link options. Instead, the packages point `link.native.stub-cc` and `cc` at
|
||||||
`tools/pkg-cc`, a wrapper that adds
|
`tools/pkg-cc`, a wrapper that adds
|
||||||
`pkg-config --cflags --libs libpipewire-0.3 wireplumber-0.5 gtk4`. moon
|
`pkg-config --cflags --libs libpipewire-0.3 wireplumber-0.5 gtk4 gio-unix-2.0`. moon
|
||||||
derives the archiver name from the compiler name, so `tools/pkg-ar` is a
|
derives the archiver name from the compiler name, so `tools/pkg-ar` is a
|
||||||
passthrough to `ar`. Set `MOONMIX_CC` or `MOONMIX_AR` to use another
|
passthrough to `ar`. Set `MOONMIX_CC` or `MOONMIX_AR` to use another
|
||||||
compiler or archiver.
|
compiler or archiver.
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ struct App {
|
|||||||
meters_paused : Ref[Bool]
|
meters_paused : Ref[Bool]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Device / application icon in each row; buttons use 16 px icons.
|
||||||
|
const ROW_ICON_SIZE : Int32 = 32
|
||||||
|
|
||||||
///|
|
///|
|
||||||
const METER_INTERVAL_MS : Int32 = 40
|
const METER_INTERVAL_MS : Int32 = 40
|
||||||
|
|
||||||
@@ -66,15 +70,6 @@ const CSS : String =
|
|||||||
#|levelbar.mm-meter trough, levelbar.mm-meter block { min-height: 4px; }
|
#|levelbar.mm-meter trough, levelbar.mm-meter block { min-height: 4px; }
|
||||||
#|levelbar.mm-meter { margin: 0 10px; }
|
#|levelbar.mm-meter { margin: 0 10px; }
|
||||||
|
|
||||||
///|
|
|
||||||
fn mute_icon(muted : Bool) -> String {
|
|
||||||
if muted {
|
|
||||||
"audio-volume-muted-symbolic"
|
|
||||||
} else {
|
|
||||||
"audio-volume-high-symbolic"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
||||||
let id = row.id
|
let id = row.id
|
||||||
@@ -82,7 +77,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
|||||||
let root = @gtk.vbox(4)
|
let root = @gtk.vbox(4)
|
||||||
root.add_css_class("mm-row")
|
root.add_css_class("mm-row")
|
||||||
let header = @gtk.hbox(8)
|
let header = @gtk.hbox(8)
|
||||||
let icon = @gtk.image(row.icon_name, 32)
|
let icon = @gtk.image(@gtk.resolve_icon(row.icons), ROW_ICON_SIZE)
|
||||||
let texts = @gtk.vbox(0)
|
let texts = @gtk.vbox(0)
|
||||||
texts.set_hexpand(true)
|
texts.set_hexpand(true)
|
||||||
texts.set_valign_center()
|
texts.set_valign_center()
|
||||||
@@ -122,17 +117,21 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
|||||||
}
|
}
|
||||||
let default_btn = match tab {
|
let default_btn = match tab {
|
||||||
OutputDevices | InputDevices => {
|
OutputDevices | InputDevices => {
|
||||||
let (b, tag) = @gtk.toggle("object-select-symbolic", "Default", fn(on) {
|
let (b, tag) = @gtk.toggle(
|
||||||
if on {
|
@gtk.resolve_icon(@model.default_button_icons()),
|
||||||
let _ = if tab is OutputDevices {
|
"Default",
|
||||||
@wp.set_default_sink(id)
|
fn(on) {
|
||||||
} else {
|
if on {
|
||||||
@wp.set_default_source(id)
|
let _ = if tab is OutputDevices {
|
||||||
|
@wp.set_default_sink(id)
|
||||||
|
} else {
|
||||||
|
@wp.set_default_source(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// The button reflects the actual default; re-sync it.
|
||||||
// The button reflects the actual default; re-sync it.
|
app.sync_default_button(tab, id)
|
||||||
app.sync_default_button(tab, id)
|
},
|
||||||
})
|
)
|
||||||
tags.push(tag)
|
tags.push(tag)
|
||||||
b.set_tooltip("Set as default (fallback) device")
|
b.set_tooltip("Set as default (fallback) device")
|
||||||
header.append(b)
|
header.append(b)
|
||||||
@@ -140,9 +139,11 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView {
|
|||||||
}
|
}
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
let (mute, mute_tag) = @gtk.toggle(mute_icon(row.mute), "", fn(on) {
|
let (mute, mute_tag) = @gtk.toggle(
|
||||||
let _ = @wp.set_mute(id, on)
|
@gtk.resolve_icon([row.volume_icon, "audio-volume-high"]),
|
||||||
})
|
"",
|
||||||
|
fn(on) { let _ = @wp.set_mute(id, on) },
|
||||||
|
)
|
||||||
tags.push(mute_tag)
|
tags.push(mute_tag)
|
||||||
mute.set_tooltip("Mute")
|
mute.set_tooltip("Mute")
|
||||||
header.append(mute)
|
header.append(mute)
|
||||||
@@ -208,8 +209,8 @@ fn apply_row(view : RowView, row : @model.Row, force~ : Bool = false) -> Unit {
|
|||||||
view.subtitle.set_text(row.subtitle)
|
view.subtitle.set_text(row.subtitle)
|
||||||
view.subtitle.set_visible(row.subtitle != "")
|
view.subtitle.set_visible(row.subtitle != "")
|
||||||
}
|
}
|
||||||
if force || old.icon_name != row.icon_name {
|
if force || old.icons != row.icons {
|
||||||
view.icon.set_icon(row.icon_name)
|
view.icon.set_icon(@gtk.resolve_icon(row.icons))
|
||||||
}
|
}
|
||||||
view.scale.set_sensitive(row.has_volume)
|
view.scale.set_sensitive(row.has_volume)
|
||||||
if force || @model.should_apply_remote(view.last_local_us, @gtk.now_us()) {
|
if force || @model.should_apply_remote(view.last_local_us, @gtk.now_us()) {
|
||||||
@@ -217,7 +218,9 @@ fn apply_row(view : RowView, row : @model.Row, force~ : Bool = false) -> Unit {
|
|||||||
view.volume_label.set_text(row.volume_text)
|
view.volume_label.set_text(row.volume_text)
|
||||||
}
|
}
|
||||||
view.mute.set_active(row.mute)
|
view.mute.set_active(row.mute)
|
||||||
view.mute.set_button_icon(mute_icon(row.mute))
|
view.mute.set_button_icon(
|
||||||
|
@gtk.resolve_icon([row.volume_icon, "audio-volume-high"]),
|
||||||
|
)
|
||||||
match view.default_btn {
|
match view.default_btn {
|
||||||
Some(b) => b.set_active(row.is_default)
|
Some(b) => b.set_active(row.is_default)
|
||||||
None => ()
|
None => ()
|
||||||
@@ -436,7 +439,15 @@ fn build_ui() -> App {
|
|||||||
empty.set_margins(24)
|
empty.set_margins(24)
|
||||||
empty.add_css_class("dim-label")
|
empty.add_css_class("dim-label")
|
||||||
list.append(empty)
|
list.append(empty)
|
||||||
nb.append_page(@gtk.scrolled(list), tab.label())
|
nb.append_page(
|
||||||
|
@gtk.scrolled(list),
|
||||||
|
tab.label(),
|
||||||
|
icon=@gtk.resolve_icon([
|
||||||
|
tab.icon(),
|
||||||
|
"audio-card-symbolic",
|
||||||
|
"audio-x-generic",
|
||||||
|
]),
|
||||||
|
)
|
||||||
tabs.push({ tab, list, empty, views: Map([]), rows: [], })
|
tabs.push({ tab, list, empty, views: Map([]), rows: [], })
|
||||||
}
|
}
|
||||||
outer.append(nb)
|
outer.append(nb)
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128" viewBox="0 0 128 128">
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
||||||
|
<stop offset="0" stop-color="#4b5fc8"/>
|
||||||
|
<stop offset="1" stop-color="#2a2f6b"/>
|
||||||
|
</linearGradient>
|
||||||
|
</defs>
|
||||||
|
<rect x="8" y="8" width="112" height="112" rx="26" fill="url(#bg)"/>
|
||||||
|
<!-- speaker -->
|
||||||
|
<path d="M26 54h16l20-16v52L42 74H26z" fill="#ffffff"/>
|
||||||
|
<path d="M74 52c5 6 5 18 0 24" fill="none" stroke="#ffffff" stroke-width="6" stroke-linecap="round"/>
|
||||||
|
<path d="M84 42c10 13 10 31 0 44" fill="none" stroke="#ffffff" stroke-width="6" stroke-linecap="round" opacity=".7"/>
|
||||||
|
<!-- slider -->
|
||||||
|
<rect x="26" y="98" width="76" height="8" rx="4" fill="#ffffff" opacity=".3"/>
|
||||||
|
<rect x="26" y="98" width="50" height="8" rx="4" fill="#f5c542"/>
|
||||||
|
<circle cx="76" cy="102" r="9" fill="#f5c542" stroke="#ffffff" stroke-width="3"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 947 B |
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||||
|
<path d="M1 5h2.5L7 2v8L3.5 7H1z" fill="#bebebe"/>
|
||||||
|
<path d="M9 4.5c1.2 1.6 1.2 2.4 0 4" fill="none" stroke="#bebebe" stroke-width="1.2" stroke-linecap="round"/>
|
||||||
|
<path d="M11 3c2 2.6 2 5.4 0 8" fill="none" stroke="#bebebe" stroke-width="1.2" stroke-linecap="round"/>
|
||||||
|
<rect x="1" y="12.2" width="14" height="1.6" rx=".8" fill="#bebebe" opacity=".5"/>
|
||||||
|
<rect x="1" y="12.2" width="9" height="1.6" rx=".8" fill="#bebebe"/>
|
||||||
|
<circle cx="10" cy="13" r="1.8" fill="#bebebe"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 609 B |
@@ -5,8 +5,9 @@ Name=moonmix
|
|||||||
GenericName=Volume Control
|
GenericName=Volume Control
|
||||||
Comment=Adjust volumes of PipeWire devices and applications
|
Comment=Adjust volumes of PipeWire devices and applications
|
||||||
Exec=moonmix
|
Exec=moonmix
|
||||||
Icon=multimedia-volume-control
|
Icon=org.latha.moonmix
|
||||||
Terminal=false
|
Terminal=false
|
||||||
Categories=AudioVideo;Audio;Mixer;GTK;Settings;HardwareSettings;
|
Categories=AudioVideo;Audio;Mixer;GTK;Settings;HardwareSettings;
|
||||||
Keywords=pipewire;wireplumber;volume;mixer;sound;audio;pavucontrol;
|
Keywords=pipewire;wireplumber;volume;mixer;sound;audio;pavucontrol;
|
||||||
StartupNotify=true
|
StartupNotify=true
|
||||||
|
StartupWMClass=org.latha.moonmix
|
||||||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
@@ -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"
|
extern "C" fn ffi_notebook_new(tag : Int32) -> Widget = "mm_gtk_notebook_new"
|
||||||
|
|
||||||
///|
|
///|
|
||||||
#borrow(label)
|
#borrow(label, icon)
|
||||||
extern "C" fn ffi_notebook_append(nb : Widget, child : Widget, label : Bytes) = "mm_gtk_notebook_append"
|
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"
|
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)
|
#borrow(icon)
|
||||||
extern "C" fn ffi_image_set_icon(img : Widget, icon : Bytes) = "mm_gtk_image_set_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"
|
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,
|
self : Widget,
|
||||||
child : Widget,
|
child : Widget,
|
||||||
label : String,
|
label : String,
|
||||||
|
icon~ : String = "",
|
||||||
) -> Unit {
|
) -> 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 {
|
pub fn Widget::save_png(self : Widget, path : String) -> Bool {
|
||||||
ffi_save_png(self, cstr(path)) != 0
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
#include <gio/gdesktopappinfo.h>
|
||||||
#include "moonbit.h"
|
#include "moonbit.h"
|
||||||
|
|
||||||
typedef void (*mm_gcall_t)(void *closure, int32_t tag, double value);
|
typedef void (*mm_gcall_t)(void *closure, int32_t tag, double value);
|
||||||
@@ -42,7 +43,84 @@ MOONBIT_FFI_EXPORT void mm_gtk_set_handler(mm_gcall_t call, void *closure) {
|
|||||||
g_closure = closure;
|
g_closure = closure;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOONBIT_FFI_EXPORT int32_t mm_gtk_init(void) { return gtk_init_check(); }
|
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. */
|
||||||
|
g_set_prgname("org.latha.moonmix");
|
||||||
|
if (!gtk_init_check())
|
||||||
|
return 0;
|
||||||
|
/* Let an uninstalled checkout find data/icons/hicolor/... too:
|
||||||
|
* $MOONMIX_ICON_DIR, then ./data/icons. */
|
||||||
|
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");
|
||||||
|
gtk_window_set_default_icon_name("org.latha.moonmix");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 1 if the icon theme has `name`. */
|
||||||
|
MOONBIT_FFI_EXPORT int32_t mm_gtk_has_icon(moonbit_bytes_t name) {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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. */
|
||||||
|
MOONBIT_FFI_EXPORT moonbit_bytes_t mm_gtk_app_icon(moonbit_bytes_t key) {
|
||||||
|
const char *k = s(key);
|
||||||
|
char *found = NULL;
|
||||||
|
GdkDisplay *d = gdk_display_get_default();
|
||||||
|
if (d && *k) {
|
||||||
|
GtkIconTheme *theme = gtk_icon_theme_get_for_display(d);
|
||||||
|
char *id = g_strconcat(k, ".desktop", NULL);
|
||||||
|
GDesktopAppInfo *di = g_desktop_app_info_new(id);
|
||||||
|
g_free(id);
|
||||||
|
if (di) {
|
||||||
|
theme_icon_of(G_APP_INFO(di), theme, &found);
|
||||||
|
g_object_unref(di);
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
GList *all = g_app_info_get_all();
|
||||||
|
for (GList *l = all; l && !found; l = l->next) {
|
||||||
|
GAppInfo *info = l->data;
|
||||||
|
if (!g_app_info_should_show(info))
|
||||||
|
continue;
|
||||||
|
const char *exe = g_app_info_get_executable(info);
|
||||||
|
char *base = exe ? g_path_get_basename(exe) : NULL;
|
||||||
|
const char *nm = g_app_info_get_name(info);
|
||||||
|
if ((base && g_ascii_strcasecmp(base, k) == 0) ||
|
||||||
|
(nm && g_ascii_strcasecmp(nm, k) == 0))
|
||||||
|
theme_icon_of(info, theme, &found);
|
||||||
|
g_free(base);
|
||||||
|
}
|
||||||
|
g_list_free_full(all, g_object_unref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_t n = found ? strlen(found) : 0;
|
||||||
|
moonbit_bytes_t out = moonbit_make_bytes(n + 1, 0);
|
||||||
|
if (found)
|
||||||
|
memcpy(out, found, n);
|
||||||
|
g_free(found);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
MOONBIT_FFI_EXPORT void mm_gtk_run(void) {
|
MOONBIT_FFI_EXPORT void mm_gtk_run(void) {
|
||||||
if (!g_loop)
|
if (!g_loop)
|
||||||
@@ -102,7 +180,7 @@ MOONBIT_FFI_EXPORT GtkWidget *mm_gtk_window_new(moonbit_bytes_t title,
|
|||||||
GtkWidget *win = gtk_window_new();
|
GtkWidget *win = gtk_window_new();
|
||||||
gtk_window_set_title(GTK_WINDOW(win), s(title));
|
gtk_window_set_title(GTK_WINDOW(win), s(title));
|
||||||
gtk_window_set_default_size(GTK_WINDOW(win), w, h);
|
gtk_window_set_default_size(GTK_WINDOW(win), w, h);
|
||||||
gtk_window_set_icon_name(GTK_WINDOW(win), "multimedia-volume-control");
|
gtk_window_set_icon_name(GTK_WINDOW(win), "org.latha.moonmix");
|
||||||
set_tag(win, tag);
|
set_tag(win, tag);
|
||||||
g_signal_connect(win, "close-request", G_CALLBACK(on_close), NULL);
|
g_signal_connect(win, "close-request", G_CALLBACK(on_close), NULL);
|
||||||
return win;
|
return win;
|
||||||
@@ -168,8 +246,16 @@ MOONBIT_FFI_EXPORT GtkWidget *mm_gtk_notebook_new(int32_t tag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MOONBIT_FFI_EXPORT void mm_gtk_notebook_append(GtkWidget *nb, GtkWidget *child,
|
MOONBIT_FFI_EXPORT void mm_gtk_notebook_append(GtkWidget *nb, GtkWidget *child,
|
||||||
moonbit_bytes_t label) {
|
moonbit_bytes_t label,
|
||||||
gtk_notebook_append_page(GTK_NOTEBOOK(nb), child, gtk_label_new(s(label)));
|
moonbit_bytes_t icon) {
|
||||||
|
GtkWidget *tab = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
||||||
|
if (s(icon)[0]) {
|
||||||
|
GtkWidget *img = gtk_image_new_from_icon_name(s(icon));
|
||||||
|
gtk_image_set_pixel_size(GTK_IMAGE(img), 16);
|
||||||
|
gtk_box_append(GTK_BOX(tab), img);
|
||||||
|
}
|
||||||
|
gtk_box_append(GTK_BOX(tab), gtk_label_new(s(label)));
|
||||||
|
gtk_notebook_append_page(GTK_NOTEBOOK(nb), child, tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
MOONBIT_FFI_EXPORT void mm_gtk_notebook_set_page(GtkWidget *nb, int32_t i) {
|
MOONBIT_FFI_EXPORT void mm_gtk_notebook_set_page(GtkWidget *nb, int32_t i) {
|
||||||
@@ -253,7 +339,10 @@ MOONBIT_FFI_EXPORT GtkWidget *mm_gtk_toggle_new(moonbit_bytes_t icon,
|
|||||||
GtkWidget *b = gtk_toggle_button_new();
|
GtkWidget *b = gtk_toggle_button_new();
|
||||||
if (s(icon)[0] && s(label)[0]) {
|
if (s(icon)[0] && s(label)[0]) {
|
||||||
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
|
||||||
gtk_box_append(GTK_BOX(box), gtk_image_new_from_icon_name(s(icon)));
|
GtkWidget *img = gtk_image_new_from_icon_name(s(icon));
|
||||||
|
gtk_image_set_pixel_size(GTK_IMAGE(img), 16);
|
||||||
|
g_object_set_data(G_OBJECT(b), "mm-img", img);
|
||||||
|
gtk_box_append(GTK_BOX(box), img);
|
||||||
gtk_box_append(GTK_BOX(box), gtk_label_new(s(label)));
|
gtk_box_append(GTK_BOX(box), gtk_label_new(s(label)));
|
||||||
gtk_button_set_child(GTK_BUTTON(b), box);
|
gtk_button_set_child(GTK_BUTTON(b), box);
|
||||||
} else if (s(icon)[0]) {
|
} else if (s(icon)[0]) {
|
||||||
@@ -275,7 +364,11 @@ MOONBIT_FFI_EXPORT void mm_gtk_toggle_set(GtkWidget *b, int32_t active) {
|
|||||||
|
|
||||||
MOONBIT_FFI_EXPORT void mm_gtk_button_set_icon(GtkWidget *b,
|
MOONBIT_FFI_EXPORT void mm_gtk_button_set_icon(GtkWidget *b,
|
||||||
moonbit_bytes_t icon) {
|
moonbit_bytes_t icon) {
|
||||||
gtk_button_set_icon_name(GTK_BUTTON(b), s(icon));
|
GtkWidget *img = g_object_get_data(G_OBJECT(b), "mm-img");
|
||||||
|
if (img)
|
||||||
|
gtk_image_set_from_icon_name(GTK_IMAGE(img), s(icon));
|
||||||
|
else
|
||||||
|
gtk_button_set_icon_name(GTK_BUTTON(b), s(icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void on_selected(GObject *dd, GParamSpec *p, gpointer d) {
|
static void on_selected(GObject *dd, GParamSpec *p, gpointer d) {
|
||||||
|
|||||||
@@ -2,8 +2,12 @@
|
|||||||
package "geordi/moonmix/gtk"
|
package "geordi/moonmix/gtk"
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
pub fn app_icon(String) -> String
|
||||||
|
|
||||||
pub fn dropdown((Int32) -> Unit) -> (Widget, Int32)
|
pub fn dropdown((Int32) -> Unit) -> (Widget, Int32)
|
||||||
|
|
||||||
|
pub fn has_icon(String) -> Bool
|
||||||
|
|
||||||
pub fn hbox(Int32) -> Widget
|
pub fn hbox(Int32) -> Widget
|
||||||
|
|
||||||
pub fn image(String, Int32) -> Widget
|
pub fn image(String, Int32) -> Widget
|
||||||
@@ -22,6 +26,8 @@ pub fn now_us() -> Int64
|
|||||||
|
|
||||||
pub fn quit() -> Unit
|
pub fn quit() -> Unit
|
||||||
|
|
||||||
|
pub fn resolve_icon(Array[String]) -> String
|
||||||
|
|
||||||
pub fn run() -> Unit
|
pub fn run() -> Unit
|
||||||
|
|
||||||
pub fn scale(Double, Double, (Double) -> Unit) -> (Widget, Int32)
|
pub fn scale(Double, Double, (Double) -> Unit) -> (Widget, Int32)
|
||||||
@@ -49,7 +55,7 @@ pub fn window(String, Int32, Int32, on_close? : () -> Unit) -> Widget
|
|||||||
pub type Widget
|
pub type Widget
|
||||||
pub fn Widget::add_css_class(Self, String) -> Unit
|
pub fn Widget::add_css_class(Self, String) -> Unit
|
||||||
pub fn Widget::append(Self, Self) -> Unit
|
pub fn Widget::append(Self, Self) -> Unit
|
||||||
pub fn Widget::append_page(Self, Self, String) -> Unit
|
pub fn Widget::append_page(Self, Self, String, icon? : String) -> Unit
|
||||||
pub fn Widget::present(Self) -> Unit
|
pub fn Widget::present(Self) -> Unit
|
||||||
pub fn Widget::remove(Self, Self) -> Unit
|
pub fn Widget::remove(Self, Self) -> Unit
|
||||||
pub fn Widget::reorder_after(Self, Self, Self?) -> Unit
|
pub fn Widget::reorder_after(Self, Self, Self?) -> Unit
|
||||||
|
|||||||
@@ -0,0 +1,200 @@
|
|||||||
|
// Icon selection, kept pure: PipeWire properties -> an ordered chain of
|
||||||
|
// icon-theme names. The GTK layer walks a chain and takes the first name the
|
||||||
|
// theme has (`gtk_icon_theme_has_icon`), so it never shows the broken-image
|
||||||
|
// placeholder unless even the last resort is missing.
|
||||||
|
//
|
||||||
|
// Chain entries starting with `APP_LOOKUP_PREFIX` ("app:<key>") ask the GUI
|
||||||
|
// to look the application up in the installed .desktop files and use that
|
||||||
|
// launcher's icon.
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn icon_fallback_device() -> Array[String] {
|
||||||
|
["audio-card-symbolic", "audio-x-generic-symbolic"]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn icon_fallback_stream() -> Array[String] {
|
||||||
|
["application-x-executable-symbolic", "audio-x-generic-symbolic"]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Absolute last resort, only used when the theme lacks everything above.
|
||||||
|
pub const ICON_MISSING : String = "image-missing"
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub const APP_LOOKUP_PREFIX : String = "app:"
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// "Default" toggle: first icon the theme has.
|
||||||
|
pub fn default_button_icons() -> Array[String] {
|
||||||
|
["emblem-ok-symbolic", "object-select-symbolic", "emblem-default-symbolic"]
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
pub fn symbolic(name : String) -> String {
|
||||||
|
if name.has_suffix("-symbolic") {
|
||||||
|
name
|
||||||
|
} else {
|
||||||
|
name + "-symbolic"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn push_unique(out : Array[String], name : String) -> Unit {
|
||||||
|
if name != "" && !out.contains(name) {
|
||||||
|
out.push(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// `name` as a themed icon, symbolic variant first (it follows the theme's
|
||||||
|
/// foreground colour).
|
||||||
|
fn push_symbolic_first(out : Array[String], name : String) -> Unit {
|
||||||
|
if name == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
push_unique(out, symbolic(name))
|
||||||
|
push_unique(out, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
fn has_any(haystack : String, needles : Array[String]) -> Bool {
|
||||||
|
let h = haystack.to_lower()
|
||||||
|
needles.any(fn(n) { h.contains(n) })
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Icon (without suffix) for a `device.form-factor` value, "" if unknown.
|
||||||
|
pub fn form_factor_icon(form_factor : String, kind : NodeKind) -> String {
|
||||||
|
match form_factor {
|
||||||
|
"headphone" => "audio-headphones"
|
||||||
|
"headset" => "audio-headset"
|
||||||
|
"speaker" | "hifi" => "audio-speakers"
|
||||||
|
"microphone" => "audio-input-microphone"
|
||||||
|
"webcam" => "camera-web"
|
||||||
|
"handset" | "hands-free" => "phone"
|
||||||
|
"portable" => "multimedia-player"
|
||||||
|
"car" =>
|
||||||
|
if kind is Source {
|
||||||
|
"audio-input-microphone"
|
||||||
|
} else {
|
||||||
|
"audio-speakers"
|
||||||
|
}
|
||||||
|
"computer" => "computer"
|
||||||
|
"tv" | "hdmi" => "video-display"
|
||||||
|
_ => ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// The bus of a device, from `device.bus` or else guessed from the
|
||||||
|
/// node.name prefix ("alsa_input.usb-...", "bluez_output...").
|
||||||
|
pub fn device_bus(n : Node) -> String {
|
||||||
|
if n.bus != "" {
|
||||||
|
return n.bus
|
||||||
|
}
|
||||||
|
let name = n.name
|
||||||
|
if name.has_prefix("bluez_") {
|
||||||
|
"bluetooth"
|
||||||
|
} else if has_any(name, [".usb-"]) {
|
||||||
|
"usb"
|
||||||
|
} else if has_any(name, [".pci-"]) {
|
||||||
|
"pci"
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Icon chain for a sink or source.
|
||||||
|
pub fn device_icon_chain(n : Node) -> Array[String] {
|
||||||
|
let kind = n.kind()
|
||||||
|
let out : Array[String] = []
|
||||||
|
// 1. what the device itself says
|
||||||
|
for h in n.icon_hints {
|
||||||
|
push_symbolic_first(out, h)
|
||||||
|
}
|
||||||
|
// 2. form factor, then HDMI / webcam heuristics, then bus
|
||||||
|
push_symbolic_first(out, form_factor_icon(n.form_factor, kind))
|
||||||
|
let text = n.name + " " + n.description
|
||||||
|
if has_any(text, ["hdmi", "displayport", "display port"]) {
|
||||||
|
push_symbolic_first(out, "video-display")
|
||||||
|
}
|
||||||
|
let bus = device_bus(n)
|
||||||
|
if kind is Source &&
|
||||||
|
(
|
||||||
|
has_any(n.description, ["webcam", "camera"]) ||
|
||||||
|
(bus == "usb" && n.description.to_lower().contains("cam"))
|
||||||
|
) {
|
||||||
|
push_symbolic_first(out, "camera-web")
|
||||||
|
}
|
||||||
|
match (bus, kind) {
|
||||||
|
("bluetooth", Source) => push_symbolic_first(out, "audio-headset")
|
||||||
|
("bluetooth", _) => push_symbolic_first(out, "audio-headphones")
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
// 3. by direction
|
||||||
|
match kind {
|
||||||
|
Source => push_symbolic_first(out, "audio-input-microphone")
|
||||||
|
_ => push_symbolic_first(out, "audio-speakers")
|
||||||
|
}
|
||||||
|
// 4. generic cards, then the placeholder
|
||||||
|
for f in icon_fallback_device() {
|
||||||
|
push_unique(out, f)
|
||||||
|
}
|
||||||
|
push_unique(out, ICON_MISSING)
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Icon chain for an application stream: the icons the app announces, its
|
||||||
|
/// launcher's icon from the installed .desktop files, names derived from the
|
||||||
|
/// binary / app name, then generic ones.
|
||||||
|
pub fn stream_icon_chain(n : Node) -> Array[String] {
|
||||||
|
let out : Array[String] = []
|
||||||
|
for h in n.icon_hints {
|
||||||
|
push_unique(out, h)
|
||||||
|
}
|
||||||
|
for key in [n.app_id, n.app_binary, n.app_name] {
|
||||||
|
if key != "" {
|
||||||
|
push_unique(out, APP_LOOKUP_PREFIX + key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for key in [n.app_id, n.app_binary, n.app_name.to_lower()] {
|
||||||
|
// Many apps ship an icon named after their binary or app id.
|
||||||
|
if key != "" && !key.contains(" ") && !key.contains("/") {
|
||||||
|
push_unique(out, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n.kind() is RecordStream {
|
||||||
|
push_unique(out, "audio-input-microphone-symbolic")
|
||||||
|
}
|
||||||
|
for f in icon_fallback_stream() {
|
||||||
|
push_unique(out, f)
|
||||||
|
}
|
||||||
|
push_unique(out, ICON_MISSING)
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Speaker icon for a volume (linked percent, 100 = 0 dB) and mute state.
|
||||||
|
pub fn volume_icon(percent : Double, mute : Bool) -> String {
|
||||||
|
if mute || percent <= 0.0 {
|
||||||
|
"audio-volume-muted-symbolic"
|
||||||
|
} else if percent < 34.0 {
|
||||||
|
"audio-volume-low-symbolic"
|
||||||
|
} else if percent < 67.0 {
|
||||||
|
"audio-volume-medium-symbolic"
|
||||||
|
} else {
|
||||||
|
"audio-volume-high-symbolic"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
/// Small symbolic icon next to a tab's label.
|
||||||
|
pub fn Tab::icon(self : Tab) -> String {
|
||||||
|
match self {
|
||||||
|
Playback | OutputDevices => "audio-speakers-symbolic"
|
||||||
|
Recording | InputDevices => "audio-input-microphone-symbolic"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
///|
|
||||||
|
fn dev(
|
||||||
|
media_class : String,
|
||||||
|
name~ : String = "",
|
||||||
|
description~ : String = "",
|
||||||
|
form_factor~ : String = "",
|
||||||
|
bus~ : String = "",
|
||||||
|
hints~ : Array[String] = [],
|
||||||
|
) -> @model.Node {
|
||||||
|
@model.Node::new(
|
||||||
|
1,
|
||||||
|
media_class,
|
||||||
|
name~,
|
||||||
|
description~,
|
||||||
|
form_factor~,
|
||||||
|
bus~,
|
||||||
|
icon_hints=hints,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "device hint comes first, symbolic variant before plain" {
|
||||||
|
let c = @model.device_icon_chain(
|
||||||
|
dev("Audio/Sink", hints=["audio-card-pci"], form_factor="headphone"),
|
||||||
|
)
|
||||||
|
assert_eq(c[0], "audio-card-pci-symbolic")
|
||||||
|
assert_eq(c[1], "audio-card-pci")
|
||||||
|
assert_eq(c[2], "audio-headphones-symbolic")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "device form factors" {
|
||||||
|
let first = fn(ff, cls) {
|
||||||
|
@model.device_icon_chain(dev(cls, form_factor=ff))[0]
|
||||||
|
}
|
||||||
|
assert_eq(first("headset", "Audio/Sink"), "audio-headset-symbolic")
|
||||||
|
assert_eq(first("speaker", "Audio/Sink"), "audio-speakers-symbolic")
|
||||||
|
assert_eq(
|
||||||
|
first("microphone", "Audio/Source"),
|
||||||
|
"audio-input-microphone-symbolic",
|
||||||
|
)
|
||||||
|
assert_eq(first("webcam", "Audio/Source"), "camera-web-symbolic")
|
||||||
|
assert_eq(first("handset", "Audio/Sink"), "phone-symbolic")
|
||||||
|
assert_eq(first("tv", "Audio/Sink"), "video-display-symbolic")
|
||||||
|
assert_eq(first("car", "Audio/Source"), "audio-input-microphone-symbolic")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "hdmi, webcam and bluetooth heuristics" {
|
||||||
|
let hdmi = @model.device_icon_chain(
|
||||||
|
dev(
|
||||||
|
"Audio/Sink",
|
||||||
|
name="alsa_output.pci-0000_01_00.1.hdmi-stereo",
|
||||||
|
description="HDMI / DisplayPort",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert_eq(hdmi[0], "video-display-symbolic")
|
||||||
|
let cam = @model.device_icon_chain(
|
||||||
|
dev(
|
||||||
|
"Audio/Source",
|
||||||
|
name="alsa_input.usb-EMEET_SmartCam_C960.mono-fallback",
|
||||||
|
description="EMEET SmartCam C960 Mono",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
assert_eq(cam[0], "camera-web-symbolic")
|
||||||
|
let bt = @model.device_icon_chain(
|
||||||
|
dev("Audio/Sink", name="bluez_output.AA_BB.1"),
|
||||||
|
)
|
||||||
|
assert_eq(bt[0], "audio-headphones-symbolic")
|
||||||
|
assert_eq(
|
||||||
|
@model.device_bus(dev("Audio/Sink", name="alsa_output.usb-X.analog-stereo")),
|
||||||
|
"usb",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "device chain always ends in fallbacks" {
|
||||||
|
let c = @model.device_icon_chain(dev("Audio/Sink"))
|
||||||
|
assert_eq(c, [
|
||||||
|
"audio-speakers-symbolic", "audio-speakers", "audio-card-symbolic", "audio-x-generic-symbolic",
|
||||||
|
"image-missing",
|
||||||
|
])
|
||||||
|
let s = @model.device_icon_chain(dev("Audio/Source"))
|
||||||
|
assert_eq(s[0], "audio-input-microphone-symbolic")
|
||||||
|
assert_eq(s[s.length() - 1], "image-missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "stream chain: hints, desktop lookup, binary, fallbacks" {
|
||||||
|
let n = @model.Node::new(
|
||||||
|
9,
|
||||||
|
"Stream/Output/Audio",
|
||||||
|
app_name="Firefox",
|
||||||
|
app_binary="firefox",
|
||||||
|
app_id="org.mozilla.firefox",
|
||||||
|
icon_hints=["firefox-esr"],
|
||||||
|
)
|
||||||
|
assert_eq(@model.stream_icon_chain(n), [
|
||||||
|
"firefox-esr", "app:org.mozilla.firefox", "app:firefox", "app:Firefox", "org.mozilla.firefox",
|
||||||
|
"firefox", "application-x-executable-symbolic", "audio-x-generic-symbolic", "image-missing",
|
||||||
|
])
|
||||||
|
let bare = @model.Node::new(10, "Stream/Input/Audio")
|
||||||
|
assert_eq(@model.stream_icon_chain(bare), [
|
||||||
|
"audio-input-microphone-symbolic", "application-x-executable-symbolic", "audio-x-generic-symbolic",
|
||||||
|
"image-missing",
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "volume icon follows volume and mute" {
|
||||||
|
assert_eq(@model.volume_icon(100.0, false), "audio-volume-high-symbolic")
|
||||||
|
assert_eq(@model.volume_icon(50.0, false), "audio-volume-medium-symbolic")
|
||||||
|
assert_eq(@model.volume_icon(10.0, false), "audio-volume-low-symbolic")
|
||||||
|
assert_eq(@model.volume_icon(0.0, false), "audio-volume-muted-symbolic")
|
||||||
|
assert_eq(@model.volume_icon(100.0, true), "audio-volume-muted-symbolic")
|
||||||
|
}
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "tab icons" {
|
||||||
|
assert_eq(@model.Tab::Playback.icon(), "audio-speakers-symbolic")
|
||||||
|
assert_eq(@model.Tab::InputDevices.icon(), "audio-input-microphone-symbolic")
|
||||||
|
}
|
||||||
@@ -6,6 +6,10 @@ import {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Values
|
// Values
|
||||||
|
pub const APP_LOOKUP_PREFIX : String = "app:"
|
||||||
|
|
||||||
|
pub const ICON_MISSING : String = "image-missing"
|
||||||
|
|
||||||
pub const MAX_PERCENT : Double = 150.0
|
pub const MAX_PERCENT : Double = 150.0
|
||||||
|
|
||||||
pub const METER_DECAY : Double = 0.04
|
pub const METER_DECAY : Double = 0.04
|
||||||
@@ -16,16 +20,28 @@ pub fn clamp_percent(Double) -> Double
|
|||||||
|
|
||||||
pub fn compare_text(String, String) -> Int32
|
pub fn compare_text(String, String) -> Int32
|
||||||
|
|
||||||
|
pub fn default_button_icons() -> Array[String]
|
||||||
|
|
||||||
|
pub fn device_bus(Node) -> String
|
||||||
|
|
||||||
|
pub fn device_icon_chain(Node) -> Array[String]
|
||||||
|
|
||||||
pub fn diff_rows(Array[Row], Array[Row]) -> Diff
|
pub fn diff_rows(Array[Row], Array[Row]) -> Diff
|
||||||
|
|
||||||
pub fn display_title(Node) -> String
|
pub fn display_title(Node) -> String
|
||||||
|
|
||||||
|
pub fn form_factor_icon(String, NodeKind) -> String
|
||||||
|
|
||||||
pub fn format_db(Double) -> String
|
pub fn format_db(Double) -> String
|
||||||
|
|
||||||
pub fn format_percent(Double) -> String
|
pub fn format_percent(Double) -> String
|
||||||
|
|
||||||
pub fn format_volume(Array[Double]) -> String
|
pub fn format_volume(Array[Double]) -> String
|
||||||
|
|
||||||
|
pub fn icon_fallback_device() -> Array[String]
|
||||||
|
|
||||||
|
pub fn icon_fallback_stream() -> Array[String]
|
||||||
|
|
||||||
pub fn linear_to_db(Double) -> Double?
|
pub fn linear_to_db(Double) -> Double?
|
||||||
|
|
||||||
pub fn linear_to_percent(Double) -> Double
|
pub fn linear_to_percent(Double) -> Double
|
||||||
@@ -44,6 +60,12 @@ pub fn scale_linked(Array[Double], Double) -> Array[Double]
|
|||||||
|
|
||||||
pub fn should_apply_remote(Int64, Int64, window_us? : Int64) -> Bool
|
pub fn should_apply_remote(Int64, Int64, window_us? : Int64) -> Bool
|
||||||
|
|
||||||
|
pub fn stream_icon_chain(Node) -> Array[String]
|
||||||
|
|
||||||
|
pub fn symbolic(String) -> String
|
||||||
|
|
||||||
|
pub fn volume_icon(Double, Bool) -> String
|
||||||
|
|
||||||
// Errors
|
// Errors
|
||||||
|
|
||||||
// Types and methods
|
// Types and methods
|
||||||
@@ -84,12 +106,16 @@ pub(all) struct Node {
|
|||||||
media_class : String
|
media_class : String
|
||||||
app_name : String
|
app_name : String
|
||||||
media_name : String
|
media_name : String
|
||||||
icon_name : String
|
icon_hints : Array[String]
|
||||||
|
form_factor : String
|
||||||
|
bus : String
|
||||||
|
app_binary : String
|
||||||
|
app_id : String
|
||||||
volumes : Array[Double]
|
volumes : Array[Double]
|
||||||
mute : Bool
|
mute : Bool
|
||||||
}
|
}
|
||||||
pub fn Node::kind(Self) -> NodeKind
|
pub fn Node::kind(Self) -> NodeKind
|
||||||
pub fn Node::new(Int32, String, name? : String, description? : String, app_name? : String, media_name? : String, icon_name? : String, volumes? : Array[Double], mute? : Bool) -> Self
|
pub fn Node::new(Int32, String, name? : String, description? : String, app_name? : String, media_name? : String, icon_hints? : Array[String], form_factor? : String, bus? : String, app_binary? : String, app_id? : String, volumes? : Array[Double], mute? : Bool) -> Self
|
||||||
|
|
||||||
#derive(Eq, @debug.Debug)
|
#derive(Eq, @debug.Debug)
|
||||||
pub(all) enum NodeKind {
|
pub(all) enum NodeKind {
|
||||||
@@ -106,7 +132,8 @@ pub(all) struct Row {
|
|||||||
id : Int32
|
id : Int32
|
||||||
title : String
|
title : String
|
||||||
subtitle : String
|
subtitle : String
|
||||||
icon_name : String
|
icons : Array[String]
|
||||||
|
volume_icon : String
|
||||||
volumes : Array[Double]
|
volumes : Array[Double]
|
||||||
percent : Double
|
percent : Double
|
||||||
volume_text : String
|
volume_text : String
|
||||||
@@ -137,6 +164,7 @@ pub(all) enum Tab {
|
|||||||
}
|
}
|
||||||
pub fn Tab::all() -> Array[Self]
|
pub fn Tab::all() -> Array[Self]
|
||||||
pub fn Tab::empty_text(Self) -> String
|
pub fn Tab::empty_text(Self) -> String
|
||||||
|
pub fn Tab::icon(Self) -> String
|
||||||
pub fn Tab::label(Self) -> String
|
pub fn Tab::label(Self) -> String
|
||||||
pub fn Tab::node_kind(Self) -> NodeKind
|
pub fn Tab::node_kind(Self) -> NodeKind
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,13 @@ pub(all) struct Node {
|
|||||||
media_class : String
|
media_class : String
|
||||||
app_name : String // application.name (streams)
|
app_name : String // application.name (streams)
|
||||||
media_name : String // media.name (streams)
|
media_name : String // media.name (streams)
|
||||||
icon_name : String // application.icon-name / device.icon-name
|
/// Icon names PipeWire/the app suggested, best first (application.icon-name,
|
||||||
|
/// media.icon-name for streams; device.icon-name, node.icon-name for devices).
|
||||||
|
icon_hints : Array[String]
|
||||||
|
form_factor : String // device.form-factor: "headset", "webcam", ...
|
||||||
|
bus : String // device.bus: "usb", "bluetooth", "pci", ...
|
||||||
|
app_binary : String // application.process.binary
|
||||||
|
app_id : String // pipewire.access.portal.app_id / application.id
|
||||||
volumes : Array[Double] // linear, one per channel; empty = no volume
|
volumes : Array[Double] // linear, one per channel; empty = no volume
|
||||||
mute : Bool
|
mute : Bool
|
||||||
}
|
}
|
||||||
@@ -51,7 +57,11 @@ pub fn Node::new(
|
|||||||
description~ : String = "",
|
description~ : String = "",
|
||||||
app_name~ : String = "",
|
app_name~ : String = "",
|
||||||
media_name~ : String = "",
|
media_name~ : String = "",
|
||||||
icon_name~ : String = "",
|
icon_hints~ : Array[String] = [],
|
||||||
|
form_factor~ : String = "",
|
||||||
|
bus~ : String = "",
|
||||||
|
app_binary~ : String = "",
|
||||||
|
app_id~ : String = "",
|
||||||
volumes~ : Array[Double] = [],
|
volumes~ : Array[Double] = [],
|
||||||
mute~ : Bool = false,
|
mute~ : Bool = false,
|
||||||
) -> Node {
|
) -> Node {
|
||||||
@@ -62,7 +72,11 @@ pub fn Node::new(
|
|||||||
media_class,
|
media_class,
|
||||||
app_name,
|
app_name,
|
||||||
media_name,
|
media_name,
|
||||||
icon_name,
|
icon_hints,
|
||||||
|
form_factor,
|
||||||
|
bus,
|
||||||
|
app_binary,
|
||||||
|
app_id,
|
||||||
volumes,
|
volumes,
|
||||||
mute,
|
mute,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ pub(all) struct Row {
|
|||||||
id : Int32
|
id : Int32
|
||||||
title : String
|
title : String
|
||||||
subtitle : String
|
subtitle : String
|
||||||
icon_name : String
|
/// Icon-theme names to try in order (see icons.mbt).
|
||||||
|
icons : Array[String]
|
||||||
|
volume_icon : String // speaker icon matching volume + mute
|
||||||
volumes : Array[Double]
|
volumes : Array[Double]
|
||||||
percent : Double // linked slider value (cubic %)
|
percent : Double // linked slider value (cubic %)
|
||||||
volume_text : String // "75% (-7.50 dB)"
|
volume_text : String // "75% (-7.50 dB)"
|
||||||
@@ -125,11 +127,12 @@ pub fn rows(state : State, tab : Tab) -> Array[Row] {
|
|||||||
id: n.id,
|
id: n.id,
|
||||||
title: display_title(n),
|
title: display_title(n),
|
||||||
subtitle,
|
subtitle,
|
||||||
icon_name: if n.icon_name != "" {
|
icons: if is_stream {
|
||||||
n.icon_name
|
stream_icon_chain(n)
|
||||||
} else {
|
} else {
|
||||||
default_icon(kind)
|
device_icon_chain(n)
|
||||||
},
|
},
|
||||||
|
volume_icon: volume_icon(linked_percent(n.volumes), n.mute),
|
||||||
volumes: n.volumes,
|
volumes: n.volumes,
|
||||||
percent: linked_percent(n.volumes),
|
percent: linked_percent(n.volumes),
|
||||||
volume_text: if n.volumes.length() > 0 {
|
volume_text: if n.volumes.length() > 0 {
|
||||||
@@ -150,17 +153,6 @@ pub fn rows(state : State, tab : Tab) -> Array[Row] {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
|
||||||
fn default_icon(kind : NodeKind) -> String {
|
|
||||||
match kind {
|
|
||||||
Sink => "audio-speakers-symbolic"
|
|
||||||
Source => "audio-input-microphone-symbolic"
|
|
||||||
PlaybackStream => "audio-x-generic-symbolic"
|
|
||||||
RecordStream => "audio-input-microphone-symbolic"
|
|
||||||
Other => "audio-x-generic-symbolic"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
///|
|
///|
|
||||||
/// Result of reconciling the rows shown on screen against new rows: which
|
/// Result of reconciling the rows shown on screen against new rows: which
|
||||||
/// row ids to remove, which to add (with their index) and which to update.
|
/// row ids to remove, which to add (with their index) and which to update.
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ test "device rows" {
|
|||||||
assert_eq(ins.length(), 1)
|
assert_eq(ins.length(), 1)
|
||||||
assert_true(ins[0].mute)
|
assert_true(ins[0].mute)
|
||||||
assert_true(ins[0].is_default)
|
assert_true(ins[0].is_default)
|
||||||
assert_eq(ins[0].icon_name, "audio-input-microphone-symbolic")
|
assert_eq(ins[0].icons[0], "audio-input-microphone-symbolic")
|
||||||
|
assert_eq(ins[0].volume_icon, "audio-volume-muted-symbolic")
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
# not expand $(pkg-config ...) in flags, so append them here. Works for both
|
# not expand $(pkg-config ...) in flags, so append them here. Works for both
|
||||||
# compiling stubs and linking the final executable.
|
# compiling stubs and linking the final executable.
|
||||||
set -e
|
set -e
|
||||||
PKGS="${MOONMIX_PKGS:-libpipewire-0.3 wireplumber-0.5 gtk4}"
|
PKGS="${MOONMIX_PKGS:-libpipewire-0.3 wireplumber-0.5 gtk4 gio-unix-2.0}"
|
||||||
exec "${MOONMIX_CC:-cc}" "$@" $(pkg-config --cflags --libs $PKGS)
|
exec "${MOONMIX_CC:-cc}" "$@" $(pkg-config --cflags --libs $PKGS)
|
||||||
@@ -25,11 +25,13 @@ context.objects = [
|
|||||||
{ factory = adapter
|
{ factory = adapter
|
||||||
args = { factory.name = support.null-audio-sink
|
args = { factory.name = support.null-audio-sink
|
||||||
node.name = "test_speakers" node.description = "Test Speakers"
|
node.name = "test_speakers" node.description = "Test Speakers"
|
||||||
|
device.form-factor = "speaker"
|
||||||
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
||||||
monitor.channel-volumes = true object.linger = true } }
|
monitor.channel-volumes = true object.linger = true } }
|
||||||
{ factory = adapter
|
{ factory = adapter
|
||||||
args = { factory.name = support.null-audio-sink
|
args = { factory.name = support.null-audio-sink
|
||||||
node.name = "test_headphones" node.description = "Test Headphones"
|
node.name = "test_headphones" node.description = "Test Headphones"
|
||||||
|
device.form-factor = "headphone"
|
||||||
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
media.class = "Audio/Sink" audio.position = [ FL FR ]
|
||||||
object.linger = true } }
|
object.linger = true } }
|
||||||
]
|
]
|
||||||
@@ -39,7 +41,7 @@ context.modules = [
|
|||||||
args = {
|
args = {
|
||||||
node.description = "Test Microphone"
|
node.description = "Test Microphone"
|
||||||
capture.props = { node.name = "test_mic_capture" node.passive = true audio.position = [ MONO ] }
|
capture.props = { node.name = "test_mic_capture" node.passive = true audio.position = [ MONO ] }
|
||||||
playback.props = { node.name = "test_mic" media.class = "Audio/Source" audio.position = [ MONO ] }
|
playback.props = { node.name = "test_mic" device.form-factor = "microphone" media.class = "Audio/Source" audio.position = [ MONO ] }
|
||||||
} }
|
} }
|
||||||
]
|
]
|
||||||
CONF
|
CONF
|
||||||
@@ -87,10 +89,10 @@ DATA=23040000
|
|||||||
{ printf 'RIFF'; le32 $((DATA + 36)); printf 'WAVEfmt '; le32 16
|
{ printf 'RIFF'; le32 $((DATA + 36)); printf 'WAVEfmt '; le32 16
|
||||||
printf '\001\000\002\000'; le32 48000; le32 192000; printf '\004\000\020\000'
|
printf '\001\000\002\000'; le32 48000; le32 192000; printf '\004\000\020\000'
|
||||||
printf 'data'; le32 $DATA; head -c $DATA /dev/urandom; } > "$LOGS/noise.wav"
|
printf 'data'; le32 $DATA; head -c $DATA /dev/urandom; } > "$LOGS/noise.wav"
|
||||||
{ pw-play -P '{ application.name = "Test Player" media.name = "Smoke test tone" }' \
|
{ pw-play -P '{ application.name = "Test Player" application.icon-name = "applications-multimedia-symbolic" media.name = "Smoke test tone" }' \
|
||||||
"$LOGS/noise.wav"; echo "pw-play exited with $?"; } >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!"
|
"$LOGS/noise.wav"; echo "pw-play exited with $?"; } >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!"
|
||||||
pw-cat --record --raw --rate 48000 --channels 1 --format s16 \
|
pw-cat --record --raw --rate 48000 --channels 1 --format s16 \
|
||||||
-P '{ application.name = "Test Recorder" media.name = "Mic capture" }' \
|
-P '{ application.name = "Test Recorder" application.icon-name = "audio-input-microphone" media.name = "Mic capture" }' \
|
||||||
/dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!"
|
/dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!"
|
||||||
wait_for 'Test Player | .*-> ' || true
|
wait_for 'Test Player | .*-> ' || true
|
||||||
|
|
||||||
@@ -154,7 +156,7 @@ if [ -n "$SHOTS" ] && [ -x "$GUI" ]; then
|
|||||||
if command -v gtk4-broadwayd >/dev/null; then
|
if command -v gtk4-broadwayd >/dev/null; then
|
||||||
gtk4-broadwayd :5 >/dev/null 2>&1 & PIDS="$PIDS $!"
|
gtk4-broadwayd :5 >/dev/null 2>&1 & PIDS="$PIDS $!"
|
||||||
sleep 1
|
sleep 1
|
||||||
GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 MOONMIX_SCREENSHOT="$SHOTS" \
|
MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 MOONMIX_SCREENSHOT="$SHOTS" \
|
||||||
timeout 30 "$GUI" || fail=1
|
timeout 30 "$GUI" || fail=1
|
||||||
else
|
else
|
||||||
echo "gtk4-broadwayd not found; skipping GUI"
|
echo "gtk4-broadwayd not found; skipping GUI"
|
||||||
|
|||||||
@@ -186,12 +186,22 @@ pub fn read_node(id : Int32) -> @model.Node? {
|
|||||||
node_prop(id, "node.nick")
|
node_prop(id, "node.nick")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let icon = {
|
let icon_hints = []
|
||||||
let a = node_prop(id, "application.icon-name")
|
for
|
||||||
|
key in [
|
||||||
|
"application.icon-name", "media.icon-name", "node.icon-name", "device.icon-name",
|
||||||
|
] {
|
||||||
|
let v = node_prop(id, key)
|
||||||
|
if v != "" && !icon_hints.contains(v) {
|
||||||
|
icon_hints.push(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let app_id = {
|
||||||
|
let a = node_prop(id, "pipewire.access.portal.app_id")
|
||||||
if a != "" {
|
if a != "" {
|
||||||
a
|
a
|
||||||
} else {
|
} else {
|
||||||
node_prop(id, "device.icon-name")
|
node_prop(id, "application.id")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(
|
Some(
|
||||||
@@ -202,7 +212,11 @@ pub fn read_node(id : Int32) -> @model.Node? {
|
|||||||
description~,
|
description~,
|
||||||
app_name=node_prop(id, "application.name"),
|
app_name=node_prop(id, "application.name"),
|
||||||
media_name=node_prop(id, "media.name"),
|
media_name=node_prop(id, "media.name"),
|
||||||
icon_name=icon,
|
icon_hints~,
|
||||||
|
form_factor=node_prop(id, "device.form-factor"),
|
||||||
|
bus=node_prop(id, "device.bus"),
|
||||||
|
app_binary=node_prop(id, "application.process.binary"),
|
||||||
|
app_id~,
|
||||||
volumes~,
|
volumes~,
|
||||||
mute~,
|
mute~,
|
||||||
),
|
),
|
||||||
|
|||||||