wip: update libcosmic (#93)

* wip: update libcosmic

* fix: damge issue resolved by updating iced

* fix: high cpu usage by time applet and app-list

* refactor subscriptions to produce fewer events

* refactor network applet to use less cpu

* fix: text size

* refactor: i18n for audio applet

* refactor: power applet i18n setup

* fix (battery): always send profile update

* fix (battery): set toggler width to layout correctly

* fix (app-list): backoff for restarts of toplevel subscription

* fix (network): alignment

* feat: ask for comfirmation before applying power applet actions

* wip: integrate cosmic-config

* update zbus

* feat: update to use latest libcosmic

* update iced

* udpate deps

* update deps

* refactor: move applet helpers to this repo, outside of libcosmic.

this should help alleviate some dependency hell

* chore update deps

* update deps

* cleanup
This commit is contained in:
Ashley Wulber 2023-06-01 12:23:12 -04:00 committed by GitHub
parent 8b46cc209f
commit 9ebd9b511a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 2841 additions and 1681 deletions

View file

@ -1,18 +1,18 @@
use cosmic::applet::{cosmic_panel_config::PanelAnchor, CosmicAppletHelper};
use cosmic::iced::wayland::popup::{destroy_popup, get_popup};
use cosmic::iced::Limits;
use cosmic::iced::{
time,
wayland::InitialSurface,
widget::{button, column, text, vertical_space},
window, Alignment, Application, Color, Command, Length, Rectangle, Subscription,
};
use cosmic::iced_sctk::layout::Limits;
use cosmic::iced_style::application::{self, Appearance};
use cosmic::theme;
use cosmic::{
widget::{icon, rectangle_tracker::*},
Element, Theme,
};
use cosmic_applet::{cosmic_panel_config::PanelAnchor, CosmicAppletHelper};
use chrono::{DateTime, Local, Timelike};
use std::time::Duration;
@ -22,10 +22,8 @@ pub fn main() -> cosmic::iced::Result {
let mut settings = helper.window_settings();
match &mut settings.initial_surface {
InitialSurface::XdgWindow(s) => {
s.iced_settings.min_size = Some((1, 1));
s.iced_settings.max_size = None;
s.autosize = true;
s.size_limits = Limits::NONE.min_height(1).min_width(1);
s.size_limits = Limits::NONE.min_height(1.0).min_width(1.0);
}
_ => {}
};
@ -36,7 +34,7 @@ struct Time {
applet_helper: CosmicAppletHelper,
theme: Theme,
popup: Option<window::Id>,
id_ctr: u32,
id_ctr: u128,
update_at: Every,
now: DateTime<Local>,
msg: String,
@ -90,7 +88,7 @@ impl Application for Time {
}
fn theme(&self) -> Theme {
self.theme
self.theme.clone()
}
fn close_requested(&self, _id: window::Id) -> Self::Message {
@ -98,10 +96,10 @@ impl Application for Time {
}
fn style(&self) -> <Self::Theme as application::StyleSheet>::Style {
<Self::Theme as application::StyleSheet>::Style::Custom(|theme| Appearance {
<Self::Theme as application::StyleSheet>::Style::Custom(Box::new(|theme| Appearance {
background_color: Color::from_rgba(0.0, 0.0, 0.0, 0.0),
text_color: theme.cosmic().on_bg_color().into(),
})
}))
}
fn subscription(&self) -> Subscription<Message> {
@ -120,7 +118,7 @@ impl Application for Time {
.expect("Setting nanoseconds to 0 should always be possible.");
let wait = 1.max((next - now).num_milliseconds());
Subscription::batch(vec![
rectangle_tracker_subscription(0).map(|(_, update)| Message::Rectangle(update)),
rectangle_tracker_subscription(0).map(|e| Message::Rectangle(e.1)),
time::every(Duration::from_millis(
wait.try_into().unwrap_or(FALLBACK_DELAY),
))
@ -149,11 +147,11 @@ impl Application for Time {
.to_string();
self.msg = calendar;
self.id_ctr += 1;
let new_id = window::Id::new(self.id_ctr);
let new_id = window::Id(self.id_ctr);
self.popup.replace(new_id);
let mut popup_settings = self.applet_helper.get_popup_settings(
window::Id::new(0),
window::Id(0),
new_id,
None,
None,
@ -194,13 +192,13 @@ impl Application for Time {
}
fn view(&self, id: window::Id) -> Element<Message> {
if id == window::Id::new(0) {
if id == window::Id(0) {
let button = button(
if matches!(
self.applet_helper.anchor,
PanelAnchor::Top | PanelAnchor::Bottom
) {
column![text(self.now.format("%b %-d %-I:%M %p").to_string())]
column![text(self.now.format("%b %-d %-I:%M %p").to_string()).size(14)]
} else {
let mut date_time_col = column![
icon(
@ -208,10 +206,10 @@ impl Application for Time {
self.applet_helper.suggested_size().0
)
.style(theme::Svg::Symbolic),
text(self.now.format("%I").to_string()),
text(self.now.format("%M").to_string()),
text(self.now.format("%p").to_string()),
vertical_space(Length::Units(4)),
text(self.now.format("%I").to_string()).size(14),
text(self.now.format("%M").to_string()).size(14),
text(self.now.format("%p").to_string()).size(14),
vertical_space(Length::Fixed(4.0)),
// TODO better calendar icon?
icon(
"calendar-go-today-symbolic",
@ -222,7 +220,7 @@ impl Application for Time {
.align_items(Alignment::Center)
.spacing(4);
for d in self.now.format("%x").to_string().split("/") {
date_time_col = date_time_col.push(text(d.to_string()));
date_time_col = date_time_col.push(text(d.to_string()).size(14));
}
date_time_col
},
@ -240,7 +238,7 @@ impl Application for Time {
.align_items(Alignment::Start)
.spacing(12)
.padding([24, 0])
.push(text(&self.msg))
.push(text(&self.msg).size(14))
.padding(8);
self.applet_helper.popup_container(content).into()