2022-12-25 09:57:27 +02:00
|
|
|
#![cfg(windows_platform)]
|
2015-04-24 09:51:23 +02:00
|
|
|
|
2023-05-28 20:02:59 +02:00
|
|
|
use smol_str::SmolStr;
|
2022-03-07 22:58:12 +01:00
|
|
|
use windows_sys::Win32::{
|
|
|
|
|
Foundation::{HANDLE, HWND},
|
|
|
|
|
UI::WindowsAndMessaging::{HMENU, WINDOW_LONG_PTR_INDEX},
|
|
|
|
|
};
|
2015-04-29 10:19:59 +02:00
|
|
|
|
2022-02-16 22:09:03 +01:00
|
|
|
pub(crate) use self::{
|
|
|
|
|
event_loop::{
|
|
|
|
|
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
|
|
|
|
|
},
|
2023-12-16 22:02:17 +02:00
|
|
|
icon::{SelectedCursor, WinIcon},
|
2024-01-04 12:54:35 +01:00
|
|
|
keyboard::{physicalkey_to_scancode, scancode_to_physicalkey},
|
2023-12-26 22:12:33 +01:00
|
|
|
monitor::{MonitorHandle, VideoModeHandle},
|
2019-06-21 11:33:15 -04:00
|
|
|
window::Window,
|
|
|
|
|
};
|
2017-01-28 15:00:17 +01:00
|
|
|
|
2024-01-05 17:02:08 +01:00
|
|
|
pub(crate) use self::icon::WinCursor as PlatformCustomCursor;
|
2020-03-07 19:42:21 +00:00
|
|
|
pub use self::icon::WinIcon as PlatformIcon;
|
2023-12-23 16:12:29 +01:00
|
|
|
pub(crate) use crate::cursor::OnlyCursorImageBuilder as PlatformCustomCursorBuilder;
|
2023-08-24 18:29:31 +02:00
|
|
|
use crate::platform_impl::Fullscreen;
|
2020-03-07 19:42:21 +00:00
|
|
|
|
|
|
|
|
use crate::event::DeviceId as RootDeviceId;
|
|
|
|
|
use crate::icon::Icon;
|
2023-05-28 20:02:59 +02:00
|
|
|
use crate::keyboard::Key;
|
2019-02-05 10:30:33 -05:00
|
|
|
|
2020-06-29 01:17:27 +03:00
|
|
|
#[derive(Clone)]
|
2016-11-25 17:05:39 +01:00
|
|
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
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,
|
2020-06-29 01:17:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for PlatformSpecificWindowBuilderAttributes {
|
|
|
|
|
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,
|
2020-06-29 01:17:27 +03:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-25 17:05:39 +01:00
|
|
|
}
|
2016-11-29 13:02:42 +01:00
|
|
|
|
|
|
|
|
unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
|
|
|
|
|
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
|
|
|
|
|
|
2018-05-19 12:02:57 -04:00
|
|
|
// Cursor name in UTF-16. Used to set cursor in `WM_SETCURSOR`.
|
2018-09-22 21:03:38 -04:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2022-03-07 22:58:12 +01:00
|
|
|
pub struct Cursor(pub *const u16);
|
2018-05-19 12:02:57 -04:00
|
|
|
unsafe impl Send for Cursor {}
|
|
|
|
|
unsafe impl Sync for Cursor {}
|
2016-10-31 17:21:48 +01:00
|
|
|
|
2017-06-26 21:21:13 +02:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
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
|
|
|
pub struct DeviceId(u32);
|
|
|
|
|
|
2018-12-21 09:51:48 -07:00
|
|
|
impl DeviceId {
|
2021-08-30 19:40:02 +02:00
|
|
|
pub const unsafe fn dummy() -> Self {
|
2018-12-21 09:51:48 -07:00
|
|
|
DeviceId(0)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
impl DeviceId {
|
2019-05-29 21:29:54 -04:00
|
|
|
pub fn persistent_identifier(&self) -> Option<String> {
|
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
|
|
|
if self.0 != 0 {
|
2022-03-07 22:58:12 +01:00
|
|
|
raw_input::get_raw_input_device_name(self.0 as HANDLE)
|
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
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Constant device ID, to be removed when this backend is updated to report real device IDs.
|
2019-02-05 10:30:33 -05:00
|
|
|
const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId(0));
|
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
|
|
|
|
2019-02-05 10:30:33 -05:00
|
|
|
fn wrap_device_id(id: u32) -> RootDeviceId {
|
|
|
|
|
RootDeviceId(DeviceId(id))
|
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
|
|
|
|
2019-05-29 21:29:54 -04:00
|
|
|
pub type OsError = std::io::Error;
|
|
|
|
|
|
2023-05-28 20:02:59 +02:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
|
|
|
|
|
pub struct KeyEventExtra {
|
2024-01-04 12:54:35 +01:00
|
|
|
pub text_with_all_modifiers: Option<SmolStr>,
|
2023-05-28 20:02:59 +02:00
|
|
|
pub key_without_modifiers: Key,
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-26 21:21:13 +02:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
2017-12-24 15:46:47 +02:00
|
|
|
pub struct WindowId(HWND);
|
2017-06-26 21:21:13 +02:00
|
|
|
unsafe impl Send for WindowId {}
|
|
|
|
|
unsafe impl Sync for WindowId {}
|
2016-10-31 17:21:48 +01:00
|
|
|
|
2018-12-21 09:51:48 -07:00
|
|
|
impl WindowId {
|
2021-08-30 19:40:02 +02:00
|
|
|
pub const unsafe fn dummy() -> Self {
|
2022-03-07 22:58:12 +01:00
|
|
|
WindowId(0)
|
2018-12-21 09:51:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 14:27:19 +03:00
|
|
|
impl From<WindowId> for u64 {
|
|
|
|
|
fn from(window_id: WindowId) -> Self {
|
|
|
|
|
window_id.0 as u64
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 02:36:37 +02:00
|
|
|
impl From<WindowId> for HWND {
|
|
|
|
|
fn from(window_id: WindowId) -> Self {
|
|
|
|
|
window_id.0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 14:27:19 +03:00
|
|
|
impl From<u64> for WindowId {
|
|
|
|
|
fn from(raw_id: u64) -> Self {
|
|
|
|
|
Self(raw_id as HWND)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
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
|
|
|
mod raw_input;
|
2017-06-26 21:21:13 +02:00
|
|
|
mod window;
|
2019-02-04 11:52:00 -05:00
|
|
|
mod window_state;
|