Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ bitflags = "2"
cursor-icon = "1.1.0"
log = "0.4"
mint = { version = "0.5.6", optional = true }
once_cell = "1.12"
rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true }
rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = ["std"], optional = true }
rwh_06 = { package = "raw-window-handle", version = "0.6", features = ["std"], optional = true }
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ mod icon;
pub mod keyboard;
pub mod monitor;
mod platform_impl;
mod utils;
pub mod window;

pub mod platform;
2 changes: 1 addition & 1 deletion src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use std::{
time::{Duration, Instant},
};

use crate::utils::Lazy;
use android_activity::input::{InputEvent, KeyAction, Keycode, MotionAction};
use android_activity::{
AndroidApp, AndroidAppWaker, ConfigurationRef, InputStatus, MainEvent, Rect,
};
use log::{debug, trace, warn};
use once_cell::sync::Lazy;

use crate::{
cursor::Cursor,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/ios/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{
time::Instant,
};

use crate::utils::Lazy;
use core_foundation::base::CFRelease;
use core_foundation::date::CFAbsoluteTimeGetCurrent;
use core_foundation::runloop::{
Expand All @@ -22,7 +23,6 @@ use icrate::Foundation::{
use objc2::rc::Id;
use objc2::runtime::AnyObject;
use objc2::{msg_send, sel};
use once_cell::sync::Lazy;

use super::uikit::UIView;
use super::window::WinitUIWindow;
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/common/xkb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::os::raw::c_char;
use std::ptr::{self, NonNull};
use std::sync::atomic::{AtomicBool, Ordering};

use crate::utils::Lazy;
use log::warn;
use once_cell::sync::Lazy;
use smol_str::SmolStr;
#[cfg(wayland_platform)]
use std::os::unix::io::OwnedFd;
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{collections::VecDeque, env, fmt};
use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Mutex};

#[cfg(x11_platform)]
use once_cell::sync::Lazy;
use crate::utils::Lazy;
use smol_str::SmolStr;

#[cfg(x11_platform)]
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/ime/input_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use super::{super::atoms::*, ffi, util, XConnection, XError};
use once_cell::sync::Lazy;
use crate::utils::Lazy;
use x11rb::protocol::xproto;

static GLOBAL_LOCK: Lazy<Mutex<()>> = Lazy::new(Default::default);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/linux/x11/util/wm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Mutex;

use once_cell::sync::Lazy;
use crate::utils::Lazy;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::Lazy;
use icrate::AppKit::{NSBitmapImageRep, NSCursor, NSDeviceRGBColorSpace, NSImage};
use icrate::Foundation::{
ns_string, NSData, NSDictionary, NSNumber, NSObject, NSObjectProtocol, NSPoint, NSSize,
Expand All @@ -6,7 +7,6 @@ use icrate::Foundation::{
use objc2::rc::Id;
use objc2::runtime::Sel;
use objc2::{msg_send_id, sel, ClassType};
use once_cell::sync::Lazy;
use std::ffi::c_uchar;
use std::slice;

Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// which is inspired by the solution in https://github.com/ysc3839/win32-darkmode
use std::{ffi::c_void, ptr};

use once_cell::sync::Lazy;
use crate::utils::Lazy;
use windows_sys::{
core::PCSTR,
Win32::{
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
time::{Duration, Instant},
};

use once_cell::sync::Lazy;
use crate::utils::Lazy;

use windows_sys::Win32::{
Devices::HumanInterfaceDevice::MOUSE_MOVE_RELATIVE,
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/keyboard_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{
sync::Mutex,
};

use once_cell::sync::Lazy;
use crate::utils::Lazy;
use smol_str::SmolStr;
use windows_sys::Win32::{
System::SystemServices::{LANG_JAPANESE, LANG_KOREAN},
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::atomic::{AtomicBool, Ordering},
};

use once_cell::sync::Lazy;
use crate::utils::Lazy;
use windows_sys::{
core::{HRESULT, PCWSTR},
Win32::{
Expand Down
33 changes: 33 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// A poly-fill for `lazy_cell`
// Replace with std::sync::LazyLock when https://github.com/rust-lang/rust/issues/109736 is stablized.

use std::cell::Cell;
use std::ops::Deref;
use std::sync::OnceLock;

pub(crate) struct Lazy<T, F = fn() -> T> {
cell: OnceLock<T>,
init: Cell<Option<F>>,
}

unsafe impl<T, F> Sync for Lazy<T, F> {}

impl<T, F: FnOnce() -> T> Lazy<T, F> {
pub const fn new(f: F) -> Self {
Self {
cell: OnceLock::new(),
init: Cell::new(Some(f)),
}
}
}

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
type Target = T;
#[inline]
fn deref(&self) -> &'_ T {
self.cell.get_or_init(|| match self.init.take() {
Some(f) => f(),
None => unreachable!(),
})
}
}