// 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:") 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" } }