diff --git a/.sweet/orange-gentle-fox.md b/.sweet/orange-gentle-fox.md new file mode 100644 index 0000000..836f4de --- /dev/null +++ b/.sweet/orange-gentle-fox.md @@ -0,0 +1,5 @@ +--- +type: feature +--- + +Overhaul icons with bundled Lucide symbolic vectors, soft rounded icon tiles, redesigned mixer-fader app icon, and read-only host app icons in the OCI container. diff --git a/Containerfile b/Containerfile index d728124..9a659f1 100644 --- a/Containerfile +++ b/Containerfile @@ -38,7 +38,8 @@ RUN apt-get update \ && test -r /usr/share/pipewire/client.conf COPY --from=build /out/ / COPY data/org.latha.moonmix.desktop /usr/share/applications/org.latha.moonmix.desktop -COPY data/icons/ /usr/share/icons/ +COPY data/icons/hicolor/ /usr/share/icons/hicolor/ +COPY data/icons/LICENSE.lucide /usr/share/doc/moonmix/LICENSE.lucide COPY --chmod=755 tools/container-entrypoint /usr/local/bin/moonmix-entrypoint RUN gtk-update-icon-cache -f -t /usr/share/icons/hicolor diff --git a/README.md b/README.md index 2f5eead..9fa7775 100644 --- a/README.md +++ b/README.md @@ -153,14 +153,16 @@ install -Dm755 _build/native/release/build/cmd/moonmix/moonmix.exe ~/.local/bin/ 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 +install -Dm644 -t ~/.local/share/icons/hicolor/scalable/actions data/icons/hicolor/scalable/actions/moonmix-*.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`. +The app icon is `org.latha.moonmix` (three gold-lit mixer faders on a dark +violet-slate card), 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`. ### OCI container and desktop launcher (Wayland) @@ -190,12 +192,19 @@ set `MOONMIX_IMAGE` to run a different local tag. The runner maps your user ID and mounts only the Wayland and PipeWire sockets (including `PIPEWIRE_RUNTIME_DIR` / `PIPEWIRE_REMOTE` overrides), -plus `$XDG_RUNTIME_DIR/bus` when present for desktop appearance settings. -It has no network, GPU devices, home-directory mount or elevated privileges; -the root filesystem is read-only and temporary files disappear on exit. -Software rendering avoids depending on the host's GPU drivers. The image -sets `MOONMIX_ICON_THEME=Adwaita` so a host-only icon theme (such as Papirus) -does not cause missing icons; native runs keep the desktop's icon theme. +`$XDG_RUNTIME_DIR/bus` when present for desktop appearance settings, and +whichever standard host icon, pixmap and `.desktop` directories exist +(`/usr/share/{icons,pixmaps,applications}`, Flatpak exports and +`$XDG_DATA_HOME/{icons,applications}`) read-only under `/run/moonmix/host/`. +Setting `XDG_DATA_DIRS` inside the container lets GIO and `GtkIconTheme` +resolve full-colour host application icons (such as Firefox, Spotify or +Flatpaks) while bundled Lucide symbolic icons in `/usr/share/icons/hicolor` +remain used for devices and controls. It has no network, GPU devices, +home-directory mount or elevated privileges; the root filesystem is +read-only and temporary files disappear on exit. Software rendering avoids +depending on the host's GPU drivers. The image sets +`MOONMIX_ICON_THEME=Adwaita` so a host-only icon theme does not leave +symbolic fallback icons missing; native runs keep the desktop's icon theme. This is packaging, **not a sandbox for untrusted apps**: the sockets still grant access to your audio session, display and, when mounted, session D-Bus. X11 sessions are not supported by this runner. @@ -206,23 +215,31 @@ graph without changing it. ### 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`: +UI controls, tabs, devices and fallback streams use bundled crisp 24×24 +[Lucide](https://lucide.dev) symbolic SVGs (`data/icons/hicolor/scalable/actions/moonmix-*.svg`, +under the ISC License — see [LICENSE.lucide](data/icons/LICENSE.lucide)), +which GTK4 recolours automatically to match light, dark and accent-tinted +surfaces, with standard freedesktop icon names as secondary fallbacks. +Row icons sit inside a 36×36 px soft rounded tile (20 px for symbolic icons, +26 px for full-colour app icons, and accent-tinted for the default device); +button and tab icons are 16 px. -- **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. +The chains are chosen in `model/icons.mbt` and tested with `moon test`; +the GTK layer checks `has_icon` (or `"file:"` for absolute icon paths): + +- **Devices**: bundled `moonmix-device-*-symbolic` icons matched from + `device.form-factor` (speaker, headphones, headset, microphone, webcam, + phone, tv/hdmi display), HDMI/DisplayPort/webcam/Bluetooth/USB hints and + sink/source direction, falling back to freedesktop names (`audio-card-symbolic`, + `audio-x-generic-symbolic`). +- **Streams**: full-colour application icons first (`application.icon-name` / + `media.icon-name`, `.desktop` lookup via `GDesktopAppInfo` including `GFileIcon` + file paths, and direct theme names from `app_id` / binary), then any + symbolic hints, then `moonmix-device-mic-symbolic` for recording streams and + `moonmix-app-fallback-symbolic`. +- **Mute button & tabs**: `moonmix-volume-high/medium/low/muted-symbolic` and + `moonmix-tab-{playback,recording,output,input}-symbolic` (with freedesktop + fallbacks). 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 diff --git a/cmd/moonmix/main.mbt b/cmd/moonmix/main.mbt index 6a0f0b0..fa693a3 100644 --- a/cmd/moonmix/main.mbt +++ b/cmd/moonmix/main.mbt @@ -15,6 +15,7 @@ extern "C" fn c_exit(code : Int32) = "exit" /// Widgets of one row (a stream or a device). struct RowView { root : @gtk.Widget + icon_tile : @gtk.Widget icon : @gtk.Widget title : @gtk.Widget subtitle : @gtk.Widget @@ -55,8 +56,12 @@ struct App { } ///| -/// Device / application icon in each row; buttons use 16 px icons. -const ROW_ICON_SIZE : Int32 = 32 +/// Symbolic device / fallback icons render at 20 px inside a 36×36 soft tile; +/// full-colour application icons render larger at 26 px. Buttons use 16 px. +const ROW_SYMBOLIC_ICON_SIZE : Int32 = 20 + +///| +const ROW_APP_ICON_SIZE : Int32 = 26 ///| const METER_INTERVAL_MS : Int32 = 40 @@ -65,19 +70,69 @@ const METER_INTERVAL_MS : Int32 = 40 const CSS : String = #|.mm-title { font-weight: bold; } #|.mm-subtitle { opacity: 0.7; font-size: smaller; } - #|.mm-row { padding: 6px 12px; } + #|.mm-row { padding: 8px 12px; } #|.mm-status { padding: 4px 8px; opacity: 0.8; font-size: smaller; } + #|.mm-icon-tile { + #| min-width: 36px; + #| min-height: 36px; + #| border-radius: 10px; + #| background-color: alpha(currentColor, 0.08); + #| box-shadow: inset 0 0 0 1px alpha(currentColor, 0.08); + #|} + #|.mm-icon-tile.mm-app-tile { + #| background-color: alpha(currentColor, 0.05); + #|} + #|.mm-icon-tile.mm-default-tile { + #| background-color: alpha(@theme_selected_bg_color, 0.14); + #| box-shadow: inset 0 0 0 1px alpha(@theme_selected_bg_color, 0.34); + #| color: @theme_selected_bg_color; + #|} #|levelbar.mm-meter trough, levelbar.mm-meter block { min-height: 4px; } #|levelbar.mm-meter { margin: 0 10px; } +///| +fn set_row_icon( + tile : @gtk.Widget, + icon : @gtk.Widget, + icons : Array[String], +) -> Unit { + let resolved = @gtk.resolve_icon(icons) + let sym = @model.is_symbolic_icon(resolved) + icon.set_icon(resolved) + icon.set_pixel_size( + if sym { + ROW_SYMBOLIC_ICON_SIZE + } else { + ROW_APP_ICON_SIZE + }, + ) + if sym { + icon.remove_css_class("mm-icon-app") + tile.remove_css_class("mm-app-tile") + } else { + icon.add_css_class("mm-icon-app") + tile.add_css_class("mm-app-tile") + } +} + ///| fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView { let id = row.id let tags = [] let root = @gtk.vbox(4) root.add_css_class("mm-row") - let header = @gtk.hbox(8) - let icon = @gtk.image(@gtk.resolve_icon(row.icons), ROW_ICON_SIZE) + let header = @gtk.hbox(10) + let icon_tile = @gtk.hbox(0) + icon_tile.add_css_class("mm-icon-tile") + icon_tile.set_hexpand(false) + icon_tile.set_vexpand(false) + icon_tile.set_valign_center() + let icon = @gtk.image("", ROW_SYMBOLIC_ICON_SIZE) + icon.set_hexpand(true) + icon.set_vexpand(true) + icon.set_halign_center() + icon.set_valign_center() + icon_tile.append(icon) let texts = @gtk.vbox(0) texts.set_hexpand(true) texts.set_valign_center() @@ -87,7 +142,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView { subtitle.add_css_class("mm-subtitle") texts.append(title) texts.append(subtitle) - header.append(icon) + header.append(icon_tile) header.append(texts) // Streams: device selector. Devices: "default" toggle. @@ -142,7 +197,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView { _ => None } let (mute, mute_tag) = @gtk.toggle( - @gtk.resolve_icon([row.volume_icon, "audio-volume-high"]), + @gtk.resolve_icon(@model.volume_icon_chain(row.percent, row.mute)), "", fn(on) { let _ = @wp.set_mute(id, on) }, ) @@ -180,6 +235,7 @@ fn new_row_view(app : App, tab : @model.Tab, row : @model.Row) -> RowView { root.append(slider_row) let view = { root, + icon_tile, icon, title, subtitle, @@ -212,7 +268,14 @@ fn apply_row(view : RowView, row : @model.Row, force~ : Bool = false) -> Unit { view.subtitle.set_visible(row.subtitle != "") } if force || old.icons != row.icons { - view.icon.set_icon(@gtk.resolve_icon(row.icons)) + set_row_icon(view.icon_tile, view.icon, row.icons) + } + if force || old.is_default != row.is_default { + if row.is_default { + view.icon_tile.add_css_class("mm-default-tile") + } else { + view.icon_tile.remove_css_class("mm-default-tile") + } } view.scale.set_sensitive(row.has_volume) if force || @model.should_apply_remote(view.last_local_us, @gtk.now_us()) { @@ -220,9 +283,11 @@ fn apply_row(view : RowView, row : @model.Row, force~ : Bool = false) -> Unit { view.volume_label.set_text(row.volume_text) } view.mute.set_active(row.mute) - view.mute.set_button_icon( - @gtk.resolve_icon([row.volume_icon, "audio-volume-high"]), - ) + if force || old.volume_icon != row.volume_icon { + view.mute.set_button_icon( + @gtk.resolve_icon(@model.volume_icon_chain(row.percent, row.mute)), + ) + } match view.default_btn { Some(b) => b.set_active(row.is_default) None => () @@ -444,11 +509,7 @@ fn build_ui() -> App { nb.append_page( @gtk.scrolled(list), tab.label(), - icon=@gtk.resolve_icon([ - tab.icon(), - "audio-card-symbolic", - "audio-x-generic", - ]), + icon=@gtk.resolve_icon(tab.icon_chain()), ) tabs.push({ tab, list, empty, views: Map([]), rows: [], }) } diff --git a/data/icons/LICENSE.lucide b/data/icons/LICENSE.lucide new file mode 100644 index 0000000..718bb3f --- /dev/null +++ b/data/icons/LICENSE.lucide @@ -0,0 +1,43 @@ +ISC License + +Copyright (c) 2026 Lucide Icons and Contributors + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +--- + +The following Lucide icons are derived from the Feather project: + +airplay, alert-circle, alert-octagon, alert-triangle, aperture, arrow-down-circle, arrow-down-left, arrow-down-right, arrow-down, arrow-left-circle, arrow-left, arrow-right-circle, arrow-right, arrow-up-circle, arrow-up-left, arrow-up-right, arrow-up, at-sign, calendar, cast, check, chevron-down, chevron-left, chevron-right, chevron-up, chevrons-down, chevrons-left, chevrons-right, chevrons-up, circle, clipboard, clock, code, columns, command, compass, corner-down-left, corner-down-right, corner-left-down, corner-left-up, corner-right-down, corner-right-up, corner-up-left, corner-up-right, crosshair, database, divide-circle, divide-square, dollar-sign, download, external-link, feather, frown, hash, headphones, help-circle, info, italic, key, layout, life-buoy, link-2, link, loader, lock, log-in, log-out, maximize, meh, minimize, minimize-2, minus-circle, minus-square, minus, monitor, moon, more-horizontal, more-vertical, move, music, navigation-2, navigation, octagon, pause-circle, percent, plus-circle, plus-square, plus, power, radio, rss, search, server, share, shopping-bag, sidebar, smartphone, smile, square, table-2, tablet, target, terminal, trash-2, trash, triangle, tv, type, upload, x-circle, x-octagon, x-square, x, zoom-in, zoom-out + +The MIT License (MIT) (for the icons listed above) + +Copyright (c) 2013-present Cole Bemis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/data/icons/hicolor/scalable/actions/moonmix-app-fallback-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-app-fallback-symbolic.svg new file mode 100644 index 0000000..9b2e4dc --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-app-fallback-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-default-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-default-symbolic.svg new file mode 100644 index 0000000..2c16409 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-default-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-audio-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-audio-symbolic.svg new file mode 100644 index 0000000..869c6d0 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-audio-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-bluetooth-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-bluetooth-symbolic.svg new file mode 100644 index 0000000..ebd6375 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-bluetooth-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-display-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-display-symbolic.svg new file mode 100644 index 0000000..e921b83 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-display-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-headphones-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-headphones-symbolic.svg new file mode 100644 index 0000000..f0222c4 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-headphones-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-headset-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-headset-symbolic.svg new file mode 100644 index 0000000..c7d946c --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-headset-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-mic-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-mic-symbolic.svg new file mode 100644 index 0000000..08d973d --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-mic-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-phone-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-phone-symbolic.svg new file mode 100644 index 0000000..bc7d0eb --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-phone-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-speaker-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-speaker-symbolic.svg new file mode 100644 index 0000000..6fc4c1e --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-speaker-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-usb-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-usb-symbolic.svg new file mode 100644 index 0000000..f64d6f5 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-usb-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-device-webcam-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-device-webcam-symbolic.svg new file mode 100644 index 0000000..4b6cc50 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-device-webcam-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-tab-input-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-tab-input-symbolic.svg new file mode 100644 index 0000000..08d973d --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-tab-input-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-tab-output-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-tab-output-symbolic.svg new file mode 100644 index 0000000..6fc4c1e --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-tab-output-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-tab-playback-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-tab-playback-symbolic.svg new file mode 100644 index 0000000..7048827 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-tab-playback-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-tab-recording-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-tab-recording-symbolic.svg new file mode 100644 index 0000000..853fc03 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-tab-recording-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-volume-high-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-volume-high-symbolic.svg new file mode 100644 index 0000000..26cb166 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-volume-high-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-volume-low-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-volume-low-symbolic.svg new file mode 100644 index 0000000..5796a3d --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-volume-low-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-volume-medium-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-volume-medium-symbolic.svg new file mode 100644 index 0000000..5e700e3 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-volume-medium-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/actions/moonmix-volume-muted-symbolic.svg b/data/icons/hicolor/scalable/actions/moonmix-volume-muted-symbolic.svg new file mode 100644 index 0000000..0995534 --- /dev/null +++ b/data/icons/hicolor/scalable/actions/moonmix-volume-muted-symbolic.svg @@ -0,0 +1,4 @@ + + + + diff --git a/data/icons/hicolor/scalable/apps/org.latha.moonmix.svg b/data/icons/hicolor/scalable/apps/org.latha.moonmix.svg index c180983..c8e2ec6 100644 --- a/data/icons/hicolor/scalable/apps/org.latha.moonmix.svg +++ b/data/icons/hicolor/scalable/apps/org.latha.moonmix.svg @@ -2,17 +2,57 @@ - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg b/data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg index c1faff4..692bb50 100644 --- a/data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg +++ b/data/icons/hicolor/symbolic/apps/org.latha.moonmix-symbolic.svg @@ -1,9 +1,15 @@ - - - - - - + + + + + + + + + + + + diff --git a/docs/screenshots/accent-input-devices.png b/docs/screenshots/accent-input-devices.png index ce5b818..4f52816 100644 Binary files a/docs/screenshots/accent-input-devices.png and b/docs/screenshots/accent-input-devices.png differ diff --git a/docs/screenshots/accent-output-devices.png b/docs/screenshots/accent-output-devices.png index 50b7517..c211e6e 100644 Binary files a/docs/screenshots/accent-output-devices.png and b/docs/screenshots/accent-output-devices.png differ diff --git a/docs/screenshots/accent-playback.png b/docs/screenshots/accent-playback.png index aebfb14..1bcb5fa 100644 Binary files a/docs/screenshots/accent-playback.png and b/docs/screenshots/accent-playback.png differ diff --git a/docs/screenshots/accent-recording.png b/docs/screenshots/accent-recording.png index 94e6b1c..ddcb33f 100644 Binary files a/docs/screenshots/accent-recording.png and b/docs/screenshots/accent-recording.png differ diff --git a/docs/screenshots/input-devices.png b/docs/screenshots/input-devices.png index 12cf641..1ba9008 100644 Binary files a/docs/screenshots/input-devices.png and b/docs/screenshots/input-devices.png differ diff --git a/docs/screenshots/output-devices.png b/docs/screenshots/output-devices.png index 03908af..7f81f14 100644 Binary files a/docs/screenshots/output-devices.png and b/docs/screenshots/output-devices.png differ diff --git a/docs/screenshots/playback.png b/docs/screenshots/playback.png index 6e37475..91d80da 100644 Binary files a/docs/screenshots/playback.png and b/docs/screenshots/playback.png differ diff --git a/docs/screenshots/recording.png b/docs/screenshots/recording.png index 3b764ce..7de855c 100644 Binary files a/docs/screenshots/recording.png and b/docs/screenshots/recording.png differ diff --git a/gtk/gtk.mbt b/gtk/gtk.mbt index c6a4cd0..7f7936d 100644 --- a/gtk/gtk.mbt +++ b/gtk/gtk.mbt @@ -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:" 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:" entries are looked up in the +/// .desktop files (and may resolve to a theme icon name or "file:"). +/// 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:") { diff --git a/gtk/gtk_stub.c b/gtk/gtk_stub.c index 6e028fc..0eba374 100644 --- a/gtk/gtk_stub.c +++ b/gtk/gtk_stub.c @@ -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:" 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:") 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 diff --git a/gtk/pkg.generated.mbti b/gtk/pkg.generated.mbti index f348333..7f3130b 100644 --- a/gtk/pkg.generated.mbti +++ b/gtk/pkg.generated.mbti @@ -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 diff --git a/model/accent.mbt b/model/accent.mbt index 6180be0..59686f2 100644 --- a/model/accent.mbt +++ b/model/accent.mbt @@ -229,6 +229,7 @@ pub fn accent_css(accent : Rgb, dark : Bool) -> String { "notebook > header.left > tabs > tab:checked { box-shadow: inset -4px 0 \{bg}; }", "notebook > header.right > tabs > tab:checked { box-shadow: inset 4px 0 \{bg}; }", "button.mm-default:checked { background-image: none; background-color: \{bg}; border-color: \{border}; color: \{fg}; }", + ".mm-icon-tile.mm-default-tile { background-color: alpha(\{bg}, 0.16); box-shadow: inset 0 0 0 1px alpha(\{bg}, 0.36); color: \{text}; }", "check:checked, radio:checked, switch:checked { background-image: none; background-color: \{bg}; border-color: \{border}; color: \{fg}; }", "row:selected, .view:selected { background-color: \{bg}; color: \{fg}; }", "link, button.link { color: \{text}; }", diff --git a/model/accent_test.mbt b/model/accent_test.mbt index e4d57d2..098cbc3 100644 --- a/model/accent_test.mbt +++ b/model/accent_test.mbt @@ -105,6 +105,7 @@ test "accent css overrides named colours and widget fills" { assert_true(css.contains("levelbar > trough > block.high")) assert_true(css.contains("tab:checked { box-shadow: inset 0 -4px #ff7800; }")) assert_true(css.contains("button.mm-default:checked")) + assert_true(css.contains(".mm-icon-tile.mm-default-tile")) // The text colour is the darkened accent, not the raw one. let text = @model.accent_text_color(hex("#ff7800"), false).to_hex() assert_true(text != "#ff7800") diff --git a/model/icons.mbt b/model/icons.mbt index 35b56c9..4fa7a48 100644 --- a/model/icons.mbt +++ b/model/icons.mbt @@ -5,16 +5,21 @@ // // Chain entries starting with `APP_LOOKUP_PREFIX` ("app:") ask the GUI // to look the application up in the installed .desktop files and use that -// launcher's icon. +// launcher's icon. Entries starting with `FILE_ICON_PREFIX` ("file:") +// point to an icon file directly. ///| pub fn icon_fallback_device() -> Array[String] { - ["audio-card-symbolic", "audio-x-generic-symbolic"] + [ + "moonmix-device-audio-symbolic", "audio-card-symbolic", "audio-x-generic-symbolic", + ] } ///| pub fn icon_fallback_stream() -> Array[String] { - ["application-x-executable-symbolic", "audio-x-generic-symbolic"] + [ + "moonmix-app-fallback-symbolic", "application-x-executable-symbolic", "audio-x-generic-symbolic", + ] } ///| @@ -24,10 +29,22 @@ pub const ICON_MISSING : String = "image-missing" ///| pub const APP_LOOKUP_PREFIX : String = "app:" +///| +pub const FILE_ICON_PREFIX : String = "file:" + +///| +/// True if a resolved icon name or path is a symbolic monochrome asset. +pub fn is_symbolic_icon(name : String) -> Bool { + name == ICON_MISSING || + name.has_suffix("-symbolic") || + name.has_suffix("-symbolic.svg") || + name.has_suffix("-symbolic.png") +} + ///| /// "Default" toggle: first icon the theme has. pub fn default_button_icons() -> Array[String] { - ["emblem-ok-symbolic", "object-select-symbolic", "emblem-default-symbolic"] + ["moonmix-default-symbolic", "emblem-ok-symbolic", "object-select-symbolic"] } ///| @@ -64,7 +81,61 @@ fn has_any(haystack : String, needles : Array[String]) -> Bool { } ///| -/// Icon (without suffix) for a `device.form-factor` value, "" if unknown. +/// Bundled Lucide symbolic icon name for a `device.form-factor` value, "" if unknown. +pub fn bundled_form_factor_icon( + form_factor : String, + kind : NodeKind, +) -> String { + match form_factor { + "headphone" => "moonmix-device-headphones-symbolic" + "headset" => "moonmix-device-headset-symbolic" + "speaker" | "hifi" => "moonmix-device-speaker-symbolic" + "microphone" => "moonmix-device-mic-symbolic" + "webcam" => "moonmix-device-webcam-symbolic" + "handset" | "hands-free" | "portable" => "moonmix-device-phone-symbolic" + "tv" | "hdmi" | "computer" => "moonmix-device-display-symbolic" + "car" => + if kind is Source { + "moonmix-device-mic-symbolic" + } else { + "moonmix-device-speaker-symbolic" + } + _ => "" + } +} + +///| +/// Map a freedesktop/PipeWire device icon hint to one of our bundled Lucide icons. +fn bundled_hint_icon(hint : String) -> String { + let h = hint.to_lower() + if h.contains("headset") { + "moonmix-device-headset-symbolic" + } else if h.contains("headphone") { + "moonmix-device-headphones-symbolic" + } else if h.contains("webcam") || h.contains("camera") { + "moonmix-device-webcam-symbolic" + } else if h.contains("display") || + h.contains("monitor") || + h.contains("hdmi") || + h.contains("tv") { + "moonmix-device-display-symbolic" + } else if h.contains("phone") { + "moonmix-device-phone-symbolic" + } else if h.contains("microphone") { + "moonmix-device-mic-symbolic" + } else if h.contains("speaker") { + "moonmix-device-speaker-symbolic" + } else if h.contains("bluetooth") { + "moonmix-device-bluetooth-symbolic" + } else if h.contains("usb") { + "moonmix-device-usb-symbolic" + } else { + "" + } +} + +///| +/// Standard freedesktop 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" @@ -106,26 +177,58 @@ pub fn device_bus(n : Node) -> String { } ///| -/// Icon chain for a sink or source. +/// Icon chain for a sink or source: bundled crisp Lucide symbolic icons first, +/// keeping standard freedesktop names as secondary fallbacks. 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 && + let is_hdmi = has_any(text, ["hdmi", "displayport", "display port"]) + let is_webcam = kind is Source && ( has_any(n.description, ["webcam", "camera"]) || (bus == "usb" && n.description.to_lower().contains("cam")) - ) { + ) + + // Phase 1: bundled Lucide symbolic icons + push_unique(out, bundled_form_factor_icon(n.form_factor, kind)) + if is_hdmi { + push_unique(out, "moonmix-device-display-symbolic") + } + if is_webcam { + push_unique(out, "moonmix-device-webcam-symbolic") + } + for h in n.icon_hints { + push_unique(out, bundled_hint_icon(h)) + } + if has_any(text, ["headset"]) { + push_unique(out, "moonmix-device-headset-symbolic") + } + if has_any(text, ["headphone", "earbud"]) { + push_unique(out, "moonmix-device-headphones-symbolic") + } + if bus == "bluetooth" { + push_unique(out, "moonmix-device-bluetooth-symbolic") + } else if bus == "usb" { + push_unique(out, "moonmix-device-usb-symbolic") + } + match kind { + Source => push_unique(out, "moonmix-device-mic-symbolic") + Sink => push_unique(out, "moonmix-device-speaker-symbolic") + _ => push_unique(out, "moonmix-device-audio-symbolic") + } + push_unique(out, "moonmix-device-audio-symbolic") + + // Phase 2: freedesktop secondary fallbacks + for h in n.icon_hints { + push_symbolic_first(out, h) + } + push_symbolic_first(out, form_factor_icon(n.form_factor, kind)) + if is_hdmi { + push_symbolic_first(out, "video-display") + } + if is_webcam { push_symbolic_first(out, "camera-web") } match (bus, kind) { @@ -133,12 +236,10 @@ pub fn device_icon_chain(n : Node) -> Array[String] { ("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) } @@ -147,31 +248,56 @@ pub fn device_icon_chain(n : Node) -> Array[String] { } ///| -/// 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. +/// Icon chain for an application stream: prefer real full-colour host app +/// icons first (non-symbolic hints, .desktop lookup, direct binary/app_id), +/// then any symbolic hints, then crisp bundled fallbacks. pub fn stream_icon_chain(n : Node) -> Array[String] { let out : Array[String] = [] + // 1. Non-symbolic icon hints (including absolute file paths). for h in n.icon_hints { - push_unique(out, h) + if h.has_prefix("/") { + if !is_symbolic_icon(h) { + push_unique(out, FILE_ICON_PREFIX + h) + } + } else if !h.has_suffix("-symbolic") { + push_unique(out, h) + } } + // 2. Installed .desktop lookup (prefers full-colour icons on the GTK side). for key in [n.app_id, n.app_binary, n.app_name] { if key != "" { push_unique(out, APP_LOOKUP_PREFIX + key) } } + // 3. Direct non-symbolic icon-theme lookup by app id / binary / lower name. 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("/") { + if key != "" && + !key.contains(" ") && + !key.contains("/") && + !key.has_suffix("-symbolic") { push_unique(out, key) } } + // 4. Symbolic hints only if no full-colour app icon was found. + for h in n.icon_hints { + if h.has_prefix("/") { + if is_symbolic_icon(h) { + push_unique(out, FILE_ICON_PREFIX + h) + } + } else if h.has_suffix("-symbolic") { + push_unique(out, h) + } + } + // 5-8. Record-stream mic, bundled fallback, freedesktop fallback, placeholder. if n.kind() is RecordStream { - push_unique(out, "audio-input-microphone-symbolic") + push_unique(out, "moonmix-device-mic-symbolic") } for f in icon_fallback_stream() { push_unique(out, f) } + if n.kind() is RecordStream { + push_unique(out, "audio-input-microphone-symbolic") + } push_unique(out, ICON_MISSING) out } @@ -180,13 +306,36 @@ pub fn stream_icon_chain(n : Node) -> Array[String] { /// 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" + "moonmix-volume-muted-symbolic" } else if percent < 34.0 { - "audio-volume-low-symbolic" + "moonmix-volume-low-symbolic" } else if percent < 67.0 { - "audio-volume-medium-symbolic" + "moonmix-volume-medium-symbolic" } else { - "audio-volume-high-symbolic" + "moonmix-volume-high-symbolic" + } +} + +///| +/// Volume icon resolution chain: bundled Lucide symbolic first, then +/// standard freedesktop fallbacks. +pub fn volume_icon_chain(percent : Double, mute : Bool) -> Array[String] { + if mute || percent <= 0.0 { + [ + "moonmix-volume-muted-symbolic", "audio-volume-muted-symbolic", "audio-volume-muted", + ] + } else if percent < 34.0 { + [ + "moonmix-volume-low-symbolic", "audio-volume-low-symbolic", "audio-volume-low", + ] + } else if percent < 67.0 { + [ + "moonmix-volume-medium-symbolic", "audio-volume-medium-symbolic", "audio-volume-medium", + ] + } else { + [ + "moonmix-volume-high-symbolic", "audio-volume-high-symbolic", "audio-volume-high", + ] } } @@ -194,7 +343,36 @@ pub fn volume_icon(percent : Double, mute : Bool) -> String { /// 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" + Playback => "moonmix-tab-playback-symbolic" + Recording => "moonmix-tab-recording-symbolic" + OutputDevices => "moonmix-tab-output-symbolic" + InputDevices => "moonmix-tab-input-symbolic" + } +} + +///| +/// Tab icon resolution chain: bundled Lucide symbolic first, then +/// standard freedesktop fallbacks. +pub fn Tab::icon_chain(self : Tab) -> Array[String] { + match self { + Playback => + [ + "moonmix-tab-playback-symbolic", "multimedia-volume-control-symbolic", "audio-speakers-symbolic", + "audio-x-generic", + ] + Recording => + [ + "moonmix-tab-recording-symbolic", "audio-input-microphone-symbolic", "audio-x-generic", + ] + OutputDevices => + [ + "moonmix-tab-output-symbolic", "audio-speakers-symbolic", "audio-card-symbolic", + "audio-x-generic", + ] + InputDevices => + [ + "moonmix-tab-input-symbolic", "audio-input-microphone-symbolic", "audio-card-symbolic", + "audio-x-generic", + ] } } diff --git a/model/icons_test.mbt b/model/icons_test.mbt index 2db6498..cffcc1d 100644 --- a/model/icons_test.mbt +++ b/model/icons_test.mbt @@ -19,34 +19,41 @@ fn dev( } ///| -test "device hint comes first, symbolic variant before plain" { +test "device bundled icon beats form factor/hint freedesktop fallback" { 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") + assert_eq(c[0], "moonmix-device-headphones-symbolic") + assert_true(c.contains("audio-card-pci-symbolic")) + assert_true(c.contains("audio-headphones-symbolic")) + let card_idx = c.search("audio-card-pci-symbolic").unwrap() + let hp_idx = c.search("audio-headphones-symbolic").unwrap() + assert_true(card_idx < hp_idx) } ///| -test "device form factors" { +test "device form factors prefer bundled lucide icons" { 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("headset", "Audio/Sink"), "moonmix-device-headset-symbolic") assert_eq( - first("microphone", "Audio/Source"), - "audio-input-microphone-symbolic", + first("headphone", "Audio/Sink"), + "moonmix-device-headphones-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") + assert_eq(first("speaker", "Audio/Sink"), "moonmix-device-speaker-symbolic") + assert_eq(first("hifi", "Audio/Sink"), "moonmix-device-speaker-symbolic") + assert_eq(first("microphone", "Audio/Source"), "moonmix-device-mic-symbolic") + assert_eq(first("webcam", "Audio/Source"), "moonmix-device-webcam-symbolic") + assert_eq(first("handset", "Audio/Sink"), "moonmix-device-phone-symbolic") + assert_eq(first("tv", "Audio/Sink"), "moonmix-device-display-symbolic") + assert_eq(first("hdmi", "Audio/Sink"), "moonmix-device-display-symbolic") + assert_eq(first("car", "Audio/Source"), "moonmix-device-mic-symbolic") + assert_eq(first("car", "Audio/Sink"), "moonmix-device-speaker-symbolic") } ///| -test "hdmi, webcam and bluetooth heuristics" { +test "hdmi, webcam, bluetooth and usb heuristics" { let hdmi = @model.device_icon_chain( dev( "Audio/Sink", @@ -54,7 +61,8 @@ test "hdmi, webcam and bluetooth heuristics" { description="HDMI / DisplayPort", ), ) - assert_eq(hdmi[0], "video-display-symbolic") + assert_eq(hdmi[0], "moonmix-device-display-symbolic") + assert_true(hdmi.contains("video-display-symbolic")) let cam = @model.device_icon_chain( dev( "Audio/Source", @@ -62,61 +70,106 @@ test "hdmi, webcam and bluetooth heuristics" { description="EMEET SmartCam C960 Mono", ), ) - assert_eq(cam[0], "camera-web-symbolic") + assert_eq(cam[0], "moonmix-device-webcam-symbolic") + assert_true(cam.contains("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", + assert_eq(bt[0], "moonmix-device-bluetooth-symbolic") + assert_true(bt.contains("audio-headphones-symbolic")) + let usb = @model.device_icon_chain( + dev("Audio/Sink", name="alsa_output.usb-Focusrite_Scarlett.analog-stereo"), ) + assert_eq(usb[0], "moonmix-device-usb-symbolic") + assert_eq(@model.device_bus(usb_dev()), "usb") } ///| -test "device chain always ends in fallbacks" { +fn usb_dev() -> @model.Node { + dev("Audio/Sink", name="alsa_output.usb-X.analog-stereo") +} + +///| +test "device chain always ends in bundled and freedesktop 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", - ]) + assert_eq(c[0], "moonmix-device-speaker-symbolic") + assert_true(c.contains("moonmix-device-audio-symbolic")) + assert_true(c.contains("audio-speakers-symbolic")) + assert_true(c.contains("audio-card-symbolic")) + assert_eq(c[c.length() - 1], "image-missing") let s = @model.device_icon_chain(dev("Audio/Source")) - assert_eq(s[0], "audio-input-microphone-symbolic") + assert_eq(s[0], "moonmix-device-mic-symbolic") assert_eq(s[s.length() - 1], "image-missing") } ///| -test "stream chain: hints, desktop lookup, binary, fallbacks" { +test "stream chain prefers full-colour app icons before symbolic hints" { let n = @model.Node::new( 9, "Stream/Output/Audio", app_name="Firefox", app_binary="firefox", app_id="org.mozilla.firefox", - icon_hints=["firefox-esr"], + icon_hints=["applications-multimedia-symbolic", "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", + "firefox", "applications-multimedia-symbolic", "moonmix-app-fallback-symbolic", + "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", + let with_path = @model.Node::new( + 11, + "Stream/Output/Audio", + app_name="Player", + icon_hints=["/usr/share/pixmaps/player.png"], + ) + assert_eq( + @model.stream_icon_chain(with_path)[0], + "file:/usr/share/pixmaps/player.png", + ) + let bare_play = @model.Node::new(12, "Stream/Output/Audio") + assert_eq(@model.stream_icon_chain(bare_play), [ + "moonmix-app-fallback-symbolic", "application-x-executable-symbolic", "audio-x-generic-symbolic", "image-missing", ]) + let bare_rec = @model.Node::new(10, "Stream/Input/Audio") + assert_eq(@model.stream_icon_chain(bare_rec), [ + "moonmix-device-mic-symbolic", "moonmix-app-fallback-symbolic", "application-x-executable-symbolic", + "audio-x-generic-symbolic", "audio-input-microphone-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 "volume icon and chain follow volume and mute" { + assert_eq(@model.volume_icon(100.0, false), "moonmix-volume-high-symbolic") + assert_eq(@model.volume_icon(50.0, false), "moonmix-volume-medium-symbolic") + assert_eq(@model.volume_icon(10.0, false), "moonmix-volume-low-symbolic") + assert_eq(@model.volume_icon(0.0, false), "moonmix-volume-muted-symbolic") + assert_eq(@model.volume_icon(100.0, true), "moonmix-volume-muted-symbolic") + assert_eq(@model.volume_icon_chain(100.0, false), [ + "moonmix-volume-high-symbolic", "audio-volume-high-symbolic", "audio-volume-high", + ]) + assert_eq(@model.volume_icon_chain(0.0, false), [ + "moonmix-volume-muted-symbolic", "audio-volume-muted-symbolic", "audio-volume-muted", + ]) } ///| -test "tab icons" { - assert_eq(@model.Tab::Playback.icon(), "audio-speakers-symbolic") - assert_eq(@model.Tab::InputDevices.icon(), "audio-input-microphone-symbolic") +test "default button, tab icons, and symbolic check" { + assert_eq(@model.default_button_icons(), [ + "moonmix-default-symbolic", "emblem-ok-symbolic", "object-select-symbolic", + ]) + assert_eq(@model.Tab::Playback.icon(), "moonmix-tab-playback-symbolic") + assert_eq(@model.Tab::Recording.icon(), "moonmix-tab-recording-symbolic") + assert_eq(@model.Tab::OutputDevices.icon(), "moonmix-tab-output-symbolic") + assert_eq(@model.Tab::InputDevices.icon(), "moonmix-tab-input-symbolic") + assert_eq( + @model.Tab::Playback.icon_chain()[0], + "moonmix-tab-playback-symbolic", + ) + assert_true(@model.is_symbolic_icon("moonmix-device-speaker-symbolic")) + assert_true(@model.is_symbolic_icon("file:/tmp/foo-symbolic.svg")) + assert_true(@model.is_symbolic_icon("image-missing")) + assert_false(@model.is_symbolic_icon("firefox")) + assert_false(@model.is_symbolic_icon("file:/usr/share/pixmaps/vlc.png")) } diff --git a/model/pkg.generated.mbti b/model/pkg.generated.mbti index be9dcdd..65445f8 100644 --- a/model/pkg.generated.mbti +++ b/model/pkg.generated.mbti @@ -8,6 +8,8 @@ import { // Values pub const APP_LOOKUP_PREFIX : String = "app:" +pub const FILE_ICON_PREFIX : String = "file:" + pub const ICON_MISSING : String = "image-missing" pub const MAX_PERCENT : Double = 150.0 @@ -26,6 +28,8 @@ pub fn accent_text_color(Rgb, Bool) -> Rgb pub let black : Rgb +pub fn bundled_form_factor_icon(String, NodeKind) -> String + pub fn clamp_percent(Double) -> Double pub fn compare_text(String, String) -> Int32 @@ -54,6 +58,8 @@ pub fn icon_fallback_device() -> Array[String] pub fn icon_fallback_stream() -> Array[String] +pub fn is_symbolic_icon(String) -> Bool + pub fn linear_to_db(Double) -> Double? pub fn linear_to_percent(Double) -> Double @@ -80,6 +86,8 @@ pub fn symbolic(String) -> String pub fn volume_icon(Double, Bool) -> String +pub fn volume_icon_chain(Double, Bool) -> Array[String] + pub let white : Rgb pub fn window_bg(Bool) -> Rgb @@ -212,6 +220,7 @@ pub(all) enum Tab { pub fn Tab::all() -> Array[Self] pub fn Tab::empty_text(Self) -> String pub fn Tab::icon(Self) -> String +pub fn Tab::icon_chain(Self) -> Array[String] pub fn Tab::label(Self) -> String pub fn Tab::node_kind(Self) -> NodeKind diff --git a/model/view_test.mbt b/model/view_test.mbt index 8a26cee..2b91343 100644 --- a/model/view_test.mbt +++ b/model/view_test.mbt @@ -33,8 +33,8 @@ test "device rows" { assert_eq(ins.length(), 1) assert_true(ins[0].mute) assert_true(ins[0].is_default) - assert_eq(ins[0].icons[0], "audio-input-microphone-symbolic") - assert_eq(ins[0].volume_icon, "audio-volume-muted-symbolic") + assert_eq(ins[0].icons[0], "moonmix-device-mic-symbolic") + assert_eq(ins[0].volume_icon, "moonmix-volume-muted-symbolic") } ///| diff --git a/tools/moonmix-container b/tools/moonmix-container index a62a30a..ca88cbd 100755 --- a/tools/moonmix-container +++ b/tools/moonmix-container @@ -45,4 +45,65 @@ else set -- "$@" --env DBUS_SESSION_BUS_ADDRESS=unix:path=/run/moonmix/no-bus fi +# Mount only existing host icon / .desktop directories read-only so GIO and +# GtkIconTheme can resolve real full-colour host app icons without exposing $HOME. +host_root=${MOONMIX_HOST_ROOT:-} +if [ -n "${XDG_DATA_HOME:-}" ]; then + data_home=$XDG_DATA_HOME +elif [ -n "${HOME:-}" ]; then + data_home=$HOME/.local/share +else + data_home= +fi + +host_xdg_dirs= +add_xdg_prefix() { + case ":$host_xdg_dirs:" in + *":$1:"*) ;; + *) host_xdg_dirs=${host_xdg_dirs:+$host_xdg_dirs:}$1 ;; + esac +} + +if [ -n "$data_home" ]; then + if [ -d "$data_home/icons" ]; then + set -- "$@" --mount "type=bind,src=$data_home/icons,dst=/run/moonmix/host/user/icons,ro" + add_xdg_prefix /run/moonmix/host/user + fi + if [ -d "$data_home/applications" ]; then + set -- "$@" --mount "type=bind,src=$data_home/applications,dst=/run/moonmix/host/user/applications,ro" + add_xdg_prefix /run/moonmix/host/user + fi + if [ -d "$data_home/flatpak/exports/share/icons" ]; then + set -- "$@" --mount "type=bind,src=$data_home/flatpak/exports/share/icons,dst=/run/moonmix/host/flatpak-user/icons,ro" + add_xdg_prefix /run/moonmix/host/flatpak-user + fi + if [ -d "$data_home/flatpak/exports/share/applications" ]; then + set -- "$@" --mount "type=bind,src=$data_home/flatpak/exports/share/applications,dst=/run/moonmix/host/flatpak-user/applications,ro" + add_xdg_prefix /run/moonmix/host/flatpak-user + fi +fi + +if [ -d "$host_root/var/lib/flatpak/exports/share/icons" ]; then + set -- "$@" --mount "type=bind,src=$host_root/var/lib/flatpak/exports/share/icons,dst=/run/moonmix/host/flatpak-sys/icons,ro" + add_xdg_prefix /run/moonmix/host/flatpak-sys +fi +if [ -d "$host_root/var/lib/flatpak/exports/share/applications" ]; then + set -- "$@" --mount "type=bind,src=$host_root/var/lib/flatpak/exports/share/applications,dst=/run/moonmix/host/flatpak-sys/applications,ro" + add_xdg_prefix /run/moonmix/host/flatpak-sys +fi +if [ -d "$host_root/usr/share/icons" ]; then + set -- "$@" --mount "type=bind,src=$host_root/usr/share/icons,dst=/run/moonmix/host/usr/icons,ro" + add_xdg_prefix /run/moonmix/host/usr +fi +if [ -d "$host_root/usr/share/pixmaps" ]; then + set -- "$@" --mount "type=bind,src=$host_root/usr/share/pixmaps,dst=/run/moonmix/host/usr/pixmaps,ro" + add_xdg_prefix /run/moonmix/host/usr +fi +if [ -d "$host_root/usr/share/applications" ]; then + set -- "$@" --mount "type=bind,src=$host_root/usr/share/applications,dst=/run/moonmix/host/usr/applications,ro" + add_xdg_prefix /run/moonmix/host/usr +fi + +set -- "$@" --env "XDG_DATA_DIRS=${host_xdg_dirs:+$host_xdg_dirs:}/usr/local/share:/usr/share" + exec "$@" "${MOONMIX_IMAGE:-localhost/moonmix:latest}" diff --git a/tools/smoke-test.sh b/tools/smoke-test.sh index 9f75d29..db13e15 100755 --- a/tools/smoke-test.sh +++ b/tools/smoke-test.sh @@ -90,10 +90,39 @@ DATA=23040000 { printf 'RIFF'; le32 $((DATA + 36)); printf 'WAVEfmt '; le32 16 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" -{ pw-play -P '{ application.name = "Test Player" application.icon-name = "applications-multimedia-symbolic" media.name = "Smoke test tone" }' \ +# Synthetic desktop app with a full-colour icon so we verify .desktop lookup +# alongside unmapped stream fallbacks. +TEST_XDG="$XDG_RUNTIME_DIR/xdg-data" +mkdir -p "$TEST_XDG/icons/hicolor/scalable/apps" "$TEST_XDG/applications" +cat > "$TEST_XDG/icons/hicolor/scalable/apps/org.example.TestPlayer.svg" <<'SVG' + + + + + + + + + + + + + +SVG +cat > "$TEST_XDG/applications/org.example.TestPlayer.desktop" <<'DESK' +[Desktop Entry] +Type=Application +Name=Test Player +Exec=pw-play +Icon=org.example.TestPlayer +DESK + +{ pw-play -P '{ application.name = "Test Player" application.id = "org.example.TestPlayer" media.name = "Smoke test tone" }' \ "$LOGS/noise.wav"; echo "pw-play exited with $?"; } >"$LOGS/play.log" 2>&1 & PIDS="$PIDS $!" +{ pw-play -P '{ application.name = "Fallback Stream" media.name = "Unmapped app stream" }' \ + "$LOGS/noise.wav"; echo "pw-play fallback exited with $?"; } >"$LOGS/play-fallback.log" 2>&1 & PIDS="$PIDS $!" pw-cat --record --raw --rate 48000 --channels 1 --format s16 \ - -P '{ application.name = "Test Recorder" application.icon-name = "audio-input-microphone" media.name = "Mic capture" }' \ + -P '{ application.name = "Test Recorder" media.name = "Mic capture" }' \ /dev/null >"$LOGS/record.log" 2>&1 & PIDS="$PIDS $!" wait_for 'Test Player | .*-> ' || true @@ -157,7 +186,7 @@ if [ -n "$SHOTS" ] && [ -x "$GUI" ]; then if command -v gtk4-broadwayd >/dev/null; then gtk4-broadwayd :5 >/dev/null 2>&1 & PIDS="$PIDS $!" sleep 1 - gui() { MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 timeout 30 stdbuf -oL "$GUI"; } + gui() { XDG_DATA_DIRS="$TEST_XDG:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}" MOONMIX_ICON_DIR="$ROOT/data/icons" GDK_BACKEND=broadway BROADWAY_DISPLAY=:5 timeout 30 stdbuf -oL "$GUI"; } # Default look: no session bus, so no portal and the theme's own accent. DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/no-bus" MOONMIX_SCREENSHOT="$SHOTS" gui || fail=1 # System accent: a fake org.freedesktop.portal.Settings on a private diff --git a/tools/test-container.py b/tools/test-container.py index bdd2e45..f2069cb 100755 --- a/tools/test-container.py +++ b/tools/test-container.py @@ -34,13 +34,25 @@ class ContainerTests(unittest.TestCase): program = bin_dir / name program.write_text("#!/bin/sh\n" + body) program.chmod(0o755) + self.host = self.directory / "host" + self.host.mkdir() + self.empty_home = self.directory / "empty-home" + self.empty_home.mkdir() self.environment = dict(os.environ) - for key in ("PIPEWIRE_RUNTIME_DIR", "PIPEWIRE_REMOTE", "MOONMIX_IMAGE"): + for key in ( + "PIPEWIRE_RUNTIME_DIR", + "PIPEWIRE_REMOTE", + "MOONMIX_IMAGE", + "XDG_DATA_HOME", + "MOONMIX_HOST_ROOT", + ): self.environment.pop(key, None) self.environment.update( PATH=f"{bin_dir}:/usr/bin:/bin", + HOME=str(self.empty_home), XDG_RUNTIME_DIR=str(self.runtime), WAYLAND_DISPLAY="wayland-test", + MOONMIX_HOST_ROOT=str(self.host), MOONMIX_TEST_ARGUMENTS=str(self.arguments), ) @@ -200,6 +212,73 @@ class ContainerTests(unittest.TestCase): self.assertTrue(self.arguments.exists(), result.stderr) self.assertEqual(self.podman_arguments()[-1], "localhost/moonmix:latest") + def env_value(self, name): + arguments = self.podman_arguments() + prefix = f"{name}=" + for i, arg in enumerate(arguments): + if arg == "--env" and i + 1 < len(arguments) and arguments[i + 1].startswith(prefix): + return arguments[i + 1][len(prefix):] + self.fail(f"missing --env {name}=... in {arguments}") + + def test_no_host_icon_mounts_when_directories_missing(self): + self.assertEqual(self.launch().returncode, 0) + self.assertFalse(any("/run/moonmix/host" in m for m in self.mounts())) + self.assertEqual(self.env_value("XDG_DATA_DIRS"), "/usr/local/share:/usr/share") + + def test_host_icon_and_desktop_directories_are_mounted_read_only(self): + home = self.directory / "home" + secret = home / ".ssh/id_rsa" + secret.parent.mkdir(parents=True) + secret.write_text("do not mount") + data_home = self.directory / "xdg-data" + expected = [ + (data_home / "icons", "/run/moonmix/host/user/icons"), + (data_home / "applications", "/run/moonmix/host/user/applications"), + (data_home / "flatpak/exports/share/icons", "/run/moonmix/host/flatpak-user/icons"), + (data_home / "flatpak/exports/share/applications", "/run/moonmix/host/flatpak-user/applications"), + (self.host / "var/lib/flatpak/exports/share/icons", "/run/moonmix/host/flatpak-sys/icons"), + (self.host / "var/lib/flatpak/exports/share/applications", "/run/moonmix/host/flatpak-sys/applications"), + (self.host / "usr/share/icons", "/run/moonmix/host/usr/icons"), + (self.host / "usr/share/pixmaps", "/run/moonmix/host/usr/pixmaps"), + (self.host / "usr/share/applications", "/run/moonmix/host/usr/applications"), + ] + for path, _ in expected: + path.mkdir(parents=True) + self.environment.update(HOME=str(home), XDG_DATA_HOME=str(data_home)) + result = self.launch() + self.assertEqual(result.returncode, 0, result.stderr) + mounts = self.mounts() + for src, dst in expected: + self.assertIn(f"type=bind,src={src},dst={dst},ro", mounts) + self.assertFalse(any(str(home) in m for m in mounts)) + self.assertEqual( + self.env_value("XDG_DATA_DIRS"), + "/run/moonmix/host/user:/run/moonmix/host/flatpak-user:/run/moonmix/host/flatpak-sys:/run/moonmix/host/usr:/usr/local/share:/usr/share", + ) + + def test_partial_host_icon_mounts_and_home_fallback(self): + home = self.directory / "home-fallback" + user_icons = home / ".local/share/icons" + sys_pixmaps = self.host / "usr/share/pixmaps" + sys_apps = self.host / "usr/share/applications" + for path in (user_icons, sys_pixmaps, sys_apps): + path.mkdir(parents=True) + self.environment["HOME"] = str(home) + result = self.launch() + self.assertEqual(result.returncode, 0, result.stderr) + mounts = self.mounts() + self.assertEqual(mounts, [ + f"type=bind,src={self.runtime}/wayland-test,dst=/run/moonmix/wayland-0,ro", + f"type=bind,src={self.runtime}/pipewire-0,dst=/run/moonmix/pipewire-0,ro", + f"type=bind,src={user_icons},dst=/run/moonmix/host/user/icons,ro", + f"type=bind,src={sys_pixmaps},dst=/run/moonmix/host/usr/pixmaps,ro", + f"type=bind,src={sys_apps},dst=/run/moonmix/host/usr/applications,ro", + ]) + self.assertEqual( + self.env_value("XDG_DATA_DIRS"), + "/run/moonmix/host/user:/run/moonmix/host/usr:/usr/local/share:/usr/share", + ) + if __name__ == "__main__": unittest.main()