get rid of once_cell

This commit is contained in:
galister
2025-04-07 03:31:58 +09:00
parent 7ac3072506
commit 60850d8d70
11 changed files with 35 additions and 40 deletions

1
Cargo.lock generated
View File

@@ -5328,7 +5328,6 @@ dependencies = [
"log",
"log-panics",
"mint",
"once_cell",
"openxr",
"ovr_overlay",
"regex",

View File

@@ -36,7 +36,6 @@ json = { version = "0.12.4", optional = true }
json5 = "0.4.1"
libc = "0.2.155"
log = "0.4.21"
once_cell = "1.19.0"
openxr = { git = "https://github.com/galister/openxrs", rev = "af4a55d", features = [
"linked",
"mint",

View File

@@ -1,6 +1,5 @@
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use once_cell::sync::Lazy;
#[cfg(feature = "openxr")]
use openxr as xr;
@@ -319,8 +318,8 @@ where
.any(|o| o.state.show_hide && o.state.want_visible);
if !any_shown {
static ANCHOR_LOCAL: Lazy<Affine3A> =
Lazy::new(|| Affine3A::from_translation(Vec3::NEG_Z));
static ANCHOR_LOCAL: LazyLock<Affine3A> =
LazyLock::new(|| Affine3A::from_translation(Vec3::NEG_Z));
let hmd = snap_upright(app.input_state.hmd, Vec3A::Y);
app.anchor = hmd * *ANCHOR_LOCAL;
}

View File

@@ -1,7 +1,10 @@
use std::{f32::consts::PI, fs::File, sync::Arc};
use std::{
f32::consts::PI,
fs::File,
sync::{Arc, LazyLock},
};
use glam::{Quat, Vec3A};
use once_cell::sync::Lazy;
use openxr::{self as xr, CompositionLayerFlags};
use vulkano::{
command_buffer::CommandBufferUsage, image::view::ImageView,
@@ -186,7 +189,7 @@ impl Skybox {
const HI_VERT_ANGLE: f32 = 0.5 * PI;
const LO_VERT_ANGLE: f32 = -0.5 * PI;
static GRID_POSE: Lazy<xr::Posef> = Lazy::new(|| {
static GRID_POSE: LazyLock<xr::Posef> = LazyLock::new(|| {
translation_rotation_to_posef(Vec3A::ZERO, Quat::from_rotation_x(PI * -0.5))
});

View File

@@ -1,6 +1,5 @@
use log::error;
use once_cell::sync::Lazy;
use std::path::PathBuf;
use std::{path::PathBuf, sync::LazyLock};
pub enum ConfigRoot {
Generic,
@@ -10,16 +9,14 @@ pub enum ConfigRoot {
const FALLBACK_CONFIG_PATH: &str = "/tmp/wlxoverlay";
static CONFIG_ROOT_PATH: Lazy<PathBuf> = Lazy::new(|| {
static CONFIG_ROOT_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
if let Ok(xdg_dirs) = xdg::BaseDirectories::new() {
let mut dir = xdg_dirs.get_config_home();
dir.push("wlxoverlay");
return dir;
}
//Return fallback config path
error!(
"Err: Failed to find config path, using {FALLBACK_CONFIG_PATH}"
);
error!("Err: Failed to find config path, using {FALLBACK_CONFIG_PATH}");
PathBuf::from(FALLBACK_CONFIG_PATH)
});

View File

@@ -1,12 +1,13 @@
use std::sync::LazyLock;
use glam::Vec4;
use once_cell::sync::Lazy;
pub mod canvas;
pub mod font;
pub mod modular;
pub type GuiColor = Vec4;
pub static FALLBACK_COLOR: Lazy<GuiColor> = Lazy::new(|| Vec4::new(1., 0., 1., 1.));
pub static FALLBACK_COLOR: LazyLock<GuiColor> = LazyLock::new(|| Vec4::new(1., 0., 1., 1.));
// Parses a color from a HTML hex string
pub fn color_parse(html_hex: &str) -> anyhow::Result<GuiColor> {

View File

@@ -6,9 +6,9 @@ use input_linux::{
UInputHandle,
};
use libc::{input_event, timeval};
use once_cell::sync::Lazy;
use serde::Deserialize;
use std::mem::transmute;
use std::sync::LazyLock;
use std::{fs::File, sync::atomic::AtomicBool};
use strum::{EnumIter, EnumString, IntoEnumIterator};
use xkbcommon::xkb;
@@ -476,7 +476,7 @@ pub enum VirtualKey {
XF86Search = 225,
}
pub static KEYS_TO_MODS: Lazy<IdMap<VirtualKey, KeyModifier>> = Lazy::new(|| {
pub static KEYS_TO_MODS: LazyLock<IdMap<VirtualKey, KeyModifier>> = LazyLock::new(|| {
idmap! {
VirtualKey::LShift => SHIFT,
VirtualKey::RShift => SHIFT,
@@ -491,7 +491,7 @@ pub static KEYS_TO_MODS: Lazy<IdMap<VirtualKey, KeyModifier>> = Lazy::new(|| {
}
});
pub static MODS_TO_KEYS: Lazy<IdMap<KeyModifier, Vec<VirtualKey>>> = Lazy::new(|| {
pub static MODS_TO_KEYS: LazyLock<IdMap<KeyModifier, Vec<VirtualKey>>> = LazyLock::new(|| {
idmap! {
SHIFT => vec![VirtualKey::LShift, VirtualKey::RShift],
CAPS_LOCK => vec![VirtualKey::Caps],

View File

@@ -1,13 +1,12 @@
use glam::Vec3A;
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};
use crate::backend::overlay::{OverlayData, OverlayState, RelativeTo, Z_ORDER_ANCHOR};
use crate::config::{load_known_yaml, ConfigType};
use crate::gui::modular::{modular_canvas, ModularUiConfig};
use crate::state::AppState;
pub static ANCHOR_NAME: Lazy<Arc<str>> = Lazy::new(|| Arc::from("anchor"));
pub static ANCHOR_NAME: LazyLock<Arc<str>> = LazyLock::new(|| Arc::from("anchor"));
pub fn create_anchor<O>(state: &mut AppState) -> anyhow::Result<OverlayData<O>>
where

View File

@@ -2,7 +2,7 @@ use std::{
collections::HashMap,
process::{Child, Command},
str::FromStr,
sync::Arc,
sync::{Arc, LazyLock},
};
use crate::{
@@ -25,7 +25,6 @@ use crate::{
state::{AppState, KeyboardFocus},
};
use glam::{vec2, vec3a, Affine2, Vec4};
use once_cell::sync::Lazy;
use regex::Regex;
use serde::{Deserialize, Serialize};
use vulkano::image::view::ImageView;
@@ -378,10 +377,10 @@ enum KeyButtonData {
},
}
static LAYOUT: Lazy<Layout> = Lazy::new(Layout::load_from_disk);
static LAYOUT: LazyLock<Layout> = LazyLock::new(Layout::load_from_disk);
static MACRO_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^([A-Za-z0-9_-]+)(?: +(UP|DOWN))?$").unwrap()); // want panic
static MACRO_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^([A-Za-z0-9_-]+)(?: +(UP|DOWN))?$").unwrap()); // want panic
#[derive(Debug, Default, Clone, Copy, Deserialize, Serialize)]
#[repr(usize)]

View File

@@ -1,10 +1,9 @@
use core::slice;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::{
f32::consts::PI,
ptr,
sync::{atomic::AtomicU64, Arc},
sync::{atomic::AtomicU64, Arc, LazyLock},
time::{Duration, Instant},
};
use vulkano::{
@@ -16,10 +15,7 @@ use vulkano::{
use wlx_capture::frame as wlx_frame;
use wlx_capture::{
frame::{
DrmFormat, FrameFormat, MouseMeta, WlxFrame, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR8888,
DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
},
frame::{FrameFormat, MouseMeta, WlxFrame},
WlxCapture,
};
@@ -57,8 +53,7 @@ use crate::{
},
config::{def_pw_tokens, GeneralConfig, PwTokenMap},
graphics::{
fourcc_to_vk, CommandBuffers, WlxCommandBuffer, WlxGraphics, WlxPipeline,
DRM_FORMAT_MOD_INVALID, SWAPCHAIN_FORMAT,
fourcc_to_vk, CommandBuffers, WlxCommandBuffer, WlxGraphics, WlxPipeline, SWAPCHAIN_FORMAT,
},
hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT},
state::{AppSession, AppState, KeyboardFocus, ScreenMeta},
@@ -72,7 +67,7 @@ pub(crate) type WlxClientAlias = ();
const CURSOR_SIZE: f32 = 16. / 1440.;
static START: Lazy<Instant> = Lazy::new(Instant::now);
static START: LazyLock<Instant> = LazyLock::new(Instant::now);
static NEXT_MOVE: AtomicU64 = AtomicU64::new(0);
fn can_move() -> bool {

View File

@@ -1,8 +1,12 @@
use std::{f32::consts::PI, ops::Add, sync::Arc, time::Instant};
use std::{
f32::consts::PI,
ops::Add,
sync::{Arc, LazyLock},
time::Instant,
};
use glam::{vec3a, Quat};
use idmap_derive::IntegerId;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use crate::{
@@ -18,7 +22,7 @@ use crate::{
const FONT_SIZE: isize = 16;
const PADDING: (f32, f32) = (25., 7.);
const PIXELS_TO_METERS: f32 = 1. / 2000.;
static TOAST_NAME: Lazy<Arc<str>> = Lazy::new(|| "toast".into());
static TOAST_NAME: LazyLock<Arc<str>> = LazyLock::new(|| "toast".into());
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum DisplayMethod {