Remove parking_lot dependency (#2423)
This commit is contained in:
parent
ec7e935248
commit
8729119536
16 changed files with 197 additions and 175 deletions
|
|
@ -1,6 +1,5 @@
|
|||
#![cfg(target_os = "windows")]
|
||||
|
||||
use parking_lot::Mutex;
|
||||
use raw_window_handle::{
|
||||
RawDisplayHandle, RawWindowHandle, Win32WindowHandle, WindowsDisplayHandle,
|
||||
};
|
||||
|
|
@ -8,7 +7,7 @@ use std::{
|
|||
cell::Cell,
|
||||
ffi::c_void,
|
||||
io, mem, panic, ptr,
|
||||
sync::{mpsc::channel, Arc},
|
||||
sync::{mpsc::channel, Arc, Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
use windows_sys::Win32::{
|
||||
|
|
@ -99,6 +98,10 @@ impl Window {
|
|||
unsafe { init(w_attr, pl_attr, event_loop) }
|
||||
}
|
||||
|
||||
fn window_state_lock(&self) -> MutexGuard<'_, WindowState> {
|
||||
self.window_state.lock().unwrap()
|
||||
}
|
||||
|
||||
pub fn set_title(&self, text: &str) {
|
||||
let wide_text = util::encode_wide(text);
|
||||
unsafe {
|
||||
|
|
@ -112,7 +115,7 @@ impl Window {
|
|||
let window_state = Arc::clone(&self.window_state);
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::VISIBLE, visible)
|
||||
});
|
||||
});
|
||||
|
|
@ -154,7 +157,7 @@ impl Window {
|
|||
let window = self.window.clone();
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, false)
|
||||
});
|
||||
});
|
||||
|
|
@ -207,18 +210,18 @@ impl Window {
|
|||
let window = self.window.clone();
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, false)
|
||||
});
|
||||
});
|
||||
|
||||
let window_flags = self.window_state.lock().window_flags;
|
||||
let window_flags = self.window_state_lock().window_flags;
|
||||
window_flags.set_size(self.hwnd(), physical_size);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_min_inner_size(&self, size: Option<Size>) {
|
||||
self.window_state.lock().min_size = size;
|
||||
self.window_state_lock().min_size = size;
|
||||
// Make windows re-check the window size bounds.
|
||||
let size = self.inner_size();
|
||||
self.set_inner_size(size.into());
|
||||
|
|
@ -226,7 +229,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn set_max_inner_size(&self, size: Option<Size>) {
|
||||
self.window_state.lock().max_size = size;
|
||||
self.window_state_lock().max_size = size;
|
||||
// Make windows re-check the window size bounds.
|
||||
let size = self.inner_size();
|
||||
self.set_inner_size(size.into());
|
||||
|
|
@ -239,7 +242,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::RESIZABLE, resizable)
|
||||
});
|
||||
});
|
||||
|
|
@ -247,7 +250,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn is_resizable(&self) -> bool {
|
||||
let window_state = self.window_state.lock();
|
||||
let window_state = self.window_state_lock();
|
||||
window_state.window_flags.contains(WindowFlags::RESIZABLE)
|
||||
}
|
||||
|
||||
|
|
@ -277,7 +280,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
||||
self.window_state.lock().mouse.cursor = cursor;
|
||||
self.window_state_lock().mouse.cursor = cursor;
|
||||
self.thread_executor.execute_in_thread(move || unsafe {
|
||||
let cursor = LoadCursorW(0, cursor.to_windows_cursor());
|
||||
SetCursor(cursor);
|
||||
|
|
@ -302,6 +305,7 @@ impl Window {
|
|||
let _ = &window;
|
||||
let result = window_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.mouse
|
||||
.set_cursor_flags(window.0, |f| f.set(CursorFlags::GRABBED, confine))
|
||||
.map_err(|e| ExternalError::Os(os_error!(e)));
|
||||
|
|
@ -320,6 +324,7 @@ impl Window {
|
|||
let _ = &window;
|
||||
let result = window_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.mouse
|
||||
.set_cursor_flags(window.0, |f| f.set(CursorFlags::HIDDEN, !visible))
|
||||
.map_err(|e| e.to_string());
|
||||
|
|
@ -330,7 +335,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn scale_factor(&self) -> f64 {
|
||||
self.window_state.lock().scale_factor
|
||||
self.window_state_lock().scale_factor
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -379,7 +384,7 @@ impl Window {
|
|||
let window = self.window.clone();
|
||||
let window_state = Arc::clone(&self.window_state);
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest)
|
||||
});
|
||||
});
|
||||
|
|
@ -399,7 +404,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MINIMIZED, minimized)
|
||||
});
|
||||
});
|
||||
|
|
@ -412,7 +417,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, maximized)
|
||||
});
|
||||
});
|
||||
|
|
@ -420,13 +425,13 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn is_maximized(&self) -> bool {
|
||||
let window_state = self.window_state.lock();
|
||||
let window_state = self.window_state_lock();
|
||||
window_state.window_flags.contains(WindowFlags::MAXIMIZED)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
||||
let window_state = self.window_state.lock();
|
||||
let window_state = self.window_state_lock();
|
||||
window_state.fullscreen.clone()
|
||||
}
|
||||
|
||||
|
|
@ -435,7 +440,7 @@ impl Window {
|
|||
let window = self.window.clone();
|
||||
let window_state = Arc::clone(&self.window_state);
|
||||
|
||||
let mut window_state_lock = window_state.lock();
|
||||
let mut window_state_lock = window_state.lock().unwrap();
|
||||
let old_fullscreen = window_state_lock.fullscreen.clone();
|
||||
if window_state_lock.fullscreen == fullscreen {
|
||||
return;
|
||||
|
|
@ -502,7 +507,7 @@ impl Window {
|
|||
}
|
||||
|
||||
// Update window style
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(
|
||||
WindowFlags::MARKER_EXCLUSIVE_FULLSCREEN,
|
||||
matches!(fullscreen, Some(Fullscreen::Exclusive(_))),
|
||||
|
|
@ -531,7 +536,7 @@ impl Window {
|
|||
placement
|
||||
};
|
||||
|
||||
window_state.lock().saved_window = Some(SavedWindow { placement });
|
||||
window_state.lock().unwrap().saved_window = Some(SavedWindow { placement });
|
||||
|
||||
let monitor = match &fullscreen {
|
||||
Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
|
||||
|
|
@ -558,7 +563,7 @@ impl Window {
|
|||
}
|
||||
}
|
||||
None => {
|
||||
let mut window_state_lock = window_state.lock();
|
||||
let mut window_state_lock = window_state.lock().unwrap();
|
||||
if let Some(SavedWindow { placement }) = window_state_lock.saved_window.take() {
|
||||
drop(window_state_lock);
|
||||
unsafe {
|
||||
|
|
@ -578,7 +583,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MARKER_DECORATIONS, decorations)
|
||||
});
|
||||
});
|
||||
|
|
@ -586,7 +591,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn is_decorated(&self) -> bool {
|
||||
let window_state = self.window_state.lock();
|
||||
let window_state = self.window_state_lock();
|
||||
window_state
|
||||
.window_flags
|
||||
.contains(WindowFlags::MARKER_DECORATIONS)
|
||||
|
|
@ -599,7 +604,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::ALWAYS_ON_TOP, always_on_top)
|
||||
});
|
||||
});
|
||||
|
|
@ -621,7 +626,7 @@ impl Window {
|
|||
} else {
|
||||
icon::unset_for_window(self.hwnd(), IconType::Small);
|
||||
}
|
||||
self.window_state.lock().window_icon = window_icon;
|
||||
self.window_state_lock().window_icon = window_icon;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -638,7 +643,7 @@ impl Window {
|
|||
} else {
|
||||
icon::unset_for_window(self.hwnd(), IconType::Big);
|
||||
}
|
||||
self.window_state.lock().taskbar_icon = taskbar_icon;
|
||||
self.window_state_lock().taskbar_icon = taskbar_icon;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -650,7 +655,7 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn set_ime_allowed(&self, allowed: bool) {
|
||||
self.window_state.lock().ime_allowed = allowed;
|
||||
self.window_state_lock().ime_allowed = allowed;
|
||||
unsafe {
|
||||
ImeContext::set_ime_allowed(self.hwnd(), allowed);
|
||||
}
|
||||
|
|
@ -686,12 +691,12 @@ impl Window {
|
|||
|
||||
#[inline]
|
||||
pub fn theme(&self) -> Theme {
|
||||
self.window_state.lock().current_theme
|
||||
self.window_state_lock().current_theme
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_skip_taskbar(&self, skip: bool) {
|
||||
self.window_state.lock().skip_taskbar = skip;
|
||||
self.window_state_lock().skip_taskbar = skip;
|
||||
unsafe { set_skip_taskbar(self.hwnd(), skip) };
|
||||
}
|
||||
|
||||
|
|
@ -702,7 +707,7 @@ impl Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock(), window.0, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
||||
f.set(WindowFlags::MARKER_UNDECORATED_SHADOW, shadow)
|
||||
});
|
||||
});
|
||||
|
|
@ -711,7 +716,7 @@ impl Window {
|
|||
#[inline]
|
||||
pub fn focus_window(&self) {
|
||||
let window = self.window.clone();
|
||||
let window_flags = self.window_state.lock().window_flags();
|
||||
let window_flags = self.window_state_lock().window_flags();
|
||||
|
||||
let is_visible = window_flags.contains(WindowFlags::VISIBLE);
|
||||
let is_minimized = window_flags.contains(WindowFlags::MINIMIZED);
|
||||
|
|
@ -783,7 +788,9 @@ impl<'a, T: 'static> InitData<'a, T> {
|
|||
self.pl_attribs.preferred_theme,
|
||||
);
|
||||
let window_state = Arc::new(Mutex::new(window_state));
|
||||
WindowState::set_window_flags(window_state.lock(), window, |f| *f = self.window_flags);
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
*f = self.window_flags
|
||||
});
|
||||
window_state
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue