Update to windows-sys 0.59 (#4098)
This commit is contained in:
parent
3a39a6ddb0
commit
23011c6b0a
17 changed files with 166 additions and 137 deletions
|
|
@ -242,7 +242,7 @@ objc2-ui-kit = { version = "0.3.0", default-features = false, features = [
|
|||
# Windows
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
unicode-segmentation = "1.7.1"
|
||||
windows-sys = { version = "0.52.0", features = [
|
||||
windows-sys = { version = "0.59.0", features = [
|
||||
"Win32_Devices_HumanInterfaceDevice",
|
||||
"Win32_Foundation",
|
||||
"Win32_Globalization",
|
||||
|
|
|
|||
|
|
@ -182,6 +182,9 @@ changelog entry.
|
|||
whilst files are being dragged over the window. It doesn't contain any file paths, just the
|
||||
pointer position.
|
||||
- Updated `objc2` to `v0.6`.
|
||||
- Updated `windows-sys` to `v0.59`.
|
||||
- To match the corresponding changes in `windows-sys`, the `HWND`, `HMONITOR`, and `HMENU` types
|
||||
now alias to `*mut c_void` instead of `isize`.
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,11 @@ use crate::monitor::MonitorHandle;
|
|||
use crate::window::{BadIcon, Icon, Window, WindowAttributes};
|
||||
|
||||
/// Window Handle type used by Win32 API
|
||||
pub type HWND = isize;
|
||||
pub type HWND = *mut c_void;
|
||||
/// Menu Handle type used by Win32 API
|
||||
pub type HMENU = isize;
|
||||
pub type HMENU = *mut c_void;
|
||||
/// Monitor Handle type used by Win32 API
|
||||
pub type HMONITOR = isize;
|
||||
pub type HMONITOR = *mut c_void;
|
||||
|
||||
/// Describes a system-drawn backdrop material of a window.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ fn should_apps_use_dark_mode() -> bool {
|
|||
|
||||
let module = LoadLibraryA("uxtheme.dll\0".as_ptr());
|
||||
|
||||
if module == 0 {
|
||||
if module.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,11 +3,15 @@
|
|||
|
||||
use std::ffi::c_void;
|
||||
|
||||
use windows_sys::core::{IUnknown, GUID, HRESULT};
|
||||
use windows_sys::core::{GUID, HRESULT};
|
||||
use windows_sys::Win32::Foundation::{BOOL, HWND, POINTL};
|
||||
use windows_sys::Win32::System::Com::{
|
||||
IAdviseSink, IDataObject, IEnumFORMATETC, IEnumSTATDATA, FORMATETC, STGMEDIUM,
|
||||
};
|
||||
use windows_sys::Win32::System::Com::{FORMATETC, STGMEDIUM};
|
||||
|
||||
pub type IUnknown = *mut c_void;
|
||||
pub type IAdviseSink = *mut c_void;
|
||||
pub type IDataObject = *mut c_void;
|
||||
pub type IEnumFORMATETC = *mut c_void;
|
||||
pub type IEnumSTATDATA = *mut c_void;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct IUnknownVtbl {
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ pub fn dpi_to_scale_factor(dpi: u32) -> f64 {
|
|||
|
||||
pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
|
||||
let hdc = unsafe { GetDC(hwnd) };
|
||||
if hdc == 0 {
|
||||
if hdc.is_null() {
|
||||
panic!("[winit] `GetDC` returned null!");
|
||||
}
|
||||
if let Some(GetDpiForWindow) = *GET_DPI_FOR_WINDOW {
|
||||
|
|
@ -85,7 +85,7 @@ pub unsafe fn hwnd_dpi(hwnd: HWND) -> u32 {
|
|||
} else if let Some(GetDpiForMonitor) = *GET_DPI_FOR_MONITOR {
|
||||
// We are on Windows 8.1 or later.
|
||||
let monitor = unsafe { MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST) };
|
||||
if monitor == 0 {
|
||||
if monitor.is_null() {
|
||||
return BASE_DPI;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,17 +5,17 @@ use std::ptr;
|
|||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
use tracing::debug;
|
||||
use windows_sys::core::{IUnknown, GUID, HRESULT};
|
||||
use windows_sys::core::{GUID, HRESULT};
|
||||
use windows_sys::Win32::Foundation::{DV_E_FORMATETC, HWND, POINT, POINTL, S_OK};
|
||||
use windows_sys::Win32::Graphics::Gdi::ScreenToClient;
|
||||
use windows_sys::Win32::System::Com::{IDataObject, DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL};
|
||||
use windows_sys::Win32::System::Com::{DVASPECT_CONTENT, FORMATETC, TYMED_HGLOBAL};
|
||||
use windows_sys::Win32::System::Ole::{CF_HDROP, DROPEFFECT_COPY, DROPEFFECT_NONE};
|
||||
use windows_sys::Win32::UI::Shell::{DragFinish, DragQueryFileW, HDROP};
|
||||
|
||||
use crate::dpi::PhysicalPosition;
|
||||
use crate::event::{Event, WindowEvent};
|
||||
use crate::platform_impl::platform::definitions::{
|
||||
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
|
||||
IDataObject, IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknown, IUnknownVtbl,
|
||||
};
|
||||
use crate::window::WindowId;
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use std::time::{Duration, Instant};
|
|||
use std::{mem, panic, ptr};
|
||||
|
||||
use runner::EventLoopRunner;
|
||||
use windows_sys::Win32::Devices::HumanInterfaceDevice::MOUSE_MOVE_RELATIVE;
|
||||
use windows_sys::Win32::Foundation::{
|
||||
GetLastError, FALSE, HANDLE, HWND, LPARAM, LRESULT, POINT, RECT, WAIT_FAILED, WPARAM,
|
||||
};
|
||||
|
|
@ -37,7 +36,9 @@ use windows_sys::Win32::UI::Input::Touch::{
|
|||
CloseTouchInputHandle, GetTouchInputInfo, TOUCHEVENTF_DOWN, TOUCHEVENTF_MOVE,
|
||||
TOUCHEVENTF_PRIMARY, TOUCHEVENTF_UP, TOUCHINPUT,
|
||||
};
|
||||
use windows_sys::Win32::UI::Input::{RAWINPUT, RIM_TYPEKEYBOARD, RIM_TYPEMOUSE};
|
||||
use windows_sys::Win32::UI::Input::{
|
||||
MOUSE_MOVE_RELATIVE, RAWINPUT, RIM_TYPEKEYBOARD, RIM_TYPEMOUSE,
|
||||
};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{
|
||||
CreateWindowExW, DefWindowProcW, DestroyWindow, DispatchMessageW, GetClientRect, GetCursorPos,
|
||||
GetMenu, LoadCursorW, MsgWaitForMultipleObjectsEx, PeekMessageW, PostMessageW,
|
||||
|
|
@ -402,7 +403,7 @@ impl EventLoop {
|
|||
|
||||
loop {
|
||||
unsafe {
|
||||
if PeekMessageW(&mut msg, 0, 0, 0, PM_REMOVE) == false.into() {
|
||||
if PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, PM_REMOVE) == false.into() {
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -634,10 +635,10 @@ fn create_high_resolution_timer() -> Option<OwnedHandle> {
|
|||
// CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is supported only after
|
||||
// Win10 1803 but it is already default option for rustc
|
||||
// (std uses it to implement `std::thread::sleep`).
|
||||
if handle == 0 {
|
||||
if handle.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(OwnedHandle::from_raw_handle(handle as *mut c_void))
|
||||
Some(OwnedHandle::from_raw_handle(handle))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -807,6 +808,7 @@ pub struct EventLoopProxy {
|
|||
}
|
||||
|
||||
unsafe impl Send for EventLoopProxy {}
|
||||
unsafe impl Sync for EventLoopProxy {}
|
||||
|
||||
impl EventLoopProxyProvider for EventLoopProxy {
|
||||
fn wake_up(&self) {
|
||||
|
|
@ -894,12 +896,12 @@ fn create_event_target_window() -> HWND {
|
|||
cbClsExtra: 0,
|
||||
cbWndExtra: 0,
|
||||
hInstance: util::get_instance_handle(),
|
||||
hIcon: 0,
|
||||
hCursor: 0, // must be null in order for cursor state to work properly
|
||||
hbrBackground: 0,
|
||||
hIcon: ptr::null_mut(),
|
||||
hCursor: ptr::null_mut(), // must be null in order for cursor state to work properly
|
||||
hbrBackground: ptr::null_mut(),
|
||||
lpszMenuName: ptr::null(),
|
||||
lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(),
|
||||
hIconSm: 0,
|
||||
hIconSm: ptr::null_mut(),
|
||||
};
|
||||
|
||||
RegisterClassExW(&class);
|
||||
|
|
@ -922,8 +924,8 @@ fn create_event_target_window() -> HWND {
|
|||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
util::get_instance_handle(),
|
||||
ptr::null(),
|
||||
);
|
||||
|
|
@ -1245,7 +1247,7 @@ unsafe fn public_window_callback_inner(
|
|||
// after marking `WM_PAINT` as handled.
|
||||
result = ProcResult::Value(unsafe { DefWindowProcW(window, msg, wparam, lparam) });
|
||||
if std::mem::take(&mut userdata.window_state_lock().redraw_requested) {
|
||||
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
|
||||
unsafe { RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT) };
|
||||
}
|
||||
},
|
||||
WM_WINDOWPOSCHANGING => {
|
||||
|
|
@ -1294,7 +1296,7 @@ unsafe fn public_window_callback_inner(
|
|||
let new_monitor = unsafe { MonitorFromRect(&new_rect, MONITOR_DEFAULTTONULL) };
|
||||
match fullscreen {
|
||||
Fullscreen::Borderless(ref mut fullscreen_monitor) => {
|
||||
if new_monitor != 0
|
||||
if !new_monitor.is_null()
|
||||
&& fullscreen_monitor
|
||||
.as_ref()
|
||||
.map(|monitor| new_monitor != monitor.hmonitor())
|
||||
|
|
@ -1741,7 +1743,7 @@ unsafe fn public_window_callback_inner(
|
|||
},
|
||||
|
||||
WM_KEYUP | WM_SYSKEYUP => {
|
||||
if msg == WM_SYSKEYUP && unsafe { GetMenu(window) != 0 } {
|
||||
if msg == WM_SYSKEYUP && unsafe { !GetMenu(window).is_null() } {
|
||||
// let Windows handle event if the window has a native menu, a modal event loop
|
||||
// is started here on Alt key up.
|
||||
result = ProcResult::DefWindowProc(wparam);
|
||||
|
|
@ -1973,7 +1975,7 @@ unsafe fn public_window_callback_inner(
|
|||
// If it is the same as our window, then we're essentially retaining the capture. This
|
||||
// can happen if `SetCapture` is called on our window when it already has the mouse
|
||||
// capture.
|
||||
if lparam != window {
|
||||
if lparam != window as isize {
|
||||
userdata.window_state_lock().mouse.capture_count = 0;
|
||||
}
|
||||
result = ProcResult::Value(0);
|
||||
|
|
@ -1986,7 +1988,7 @@ unsafe fn public_window_callback_inner(
|
|||
|
||||
let pcount = super::loword(wparam as u32) as usize;
|
||||
let mut inputs = Vec::with_capacity(pcount);
|
||||
let htouch = lparam;
|
||||
let htouch = lparam as *mut _;
|
||||
if unsafe {
|
||||
GetTouchInputInfo(
|
||||
htouch,
|
||||
|
|
@ -2309,7 +2311,7 @@ unsafe fn public_window_callback_inner(
|
|||
Some(selected_cursor) => {
|
||||
let hcursor = match selected_cursor {
|
||||
SelectedCursor::Named(cursor_icon) => unsafe {
|
||||
LoadCursorW(0, util::to_windows_cursor(cursor_icon))
|
||||
LoadCursorW(ptr::null_mut(), util::to_windows_cursor(cursor_icon))
|
||||
},
|
||||
SelectedCursor::Custom(cursor) => cursor.as_raw_handle(),
|
||||
};
|
||||
|
|
@ -2541,7 +2543,7 @@ unsafe fn public_window_callback_inner(
|
|||
unsafe {
|
||||
SetWindowPos(
|
||||
window,
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
new_outer_rect.left,
|
||||
new_outer_rect.top,
|
||||
new_outer_rect.right - new_outer_rect.left,
|
||||
|
|
@ -2621,7 +2623,7 @@ unsafe extern "system" fn thread_event_target_callback(
|
|||
let userdata = unsafe { Box::from_raw(userdata_ptr) };
|
||||
|
||||
if msg != WM_PAINT {
|
||||
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
|
||||
unsafe { RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT) };
|
||||
}
|
||||
|
||||
let mut userdata_removed = false;
|
||||
|
|
@ -2685,7 +2687,7 @@ unsafe fn handle_raw_input(userdata: &ThreadMsgTargetData, data: RAWINPUT) {
|
|||
if data.header.dwType == RIM_TYPEMOUSE {
|
||||
let mouse = unsafe { data.data.mouse };
|
||||
|
||||
if util::has_flag(mouse.usFlags as u32, MOUSE_MOVE_RELATIVE) {
|
||||
if util::has_flag(mouse.usFlags, MOUSE_MOVE_RELATIVE) {
|
||||
let x = mouse.lLastX as f64;
|
||||
let y = mouse.lLastY as f64;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::ffi::c_void;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use std::{fmt, io, mem};
|
||||
use std::{fmt, io, mem, ptr};
|
||||
|
||||
use cursor_icon::CursorIcon;
|
||||
use windows_sys::core::PCWSTR;
|
||||
|
|
@ -40,7 +40,7 @@ impl RgbaIcon {
|
|||
assert_eq!(and_mask.len(), pixel_count);
|
||||
let handle = unsafe {
|
||||
CreateIcon(
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
self.width as i32,
|
||||
self.height as i32,
|
||||
1,
|
||||
|
|
@ -49,7 +49,7 @@ impl RgbaIcon {
|
|||
rgba.as_ptr(),
|
||||
)
|
||||
};
|
||||
if handle != 0 {
|
||||
if !handle.is_null() {
|
||||
Ok(WinIcon::from_handle(handle))
|
||||
} else {
|
||||
Err(BadIcon::OsError(io::Error::last_os_error()))
|
||||
|
|
@ -68,6 +68,9 @@ struct RaiiIcon {
|
|||
handle: HICON,
|
||||
}
|
||||
|
||||
unsafe impl Send for RaiiIcon {}
|
||||
unsafe impl Sync for RaiiIcon {}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct WinIcon {
|
||||
inner: Arc<RaiiIcon>,
|
||||
|
|
@ -91,7 +94,7 @@ impl WinIcon {
|
|||
|
||||
let handle = unsafe {
|
||||
LoadImageW(
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
wide_path.as_ptr(),
|
||||
IMAGE_ICON,
|
||||
width,
|
||||
|
|
@ -99,7 +102,7 @@ impl WinIcon {
|
|||
LR_DEFAULTSIZE | LR_LOADFROMFILE,
|
||||
)
|
||||
};
|
||||
if handle != 0 {
|
||||
if !handle.is_null() {
|
||||
Ok(WinIcon::from_handle(handle as HICON))
|
||||
} else {
|
||||
Err(BadIcon::OsError(io::Error::last_os_error()))
|
||||
|
|
@ -122,7 +125,7 @@ impl WinIcon {
|
|||
LR_DEFAULTSIZE,
|
||||
)
|
||||
};
|
||||
if handle != 0 {
|
||||
if !handle.is_null() {
|
||||
Ok(WinIcon::from_handle(handle as HICON))
|
||||
} else {
|
||||
Err(BadIcon::OsError(io::Error::last_os_error()))
|
||||
|
|
@ -136,7 +139,7 @@ impl WinIcon {
|
|||
|
||||
pub fn set_for_window(&self, hwnd: HWND, icon_type: IconType) {
|
||||
unsafe {
|
||||
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle());
|
||||
SendMessageW(hwnd, WM_SETICON, icon_type as usize, self.as_raw_handle() as isize);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,13 +190,13 @@ impl WinCursor {
|
|||
let h = image.height as i32;
|
||||
|
||||
unsafe {
|
||||
let hdc_screen = GetDC(0);
|
||||
if hdc_screen == 0 {
|
||||
let hdc_screen = GetDC(ptr::null_mut());
|
||||
if hdc_screen.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
let hbm_color = CreateCompatibleBitmap(hdc_screen, w, h);
|
||||
ReleaseDC(0, hdc_screen);
|
||||
if hbm_color == 0 {
|
||||
ReleaseDC(ptr::null_mut(), hdc_screen);
|
||||
if hbm_color.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void) == 0 {
|
||||
|
|
@ -204,7 +207,7 @@ impl WinCursor {
|
|||
// Mask created according to https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap#parameters
|
||||
let mask_bits: Vec<u8> = vec![0xff; ((((w + 15) >> 4) << 1) * h) as usize];
|
||||
let hbm_mask = CreateBitmap(w, h, 1, 1, mask_bits.as_ptr() as *const _);
|
||||
if hbm_mask == 0 {
|
||||
if hbm_mask.is_null() {
|
||||
DeleteObject(hbm_color);
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
|
|
@ -220,7 +223,7 @@ impl WinCursor {
|
|||
let handle = CreateIconIndirect(&icon_info as *const _);
|
||||
DeleteObject(hbm_color);
|
||||
DeleteObject(hbm_mask);
|
||||
if handle == 0 {
|
||||
if handle.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
|
||||
|
|
@ -234,6 +237,9 @@ pub struct RaiiCursor {
|
|||
handle: HCURSOR,
|
||||
}
|
||||
|
||||
unsafe impl Send for RaiiCursor {}
|
||||
unsafe impl Sync for RaiiCursor {}
|
||||
|
||||
impl Drop for RaiiCursor {
|
||||
fn drop(&mut self) {
|
||||
unsafe { DestroyCursor(self.handle) };
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@ use std::os::windows::prelude::OsStringExt;
|
|||
use std::ptr::null_mut;
|
||||
|
||||
use windows_sys::Win32::Foundation::{POINT, RECT};
|
||||
use windows_sys::Win32::Globalization::HIMC;
|
||||
use windows_sys::Win32::UI::Input::Ime::{
|
||||
ImmAssociateContextEx, ImmGetCompositionStringW, ImmGetContext, ImmReleaseContext,
|
||||
ImmSetCandidateWindow, ImmSetCompositionWindow, ATTR_TARGET_CONVERTED,
|
||||
ATTR_TARGET_NOTCONVERTED, CANDIDATEFORM, CFS_EXCLUDE, CFS_POINT, COMPOSITIONFORM, GCS_COMPATTR,
|
||||
GCS_COMPSTR, GCS_CURSORPOS, GCS_RESULTSTR, IACE_CHILDREN, IACE_DEFAULT,
|
||||
GCS_COMPSTR, GCS_CURSORPOS, GCS_RESULTSTR, HIMC, IACE_CHILDREN, IACE_DEFAULT,
|
||||
};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{GetSystemMetrics, SM_IMMENABLED};
|
||||
|
||||
|
|
@ -138,9 +137,9 @@ impl ImeContext {
|
|||
}
|
||||
|
||||
if allowed {
|
||||
unsafe { ImmAssociateContextEx(hwnd, 0, IACE_DEFAULT) };
|
||||
unsafe { ImmAssociateContextEx(hwnd, null_mut(), IACE_DEFAULT) };
|
||||
} else {
|
||||
unsafe { ImmAssociateContextEx(hwnd, 0, IACE_CHILDREN) };
|
||||
unsafe { ImmAssociateContextEx(hwnd, null_mut(), IACE_CHILDREN) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use unicode_segmentation::UnicodeSegmentation;
|
|||
use windows_sys::Win32::Foundation::{HWND, LPARAM, WPARAM};
|
||||
use windows_sys::Win32::System::SystemServices::LANG_KOREAN;
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{
|
||||
GetAsyncKeyState, GetKeyState, GetKeyboardLayout, GetKeyboardState, MapVirtualKeyExW,
|
||||
GetAsyncKeyState, GetKeyState, GetKeyboardLayout, GetKeyboardState, MapVirtualKeyExW, HKL,
|
||||
MAPVK_VK_TO_VSC_EX, MAPVK_VSC_TO_VK_EX, VIRTUAL_KEY, VK_ABNT_C2, VK_ADD, VK_CAPITAL, VK_CLEAR,
|
||||
VK_CONTROL, VK_DECIMAL, VK_DELETE, VK_DIVIDE, VK_DOWN, VK_END, VK_F4, VK_HOME, VK_INSERT,
|
||||
VK_LCONTROL, VK_LEFT, VK_LMENU, VK_LSHIFT, VK_LWIN, VK_MENU, VK_MULTIPLY, VK_NEXT, VK_NUMLOCK,
|
||||
|
|
@ -20,7 +20,6 @@ use windows_sys::Win32::UI::Input::KeyboardAndMouse::{
|
|||
VK_NUMPAD8, VK_NUMPAD9, VK_PRIOR, VK_RCONTROL, VK_RETURN, VK_RIGHT, VK_RMENU, VK_RSHIFT,
|
||||
VK_RWIN, VK_SCROLL, VK_SHIFT, VK_SUBTRACT, VK_UP,
|
||||
};
|
||||
use windows_sys::Win32::UI::TextServices::HKL;
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{
|
||||
PeekMessageW, MSG, PM_NOREMOVE, WM_CHAR, WM_DEADCHAR, WM_KEYDOWN, WM_KEYFIRST, WM_KEYLAST,
|
||||
WM_KEYUP, WM_KILLFOCUS, WM_SETFOCUS, WM_SYSCHAR, WM_SYSDEADCHAR, WM_SYSKEYDOWN, WM_SYSKEYUP,
|
||||
|
|
|
|||
|
|
@ -7,18 +7,19 @@ use std::sync::Mutex;
|
|||
use smol_str::SmolStr;
|
||||
use windows_sys::Win32::System::SystemServices::{LANG_JAPANESE, LANG_KOREAN};
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{
|
||||
GetKeyState, GetKeyboardLayout, MapVirtualKeyExW, ToUnicodeEx, MAPVK_VK_TO_VSC_EX, VIRTUAL_KEY,
|
||||
VK_ACCEPT, VK_ADD, VK_APPS, VK_ATTN, VK_BACK, VK_BROWSER_BACK, VK_BROWSER_FAVORITES,
|
||||
VK_BROWSER_FORWARD, VK_BROWSER_HOME, VK_BROWSER_REFRESH, VK_BROWSER_SEARCH, VK_BROWSER_STOP,
|
||||
VK_CANCEL, VK_CAPITAL, VK_CLEAR, VK_CONTROL, VK_CONVERT, VK_CRSEL, VK_DECIMAL, VK_DELETE,
|
||||
VK_DIVIDE, VK_DOWN, VK_END, VK_EREOF, VK_ESCAPE, VK_EXECUTE, VK_EXSEL, VK_F1, VK_F10, VK_F11,
|
||||
VK_F12, VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18, VK_F19, VK_F2, VK_F20, VK_F21, VK_F22,
|
||||
VK_F23, VK_F24, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7, VK_F8, VK_F9, VK_FINAL, VK_GAMEPAD_A,
|
||||
VK_GAMEPAD_B, VK_GAMEPAD_DPAD_DOWN, VK_GAMEPAD_DPAD_LEFT, VK_GAMEPAD_DPAD_RIGHT,
|
||||
VK_GAMEPAD_DPAD_UP, VK_GAMEPAD_LEFT_SHOULDER, VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON,
|
||||
VK_GAMEPAD_LEFT_THUMBSTICK_DOWN, VK_GAMEPAD_LEFT_THUMBSTICK_LEFT,
|
||||
VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT, VK_GAMEPAD_LEFT_THUMBSTICK_UP, VK_GAMEPAD_LEFT_TRIGGER,
|
||||
VK_GAMEPAD_MENU, VK_GAMEPAD_RIGHT_SHOULDER, VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON,
|
||||
GetKeyState, GetKeyboardLayout, MapVirtualKeyExW, ToUnicodeEx, HKL, MAPVK_VK_TO_VSC_EX,
|
||||
VIRTUAL_KEY, VK_ACCEPT, VK_ADD, VK_APPS, VK_ATTN, VK_BACK, VK_BROWSER_BACK,
|
||||
VK_BROWSER_FAVORITES, VK_BROWSER_FORWARD, VK_BROWSER_HOME, VK_BROWSER_REFRESH,
|
||||
VK_BROWSER_SEARCH, VK_BROWSER_STOP, VK_CANCEL, VK_CAPITAL, VK_CLEAR, VK_CONTROL, VK_CONVERT,
|
||||
VK_CRSEL, VK_DECIMAL, VK_DELETE, VK_DIVIDE, VK_DOWN, VK_END, VK_EREOF, VK_ESCAPE, VK_EXECUTE,
|
||||
VK_EXSEL, VK_F1, VK_F10, VK_F11, VK_F12, VK_F13, VK_F14, VK_F15, VK_F16, VK_F17, VK_F18,
|
||||
VK_F19, VK_F2, VK_F20, VK_F21, VK_F22, VK_F23, VK_F24, VK_F3, VK_F4, VK_F5, VK_F6, VK_F7,
|
||||
VK_F8, VK_F9, VK_FINAL, VK_GAMEPAD_A, VK_GAMEPAD_B, VK_GAMEPAD_DPAD_DOWN, VK_GAMEPAD_DPAD_LEFT,
|
||||
VK_GAMEPAD_DPAD_RIGHT, VK_GAMEPAD_DPAD_UP, VK_GAMEPAD_LEFT_SHOULDER,
|
||||
VK_GAMEPAD_LEFT_THUMBSTICK_BUTTON, VK_GAMEPAD_LEFT_THUMBSTICK_DOWN,
|
||||
VK_GAMEPAD_LEFT_THUMBSTICK_LEFT, VK_GAMEPAD_LEFT_THUMBSTICK_RIGHT,
|
||||
VK_GAMEPAD_LEFT_THUMBSTICK_UP, VK_GAMEPAD_LEFT_TRIGGER, VK_GAMEPAD_MENU,
|
||||
VK_GAMEPAD_RIGHT_SHOULDER, VK_GAMEPAD_RIGHT_THUMBSTICK_BUTTON,
|
||||
VK_GAMEPAD_RIGHT_THUMBSTICK_DOWN, VK_GAMEPAD_RIGHT_THUMBSTICK_LEFT,
|
||||
VK_GAMEPAD_RIGHT_THUMBSTICK_RIGHT, VK_GAMEPAD_RIGHT_THUMBSTICK_UP, VK_GAMEPAD_RIGHT_TRIGGER,
|
||||
VK_GAMEPAD_VIEW, VK_GAMEPAD_X, VK_GAMEPAD_Y, VK_HANGUL, VK_HANJA, VK_HELP, VK_HOME, VK_ICO_00,
|
||||
|
|
@ -39,7 +40,6 @@ use windows_sys::Win32::UI::Input::KeyboardAndMouse::{
|
|||
VK_SCROLL, VK_SELECT, VK_SEPARATOR, VK_SHIFT, VK_SLEEP, VK_SNAPSHOT, VK_SPACE, VK_SUBTRACT,
|
||||
VK_TAB, VK_UP, VK_VOLUME_DOWN, VK_VOLUME_MUTE, VK_VOLUME_UP, VK_XBUTTON1, VK_XBUTTON2, VK_ZOOM,
|
||||
};
|
||||
use windows_sys::Win32::UI::TextServices::HKL;
|
||||
|
||||
use crate::keyboard::{Key, KeyCode, ModifiersState, NamedKey, NativeKey, PhysicalKey};
|
||||
use crate::platform_impl::{loword, primarylangid, scancode_to_physicalkey};
|
||||
|
|
|
|||
|
|
@ -63,12 +63,10 @@ impl VideoModeHandle {
|
|||
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
|
||||
pub struct MonitorHandle(HMONITOR);
|
||||
|
||||
// Send is not implemented for HMONITOR, we have to wrap it and implement it manually.
|
||||
// For more info see:
|
||||
// https://github.com/retep998/winapi-rs/issues/360
|
||||
// https://github.com/retep998/winapi-rs/issues/396
|
||||
// Send and Sync are not implemented for HMONITOR, we have to wrap it and implement them manually.
|
||||
|
||||
unsafe impl Send for MonitorHandle {}
|
||||
unsafe impl Sync for MonitorHandle {}
|
||||
|
||||
unsafe extern "system" fn monitor_enum_proc(
|
||||
hmonitor: HMONITOR,
|
||||
|
|
@ -85,7 +83,7 @@ pub fn available_monitors() -> VecDeque<MonitorHandle> {
|
|||
let mut monitors: VecDeque<MonitorHandle> = VecDeque::new();
|
||||
unsafe {
|
||||
EnumDisplayMonitors(
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
ptr::null(),
|
||||
Some(monitor_enum_proc),
|
||||
&mut monitors as *mut _ as LPARAM,
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ pub fn register_all_mice_and_keyboards_for_raw_input(
|
|||
// RIDEV_REMOVE: don't receive device events (requires NULL hwndTarget)
|
||||
let flags = match filter {
|
||||
DeviceEvents::Never => {
|
||||
window_handle = 0;
|
||||
window_handle = ptr::null_mut();
|
||||
RIDEV_REMOVE
|
||||
},
|
||||
DeviceEvents::WhenFocused => RIDEV_DEVNOTIFY,
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ pub(super) fn get_function_impl(library: &str, function: &str) -> Option<*const
|
|||
|
||||
// Library names we will use are ASCII so we can use the A version to avoid string conversion.
|
||||
let module = unsafe { LoadLibraryA(library.as_ptr()) };
|
||||
if module == 0 {
|
||||
if module.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,10 +73,25 @@ use crate::window::{
|
|||
WindowLevel,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
/// We need to pass the window handle to the event loop thread, which means it needs to be
|
||||
/// Send+Sync.
|
||||
struct SyncWindowHandle(HWND);
|
||||
|
||||
unsafe impl Send for SyncWindowHandle {}
|
||||
unsafe impl Sync for SyncWindowHandle {}
|
||||
|
||||
impl SyncWindowHandle {
|
||||
fn hwnd(&self) -> HWND {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The Win32 implementation of the main `Window` object.
|
||||
pub(crate) struct Window {
|
||||
/// Main handle for the window.
|
||||
window: HWND,
|
||||
window: SyncWindowHandle,
|
||||
|
||||
/// The current window state.
|
||||
window_state: Arc<Mutex<WindowState>>,
|
||||
|
|
@ -103,7 +118,7 @@ impl Window {
|
|||
|
||||
/// Returns the `hwnd` of this window.
|
||||
pub fn hwnd(&self) -> HWND {
|
||||
self.window
|
||||
self.window.hwnd()
|
||||
}
|
||||
|
||||
pub unsafe fn rwh_06_no_thread_check(
|
||||
|
|
@ -111,7 +126,7 @@ impl Window {
|
|||
) -> Result<rwh_06::RawWindowHandle, rwh_06::HandleError> {
|
||||
let mut window_handle = rwh_06::Win32WindowHandle::new(unsafe {
|
||||
// SAFETY: Handle will never be zero.
|
||||
std::num::NonZeroIsize::new_unchecked(self.window)
|
||||
std::num::NonZeroIsize::new_unchecked(self.window.hwnd() as isize)
|
||||
});
|
||||
let hinstance = unsafe { super::get_window_long(self.hwnd(), GWLP_HINSTANCE) };
|
||||
window_handle.hinstance = std::num::NonZeroIsize::new(hinstance);
|
||||
|
|
@ -150,8 +165,7 @@ impl Window {
|
|||
let window_state = Arc::clone(&self.window_state);
|
||||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MARKER_UNDECORATED_SHADOW, shadow)
|
||||
});
|
||||
});
|
||||
|
|
@ -202,7 +216,7 @@ impl Window {
|
|||
unsafe { ReleaseCapture() };
|
||||
|
||||
unsafe {
|
||||
PostMessageW(window, WM_NCLBUTTONDOWN, wparam, &points as *const _ as LPARAM)
|
||||
PostMessageW(window.hwnd(), WM_NCLBUTTONDOWN, wparam, &points as *const _ as LPARAM)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
@ -227,7 +241,7 @@ impl Window {
|
|||
|
||||
// get the current system menu
|
||||
let h_menu = GetSystemMenu(self.hwnd(), 0);
|
||||
if h_menu == 0 {
|
||||
if h_menu.is_null() {
|
||||
warn!("The corresponding window doesn't have a system menu");
|
||||
// This situation should not be treated as an error so just return without showing
|
||||
// menu.
|
||||
|
|
@ -373,7 +387,7 @@ impl CoreWindow for Window {
|
|||
let window_state = Arc::clone(&self.window_state);
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::TRANSPARENT, transparent)
|
||||
});
|
||||
});
|
||||
|
|
@ -386,21 +400,21 @@ impl CoreWindow for Window {
|
|||
let window_state = Arc::clone(&self.window_state);
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::VISIBLE, visible)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn is_visible(&self) -> Option<bool> {
|
||||
Some(unsafe { IsWindowVisible(self.window) == 1 })
|
||||
Some(unsafe { IsWindowVisible(self.window.hwnd()) == 1 })
|
||||
}
|
||||
|
||||
fn request_redraw(&self) {
|
||||
// NOTE: mark that we requested a redraw to handle requests during `WM_PAINT` handling.
|
||||
self.window_state.lock().unwrap().redraw_requested = true;
|
||||
unsafe {
|
||||
RedrawWindow(self.hwnd(), ptr::null(), 0, RDW_INTERNALPAINT);
|
||||
RedrawWindow(self.hwnd(), ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -434,7 +448,7 @@ impl CoreWindow for Window {
|
|||
let window = self.window;
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, false)
|
||||
});
|
||||
});
|
||||
|
|
@ -442,14 +456,14 @@ impl CoreWindow for Window {
|
|||
unsafe {
|
||||
SetWindowPos(
|
||||
self.hwnd(),
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
x,
|
||||
y,
|
||||
0,
|
||||
0,
|
||||
SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE,
|
||||
);
|
||||
InvalidateRgn(self.hwnd(), 0, false.into());
|
||||
InvalidateRgn(self.hwnd(), ptr::null_mut(), false.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -485,7 +499,7 @@ impl CoreWindow for Window {
|
|||
let window = self.window;
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, false)
|
||||
});
|
||||
});
|
||||
|
|
@ -528,7 +542,7 @@ impl CoreWindow for Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::RESIZABLE, resizable)
|
||||
});
|
||||
});
|
||||
|
|
@ -545,7 +559,7 @@ impl CoreWindow for Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MINIMIZABLE, buttons.contains(WindowButtons::MINIMIZE));
|
||||
f.set(WindowFlags::MAXIMIZABLE, buttons.contains(WindowButtons::MAXIMIZE));
|
||||
f.set(WindowFlags::CLOSABLE, buttons.contains(WindowButtons::CLOSE))
|
||||
|
|
@ -573,7 +587,7 @@ impl CoreWindow for Window {
|
|||
Cursor::Icon(icon) => {
|
||||
self.window_state_lock().mouse.selected_cursor = SelectedCursor::Named(icon);
|
||||
self.thread_executor.execute_in_thread(move || unsafe {
|
||||
let cursor = LoadCursorW(0, util::to_windows_cursor(icon));
|
||||
let cursor = LoadCursorW(ptr::null_mut(), util::to_windows_cursor(icon));
|
||||
SetCursor(cursor);
|
||||
});
|
||||
},
|
||||
|
|
@ -606,7 +620,7 @@ impl CoreWindow for Window {
|
|||
.lock()
|
||||
.unwrap()
|
||||
.mouse
|
||||
.set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine))
|
||||
.set_cursor_flags(window.hwnd(), |f| f.set(CursorFlags::GRABBED, confine))
|
||||
.map_err(|err| os_error!(err).into());
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
|
@ -625,7 +639,7 @@ impl CoreWindow for Window {
|
|||
.lock()
|
||||
.unwrap()
|
||||
.mouse
|
||||
.set_cursor_flags(window, |f| f.set(CursorFlags::HIDDEN, !visible))
|
||||
.set_cursor_flags(window.hwnd(), |f| f.set(CursorFlags::HIDDEN, !visible))
|
||||
.map_err(|e| e.to_string());
|
||||
let _ = tx.send(result);
|
||||
});
|
||||
|
|
@ -687,7 +701,7 @@ impl CoreWindow for Window {
|
|||
let window = self.window;
|
||||
let window_state = Arc::clone(&self.window_state);
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::IGNORE_CURSOR_EVENT, !hittest)
|
||||
});
|
||||
});
|
||||
|
|
@ -710,7 +724,7 @@ impl CoreWindow for Window {
|
|||
WindowState::set_window_flags_in_place(&mut window_state.lock().unwrap(), |f| {
|
||||
f.set(WindowFlags::MINIMIZED, is_minimized)
|
||||
});
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MINIMIZED, minimized)
|
||||
});
|
||||
});
|
||||
|
|
@ -726,7 +740,7 @@ impl CoreWindow for Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MAXIMIZED, maximized)
|
||||
});
|
||||
});
|
||||
|
|
@ -756,7 +770,7 @@ impl CoreWindow for Window {
|
|||
// 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)))
|
||||
if *monitor == monitor::current_monitor(window) =>
|
||||
if *monitor == monitor::current_monitor(window.hwnd()) =>
|
||||
{
|
||||
return
|
||||
},
|
||||
|
|
@ -783,7 +797,7 @@ impl CoreWindow for Window {
|
|||
ChangeDisplaySettingsExW(
|
||||
monitor_info.szDevice.as_ptr(),
|
||||
&*video_mode.native_video_mode,
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
CDS_FULLSCREEN,
|
||||
ptr::null(),
|
||||
)
|
||||
|
|
@ -800,7 +814,7 @@ impl CoreWindow for Window {
|
|||
ChangeDisplaySettingsExW(
|
||||
ptr::null(),
|
||||
ptr::null(),
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
CDS_FULLSCREEN,
|
||||
ptr::null(),
|
||||
)
|
||||
|
|
@ -825,11 +839,11 @@ impl CoreWindow for Window {
|
|||
// fine, taking control back from the DWM and ensuring that the `SetWindowPos` call
|
||||
// below goes through.
|
||||
let mut msg = mem::zeroed();
|
||||
PeekMessageW(&mut msg, 0, 0, 0, PM_NOREMOVE);
|
||||
PeekMessageW(&mut msg, ptr::null_mut(), 0, 0, PM_NOREMOVE);
|
||||
}
|
||||
|
||||
// Update window style
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(
|
||||
WindowFlags::MARKER_EXCLUSIVE_FULLSCREEN,
|
||||
matches!(fullscreen, Some(Fullscreen::Exclusive(_, _))),
|
||||
|
|
@ -846,7 +860,7 @@ impl CoreWindow for Window {
|
|||
// will generate WM_SIZE messages of the old window size that can race with what we set
|
||||
// below
|
||||
unsafe {
|
||||
taskbar_mark_fullscreen(window, fullscreen.is_some());
|
||||
taskbar_mark_fullscreen(window.hwnd(), fullscreen.is_some());
|
||||
}
|
||||
|
||||
// Update window bounds
|
||||
|
|
@ -855,7 +869,7 @@ impl CoreWindow for Window {
|
|||
// Save window bounds before entering fullscreen
|
||||
let placement = unsafe {
|
||||
let mut placement = mem::zeroed();
|
||||
GetWindowPlacement(window, &mut placement);
|
||||
GetWindowPlacement(window.hwnd(), &mut placement);
|
||||
placement
|
||||
};
|
||||
|
||||
|
|
@ -864,7 +878,7 @@ impl CoreWindow for Window {
|
|||
let monitor = match &fullscreen {
|
||||
Fullscreen::Exclusive(monitor, _) => monitor.clone(),
|
||||
Fullscreen::Borderless(Some(monitor)) => monitor.clone(),
|
||||
Fullscreen::Borderless(None) => monitor::current_monitor(window),
|
||||
Fullscreen::Borderless(None) => monitor::current_monitor(window.hwnd()),
|
||||
};
|
||||
|
||||
let position: (i32, i32) = monitor.position().unwrap_or_default().into();
|
||||
|
|
@ -872,15 +886,15 @@ impl CoreWindow for Window {
|
|||
|
||||
unsafe {
|
||||
SetWindowPos(
|
||||
window,
|
||||
0,
|
||||
window.hwnd(),
|
||||
ptr::null_mut(),
|
||||
position.0,
|
||||
position.1,
|
||||
size.0 as i32,
|
||||
size.1 as i32,
|
||||
SWP_ASYNCWINDOWPOS | SWP_NOZORDER,
|
||||
);
|
||||
InvalidateRgn(window, 0, false.into());
|
||||
InvalidateRgn(window.hwnd(), ptr::null_mut(), false.into());
|
||||
}
|
||||
},
|
||||
None => {
|
||||
|
|
@ -888,8 +902,8 @@ impl CoreWindow for Window {
|
|||
if let Some(SavedWindow { placement }) = window_state_lock.saved_window.take() {
|
||||
drop(window_state_lock);
|
||||
unsafe {
|
||||
SetWindowPlacement(window, &placement);
|
||||
InvalidateRgn(window, 0, false.into());
|
||||
SetWindowPlacement(window.hwnd(), &placement);
|
||||
InvalidateRgn(window.hwnd(), ptr::null_mut(), false.into());
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -903,7 +917,7 @@ impl CoreWindow for Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::MARKER_DECORATIONS, decorations)
|
||||
});
|
||||
});
|
||||
|
|
@ -920,7 +934,7 @@ impl CoreWindow for Window {
|
|||
|
||||
self.thread_executor.execute_in_thread(move || {
|
||||
let _ = &window;
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window, |f| {
|
||||
WindowState::set_window_flags(window_state.lock().unwrap(), window.hwnd(), |f| {
|
||||
f.set(WindowFlags::ALWAYS_ON_TOP, level == WindowLevel::AlwaysOnTop);
|
||||
f.set(WindowFlags::ALWAYS_ON_BOTTOM, level == WindowLevel::AlwaysOnBottom);
|
||||
});
|
||||
|
|
@ -953,7 +967,7 @@ impl CoreWindow for Window {
|
|||
let state = self.window_state.clone();
|
||||
self.thread_executor.execute_in_thread(move || unsafe {
|
||||
let scale_factor = state.lock().unwrap().scale_factor;
|
||||
ImeContext::current(window).set_ime_cursor_area(spot, size, scale_factor);
|
||||
ImeContext::current(window.hwnd()).set_ime_cursor_area(spot, size, scale_factor);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -962,7 +976,7 @@ impl CoreWindow for Window {
|
|||
let state = self.window_state.clone();
|
||||
self.thread_executor.execute_in_thread(move || unsafe {
|
||||
state.lock().unwrap().ime_allowed = allowed;
|
||||
ImeContext::set_ime_allowed(window, allowed);
|
||||
ImeContext::set_ime_allowed(window.hwnd(), allowed);
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -971,7 +985,7 @@ impl CoreWindow for Window {
|
|||
fn request_user_attention(&self, request_type: Option<UserAttentionType>) {
|
||||
let window = self.window;
|
||||
let active_window_handle = unsafe { GetActiveWindow() };
|
||||
if window == active_window_handle {
|
||||
if window.hwnd() == active_window_handle {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -985,7 +999,7 @@ impl CoreWindow for Window {
|
|||
|
||||
let flash_info = FLASHWINFO {
|
||||
cbSize: mem::size_of::<FLASHWINFO>() as u32,
|
||||
hwnd: window,
|
||||
hwnd: window.hwnd(),
|
||||
dwFlags: flags,
|
||||
uCount: count,
|
||||
dwTimeout: 0,
|
||||
|
|
@ -995,7 +1009,7 @@ impl CoreWindow for Window {
|
|||
}
|
||||
|
||||
fn set_theme(&self, theme: Option<Theme>) {
|
||||
try_theme(self.window, theme);
|
||||
try_theme(self.window.hwnd(), theme);
|
||||
}
|
||||
|
||||
fn theme(&self) -> Option<Theme> {
|
||||
|
|
@ -1008,9 +1022,9 @@ impl CoreWindow for Window {
|
|||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
let len = unsafe { GetWindowTextLengthW(self.window) } + 1;
|
||||
let len = unsafe { GetWindowTextLengthW(self.window.hwnd()) } + 1;
|
||||
let mut buf = vec![0; len as usize];
|
||||
unsafe { GetWindowTextW(self.window, buf.as_mut_ptr(), len) };
|
||||
unsafe { GetWindowTextW(self.window.hwnd(), buf.as_mut_ptr(), len) };
|
||||
util::decode_wide(&buf).to_string_lossy().to_string()
|
||||
}
|
||||
|
||||
|
|
@ -1020,10 +1034,10 @@ impl CoreWindow for Window {
|
|||
|
||||
let is_visible = window_flags.contains(WindowFlags::VISIBLE);
|
||||
let is_minimized = util::is_minimized(self.hwnd());
|
||||
let is_foreground = self.window == unsafe { GetForegroundWindow() };
|
||||
let is_foreground = self.window.hwnd() == unsafe { GetForegroundWindow() };
|
||||
|
||||
if is_visible && !is_minimized && !is_foreground {
|
||||
unsafe { force_window_active(self.window) };
|
||||
unsafe { force_window_active(self.window.hwnd()) };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1111,7 +1125,11 @@ impl InitData<'_> {
|
|||
|
||||
unsafe { ImeContext::set_ime_allowed(window, false) };
|
||||
|
||||
Window { window, window_state, thread_executor: self.event_loop.create_thread_executor() }
|
||||
Window {
|
||||
window: SyncWindowHandle(window),
|
||||
window_state,
|
||||
thread_executor: self.event_loop.create_thread_executor(),
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn create_window_data(&self, win: &Window) -> event_loop::WindowData {
|
||||
|
|
@ -1131,14 +1149,14 @@ impl InitData<'_> {
|
|||
|
||||
let file_drop_runner = self.event_loop.runner_shared.clone();
|
||||
let file_drop_handler = FileDropHandler::new(
|
||||
win.window,
|
||||
win.window.hwnd(),
|
||||
Box::new(move |event| file_drop_runner.send_event(event)),
|
||||
);
|
||||
|
||||
let handler_interface_ptr =
|
||||
unsafe { &mut (*file_drop_handler.data).interface as *mut _ as *mut c_void };
|
||||
|
||||
assert_eq!(unsafe { RegisterDragDrop(win.window, handler_interface_ptr) }, S_OK);
|
||||
assert_eq!(unsafe { RegisterDragDrop(win.window.hwnd(), handler_interface_ptr) }, S_OK);
|
||||
Some(file_drop_handler)
|
||||
} else {
|
||||
None
|
||||
|
|
@ -1317,8 +1335,8 @@ unsafe fn init(
|
|||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
parent.unwrap_or(0),
|
||||
menu.unwrap_or(0),
|
||||
parent.unwrap_or(ptr::null_mut()),
|
||||
menu.unwrap_or(ptr::null_mut()),
|
||||
util::get_instance_handle(),
|
||||
&mut initdata as *mut _ as *mut _,
|
||||
)
|
||||
|
|
@ -1329,7 +1347,7 @@ unsafe fn init(
|
|||
panic::resume_unwind(panic_error)
|
||||
}
|
||||
|
||||
if handle == 0 {
|
||||
if handle.is_null() {
|
||||
return Err(os_error!(io::Error::last_os_error()).into());
|
||||
}
|
||||
|
||||
|
|
@ -1342,7 +1360,7 @@ unsafe fn init(
|
|||
// size.
|
||||
if fullscreen.is_some() {
|
||||
win.set_fullscreen(fullscreen);
|
||||
unsafe { force_window_active(win.window) };
|
||||
unsafe { force_window_active(win.window.hwnd()) };
|
||||
} else if maximized {
|
||||
win.set_maximized(true);
|
||||
}
|
||||
|
|
@ -1358,12 +1376,12 @@ unsafe fn register_window_class(class_name: &[u16]) {
|
|||
cbClsExtra: 0,
|
||||
cbWndExtra: 0,
|
||||
hInstance: util::get_instance_handle(),
|
||||
hIcon: 0,
|
||||
hCursor: 0, // must be null in order for cursor state to work properly
|
||||
hbrBackground: 0,
|
||||
hIcon: ptr::null_mut(),
|
||||
hCursor: ptr::null_mut(), // must be null in order for cursor state to work properly
|
||||
hbrBackground: ptr::null_mut(),
|
||||
lpszMenuName: ptr::null(),
|
||||
lpszClassName: class_name.as_ptr(),
|
||||
hIconSm: 0,
|
||||
hIconSm: ptr::null_mut(),
|
||||
};
|
||||
|
||||
// We ignore errors because registering the same window class twice would trigger
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use std::io;
|
||||
use std::sync::MutexGuard;
|
||||
use std::{io, ptr};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use windows_sys::Win32::Foundation::{HWND, RECT};
|
||||
|
|
@ -356,7 +356,7 @@ impl WindowFlags {
|
|||
0,
|
||||
SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE,
|
||||
);
|
||||
InvalidateRgn(window, 0, false.into());
|
||||
InvalidateRgn(window, ptr::null_mut(), false.into());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -420,7 +420,7 @@ impl WindowFlags {
|
|||
}
|
||||
|
||||
// Refresh the window frame
|
||||
SetWindowPos(window, 0, 0, 0, 0, 0, flags);
|
||||
SetWindowPos(window, ptr::null_mut(), 0, 0, 0, 0, flags);
|
||||
SendMessageW(window, event_loop::SET_RETAIN_STATE_ON_SIZE_MSG_ID.get(), 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
@ -438,7 +438,7 @@ impl WindowFlags {
|
|||
}
|
||||
|
||||
util::win_to_err({
|
||||
let b_menu = GetMenu(hwnd) != 0;
|
||||
let b_menu = !GetMenu(hwnd).is_null();
|
||||
if let (Some(get_dpi_for_window), Some(adjust_window_rect_ex_for_dpi)) =
|
||||
(*util::GET_DPI_FOR_WINDOW, *util::ADJUST_WINDOW_RECT_EX_FOR_DPI)
|
||||
{
|
||||
|
|
@ -468,14 +468,14 @@ impl WindowFlags {
|
|||
let (width, height): (u32, u32) = self.adjust_size(hwnd, size).into();
|
||||
SetWindowPos(
|
||||
hwnd,
|
||||
0,
|
||||
ptr::null_mut(),
|
||||
0,
|
||||
0,
|
||||
width as _,
|
||||
height as _,
|
||||
SWP_ASYNCWINDOWPOS | SWP_NOZORDER | SWP_NOREPOSITION | SWP_NOMOVE | SWP_NOACTIVATE,
|
||||
);
|
||||
InvalidateRgn(hwnd, 0, false.into());
|
||||
InvalidateRgn(hwnd, ptr::null_mut(), false.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue