1use fltk_sys::fl;
2use std::sync::{
3 Arc, LazyLock, Mutex,
4 atomic::{AtomicBool, Ordering},
5};
6
7pub(crate) static IS_INIT: AtomicBool = AtomicBool::new(false);
9
10pub(crate) static FONTS: LazyLock<Arc<Mutex<Vec<String>>>> = LazyLock::new(|| {
12 Arc::from(Mutex::from(vec![
13 "Helvetica".to_owned(),
14 "HelveticaBold".to_owned(),
15 "HelveticaItalic".to_owned(),
16 "HelveticaBoldItalic".to_owned(),
17 "Courier".to_owned(),
18 "CourierBold".to_owned(),
19 "CourierItalic".to_owned(),
20 "CourierBoldItalic".to_owned(),
21 "Times".to_owned(),
22 "TimesBold".to_owned(),
23 "TimesItalic".to_owned(),
24 "TimesBoldItalic".to_owned(),
25 "Symbol".to_owned(),
26 "Screen".to_owned(),
27 "ScreenBold".to_owned(),
28 "Zapfdingbats".to_owned(),
29 ]))
30});
31static UI_THREAD: LazyLock<std::thread::ThreadId> = LazyLock::new(|| std::thread::current().id());
32
33pub fn init_all() {
38 unsafe {
39 fl::Fl_init_all();
40 #[cfg(not(feature = "single-threaded"))]
41 assert!((fl::Fl_lock() == 0), "fltk-rs requires threading support!");
42 #[cfg(feature = "enable-glwindow")]
43 {
44 unsafe extern "C" {
45 pub fn open_gl() -> i32;
46 }
47 open_gl();
48 }
49 if !IS_INIT.load(Ordering::Relaxed) {
50 IS_INIT.store(true, Ordering::Relaxed);
51 }
52 }
53}
54
55#[doc(hidden)]
56pub fn is_ui_thread() -> bool {
58 *UI_THREAD == std::thread::current().id()
59}
60
61pub fn is_initialized() -> bool {
63 IS_INIT.load(Ordering::Relaxed)
64}
65
66pub fn disable_wayland() {
69 unsafe { fl::Fl_disable_wayland() }
70}