mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-07-29 20:28:48 +00:00
feat: integrate new libmonado-rs battery status
This commit is contained in:
parent
5368c73be0
commit
dbb5ea7eb0
6 changed files with 36 additions and 33 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1109,7 +1109,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "libmonado-rs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/technobaboo/libmonado-rs#626d8f52d218c59a915edc61e91f849b8dc8922e"
|
||||
source = "git+https://github.com/technobaboo/libmonado-rs?rev=ddad003d5701c7139dd0de69c8195ed2105784ca#ddad003d5701c7139dd0de69c8195ed2105784ca"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"cmake",
|
||||
|
|
|
@ -12,7 +12,7 @@ git2 = "0.19.0"
|
|||
gtk4 = { version = "0.9.0", features = ["v4_10"] }
|
||||
lazy_static = "1.5.0"
|
||||
libadwaita = { version = "0.7.0", features = ["v1_5"] }
|
||||
libmonado-rs = { git = "https://github.com/technobaboo/libmonado-rs" }
|
||||
libmonado-rs = { git = "https://github.com/technobaboo/libmonado-rs", rev = "ddad003d5701c7139dd0de69c8195ed2105784ca" }
|
||||
rusb = "0.9.4"
|
||||
nix = { version = "0.29.0", features = ["fs", "signal"] }
|
||||
phf = "0.11.2"
|
||||
|
|
|
@ -1,34 +1,39 @@
|
|||
use libmonado_rs::BatteryStatus;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct BatteryStatus {
|
||||
/// between 0 and 100
|
||||
pub percentage: u8,
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EnvisionBatteryStatus {
|
||||
pub battery_status: BatteryStatus,
|
||||
}
|
||||
|
||||
impl Display for BatteryStatus {
|
||||
impl Display for EnvisionBatteryStatus {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.write_str(&format!("{}%", self.percentage))
|
||||
f.write_str(&format!(
|
||||
"{}%",
|
||||
(self.battery_status.charge * 100.0).round()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl BatteryStatus {
|
||||
pub fn new(percentage: u8) -> Self {
|
||||
Self { percentage }
|
||||
impl From<BatteryStatus> for EnvisionBatteryStatus {
|
||||
fn from(battery_status: BatteryStatus) -> Self {
|
||||
Self { battery_status }
|
||||
}
|
||||
}
|
||||
|
||||
impl EnvisionBatteryStatus {
|
||||
pub fn icon(&self) -> &str {
|
||||
match self.percentage {
|
||||
n if n >= 100 => "battery-level-100-symbolic",
|
||||
n if n >= 90 => "battery-level-90-symbolic",
|
||||
n if n >= 80 => "battery-level-80-symbolic",
|
||||
n if n >= 70 => "battery-level-70-symbolic",
|
||||
n if n >= 60 => "battery-level-60-symbolic",
|
||||
n if n >= 50 => "battery-level-50-symbolic",
|
||||
n if n >= 40 => "battery-level-40-symbolic",
|
||||
n if n >= 30 => "battery-level-30-symbolic",
|
||||
n if n >= 20 => "battery-level-20-symbolic",
|
||||
n if n >= 10 => "battery-level-10-symbolic",
|
||||
match self.battery_status.charge {
|
||||
n if n >= 1.0 => "battery-level-100-symbolic",
|
||||
n if n >= 0.9 => "battery-level-90-symbolic",
|
||||
n if n >= 0.8 => "battery-level-80-symbolic",
|
||||
n if n >= 0.7 => "battery-level-70-symbolic",
|
||||
n if n >= 0.6 => "battery-level-60-symbolic",
|
||||
n if n >= 0.5 => "battery-level-50-symbolic",
|
||||
n if n >= 0.4 => "battery-level-40-symbolic",
|
||||
n if n >= 0.3 => "battery-level-30-symbolic",
|
||||
n if n >= 0.2 => "battery-level-20-symbolic",
|
||||
n if n >= 0.1 => "battery-level-10-symbolic",
|
||||
_ => "battery-level-0-symbolic",
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use relm4::{factory::AsyncFactoryVecDeque, prelude::*};
|
|||
|
||||
#[tracker::track]
|
||||
pub struct DevicesBox {
|
||||
#[no_eq]
|
||||
devices: Vec<XRDevice>,
|
||||
|
||||
#[tracker::do_not_track]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
ui::battery_status::BatteryStatus,
|
||||
ui::battery_status::EnvisionBatteryStatus,
|
||||
xr_devices::{XRDevice, XRDeviceRole},
|
||||
};
|
||||
use adw::prelude::*;
|
||||
|
@ -42,7 +42,7 @@ pub struct DeviceRowModel {
|
|||
subtitle: String,
|
||||
state: DeviceRowState,
|
||||
suffix: Option<gtk::Widget>,
|
||||
battery_status: Option<BatteryStatus>,
|
||||
battery_status: Option<EnvisionBatteryStatus>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -51,7 +51,7 @@ pub struct DeviceRowModelInit {
|
|||
pub subtitle: Option<String>,
|
||||
pub state: Option<DeviceRowState>,
|
||||
pub suffix: Option<gtk::Widget>,
|
||||
pub battery_status: Option<BatteryStatus>,
|
||||
pub battery_status: Option<EnvisionBatteryStatus>,
|
||||
}
|
||||
|
||||
impl DeviceRowModelInit {
|
||||
|
@ -59,9 +59,7 @@ impl DeviceRowModelInit {
|
|||
Self {
|
||||
title: Some(d.dev_type.to_string()),
|
||||
subtitle: Some(d.name.clone()),
|
||||
battery_status: d
|
||||
.battery
|
||||
.map(|bat| BatteryStatus::new((bat * 100.0).trunc() as u8)),
|
||||
battery_status: d.battery.map(EnvisionBatteryStatus::from),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use libmonado_rs;
|
||||
use libmonado_rs::{self, BatteryStatus};
|
||||
use std::{fmt::Display, slice::Iter};
|
||||
|
||||
const GENERIC_TRACKER_PREFIX: &str = "Found generic tracker device: ";
|
||||
|
@ -224,14 +224,13 @@ impl XRDeviceRole {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct XRDevice {
|
||||
pub dev_type: XRDeviceRole,
|
||||
pub name: String,
|
||||
pub index: String,
|
||||
pub serial: Option<String>,
|
||||
pub battery: Option<f32>, // battery percentage, from 0 to 1 maybe
|
||||
// still need to implement it in monado
|
||||
pub battery: Option<BatteryStatus>,
|
||||
}
|
||||
|
||||
impl Default for XRDevice {
|
||||
|
@ -320,9 +319,9 @@ impl XRDevice {
|
|||
res.push(Self {
|
||||
index: dev.id.to_string(),
|
||||
serial: dev.serial().ok(),
|
||||
battery: dev.battery_status().ok(),
|
||||
name: dev.name,
|
||||
dev_type: xrd,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue