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-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",

View file

@ -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"

View file

@ -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 = &gtk4::MenuButton {
// TODO: adjust based on volume, mute
set_icon_name: "multimedia-volume-control-symbolic",
#[wrap(Some)]
set_popover = &gtk4::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,
}
}
}

View file

@ -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"

View file

@ -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(
&gtk4::gdk::Display::default().expect("Could not connect to a display."),
&provider,
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
);
let notification_list = NotificationList::new(&notifications);
let popover = cascade! {
gtk4::Popover::new();
..set_child(Some(&notification_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(&notification_list));
..show();
};
// XXX show in correct place
cascade! {
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);
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 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 {