From 7d987f5cb849481519df6db8bf29cafe6ffb2ca7 Mon Sep 17 00:00:00 2001 From: galister <22305755+galister@users.noreply.github.com> Date: Fri, 29 Mar 2024 14:09:39 +0100 Subject: [PATCH] fix: watch notifications --- src/config.rs | 13 ++++--------- src/overlays/toast.rs | 21 ++++++++++++++------- src/res/settings.yaml | 4 ++-- src/state.rs | 14 ++++++++++++++ 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2fc2645..dbc101b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,12 +66,7 @@ fn def_auto() -> Arc { } fn def_toast_topics() -> IdMap { - let mut map = IdMap::new(); - map.insert(ToastTopic::System, DisplayMethod::Center); - map.insert(ToastTopic::DesktopNotification, DisplayMethod::Center); - map.insert(ToastTopic::XSNotification, DisplayMethod::Center); - map.insert(ToastTopic::IpdChange, DisplayMethod::Hide); - map + IdMap::new() } #[derive(Deserialize, Serialize)] @@ -94,6 +89,9 @@ pub struct GeneralConfig { #[serde(default = "def_true")] pub notifications_sound_enabled: bool, + #[serde(default = "def_toast_topics")] + pub notification_topics: IdMap, + #[serde(default = "def_true")] pub keyboard_sound_enabled: bool, @@ -115,9 +113,6 @@ pub struct GeneralConfig { #[serde(default = "def_pw_tokens")] pub pw_tokens: Vec<(String, String)>, - #[serde(default = "def_toast_topics")] - pub toast_topics: IdMap, - #[serde(default = "def_osc_port")] pub osc_out_port: u16, diff --git a/src/overlays/toast.rs b/src/overlays/toast.rs index 0dd658d..6c9e323 100644 --- a/src/overlays/toast.rs +++ b/src/overlays/toast.rs @@ -1,10 +1,11 @@ use std::{ + f32::consts::PI, ops::Add, sync::{atomic::AtomicUsize, Arc}, time::Instant, }; -use glam::{vec3a, Vec3A}; +use glam::{vec3a, Quat, Vec3A}; use idmap_derive::IntegerId; use serde::{Deserialize, Serialize}; @@ -108,22 +109,27 @@ fn new_toast( ) -> Option<(OverlayState, Box)> { let current_method = app .session - .config .toast_topics .get(toast.topic) .copied() .unwrap_or(DisplayMethod::Hide); - let (spawn_point, relative_to) = match current_method { + let (spawn_point, spawn_rotation, relative_to) = match current_method { DisplayMethod::Hide => return None, - DisplayMethod::Center => (vec3a(0., -2.0, -0.5), RelativeTo::Head), + DisplayMethod::Center => (vec3a(0., -0.2, -0.5), Quat::IDENTITY, RelativeTo::Head), DisplayMethod::Watch => { + let mut watch_pos = + Vec3A::from_slice(&app.session.config.watch_pos) + vec3a(-0.005, -0.05, 0.02); + let mut watch_rot = Quat::from_slice(&app.session.config.watch_rot); let relative_to = match app.session.config.watch_hand { LeftRight::Left => RelativeTo::Hand(0), - LeftRight::Right => RelativeTo::Hand(1), + LeftRight::Right => { + watch_pos.x = -watch_pos.x; + watch_rot = watch_rot * Quat::from_rotation_x(PI) * Quat::from_rotation_z(PI); + RelativeTo::Hand(1) + } }; - let watch_pos = Vec3A::from_slice(&app.session.config.watch_pos); - (watch_pos + Vec3A::Y * 0.05, relative_to) + (watch_pos, watch_rot, relative_to) } }; @@ -183,6 +189,7 @@ fn new_toast( name, want_visible: true, spawn_scale: size.0 * PIXELS_TO_METERS, + spawn_rotation, spawn_point, relative_to, ..Default::default() diff --git a/src/res/settings.yaml b/src/res/settings.yaml index 6504da5..b95798f 100644 --- a/src/res/settings.yaml +++ b/src/res/settings.yaml @@ -528,7 +528,7 @@ elements: rect: [330, 505, 220, 30] font_size: 12 fg_color: "#ffffff" - bg_color: "#606020" + bg_color: "#303010" text: "Enabled" click_down: - type: System @@ -539,7 +539,7 @@ elements: rect: [330, 555, 220, 30] font_size: 12 fg_color: "#ffffff" - bg_color: "#606020" + bg_color: "#303010" text: "Sound Enabled" click_down: - type: System diff --git a/src/state.rs b/src/state.rs index 7b68356..57def9c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -2,6 +2,7 @@ use std::{io::Cursor, path::PathBuf, sync::Arc}; use anyhow::bail; use glam::Vec3; +use idmap::IdMap; use rodio::{Decoder, OutputStream, OutputStreamHandle, Source}; use serde::{Deserialize, Serialize}; use smallvec::{smallvec, SmallVec}; @@ -14,6 +15,7 @@ use crate::{ graphics::WlxGraphics, gui::font::FontCache, hid::HidProvider, + overlays::toast::{DisplayMethod, ToastTopic}, shaders::{frag_color, frag_glyph, frag_screen, frag_sprite, frag_srgb, vert_common}, }; @@ -74,6 +76,8 @@ pub struct AppSession { pub config_root_path: PathBuf, pub config: GeneralConfig, + pub toast_topics: IdMap, + pub color_norm: Vec3, pub color_shift: Vec3, pub color_alt: Vec3, @@ -86,9 +90,19 @@ impl AppSession { log::info!("Config root path: {}", config_root_path.to_string_lossy()); let config = GeneralConfig::load_from_disk(); + let mut toast_topics = IdMap::new(); + toast_topics.insert(ToastTopic::System, DisplayMethod::Center); + toast_topics.insert(ToastTopic::DesktopNotification, DisplayMethod::Center); + toast_topics.insert(ToastTopic::XSNotification, DisplayMethod::Center); + + config.notification_topics.iter().for_each(|(k, v)| { + toast_topics.insert(*k, *v); + }); + AppSession { config_root_path, config, + toast_topics, color_norm: Vec3 { x: 0., y: 1.,