Use libcosmic-applet in audio, notifications

This commit is contained in:
Ian Douglas Scott 2022-07-01 21:55:57 -07:00
parent f56b160635
commit 68986d773c
7 changed files with 87 additions and 148 deletions

2
Cargo.lock generated
View file

@ -338,6 +338,7 @@ dependencies = [
"futures", "futures",
"futures-util", "futures-util",
"gtk4", "gtk4",
"libcosmic-applet",
"libcosmic-widgets", "libcosmic-widgets",
"libpulse-binding", "libpulse-binding",
"libpulse-glib-binding", "libpulse-glib-binding",
@ -398,6 +399,7 @@ dependencies = [
"cosmic-panel-config", "cosmic-panel-config",
"futures", "futures",
"gtk4", "gtk4",
"libcosmic-applet",
"once_cell", "once_cell",
"serde", "serde",
"zbus", "zbus",

View file

@ -7,6 +7,7 @@ license = "GPL-3.0-or-later"
[dependencies] [dependencies]
futures = "0.3.21" futures = "0.3.21"
futures-util = "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" } libcosmic-widgets = { git = "https://github.com/pop-os/libcosmic", branch = "relm4-next" }
libpulse-binding = "2.26.0" libpulse-binding = "2.26.0"
libpulse-glib-binding = "2.25.0" libpulse-glib-binding = "2.25.0"

View file

@ -76,22 +76,13 @@ fn app(application: &Application) {
}); });
pa.connect().unwrap(); // XXX unwrap pa.connect().unwrap(); // XXX unwrap
view! { view! {
window = ApplicationWindow { window = libcosmic_applet::Applet {
set_application: Some(application), set_application: Some(application),
set_title: Some("COSMIC Network Applet"), set_title: Some("COSMIC Network Applet"),
set_decorated: false,
set_resizable: false,
set_width_request: 1,
set_height_request: 1,
#[wrap(Some)]
set_child = &gtk4::MenuButton {
// TODO: adjust based on volume, mute // TODO: adjust based on volume, mute
set_icon_name: "multimedia-volume-control-symbolic", set_button_icon_name: "multimedia-volume-control-symbolic",
#[wrap(Some)] #[wrap(Some)]
set_popover = &gtk4::Popover { set_popover_child: window_box = &GtkBox {
#[wrap(Some)]
set_child: window_box = &GtkBox {
set_orientation: Orientation::Vertical, set_orientation: Orientation::Vertical,
set_spacing: 24, set_spacing: 24,
append: output_box = &GtkBox { append: output_box = &GtkBox {
@ -173,8 +164,6 @@ fn app(application: &Application) {
} }
} }
} }
}
}
glib::MainContext::default().spawn_local( glib::MainContext::default().spawn_local(
clone!(@weak inputs, @weak current_input, @weak input_volume, @strong pa => async move { clone!(@weak inputs, @weak current_input, @weak input_volume, @strong pa => async move {

View file

@ -8,6 +8,7 @@ license = "GPL-3.0-or-later"
cascade = "1" cascade = "1"
futures = "0.3" futures = "0.3"
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" } gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs" }
libcosmic-applet = { path = "../../libcosmic-applet" }
once_cell = "1.12" once_cell = "1.12"
serde = "1" serde = "1"
zbus = "2.0.1" zbus = "2.0.1"

View file

@ -17,43 +17,21 @@ fn main() {
// XXX Implement DBus service somewhere other than applet? // XXX Implement DBus service somewhere other than applet?
let notifications = Notifications::new(); let notifications = Notifications::new();
let provider = gtk4::CssProvider::new();
provider.load_from_data(include_bytes!("style.css"));
gtk4::StyleContext::add_provider_for_display(
&gtk4::gdk::Display::default().expect("Could not connect to a display."),
&provider,
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
let notification_list = NotificationList::new(&notifications); let notification_list = NotificationList::new(&notifications);
let popover = cascade! { let window = cascade! {
gtk4::Popover::new(); libcosmic_applet::Applet::new();
..set_child(Some(&notification_list)); ..set_button_icon_name("user-invisible-symbolic"); // TODO
}; ..set_popover_child(Some(&notification_list));
..show();
let menu_button = cascade! {
gtk4::MenuButton::new();
..set_icon_name("user-invisible-symbolic"); // TODO
..set_popover(Some(&popover));
}; };
// XXX show in correct place // XXX show in correct place
cascade! { cascade! {
NotificationPopover::new(&notifications); NotificationPopover::new(&notifications);
..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); let main_loop = glib::MainLoop::new(None, false);
main_loop.run(); main_loop.run();
} }

View file

@ -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;
}

View file

@ -9,6 +9,7 @@ use deref_cell::DerefCell;
// TODO gir bindings // TODO gir bindings
// TODO orientation, etc. // TODO orientation, etc.
// TODO make image size dependent on CosmicPanelConfig? // TODO make image size dependent on CosmicPanelConfig?
// TODO way to have multiple applets with this style, for system tray.
static STYLE: &str = " static STYLE: &str = "
window.cosmic_applet_window { window.cosmic_applet_window {