Use libcosmic-applet in time applet

Need to get button height right.
This commit is contained in:
Ian Douglas Scott 2022-07-05 16:52:04 -07:00
parent 765e3af815
commit ee142903bb
10 changed files with 24 additions and 75 deletions

6
Cargo.lock generated
View file

@ -366,7 +366,6 @@ dependencies = [
name = "cosmic-applet-graphics"
version = "0.1.0"
dependencies = [
"cosmic-panel-config",
"gtk4",
"libcosmic-applet",
"once_cell",
@ -380,7 +379,6 @@ name = "cosmic-applet-network"
version = "0.1.0"
dependencies = [
"cosmic-dbus-networkmanager",
"cosmic-panel-config",
"futures-util",
"gtk4",
"itertools",
@ -398,7 +396,6 @@ name = "cosmic-applet-notifications"
version = "0.1.0"
dependencies = [
"cascade",
"cosmic-panel-config",
"futures",
"gtk4",
"libcosmic-applet",
@ -430,7 +427,6 @@ name = "cosmic-applet-status-area"
version = "0.1.0"
dependencies = [
"cascade",
"cosmic-panel-config",
"futures",
"gtk4",
"libcosmic-applet",
@ -447,9 +443,9 @@ version = "0.1.0"
dependencies = [
"cascade",
"chrono",
"cosmic-panel-config",
"futures",
"gtk4",
"libcosmic-applet",
"once_cell",
"serde",
"zbus",

View file

@ -12,4 +12,3 @@ once_cell = "1.9.0"
relm4-macros = { git = "https://github.com/Relm4/Relm4.git", branch = "next" }
tokio = { version = "1.16.1", features = ["full"] }
zbus = "2.1.1"
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -16,4 +16,3 @@ tokio = { version = "1.15.0", features = ["full"] }
zbus = "2.0.1"
libcosmic-applet = { path = "../../libcosmic-applet" }
libcosmic-widgets = { git = "https://github.com/pop-os/libcosmic", branch = "relm4-next" }
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -15,4 +15,3 @@ serde = "1"
zbus = "2.0.1"
zbus_names = "2"
zvariant = "3"
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -14,4 +14,3 @@ serde = "1"
zbus = "2.0.1"
zbus_names = "2"
zvariant = "3"
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -9,9 +9,9 @@ cascade = "1"
chrono = "0.4"
futures = "0.3"
gtk4 = { git = "https://github.com/gtk-rs/gtk4-rs", features = [ "v4_6" ] }
libcosmic-applet = { path = "../../libcosmic-applet" }
once_cell = "1.12"
serde = "1"
zbus = "2.0.1"
zbus_names = "2"
zvariant = "3"
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -1,3 +1,4 @@
use cascade::cascade;
use gtk4::{glib, prelude::*};
mod deref_cell;
@ -7,25 +8,11 @@ use time_button::TimeButton;
fn main() {
gtk4::init().unwrap();
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 time_button = TimeButton::new();
gtk4::Window::builder()
.decorated(false)
.child(&time_button)
.resizable(false)
.width_request(1)
.height_request(1)
.css_classes(vec!["root_window".to_string()])
.build()
.show();
cascade! {
libcosmic_applet::AppletWindow::new();
..set_child(Some(&TimeButton::new()));
..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

@ -11,7 +11,7 @@ use crate::deref_cell::DerefCell;
#[derive(Default)]
pub struct TimeButtonInner {
calendar: DerefCell<gtk4::Calendar>,
button: DerefCell<gtk4::MenuButton>,
button: DerefCell<libcosmic_applet::AppletButton>,
label: DerefCell<gtk4::Label>,
}
@ -40,21 +40,15 @@ impl ObjectImpl for TimeButtonInner {
}));
};
let popover = cascade! {
gtk4::Popover::new();
..set_child(Some(&cascade! {
let button = cascade! {
libcosmic_applet::AppletButton::new();
..set_parent(obj);
..connect_activate(clone!(@strong obj => move |_| obj.opening()));
..set_button_child(Some(&label));
..set_popover_child(Some(&cascade! {
gtk4::Box::new(gtk4::Orientation::Horizontal, 0);
..append(&calendar);
}));
..connect_show(clone!(@strong obj => move |_| obj.opening()));
};
let button = cascade! {
gtk4::MenuButton::new();
..set_child(Some(&label));
..set_has_frame(false);
..set_parent(obj);
..set_popover(Some(&popover));
};
self.calendar.set(calendar);

View file

@ -131,4 +131,13 @@ impl AppletButton {
pub fn popup(&self) {
self.inner().popover.popup();
}
// XXX better API? Actual signal
pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
self.inner()
.menu_button
.connect_activate(glib::clone!(@weak self as _self => move |_| {
f(&_self)
}))
}
}