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