mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 06:40:06 -04:00
On Windows, remove internal WindowWrapper (#3294)
HWND in windows-sys doesn't require a newtype wrapper for Send/Sync.
This commit is contained in:
committed by
Kirill Chibisov
parent
9b03bb7276
commit
a32e232020
@@ -83,7 +83,7 @@ use crate::{
|
|||||||
/// The Win32 implementation of the main `Window` object.
|
/// The Win32 implementation of the main `Window` object.
|
||||||
pub(crate) struct Window {
|
pub(crate) struct Window {
|
||||||
/// Main handle for the window.
|
/// Main handle for the window.
|
||||||
window: WindowWrapper,
|
window: HWND,
|
||||||
|
|
||||||
/// The current window state.
|
/// The current window state.
|
||||||
window_state: Arc<Mutex<WindowState>>,
|
window_state: Arc<Mutex<WindowState>>,
|
||||||
@@ -127,11 +127,11 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_transparent(&self, transparent: bool) {
|
pub fn set_transparent(&self, transparent: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::TRANSPARENT, transparent)
|
f.set(WindowFlags::TRANSPARENT, transparent)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -141,11 +141,11 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_visible(&self, visible: bool) {
|
pub fn set_visible(&self, visible: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::VISIBLE, visible)
|
f.set(WindowFlags::VISIBLE, visible)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -153,7 +153,7 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_visible(&self) -> Option<bool> {
|
pub fn is_visible(&self) -> Option<bool> {
|
||||||
Some(unsafe { IsWindowVisible(self.window.0) == 1 })
|
Some(unsafe { IsWindowVisible(self.window) == 1 })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -189,10 +189,10 @@ impl Window {
|
|||||||
let (x, y): (i32, i32) = position.to_physical::<i32>(self.scale_factor()).into();
|
let (x, y): (i32, i32) = position.to_physical::<i32>(self.scale_factor()).into();
|
||||||
|
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MAXIMIZED, false)
|
f.set(WindowFlags::MAXIMIZED, false)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -246,10 +246,10 @@ impl Window {
|
|||||||
|
|
||||||
if physical_size != self.inner_size() {
|
if physical_size != self.inner_size() {
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MAXIMIZED, false)
|
f.set(WindowFlags::MAXIMIZED, false)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -284,12 +284,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_resizable(&self, resizable: bool) {
|
pub fn set_resizable(&self, resizable: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::RESIZABLE, resizable)
|
f.set(WindowFlags::RESIZABLE, resizable)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -303,12 +303,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_enabled_buttons(&self, buttons: WindowButtons) {
|
pub fn set_enabled_buttons(&self, buttons: WindowButtons) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(
|
f.set(
|
||||||
WindowFlags::MINIMIZABLE,
|
WindowFlags::MINIMIZABLE,
|
||||||
buttons.contains(WindowButtons::MINIMIZE),
|
buttons.contains(WindowButtons::MINIMIZE),
|
||||||
@@ -342,14 +342,14 @@ impl Window {
|
|||||||
/// Returns the `hwnd` of this window.
|
/// Returns the `hwnd` of this window.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn hwnd(&self) -> HWND {
|
pub fn hwnd(&self) -> HWND {
|
||||||
self.window.0
|
self.window
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rwh_04")]
|
#[cfg(feature = "rwh_04")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle {
|
pub fn raw_window_handle_rwh_04(&self) -> rwh_04::RawWindowHandle {
|
||||||
let mut window_handle = rwh_04::Win32Handle::empty();
|
let mut window_handle = rwh_04::Win32Handle::empty();
|
||||||
window_handle.hwnd = self.window.0 as *mut _;
|
window_handle.hwnd = self.window as *mut _;
|
||||||
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
||||||
window_handle.hinstance = hinstance as *mut _;
|
window_handle.hinstance = hinstance as *mut _;
|
||||||
rwh_04::RawWindowHandle::Win32(window_handle)
|
rwh_04::RawWindowHandle::Win32(window_handle)
|
||||||
@@ -359,7 +359,7 @@ impl Window {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle {
|
pub fn raw_window_handle_rwh_05(&self) -> rwh_05::RawWindowHandle {
|
||||||
let mut window_handle = rwh_05::Win32WindowHandle::empty();
|
let mut window_handle = rwh_05::Win32WindowHandle::empty();
|
||||||
window_handle.hwnd = self.window.0 as *mut _;
|
window_handle.hwnd = self.window as *mut _;
|
||||||
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
||||||
window_handle.hinstance = hinstance as *mut _;
|
window_handle.hinstance = hinstance as *mut _;
|
||||||
rwh_05::RawWindowHandle::Win32(window_handle)
|
rwh_05::RawWindowHandle::Win32(window_handle)
|
||||||
@@ -376,8 +376,7 @@ impl Window {
|
|||||||
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
|
pub fn raw_window_handle_rwh_06(&self) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
|
||||||
let mut window_handle = rwh_06::Win32WindowHandle::new(unsafe {
|
let mut window_handle = rwh_06::Win32WindowHandle::new(unsafe {
|
||||||
// SAFETY: Handle will never be zero.
|
// SAFETY: Handle will never be zero.
|
||||||
let window = self.window.0;
|
std::num::NonZeroIsize::new_unchecked(self.window)
|
||||||
std::num::NonZeroIsize::new_unchecked(window)
|
|
||||||
});
|
});
|
||||||
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
||||||
window_handle.hinstance = std::num::NonZeroIsize::new(hinstance);
|
window_handle.hinstance = std::num::NonZeroIsize::new(hinstance);
|
||||||
@@ -413,7 +412,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
@@ -423,7 +422,7 @@ impl Window {
|
|||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mouse
|
.mouse
|
||||||
.set_cursor_flags(window.0, |f| f.set(CursorFlags::GRABBED, confine))
|
.set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine))
|
||||||
.map_err(|e| ExternalError::Os(os_error!(e)));
|
.map_err(|e| ExternalError::Os(os_error!(e)));
|
||||||
let _ = tx.send(result);
|
let _ = tx.send(result);
|
||||||
});
|
});
|
||||||
@@ -432,7 +431,7 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_cursor_visible(&self, visible: bool) {
|
pub fn set_cursor_visible(&self, visible: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
||||||
@@ -442,7 +441,7 @@ impl Window {
|
|||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.mouse
|
.mouse
|
||||||
.set_cursor_flags(window.0, |f| f.set(CursorFlags::HIDDEN, !visible))
|
.set_cursor_flags(window, |f| f.set(CursorFlags::HIDDEN, !visible))
|
||||||
.map_err(|e| e.to_string());
|
.map_err(|e| e.to_string());
|
||||||
let _ = tx.send(result);
|
let _ = tx.send(result);
|
||||||
});
|
});
|
||||||
@@ -472,7 +471,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
|
unsafe fn handle_os_dragging(&self, wparam: WPARAM) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let window_state = self.window_state.clone();
|
let window_state = self.window_state.clone();
|
||||||
|
|
||||||
self.thread_executor.execute_in_thread(move || {
|
self.thread_executor.execute_in_thread(move || {
|
||||||
@@ -500,7 +499,7 @@ impl Window {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
PostMessageW(
|
PostMessageW(
|
||||||
window.0,
|
window,
|
||||||
WM_NCLBUTTONDOWN,
|
WM_NCLBUTTONDOWN,
|
||||||
wparam,
|
wparam,
|
||||||
&points as *const _ as LPARAM,
|
&points as *const _ as LPARAM,
|
||||||
@@ -615,10 +614,10 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
|
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> {
|
||||||
let window = self.window.clone();
|
let window = self.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 || {
|
||||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest)
|
f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -633,7 +632,7 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_minimized(&self, minimized: bool) {
|
pub fn set_minimized(&self, minimized: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
|
|
||||||
let is_minimized = util::is_minimized(self.hwnd());
|
let is_minimized = util::is_minimized(self.hwnd());
|
||||||
@@ -643,7 +642,7 @@ impl Window {
|
|||||||
WindowState::set_window_flags_in_place(&mut window_state.lock().unwrap(), |f| {
|
WindowState::set_window_flags_in_place(&mut window_state.lock().unwrap(), |f| {
|
||||||
f.set(WindowFlags::MINIMIZED, is_minimized)
|
f.set(WindowFlags::MINIMIZED, is_minimized)
|
||||||
});
|
});
|
||||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MINIMIZED, minimized)
|
f.set(WindowFlags::MINIMIZED, minimized)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -656,12 +655,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_maximized(&self, maximized: bool) {
|
pub fn set_maximized(&self, maximized: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MAXIMIZED, maximized)
|
f.set(WindowFlags::MAXIMIZED, maximized)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -681,7 +680,7 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
pub fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
|
|
||||||
let mut window_state_lock = window_state.lock().unwrap();
|
let mut window_state_lock = window_state.lock().unwrap();
|
||||||
@@ -692,7 +691,7 @@ impl Window {
|
|||||||
_ if old_fullscreen == fullscreen => return,
|
_ if old_fullscreen == fullscreen => return,
|
||||||
// Return if saved Borderless(monitor) is the same as current monitor when requested fullscreen is Borderless(None)
|
// Return if saved Borderless(monitor) is the same as current monitor when requested fullscreen is Borderless(None)
|
||||||
(Some(Fullscreen::Borderless(Some(monitor))), Some(Fullscreen::Borderless(None)))
|
(Some(Fullscreen::Borderless(Some(monitor))), Some(Fullscreen::Borderless(None)))
|
||||||
if *monitor == monitor::current_monitor(window.0) =>
|
if *monitor == monitor::current_monitor(window) =>
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -761,7 +760,7 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update window style
|
// Update window style
|
||||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(
|
f.set(
|
||||||
WindowFlags::MARKER_EXCLUSIVE_FULLSCREEN,
|
WindowFlags::MARKER_EXCLUSIVE_FULLSCREEN,
|
||||||
matches!(fullscreen, Some(Fullscreen::Exclusive(_))),
|
matches!(fullscreen, Some(Fullscreen::Exclusive(_))),
|
||||||
@@ -777,7 +776,7 @@ impl Window {
|
|||||||
// this needs to be called before the below fullscreen SetWindowPos as this itself
|
// this needs to be called before the below fullscreen SetWindowPos as this itself
|
||||||
// will generate WM_SIZE messages of the old window size that can race with what we set below
|
// will generate WM_SIZE messages of the old window size that can race with what we set below
|
||||||
unsafe {
|
unsafe {
|
||||||
taskbar_mark_fullscreen(window.0, fullscreen.is_some());
|
taskbar_mark_fullscreen(window, fullscreen.is_some());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update window bounds
|
// Update window bounds
|
||||||
@@ -786,7 +785,7 @@ impl Window {
|
|||||||
// Save window bounds before entering fullscreen
|
// Save window bounds before entering fullscreen
|
||||||
let placement = unsafe {
|
let placement = unsafe {
|
||||||
let mut placement = mem::zeroed();
|
let mut placement = mem::zeroed();
|
||||||
GetWindowPlacement(window.0, &mut placement);
|
GetWindowPlacement(window, &mut placement);
|
||||||
placement
|
placement
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -795,7 +794,7 @@ impl Window {
|
|||||||
let monitor = match &fullscreen {
|
let monitor = match &fullscreen {
|
||||||
Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
|
Fullscreen::Exclusive(video_mode) => video_mode.monitor(),
|
||||||
Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
|
Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
|
||||||
Fullscreen::Borderless(None) => monitor::current_monitor(window.0),
|
Fullscreen::Borderless(None) => monitor::current_monitor(window),
|
||||||
};
|
};
|
||||||
|
|
||||||
let position: (i32, i32) = monitor.position().into();
|
let position: (i32, i32) = monitor.position().into();
|
||||||
@@ -803,7 +802,7 @@ impl Window {
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
SetWindowPos(
|
SetWindowPos(
|
||||||
window.0,
|
window,
|
||||||
0,
|
0,
|
||||||
position.0,
|
position.0,
|
||||||
position.1,
|
position.1,
|
||||||
@@ -811,7 +810,7 @@ impl Window {
|
|||||||
size.1 as i32,
|
size.1 as i32,
|
||||||
SWP_ASYNCWINDOWPOS | SWP_NOZORDER,
|
SWP_ASYNCWINDOWPOS | SWP_NOZORDER,
|
||||||
);
|
);
|
||||||
InvalidateRgn(window.0, 0, false.into());
|
InvalidateRgn(window, 0, false.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
@@ -819,8 +818,8 @@ impl Window {
|
|||||||
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 {
|
||||||
SetWindowPlacement(window.0, &placement);
|
SetWindowPlacement(window, &placement);
|
||||||
InvalidateRgn(window.0, 0, false.into());
|
InvalidateRgn(window, 0, false.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -830,12 +829,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_decorations(&self, decorations: bool) {
|
pub fn set_decorations(&self, decorations: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MARKER_DECORATIONS, decorations)
|
f.set(WindowFlags::MARKER_DECORATIONS, decorations)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -851,12 +850,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_window_level(&self, level: WindowLevel) {
|
pub fn set_window_level(&self, level: WindowLevel) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(
|
f.set(
|
||||||
WindowFlags::ALWAYS_ON_TOP,
|
WindowFlags::ALWAYS_ON_TOP,
|
||||||
level == WindowLevel::AlwaysOnTop,
|
level == WindowLevel::AlwaysOnTop,
|
||||||
@@ -905,21 +904,21 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_ime_cursor_area(&self, spot: Position, size: Size) {
|
pub fn set_ime_cursor_area(&self, spot: Position, size: Size) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let state = self.window_state.clone();
|
let state = self.window_state.clone();
|
||||||
self.thread_executor.execute_in_thread(move || unsafe {
|
self.thread_executor.execute_in_thread(move || unsafe {
|
||||||
let scale_factor = state.lock().unwrap().scale_factor;
|
let scale_factor = state.lock().unwrap().scale_factor;
|
||||||
ImeContext::current(window.0).set_ime_cursor_area(spot, size, scale_factor);
|
ImeContext::current(window).set_ime_cursor_area(spot, size, scale_factor);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_ime_allowed(&self, allowed: bool) {
|
pub fn set_ime_allowed(&self, allowed: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let state = self.window_state.clone();
|
let state = self.window_state.clone();
|
||||||
self.thread_executor.execute_in_thread(move || unsafe {
|
self.thread_executor.execute_in_thread(move || unsafe {
|
||||||
state.lock().unwrap().ime_allowed = allowed;
|
state.lock().unwrap().ime_allowed = allowed;
|
||||||
ImeContext::set_ime_allowed(window.0, allowed);
|
ImeContext::set_ime_allowed(window, allowed);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -928,14 +927,13 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
pub fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||||
let window = self.window.clone();
|
let window = self.window;
|
||||||
let active_window_handle = unsafe { GetActiveWindow() };
|
let active_window_handle = unsafe { GetActiveWindow() };
|
||||||
if window.0 == active_window_handle {
|
if window == active_window_handle {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.thread_executor.execute_in_thread(move || unsafe {
|
self.thread_executor.execute_in_thread(move || unsafe {
|
||||||
let _ = &window;
|
|
||||||
let (flags, count) = request_type
|
let (flags, count) = request_type
|
||||||
.map(|ty| match ty {
|
.map(|ty| match ty {
|
||||||
UserAttentionType::Critical => (FLASHW_ALL | FLASHW_TIMERNOFG, u32::MAX),
|
UserAttentionType::Critical => (FLASHW_ALL | FLASHW_TIMERNOFG, u32::MAX),
|
||||||
@@ -945,7 +943,7 @@ impl Window {
|
|||||||
|
|
||||||
let flash_info = FLASHWINFO {
|
let flash_info = FLASHWINFO {
|
||||||
cbSize: mem::size_of::<FLASHWINFO>() as u32,
|
cbSize: mem::size_of::<FLASHWINFO>() as u32,
|
||||||
hwnd: window.0,
|
hwnd: window,
|
||||||
dwFlags: flags,
|
dwFlags: flags,
|
||||||
uCount: count,
|
uCount: count,
|
||||||
dwTimeout: 0,
|
dwTimeout: 0,
|
||||||
@@ -956,7 +954,7 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_theme(&self, theme: Option<Theme>) {
|
pub fn set_theme(&self, theme: Option<Theme>) {
|
||||||
try_theme(self.window.0, theme);
|
try_theme(self.window, theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -971,9 +969,9 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn title(&self) -> String {
|
pub fn title(&self) -> String {
|
||||||
let len = unsafe { GetWindowTextLengthW(self.window.0) } + 1;
|
let len = unsafe { GetWindowTextLengthW(self.window) } + 1;
|
||||||
let mut buf = vec![0; len as usize];
|
let mut buf = vec![0; len as usize];
|
||||||
unsafe { GetWindowTextW(self.window.0, buf.as_mut_ptr(), len) };
|
unsafe { GetWindowTextW(self.window, buf.as_mut_ptr(), len) };
|
||||||
util::decode_wide(&buf).to_string_lossy().to_string()
|
util::decode_wide(&buf).to_string_lossy().to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -985,12 +983,12 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_undecorated_shadow(&self, shadow: bool) {
|
pub fn set_undecorated_shadow(&self, shadow: bool) {
|
||||||
let window = self.window.clone();
|
let window = self.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().unwrap(), window.0, |f| {
|
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||||
f.set(WindowFlags::MARKER_UNDECORATED_SHADOW, shadow)
|
f.set(WindowFlags::MARKER_UNDECORATED_SHADOW, shadow)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -998,15 +996,14 @@ impl Window {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn focus_window(&self) {
|
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_visible = window_flags.contains(WindowFlags::VISIBLE);
|
||||||
let is_minimized = util::is_minimized(self.hwnd());
|
let is_minimized = util::is_minimized(self.hwnd());
|
||||||
let is_foreground = window.0 == unsafe { GetForegroundWindow() };
|
let is_foreground = self.window == unsafe { GetForegroundWindow() };
|
||||||
|
|
||||||
if is_visible && !is_minimized && !is_foreground {
|
if is_visible && !is_minimized && !is_foreground {
|
||||||
unsafe { force_window_active(window.0) };
|
unsafe { force_window_active(self.window) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1056,18 +1053,6 @@ impl Drop for Window {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A simple non-owning wrapper around a window.
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct WindowWrapper(HWND);
|
|
||||||
|
|
||||||
// Send and Sync are not implemented for HWND and HDC, we have to wrap it and implement them manually.
|
|
||||||
// For more info see:
|
|
||||||
// https://github.com/retep998/winapi-rs/issues/360
|
|
||||||
// https://github.com/retep998/winapi-rs/issues/396
|
|
||||||
unsafe impl Sync for WindowWrapper {}
|
|
||||||
unsafe impl Send for WindowWrapper {}
|
|
||||||
|
|
||||||
pub(super) struct InitData<'a, T: 'static> {
|
pub(super) struct InitData<'a, T: 'static> {
|
||||||
// inputs
|
// inputs
|
||||||
pub event_loop: &'a EventLoopWindowTarget<T>,
|
pub event_loop: &'a EventLoopWindowTarget<T>,
|
||||||
@@ -1115,7 +1100,7 @@ impl<'a, T: 'static> InitData<'a, T> {
|
|||||||
unsafe { ImeContext::set_ime_allowed(window, false) };
|
unsafe { ImeContext::set_ime_allowed(window, false) };
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
window: WindowWrapper(window),
|
window,
|
||||||
window_state,
|
window_state,
|
||||||
thread_executor: self.event_loop.create_thread_executor(),
|
thread_executor: self.event_loop.create_thread_executor(),
|
||||||
}
|
}
|
||||||
@@ -1138,7 +1123,7 @@ impl<'a, T: 'static> InitData<'a, T> {
|
|||||||
|
|
||||||
let file_drop_runner = self.event_loop.runner_shared.clone();
|
let file_drop_runner = self.event_loop.runner_shared.clone();
|
||||||
let file_drop_handler = FileDropHandler::new(
|
let file_drop_handler = FileDropHandler::new(
|
||||||
win.window.0,
|
win.window,
|
||||||
Box::new(move |event| {
|
Box::new(move |event| {
|
||||||
if let Ok(e) = event.map_nonuser_event() {
|
if let Ok(e) = event.map_nonuser_event() {
|
||||||
file_drop_runner.send_event(e)
|
file_drop_runner.send_event(e)
|
||||||
@@ -1150,7 +1135,7 @@ impl<'a, T: 'static> InitData<'a, T> {
|
|||||||
unsafe { &mut (*file_drop_handler.data).interface as *mut _ as *mut c_void };
|
unsafe { &mut (*file_drop_handler.data).interface as *mut _ as *mut c_void };
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
unsafe { RegisterDragDrop(win.window.0, handler_interface_ptr) },
|
unsafe { RegisterDragDrop(win.window, handler_interface_ptr) },
|
||||||
S_OK
|
S_OK
|
||||||
);
|
);
|
||||||
Some(file_drop_handler)
|
Some(file_drop_handler)
|
||||||
@@ -1227,7 +1212,7 @@ impl<'a, T: 'static> InitData<'a, T> {
|
|||||||
|
|
||||||
if attributes.fullscreen.0.is_some() {
|
if attributes.fullscreen.0.is_some() {
|
||||||
win.set_fullscreen(attributes.fullscreen.0.map(Into::into));
|
win.set_fullscreen(attributes.fullscreen.0.map(Into::into));
|
||||||
unsafe { force_window_active(win.window.0) };
|
unsafe { force_window_active(win.window) };
|
||||||
} else {
|
} else {
|
||||||
let size = attributes
|
let size = attributes
|
||||||
.inner_size
|
.inner_size
|
||||||
|
|||||||
Reference in New Issue
Block a user