diff --git a/Cargo.toml b/Cargo.toml index 68f2153..e3ee56a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,6 @@ edition = "2021" [dependencies] log = "0.4.14" -once_cell = "1.9.0" atomic = "0.5.1" cgmath = "0.18.0" libc = "0.2.69" diff --git a/examples/demo.rs b/examples/demo.rs index f9c3b82..fd700e3 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -18,7 +18,7 @@ use libremarkable::stopwatch; use atomic::Atomic; use chrono::{DateTime, Local}; use log::info; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use std::collections::VecDeque; use std::fmt; @@ -100,16 +100,16 @@ const CANVAS_REGION: mxcfb_rect = mxcfb_rect { type PointAndPressure = (cgmath::Point2, i32); -static G_TOUCH_MODE: Lazy> = Lazy::new(|| Atomic::new(TouchMode::OnlyUI)); -static G_DRAW_MODE: Lazy> = Lazy::new(|| Atomic::new(DrawMode::Draw(2))); -static UNPRESS_OBSERVED: Lazy = Lazy::new(|| AtomicBool::new(false)); -static WACOM_IN_RANGE: Lazy = Lazy::new(|| AtomicBool::new(false)); -static WACOM_RUBBER_SIDE: Lazy = Lazy::new(|| AtomicBool::new(false)); -static WACOM_HISTORY: Lazy>> = - Lazy::new(|| Mutex::new(VecDeque::new())); -static G_COUNTER: Lazy> = Lazy::new(|| Mutex::new(0)); -static SAVED_CANVAS: Lazy>> = - Lazy::new(|| Mutex::new(None)); +static G_TOUCH_MODE: LazyLock> = LazyLock::new(|| Atomic::new(TouchMode::OnlyUI)); +static G_DRAW_MODE: LazyLock> = LazyLock::new(|| Atomic::new(DrawMode::Draw(2))); +static UNPRESS_OBSERVED: LazyLock = LazyLock::new(|| AtomicBool::new(false)); +static WACOM_IN_RANGE: LazyLock = LazyLock::new(|| AtomicBool::new(false)); +static WACOM_RUBBER_SIDE: LazyLock = LazyLock::new(|| AtomicBool::new(false)); +static WACOM_HISTORY: LazyLock>> = + LazyLock::new(|| Mutex::new(VecDeque::new())); +static G_COUNTER: LazyLock> = LazyLock::new(|| Mutex::new(0)); +static SAVED_CANVAS: LazyLock>> = + LazyLock::new(|| Mutex::new(None)); // #################### // ## Button Handlers diff --git a/examples/spy.rs b/examples/spy.rs index a180835..1931adf 100644 --- a/examples/spy.rs +++ b/examples/spy.rs @@ -3,30 +3,30 @@ use std::sync::Mutex; use libc::c_int; use libc::intptr_t; -use once_cell::sync::Lazy; use redhook::{hook, real}; +use std::sync::LazyLock; use libremarkable::framebuffer::common::*; use libremarkable::framebuffer::mxcfb::*; use libremarkable::framebuffer::screeninfo::VarScreeninfo; -static DIST_DITHER: Lazy>> = Lazy::new(|| { +static DIST_DITHER: LazyLock>> = LazyLock::new(|| { let m = HashMap::new(); Mutex::new(m) }); -static DIST_WAVEFORM: Lazy>> = Lazy::new(|| { +static DIST_WAVEFORM: LazyLock>> = LazyLock::new(|| { let m = HashMap::new(); Mutex::new(m) }); -static DIST_QUANT: Lazy>> = Lazy::new(|| { +static DIST_QUANT: LazyLock>> = LazyLock::new(|| { let m = HashMap::new(); Mutex::new(m) }); -static DIST_FLAGS: Lazy>> = Lazy::new(|| { +static DIST_FLAGS: LazyLock>> = LazyLock::new(|| { let m = HashMap::new(); Mutex::new(m) }); -static DIST_TEMP: Lazy>> = Lazy::new(|| { +static DIST_TEMP: LazyLock>> = LazyLock::new(|| { let m = HashMap::new(); Mutex::new(m) }); diff --git a/src/device/mod.rs b/src/device/mod.rs index 5ac7801..f2b5acb 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use rotate::InputDeviceRotation; +use std::sync::LazyLock; /// Utility for rotating pub mod rotate; @@ -52,7 +52,7 @@ impl Model { } } -pub static CURRENT_DEVICE: Lazy = Lazy::new(Device::new); +pub static CURRENT_DEVICE: LazyLock = LazyLock::new(Device::new); /// Differentiate between the reasons why the determination of the current device model can fail. #[derive(Debug)] diff --git a/src/dimensions.rs b/src/dimensions.rs index 26a5c69..db96f8b 100644 --- a/src/dimensions.rs +++ b/src/dimensions.rs @@ -1,21 +1,21 @@ #[cfg(feature = "input")] use crate::input::scan::SCANNED; #[cfg(feature = "input")] -use once_cell::sync::Lazy; +use std::sync::LazyLock; pub const DISPLAYWIDTH: u16 = 1404; pub const DISPLAYHEIGHT: u16 = 1872; /// Will be 767 rM1 and 1403 on the rM2 #[cfg(feature = "input")] -pub static MTWIDTH: Lazy = Lazy::new(|| SCANNED.mt_width); +pub static MTWIDTH: LazyLock = LazyLock::new(|| SCANNED.mt_width); /// Will be 1023 the rM1 and 1871 on the rM2 #[cfg(feature = "input")] -pub static MTHEIGHT: Lazy = Lazy::new(|| SCANNED.mt_height); +pub static MTHEIGHT: LazyLock = LazyLock::new(|| SCANNED.mt_height); /// Will be 15725 on both the rM1 and rM2 #[cfg(feature = "input")] -pub static WACOMWIDTH: Lazy = Lazy::new(|| SCANNED.wacom_width); +pub static WACOMWIDTH: LazyLock = LazyLock::new(|| SCANNED.wacom_width); /// Will be 20967 on the rM1 and 20966 on the rM2 #[cfg(feature = "input")] -pub static WACOMHEIGHT: Lazy = Lazy::new(|| SCANNED.wacom_height); +pub static WACOMHEIGHT: LazyLock = LazyLock::new(|| SCANNED.wacom_height); diff --git a/src/framebuffer/draw.rs b/src/framebuffer/draw.rs index 5ea3135..49ab9b0 100644 --- a/src/framebuffer/draw.rs +++ b/src/framebuffer/draw.rs @@ -1,10 +1,10 @@ #[cfg(feature = "image")] use image::RgbImage; -#[cfg(feature = "framebuffer-text-drawing")] -use once_cell::sync::Lazy; #[cfg(feature = "framebuffer-text-drawing")] use rusttype::{point, Font, Scale}; +#[cfg(feature = "framebuffer-text-drawing")] +use std::sync::LazyLock; use crate::framebuffer; use crate::framebuffer::cgmath::*; @@ -14,7 +14,7 @@ use crate::framebuffer::graphics; use crate::framebuffer::FramebufferIO; #[cfg(feature = "framebuffer-text-drawing")] -pub static DEFAULT_FONT: Lazy> = Lazy::new(|| { +pub static DEFAULT_FONT: LazyLock> = LazyLock::new(|| { Font::try_from_bytes(include_bytes!("../../assets/Roboto-Regular.ttf").as_slice()) .expect("corrupted font data") }); diff --git a/src/input/multitouch.rs b/src/input/multitouch.rs index 20a5264..0f5909c 100644 --- a/src/input/multitouch.rs +++ b/src/input/multitouch.rs @@ -4,7 +4,7 @@ use crate::device::CURRENT_DEVICE; use crate::dimensions::{DISPLAYHEIGHT, DISPLAYWIDTH, MTHEIGHT, MTWIDTH}; use crate::input::scan::SCANNED; use crate::input::{Finger, InputDeviceState, InputEvent, MultitouchEvent}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use evdev::InputEvent as EvInputEvent; use fxhash::FxHashMap; @@ -14,8 +14,9 @@ use std::sync::{ Mutex, }; -static MT_HSCALAR: Lazy = Lazy::new(|| f32::from(DISPLAYWIDTH) / f32::from(*MTWIDTH)); -static MT_VSCALAR: Lazy = Lazy::new(|| f32::from(DISPLAYHEIGHT) / f32::from(*MTHEIGHT)); +static MT_HSCALAR: LazyLock = LazyLock::new(|| f32::from(DISPLAYWIDTH) / f32::from(*MTWIDTH)); +static MT_VSCALAR: LazyLock = + LazyLock::new(|| f32::from(DISPLAYHEIGHT) / f32::from(*MTHEIGHT)); pub struct MultitouchState { fingers: Mutex>, diff --git a/src/input/scan.rs b/src/input/scan.rs index 5a12b86..dca3131 100644 --- a/src/input/scan.rs +++ b/src/input/scan.rs @@ -2,15 +2,15 @@ use super::ecodes; use super::InputDevice; use cgmath::Vector2; use log::debug; -use once_cell::sync::Lazy; use std::path::{Path, PathBuf}; +use std::sync::LazyLock; use std::sync::{Arc, Mutex}; use std::time::Duration; pub const INITIAL_DEVS_AVAILABLE_FOR: Duration = Duration::from_millis(150); /// A singleton of the EvDevsScan object -pub static SCANNED: Lazy = Lazy::new(EvDevs::new); +pub static SCANNED: LazyLock = LazyLock::new(EvDevs::new); /// This struct contains the results of initially scaning all evdev devices, /// which allows for device model independancy. diff --git a/src/input/wacom.rs b/src/input/wacom.rs index 36bed02..1a2184e 100644 --- a/src/input/wacom.rs +++ b/src/input/wacom.rs @@ -6,14 +6,16 @@ use crate::input::{InputDeviceState, InputEvent, WacomEvent, WacomPen}; use atomic::Atomic; use evdev::InputEvent as EvInputEvent; use log::debug; -use once_cell::sync::Lazy; use std::sync::atomic::{AtomicU16, Ordering}; +use std::sync::LazyLock; use crate::cgmath; use crate::dimensions::{DISPLAYHEIGHT, DISPLAYWIDTH, WACOMHEIGHT, WACOMWIDTH}; -static WACOM_HSCALAR: Lazy = Lazy::new(|| f32::from(DISPLAYWIDTH) / f32::from(*WACOMWIDTH)); -static WACOM_VSCALAR: Lazy = Lazy::new(|| f32::from(DISPLAYHEIGHT) / f32::from(*WACOMHEIGHT)); +static WACOM_HSCALAR: LazyLock = + LazyLock::new(|| f32::from(DISPLAYWIDTH) / f32::from(*WACOMWIDTH)); +static WACOM_VSCALAR: LazyLock = + LazyLock::new(|| f32::from(DISPLAYHEIGHT) / f32::from(*WACOMHEIGHT)); pub struct WacomState { last_x: AtomicU16,