Remove parking_lot dependency (#2423)

This commit is contained in:
Mads Marquart 2022-08-31 18:32:19 +02:00 committed by GitHub
parent ec7e935248
commit 8729119536
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 197 additions and 175 deletions

View file

@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre
# Unreleased # Unreleased
- Removed `parking_lot` dependency.
- On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window. - On Windows, added `WindowExtWindows::set_undecorated_shadow` and `WindowBuilderExtWindows::with_undecorated_shadow` to draw the drop shadow behind a borderless window.
- On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled. - On Windows, fixed default window features (ie snap, animations, shake, etc.) when decorations are disabled.
- **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`. - **Breaking:** On macOS, add support for two-finger touchpad magnification and rotation gestures with new events `WindowEvent::TouchpadMagnify` and `WindowEvent::TouchpadRotate`.

View file

@ -35,7 +35,7 @@ targets = [
[features] [features]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"] default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
x11 = ["x11-dl", "mio", "percent-encoding", "parking_lot"] x11 = ["x11-dl", "mio", "percent-encoding"]
wayland = ["wayland-client", "wayland-protocols", "sctk"] wayland = ["wayland-client", "wayland-protocols", "sctk"]
wayland-dlopen = ["sctk/dlopen", "wayland-client/dlopen"] wayland-dlopen = ["sctk/dlopen", "wayland-client/dlopen"]
wayland-csd-adwaita = ["sctk-adwaita", "sctk-adwaita/ab_glyph"] wayland-csd-adwaita = ["sctk-adwaita", "sctk-adwaita/ab_glyph"]
@ -70,9 +70,6 @@ core-foundation = "0.9"
core-graphics = "0.22" core-graphics = "0.22"
dispatch = "0.2.0" dispatch = "0.2.0"
[target.'cfg(target_os = "windows")'.dependencies]
parking_lot = "0.12"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys] [target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.36" version = "0.36"
features = [ features = [
@ -110,7 +107,6 @@ sctk-adwaita = { version = "0.5.1", default_features = false, optional = true }
mio = { version = "0.8", features = ["os-ext"], optional = true } mio = { version = "0.8", features = ["os-ext"], optional = true }
x11-dl = { version = "2.18.5", optional = true } x11-dl = { version = "2.18.5", optional = true }
percent-encoding = { version = "2.0", optional = true } percent-encoding = { version = "2.0", optional = true }
parking_lot = { version = "0.12.0", optional = true }
libc = "0.2.64" libc = "0.2.64"
[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys] [target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]

View file

@ -56,7 +56,7 @@ pub type XlibErrorHook =
pub fn register_xlib_error_hook(hook: XlibErrorHook) { pub fn register_xlib_error_hook(hook: XlibErrorHook) {
// Append new hook. // Append new hook.
unsafe { unsafe {
XLIB_ERROR_HOOKS.lock().push(hook); XLIB_ERROR_HOOKS.lock().unwrap().push(hook);
} }
} }

View file

@ -14,12 +14,15 @@ use std::error::Error;
use std::{collections::VecDeque, env, fmt}; use std::{collections::VecDeque, env, fmt};
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Arc}; use std::{
ffi::CStr,
mem::MaybeUninit,
os::raw::*,
sync::{Arc, Mutex},
};
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
#[cfg(feature = "x11")]
use parking_lot::Mutex;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
@ -595,11 +598,11 @@ unsafe extern "C" fn x_error_callback(
display: *mut x11::ffi::Display, display: *mut x11::ffi::Display,
event: *mut x11::ffi::XErrorEvent, event: *mut x11::ffi::XErrorEvent,
) -> c_int { ) -> c_int {
let xconn_lock = X11_BACKEND.lock(); let xconn_lock = X11_BACKEND.lock().unwrap();
if let Ok(ref xconn) = *xconn_lock { if let Ok(ref xconn) = *xconn_lock {
// Call all the hooks. // Call all the hooks.
let mut error_handled = false; let mut error_handled = false;
for hook in XLIB_ERROR_HOOKS.lock().iter() { for hook in XLIB_ERROR_HOOKS.lock().unwrap().iter() {
error_handled |= hook(display as *mut _, event as *mut _); error_handled |= hook(display as *mut _, event as *mut _);
} }
@ -626,7 +629,7 @@ unsafe extern "C" fn x_error_callback(
error!("X11 error: {:#?}", error); error!("X11 error: {:#?}", error);
} }
*xconn.latest_error.lock() = Some(error); *xconn.latest_error.lock().unwrap() = Some(error);
} }
// Fun fact: this return value is completely ignored. // Fun fact: this return value is completely ignored.
0 0
@ -729,7 +732,7 @@ impl<T: 'static> EventLoop<T> {
#[cfg(feature = "x11")] #[cfg(feature = "x11")]
fn new_x11_any_thread() -> Result<EventLoop<T>, XNotSupported> { fn new_x11_any_thread() -> Result<EventLoop<T>, XNotSupported> {
let xconn = match X11_BACKEND.lock().as_ref() { let xconn = match X11_BACKEND.lock().unwrap().as_ref() {
Ok(xconn) => xconn.clone(), Ok(xconn) => xconn.clone(),
Err(err) => return Err(err.clone()), Err(err) => return Err(err.clone()),
}; };

View file

@ -2,8 +2,6 @@ use std::{cell::RefCell, collections::HashMap, rc::Rc, slice, sync::Arc};
use libc::{c_char, c_int, c_long, c_uint, c_ulong}; use libc::{c_char, c_int, c_long, c_uint, c_ulong};
use parking_lot::MutexGuard;
use super::{ use super::{
events, ffi, get_xtarget, mkdid, mkwid, monitor, util, Device, DeviceId, DeviceInfo, Dnd, events, ffi, get_xtarget, mkdid, mkwid, monitor, util, Device, DeviceId, DeviceInfo, Dnd,
DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow, WindowId, DndState, GenericEventCookie, ImeReceiver, ScrollOrientation, UnownedWindow, WindowId,
@ -351,9 +349,9 @@ impl<T: 'static> EventProcessor<T> {
let new_inner_size = (xev.width as u32, xev.height as u32); let new_inner_size = (xev.width as u32, xev.height as u32);
let new_inner_position = (xev.x as i32, xev.y as i32); let new_inner_position = (xev.x as i32, xev.y as i32);
let mut shared_state_lock = window.shared_state.lock();
let (mut resized, moved) = { let (mut resized, moved) = {
let mut shared_state_lock = window.shared_state_lock();
let resized = let resized =
util::maybe_change(&mut shared_state_lock.size, new_inner_size); util::maybe_change(&mut shared_state_lock.size, new_inner_size);
let moved = if is_synthetic { let moved = if is_synthetic {
@ -380,7 +378,13 @@ impl<T: 'static> EventProcessor<T> {
(resized, moved) (resized, moved)
}; };
let new_outer_position = if moved || shared_state_lock.position.is_none() { let position = window.shared_state_lock().position;
let new_outer_position = if let (Some(position), false) = (position, moved) {
position
} else {
let mut shared_state_lock = window.shared_state_lock();
// We need to convert client area position to window position. // We need to convert client area position to window position.
let frame_extents = shared_state_lock let frame_extents = shared_state_lock
.frame_extents .frame_extents
@ -395,21 +399,21 @@ impl<T: 'static> EventProcessor<T> {
let outer = frame_extents let outer = frame_extents
.inner_pos_to_outer(new_inner_position.0, new_inner_position.1); .inner_pos_to_outer(new_inner_position.0, new_inner_position.1);
shared_state_lock.position = Some(outer); shared_state_lock.position = Some(outer);
// Unlock shared state to prevent deadlock in callback below
drop(shared_state_lock);
if moved { if moved {
// Temporarily unlock shared state to prevent deadlock callback(Event::WindowEvent {
MutexGuard::unlocked(&mut shared_state_lock, || { window_id,
callback(Event::WindowEvent { event: WindowEvent::Moved(outer.into()),
window_id,
event: WindowEvent::Moved(outer.into()),
});
}); });
} }
outer outer
} else {
shared_state_lock.position.unwrap()
}; };
if is_synthetic { if is_synthetic {
let mut shared_state_lock = window.shared_state_lock();
// If we don't use the existing adjusted value when available, then the user can screw up the // If we don't use the existing adjusted value when available, then the user can screw up the
// resizing by dragging across monitors *without* dropping the window. // resizing by dragging across monitors *without* dropping the window.
let (width, height) = shared_state_lock let (width, height) = shared_state_lock
@ -441,15 +445,15 @@ impl<T: 'static> EventProcessor<T> {
let old_inner_size = PhysicalSize::new(width, height); let old_inner_size = PhysicalSize::new(width, height);
let mut new_inner_size = PhysicalSize::new(new_width, new_height); let mut new_inner_size = PhysicalSize::new(new_width, new_height);
// Temporarily unlock shared state to prevent deadlock // Unlock shared state to prevent deadlock in callback below
MutexGuard::unlocked(&mut shared_state_lock, || { drop(shared_state_lock);
callback(Event::WindowEvent {
window_id, callback(Event::WindowEvent {
event: WindowEvent::ScaleFactorChanged { window_id,
scale_factor: new_scale_factor, event: WindowEvent::ScaleFactorChanged {
new_inner_size: &mut new_inner_size, scale_factor: new_scale_factor,
}, new_inner_size: &mut new_inner_size,
}); },
}); });
if new_inner_size != old_inner_size { if new_inner_size != old_inner_size {
@ -457,7 +461,8 @@ impl<T: 'static> EventProcessor<T> {
new_inner_size.width, new_inner_size.width,
new_inner_size.height, new_inner_size.height,
); );
shared_state_lock.dpi_adjusted = Some(new_inner_size.into()); window.shared_state_lock().dpi_adjusted =
Some(new_inner_size.into());
// if the DPI factor changed, force a resize event to ensure the logical // if the DPI factor changed, force a resize event to ensure the logical
// size is computed with the right DPI factor // size is computed with the right DPI factor
resized = true; resized = true;
@ -465,6 +470,8 @@ impl<T: 'static> EventProcessor<T> {
} }
} }
let mut shared_state_lock = window.shared_state_lock();
// This is a hack to ensure that the DPI adjusted resize is actually applied on all WMs. KWin // This is a hack to ensure that the DPI adjusted resize is actually applied on all WMs. KWin
// doesn't need this, but Xfwm does. The hack should not be run on other WMs, since tiling // doesn't need this, but Xfwm does. The hack should not be run on other WMs, since tiling
// WMs constrain the window size, making the resize fail. This would cause an endless stream of // WMs constrain the window size, making the resize fail. This would cause an endless stream of
@ -478,10 +485,10 @@ impl<T: 'static> EventProcessor<T> {
} }
} }
if resized { // Unlock shared state to prevent deadlock in callback below
// Drop the shared state lock to prevent deadlock drop(shared_state_lock);
drop(shared_state_lock);
if resized {
callback(Event::WindowEvent { callback(Event::WindowEvent {
window_id, window_id,
event: WindowEvent::Resized(new_inner_size.into()), event: WindowEvent::Resized(new_inner_size.into()),
@ -747,7 +754,7 @@ impl<T: 'static> EventProcessor<T> {
update_modifiers!(modifiers, None); update_modifiers!(modifiers, None);
let cursor_moved = self.with_window(xev.event, |window| { let cursor_moved = self.with_window(xev.event, |window| {
let mut shared_state_lock = window.shared_state.lock(); let mut shared_state_lock = window.shared_state_lock();
util::maybe_change(&mut shared_state_lock.cursor_pos, new_cursor_pos) util::maybe_change(&mut shared_state_lock.cursor_pos, new_cursor_pos)
}); });
if cursor_moved == Some(true) { if cursor_moved == Some(true) {
@ -1215,7 +1222,7 @@ impl<T: 'static> EventProcessor<T> {
new_monitor.scale_factor, new_monitor.scale_factor,
width, width,
height, height,
&*window.shared_state.lock(), &*window.shared_state_lock(),
); );
let window_id = crate::window::WindowId(*window_id); let window_id = crate::window::WindowId(*window_id);

View file

@ -4,11 +4,10 @@ use std::{
fmt, fmt,
os::raw::c_char, os::raw::c_char,
ptr, ptr,
sync::Arc, sync::{Arc, Mutex},
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex;
use super::{ffi, util, XConnection, XError}; use super::{ffi, util, XConnection, XError};

View file

@ -1,8 +1,8 @@
use std::os::raw::*; use std::os::raw::*;
use std::slice; use std::slice;
use std::sync::Mutex;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex;
use super::{ use super::{
ffi::{ ffi::{
@ -24,7 +24,7 @@ static MONITORS: Lazy<Mutex<Option<Vec<MonitorHandle>>>> = Lazy::new(Mutex::defa
pub fn invalidate_cached_monitor_list() -> Option<Vec<MonitorHandle>> { pub fn invalidate_cached_monitor_list() -> Option<Vec<MonitorHandle>> {
// We update this lazily. // We update this lazily.
(*MONITORS.lock()).take() (*MONITORS.lock().unwrap()).take()
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -293,7 +293,7 @@ impl XConnection {
} }
pub fn available_monitors(&self) -> Vec<MonitorHandle> { pub fn available_monitors(&self) -> Vec<MonitorHandle> {
let mut monitors_lock = MONITORS.lock(); let mut monitors_lock = MONITORS.lock().unwrap();
(*monitors_lock) (*monitors_lock)
.as_ref() .as_ref()
.cloned() .cloned()

View file

@ -3,10 +3,10 @@ use std::{
ffi::{CStr, CString}, ffi::{CStr, CString},
fmt::Debug, fmt::Debug,
os::raw::*, os::raw::*,
sync::Mutex,
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex;
use super::*; use super::*;
@ -17,7 +17,7 @@ static ATOM_CACHE: Lazy<Mutex<AtomCache>> = Lazy::new(|| Mutex::new(HashMap::wit
impl XConnection { impl XConnection {
pub fn get_atom<T: AsRef<CStr> + Debug>(&self, name: T) -> ffi::Atom { pub fn get_atom<T: AsRef<CStr> + Debug>(&self, name: T) -> ffi::Atom {
let name = name.as_ref(); let name = name.as_ref();
let mut atom_cache_lock = ATOM_CACHE.lock(); let mut atom_cache_lock = ATOM_CACHE.lock().unwrap();
let cached_atom = (*atom_cache_lock).get(name).cloned(); let cached_atom = (*atom_cache_lock).get(name).cloned();
if let Some(atom) = cached_atom { if let Some(atom) = cached_atom {
atom atom

View file

@ -7,6 +7,7 @@ impl XConnection {
let cursor = *self let cursor = *self
.cursor_cache .cursor_cache
.lock() .lock()
.unwrap()
.entry(cursor) .entry(cursor)
.or_insert_with(|| self.get_cursor(cursor)); .or_insert_with(|| self.get_cursor(cursor));

View file

@ -1,5 +1,6 @@
use std::sync::Mutex;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex;
use super::*; use super::*;
@ -9,11 +10,11 @@ static SUPPORTED_HINTS: Lazy<Mutex<Vec<ffi::Atom>>> =
static WM_NAME: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None)); static WM_NAME: Lazy<Mutex<Option<String>>> = Lazy::new(|| Mutex::new(None));
pub fn hint_is_supported(hint: ffi::Atom) -> bool { pub fn hint_is_supported(hint: ffi::Atom) -> bool {
(*SUPPORTED_HINTS.lock()).contains(&hint) (*SUPPORTED_HINTS.lock().unwrap()).contains(&hint)
} }
pub fn wm_name_is_one_of(names: &[&str]) -> bool { pub fn wm_name_is_one_of(names: &[&str]) -> bool {
if let Some(ref name) = *WM_NAME.lock() { if let Some(ref name) = *WM_NAME.lock().unwrap() {
names.contains(&name.as_str()) names.contains(&name.as_str())
} else { } else {
false false
@ -22,8 +23,8 @@ pub fn wm_name_is_one_of(names: &[&str]) -> bool {
impl XConnection { impl XConnection {
pub fn update_cached_wm_info(&self, root: ffi::Window) { pub fn update_cached_wm_info(&self, root: ffi::Window) {
*SUPPORTED_HINTS.lock() = self.get_supported_hints(root); *SUPPORTED_HINTS.lock().unwrap() = self.get_supported_hints(root);
*WM_NAME.lock() = self.get_wm_name(root); *WM_NAME.lock().unwrap() = self.get_wm_name(root);
} }
fn get_supported_hints(&self, root: ffi::Window) -> Vec<ffi::Atom> { fn get_supported_hints(&self, root: ffi::Window) -> Vec<ffi::Atom> {

View file

@ -5,11 +5,10 @@ use std::{
os::raw::*, os::raw::*,
path::Path, path::Path,
ptr, slice, ptr, slice,
sync::Arc, sync::{Arc, Mutex, MutexGuard},
}; };
use libc; use libc;
use parking_lot::Mutex;
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, XlibWindowHandle}; use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
use x11_dl::xlib::TrueColor; use x11_dl::xlib::TrueColor;
@ -107,6 +106,7 @@ pub struct UnownedWindow {
screen_id: i32, // never changes screen_id: i32, // never changes
cursor: Mutex<CursorIcon>, cursor: Mutex<CursorIcon>,
cursor_grabbed_mode: Mutex<CursorGrabMode>, cursor_grabbed_mode: Mutex<CursorGrabMode>,
#[allow(clippy::mutex_atomic)]
cursor_visible: Mutex<bool>, cursor_visible: Mutex<bool>,
ime_sender: Mutex<ImeSender>, ime_sender: Mutex<ImeSender>,
pub shared_state: Mutex<SharedState>, pub shared_state: Mutex<SharedState>,
@ -270,6 +270,7 @@ impl UnownedWindow {
) )
}; };
#[allow(clippy::mutex_atomic)]
let mut window = UnownedWindow { let mut window = UnownedWindow {
xconn: Arc::clone(xconn), xconn: Arc::clone(xconn),
xwindow, xwindow,
@ -374,7 +375,7 @@ impl UnownedWindow {
} }
} }
let mut shared_state = window.shared_state.get_mut(); let mut shared_state = window.shared_state.get_mut().unwrap();
shared_state.min_inner_size = min_inner_size.map(Into::into); shared_state.min_inner_size = min_inner_size.map(Into::into);
shared_state.max_inner_size = max_inner_size.map(Into::into); shared_state.max_inner_size = max_inner_size.map(Into::into);
shared_state.resize_increments = pl_attribs.resize_increments; shared_state.resize_increments = pl_attribs.resize_increments;
@ -480,7 +481,7 @@ impl UnownedWindow {
} }
if let Some(PhysicalPosition { x, y }) = position { if let Some(PhysicalPosition { x, y }) = position {
let shared_state = window.shared_state.get_mut(); let shared_state = window.shared_state.get_mut().unwrap();
shared_state.restore_position = Some((x, y)); shared_state.restore_position = Some((x, y));
} }
@ -499,6 +500,10 @@ impl UnownedWindow {
.map_err(|x_err| os_error!(OsError::XError(x_err))) .map_err(|x_err| os_error!(OsError::XError(x_err)))
} }
pub(super) fn shared_state_lock(&self) -> MutexGuard<'_, SharedState> {
self.shared_state.lock().unwrap()
}
fn set_pid(&self) -> Option<util::Flusher<'_>> { fn set_pid(&self) -> Option<util::Flusher<'_>> {
let pid_atom = unsafe { self.xconn.get_atom_unchecked(b"_NET_WM_PID\0") }; let pid_atom = unsafe { self.xconn.get_atom_unchecked(b"_NET_WM_PID\0") };
let client_machine_atom = unsafe { self.xconn.get_atom_unchecked(b"WM_CLIENT_MACHINE\0") }; let client_machine_atom = unsafe { self.xconn.get_atom_unchecked(b"WM_CLIENT_MACHINE\0") };
@ -611,7 +616,7 @@ impl UnownedWindow {
} }
fn set_fullscreen_inner(&self, fullscreen: Option<Fullscreen>) -> Option<util::Flusher<'_>> { fn set_fullscreen_inner(&self, fullscreen: Option<Fullscreen>) -> Option<util::Flusher<'_>> {
let mut shared_state_lock = self.shared_state.lock(); let mut shared_state_lock = self.shared_state_lock();
match shared_state_lock.visibility { match shared_state_lock.visibility {
// Setting fullscreen on a window that is not visible will generate an error. // Setting fullscreen on a window that is not visible will generate an error.
@ -665,7 +670,7 @@ impl UnownedWindow {
match fullscreen { match fullscreen {
None => { None => {
let flusher = self.set_fullscreen_hint(false); let flusher = self.set_fullscreen_hint(false);
let mut shared_state_lock = self.shared_state.lock(); let mut shared_state_lock = self.shared_state_lock();
if let Some(position) = shared_state_lock.restore_position.take() { if let Some(position) = shared_state_lock.restore_position.take() {
drop(shared_state_lock); drop(shared_state_lock);
self.set_position_inner(position.0, position.1).queue(); self.set_position_inner(position.0, position.1).queue();
@ -722,7 +727,7 @@ impl UnownedWindow {
} }
let window_position = self.outer_position_physical(); let window_position = self.outer_position_physical();
self.shared_state.lock().restore_position = Some(window_position); self.shared_state_lock().restore_position = Some(window_position);
let monitor_origin: (i32, i32) = monitor.position().into(); let monitor_origin: (i32, i32) = monitor.position().into();
self.set_position_inner(monitor_origin.0, monitor_origin.1) self.set_position_inner(monitor_origin.0, monitor_origin.1)
.queue(); .queue();
@ -733,7 +738,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> { pub fn fullscreen(&self) -> Option<Fullscreen> {
let shared_state = self.shared_state.lock(); let shared_state = self.shared_state_lock();
shared_state shared_state
.desired_fullscreen .desired_fullscreen
@ -753,7 +758,7 @@ impl UnownedWindow {
// Called by EventProcessor when a VisibilityNotify event is received // Called by EventProcessor when a VisibilityNotify event is received
pub(crate) fn visibility_notify(&self) { pub(crate) fn visibility_notify(&self) {
let mut shared_state = self.shared_state.lock(); let mut shared_state = self.shared_state_lock();
match shared_state.visibility { match shared_state.visibility {
Visibility::No => unsafe { Visibility::No => unsafe {
@ -773,7 +778,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn current_monitor(&self) -> X11MonitorHandle { pub fn current_monitor(&self) -> X11MonitorHandle {
self.shared_state.lock().last_monitor.clone() self.shared_state_lock().last_monitor.clone()
} }
pub fn available_monitors(&self) -> Vec<X11MonitorHandle> { pub fn available_monitors(&self) -> Vec<X11MonitorHandle> {
@ -888,7 +893,7 @@ impl UnownedWindow {
} }
fn set_decorations_inner(&self, decorations: bool) -> util::Flusher<'_> { fn set_decorations_inner(&self, decorations: bool) -> util::Flusher<'_> {
self.shared_state.lock().is_decorated = decorations; self.shared_state_lock().is_decorated = decorations;
let mut hints = self.xconn.get_motif_hints(self.xwindow); let mut hints = self.xconn.get_motif_hints(self.xwindow);
hints.set_decorations(decorations); hints.set_decorations(decorations);
@ -906,7 +911,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn is_decorated(&self) -> bool { pub fn is_decorated(&self) -> bool {
self.shared_state.lock().is_decorated self.shared_state_lock().is_decorated
} }
fn set_maximizable_inner(&self, maximizable: bool) -> util::Flusher<'_> { fn set_maximizable_inner(&self, maximizable: bool) -> util::Flusher<'_> {
@ -965,7 +970,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn set_visible(&self, visible: bool) { pub fn set_visible(&self, visible: bool) {
let mut shared_state = self.shared_state.lock(); let mut shared_state = self.shared_state_lock();
match (visible, shared_state.visibility) { match (visible, shared_state.visibility) {
(true, Visibility::Yes) | (true, Visibility::YesWait) | (false, Visibility::No) => { (true, Visibility::Yes) | (true, Visibility::YesWait) | (false, Visibility::No) => {
@ -995,22 +1000,22 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn is_visible(&self) -> Option<bool> { pub fn is_visible(&self) -> Option<bool> {
Some(self.shared_state.lock().visibility == Visibility::Yes) Some(self.shared_state_lock().visibility == Visibility::Yes)
} }
fn update_cached_frame_extents(&self) { fn update_cached_frame_extents(&self) {
let extents = self let extents = self
.xconn .xconn
.get_frame_extents_heuristic(self.xwindow, self.root); .get_frame_extents_heuristic(self.xwindow, self.root);
(*self.shared_state.lock()).frame_extents = Some(extents); (*self.shared_state_lock()).frame_extents = Some(extents);
} }
pub(crate) fn invalidate_cached_frame_extents(&self) { pub(crate) fn invalidate_cached_frame_extents(&self) {
(*self.shared_state.lock()).frame_extents.take(); (*self.shared_state_lock()).frame_extents.take();
} }
pub(crate) fn outer_position_physical(&self) -> (i32, i32) { pub(crate) fn outer_position_physical(&self) -> (i32, i32) {
let extents = (*self.shared_state.lock()).frame_extents.clone(); let extents = (*self.shared_state_lock()).frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
let (x, y) = self.inner_position_physical(); let (x, y) = self.inner_position_physical();
extents.inner_pos_to_outer(x, y) extents.inner_pos_to_outer(x, y)
@ -1022,7 +1027,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> {
let extents = (*self.shared_state.lock()).frame_extents.clone(); let extents = (*self.shared_state_lock()).frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
let (x, y) = self.inner_position_physical(); let (x, y) = self.inner_position_physical();
Ok(extents.inner_pos_to_outer(x, y).into()) Ok(extents.inner_pos_to_outer(x, y).into())
@ -1050,7 +1055,7 @@ impl UnownedWindow {
// There are a few WMs that set client area position rather than window position, so // There are a few WMs that set client area position rather than window position, so
// we'll translate for consistency. // we'll translate for consistency.
if util::wm_name_is_one_of(&["Enlightenment", "FVWM"]) { if util::wm_name_is_one_of(&["Enlightenment", "FVWM"]) {
let extents = (*self.shared_state.lock()).frame_extents.clone(); let extents = (*self.shared_state_lock()).frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
x += extents.frame_extents.left as i32; x += extents.frame_extents.left as i32;
y += extents.frame_extents.top as i32; y += extents.frame_extents.top as i32;
@ -1093,7 +1098,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn outer_size(&self) -> PhysicalSize<u32> { pub fn outer_size(&self) -> PhysicalSize<u32> {
let extents = self.shared_state.lock().frame_extents.clone(); let extents = self.shared_state_lock().frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
let (width, height) = self.inner_size_physical(); let (width, height) = self.inner_size_physical();
extents.inner_size_to_outer(width, height).into() extents.inner_size_to_outer(width, height).into()
@ -1120,7 +1125,7 @@ impl UnownedWindow {
pub fn set_inner_size(&self, size: Size) { pub fn set_inner_size(&self, size: Size) {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let size = size.to_physical::<u32>(scale_factor).into(); let size = size.to_physical::<u32>(scale_factor).into();
if !self.shared_state.lock().is_resizable { if !self.shared_state_lock().is_resizable {
self.update_normal_hints(|normal_hints| { self.update_normal_hints(|normal_hints| {
normal_hints.set_min_size(Some(size)); normal_hints.set_min_size(Some(size));
normal_hints.set_max_size(Some(size)); normal_hints.set_max_size(Some(size));
@ -1148,7 +1153,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn set_min_inner_size(&self, dimensions: Option<Size>) { pub fn set_min_inner_size(&self, dimensions: Option<Size>) {
self.shared_state.lock().min_inner_size = dimensions; self.shared_state_lock().min_inner_size = dimensions;
let physical_dimensions = let physical_dimensions =
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into()); dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
self.set_min_inner_size_physical(physical_dimensions); self.set_min_inner_size_physical(physical_dimensions);
@ -1161,7 +1166,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn set_max_inner_size(&self, dimensions: Option<Size>) { pub fn set_max_inner_size(&self, dimensions: Option<Size>) {
self.shared_state.lock().max_inner_size = dimensions; self.shared_state_lock().max_inner_size = dimensions;
let physical_dimensions = let physical_dimensions =
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into()); dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
self.set_max_inner_size_physical(physical_dimensions); self.set_max_inner_size_physical(physical_dimensions);
@ -1206,7 +1211,7 @@ impl UnownedWindow {
} }
let (min_size, max_size) = if resizable { let (min_size, max_size) = if resizable {
let shared_state_lock = self.shared_state.lock(); let shared_state_lock = self.shared_state_lock();
( (
shared_state_lock.min_inner_size, shared_state_lock.min_inner_size,
shared_state_lock.max_inner_size, shared_state_lock.max_inner_size,
@ -1215,7 +1220,7 @@ impl UnownedWindow {
let window_size = Some(Size::from(self.inner_size())); let window_size = Some(Size::from(self.inner_size()));
(window_size, window_size) (window_size, window_size)
}; };
self.shared_state.lock().is_resizable = resizable; self.shared_state_lock().is_resizable = resizable;
self.set_maximizable_inner(resizable).queue(); self.set_maximizable_inner(resizable).queue();
@ -1235,7 +1240,7 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn is_resizable(&self) -> bool { pub fn is_resizable(&self) -> bool {
self.shared_state.lock().is_resizable self.shared_state_lock().is_resizable
} }
#[inline] #[inline]
@ -1265,15 +1270,16 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn set_cursor_icon(&self, cursor: CursorIcon) { pub fn set_cursor_icon(&self, cursor: CursorIcon) {
let old_cursor = replace(&mut *self.cursor.lock(), cursor); let old_cursor = replace(&mut *self.cursor.lock().unwrap(), cursor);
if cursor != old_cursor && *self.cursor_visible.lock() { #[allow(clippy::mutex_atomic)]
if cursor != old_cursor && *self.cursor_visible.lock().unwrap() {
self.xconn.set_cursor_icon(self.xwindow, Some(cursor)); self.xconn.set_cursor_icon(self.xwindow, Some(cursor));
} }
} }
#[inline] #[inline]
pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> {
let mut grabbed_lock = self.cursor_grabbed_mode.lock(); let mut grabbed_lock = self.cursor_grabbed_mode.lock().unwrap();
if mode == *grabbed_lock { if mode == *grabbed_lock {
return Ok(()); return Ok(());
} }
@ -1346,12 +1352,13 @@ impl UnownedWindow {
#[inline] #[inline]
pub fn set_cursor_visible(&self, visible: bool) { pub fn set_cursor_visible(&self, visible: bool) {
let mut visible_lock = self.cursor_visible.lock(); #[allow(clippy::mutex_atomic)]
let mut visible_lock = self.cursor_visible.lock().unwrap();
if visible == *visible_lock { if visible == *visible_lock {
return; return;
} }
let cursor = if visible { let cursor = if visible {
Some(*self.cursor.lock()) Some(*self.cursor.lock().unwrap())
} else { } else {
None None
}; };
@ -1397,7 +1404,7 @@ impl UnownedWindow {
// we can't use `set_cursor_grab(false)` here because it doesn't run `XUngrabPointer` // we can't use `set_cursor_grab(false)` here because it doesn't run `XUngrabPointer`
// if the cursor isn't currently grabbed // if the cursor isn't currently grabbed
let mut grabbed_lock = self.cursor_grabbed_mode.lock(); let mut grabbed_lock = self.cursor_grabbed_mode.lock().unwrap();
unsafe { unsafe {
(self.xconn.xlib.XUngrabPointer)(self.xconn.display, ffi::CurrentTime); (self.xconn.xlib.XUngrabPointer)(self.xconn.display, ffi::CurrentTime);
} }
@ -1431,6 +1438,7 @@ impl UnownedWindow {
let _ = self let _ = self
.ime_sender .ime_sender
.lock() .lock()
.unwrap()
.send(ImeRequest::Position(self.xwindow, x, y)); .send(ImeRequest::Position(self.xwindow, x, y));
} }
@ -1439,6 +1447,7 @@ impl UnownedWindow {
let _ = self let _ = self
.ime_sender .ime_sender
.lock() .lock()
.unwrap()
.send(ImeRequest::Allow(self.xwindow, allowed)); .send(ImeRequest::Allow(self.xwindow, allowed));
} }
@ -1454,7 +1463,7 @@ impl UnownedWindow {
} else { } else {
false false
}; };
let is_visible = match self.shared_state.lock().visibility { let is_visible = match self.shared_state_lock().visibility {
Visibility::Yes => true, Visibility::Yes => true,
Visibility::YesWait | Visibility::No => false, Visibility::YesWait | Visibility::No => false,
}; };

View file

@ -1,7 +1,4 @@
use std::{collections::HashMap, error::Error, fmt, os::raw::c_int, ptr}; use std::{collections::HashMap, error::Error, fmt, os::raw::c_int, ptr, sync::Mutex};
use libc;
use parking_lot::Mutex;
use crate::window::CursorIcon; use crate::window::CursorIcon;
@ -74,7 +71,7 @@ impl XConnection {
/// Checks whether an error has been triggered by the previous function calls. /// Checks whether an error has been triggered by the previous function calls.
#[inline] #[inline]
pub fn check_errors(&self) -> Result<(), XError> { pub fn check_errors(&self) -> Result<(), XError> {
let error = self.latest_error.lock().take(); let error = self.latest_error.lock().unwrap().take();
if let Some(error) = error { if let Some(error) = error {
Err(error) Err(error)
} else { } else {
@ -85,7 +82,7 @@ impl XConnection {
/// Ignores any previous error. /// Ignores any previous error.
#[inline] #[inline]
pub fn ignore_error(&self) { pub fn ignore_error(&self) {
*self.latest_error.lock() = None; *self.latest_error.lock().unwrap() = None;
} }
} }

View file

@ -11,14 +11,13 @@ use std::{
rc::Rc, rc::Rc,
sync::{ sync::{
mpsc::{self, Receiver, Sender}, mpsc::{self, Receiver, Sender},
Arc, Arc, Mutex, MutexGuard,
}, },
thread, thread,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use parking_lot::Mutex;
use raw_window_handle::{RawDisplayHandle, WindowsDisplayHandle}; use raw_window_handle::{RawDisplayHandle, WindowsDisplayHandle};
use windows_sys::Win32::{ use windows_sys::Win32::{
@ -142,6 +141,10 @@ impl<T> WindowData<T> {
unsafe fn send_event(&self, event: Event<'_, T>) { unsafe fn send_event(&self, event: Event<'_, T>) {
self.event_loop_runner.send_event(event); self.event_loop_runner.send_event(event);
} }
fn window_state_lock(&self) -> MutexGuard<'_, WindowState> {
self.window_state.lock().unwrap()
}
} }
struct ThreadMsgTargetData<T: 'static> { struct ThreadMsgTargetData<T: 'static> {
@ -718,7 +721,7 @@ unsafe fn capture_mouse(window: HWND, window_state: &mut WindowState) {
/// Release mouse input, stopping windows on this thread from receiving mouse input when the cursor /// Release mouse input, stopping windows on this thread from receiving mouse input when the cursor
/// is outside the window. /// is outside the window.
unsafe fn release_mouse(mut window_state: parking_lot::MutexGuard<'_, WindowState>) { unsafe fn release_mouse(mut window_state: MutexGuard<'_, WindowState>) {
window_state.mouse.capture_count = window_state.mouse.capture_count.saturating_sub(1); window_state.mouse.capture_count = window_state.mouse.capture_count.saturating_sub(1);
if window_state.mouse.capture_count == 0 { if window_state.mouse.capture_count == 0 {
// ReleaseCapture() causes a WM_CAPTURECHANGED where we lock the window_state. // ReleaseCapture() causes a WM_CAPTURECHANGED where we lock the window_state.
@ -802,7 +805,7 @@ fn update_modifiers<T>(window: HWND, userdata: &WindowData<T>) {
use crate::event::WindowEvent::ModifiersChanged; use crate::event::WindowEvent::ModifiersChanged;
let modifiers = event::get_key_mods(); let modifiers = event::get_key_mods();
let mut window_state = userdata.window_state.lock(); let mut window_state = userdata.window_state_lock();
if window_state.modifiers_state != modifiers { if window_state.modifiers_state != modifiers {
window_state.modifiers_state = modifiers; window_state.modifiers_state = modifiers;
@ -874,7 +877,7 @@ unsafe fn lose_active_focus<T>(window: HWND, userdata: &WindowData<T>) {
}) })
} }
userdata.window_state.lock().modifiers_state = ModifiersState::empty(); userdata.window_state_lock().modifiers_state = ModifiersState::empty();
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)), window_id: RootWindowId(WindowId(window)),
event: ModifiersChanged(ModifiersState::empty()), event: ModifiersChanged(ModifiersState::empty()),
@ -971,7 +974,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
// the git blame and history would be preserved. // the git blame and history would be preserved.
let callback = || match msg { let callback = || match msg {
WM_NCCALCSIZE => { WM_NCCALCSIZE => {
let window_flags = userdata.window_state.lock().window_flags; let window_flags = userdata.window_state_lock().window_flags;
if wparam == 0 || window_flags.contains(WindowFlags::MARKER_DECORATIONS) { if wparam == 0 || window_flags.contains(WindowFlags::MARKER_DECORATIONS) {
return DefWindowProcW(window, msg, wparam, lparam); return DefWindowProcW(window, msg, wparam, lparam);
} }
@ -998,16 +1001,14 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_ENTERSIZEMOVE => { WM_ENTERSIZEMOVE => {
userdata userdata
.window_state .window_state_lock()
.lock()
.set_window_flags_in_place(|f| f.insert(WindowFlags::MARKER_IN_SIZE_MOVE)); .set_window_flags_in_place(|f| f.insert(WindowFlags::MARKER_IN_SIZE_MOVE));
0 0
} }
WM_EXITSIZEMOVE => { WM_EXITSIZEMOVE => {
userdata userdata
.window_state .window_state_lock()
.lock()
.set_window_flags_in_place(|f| f.remove(WindowFlags::MARKER_IN_SIZE_MOVE)); .set_window_flags_in_place(|f| f.remove(WindowFlags::MARKER_IN_SIZE_MOVE));
0 0
} }
@ -1064,7 +1065,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
WM_WINDOWPOSCHANGING => { WM_WINDOWPOSCHANGING => {
let mut window_state = userdata.window_state.lock(); let mut window_state = userdata.window_state_lock();
if let Some(ref mut fullscreen) = window_state.fullscreen { if let Some(ref mut fullscreen) = window_state.fullscreen {
let window_pos = &mut *(lparam as *mut WINDOWPOS); let window_pos = &mut *(lparam as *mut WINDOWPOS);
let new_rect = RECT { let new_rect = RECT {
@ -1173,7 +1174,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
}; };
{ {
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
// See WindowFlags::MARKER_RETAIN_STATE_ON_SIZE docs for info on why this `if` check exists. // See WindowFlags::MARKER_RETAIN_STATE_ON_SIZE docs for info on why this `if` check exists.
if !w if !w
.window_flags() .window_flags()
@ -1195,9 +1196,9 @@ unsafe fn public_window_callback_inner<T: 'static>(
let is_low_surrogate = (0xDC00..=0xDFFF).contains(&wparam); let is_low_surrogate = (0xDC00..=0xDFFF).contains(&wparam);
if is_high_surrogate { if is_high_surrogate {
userdata.window_state.lock().high_surrogate = Some(wparam as u16); userdata.window_state_lock().high_surrogate = Some(wparam as u16);
} else if is_low_surrogate { } else if is_low_surrogate {
let high_surrogate = userdata.window_state.lock().high_surrogate.take(); let high_surrogate = userdata.window_state_lock().high_surrogate.take();
if let Some(high_surrogate) = high_surrogate { if let Some(high_surrogate) = high_surrogate {
let pair = [high_surrogate, wparam as u16]; let pair = [high_surrogate, wparam as u16];
@ -1209,7 +1210,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
} }
} else { } else {
userdata.window_state.lock().high_surrogate = None; userdata.window_state_lock().high_surrogate = None;
if let Some(chr) = char::from_u32(wparam as u32) { if let Some(chr) = char::from_u32(wparam as u32) {
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
@ -1222,9 +1223,9 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
WM_IME_STARTCOMPOSITION => { WM_IME_STARTCOMPOSITION => {
let ime_allowed = userdata.window_state.lock().ime_allowed; let ime_allowed = userdata.window_state_lock().ime_allowed;
if ime_allowed { if ime_allowed {
userdata.window_state.lock().ime_state = ImeState::Enabled; userdata.window_state_lock().ime_state = ImeState::Enabled;
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)), window_id: RootWindowId(WindowId(window)),
@ -1237,7 +1238,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_IME_COMPOSITION => { WM_IME_COMPOSITION => {
let ime_allowed_and_composing = { let ime_allowed_and_composing = {
let w = userdata.window_state.lock(); let w = userdata.window_state_lock();
w.ime_allowed && w.ime_state != ImeState::Disabled w.ime_allowed && w.ime_state != ImeState::Disabled
}; };
// Windows Hangul IME sends WM_IME_COMPOSITION after WM_IME_ENDCOMPOSITION, so // Windows Hangul IME sends WM_IME_COMPOSITION after WM_IME_ENDCOMPOSITION, so
@ -1256,7 +1257,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
// first, receive composing result if exist. // first, receive composing result if exist.
if (lparam as u32 & GCS_RESULTSTR) != 0 { if (lparam as u32 & GCS_RESULTSTR) != 0 {
if let Some(text) = ime_context.get_composed_text() { if let Some(text) = ime_context.get_composed_text() {
userdata.window_state.lock().ime_state = ImeState::Enabled; userdata.window_state_lock().ime_state = ImeState::Enabled;
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)), window_id: RootWindowId(WindowId(window)),
@ -1268,7 +1269,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
// Next, receive preedit range for next composing if exist. // Next, receive preedit range for next composing if exist.
if (lparam as u32 & GCS_COMPSTR) != 0 { if (lparam as u32 & GCS_COMPSTR) != 0 {
if let Some((text, first, last)) = ime_context.get_composing_text_and_cursor() { if let Some((text, first, last)) = ime_context.get_composing_text_and_cursor() {
userdata.window_state.lock().ime_state = ImeState::Preedit; userdata.window_state_lock().ime_state = ImeState::Preedit;
let cursor_range = first.map(|f| (f, last.unwrap_or(f))); let cursor_range = first.map(|f| (f, last.unwrap_or(f)));
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
@ -1285,11 +1286,11 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_IME_ENDCOMPOSITION => { WM_IME_ENDCOMPOSITION => {
let ime_allowed_or_composing = { let ime_allowed_or_composing = {
let w = userdata.window_state.lock(); let w = userdata.window_state_lock();
w.ime_allowed || w.ime_state != ImeState::Disabled w.ime_allowed || w.ime_state != ImeState::Disabled
}; };
if ime_allowed_or_composing { if ime_allowed_or_composing {
if userdata.window_state.lock().ime_state == ImeState::Preedit { if userdata.window_state_lock().ime_state == ImeState::Preedit {
// Windows Hangul IME sends WM_IME_COMPOSITION after WM_IME_ENDCOMPOSITION, so // Windows Hangul IME sends WM_IME_COMPOSITION after WM_IME_ENDCOMPOSITION, so
// trying receiving composing result and commit if exists. // trying receiving composing result and commit if exists.
let ime_context = ImeContext::current(window); let ime_context = ImeContext::current(window);
@ -1301,7 +1302,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
} }
userdata.window_state.lock().ime_state = ImeState::Disabled; userdata.window_state_lock().ime_state = ImeState::Disabled;
userdata.send_event(Event::WindowEvent { userdata.send_event(Event::WindowEvent {
window_id: RootWindowId(WindowId(window)), window_id: RootWindowId(WindowId(window)),
@ -1322,17 +1323,17 @@ unsafe fn public_window_callback_inner<T: 'static>(
// this is necessary for us to maintain minimize/restore state // this is necessary for us to maintain minimize/restore state
WM_SYSCOMMAND => { WM_SYSCOMMAND => {
if wparam == SC_RESTORE as usize { if wparam == SC_RESTORE as usize {
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
w.set_window_flags_in_place(|f| f.set(WindowFlags::MINIMIZED, false)); w.set_window_flags_in_place(|f| f.set(WindowFlags::MINIMIZED, false));
} }
if wparam == SC_MINIMIZE as usize { if wparam == SC_MINIMIZE as usize {
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
w.set_window_flags_in_place(|f| f.set(WindowFlags::MINIMIZED, true)); w.set_window_flags_in_place(|f| f.set(WindowFlags::MINIMIZED, true));
} }
// Send `WindowEvent::Minimized` here if we decide to implement one // Send `WindowEvent::Minimized` here if we decide to implement one
if wparam == SC_SCREENSAVE as usize { if wparam == SC_SCREENSAVE as usize {
let window_state = userdata.window_state.lock(); let window_state = userdata.window_state_lock();
if window_state.fullscreen.is_some() { if window_state.fullscreen.is_some() {
return 0; return 0;
} }
@ -1344,7 +1345,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_MOUSEMOVE => { WM_MOUSEMOVE => {
use crate::event::WindowEvent::{CursorEntered, CursorMoved}; use crate::event::WindowEvent::{CursorEntered, CursorMoved};
let mouse_was_outside_window = { let mouse_was_outside_window = {
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
let was_outside_window = !w.mouse.cursor_flags().contains(CursorFlags::IN_WINDOW); let was_outside_window = !w.mouse.cursor_flags().contains(CursorFlags::IN_WINDOW);
w.mouse w.mouse
@ -1378,7 +1379,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
// handle spurious WM_MOUSEMOVE messages // handle spurious WM_MOUSEMOVE messages
// see https://devblogs.microsoft.com/oldnewthing/20031001-00/?p=42343 // see https://devblogs.microsoft.com/oldnewthing/20031001-00/?p=42343
// and http://debugandconquer.blogspot.com/2015/08/the-cause-of-spurious-mouse-move.html // and http://debugandconquer.blogspot.com/2015/08/the-cause-of-spurious-mouse-move.html
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
cursor_moved = w.mouse.last_position != Some(position); cursor_moved = w.mouse.last_position != Some(position);
w.mouse.last_position = Some(position); w.mouse.last_position = Some(position);
} }
@ -1401,7 +1402,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_MOUSELEAVE => { WM_MOUSELEAVE => {
use crate::event::WindowEvent::CursorLeft; use crate::event::WindowEvent::CursorLeft;
{ {
let mut w = userdata.window_state.lock(); let mut w = userdata.window_state_lock();
w.mouse w.mouse
.set_cursor_flags(window, |f| f.set(CursorFlags::IN_WINDOW, false)) .set_cursor_flags(window, |f| f.set(CursorFlags::IN_WINDOW, false))
.ok(); .ok();
@ -1522,7 +1523,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_LBUTTONDOWN => { WM_LBUTTONDOWN => {
use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput}; use crate::event::{ElementState::Pressed, MouseButton::Left, WindowEvent::MouseInput};
capture_mouse(window, &mut *userdata.window_state.lock()); capture_mouse(window, &mut *userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1543,7 +1544,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
ElementState::Released, MouseButton::Left, WindowEvent::MouseInput, ElementState::Released, MouseButton::Left, WindowEvent::MouseInput,
}; };
release_mouse(userdata.window_state.lock()); release_mouse(userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1564,7 +1565,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
ElementState::Pressed, MouseButton::Right, WindowEvent::MouseInput, ElementState::Pressed, MouseButton::Right, WindowEvent::MouseInput,
}; };
capture_mouse(window, &mut *userdata.window_state.lock()); capture_mouse(window, &mut *userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1585,7 +1586,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
ElementState::Released, MouseButton::Right, WindowEvent::MouseInput, ElementState::Released, MouseButton::Right, WindowEvent::MouseInput,
}; };
release_mouse(userdata.window_state.lock()); release_mouse(userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1606,7 +1607,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
ElementState::Pressed, MouseButton::Middle, WindowEvent::MouseInput, ElementState::Pressed, MouseButton::Middle, WindowEvent::MouseInput,
}; };
capture_mouse(window, &mut *userdata.window_state.lock()); capture_mouse(window, &mut *userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1627,7 +1628,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
ElementState::Released, MouseButton::Middle, WindowEvent::MouseInput, ElementState::Released, MouseButton::Middle, WindowEvent::MouseInput,
}; };
release_mouse(userdata.window_state.lock()); release_mouse(userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1649,7 +1650,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
}; };
let xbutton = super::get_xbutton_wparam(wparam as u32); let xbutton = super::get_xbutton_wparam(wparam as u32);
capture_mouse(window, &mut *userdata.window_state.lock()); capture_mouse(window, &mut *userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1671,7 +1672,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
}; };
let xbutton = super::get_xbutton_wparam(wparam as u32); let xbutton = super::get_xbutton_wparam(wparam as u32);
release_mouse(userdata.window_state.lock()); release_mouse(userdata.window_state_lock());
update_modifiers(window, userdata); update_modifiers(window, userdata);
@ -1693,7 +1694,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
// can happen if `SetCapture` is called on our window when it already has the mouse // can happen if `SetCapture` is called on our window when it already has the mouse
// capture. // capture.
if lparam != window { if lparam != window {
userdata.window_state.lock().mouse.capture_count = 0; userdata.window_state_lock().mouse.capture_count = 0;
} }
0 0
} }
@ -1889,7 +1890,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_NCACTIVATE => { WM_NCACTIVATE => {
let is_active = wparam == 1; let is_active = wparam == 1;
let active_focus_changed = userdata.window_state.lock().set_active(is_active); let active_focus_changed = userdata.window_state_lock().set_active(is_active);
if active_focus_changed { if active_focus_changed {
if is_active { if is_active {
gain_active_focus(window, userdata); gain_active_focus(window, userdata);
@ -1901,7 +1902,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
WM_SETFOCUS => { WM_SETFOCUS => {
let active_focus_changed = userdata.window_state.lock().set_focused(true); let active_focus_changed = userdata.window_state_lock().set_focused(true);
if active_focus_changed { if active_focus_changed {
gain_active_focus(window, userdata); gain_active_focus(window, userdata);
} }
@ -1909,7 +1910,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
} }
WM_KILLFOCUS => { WM_KILLFOCUS => {
let active_focus_changed = userdata.window_state.lock().set_focused(false); let active_focus_changed = userdata.window_state_lock().set_focused(false);
if active_focus_changed { if active_focus_changed {
lose_active_focus(window, userdata); lose_active_focus(window, userdata);
} }
@ -1918,7 +1919,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_SETCURSOR => { WM_SETCURSOR => {
let set_cursor_to = { let set_cursor_to = {
let window_state = userdata.window_state.lock(); let window_state = userdata.window_state_lock();
// The return value for the preceding `WM_NCHITTEST` message is conveniently // The return value for the preceding `WM_NCHITTEST` message is conveniently
// provided through the low-order word of lParam. We use that here since // provided through the low-order word of lParam. We use that here since
// `WM_MOUSEMOVE` seems to come after `WM_SETCURSOR` for a given cursor movement. // `WM_MOUSEMOVE` seems to come after `WM_SETCURSOR` for a given cursor movement.
@ -1948,7 +1949,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_GETMINMAXINFO => { WM_GETMINMAXINFO => {
let mmi = lparam as *mut MINMAXINFO; let mmi = lparam as *mut MINMAXINFO;
let window_state = userdata.window_state.lock(); let window_state = userdata.window_state_lock();
let window_flags = window_state.window_flags; let window_flags = window_state.window_flags;
if window_state.min_size.is_some() || window_state.max_size.is_some() { if window_state.min_size.is_some() || window_state.max_size.is_some() {
@ -1989,7 +1990,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
let old_scale_factor: f64; let old_scale_factor: f64;
let (allow_resize, window_flags) = { let (allow_resize, window_flags) = {
let mut window_state = userdata.window_state.lock(); let mut window_state = userdata.window_state_lock();
old_scale_factor = window_state.scale_factor; old_scale_factor = window_state.scale_factor;
window_state.scale_factor = new_scale_factor; window_state.scale_factor = new_scale_factor;
@ -2054,7 +2055,7 @@ unsafe fn public_window_callback_inner<T: 'static>(
let dragging_window: bool; let dragging_window: bool;
{ {
let window_state = userdata.window_state.lock(); let window_state = userdata.window_state_lock();
dragging_window = window_state dragging_window = window_state
.window_flags() .window_flags()
.contains(WindowFlags::MARKER_IN_SIZE_MOVE); .contains(WindowFlags::MARKER_IN_SIZE_MOVE);
@ -2183,11 +2184,11 @@ unsafe fn public_window_callback_inner<T: 'static>(
WM_SETTINGCHANGE => { WM_SETTINGCHANGE => {
use crate::event::WindowEvent::ThemeChanged; use crate::event::WindowEvent::ThemeChanged;
let preferred_theme = userdata.window_state.lock().preferred_theme; let preferred_theme = userdata.window_state_lock().preferred_theme;
if preferred_theme == None { if preferred_theme == None {
let new_theme = try_theme(window, preferred_theme); let new_theme = try_theme(window, preferred_theme);
let mut window_state = userdata.window_state.lock(); let mut window_state = userdata.window_state_lock();
if window_state.current_theme != new_theme { if window_state.current_theme != new_theme {
window_state.current_theme = new_theme; window_state.current_theme = new_theme;
@ -2207,13 +2208,13 @@ unsafe fn public_window_callback_inner<T: 'static>(
DestroyWindow(window); DestroyWindow(window);
0 0
} else if msg == *SET_RETAIN_STATE_ON_SIZE_MSG_ID { } else if msg == *SET_RETAIN_STATE_ON_SIZE_MSG_ID {
let mut window_state = userdata.window_state.lock(); let mut window_state = userdata.window_state_lock();
window_state.set_window_flags_in_place(|f| { window_state.set_window_flags_in_place(|f| {
f.set(WindowFlags::MARKER_RETAIN_STATE_ON_SIZE, wparam != 0) f.set(WindowFlags::MARKER_RETAIN_STATE_ON_SIZE, wparam != 0)
}); });
0 0
} else if msg == *TASKBAR_CREATED { } else if msg == *TASKBAR_CREATED {
let window_state = userdata.window_state.lock(); let window_state = userdata.window_state_lock();
set_skip_taskbar(window, window_state.skip_taskbar); set_skip_taskbar(window, window_state.skip_taskbar);
DefWindowProcW(window, msg, wparam, lparam) DefWindowProcW(window, msg, wparam, lparam)
} else { } else {

View file

@ -441,7 +441,7 @@ impl<T> BufferedEvent<T> {
let window_flags = unsafe { let window_flags = unsafe {
let userdata = let userdata =
get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData<T>; get_window_long(window_id.0.into(), GWL_USERDATA) as *mut WindowData<T>;
(*userdata).window_state.lock().window_flags (*userdata).window_state_lock().window_flags
}; };
window_flags.set_size((window_id.0).0, new_inner_size); window_flags.set_size((window_id.0).0, new_inner_size);
} }

View file

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

View file

@ -5,8 +5,8 @@ use crate::{
platform_impl::platform::{event_loop, util}, platform_impl::platform::{event_loop, util},
window::{CursorIcon, Fullscreen, Theme, WindowAttributes}, window::{CursorIcon, Fullscreen, Theme, WindowAttributes},
}; };
use parking_lot::MutexGuard;
use std::io; use std::io;
use std::sync::MutexGuard;
use windows_sys::Win32::{ use windows_sys::Win32::{
Foundation::{HWND, RECT}, Foundation::{HWND, RECT},
Graphics::Gdi::InvalidateRgn, Graphics::Gdi::InvalidateRgn,