diff --git a/applets/cosmic-applet-audio/src/app.rs b/applets/cosmic-applet-audio/src/app.rs index e00f72ab..a9c29304 100644 --- a/applets/cosmic-applet-audio/src/app.rs +++ b/applets/cosmic-applet-audio/src/app.rs @@ -1,6 +1,6 @@ use gtk4::{ - prelude::*, Box as GtkBox, Image, ListBox, Orientation, PositionType, RevealerTransitionType, - Scale, Separator, Stack, Window, + prelude::*, Box as GtkBox, Image, Label, ListBox, Orientation, PositionType, + RevealerTransitionType, Scale, Separator, Stack, Window, }; use libcosmic_widgets::LabeledItem; use pulsectl::controllers::types::DeviceInfo; @@ -14,8 +14,32 @@ pub struct App { outputs: Vec, } +impl App { + pub fn get_default_input_name(&self) -> &str { + match &self.default_input { + Some(input) => match &input.name { + Some(name) => name.as_str(), + None => "Input Device", + }, + None => "No Input Device", + } + } + + pub fn get_default_output_name(&self) -> &str { + match &self.default_output { + Some(output) => match &output.name { + Some(name) => name.as_str(), + None => "Output Device", + }, + None => "No Output Device", + } + } +} + pub struct Widgets { output_stack: Stack, + current_input: Label, + current_output: Label, inputs: ListBox, outputs: ListBox, } @@ -49,8 +73,9 @@ impl Component for App { input: &Sender, _output: &Sender, ) -> ComponentParts { + let model = App::default(); view! { - GtkBox { + container = GtkBox { set_orientation: Orientation::Vertical, set_spacing: 24, append: output_box = &GtkBox { @@ -86,16 +111,39 @@ impl Component for App { }, append: output_stack = &Stack { add_child: current_output = &Label { - set_text: watch! { model.name.unwrap_or_else(|| "Output Device".into()) } + set_text: watch! { model.get_default_output_name() } }, - add_child: list_outputs = &GtkBox { - append: outputs = &ListBox { - set_selection_mode: gtk4::SelectionMode::None, - set_activate_on_single_click: true, - }, + add_child: outputs = &ListBox { + set_selection_mode: gtk4::SelectionMode::None, + set_activate_on_single_click: true + } + }, + append: _sep = &Separator { + set_orientation: Orientation::Horizontal, + }, + append: input_stack = &Stack { + add_child: current_input = &Label { + set_text: watch! { model.get_default_input_name() } + }, + add_child: inputs = &ListBox { + set_selection_mode: gtk4::SelectionMode::None, + set_activate_on_single_click: true } } } } + output_stack.set_visible_child(¤t_output); + input_stack.set_visible_child(¤t_input); + root.set_child(Some(&container)); + ComponentParts { + model, + widgets: Widgets { + output_stack, + inputs, + outputs, + current_input, + current_output, + }, + } } } diff --git a/applets/cosmic-applet-audio/src/main.rs b/applets/cosmic-applet-audio/src/main.rs index 9bd49a9a..40e0f4db 100644 --- a/applets/cosmic-applet-audio/src/main.rs +++ b/applets/cosmic-applet-audio/src/main.rs @@ -6,10 +6,11 @@ extern crate relm4; mod app; use once_cell::sync::Lazy; +use relm4::RelmApp; use tokio::runtime::Runtime; static RT: Lazy = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime")); fn main() { - println!("Hello, world!"); + RelmApp::::new("com.system76.cosmic.applets.audio").run(()); }