experimental battery display

This commit is contained in:
galister
2024-02-06 21:14:10 +01:00
parent c14fa4194b
commit fd2b96c0d6
9 changed files with 128 additions and 61 deletions

54
Cargo.lock generated
View File

@@ -182,7 +182,7 @@ version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ac22eda5891cc086690cb6fa10121c0390de0e3b04eb269f2d766b00d3f2d81"
dependencies = [
"async-fs 2.1.0",
"async-fs 2.1.1",
"async-net",
"enumflags2",
"futures-channel",
@@ -246,9 +246,9 @@ dependencies = [
[[package]]
name = "async-fs"
version = "2.1.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd1f344136bad34df1f83a47f3fd7f2ab85d75cb8a940af4ccf6d482a84ea01b"
checksum = "bc19683171f287921f2405677dd2ed2549c3b3bda697a563ebc3a121ace2aba1"
dependencies = [
"async-lock 3.3.0",
"blocking",
@@ -287,7 +287,7 @@ dependencies = [
"futures-io",
"futures-lite 2.2.0",
"parking",
"polling 3.3.2",
"polling 3.4.0",
"rustix 0.38.31",
"slab",
"tracing",
@@ -682,7 +682,7 @@ checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298"
dependencies = [
"bitflags 2.4.2",
"log",
"polling 3.3.2",
"polling 3.4.0",
"rustix 0.38.31",
"slab",
"thiserror",
@@ -1910,9 +1910,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.67"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1"
checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee"
dependencies = [
"wasm-bindgen",
]
@@ -2449,7 +2449,7 @@ dependencies = [
[[package]]
name = "ovr_overlay"
version = "0.0.0"
source = "git+https://github.com/galister/ovr_overlay_oyasumi#df243248c4eb021ae43fbb96e3fe1c5b9fe48be5"
source = "git+https://github.com/galister/ovr_overlay_oyasumi#7682483e0ed719bd8c84dcb55bdd78c237383937"
dependencies = [
"byteorder",
"derive_more",
@@ -2464,7 +2464,7 @@ dependencies = [
[[package]]
name = "ovr_overlay_sys"
version = "0.0.0"
source = "git+https://github.com/galister/ovr_overlay_oyasumi#df243248c4eb021ae43fbb96e3fe1c5b9fe48be5"
source = "git+https://github.com/galister/ovr_overlay_oyasumi#7682483e0ed719bd8c84dcb55bdd78c237383937"
dependencies = [
"autocxx",
"autocxx-build",
@@ -2657,9 +2657,9 @@ dependencies = [
[[package]]
name = "polling"
version = "3.3.2"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "545c980a3880efd47b2e262f6a4bb6daad6555cf3367aa9c4e52895f69537a41"
checksum = "30054e72317ab98eddd8561db0f6524df3367636884b7b21b703e4b280a84a14"
dependencies = [
"cfg-if",
"concurrent-queue",
@@ -3661,9 +3661,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasm-bindgen"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406"
checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
@@ -3671,9 +3671,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd"
checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b"
dependencies = [
"bumpalo",
"log",
@@ -3686,9 +3686,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.40"
version = "0.4.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461"
checksum = "877b9c3f61ceea0e56331985743b13f3d25c406a7098d45180fb5f09bc19ed97"
dependencies = [
"cfg-if",
"js-sys",
@@ -3698,9 +3698,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999"
checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -3708,9 +3708,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7"
checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66"
dependencies = [
"proc-macro2",
"quote",
@@ -3721,9 +3721,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.90"
version = "0.2.91"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b"
checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838"
[[package]]
name = "wayland-backend"
@@ -3922,9 +3922,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.67"
version = "0.3.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed"
checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446"
dependencies = [
"js-sys",
"wasm-bindgen",
@@ -4249,9 +4249,9 @@ dependencies = [
[[package]]
name = "winnow"
version = "0.5.37"
version = "0.5.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cad8365489051ae9f054164e459304af2e7e9bb407c958076c8bf4aef52da5"
checksum = "4a665c9321a199a107f7d84ab7b179ab738c460bf8a8f90f121cdd087b569fd5"
dependencies = [
"memchr",
]

View File

@@ -1,8 +1,6 @@
use std::f32::consts::PI;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread::sleep;
use std::time::Duration;
use glam::{Affine3A, Vec3, Vec3A, Vec4};
use idmap::IdMap;
@@ -59,7 +57,7 @@ impl LinePool {
}
}
pub fn allocate(&mut self, overlay: &mut OverlayManager, app: &mut AppState) -> usize {
pub fn allocate(&mut self) -> usize {
let id = AUTO_INCREMENT.fetch_add(1, Ordering::Relaxed);
let mut data = OverlayData::<OpenVrOverlayData> {
@@ -147,7 +145,6 @@ impl LinePool {
data.after_input(overlay, app);
if data.state.want_visible {
if data.state.dirty {
data.initialize(overlay, app);
data.upload_texture(overlay, &app.graphics);
data.state.dirty = false;
}

View File

@@ -118,10 +118,7 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
let mut due_tasks = VecDeque::with_capacity(4);
let mut lines = LinePool::new(state.graphics.clone());
let pointer_lines = [
lines.allocate(&mut overlay_mngr, &mut state),
lines.allocate(&mut overlay_mngr, &mut state),
];
let pointer_lines = [lines.allocate(), lines.allocate()];
'main_loop: loop {
if !running.load(Ordering::Relaxed) {

View File

@@ -34,6 +34,7 @@ impl OverlayData<OpenVrOverlayData> {
app: &mut AppState,
) -> OverlayHandle {
let key = format!("wlx-{}", self.state.name);
log::debug!("Create overlay with key: {}", &key);
let handle = match overlay.create_overlay(&key, &key) {
Ok(handle) => handle,
Err(e) => {

View File

@@ -114,7 +114,6 @@ pub struct WlxGraphics {
pub quad_indices: Subbuffer<[u16]>,
pub shared_shaders: RwLock<HashMap<&'static str, Arc<ShaderModule>>>,
pub shared_images: RwLock<HashMap<&'static str, Arc<ImageView>>>,
}
impl WlxGraphics {
@@ -313,7 +312,6 @@ impl WlxGraphics {
descriptor_set_allocator,
quad_indices,
quad_verts,
shared_images: RwLock::new(HashMap::new()),
shared_shaders: RwLock::new(HashMap::new()),
};
@@ -440,7 +438,6 @@ impl WlxGraphics {
descriptor_set_allocator,
quad_indices,
quad_verts,
shared_images: RwLock::new(HashMap::new()),
shared_shaders: RwLock::new(HashMap::new()),
};

View File

@@ -285,9 +285,7 @@ impl ScreenRenderer {
}
impl OverlayRenderer for ScreenRenderer {
fn init(&mut self, app: &mut AppState) {
let images = app.graphics.shared_images.read().unwrap();
}
fn init(&mut self, _app: &mut AppState) {}
fn render(&mut self, app: &mut AppState) {
let receiver = self.receiver.get_or_insert_with(|| {
let _drm_formats = DRM_FORMATS.get_or_init({
@@ -504,9 +502,6 @@ where
let axis = Vec3::new(0., 0., 1.);
let logical_ratio = output.logical_size.0 as f32 / output.logical_size.1 as f32;
let physical_ratio = output.size.0 as f32 / output.size.1 as f32;
let angle = if session.config.upright_screen_fix {
match output.transform {
Transform::_90 | Transform::Flipped90 => PI / 2.,

View File

@@ -144,6 +144,49 @@ where
});
button.on_press = Some(exec_button);
}
WatchElement::Batteries {
rect,
font_size,
num_devices,
normal_fg_color,
layout,
..
} => {
let num_buttons = num_devices as f32;
let mut button_x = rect[0];
let mut button_y = rect[1];
let (button_w, button_h) = match layout {
ListLayout::Horizontal => (rect[2] / num_buttons, rect[3]),
ListLayout::Vertical => (rect[2], rect[3] / num_buttons),
};
canvas.font_size = font_size;
canvas.fg_color = color_parse(&normal_fg_color).unwrap_or(FALLBACK_COLOR);
for i in 0..num_devices {
let label = canvas.label(
button_x + 2.,
button_y + 2.,
button_w - 4.,
button_h - 4.,
empty_str.clone(),
);
label.state = Some(ElemState {
battery: Some(i as usize),
..Default::default()
});
label.on_update = Some(battery_update);
button_x += match layout {
ListLayout::Horizontal => button_w,
ListLayout::Vertical => 0.,
};
button_y += match layout {
ListLayout::Horizontal => 0.,
ListLayout::Vertical => button_h,
};
}
}
WatchElement::OverlayList {
rect,
font_size,
@@ -244,6 +287,7 @@ where
#[derive(Default)]
struct ElemState {
battery: Option<usize>,
clock: Option<ClockState>,
exec: Option<ExecState>,
button: Option<WatchButtonState>,
@@ -267,6 +311,25 @@ struct ExecState {
child: Option<process::Child>,
}
fn battery_update(control: &mut Control<(), ElemState>, _: &mut (), app: &mut AppState) {
let state = control.state.as_ref().unwrap();
let device_idx = state.battery.unwrap();
let device = app.input_state.devices.get(device_idx);
let tags = ["", "H", "L", "R", "T"];
let text = match device {
Some(d) => d
.soc
.map(|soc| format!("{}{}", tags[d.role as usize], soc as u32))
.unwrap_or_else(|| "".into()),
None => "".into(),
};
control.set_text(&text);
}
fn exec_button(
control: &mut Control<(), ElemState>,
_: &mut (),
@@ -461,6 +524,7 @@ pub struct WatchConfig {
watch_elements: Vec<WatchElement>,
}
#[allow(dead_code)]
#[derive(Deserialize)]
#[serde(tag = "type")]
enum WatchElement {
@@ -496,6 +560,19 @@ enum WatchElement {
exec: Vec<Arc<str>>,
text: Arc<str>,
},
Batteries {
rect: [f32; 4],
font_size: isize,
low_threshold: f32,
num_devices: u16,
normal_fg_color: Arc<str>,
normal_bg_color: Arc<str>,
low_fg_color: Arc<str>,
low_bg_color: Arc<str>,
charging_fg_color: Arc<str>,
charging_bg_color: Arc<str>,
layout: ListLayout,
},
OverlayList {
rect: [f32; 4],
font_size: isize,

View File

@@ -89,13 +89,26 @@ watch_elements:
fg_color: "#AA99BB"
text: "Chicago" # change TZ2 label here
# sample
- type: ExecLabel
rect: [50, 20, 200, 50]
- type: Batteries
rect: [0, 20, 400, 40]
font_size: 14
fg_color: "#FFFFFF"
exec: ["echo", "customize me! see watch.yaml"]
interval: 0 # seconds
num_devices: 9
low_threshold: 15
normal_fg_color: "#406040"
normal_bg_color: "#353535"
low_fg_color: "#604040"
low_bg_color: "#353535"
charging_fg_color: "#204070"
charging_bg_color: "#353535"
layout: Horizontal
# sample
# - type: ExecLabel
# rect: [50, 20, 200, 50]
# font_size: 14
# fg_color: "#FFFFFF"
# exec: ["echo", "customize me! see watch.yaml"]
# interval: 0 # seconds
# volume buttons
- type: ExecButton

View File

@@ -1,7 +1,7 @@
use std::{path::PathBuf, sync::Arc};
use glam::{Quat, Vec3};
use vulkano::{command_buffer::CommandBufferUsage, format::Format, image::view::ImageView};
use vulkano::format::Format;
use crate::{
backend::{common::TaskContainer, input::InputState},
@@ -30,16 +30,6 @@ impl AppState {
pub fn from_graphics(graphics: Arc<WlxGraphics>) -> Self {
// insert shared resources
{
let mut uploads = graphics.create_command_buffer(CommandBufferUsage::OneTimeSubmit);
let texture = uploads.texture2d(1, 1, Format::R8G8B8A8_UNORM, &[255, 0, 255, 255]);
uploads.build_and_execute_now();
let Ok(mut images) = graphics.shared_images.write() else {
panic!("Shared Images RwLock poisoned");
};
images.insert("fallback", ImageView::new_default(texture).unwrap());
let Ok(mut shaders) = graphics.shared_shaders.write() else {
panic!("Shared Shaders RwLock poisoned");
};