From 68986d773c4704e0b8a40c55cb0153c3c7d1e855 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 1 Jul 2022 21:55:57 -0700 Subject: [PATCH] Use libcosmic-applet in audio, notifications --- Cargo.lock | 2 + applets/cosmic-applet-audio/Cargo.toml | 1 + applets/cosmic-applet-audio/src/main.rs | 163 ++++++++---------- .../cosmic-applet-notifications/Cargo.toml | 1 + .../cosmic-applet-notifications/src/main.rs | 34 +--- .../cosmic-applet-notifications/src/style.css | 33 ---- libcosmic-applet/src/lib.rs | 1 + 7 files changed, 87 insertions(+), 148 deletions(-) delete mode 100644 applets/cosmic-applet-notifications/src/style.css diff --git a/Cargo.lock b/Cargo.lock index 09440f00..1beb7a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,6 +338,7 @@ dependencies = [ "futures", "futures-util", "gtk4", + "libcosmic-applet", "libcosmic-widgets", "libpulse-binding", "libpulse-glib-binding", @@ -398,6 +399,7 @@ dependencies = [ "cosmic-panel-config", "futures", "gtk4", + "libcosmic-applet", "once_cell", "serde", "zbus", diff --git a/applets/cosmic-applet-audio/Cargo.toml b/applets/cosmic-applet-audio/Cargo.toml index acdda3e1..700b69ab 100644 --- a/applets/cosmic-applet-audio/Cargo.toml +++ b/applets/cosmic-applet-audio/Cargo.toml @@ -7,6 +7,7 @@ license = "GPL-3.0-or-later" [dependencies] futures = "0.3.21" futures-util = "0.3.21" +libcosmic-applet = { path = "../../libcosmic-applet" } libcosmic-widgets = { git = "https://github.com/pop-os/libcosmic", branch = "relm4-next" } libpulse-binding = "2.26.0" libpulse-glib-binding = "2.25.0" diff --git a/applets/cosmic-applet-audio/src/main.rs b/applets/cosmic-applet-audio/src/main.rs index 19c368d7..938e1956 100644 --- a/applets/cosmic-applet-audio/src/main.rs +++ b/applets/cosmic-applet-audio/src/main.rs @@ -76,101 +76,90 @@ fn app(application: &Application) { }); pa.connect().unwrap(); // XXX unwrap view! { - window = ApplicationWindow { + window = libcosmic_applet::Applet { set_application: Some(application), set_title: Some("COSMIC Network Applet"), - set_decorated: false, - set_resizable: false, - set_width_request: 1, - set_height_request: 1, - + // TODO: adjust based on volume, mute + set_button_icon_name: "multimedia-volume-control-symbolic", #[wrap(Some)] - 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_popover_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) }, - 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: 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: _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_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 { 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, } } } diff --git a/applets/cosmic-applet-notifications/Cargo.toml b/applets/cosmic-applet-notifications/Cargo.toml index b66ab210..bf00089c 100644 --- a/applets/cosmic-applet-notifications/Cargo.toml +++ b/applets/cosmic-applet-notifications/Cargo.toml @@ -8,6 +8,7 @@ license = "GPL-3.0-or-later" cascade = "1" futures = "0.3" gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" } +libcosmic-applet = { path = "../../libcosmic-applet" } once_cell = "1.12" serde = "1" zbus = "2.0.1" diff --git a/applets/cosmic-applet-notifications/src/main.rs b/applets/cosmic-applet-notifications/src/main.rs index 7a131456..e9dc63d7 100644 --- a/applets/cosmic-applet-notifications/src/main.rs +++ b/applets/cosmic-applet-notifications/src/main.rs @@ -17,43 +17,21 @@ fn main() { // XXX Implement DBus service somewhere other than applet? let notifications = Notifications::new(); - let provider = gtk4::CssProvider::new(); - provider.load_from_data(include_bytes!("style.css")); - gtk4::StyleContext::add_provider_for_display( - >k4::gdk::Display::default().expect("Could not connect to a display."), - &provider, - gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); - let notification_list = NotificationList::new(¬ifications); - let popover = cascade! { - gtk4::Popover::new(); - ..set_child(Some(¬ification_list)); - }; - - let menu_button = cascade! { - gtk4::MenuButton::new(); - ..set_icon_name("user-invisible-symbolic"); // TODO - ..set_popover(Some(&popover)); + let window = cascade! { + libcosmic_applet::Applet::new(); + ..set_button_icon_name("user-invisible-symbolic"); // TODO + ..set_popover_child(Some(¬ification_list)); + ..show(); }; // XXX show in correct place cascade! { NotificationPopover::new(¬ifications); - ..set_parent(&menu_button); + ..set_parent(&window.child().unwrap()); // XXX better way? }; - gtk4::Window::builder() - .decorated(false) - .child(&menu_button) - .resizable(false) - .width_request(1) - .height_request(1) - .css_classes(vec!["root_window".to_string()]) - .build() - .show(); - let main_loop = glib::MainLoop::new(None, false); main_loop.run(); } diff --git a/applets/cosmic-applet-notifications/src/style.css b/applets/cosmic-applet-notifications/src/style.css deleted file mode 100644 index 8a91f3eb..00000000 --- a/applets/cosmic-applet-notifications/src/style.css +++ /dev/null @@ -1,33 +0,0 @@ -.loading-overlay { - background-color: #2f2f2f; - opacity: 0.85; -} - -image.panel_icon { - padding-left: 0px; - padding-right: 0px; - padding-top: 0px; - padding-bottom: 0px; -} - -button.panel_icon { - border-radius: 12px; - transition: 100ms; - padding: 4px; - border-color: transparent; - background: transparent; - outline-color: transparent; -} - -button.panel_icon:hover { - border-radius: 12px; - transition: 100ms; - padding: 4px; - border-color: rgba(255, 255, 255, 0.1); - outline-color: rgba(255, 255, 255, 0.1); - background: rgba(255, 255, 255, 0.1); -} - -window.root_window { - background: transparent; -} \ No newline at end of file diff --git a/libcosmic-applet/src/lib.rs b/libcosmic-applet/src/lib.rs index 15e996c5..55229d64 100644 --- a/libcosmic-applet/src/lib.rs +++ b/libcosmic-applet/src/lib.rs @@ -9,6 +9,7 @@ use deref_cell::DerefCell; // TODO gir bindings // TODO orientation, etc. // TODO make image size dependent on CosmicPanelConfig? +// TODO way to have multiple applets with this style, for system tray. static STYLE: &str = " window.cosmic_applet_window {