Skip to content

Commit

Permalink
update remaining files
Browse files Browse the repository at this point in the history
  • Loading branch information
raphamorim committed Feb 18, 2025
1 parent 845c68a commit ebe19ac
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 207 deletions.
8 changes: 3 additions & 5 deletions rio-window/src/platform_impl/windows/drop_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ use std::path::PathBuf;
use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};

use windows_sys::core::{IUnknown, GUID, HRESULT};
use windows_sys::core::{GUID, HRESULT};
use windows_sys::Win32::Foundation::{DV_E_FORMATETC, HWND, POINTL, S_OK};
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 tracing::debug;

use crate::platform_impl::platform::definitions::{
IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknownVtbl,
IDataObject, IDataObjectVtbl, IDropTarget, IDropTargetVtbl, IUnknown, IUnknownVtbl,
};
use crate::platform_impl::platform::WindowId;

Expand Down
66 changes: 42 additions & 24 deletions rio-window/src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::{mem, panic, ptr};

use crate::utils::Lazy;

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,
};
Expand All @@ -45,7 +44,9 @@ use windows_sys::Win32::UI::Input::Touch::{
CloseTouchInputHandle, GetTouchInputInfo, TOUCHEVENTF_DOWN, TOUCHEVENTF_MOVE,
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,
Expand Down Expand Up @@ -432,7 +433,9 @@ impl<T: 'static> EventLoop<T> {

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;
}

Expand Down Expand Up @@ -671,10 +674,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))
}
}
}
Expand Down Expand Up @@ -973,12 +976,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);
Expand All @@ -1001,8 +1004,8 @@ fn create_event_target_window() -> HWND {
0,
0,
0,
0,
0,
ptr::null_mut(),
ptr::null_mut(),
util::get_instance_handle(),
ptr::null(),
);
Expand Down Expand Up @@ -1338,7 +1341,9 @@ unsafe fn public_window_callback_inner(
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 => {
Expand Down Expand Up @@ -1388,7 +1393,7 @@ unsafe fn public_window_callback_inner(
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())
Expand Down Expand Up @@ -1851,7 +1856,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);
Expand Down Expand Up @@ -2033,7 +2038,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);
Expand All @@ -2042,7 +2047,7 @@ unsafe fn public_window_callback_inner(
WM_TOUCH => {
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,
Expand Down Expand Up @@ -2301,7 +2306,10 @@ 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(),
};
Expand Down Expand Up @@ -2552,7 +2560,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,
Expand Down Expand Up @@ -2640,7 +2648,9 @@ unsafe extern "system" fn thread_event_target_callback(
// the git blame and history would be preserved.
let callback = || match msg {
WM_NCDESTROY => {
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
unsafe {
RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT)
};
unsafe { super::set_window_long(window, GWL_USERDATA, 0) };
userdata_removed = true;
0
Expand All @@ -2653,13 +2663,17 @@ unsafe extern "system" fn thread_event_target_callback(
},

WM_INPUT_DEVICE_CHANGE => {
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
unsafe {
RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT)
};
let event = match wparam as u32 {
GIDC_ARRIVAL => DeviceEvent::Added,
GIDC_REMOVAL => DeviceEvent::Removed,
_ => unreachable!(),
};
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
unsafe {
RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT)
};

userdata.send_event(Event::DeviceEvent {
device_id: wrap_device_id(lparam as u32),
Expand All @@ -2678,7 +2692,9 @@ unsafe extern "system" fn thread_event_target_callback(
}

_ if msg == USER_EVENT_MSG_ID.get() => {
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
unsafe {
RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT)
};
// synthesis a placeholder UserEvent, so that if the callback is
// re-entered it can be buffered for later delivery. the real
// user event is still in the mpsc channel and will be pulled
Expand All @@ -2688,7 +2704,9 @@ unsafe extern "system" fn thread_event_target_callback(
0
}
_ if msg == EXEC_MSG_ID.get() => {
unsafe { RedrawWindow(window, ptr::null(), 0, RDW_INTERNALPAINT) };
unsafe {
RedrawWindow(window, ptr::null(), ptr::null_mut(), RDW_INTERNALPAINT)
};
let mut function: ThreadExecFn = unsafe { Box::from_raw(wparam as *mut _) };
function();
0
Expand Down Expand Up @@ -2718,7 +2736,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;

Expand Down
37 changes: 24 additions & 13 deletions rio-window/src/platform_impl/windows/icon.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,7 +42,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,
Expand All @@ -51,7 +51,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()))
Expand All @@ -70,6 +70,9 @@ struct RaiiIcon {
handle: HICON,
}

unsafe impl Send for RaiiIcon {}
unsafe impl Sync for RaiiIcon {}

#[derive(Clone)]
pub struct WinIcon {
inner: Arc<RaiiIcon>,
Expand All @@ -93,15 +96,15 @@ impl WinIcon {

let handle = unsafe {
LoadImageW(
0,
ptr::null_mut(),
wide_path.as_ptr(),
IMAGE_ICON,
width,
height,
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()))
Expand All @@ -124,7 +127,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()))
Expand All @@ -138,7 +141,12 @@ 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,
);
}
}

Expand Down Expand Up @@ -194,13 +202,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(io::Error::last_os_error());
}
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(io::Error::last_os_error());
}
if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void)
Expand All @@ -213,7 +221,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(io::Error::last_os_error());
}
Expand All @@ -229,7 +237,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(io::Error::last_os_error());
}

Expand All @@ -243,6 +251,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) };
Expand Down
8 changes: 4 additions & 4 deletions rio-window/src/platform_impl/windows/ime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ 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_COMPATTR, GCS_COMPSTR, GCS_CURSORPOS, GCS_RESULTSTR, HIMC, IACE_CHILDREN,
IACE_DEFAULT,
};
use windows_sys::Win32::UI::WindowsAndMessaging::{GetSystemMetrics, SM_IMMENABLED};

Expand Down Expand Up @@ -152,9 +152,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) };
}
}

Expand Down
15 changes: 7 additions & 8 deletions rio-window/src/platform_impl/windows/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ 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,
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, VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, 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,
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, VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2,
VK_NUMPAD3, VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7, 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,
Expand Down
Loading

0 comments on commit ebe19ac

Please sign in to comment.