From ee142903bba69498e35eae9ab637374199ca3986 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Tue, 5 Jul 2022 16:52:04 -0700 Subject: [PATCH] Use `libcosmic-applet` in time applet Need to get button height right. --- Cargo.lock | 6 +--- applets/cosmic-applet-graphics/Cargo.toml | 1 - applets/cosmic-applet-network/Cargo.toml | 1 - .../cosmic-applet-notifications/Cargo.toml | 1 - applets/cosmic-applet-status-area/Cargo.toml | 1 - applets/cosmic-applet-time/Cargo.toml | 2 +- applets/cosmic-applet-time/src/main.rs | 25 ++++---------- applets/cosmic-applet-time/src/style.css | 33 ------------------- applets/cosmic-applet-time/src/time_button.rs | 20 ++++------- libcosmic-applet/src/button.rs | 9 +++++ 10 files changed, 24 insertions(+), 75 deletions(-) delete mode 100644 applets/cosmic-applet-time/src/style.css diff --git a/Cargo.lock b/Cargo.lock index 4c178b3e..d2e44ee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/applets/cosmic-applet-graphics/Cargo.toml b/applets/cosmic-applet-graphics/Cargo.toml index fd29821c..9fa48c03 100644 --- a/applets/cosmic-applet-graphics/Cargo.toml +++ b/applets/cosmic-applet-graphics/Cargo.toml @@ -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"]} diff --git a/applets/cosmic-applet-network/Cargo.toml b/applets/cosmic-applet-network/Cargo.toml index 85ab9019..f7b83b82 100644 --- a/applets/cosmic-applet-network/Cargo.toml +++ b/applets/cosmic-applet-network/Cargo.toml @@ -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"]} diff --git a/applets/cosmic-applet-notifications/Cargo.toml b/applets/cosmic-applet-notifications/Cargo.toml index bc22b597..a6c752a4 100644 --- a/applets/cosmic-applet-notifications/Cargo.toml +++ b/applets/cosmic-applet-notifications/Cargo.toml @@ -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"]} diff --git a/applets/cosmic-applet-status-area/Cargo.toml b/applets/cosmic-applet-status-area/Cargo.toml index b8e1e03c..e61daf1a 100644 --- a/applets/cosmic-applet-status-area/Cargo.toml +++ b/applets/cosmic-applet-status-area/Cargo.toml @@ -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"]} diff --git a/applets/cosmic-applet-time/Cargo.toml b/applets/cosmic-applet-time/Cargo.toml index 6880dc8e..3f869646 100644 --- a/applets/cosmic-applet-time/Cargo.toml +++ b/applets/cosmic-applet-time/Cargo.toml @@ -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"]} diff --git a/applets/cosmic-applet-time/src/main.rs b/applets/cosmic-applet-time/src/main.rs index 6233b522..bbb29413 100644 --- a/applets/cosmic-applet-time/src/main.rs +++ b/applets/cosmic-applet-time/src/main.rs @@ -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( - >k4::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(); diff --git a/applets/cosmic-applet-time/src/style.css b/applets/cosmic-applet-time/src/style.css deleted file mode 100644 index 8a91f3eb..00000000 --- a/applets/cosmic-applet-time/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/applets/cosmic-applet-time/src/time_button.rs b/applets/cosmic-applet-time/src/time_button.rs index c05369b2..d2bcb16d 100644 --- a/applets/cosmic-applet-time/src/time_button.rs +++ b/applets/cosmic-applet-time/src/time_button.rs @@ -11,7 +11,7 @@ use crate::deref_cell::DerefCell; #[derive(Default)] pub struct TimeButtonInner { calendar: DerefCell, - button: DerefCell, + button: DerefCell, label: DerefCell, } @@ -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); diff --git a/libcosmic-applet/src/button.rs b/libcosmic-applet/src/button.rs index d434df3c..32c4299f 100644 --- a/libcosmic-applet/src/button.rs +++ b/libcosmic-applet/src/button.rs @@ -131,4 +131,13 @@ impl AppletButton { pub fn popup(&self) { self.inner().popover.popup(); } + + // XXX better API? Actual signal + pub fn connect_activate(&self, f: F) -> glib::SignalHandlerId { + self.inner() + .menu_button + .connect_activate(glib::clone!(@weak self as _self => move |_| { + f(&_self) + })) + } }