2015-04-24 17:51:23 +10:00
|
|
|
#![cfg(target_os = "windows")]
|
|
|
|
|
2017-06-27 05:21:13 +10:00
|
|
|
use winapi;
|
2017-12-25 00:46:47 +11:00
|
|
|
use winapi::shared::windef::HWND;
|
2015-04-29 18:19:59 +10:00
|
|
|
|
2017-06-27 05:21:13 +10:00
|
|
|
pub use self::events_loop::{EventsLoop, EventsLoopProxy};
|
2017-09-01 19:04:57 +10:00
|
|
|
pub use self::monitor::MonitorId;
|
2017-06-27 05:21:13 +10:00
|
|
|
pub use self::window::Window;
|
2017-01-29 01:00:17 +11:00
|
|
|
|
2016-05-23 16:17:31 +10:00
|
|
|
#[derive(Clone, Default)]
|
2016-11-26 03:05:39 +11:00
|
|
|
pub struct PlatformSpecificWindowBuilderAttributes {
|
2017-12-25 00:46:47 +11:00
|
|
|
pub parent: Option<HWND>,
|
2018-05-08 07:36:21 +10:00
|
|
|
pub taskbar_icon: Option<::Icon>,
|
2018-06-22 11:33:29 +10:00
|
|
|
pub no_redirection_bitmap: bool,
|
2016-11-26 03:05:39 +11:00
|
|
|
}
|
2016-11-29 23:02:42 +11:00
|
|
|
|
|
|
|
unsafe impl Send for PlatformSpecificWindowBuilderAttributes {}
|
|
|
|
unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
|
|
|
|
|
2018-05-20 02:02:57 +10:00
|
|
|
// Cursor name in UTF-16. Used to set cursor in `WM_SETCURSOR`.
|
2018-09-23 11:03:38 +10:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2018-05-20 02:02:57 +10:00
|
|
|
pub struct Cursor(pub *const winapi::ctypes::wchar_t);
|
|
|
|
unsafe impl Send for Cursor {}
|
|
|
|
unsafe impl Sync for Cursor {}
|
2016-11-01 03:21:48 +11:00
|
|
|
|
2017-06-27 05:21:13 +10: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-29 02:42:33 +10:00
|
|
|
pub struct DeviceId(u32);
|
|
|
|
|
2018-12-22 03:51:48 +11:00
|
|
|
impl DeviceId {
|
|
|
|
pub unsafe fn dummy() -> Self {
|
|
|
|
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-29 02:42:33 +10:00
|
|
|
impl DeviceId {
|
|
|
|
pub fn get_persistent_identifier(&self) -> Option<String> {
|
|
|
|
if self.0 != 0 {
|
|
|
|
raw_input::get_raw_input_device_name(self.0 as _)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constant device ID, to be removed when this backend is updated to report real device IDs.
|
|
|
|
const DEVICE_ID: ::DeviceId = ::DeviceId(DeviceId(0));
|
|
|
|
|
|
|
|
fn wrap_device_id(id: u32) -> ::DeviceId {
|
|
|
|
::DeviceId(DeviceId(id))
|
|
|
|
}
|
2016-11-01 03:21:48 +11:00
|
|
|
|
2017-06-27 05:21:13 +10:00
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
2017-12-25 00:46:47 +11:00
|
|
|
pub struct WindowId(HWND);
|
2017-06-27 05:21:13 +10:00
|
|
|
unsafe impl Send for WindowId {}
|
|
|
|
unsafe impl Sync for WindowId {}
|
2016-11-01 03:21:48 +11:00
|
|
|
|
2018-12-22 03:51:48 +11:00
|
|
|
impl WindowId {
|
|
|
|
pub unsafe fn dummy() -> Self {
|
|
|
|
use std::ptr::null_mut;
|
|
|
|
|
|
|
|
WindowId(null_mut())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-15 09:42:18 +10:00
|
|
|
mod dpi;
|
2018-10-25 05:40:12 +11:00
|
|
|
mod drop_handler;
|
2017-06-27 05:21:13 +10:00
|
|
|
mod event;
|
|
|
|
mod events_loop;
|
2018-05-08 07:36:21 +10:00
|
|
|
mod icon;
|
2017-06-27 05:21:13 +10: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-29 02:42:33 +10:00
|
|
|
mod raw_input;
|
|
|
|
mod util;
|
2017-06-27 05:21:13 +10:00
|
|
|
mod window;
|
2019-02-05 03:52:00 +11:00
|
|
|
mod window_state;
|