experimental battery display
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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()),
|
||||
};
|
||||
|
||||
|
||||
@@ -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.,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
12
src/state.rs
12
src/state.rs
@@ -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");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user