Remove parking_lot dependency (#2423)
This commit is contained in:
parent
ec7e935248
commit
8729119536
16 changed files with 197 additions and 175 deletions
|
|
@ -5,11 +5,10 @@ use std::{
|
|||
os::raw::*,
|
||||
path::Path,
|
||||
ptr, slice,
|
||||
sync::Arc,
|
||||
sync::{Arc, Mutex, MutexGuard},
|
||||
};
|
||||
|
||||
use libc;
|
||||
use parking_lot::Mutex;
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||
use x11_dl::xlib::TrueColor;
|
||||
|
||||
|
|
@ -107,6 +106,7 @@ pub struct UnownedWindow {
|
|||
screen_id: i32, // never changes
|
||||
cursor: Mutex<CursorIcon>,
|
||||
cursor_grabbed_mode: Mutex<CursorGrabMode>,
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
cursor_visible: Mutex<bool>,
|
||||
ime_sender: Mutex<ImeSender>,
|
||||
pub shared_state: Mutex<SharedState>,
|
||||
|
|
@ -270,6 +270,7 @@ impl UnownedWindow {
|
|||
)
|
||||
};
|
||||
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
let mut window = UnownedWindow {
|
||||
xconn: Arc::clone(xconn),
|
||||
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.max_inner_size = max_inner_size.map(Into::into);
|
||||
shared_state.resize_increments = pl_attribs.resize_increments;
|
||||
|
|
@ -480,7 +481,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
@ -499,6 +500,10 @@ impl UnownedWindow {
|
|||
.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<'_>> {
|
||||
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") };
|
||||
|
|
@ -611,7 +616,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
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 {
|
||||
// Setting fullscreen on a window that is not visible will generate an error.
|
||||
|
|
@ -665,7 +670,7 @@ impl UnownedWindow {
|
|||
match fullscreen {
|
||||
None => {
|
||||
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() {
|
||||
drop(shared_state_lock);
|
||||
self.set_position_inner(position.0, position.1).queue();
|
||||
|
|
@ -722,7 +727,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
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();
|
||||
self.set_position_inner(monitor_origin.0, monitor_origin.1)
|
||||
.queue();
|
||||
|
|
@ -733,7 +738,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
||||
let shared_state = self.shared_state.lock();
|
||||
let shared_state = self.shared_state_lock();
|
||||
|
||||
shared_state
|
||||
.desired_fullscreen
|
||||
|
|
@ -753,7 +758,7 @@ impl UnownedWindow {
|
|||
|
||||
// Called by EventProcessor when a VisibilityNotify event is received
|
||||
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 {
|
||||
Visibility::No => unsafe {
|
||||
|
|
@ -773,7 +778,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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> {
|
||||
|
|
@ -888,7 +893,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
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);
|
||||
|
||||
hints.set_decorations(decorations);
|
||||
|
|
@ -906,7 +911,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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<'_> {
|
||||
|
|
@ -965,7 +970,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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) {
|
||||
(true, Visibility::Yes) | (true, Visibility::YesWait) | (false, Visibility::No) => {
|
||||
|
|
@ -995,22 +1000,22 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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) {
|
||||
let extents = self
|
||||
.xconn
|
||||
.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) {
|
||||
(*self.shared_state.lock()).frame_extents.take();
|
||||
(*self.shared_state_lock()).frame_extents.take();
|
||||
}
|
||||
|
||||
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 {
|
||||
let (x, y) = self.inner_position_physical();
|
||||
extents.inner_pos_to_outer(x, y)
|
||||
|
|
@ -1022,7 +1027,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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 {
|
||||
let (x, y) = self.inner_position_physical();
|
||||
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
|
||||
// we'll translate for consistency.
|
||||
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 {
|
||||
x += extents.frame_extents.left as i32;
|
||||
y += extents.frame_extents.top as i32;
|
||||
|
|
@ -1093,7 +1098,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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 {
|
||||
let (width, height) = self.inner_size_physical();
|
||||
extents.inner_size_to_outer(width, height).into()
|
||||
|
|
@ -1120,7 +1125,7 @@ impl UnownedWindow {
|
|||
pub fn set_inner_size(&self, size: Size) {
|
||||
let scale_factor = self.scale_factor();
|
||||
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| {
|
||||
normal_hints.set_min_size(Some(size));
|
||||
normal_hints.set_max_size(Some(size));
|
||||
|
|
@ -1148,7 +1153,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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 =
|
||||
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
|
||||
self.set_min_inner_size_physical(physical_dimensions);
|
||||
|
|
@ -1161,7 +1166,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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 =
|
||||
dimensions.map(|dimensions| dimensions.to_physical::<u32>(self.scale_factor()).into());
|
||||
self.set_max_inner_size_physical(physical_dimensions);
|
||||
|
|
@ -1206,7 +1211,7 @@ impl UnownedWindow {
|
|||
}
|
||||
|
||||
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.max_inner_size,
|
||||
|
|
@ -1215,7 +1220,7 @@ impl UnownedWindow {
|
|||
let window_size = Some(Size::from(self.inner_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();
|
||||
|
||||
|
|
@ -1235,7 +1240,7 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn is_resizable(&self) -> bool {
|
||||
self.shared_state.lock().is_resizable
|
||||
self.shared_state_lock().is_resizable
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1265,15 +1270,16 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
pub fn set_cursor_icon(&self, cursor: CursorIcon) {
|
||||
let old_cursor = replace(&mut *self.cursor.lock(), cursor);
|
||||
if cursor != old_cursor && *self.cursor_visible.lock() {
|
||||
let old_cursor = replace(&mut *self.cursor.lock().unwrap(), cursor);
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
if cursor != old_cursor && *self.cursor_visible.lock().unwrap() {
|
||||
self.xconn.set_cursor_icon(self.xwindow, Some(cursor));
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
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 {
|
||||
return Ok(());
|
||||
}
|
||||
|
|
@ -1346,12 +1352,13 @@ impl UnownedWindow {
|
|||
|
||||
#[inline]
|
||||
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 {
|
||||
return;
|
||||
}
|
||||
let cursor = if visible {
|
||||
Some(*self.cursor.lock())
|
||||
Some(*self.cursor.lock().unwrap())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
@ -1397,7 +1404,7 @@ impl UnownedWindow {
|
|||
|
||||
// we can't use `set_cursor_grab(false)` here because it doesn't run `XUngrabPointer`
|
||||
// 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 {
|
||||
(self.xconn.xlib.XUngrabPointer)(self.xconn.display, ffi::CurrentTime);
|
||||
}
|
||||
|
|
@ -1431,6 +1438,7 @@ impl UnownedWindow {
|
|||
let _ = self
|
||||
.ime_sender
|
||||
.lock()
|
||||
.unwrap()
|
||||
.send(ImeRequest::Position(self.xwindow, x, y));
|
||||
}
|
||||
|
||||
|
|
@ -1439,6 +1447,7 @@ impl UnownedWindow {
|
|||
let _ = self
|
||||
.ime_sender
|
||||
.lock()
|
||||
.unwrap()
|
||||
.send(ImeRequest::Allow(self.xwindow, allowed));
|
||||
}
|
||||
|
||||
|
|
@ -1454,7 +1463,7 @@ impl UnownedWindow {
|
|||
} else {
|
||||
false
|
||||
};
|
||||
let is_visible = match self.shared_state.lock().visibility {
|
||||
let is_visible = match self.shared_state_lock().visibility {
|
||||
Visibility::Yes => true,
|
||||
Visibility::YesWait | Visibility::No => false,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue