diff --git a/applets/cosmic-applet-battery/Cargo.lock b/applets/cosmic-applet-battery/Cargo.lock index 4fdd0cc2..bf5a4e6e 100644 --- a/applets/cosmic-applet-battery/Cargo.lock +++ b/applets/cosmic-applet-battery/Cargo.lock @@ -470,7 +470,7 @@ dependencies = [ [[package]] name = "cosmic-panel-config" version = "0.1.0" -source = "git+https://github.com/pop-os/cosmic-panel#a452fc323b574c28aef832951edd413a1d87bc3d" +source = "git+https://github.com/pop-os/cosmic-panel#35d61a3a617b2ef552931645ec35c545a3a688f6" dependencies = [ "anyhow", "ron", @@ -1730,7 +1730,7 @@ checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" [[package]] name = "libcosmic" version = "0.1.0" -source = "git+https://github.com/pop-os/libcosmic/?branch=sctk-cosmic-design-system#0f857b18ea0987a192b99a2dc34d29b9e41e5bf8" +source = "git+https://github.com/pop-os/libcosmic/?branch=fix/applets#0760008f54428ef44968df8db465dfceb7ee837d" dependencies = [ "apply", "cosmic-panel-config", @@ -2946,13 +2946,14 @@ dependencies = [ [[package]] name = "tokio" -version = "1.22.0" +version = "1.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" +checksum = "eab6d665857cc6ca78d6e80303a02cea7a7851e85dfbd77cbdc09bd129f1ef46" dependencies = [ "autocfg", "num_cpus", "pin-project-lite", + "windows-sys 0.42.0", ] [[package]] diff --git a/applets/cosmic-applet-battery/Cargo.toml b/applets/cosmic-applet-battery/Cargo.toml index 11262d6e..b1d56e55 100644 --- a/applets/cosmic-applet-battery/Cargo.toml +++ b/applets/cosmic-applet-battery/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] once_cell = "1.16.0" -libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "sctk-cosmic-design-system", default-features = false, features = ["wayland", "applet"] } +libcosmic = { git = "https://github.com/pop-os/libcosmic/", branch = "fix/applets", default-features = false, features = ["wayland", "applet"] } cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", default-features = false } iced_sctk = { git = "https://github.com/pop-os/iced-sctk" } sctk = { package = "smithay-client-toolkit", git = "https://github.com/Smithay/client-toolkit", version = "0.16" } diff --git a/applets/cosmic-applet-battery/src/app.rs b/applets/cosmic-applet-battery/src/app.rs index b423cd11..14d34c58 100644 --- a/applets/cosmic-applet-battery/src/app.rs +++ b/applets/cosmic-applet-battery/src/app.rs @@ -7,19 +7,18 @@ use crate::upower_device::{device_subscription, DeviceDbusEvent}; use crate::upower_kbdbacklight::{ kbd_backlight_subscription, KeyboardBacklightRequest, KeyboardBacklightUpdate, }; -use cosmic::applet::{get_popup_settings, icon_button, popup_container}; +use cosmic::applet::CosmicAppletHelper; use cosmic::iced::alignment::Horizontal; use cosmic::iced::{ executor, - widget::{button, column, row, text}, + widget::{button, column, row, text, slider}, window, Alignment, Application, Command, Length, Subscription, }; use cosmic::iced_native::window::Settings; use cosmic::iced_style::application::{self, Appearance}; use cosmic::iced_style::svg; -use cosmic::separator; -use cosmic::theme::{self, Button, Svg}; -use cosmic::widget::{icon, widget}; +use cosmic::theme::{self, Svg}; +use cosmic::widget::{icon, toggler, horizontal_rule}; use cosmic::{iced_style, settings, Element, Theme}; use cosmic_panel_config::{PanelAnchor, PanelSize}; use iced_sctk::application::SurfaceIdWrapper; @@ -82,9 +81,9 @@ struct CosmicBatteryApplet { screen_brightness: f64, popup: Option, id_ctr: u32, - anchor: PanelAnchor, screen_sender: Option>, kbd_sender: Option>, + applet_helper: CosmicAppletHelper, } #[derive(Debug, Clone)] @@ -117,13 +116,6 @@ impl Application for CosmicBatteryApplet { ( CosmicBatteryApplet { icon_name: "battery-symbolic".to_string(), - anchor: std::env::var("COSMIC_PANEL_ANCHOR") - .ok() - .map(|size| match size.parse::() { - Ok(p) => p, - Err(_) => PanelAnchor::Top, - }) - .unwrap_or(PanelAnchor::Top), ..Default::default() }, Command::none(), @@ -172,8 +164,8 @@ impl Application for CosmicBatteryApplet { let new_id = window::Id::new(self.id_ctr); self.popup.replace(new_id); - let mut popup_settings = - get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None); + let popup_settings = + self.applet_helper.get_popup_settings(window::Id::new(0), new_id, (400, 240), None, None); return get_popup(popup_settings); } } @@ -209,14 +201,10 @@ impl Application for CosmicBatteryApplet { fn view(&self, id: SurfaceIdWrapper) -> Element { match id { SurfaceIdWrapper::LayerSurface(_) => unimplemented!(), - SurfaceIdWrapper::Window(_) => icon_button( + SurfaceIdWrapper::Window(_) => self.applet_helper.icon_button( &self.icon_name, - Svg::Custom(|theme| svg::Appearance { - fill: Some(theme.palette().text), - }), ) .on_press(Message::TogglePopup) - .style(Button::Text) .into(), SurfaceIdWrapper::Popup(_) => { let name = text(fl!("battery")).size(18); @@ -235,7 +223,7 @@ impl Application for CosmicBatteryApplet { }, ) .size(12); - popup_container( + self.applet_helper.popup_container( column![ row![ icon(&self.icon_name, 24) @@ -250,12 +238,12 @@ impl Application for CosmicBatteryApplet { ] .spacing(8) .align_items(Alignment::Center), - separator!(1), + horizontal_rule(1), // text{"Limit Battery Charging"}, - widget::Toggler::new(self.charging_limit, fl!("max-charge"), |_| { + toggler(fl!("max-charge"), self.charging_limit, |_| { Message::SetChargingLimit(!self.charging_limit) }), - separator!(1), + horizontal_rule(1), row![ icon("display-brightness-symbolic", 24) .style(Svg::Custom(|theme| { @@ -265,7 +253,7 @@ impl Application for CosmicBatteryApplet { })) .width(Length::Units(24)) .height(Length::Units(24)), - widget::slider( + slider( 0..=100, (self.screen_brightness * 100.0) as i32, Message::SetScreenBrightness @@ -284,7 +272,7 @@ impl Application for CosmicBatteryApplet { })) .width(Length::Units(24)) .height(Length::Units(24)), - widget::slider( + slider( 0..=100, (self.kbd_brightness * 100.0) as i32, Message::SetKbdBrightness