2024-10-11 11:15:54 +03:00
|
|
|
use windows_sys::Win32::Foundation::HWND;
|
2022-03-07 22:58:12 +01:00
|
|
|
use windows_sys::Win32::UI::WindowsAndMessaging::{HMENU, WINDOW_LONG_PTR_INDEX};
|
2015-04-29 10:19:59 +02:00
|
|
|
|
2024-11-13 15:29:05 +03:00
|
|
|
pub(crate) use self::event_loop::{EventLoop, PlatformSpecificEventLoopAttributes};
|
2020-03-07 19:42:21 +00:00
|
|
|
pub use self::icon::WinIcon as PlatformIcon;
|
2024-01-05 17:02:08 +01:00
|
|
|
pub(crate) use self::icon::{SelectedCursor, WinCursor as PlatformCustomCursor, WinIcon};
|
2024-01-04 12:54:35 +01:00
|
|
|
pub(crate) use self::keyboard::{physicalkey_to_scancode, scancode_to_physicalkey};
|
2025-01-02 03:29:42 +03:00
|
|
|
pub(crate) use self::monitor::MonitorHandle;
|
2024-01-05 17:02:08 +01:00
|
|
|
pub(crate) use self::window::Window;
|
2024-02-03 07:27:17 +04:00
|
|
|
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
|
2024-10-11 11:15:54 +03:00
|
|
|
use crate::event::DeviceId;
|
2020-03-07 19:42:21 +00:00
|
|
|
use crate::icon::Icon;
|
2024-01-25 20:59:10 +03:00
|
|
|
use crate::platform::windows::{BackdropType, Color, CornerPreference};
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2024-08-08 00:46:28 +02:00
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
2024-01-31 17:29:59 +04:00
|
|
|
pub struct PlatformSpecificWindowAttributes {
|
2022-12-22 08:07:13 +08:00
|
|
|
pub owner: Option<HWND>,
|
2021-02-04 22:26:33 +01:00
|
|
|
pub menu: Option<HMENU>,
|
2019-02-05 10:30:33 -05:00
|
|
|
pub taskbar_icon: Option<Icon>,
|
2018-06-22 10:33:29 +09:00
|
|
|
pub no_redirection_bitmap: bool,
|
2020-06-29 01:17:27 +03:00
|
|
|
pub drag_and_drop: bool,
|
2022-04-01 20:21:09 +02:00
|
|
|
pub skip_taskbar: bool,
|
2023-07-29 15:39:23 +02:00
|
|
|
pub class_name: String,
|
2022-08-15 02:36:37 +02:00
|
|
|
pub decoration_shadow: bool,
|
2024-01-25 20:59:10 +03:00
|
|
|
pub backdrop_type: BackdropType,
|
2024-01-22 19:55:37 +02:00
|
|
|
pub clip_children: bool,
|
2024-01-19 12:43:39 +01:00
|
|
|
pub border_color: Option<Color>,
|
|
|
|
|
pub title_background_color: Option<Color>,
|
|
|
|
|
pub title_text_color: Option<Color>,
|
|
|
|
|
pub corner_preference: Option<CornerPreference>,
|
2020-06-29 01:17:27 +03:00
|
|
|
}
|
|
|
|
|
|
2024-01-31 17:29:59 +04:00
|
|
|
impl Default for PlatformSpecificWindowAttributes {
|
2020-06-29 01:17:27 +03:00
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
2022-12-22 08:07:13 +08:00
|
|
|
owner: None,
|
2021-02-04 22:26:33 +01:00
|
|
|
menu: None,
|
2020-06-29 01:17:27 +03:00
|
|
|
taskbar_icon: None,
|
|
|
|
|
no_redirection_bitmap: false,
|
|
|
|
|
drag_and_drop: true,
|
2022-04-01 20:21:09 +02:00
|
|
|
skip_taskbar: false,
|
2023-07-29 15:39:23 +02:00
|
|
|
class_name: "Window Class".to_string(),
|
2022-08-15 02:36:37 +02:00
|
|
|
decoration_shadow: false,
|
2024-01-25 20:59:10 +03:00
|
|
|
backdrop_type: BackdropType::default(),
|
2024-01-22 19:55:37 +02:00
|
|
|
clip_children: true,
|
2024-01-19 12:43:39 +01:00
|
|
|
border_color: None,
|
|
|
|
|
title_background_color: None,
|
|
|
|
|
title_text_color: None,
|
|
|
|
|
corner_preference: None,
|
2020-06-29 01:17:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-25 17:05:39 +01:00
|
|
|
}
|
2016-11-29 13:02:42 +01:00
|
|
|
|
2024-01-31 17:29:59 +04:00
|
|
|
unsafe impl Send for PlatformSpecificWindowAttributes {}
|
|
|
|
|
unsafe impl Sync for PlatformSpecificWindowAttributes {}
|
2016-11-29 13:02:42 +01:00
|
|
|
|
2024-10-11 11:15:54 +03:00
|
|
|
fn wrap_device_id(id: u32) -> DeviceId {
|
|
|
|
|
DeviceId::from_raw(id as i64)
|
Windows: Implement DeviceEvents (#482)
Fixes #467
All variants other than Text have been implemented. While Text can
be implemented using ToUnicode, that doesn't play nice with dead
keys, IME, etc.
Most of the mouse DeviceEvents were already implemented, but due
to the flags that were used when registering for raw input events,
they only worked when the window was in the foreground.
This is also a step forward for #338, as DeviceIds are no longer
useless on Windows. On DeviceEvents, the DeviceId contains that
device's handle. While that handle could ostensibly be used by
developers to query device information, my actual reason for
choosing it is because it's simply a very easy way to handle this.
As a fun bonus, this enabled me to create this method:
DevideIdExt::get_persistent_identifier() -> Option<String>
Using this gives you a unique identifier for the device that
persists across replugs/reboots/etc., so it's ideal for something
like device-specific configuration.
There's a notable caveat to the new DeviceIds, which is that the
value will always be 0 for a WindowEvent. There doesn't seem to be
any straightforward way around this limitation.
I was concerned that multi-window applications would receive n
copies of every DeviceEvent, but Windows only sends them to one
window per application.
Lastly, there's a chance that these additions will cause
antivirus/etc. software to detect winit applications as keyloggers.
I don't know how likely that is to actually happen to people, but
if it does become an issue, the raw input code is neatly
sequestered and would be easy to make optional during compilation.
2018-04-28 12:42:33 -04:00
|
|
|
}
|
2016-10-31 17:21:48 +01:00
|
|
|
|
2022-03-07 22:58:12 +01:00
|
|
|
#[inline(always)]
|
|
|
|
|
const fn get_xbutton_wparam(x: u32) -> u16 {
|
2022-11-23 16:43:56 +01:00
|
|
|
hiword(x)
|
2022-03-07 22:58:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
2022-06-02 19:08:54 +02:00
|
|
|
const fn get_x_lparam(x: u32) -> i16 {
|
|
|
|
|
loword(x) as _
|
2022-03-07 22:58:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
2022-06-02 19:08:54 +02:00
|
|
|
const fn get_y_lparam(x: u32) -> i16 {
|
|
|
|
|
hiword(x) as _
|
2022-03-07 22:58:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
2023-05-28 20:02:59 +02:00
|
|
|
pub(crate) const fn primarylangid(lgid: u16) -> u16 {
|
|
|
|
|
lgid & 0x3ff
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
pub(crate) const fn loword(x: u32) -> u16 {
|
2022-03-07 22:58:12 +01:00
|
|
|
(x & 0xffff) as u16
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
const fn hiword(x: u32) -> u16 {
|
|
|
|
|
((x >> 16) & 0xffff) as u16
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
unsafe fn get_window_long(hwnd: HWND, nindex: WINDOW_LONG_PTR_INDEX) -> isize {
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2023-09-29 16:07:44 +02:00
|
|
|
return unsafe { windows_sys::Win32::UI::WindowsAndMessaging::GetWindowLongPtrW(hwnd, nindex) };
|
2022-03-07 22:58:12 +01:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
2023-09-29 16:07:44 +02:00
|
|
|
return unsafe {
|
|
|
|
|
windows_sys::Win32::UI::WindowsAndMessaging::GetWindowLongW(hwnd, nindex) as isize
|
|
|
|
|
};
|
2022-03-07 22:58:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
|
unsafe fn set_window_long(hwnd: HWND, nindex: WINDOW_LONG_PTR_INDEX, dwnewlong: isize) -> isize {
|
|
|
|
|
#[cfg(target_pointer_width = "64")]
|
2023-09-29 16:07:44 +02:00
|
|
|
return unsafe {
|
|
|
|
|
windows_sys::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW(hwnd, nindex, dwnewlong)
|
|
|
|
|
};
|
2022-03-07 22:58:12 +01:00
|
|
|
#[cfg(target_pointer_width = "32")]
|
2023-09-29 16:07:44 +02:00
|
|
|
return unsafe {
|
|
|
|
|
windows_sys::Win32::UI::WindowsAndMessaging::SetWindowLongW(hwnd, nindex, dwnewlong as i32)
|
|
|
|
|
as isize
|
|
|
|
|
};
|
2022-03-07 22:58:12 +01:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 18:37:25 +02:00
|
|
|
#[macro_use]
|
|
|
|
|
mod util;
|
2019-12-22 19:04:09 +00:00
|
|
|
mod dark_mode;
|
2022-03-07 22:58:12 +01:00
|
|
|
mod definitions;
|
2018-06-14 19:42:18 -04:00
|
|
|
mod dpi;
|
2018-10-24 20:40:12 +02:00
|
|
|
mod drop_handler;
|
2019-02-05 10:30:33 -05:00
|
|
|
mod event_loop;
|
2018-05-07 17:36:21 -04:00
|
|
|
mod icon;
|
2022-05-07 05:29:25 +03:00
|
|
|
mod ime;
|
2023-05-28 20:02:59 +02:00
|
|
|
mod keyboard;
|
|
|
|
|
mod keyboard_layout;
|
2017-06-26 21:21:13 +02:00
|
|
|
mod monitor;
|
2024-10-11 11:15:54 +03:00
|
|
|
pub(crate) mod raw_input;
|
2017-06-26 21:21:13 +02:00
|
|
|
mod window;
|
2019-02-04 11:52:00 -05:00
|
|
|
mod window_state;
|