2019-02-06 02:30:33 +11:00
|
|
|
|
//! The `Event` enum and assorted supporting types.
|
|
|
|
|
//!
|
|
|
|
|
//! These are sent to the closure given to [`EventLoop::run(...)`][event_loop_run], where they get
|
|
|
|
|
//! processed and used to modify the program state. For more details, see the root-level documentation.
|
|
|
|
|
//!
|
2020-01-06 03:02:41 +11:00
|
|
|
|
//! Some of these events represent different "parts" of a traditional event-handling loop. You could
|
|
|
|
|
//! approximate the basic ordering loop of [`EventLoop::run(...)`][event_loop_run] like this:
|
|
|
|
|
//!
|
|
|
|
|
//! ```rust,ignore
|
|
|
|
|
//! let mut control_flow = ControlFlow::Poll;
|
|
|
|
|
//! let mut start_cause = StartCause::Init;
|
|
|
|
|
//!
|
|
|
|
|
//! while control_flow != ControlFlow::Exit {
|
|
|
|
|
//! event_handler(NewEvents(start_cause), ..., &mut control_flow);
|
|
|
|
|
//!
|
|
|
|
|
//! for e in (window events, user events, device events) {
|
|
|
|
|
//! event_handler(e, ..., &mut control_flow);
|
|
|
|
|
//! }
|
|
|
|
|
//! event_handler(MainEventsCleared, ..., &mut control_flow);
|
|
|
|
|
//!
|
|
|
|
|
//! for w in (redraw windows) {
|
|
|
|
|
//! event_handler(RedrawRequested(w), ..., &mut control_flow);
|
|
|
|
|
//! }
|
|
|
|
|
//! event_handler(RedrawEventsCleared, ..., &mut control_flow);
|
|
|
|
|
//!
|
|
|
|
|
//! start_cause = wait_if_necessary(control_flow);
|
|
|
|
|
//! }
|
|
|
|
|
//!
|
|
|
|
|
//! event_handler(LoopDestroyed, ..., &mut control_flow);
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! This leaves out timing details like `ControlFlow::WaitUntil` but hopefully
|
|
|
|
|
//! describes what happens in what order.
|
|
|
|
|
//!
|
2019-11-13 10:51:46 +11:00
|
|
|
|
//! [event_loop_run]: crate::event_loop::EventLoop::run
|
2019-06-17 14:30:05 +10:00
|
|
|
|
use instant::Instant;
|
2015-06-24 08:05:37 +10:00
|
|
|
|
use std::path::PathBuf;
|
2018-06-15 09:42:18 +10:00
|
|
|
|
|
2019-06-22 01:33:15 +10:00
|
|
|
|
use crate::{
|
2020-07-27 08:16:21 +10:00
|
|
|
|
dpi::{PhysicalPosition, PhysicalSize},
|
2019-06-22 01:33:15 +10:00
|
|
|
|
platform_impl,
|
2019-12-23 06:04:09 +11:00
|
|
|
|
window::{Theme, WindowId},
|
2019-06-22 01:33:15 +10:00
|
|
|
|
};
|
2015-06-24 08:05:37 +10:00
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes a generic event.
|
2020-01-06 03:02:41 +11:00
|
|
|
|
///
|
|
|
|
|
/// See the module-level docs for more information on the event loop manages each event.
|
2019-06-20 06:49:43 +10:00
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
|
pub enum Event<'a, T: 'static> {
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// Emitted when new events arrive from the OS to be processed.
|
|
|
|
|
///
|
|
|
|
|
/// This event type is useful as a place to put code that should be done before you start
|
|
|
|
|
/// processing events, such as updating frame timing information for benchmarking or checking
|
|
|
|
|
/// the [`StartCause`][crate::event::StartCause] to see if a timer set by
|
|
|
|
|
/// [`ControlFlow::WaitUntil`](crate::event_loop::ControlFlow::WaitUntil) has elapsed.
|
|
|
|
|
NewEvents(StartCause),
|
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
|
/// Emitted when the OS sends an event to a winit window.
|
2017-01-29 01:00:17 +11:00
|
|
|
|
WindowEvent {
|
2017-02-03 19:13:11 +11:00
|
|
|
|
window_id: WindowId,
|
2019-06-20 06:49:43 +10:00
|
|
|
|
event: WindowEvent<'a>,
|
2017-04-23 06:52:35 +10:00
|
|
|
|
},
|
2020-01-06 03:02:41 +11:00
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
|
/// Emitted when the OS sends an event to a device.
|
2017-04-23 06:52:35 +10:00
|
|
|
|
DeviceEvent {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
event: DeviceEvent,
|
|
|
|
|
},
|
2020-01-06 03:02:41 +11:00
|
|
|
|
|
2019-11-12 10:05:59 +11:00
|
|
|
|
/// Emitted when an event is sent from [`EventLoopProxy::send_event`](crate::event_loop::EventLoopProxy::send_event)
|
2019-02-06 02:30:33 +11:00
|
|
|
|
UserEvent(T),
|
2020-01-06 03:02:41 +11:00
|
|
|
|
|
|
|
|
|
/// Emitted when the application has been suspended.
|
|
|
|
|
Suspended,
|
|
|
|
|
|
|
|
|
|
/// Emitted when the application has been resumed.
|
|
|
|
|
Resumed,
|
|
|
|
|
|
|
|
|
|
/// Emitted when all of the event loop's input events have been processed and redraw processing
|
|
|
|
|
/// is about to begin.
|
2019-07-31 16:31:12 +10:00
|
|
|
|
///
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// This event is useful as a place to put your code that should be run after all
|
|
|
|
|
/// state-changing events have been handled and you want to do stuff (updating state, performing
|
2020-04-20 07:09:08 +10:00
|
|
|
|
/// calculations, etc) that happens as the "main body" of your event loop. If your program only draws
|
|
|
|
|
/// graphics when something changes, it's usually better to do it in response to
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// [`Event::RedrawRequested`](crate::event::Event::RedrawRequested), which gets emitted
|
2020-04-20 07:09:08 +10:00
|
|
|
|
/// immediately after this event. Programs that draw graphics continuously, like most games,
|
|
|
|
|
/// can render here unconditionally for simplicity.
|
2019-07-31 16:31:12 +10:00
|
|
|
|
MainEventsCleared,
|
|
|
|
|
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// Emitted after `MainEventsCleared` when a window should be redrawn.
|
|
|
|
|
///
|
|
|
|
|
/// This gets triggered in two scenarios:
|
|
|
|
|
/// - The OS has performed an operation that's invalidated the window's contents (such as
|
|
|
|
|
/// resizing the window).
|
|
|
|
|
/// - The application has explicitly requested a redraw via
|
|
|
|
|
/// [`Window::request_redraw`](crate::window::Window::request_redraw).
|
2019-07-31 16:31:12 +10:00
|
|
|
|
///
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// During each iteration of the event loop, Winit will aggregate duplicate redraw requests
|
|
|
|
|
/// into a single event, to help avoid duplicating rendering work.
|
2020-04-20 07:09:08 +10:00
|
|
|
|
///
|
|
|
|
|
/// Mainly of interest to applications with mostly-static graphics that avoid redrawing unless
|
|
|
|
|
/// something changes, like most non-game GUIs.
|
2019-07-31 16:31:12 +10:00
|
|
|
|
RedrawRequested(WindowId),
|
|
|
|
|
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// Emitted after all `RedrawRequested` events have been processed and control flow is about to
|
|
|
|
|
/// be taken away from the program. If there are no `RedrawRequested` events, it is emitted
|
|
|
|
|
/// immediately after `MainEventsCleared`.
|
2019-07-31 16:31:12 +10:00
|
|
|
|
///
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// This event is useful for doing any cleanup or bookkeeping work after all the rendering
|
|
|
|
|
/// tasks have been completed.
|
2019-07-31 16:31:12 +10:00
|
|
|
|
RedrawEventsCleared,
|
2019-02-06 02:30:33 +11:00
|
|
|
|
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// Emitted when the event loop is being shut down.
|
|
|
|
|
///
|
2021-06-13 22:26:20 +10:00
|
|
|
|
/// This is irreversible - if this event is emitted, it is guaranteed to be the last event that
|
2020-01-06 03:02:41 +11:00
|
|
|
|
/// gets emitted. You generally want to treat this as an "do on quit" event.
|
2019-02-06 02:30:33 +11:00
|
|
|
|
LoopDestroyed,
|
2017-01-29 01:00:17 +11:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 04:58:12 +10:00
|
|
|
|
impl<T: Clone> Clone for Event<'static, T> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
use self::Event::*;
|
|
|
|
|
match self {
|
|
|
|
|
WindowEvent { window_id, event } => WindowEvent {
|
|
|
|
|
window_id: *window_id,
|
|
|
|
|
event: event.clone(),
|
|
|
|
|
},
|
|
|
|
|
UserEvent(event) => UserEvent(event.clone()),
|
|
|
|
|
DeviceEvent { device_id, event } => DeviceEvent {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
event: event.clone(),
|
|
|
|
|
},
|
2021-08-31 03:40:02 +10:00
|
|
|
|
NewEvents(cause) => NewEvents(*cause),
|
2020-05-16 04:58:12 +10:00
|
|
|
|
MainEventsCleared => MainEventsCleared,
|
|
|
|
|
RedrawRequested(wid) => RedrawRequested(*wid),
|
|
|
|
|
RedrawEventsCleared => RedrawEventsCleared,
|
|
|
|
|
LoopDestroyed => LoopDestroyed,
|
|
|
|
|
Suspended => Suspended,
|
|
|
|
|
Resumed => Resumed,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 06:49:43 +10:00
|
|
|
|
impl<'a, T> Event<'a, T> {
|
|
|
|
|
pub fn map_nonuser_event<U>(self) -> Result<Event<'a, U>, Event<'a, T>> {
|
2019-02-06 02:30:33 +11:00
|
|
|
|
use self::Event::*;
|
|
|
|
|
match self {
|
|
|
|
|
UserEvent(_) => Err(self),
|
2019-06-22 01:33:15 +10:00
|
|
|
|
WindowEvent { window_id, event } => Ok(WindowEvent { window_id, event }),
|
|
|
|
|
DeviceEvent { device_id, event } => Ok(DeviceEvent { device_id, event }),
|
2019-02-06 02:30:33 +11:00
|
|
|
|
NewEvents(cause) => Ok(NewEvents(cause)),
|
2019-07-31 16:31:12 +10:00
|
|
|
|
MainEventsCleared => Ok(MainEventsCleared),
|
|
|
|
|
RedrawRequested(wid) => Ok(RedrawRequested(wid)),
|
|
|
|
|
RedrawEventsCleared => Ok(RedrawEventsCleared),
|
2019-02-06 02:30:33 +11:00
|
|
|
|
LoopDestroyed => Ok(LoopDestroyed),
|
2019-06-22 12:59:31 +10:00
|
|
|
|
Suspended => Ok(Suspended),
|
|
|
|
|
Resumed => Ok(Resumed),
|
2019-02-06 02:30:33 +11:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-20 06:49:43 +10:00
|
|
|
|
|
|
|
|
|
/// If the event doesn't contain a reference, turn it into an event with a `'static` lifetime.
|
|
|
|
|
/// Otherwise, return `None`.
|
|
|
|
|
pub fn to_static(self) -> Option<Event<'static, T>> {
|
|
|
|
|
use self::Event::*;
|
|
|
|
|
match self {
|
|
|
|
|
WindowEvent { window_id, event } => event
|
|
|
|
|
.to_static()
|
|
|
|
|
.map(|event| WindowEvent { window_id, event }),
|
2020-02-17 04:53:02 +11:00
|
|
|
|
UserEvent(event) => Some(UserEvent(event)),
|
2019-06-20 06:49:43 +10:00
|
|
|
|
DeviceEvent { device_id, event } => Some(DeviceEvent { device_id, event }),
|
|
|
|
|
NewEvents(cause) => Some(NewEvents(cause)),
|
|
|
|
|
MainEventsCleared => Some(MainEventsCleared),
|
|
|
|
|
RedrawRequested(wid) => Some(RedrawRequested(wid)),
|
|
|
|
|
RedrawEventsCleared => Some(RedrawEventsCleared),
|
|
|
|
|
LoopDestroyed => Some(LoopDestroyed),
|
|
|
|
|
Suspended => Some(Suspended),
|
|
|
|
|
Resumed => Some(Resumed),
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-06 02:30:33 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Describes the reason the event loop is resuming.
|
2019-06-17 14:30:05 +10:00
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
2019-02-06 02:30:33 +11:00
|
|
|
|
pub enum StartCause {
|
|
|
|
|
/// Sent if the time specified by `ControlFlow::WaitUntil` has been reached. Contains the
|
|
|
|
|
/// moment the timeout was requested and the requested resume time. The actual resume time is
|
|
|
|
|
/// guaranteed to be equal to or after the requested resume time.
|
|
|
|
|
ResumeTimeReached {
|
|
|
|
|
start: Instant,
|
2019-06-22 01:33:15 +10:00
|
|
|
|
requested_resume: Instant,
|
2019-02-06 02:30:33 +11:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Sent if the OS has new events to send to the window, after a wait was requested. Contains
|
|
|
|
|
/// the moment the wait was requested and the resume time, if requested.
|
|
|
|
|
WaitCancelled {
|
|
|
|
|
start: Instant,
|
2019-06-22 01:33:15 +10:00
|
|
|
|
requested_resume: Option<Instant>,
|
2019-02-06 02:30:33 +11:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Sent if the event loop is being resumed after the loop's control flow was set to
|
|
|
|
|
/// `ControlFlow::Poll`.
|
|
|
|
|
Poll,
|
|
|
|
|
|
|
|
|
|
/// Sent once, immediately after `run` is called. Indicates that the loop was just initialized.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
Init,
|
2019-02-06 02:30:33 +11:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes an event from a `Window`.
|
2019-06-20 06:49:43 +10:00
|
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
|
pub enum WindowEvent<'a> {
|
Windows: Position fixes (#479)
* Remove executable flag from os/macos.rs
This was causing me some grief while working on Windows, and it
doesn't belong here to begin with.
* Windows: get_position returns screen coordinates instead of workspace coordinates
Previously, get_position used GetWindowPlacement. As per the
documentation of WINDOWSTRUCT, the returned coordinates are in
workspace space, meaning they're relative to the taskbar. It's
also explicitly remarked that these coordinates should only be
used in conjunction with SetWindowPlacement, as mixing them with
functions expecting screen coordinates can cause unpleasantness.
Since our set_position (correctly) uses SetWindowPos, this meant
that passing the return of get_position to set_position would
cause the window to move.
We now use GetWindowRect, which returns screen coordinates. This
gives us both better consistency within the Windows backend and
across platforms.
Note that this only makes a difference if the taskbar is visible.
With the taskbar hidden, the values are exactly the same as before.
* Windows: Moved event position values are consistent with get_position
The old Moved values had two problems:
* They were obtained by casting a WORD (u16) straight to an i32.
This meant wrap-around would never be interpreted as negative,
thus negative positions (which are ubiquitous when using multiple
monitors) would result in positions around u16::MAX.
* WM_MOVE supplies client area positions, not window positions.
Switching to handling WM_WINDOWPOSCHANGED solves both of these
problems.
* Better documentation for Moved and Resized
2018-04-27 10:09:33 +10:00
|
|
|
|
/// The size of the window has changed. Contains the client area's new dimensions.
|
2020-01-04 17:33:07 +11:00
|
|
|
|
Resized(PhysicalSize<u32>),
|
2014-07-27 20:59:45 +10:00
|
|
|
|
|
Windows: Position fixes (#479)
* Remove executable flag from os/macos.rs
This was causing me some grief while working on Windows, and it
doesn't belong here to begin with.
* Windows: get_position returns screen coordinates instead of workspace coordinates
Previously, get_position used GetWindowPlacement. As per the
documentation of WINDOWSTRUCT, the returned coordinates are in
workspace space, meaning they're relative to the taskbar. It's
also explicitly remarked that these coordinates should only be
used in conjunction with SetWindowPlacement, as mixing them with
functions expecting screen coordinates can cause unpleasantness.
Since our set_position (correctly) uses SetWindowPos, this meant
that passing the return of get_position to set_position would
cause the window to move.
We now use GetWindowRect, which returns screen coordinates. This
gives us both better consistency within the Windows backend and
across platforms.
Note that this only makes a difference if the taskbar is visible.
With the taskbar hidden, the values are exactly the same as before.
* Windows: Moved event position values are consistent with get_position
The old Moved values had two problems:
* They were obtained by casting a WORD (u16) straight to an i32.
This meant wrap-around would never be interpreted as negative,
thus negative positions (which are ubiquitous when using multiple
monitors) would result in positions around u16::MAX.
* WM_MOVE supplies client area positions, not window positions.
Switching to handling WM_WINDOWPOSCHANGED solves both of these
problems.
* Better documentation for Moved and Resized
2018-04-27 10:09:33 +10:00
|
|
|
|
/// The position of the window has changed. Contains the window's new position.
|
2020-03-08 16:21:04 +11:00
|
|
|
|
Moved(PhysicalPosition<i32>),
|
2014-07-28 04:08:31 +10:00
|
|
|
|
|
2018-04-25 06:20:40 +10:00
|
|
|
|
/// The window has been requested to close.
|
|
|
|
|
CloseRequested,
|
|
|
|
|
|
|
|
|
|
/// The window has been destroyed.
|
|
|
|
|
Destroyed,
|
2014-07-27 20:59:45 +10:00
|
|
|
|
|
2017-07-27 12:56:34 +10:00
|
|
|
|
/// A file has been dropped into the window.
|
2019-02-06 02:30:33 +11:00
|
|
|
|
///
|
2018-11-20 19:28:26 +11:00
|
|
|
|
/// When the user drops multiple files at once, this event will be emitted for each file
|
|
|
|
|
/// separately.
|
2017-07-27 12:56:34 +10:00
|
|
|
|
DroppedFile(PathBuf),
|
|
|
|
|
|
2017-07-27 12:51:00 +10:00
|
|
|
|
/// A file is being hovered over the window.
|
2019-02-06 02:30:33 +11:00
|
|
|
|
///
|
2018-11-20 19:28:26 +11:00
|
|
|
|
/// When the user hovers multiple files at once, this event will be emitted for each file
|
|
|
|
|
/// separately.
|
2017-07-27 12:51:00 +10:00
|
|
|
|
HoveredFile(PathBuf),
|
|
|
|
|
|
2017-07-27 12:56:34 +10:00
|
|
|
|
/// A file was hovered, but has exited the window.
|
2019-02-06 02:30:33 +11:00
|
|
|
|
///
|
2018-11-20 19:28:26 +11:00
|
|
|
|
/// There will be a single `HoveredFileCancelled` event triggered even if multiple files were
|
|
|
|
|
/// hovered.
|
2017-07-27 12:56:34 +10:00
|
|
|
|
HoveredFileCancelled,
|
2015-06-24 08:05:37 +10:00
|
|
|
|
|
2014-07-28 01:06:03 +10:00
|
|
|
|
/// The window received a unicode character.
|
|
|
|
|
ReceivedCharacter(char),
|
|
|
|
|
|
2014-07-27 20:59:45 +10:00
|
|
|
|
/// The window gained or lost focus.
|
2014-10-11 21:04:48 +11:00
|
|
|
|
///
|
2014-07-27 20:59:45 +10:00
|
|
|
|
/// The parameter is true if the window has gained focus, and false if it has lost focus.
|
|
|
|
|
Focused(bool),
|
|
|
|
|
|
2014-08-14 01:04:57 +10:00
|
|
|
|
/// An event from the keyboard has been received.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
KeyboardInput {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
input: KeyboardInput,
|
2019-12-08 09:51:37 +11:00
|
|
|
|
/// If `true`, the event was generated synthetically by winit
|
|
|
|
|
/// in one of the following circumstances:
|
|
|
|
|
///
|
2019-12-28 08:26:23 +11:00
|
|
|
|
/// * Synthetic key press events are generated for all keys pressed
|
2019-12-08 09:51:37 +11:00
|
|
|
|
/// when a window gains focus. Likewise, synthetic key release events
|
|
|
|
|
/// are generated for all keys pressed when a window goes out of focus.
|
2019-12-28 08:26:23 +11:00
|
|
|
|
/// ***Currently, this is only functional on X11 and Windows***
|
2019-12-08 09:51:37 +11:00
|
|
|
|
///
|
|
|
|
|
/// Otherwise, this value is always `false`.
|
|
|
|
|
is_synthetic: bool,
|
2019-06-22 01:33:15 +10:00
|
|
|
|
},
|
2014-08-14 01:04:57 +10:00
|
|
|
|
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
/// The keyboard modifiers have changed.
|
|
|
|
|
///
|
|
|
|
|
/// Platform-specific behavior:
|
|
|
|
|
/// - **Web**: This API is currently unimplemented on the web. This isn't by design - it's an
|
|
|
|
|
/// issue, and it should get fixed - but it's the current state of the API.
|
|
|
|
|
ModifiersChanged(ModifiersState),
|
|
|
|
|
|
2014-08-14 01:04:57 +10:00
|
|
|
|
/// The cursor has moved on the window.
|
2017-11-13 07:56:57 +11:00
|
|
|
|
CursorMoved {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
|
|
|
|
|
/// (x,y) coords in pixels relative to the top-left corner of the window. Because the range of this data is
|
|
|
|
|
/// limited by the display area and it may have been transformed by the OS to implement effects such as cursor
|
|
|
|
|
/// acceleration, it should not be used to implement non-cursor-like interactions such as 3D camera control.
|
2020-01-10 15:19:50 +11:00
|
|
|
|
position: PhysicalPosition<f64>,
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
2019-06-22 01:33:15 +10:00
|
|
|
|
modifiers: ModifiersState,
|
2017-11-13 07:56:57 +11:00
|
|
|
|
},
|
2014-08-14 01:04:57 +10:00
|
|
|
|
|
2016-11-03 19:31:16 +11:00
|
|
|
|
/// The cursor has entered the window.
|
2017-11-13 07:56:57 +11:00
|
|
|
|
CursorEntered { device_id: DeviceId },
|
2016-11-03 19:31:16 +11:00
|
|
|
|
|
|
|
|
|
/// The cursor has left the window.
|
2017-11-13 07:56:57 +11:00
|
|
|
|
CursorLeft { device_id: DeviceId },
|
2016-11-03 19:31:16 +11:00
|
|
|
|
|
2015-06-16 08:54:43 +10:00
|
|
|
|
/// A mouse wheel movement or touchpad scroll occurred.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
MouseWheel {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
delta: MouseScrollDelta,
|
|
|
|
|
phase: TouchPhase,
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
2019-06-22 01:33:15 +10:00
|
|
|
|
modifiers: ModifiersState,
|
|
|
|
|
},
|
2014-08-14 01:04:57 +10:00
|
|
|
|
|
2017-04-23 06:52:35 +10:00
|
|
|
|
/// An mouse button press has been received.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
MouseInput {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
state: ElementState,
|
|
|
|
|
button: MouseButton,
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
2019-06-22 01:33:15 +10:00
|
|
|
|
modifiers: ModifiersState,
|
|
|
|
|
},
|
2014-12-17 15:49:11 +11:00
|
|
|
|
|
2016-02-19 14:51:02 +11:00
|
|
|
|
/// Touchpad pressure event.
|
|
|
|
|
///
|
|
|
|
|
/// At the moment, only supported on Apple forcetouch-capable macbooks.
|
|
|
|
|
/// The parameters are: pressure level (value between 0 and 1 representing how hard the touchpad
|
|
|
|
|
/// is being pressed) and stage (integer representing the click level).
|
2019-06-22 01:33:15 +10:00
|
|
|
|
TouchpadPressure {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
pressure: f32,
|
|
|
|
|
stage: i64,
|
|
|
|
|
},
|
2017-04-23 06:52:35 +10:00
|
|
|
|
|
2017-11-13 07:56:57 +11:00
|
|
|
|
/// Motion on some analog axis. May report data redundant to other, more specific events.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
AxisMotion {
|
|
|
|
|
device_id: DeviceId,
|
|
|
|
|
axis: AxisId,
|
|
|
|
|
value: f64,
|
|
|
|
|
},
|
2016-02-19 14:51:02 +11:00
|
|
|
|
|
2015-06-05 23:38:21 +10:00
|
|
|
|
/// Touch event has been received
|
2017-09-16 00:24:09 +10:00
|
|
|
|
Touch(Touch),
|
2017-10-17 22:56:38 +11:00
|
|
|
|
|
2020-01-04 06:52:27 +11:00
|
|
|
|
/// The window's scale factor has changed.
|
2018-06-15 09:42:18 +10:00
|
|
|
|
///
|
|
|
|
|
/// The following user actions can cause DPI changes:
|
2017-10-17 22:56:38 +11:00
|
|
|
|
///
|
2018-06-15 09:42:18 +10:00
|
|
|
|
/// * Changing the display's resolution.
|
2020-01-04 06:52:27 +11:00
|
|
|
|
/// * Changing the display's scale factor (e.g. in Control Panel on Windows).
|
|
|
|
|
/// * Moving the window to a display with a different scale factor.
|
2017-10-17 22:56:38 +11:00
|
|
|
|
///
|
2019-06-20 06:49:43 +10:00
|
|
|
|
/// After this event callback has been processed, the window will be resized to whatever value
|
|
|
|
|
/// is pointed to by the `new_inner_size` reference. By default, this will contain the size suggested
|
2020-01-03 16:28:41 +11:00
|
|
|
|
/// by the OS, but it can be changed to any value.
|
2019-06-20 06:49:43 +10:00
|
|
|
|
///
|
2020-01-05 11:19:17 +11:00
|
|
|
|
/// For more information about DPI in general, see the [`dpi`](crate::dpi) module.
|
2020-01-06 08:57:32 +11:00
|
|
|
|
ScaleFactorChanged {
|
2020-01-04 06:52:27 +11:00
|
|
|
|
scale_factor: f64,
|
2020-01-03 16:28:41 +11:00
|
|
|
|
new_inner_size: &'a mut PhysicalSize<u32>,
|
2019-06-20 06:49:43 +10:00
|
|
|
|
},
|
2019-12-23 06:04:09 +11:00
|
|
|
|
|
|
|
|
|
/// The system window theme has changed.
|
|
|
|
|
///
|
|
|
|
|
/// Applications might wish to react to this to change the theme of the content of the window
|
|
|
|
|
/// when the system changes the window theme.
|
|
|
|
|
///
|
|
|
|
|
/// At the moment this is only supported on Windows.
|
|
|
|
|
ThemeChanged(Theme),
|
2015-06-05 23:38:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-16 04:58:12 +10:00
|
|
|
|
impl Clone for WindowEvent<'static> {
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
use self::WindowEvent::*;
|
|
|
|
|
return match self {
|
2021-08-31 03:40:02 +10:00
|
|
|
|
Resized(size) => Resized(*size),
|
|
|
|
|
Moved(pos) => Moved(*pos),
|
2020-05-16 04:58:12 +10:00
|
|
|
|
CloseRequested => CloseRequested,
|
|
|
|
|
Destroyed => Destroyed,
|
|
|
|
|
DroppedFile(file) => DroppedFile(file.clone()),
|
|
|
|
|
HoveredFile(file) => HoveredFile(file.clone()),
|
|
|
|
|
HoveredFileCancelled => HoveredFileCancelled,
|
|
|
|
|
ReceivedCharacter(c) => ReceivedCharacter(*c),
|
|
|
|
|
Focused(f) => Focused(*f),
|
|
|
|
|
KeyboardInput {
|
|
|
|
|
device_id,
|
|
|
|
|
input,
|
|
|
|
|
is_synthetic,
|
|
|
|
|
} => KeyboardInput {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
input: *input,
|
|
|
|
|
is_synthetic: *is_synthetic,
|
|
|
|
|
},
|
|
|
|
|
|
2021-08-31 03:40:02 +10:00
|
|
|
|
ModifiersChanged(modifiers) => ModifiersChanged(*modifiers),
|
2020-05-16 04:58:12 +10:00
|
|
|
|
#[allow(deprecated)]
|
|
|
|
|
CursorMoved {
|
|
|
|
|
device_id,
|
|
|
|
|
position,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => CursorMoved {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
position: *position,
|
|
|
|
|
modifiers: *modifiers,
|
|
|
|
|
},
|
|
|
|
|
CursorEntered { device_id } => CursorEntered {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
},
|
|
|
|
|
CursorLeft { device_id } => CursorLeft {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
},
|
|
|
|
|
#[allow(deprecated)]
|
|
|
|
|
MouseWheel {
|
|
|
|
|
device_id,
|
|
|
|
|
delta,
|
|
|
|
|
phase,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => MouseWheel {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
delta: *delta,
|
|
|
|
|
phase: *phase,
|
|
|
|
|
modifiers: *modifiers,
|
|
|
|
|
},
|
|
|
|
|
#[allow(deprecated)]
|
|
|
|
|
MouseInput {
|
|
|
|
|
device_id,
|
|
|
|
|
state,
|
|
|
|
|
button,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => MouseInput {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
state: *state,
|
|
|
|
|
button: *button,
|
|
|
|
|
modifiers: *modifiers,
|
|
|
|
|
},
|
|
|
|
|
TouchpadPressure {
|
|
|
|
|
device_id,
|
|
|
|
|
pressure,
|
|
|
|
|
stage,
|
|
|
|
|
} => TouchpadPressure {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
pressure: *pressure,
|
|
|
|
|
stage: *stage,
|
|
|
|
|
},
|
|
|
|
|
AxisMotion {
|
|
|
|
|
device_id,
|
|
|
|
|
axis,
|
|
|
|
|
value,
|
|
|
|
|
} => AxisMotion {
|
|
|
|
|
device_id: *device_id,
|
|
|
|
|
axis: *axis,
|
|
|
|
|
value: *value,
|
|
|
|
|
},
|
|
|
|
|
Touch(touch) => Touch(*touch),
|
2021-08-31 03:40:02 +10:00
|
|
|
|
ThemeChanged(theme) => ThemeChanged(*theme),
|
2020-05-16 04:58:12 +10:00
|
|
|
|
ScaleFactorChanged { .. } => {
|
|
|
|
|
unreachable!("Static event can't be about scale factor changing")
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-20 06:49:43 +10:00
|
|
|
|
impl<'a> WindowEvent<'a> {
|
|
|
|
|
pub fn to_static(self) -> Option<WindowEvent<'static>> {
|
|
|
|
|
use self::WindowEvent::*;
|
|
|
|
|
match self {
|
|
|
|
|
Resized(size) => Some(Resized(size)),
|
|
|
|
|
Moved(position) => Some(Moved(position)),
|
|
|
|
|
CloseRequested => Some(CloseRequested),
|
|
|
|
|
Destroyed => Some(Destroyed),
|
|
|
|
|
DroppedFile(file) => Some(DroppedFile(file)),
|
|
|
|
|
HoveredFile(file) => Some(HoveredFile(file)),
|
|
|
|
|
HoveredFileCancelled => Some(HoveredFileCancelled),
|
|
|
|
|
ReceivedCharacter(c) => Some(ReceivedCharacter(c)),
|
|
|
|
|
Focused(focused) => Some(Focused(focused)),
|
2020-01-04 17:29:40 +11:00
|
|
|
|
KeyboardInput {
|
|
|
|
|
device_id,
|
|
|
|
|
input,
|
|
|
|
|
is_synthetic,
|
|
|
|
|
} => Some(KeyboardInput {
|
|
|
|
|
device_id,
|
|
|
|
|
input,
|
|
|
|
|
is_synthetic,
|
|
|
|
|
}),
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
ModifiersChanged(modifiers) => Some(ModifiersChanged(modifiers)),
|
2020-01-05 04:58:39 +11:00
|
|
|
|
#[allow(deprecated)]
|
2019-06-20 06:49:43 +10:00
|
|
|
|
CursorMoved {
|
|
|
|
|
device_id,
|
|
|
|
|
position,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => Some(CursorMoved {
|
|
|
|
|
device_id,
|
|
|
|
|
position,
|
|
|
|
|
modifiers,
|
|
|
|
|
}),
|
|
|
|
|
CursorEntered { device_id } => Some(CursorEntered { device_id }),
|
|
|
|
|
CursorLeft { device_id } => Some(CursorLeft { device_id }),
|
2020-01-05 04:58:39 +11:00
|
|
|
|
#[allow(deprecated)]
|
2019-06-20 06:49:43 +10:00
|
|
|
|
MouseWheel {
|
|
|
|
|
device_id,
|
|
|
|
|
delta,
|
|
|
|
|
phase,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => Some(MouseWheel {
|
|
|
|
|
device_id,
|
|
|
|
|
delta,
|
|
|
|
|
phase,
|
|
|
|
|
modifiers,
|
|
|
|
|
}),
|
2020-01-05 04:58:39 +11:00
|
|
|
|
#[allow(deprecated)]
|
2019-06-20 06:49:43 +10:00
|
|
|
|
MouseInput {
|
|
|
|
|
device_id,
|
|
|
|
|
state,
|
|
|
|
|
button,
|
|
|
|
|
modifiers,
|
|
|
|
|
} => Some(MouseInput {
|
|
|
|
|
device_id,
|
|
|
|
|
state,
|
|
|
|
|
button,
|
|
|
|
|
modifiers,
|
|
|
|
|
}),
|
|
|
|
|
TouchpadPressure {
|
|
|
|
|
device_id,
|
|
|
|
|
pressure,
|
|
|
|
|
stage,
|
|
|
|
|
} => Some(TouchpadPressure {
|
|
|
|
|
device_id,
|
|
|
|
|
pressure,
|
|
|
|
|
stage,
|
|
|
|
|
}),
|
|
|
|
|
AxisMotion {
|
|
|
|
|
device_id,
|
|
|
|
|
axis,
|
|
|
|
|
value,
|
|
|
|
|
} => Some(AxisMotion {
|
|
|
|
|
device_id,
|
|
|
|
|
axis,
|
|
|
|
|
value,
|
|
|
|
|
}),
|
|
|
|
|
Touch(touch) => Some(Touch(touch)),
|
|
|
|
|
ThemeChanged(theme) => Some(ThemeChanged(theme)),
|
2020-01-06 08:57:32 +11:00
|
|
|
|
ScaleFactorChanged { .. } => None,
|
2019-06-20 06:49:43 +10:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
|
/// Identifier of an input device.
|
|
|
|
|
///
|
|
|
|
|
/// Whenever you receive an event arising from a particular input device, this event contains a `DeviceId` which
|
|
|
|
|
/// identifies its origin. Note that devices may be virtual (representing an on-screen cursor and keyboard focus) or
|
|
|
|
|
/// physical. Virtual devices typically aggregate inputs from multiple physical devices.
|
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
|
|
|
pub struct DeviceId(pub(crate) platform_impl::DeviceId);
|
|
|
|
|
|
|
|
|
|
impl DeviceId {
|
2021-08-31 03:40:02 +10:00
|
|
|
|
/// Returns a dummy `DeviceId`, useful for unit testing.
|
|
|
|
|
///
|
|
|
|
|
/// # Safety
|
|
|
|
|
///
|
|
|
|
|
/// The only guarantee made about the return value of this function is that
|
|
|
|
|
/// it will always be equal to itself and to future values returned by this function.
|
|
|
|
|
/// No other guarantees are made. This may be equal to a real `DeviceId`.
|
2019-02-06 02:30:33 +11:00
|
|
|
|
///
|
|
|
|
|
/// **Passing this into a winit function will result in undefined behavior.**
|
2021-08-31 03:40:02 +10:00
|
|
|
|
pub const unsafe fn dummy() -> Self {
|
2019-02-06 02:30:33 +11:00
|
|
|
|
DeviceId(platform_impl::DeviceId::dummy())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 06:52:35 +10:00
|
|
|
|
/// Represents raw hardware events that are not associated with any particular window.
|
|
|
|
|
///
|
|
|
|
|
/// Useful for interactions that diverge significantly from a conventional 2D GUI, such as 3D camera or first-person
|
|
|
|
|
/// game controls. Many physical actions, such as mouse movement, can produce both device and window events. Because
|
|
|
|
|
/// window events typically arise from virtual devices (corresponding to GUI cursors and keyboard focus) the device IDs
|
|
|
|
|
/// may not match.
|
|
|
|
|
///
|
|
|
|
|
/// Note that these events are delivered regardless of input focus.
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[derive(Clone, Debug, PartialEq)]
|
2017-04-23 06:52:35 +10:00
|
|
|
|
pub enum DeviceEvent {
|
|
|
|
|
Added,
|
|
|
|
|
Removed,
|
2017-11-13 07:56:57 +11:00
|
|
|
|
|
|
|
|
|
/// Change in physical position of a pointing device.
|
|
|
|
|
///
|
|
|
|
|
/// This represents raw, unfiltered physical motion. Not to be confused with `WindowEvent::CursorMoved`.
|
|
|
|
|
MouseMotion {
|
|
|
|
|
/// (x, y) change in position in unspecified units.
|
|
|
|
|
///
|
|
|
|
|
/// Different devices may use different units.
|
|
|
|
|
delta: (f64, f64),
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Physical scroll event
|
|
|
|
|
MouseWheel {
|
|
|
|
|
delta: MouseScrollDelta,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// Motion on some analog axis. This event will be reported for all arbitrary input devices
|
|
|
|
|
/// that winit supports on this platform, including mouse devices. If the device is a mouse
|
|
|
|
|
/// device then this will be reported alongside the MouseMotion event.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
Motion {
|
|
|
|
|
axis: AxisId,
|
|
|
|
|
value: f64,
|
|
|
|
|
},
|
2017-11-13 07:56:57 +11:00
|
|
|
|
|
2019-06-22 01:33:15 +10:00
|
|
|
|
Button {
|
|
|
|
|
button: ButtonId,
|
|
|
|
|
state: ElementState,
|
|
|
|
|
},
|
2019-11-10 18:16:44 +11:00
|
|
|
|
|
2017-04-23 06:52:35 +10:00
|
|
|
|
Key(KeyboardInput),
|
2019-11-10 18:16:44 +11:00
|
|
|
|
|
2019-06-22 01:33:15 +10:00
|
|
|
|
Text {
|
|
|
|
|
codepoint: char,
|
|
|
|
|
},
|
2017-04-23 06:52:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes a keyboard input event.
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2017-04-23 06:52:35 +10:00
|
|
|
|
pub struct KeyboardInput {
|
|
|
|
|
/// Identifies the physical key pressed
|
|
|
|
|
///
|
|
|
|
|
/// This should not change if the user adjusts the host's keyboard map. Use when the physical location of the
|
|
|
|
|
/// key is more important than the key's host GUI semantics, such as for movement controls in a first-person
|
|
|
|
|
/// game.
|
|
|
|
|
pub scancode: ScanCode,
|
|
|
|
|
|
|
|
|
|
pub state: ElementState,
|
|
|
|
|
|
|
|
|
|
/// Identifies the semantic meaning of the key
|
|
|
|
|
///
|
|
|
|
|
/// Use when the semantics of the key are more important than the physical location of the key, such as when
|
|
|
|
|
/// implementing appropriate behavior for "page up."
|
|
|
|
|
pub virtual_keycode: Option<VirtualKeyCode>,
|
|
|
|
|
|
|
|
|
|
/// Modifier keys active at the time of this input.
|
|
|
|
|
///
|
|
|
|
|
/// This is tracked internally to avoid tracking errors arising from modifier key state changes when events from
|
|
|
|
|
/// this device are not being delivered to the application, e.g. due to keyboard focus being elsewhere.
|
Move `ModifiersChanged` variant to `WindowEvent` (#1381)
* Move `ModifiersChanged` variant to `WindowEvent`
* macos: Fix flags_changed for ModifiersChanged variant move
I haven't look too deep at what this does internally, but at least
cargo-check is fully happy now. :)
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Fire a ModifiersChanged event on window_did_resign_key
From debugging, I determined that macOS' emission of a flagsChanged
around window switching is inconsistent. It is fair to assume, I think,
that when the user switches windows, they do not expect their former
modifiers state to remain effective; so I think it's best to clear that
state by sending a ModifiersChanged(ModifiersState::empty()).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Fix build
I don't know enough about the code to implement the fix as it is done on
this branch, but this commit at least fixes the build.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* windows: Send ModifiersChanged(ModifiersState::empty) on KILLFOCUS
Very similar to the changes made in [1], as focus is lost, send an event
to the window indicating that the modifiers have been released.
It's unclear to me (without a Windows device to test this on) whether
this is necessary, but it certainly ensures that unfocused windows will
have at least received this event, which is an improvement.
[1]: f79f21641a31da3e4039d41be89047cdcc6028f7
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* macos: Add a hook to update stale modifiers
Sometimes, `ViewState` and `event` might have different values for their
stored `modifiers` flags. These are internally stored as a bitmask in
the latter and an enum in the former.
We can check to see if they differ, and if they do, automatically
dispatch an event to update consumers of modifier state as well as the
stored `state.modifiers`. That's what the hook does.
This hook is then called in the key_down, mouse_entered, mouse_exited,
mouse_click, scroll_wheel, and pressure_change_with_event callbacks,
which each will contain updated modifiers.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Only call event_mods once when determining whether to update state
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* flags_changed: Memoize window_id collection
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_did_resign_key: Remove synthetic ModifiersChanged event
We no longer need to emit this event, since we are checking the state of
our modifiers before emitting most other events.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Add a call to update_potentially_stale_modifiers
Now, cover all events (that I can think of, at least) where stale
modifiers might affect how user programs behave. Effectively, every
human-interface event (keypress, mouse click, keydown, etc.) will cause
a ModifiersChanged event to be fired if something has changed.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* key_up: Add a call to update_potentially_stale_modifiers
We also want to make sure modifiers state is synchronized here, too.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* mouse_motion: Remove update_potentially_stale_modifiers invocation
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Retry CI
* ViewState: Promote visibility of modifiers to the macos impl
This is so that we can interact with the ViewState directly from the
WindowDelegate.
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* window_delegate: Synthetically set modifiers state to empty on resignKey
This logic is implemented similarly on other platforms, so we wish to
regain parity here. Originally this behavior was implemented to always
fire an event with ModifiersState::empty(), but that was not the best as
it was not necessarily correct and could be a duplicate event.
This solution is perhaps the most elegant possible to implement the
desired behavior of sending a synthetic empty modifiers event when a
window loses focus, trading some safety for interoperation between the
NSWindowDelegate and the NSView (as the objc runtime must now be
consulted in order to acquire access to the ViewState which is "owned"
by the NSView).
Signed-off-by: Kristofer Rye <kristofer.rye@gmail.com>
* Check for modifiers change in window events
* Fix modifier changed on macOS
Since the `mouse_entered` function was generating a mouse motion, which
updates the modifier state, a modifiers changed event was incorrectly
generated.
The updating of the modifier state has also been changed to make sure it
consistently happens before events that have a modifier state attached
to it, without happening on any other event.
This of course means that no `CursorMoved` event is generated anymore
when the user enters the window without it being focused, however I'd
say that is consistent with how winit should behave.
* Fix unused variable warning
* Move changelog entry into `Unreleased` section
Co-authored-by: Freya Gentz <zegentzy@protonmail.com>
Co-authored-by: Kristofer Rye <kristofer.rye@gmail.com>
Co-authored-by: Christian Duerr <contact@christianduerr.com>
2020-03-07 09:43:55 +11:00
|
|
|
|
#[deprecated = "Deprecated in favor of WindowEvent::ModifiersChanged"]
|
2019-06-22 01:33:15 +10:00
|
|
|
|
pub modifiers: ModifiersState,
|
2017-04-23 06:52:35 +10:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes touch-screen input state.
|
2015-06-05 23:38:21 +10:00
|
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2015-06-05 23:38:21 +10:00
|
|
|
|
pub enum TouchPhase {
|
|
|
|
|
Started,
|
|
|
|
|
Moved,
|
|
|
|
|
Ended,
|
2019-06-22 01:33:15 +10:00
|
|
|
|
Cancelled,
|
2015-06-05 23:38:21 +10:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// Represents a touch event
|
2015-06-05 23:38:21 +10:00
|
|
|
|
///
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// Every time the user touches the screen, a new `Start` event with an unique
|
|
|
|
|
/// identifier for the finger is generated. When the finger is lifted, an `End`
|
|
|
|
|
/// event is generated with the same finger id.
|
2015-06-05 23:38:21 +10:00
|
|
|
|
///
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// After a `Start` event has been emitted, there may be zero or more `Move`
|
|
|
|
|
/// events when the finger is moved or the touch pressure changes.
|
2015-06-05 23:38:21 +10:00
|
|
|
|
///
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// The finger id may be reused by the system after an `End` event. The user
|
|
|
|
|
/// should assume that a new `Start` event received with the same id has nothing
|
|
|
|
|
/// to do with the old finger and is a new finger.
|
2015-06-05 23:38:21 +10:00
|
|
|
|
///
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// A `Cancelled` event is emitted when the system has canceled tracking this
|
|
|
|
|
/// touch, such as when the window loses focus, or on iOS if the user moves the
|
|
|
|
|
/// device against their face.
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2015-06-05 23:38:21 +10:00
|
|
|
|
pub struct Touch {
|
2017-04-23 06:52:35 +10:00
|
|
|
|
pub device_id: DeviceId,
|
2015-06-05 23:38:21 +10:00
|
|
|
|
pub phase: TouchPhase,
|
2020-01-04 17:33:07 +11:00
|
|
|
|
pub location: PhysicalPosition<f64>,
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// Describes how hard the screen was pressed. May be `None` if the platform
|
|
|
|
|
/// does not support pressure sensitivity.
|
|
|
|
|
///
|
|
|
|
|
/// ## Platform-specific
|
|
|
|
|
///
|
2019-09-10 04:15:49 +10:00
|
|
|
|
/// - Only available on **iOS** 9.0+ and **Windows** 8+.
|
2019-08-14 08:12:13 +10:00
|
|
|
|
pub force: Option<Force>,
|
|
|
|
|
/// Unique identifier of a finger.
|
2019-06-22 01:33:15 +10:00
|
|
|
|
pub id: u64,
|
2014-08-14 01:04:57 +10:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-14 08:12:13 +10:00
|
|
|
|
/// Describes the force of a touch event
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
|
|
|
pub enum Force {
|
|
|
|
|
/// On iOS, the force is calibrated so that the same number corresponds to
|
|
|
|
|
/// roughly the same amount of pressure on the screen regardless of the
|
|
|
|
|
/// device.
|
|
|
|
|
Calibrated {
|
|
|
|
|
/// The force of the touch, where a value of 1.0 represents the force of
|
|
|
|
|
/// an average touch (predetermined by the system, not user-specific).
|
|
|
|
|
///
|
|
|
|
|
/// The force reported by Apple Pencil is measured along the axis of the
|
|
|
|
|
/// pencil. If you want a force perpendicular to the device, you need to
|
|
|
|
|
/// calculate this value using the `altitude_angle` value.
|
|
|
|
|
force: f64,
|
|
|
|
|
/// The maximum possible force for a touch.
|
|
|
|
|
///
|
|
|
|
|
/// The value of this field is sufficiently high to provide a wide
|
|
|
|
|
/// dynamic range for values of the `force` field.
|
|
|
|
|
max_possible_force: f64,
|
|
|
|
|
/// The altitude (in radians) of the stylus.
|
|
|
|
|
///
|
|
|
|
|
/// A value of 0 radians indicates that the stylus is parallel to the
|
|
|
|
|
/// surface. The value of this property is Pi/2 when the stylus is
|
|
|
|
|
/// perpendicular to the surface.
|
|
|
|
|
altitude_angle: Option<f64>,
|
|
|
|
|
},
|
|
|
|
|
/// If the platform reports the force as normalized, we have no way of
|
|
|
|
|
/// knowing how much pressure 1.0 corresponds to – we know it's the maximum
|
|
|
|
|
/// amount of force, but as to how much force, you might either have to
|
|
|
|
|
/// press really really hard, or not hard at all, depending on the device.
|
|
|
|
|
Normalized(f64),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Force {
|
|
|
|
|
/// Returns the force normalized to the range between 0.0 and 1.0 inclusive.
|
|
|
|
|
/// Instead of normalizing the force, you should prefer to handle
|
|
|
|
|
/// `Force::Calibrated` so that the amount of force the user has to apply is
|
|
|
|
|
/// consistent across devices.
|
|
|
|
|
pub fn normalized(&self) -> f64 {
|
|
|
|
|
match self {
|
|
|
|
|
Force::Calibrated {
|
|
|
|
|
force,
|
|
|
|
|
max_possible_force,
|
|
|
|
|
altitude_angle,
|
|
|
|
|
} => {
|
|
|
|
|
let force = match altitude_angle {
|
|
|
|
|
Some(altitude_angle) => force / altitude_angle.sin(),
|
|
|
|
|
None => *force,
|
|
|
|
|
};
|
|
|
|
|
force / max_possible_force
|
|
|
|
|
}
|
|
|
|
|
Force::Normalized(force) => *force,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Hardware-dependent keyboard scan code.
|
2017-04-23 06:52:35 +10:00
|
|
|
|
pub type ScanCode = u32;
|
2014-08-14 01:04:57 +10:00
|
|
|
|
|
2017-07-01 19:20:13 +10:00
|
|
|
|
/// Identifier for a specific analog axis on some device.
|
|
|
|
|
pub type AxisId = u32;
|
|
|
|
|
|
|
|
|
|
/// Identifier for a specific button on some device.
|
|
|
|
|
pub type ButtonId = u32;
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes the input state of a key.
|
2015-01-24 12:50:06 +11:00
|
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2014-08-14 01:04:57 +10:00
|
|
|
|
pub enum ElementState {
|
|
|
|
|
Pressed,
|
|
|
|
|
Released,
|
|
|
|
|
}
|
2014-07-28 01:06:03 +10:00
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes a button of a mouse controller.
|
2015-01-24 12:50:06 +11:00
|
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2014-08-14 01:04:57 +10:00
|
|
|
|
pub enum MouseButton {
|
2015-02-06 02:52:53 +11:00
|
|
|
|
Left,
|
|
|
|
|
Right,
|
|
|
|
|
Middle,
|
2020-12-10 07:11:25 +11:00
|
|
|
|
Other(u16),
|
2014-07-28 01:06:03 +10:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Describes a difference in the mouse scroll wheel state.
|
2015-07-16 02:37:15 +10:00
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2015-06-13 00:32:11 +10:00
|
|
|
|
pub enum MouseScrollDelta {
|
2019-06-22 01:33:15 +10:00
|
|
|
|
/// Amount in lines or rows to scroll in the horizontal
|
|
|
|
|
/// and vertical directions.
|
|
|
|
|
///
|
|
|
|
|
/// Positive values indicate movement forward
|
|
|
|
|
/// (away from the user) or rightwards.
|
|
|
|
|
LineDelta(f32, f32),
|
|
|
|
|
/// Amount in pixels to scroll in the horizontal and
|
|
|
|
|
/// vertical direction.
|
|
|
|
|
///
|
|
|
|
|
/// Scroll events are expressed as a PixelDelta if
|
|
|
|
|
/// supported by the device (eg. a touchpad) and
|
|
|
|
|
/// platform.
|
2020-07-27 08:16:21 +10:00
|
|
|
|
PixelDelta(PhysicalPosition<f64>),
|
2015-06-13 00:32:11 +10:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-25 23:58:59 +10:00
|
|
|
|
/// Symbolic name for a keyboard key.
|
2018-11-20 08:59:04 +11:00
|
|
|
|
#[derive(Debug, Hash, Ord, PartialOrd, PartialEq, Eq, Clone, Copy)]
|
2017-04-12 23:49:14 +10:00
|
|
|
|
#[repr(u32)]
|
2018-11-01 19:24:56 +11:00
|
|
|
|
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
2014-08-14 01:04:57 +10:00
|
|
|
|
pub enum VirtualKeyCode {
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '1' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key1,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '2' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key2,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '3' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key3,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '4' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key4,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '5' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key5,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '6' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key6,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '7' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key7,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '8' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key8,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '9' key over the letters.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Key9,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
/// The '0' key over the 'O' and 'P' keys.
|
|
|
|
|
Key0,
|
|
|
|
|
|
2014-07-28 01:06:03 +10:00
|
|
|
|
A,
|
|
|
|
|
B,
|
|
|
|
|
C,
|
|
|
|
|
D,
|
|
|
|
|
E,
|
|
|
|
|
F,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
G,
|
|
|
|
|
H,
|
|
|
|
|
I,
|
|
|
|
|
J,
|
|
|
|
|
K,
|
|
|
|
|
L,
|
|
|
|
|
M,
|
|
|
|
|
N,
|
|
|
|
|
O,
|
|
|
|
|
P,
|
|
|
|
|
Q,
|
|
|
|
|
R,
|
|
|
|
|
S,
|
|
|
|
|
T,
|
|
|
|
|
U,
|
|
|
|
|
V,
|
|
|
|
|
W,
|
|
|
|
|
X,
|
|
|
|
|
Y,
|
|
|
|
|
Z,
|
|
|
|
|
|
|
|
|
|
/// The Escape key, next to F1.
|
|
|
|
|
Escape,
|
|
|
|
|
|
2014-07-28 01:06:03 +10:00
|
|
|
|
F1,
|
|
|
|
|
F2,
|
|
|
|
|
F3,
|
|
|
|
|
F4,
|
|
|
|
|
F5,
|
|
|
|
|
F6,
|
|
|
|
|
F7,
|
|
|
|
|
F8,
|
|
|
|
|
F9,
|
|
|
|
|
F10,
|
|
|
|
|
F11,
|
|
|
|
|
F12,
|
|
|
|
|
F13,
|
|
|
|
|
F14,
|
|
|
|
|
F15,
|
2018-09-13 03:04:16 +10:00
|
|
|
|
F16,
|
|
|
|
|
F17,
|
|
|
|
|
F18,
|
|
|
|
|
F19,
|
|
|
|
|
F20,
|
|
|
|
|
F21,
|
|
|
|
|
F22,
|
|
|
|
|
F23,
|
|
|
|
|
F24,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
|
|
|
|
|
/// Print Screen/SysRq.
|
|
|
|
|
Snapshot,
|
|
|
|
|
/// Scroll Lock.
|
|
|
|
|
Scroll,
|
|
|
|
|
/// Pause/Break key, next to Scroll lock.
|
|
|
|
|
Pause,
|
|
|
|
|
|
|
|
|
|
/// `Insert`, next to Backspace.
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Insert,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
Home,
|
|
|
|
|
Delete,
|
|
|
|
|
End,
|
|
|
|
|
PageDown,
|
|
|
|
|
PageUp,
|
|
|
|
|
|
|
|
|
|
Left,
|
|
|
|
|
Up,
|
|
|
|
|
Right,
|
|
|
|
|
Down,
|
|
|
|
|
|
|
|
|
|
/// The Backspace key, right over Enter.
|
|
|
|
|
// TODO: rename
|
|
|
|
|
Back,
|
|
|
|
|
/// The Enter key.
|
|
|
|
|
Return,
|
|
|
|
|
/// The space bar.
|
|
|
|
|
Space,
|
|
|
|
|
|
2016-07-05 09:20:18 +10:00
|
|
|
|
/// The "Compose" key on Linux.
|
|
|
|
|
Compose,
|
|
|
|
|
|
2018-01-25 23:32:30 +11:00
|
|
|
|
Caret,
|
|
|
|
|
|
2014-11-06 23:26:42 +11:00
|
|
|
|
Numlock,
|
|
|
|
|
Numpad0,
|
|
|
|
|
Numpad1,
|
|
|
|
|
Numpad2,
|
|
|
|
|
Numpad3,
|
|
|
|
|
Numpad4,
|
|
|
|
|
Numpad5,
|
|
|
|
|
Numpad6,
|
|
|
|
|
Numpad7,
|
|
|
|
|
Numpad8,
|
|
|
|
|
Numpad9,
|
2020-09-20 19:58:24 +10:00
|
|
|
|
NumpadAdd,
|
|
|
|
|
NumpadDivide,
|
|
|
|
|
NumpadDecimal,
|
2020-08-29 23:38:41 +10:00
|
|
|
|
NumpadComma,
|
|
|
|
|
NumpadEnter,
|
|
|
|
|
NumpadEquals,
|
2020-09-20 19:58:24 +10:00
|
|
|
|
NumpadMultiply,
|
2020-08-29 23:38:41 +10:00
|
|
|
|
NumpadSubtract,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
|
|
|
|
|
AbntC1,
|
|
|
|
|
AbntC2,
|
|
|
|
|
Apostrophe,
|
|
|
|
|
Apps,
|
2020-09-20 19:58:24 +10:00
|
|
|
|
Asterisk,
|
2014-11-06 23:26:42 +11:00
|
|
|
|
At,
|
|
|
|
|
Ax,
|
|
|
|
|
Backslash,
|
|
|
|
|
Calculator,
|
|
|
|
|
Capital,
|
|
|
|
|
Colon,
|
|
|
|
|
Comma,
|
|
|
|
|
Convert,
|
|
|
|
|
Equals,
|
|
|
|
|
Grave,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Kana,
|
|
|
|
|
Kanji,
|
2014-10-24 03:01:09 +11:00
|
|
|
|
LAlt,
|
2014-10-15 20:49:10 +11:00
|
|
|
|
LBracket,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
LControl,
|
|
|
|
|
LShift,
|
|
|
|
|
LWin,
|
|
|
|
|
Mail,
|
|
|
|
|
MediaSelect,
|
|
|
|
|
MediaStop,
|
|
|
|
|
Minus,
|
|
|
|
|
Mute,
|
|
|
|
|
MyComputer,
|
2020-05-16 04:58:12 +10:00
|
|
|
|
// also called "Next"
|
|
|
|
|
NavigateForward,
|
|
|
|
|
// also called "Prior"
|
|
|
|
|
NavigateBackward,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
NextTrack,
|
|
|
|
|
NoConvert,
|
|
|
|
|
OEM102,
|
|
|
|
|
Period,
|
2015-07-02 17:52:44 +10:00
|
|
|
|
PlayPause,
|
2020-09-20 19:58:24 +10:00
|
|
|
|
Plus,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
Power,
|
2015-07-02 17:52:44 +10:00
|
|
|
|
PrevTrack,
|
2014-10-24 03:01:09 +11:00
|
|
|
|
RAlt,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
RBracket,
|
|
|
|
|
RControl,
|
|
|
|
|
RShift,
|
|
|
|
|
RWin,
|
|
|
|
|
Semicolon,
|
|
|
|
|
Slash,
|
|
|
|
|
Sleep,
|
|
|
|
|
Stop,
|
|
|
|
|
Sysrq,
|
|
|
|
|
Tab,
|
|
|
|
|
Underline,
|
|
|
|
|
Unlabeled,
|
|
|
|
|
VolumeDown,
|
|
|
|
|
VolumeUp,
|
|
|
|
|
Wake,
|
2015-07-02 17:52:44 +10:00
|
|
|
|
WebBack,
|
2014-07-28 01:06:03 +10:00
|
|
|
|
WebFavorites,
|
|
|
|
|
WebForward,
|
|
|
|
|
WebHome,
|
|
|
|
|
WebRefresh,
|
|
|
|
|
WebSearch,
|
|
|
|
|
WebStop,
|
|
|
|
|
Yen,
|
2018-05-03 09:18:52 +10:00
|
|
|
|
Copy,
|
|
|
|
|
Paste,
|
|
|
|
|
Cut,
|
2014-07-27 20:59:45 +10:00
|
|
|
|
}
|
2017-01-18 05:01:10 +11:00
|
|
|
|
|
2019-12-29 07:36:06 +11:00
|
|
|
|
impl ModifiersState {
|
|
|
|
|
/// Returns `true` if the shift key is pressed.
|
|
|
|
|
pub fn shift(&self) -> bool {
|
|
|
|
|
self.intersects(Self::SHIFT)
|
|
|
|
|
}
|
|
|
|
|
/// Returns `true` if the control key is pressed.
|
|
|
|
|
pub fn ctrl(&self) -> bool {
|
|
|
|
|
self.intersects(Self::CTRL)
|
|
|
|
|
}
|
|
|
|
|
/// Returns `true` if the alt key is pressed.
|
|
|
|
|
pub fn alt(&self) -> bool {
|
|
|
|
|
self.intersects(Self::ALT)
|
|
|
|
|
}
|
|
|
|
|
/// Returns `true` if the logo key is pressed.
|
|
|
|
|
pub fn logo(&self) -> bool {
|
|
|
|
|
self.intersects(Self::LOGO)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bitflags! {
|
|
|
|
|
/// Represents the current state of the keyboard modifiers
|
2017-01-18 05:01:10 +11:00
|
|
|
|
///
|
2019-12-29 07:36:06 +11:00
|
|
|
|
/// Each flag represents a modifier and is set if this modifier is active.
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
pub struct ModifiersState: u32 {
|
|
|
|
|
// left and right modifiers are currently commented out, but we should be able to support
|
|
|
|
|
// them in a future release
|
|
|
|
|
/// The "shift" key.
|
2021-08-31 03:40:02 +10:00
|
|
|
|
const SHIFT = 0b100;
|
|
|
|
|
// const LSHIFT = 0b010;
|
|
|
|
|
// const RSHIFT = 0b001;
|
2019-12-29 07:36:06 +11:00
|
|
|
|
/// The "control" key.
|
|
|
|
|
const CTRL = 0b100 << 3;
|
|
|
|
|
// const LCTRL = 0b010 << 3;
|
|
|
|
|
// const RCTRL = 0b001 << 3;
|
|
|
|
|
/// The "alt" key.
|
|
|
|
|
const ALT = 0b100 << 6;
|
|
|
|
|
// const LALT = 0b010 << 6;
|
|
|
|
|
// const RALT = 0b001 << 6;
|
|
|
|
|
/// This is the "windows" key on PC and "command" key on Mac.
|
|
|
|
|
const LOGO = 0b100 << 9;
|
|
|
|
|
// const LLOGO = 0b010 << 9;
|
|
|
|
|
// const RLOGO = 0b001 << 9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "serde")]
|
|
|
|
|
mod modifiers_serde {
|
|
|
|
|
use super::ModifiersState;
|
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
|
|
|
|
|
|
|
|
#[derive(Default, Serialize, Deserialize)]
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
#[serde(rename = "ModifiersState")]
|
|
|
|
|
pub struct ModifiersStateSerialize {
|
|
|
|
|
pub shift: bool,
|
|
|
|
|
pub ctrl: bool,
|
|
|
|
|
pub alt: bool,
|
|
|
|
|
pub logo: bool,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Serialize for ModifiersState {
|
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
|
where
|
|
|
|
|
S: Serializer,
|
|
|
|
|
{
|
|
|
|
|
let s = ModifiersStateSerialize {
|
|
|
|
|
shift: self.shift(),
|
|
|
|
|
ctrl: self.ctrl(),
|
|
|
|
|
alt: self.alt(),
|
|
|
|
|
logo: self.logo(),
|
|
|
|
|
};
|
|
|
|
|
s.serialize(serializer)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'de> Deserialize<'de> for ModifiersState {
|
|
|
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
|
|
|
where
|
|
|
|
|
D: Deserializer<'de>,
|
|
|
|
|
{
|
|
|
|
|
let ModifiersStateSerialize {
|
|
|
|
|
shift,
|
|
|
|
|
ctrl,
|
|
|
|
|
alt,
|
|
|
|
|
logo,
|
|
|
|
|
} = ModifiersStateSerialize::deserialize(deserializer)?;
|
|
|
|
|
let mut m = ModifiersState::empty();
|
|
|
|
|
m.set(ModifiersState::SHIFT, shift);
|
|
|
|
|
m.set(ModifiersState::CTRL, ctrl);
|
|
|
|
|
m.set(ModifiersState::ALT, alt);
|
|
|
|
|
m.set(ModifiersState::LOGO, logo);
|
|
|
|
|
Ok(m)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-18 05:01:10 +11:00
|
|
|
|
}
|