From ab8131f5e6a5e9b9af4e33d771aadf2b1d1214b2 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 1 Jul 2022 21:13:42 -0700 Subject: [PATCH] applet: Place in a popover with a button --- .../com.system76.CosmicAppletAudio.desktop | 4 +- applets/cosmic-applet-audio/src/main.rs | 161 ++++++++++-------- 2 files changed, 88 insertions(+), 77 deletions(-) diff --git a/applets/cosmic-applet-audio/data/com.system76.CosmicAppletAudio.desktop b/applets/cosmic-applet-audio/data/com.system76.CosmicAppletAudio.desktop index aca6cf6d..ea136a38 100644 --- a/applets/cosmic-applet-audio/data/com.system76.CosmicAppletAudio.desktop +++ b/applets/cosmic-applet-audio/data/com.system76.CosmicAppletAudio.desktop @@ -2,11 +2,11 @@ Name=Cosmic Dock App List Comment=Write a GTK + Rust application Type=Application -Exec=cosmic-dock-app-list +Exec=cosmic-applet-audio Terminal=false Categories=GNOME;GTK; Keywords=Gnome;GTK; # Translators: Do NOT translate or transliterate this text (this is an icon file name)! -Icon=com.system76.CosmicDockAppList.svg +Icon=com.system76.CosmicAppletAudio.svg StartupNotify=true NoDisplay=true diff --git a/applets/cosmic-applet-audio/src/main.rs b/applets/cosmic-applet-audio/src/main.rs index 4c4f7fe0..19c368d7 100644 --- a/applets/cosmic-applet-audio/src/main.rs +++ b/applets/cosmic-applet-audio/src/main.rs @@ -79,92 +79,103 @@ fn app(application: &Application) { window = ApplicationWindow { set_application: Some(application), set_title: Some("COSMIC Network Applet"), - set_default_width: 400, - set_default_height: 300, + set_decorated: false, + set_resizable: false, + set_width_request: 1, + set_height_request: 1, #[wrap(Some)] - set_child: window_box = &GtkBox { - set_orientation: Orientation::Vertical, - set_spacing: 24, - append: output_box = &GtkBox { - set_orientation: Orientation::Horizontal, - set_spacing: 16, - append: output_icon = &Image { - set_icon_name: Some("audio-speakers-symbolic"), - }, - append: output_volume = &Scale::with_range(Orientation::Horizontal, 0., 100., 1.) { - set_format_value_func: |_, value| { - format!("{:.0}%", value) + set_child = >k4::MenuButton { + // TODO: adjust based on volume, mute + set_icon_name: "multimedia-volume-control-symbolic", + #[wrap(Some)] + set_popover = >k4::Popover { + #[wrap(Some)] + set_child: window_box = &GtkBox { + set_orientation: Orientation::Vertical, + set_spacing: 24, + append: output_box = &GtkBox { + set_orientation: Orientation::Horizontal, + set_spacing: 16, + append: output_icon = &Image { + set_icon_name: Some("audio-speakers-symbolic"), + }, + append: output_volume = &Scale::with_range(Orientation::Horizontal, 0., 100., 1.) { + set_format_value_func: |_, value| { + format!("{:.0}%", value) + }, + set_value_pos: PositionType::Right, + set_hexpand: true + } }, - set_value_pos: PositionType::Right, - set_hexpand: true - } - }, - append: input_box = &GtkBox { - set_orientation: Orientation::Horizontal, - set_spacing: 16, - append: input_icon = &Image { - set_icon_name: Some("audio-input-microphone-symbolic"), - }, - append: input_volume = &Scale::with_range(Orientation::Horizontal, 0., 100., 1.) { - set_format_value_func: |_, value| { - format!("{:.0}%", value) + append: input_box = &GtkBox { + set_orientation: Orientation::Horizontal, + set_spacing: 16, + append: input_icon = &Image { + set_icon_name: Some("audio-input-microphone-symbolic"), + }, + append: input_volume = &Scale::with_range(Orientation::Horizontal, 0., 100., 1.) { + set_format_value_func: |_, value| { + format!("{:.0}%", value) + }, + set_value_pos: PositionType::Right, + set_hexpand: true + } }, - set_value_pos: PositionType::Right, - set_hexpand: true - } - }, - append: _sep = &Separator { - set_orientation: Orientation::Horizontal, - }, - append: output_list_box = &GtkBox { - set_orientation: Orientation::Vertical, - append: current_output_button = &Button { - #[wrap(Some)] - set_child: current_output = &Label {}, - connect_clicked[outputs_revealer] => move |_| { - outputs_revealer.set_reveal_child(!outputs_revealer.reveals_child()); - } - }, - append: outputs_revealer = &Revealer { - set_transition_type: RevealerTransitionType::SlideDown, - #[wrap(Some)] - set_child: outputs = &ListBox { + append: _sep = &Separator { + set_orientation: Orientation::Horizontal, + }, + append: output_list_box = &GtkBox { + set_orientation: Orientation::Vertical, + append: current_output_button = &Button { + #[wrap(Some)] + set_child: current_output = &Label {}, + connect_clicked[outputs_revealer] => move |_| { + outputs_revealer.set_reveal_child(!outputs_revealer.reveals_child()); + } + }, + append: outputs_revealer = &Revealer { + set_transition_type: RevealerTransitionType::SlideDown, + #[wrap(Some)] + set_child: outputs = &ListBox { + set_selection_mode: SelectionMode::None, + set_activate_on_single_click: true + } + } + }, + append: _sep = &Separator { + set_orientation: Orientation::Horizontal, + }, + append: input_list_box = &GtkBox { + set_orientation: Orientation::Vertical, + append: current_input_button = &Button { + #[wrap(Some)] + set_child: current_input = &Label {}, + connect_clicked[inputs_revealer] => move |_| { + inputs_revealer.set_reveal_child(!inputs_revealer.reveals_child()); + } + }, + append: inputs_revealer = &Revealer { + set_transition_type: RevealerTransitionType::SlideDown, + #[wrap(Some)] + set_child: inputs = &ListBox { + set_selection_mode: SelectionMode::None, + set_activate_on_single_click: true + } + } + }, + append: _sep = &Separator { + set_orientation: Orientation::Horizontal, + }, + append: playing_apps = &ListBox { set_selection_mode: SelectionMode::None, - set_activate_on_single_click: true } } - }, - append: _sep = &Separator { - set_orientation: Orientation::Horizontal, - }, - append: input_list_box = &GtkBox { - set_orientation: Orientation::Vertical, - append: current_input_button = &Button { - #[wrap(Some)] - set_child: current_input = &Label {}, - connect_clicked[inputs_revealer] => move |_| { - inputs_revealer.set_reveal_child(!inputs_revealer.reveals_child()); - } - }, - append: inputs_revealer = &Revealer { - set_transition_type: RevealerTransitionType::SlideDown, - #[wrap(Some)] - set_child: inputs = &ListBox { - set_selection_mode: SelectionMode::None, - set_activate_on_single_click: true - } - } - }, - append: _sep = &Separator { - set_orientation: Orientation::Horizontal, - }, - append: playing_apps = &ListBox { - set_selection_mode: SelectionMode::None, } } } } + glib::MainContext::default().spawn_local( clone!(@weak inputs, @weak current_input, @weak input_volume, @strong pa => async move { while let Some(()) = refresh_input_rx.next().await {