Refactor icons jammy (#108)
* chore: add icons and installation * refactor: use the new battery icons * refactor: use audio applet icons * chore dependency cleanup * chore: remove icons included in cosmic-icons package * refactor: use icons for signal strength and fix handling of new connections * fix: improve some logic for the networking applet * chore: add cosmic-icons to Depends * feat: use notifications icons * chore: set bluetooth icon depending on state * fix: set default font and text size * feat (network): add airplane-mode message * feat (battery): add display icons to the battery applet * fix (battery): logic for selecting the battery icon & use new battery icons
This commit is contained in:
parent
76ce8838b5
commit
3ad64df5f3
77 changed files with 653 additions and 615 deletions
|
|
@ -55,9 +55,11 @@ static MAX_CHARGE: Lazy<id::Toggler> = Lazy::new(id::Toggler::unique);
|
|||
#[derive(Clone, Default)]
|
||||
struct CosmicBatteryApplet {
|
||||
icon_name: String,
|
||||
display_icon_name: String,
|
||||
theme: Theme,
|
||||
charging_limit: bool,
|
||||
battery_percent: f64,
|
||||
on_battery: bool,
|
||||
time_remaining: Duration,
|
||||
kbd_brightness: f64,
|
||||
screen_brightness: f64,
|
||||
|
|
@ -71,11 +73,65 @@ struct CosmicBatteryApplet {
|
|||
timeline: Timeline,
|
||||
}
|
||||
|
||||
impl CosmicBatteryApplet {
|
||||
fn update_battery(&mut self, mut percent: f64, on_battery: bool) {
|
||||
percent = percent.clamp(0.0, 100.0);
|
||||
self.on_battery = on_battery;
|
||||
self.battery_percent = percent;
|
||||
let battery_percent = if self.battery_percent > 95.0 && !self.charging_limit {
|
||||
100
|
||||
} else if self.battery_percent > 80.0 && !self.charging_limit {
|
||||
90
|
||||
} else if self.battery_percent > 65.0 {
|
||||
80
|
||||
} else if self.battery_percent > 35.0 {
|
||||
50
|
||||
} else if self.battery_percent > 20.0 {
|
||||
35
|
||||
} else if self.battery_percent > 14.0 {
|
||||
20
|
||||
} else if self.battery_percent > 9.0 {
|
||||
10
|
||||
} else if self.battery_percent > 5.0 {
|
||||
5
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let limited = if self.charging_limit { "limited-" } else { "" };
|
||||
let charging = if on_battery { "" } else { "charging-" };
|
||||
self.icon_name =
|
||||
format!("cosmic-applet-battery-level-{battery_percent}-{limited}{charging}symbolic",);
|
||||
}
|
||||
|
||||
fn update_display(&mut self, mut percent: f64) {
|
||||
percent = percent.clamp(0.01, 1.0);
|
||||
self.screen_brightness = percent;
|
||||
let screen_brightness = if self.screen_brightness < 0.011 {
|
||||
"off"
|
||||
} else if self.screen_brightness < 0.333 {
|
||||
"low"
|
||||
} else if self.screen_brightness < 0.666 {
|
||||
"medium"
|
||||
} else {
|
||||
"high"
|
||||
}
|
||||
.to_string();
|
||||
|
||||
self.display_icon_name =
|
||||
format!("cosmic-applet-battery-display-brightness-{screen_brightness}-symbolic",);
|
||||
}
|
||||
|
||||
fn set_charging_limit(&mut self, limit: bool) {
|
||||
self.charging_limit = limit;
|
||||
self.update_battery(self.battery_percent, self.on_battery);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
TogglePopup,
|
||||
Update {
|
||||
icon_name: String,
|
||||
on_battery: bool,
|
||||
percent: f64,
|
||||
time_to_empty: i64,
|
||||
},
|
||||
|
|
@ -108,6 +164,7 @@ impl Application for CosmicBatteryApplet {
|
|||
(
|
||||
CosmicBatteryApplet {
|
||||
icon_name: "battery-symbolic".to_string(),
|
||||
display_icon_name: "display-brightness-symbolic".to_string(),
|
||||
applet_helper,
|
||||
theme,
|
||||
..Default::default()
|
||||
|
|
@ -130,14 +187,14 @@ impl Application for CosmicBatteryApplet {
|
|||
}
|
||||
}
|
||||
Message::SetScreenBrightness(brightness) => {
|
||||
self.screen_brightness = (brightness as f64 / 100.0).clamp(0.01, 1.0);
|
||||
self.update_display((brightness as f64 / 100.0).clamp(0.01, 1.0));
|
||||
if let Some(tx) = &self.screen_sender {
|
||||
let _ = tx.send(ScreenBacklightRequest::Set(self.screen_brightness));
|
||||
}
|
||||
}
|
||||
Message::SetChargingLimit(chain, enable) => {
|
||||
self.timeline.set_chain(chain).start();
|
||||
self.charging_limit = enable;
|
||||
self.set_charging_limit(enable);
|
||||
}
|
||||
Message::OpenBatterySettings => {
|
||||
// TODO Ashley
|
||||
|
|
@ -179,12 +236,11 @@ impl Application for CosmicBatteryApplet {
|
|||
}
|
||||
}
|
||||
Message::Update {
|
||||
icon_name,
|
||||
on_battery,
|
||||
percent,
|
||||
time_to_empty,
|
||||
} => {
|
||||
self.icon_name = icon_name;
|
||||
self.battery_percent = percent;
|
||||
self.update_battery(percent, on_battery);
|
||||
self.time_remaining = Duration::from_secs(time_to_empty as u64);
|
||||
}
|
||||
Message::UpdateKbdBrightness(b) => {
|
||||
|
|
@ -199,10 +255,10 @@ impl Application for CosmicBatteryApplet {
|
|||
Message::InitScreenBacklight(tx, brightness) => {
|
||||
let _ = tx.send(ScreenBacklightRequest::Get);
|
||||
self.screen_sender = Some(tx);
|
||||
self.screen_brightness = brightness;
|
||||
self.update_display(brightness);
|
||||
}
|
||||
Message::UpdateScreenBrightness(b) => {
|
||||
self.screen_brightness = b;
|
||||
self.update_display(b);
|
||||
}
|
||||
Message::InitProfile(tx, profile) => {
|
||||
self.power_profile_sender.replace(tx);
|
||||
|
|
@ -236,20 +292,16 @@ impl Application for CosmicBatteryApplet {
|
|||
.into()
|
||||
} else {
|
||||
let name = text(fl!("battery")).size(14);
|
||||
let description = text(
|
||||
if "battery-full-charging-symbolic" == self.icon_name
|
||||
|| "battery-full-charged-symbolic" == self.icon_name
|
||||
{
|
||||
format!("{}%", self.battery_percent)
|
||||
} else {
|
||||
format!(
|
||||
"{} {} ({:.0}%)",
|
||||
format_duration(self.time_remaining),
|
||||
fl!("until-empty"),
|
||||
self.battery_percent
|
||||
)
|
||||
},
|
||||
)
|
||||
let description = text(if !self.on_battery {
|
||||
format!("{}%", self.battery_percent)
|
||||
} else {
|
||||
format!(
|
||||
"{} {} ({:.0}%)",
|
||||
format_duration(self.time_remaining),
|
||||
fl!("until-empty"),
|
||||
self.battery_percent
|
||||
)
|
||||
})
|
||||
.size(10);
|
||||
self.applet_helper
|
||||
.popup_container(
|
||||
|
|
@ -342,7 +394,7 @@ impl Application for CosmicBatteryApplet {
|
|||
.width(Length::Fill)
|
||||
.padding([0, 12]),
|
||||
row![
|
||||
icon("display-brightness-symbolic", 24).style(Svg::Symbolic),
|
||||
icon(self.display_icon_name.as_str(), 24).style(Svg::Symbolic),
|
||||
slider(
|
||||
1..=100,
|
||||
(self.screen_brightness * 100.0) as i32,
|
||||
|
|
@ -393,11 +445,11 @@ impl Application for CosmicBatteryApplet {
|
|||
self.applet_helper.theme_subscription(0).map(Message::Theme),
|
||||
device_subscription(0).map(
|
||||
|DeviceDbusEvent::Update {
|
||||
icon_name,
|
||||
on_battery,
|
||||
percent,
|
||||
time_to_empty,
|
||||
}| Message::Update {
|
||||
icon_name,
|
||||
on_battery,
|
||||
percent,
|
||||
time_to_empty,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -168,19 +168,20 @@ pub fn device_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
|||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Ready,
|
||||
Waiting(DeviceProxy<'static>),
|
||||
Waiting(UPowerProxy<'static>, DeviceProxy<'static>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
async fn display_device() -> zbus::Result<DeviceProxy<'static>> {
|
||||
async fn display_device() -> zbus::Result<(UPowerProxy<'static>, DeviceProxy<'static>)> {
|
||||
let connection = zbus::Connection::system().await?;
|
||||
let upower = UPowerProxy::new(&connection).await?;
|
||||
let upower: UPowerProxy<'_> = UPowerProxy::new(&connection).await?;
|
||||
let device_path = upower.get_display_device().await?;
|
||||
DeviceProxy::builder(&connection)
|
||||
.path(device_path)?
|
||||
.cache_properties(zbus::CacheProperties::Yes)
|
||||
.build()
|
||||
.await
|
||||
.map(|dp| (upower, dp))
|
||||
}
|
||||
|
||||
async fn start_listening(
|
||||
|
|
@ -189,11 +190,11 @@ async fn start_listening(
|
|||
) -> State {
|
||||
match state {
|
||||
State::Ready => {
|
||||
if let Ok(device) = display_device().await {
|
||||
if let Ok((upower, device)) = display_device().await {
|
||||
_ = output
|
||||
.send(DeviceDbusEvent::Update {
|
||||
icon_name: device
|
||||
.cached_icon_name()
|
||||
on_battery: upower
|
||||
.cached_on_battery()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
percent: device
|
||||
|
|
@ -206,13 +207,13 @@ async fn start_listening(
|
|||
.unwrap_or_default(),
|
||||
})
|
||||
.await;
|
||||
return State::Waiting(device);
|
||||
return State::Waiting(upower, device);
|
||||
}
|
||||
State::Finished
|
||||
}
|
||||
State::Waiting(device) => {
|
||||
State::Waiting(upower, device) => {
|
||||
let mut stream = futures::stream_select!(
|
||||
device.receive_icon_name_changed().await.map(|_| ()),
|
||||
upower.receive_on_battery_changed().await.map(|_| ()),
|
||||
device.receive_percentage_changed().await.map(|_| ()),
|
||||
device.receive_time_to_empty_changed().await.map(|_| ()),
|
||||
);
|
||||
|
|
@ -220,8 +221,8 @@ async fn start_listening(
|
|||
Some(_) => {
|
||||
_ = output
|
||||
.send(DeviceDbusEvent::Update {
|
||||
icon_name: device
|
||||
.cached_icon_name()
|
||||
on_battery: upower
|
||||
.cached_on_battery()
|
||||
.unwrap_or_default()
|
||||
.unwrap_or_default(),
|
||||
percent: device
|
||||
|
|
@ -235,7 +236,7 @@ async fn start_listening(
|
|||
})
|
||||
.await;
|
||||
|
||||
State::Waiting(device)
|
||||
State::Waiting(upower, device)
|
||||
}
|
||||
None => State::Finished,
|
||||
}
|
||||
|
|
@ -247,7 +248,7 @@ async fn start_listening(
|
|||
#[derive(Debug, Clone)]
|
||||
pub enum DeviceDbusEvent {
|
||||
Update {
|
||||
icon_name: String,
|
||||
on_battery: bool,
|
||||
percent: f64,
|
||||
time_to_empty: i64,
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue