Overhaul the keyboard API in winit to mimic the W3C specification
to achieve better crossplatform parity. The `KeyboardInput` event
is now uses `KeyEvent` which consists of:
- `physical_key` - a cross platform way to refer to scancodes;
- `logical_key` - keysym value, which shows your key respecting the
layout;
- `text` - the text produced by this keypress;
- `location` - the location of the key on the keyboard;
- `repeat` - whether the key was produced by the repeat.
And also a `platform_specific` field which encapsulates extra
information on desktop platforms, like key without modifiers
and text with all modifiers.
The `Modifiers` were also slightly reworked as in, the information
whether the left or right modifier is pressed is now also exposed
on platforms where it could be queried reliably. The support was
also added for the web and orbital platforms finishing the API
change.
This change made the `OptionAsAlt` API on macOS redundant thus it
was removed all together.
Co-authored-by: Artúr Kovács <kovacs.artur.barnabas@gmail.com>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Fixes: #2631.
Fixes: #2055.
Fixes: #2032.
Fixes: #1904.
Fixes: #1810.
Fixes: #1700.
Fixes: #1443.
Fixes: #1343.
Fixes: #1208.
Fixes: #1151.
Fixes: #812.
Fixes: #600.
Fixes: #361.
Fixes: #343.
100 lines
2.4 KiB
Rust
100 lines
2.4 KiB
Rust
#![deny(unsafe_op_in_unsafe_fn)]
|
|
|
|
#[macro_use]
|
|
mod util;
|
|
|
|
mod app;
|
|
mod app_delegate;
|
|
mod app_state;
|
|
mod appkit;
|
|
mod event;
|
|
mod event_loop;
|
|
mod ffi;
|
|
mod menu;
|
|
mod monitor;
|
|
mod observer;
|
|
mod view;
|
|
mod window;
|
|
mod window_delegate;
|
|
|
|
use std::{fmt, ops::Deref};
|
|
|
|
use self::window::WinitWindow;
|
|
use self::window_delegate::WinitWindowDelegate;
|
|
pub(crate) use self::{
|
|
event::KeyEventExtra,
|
|
event_loop::{
|
|
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
|
|
},
|
|
monitor::{MonitorHandle, VideoMode},
|
|
window::{PlatformSpecificWindowBuilderAttributes, WindowId},
|
|
};
|
|
use crate::{
|
|
error::OsError as RootOsError, event::DeviceId as RootDeviceId, window::WindowAttributes,
|
|
};
|
|
use objc2::rc::{autoreleasepool, Id, Shared};
|
|
|
|
pub(crate) use crate::icon::NoIcon as PlatformIcon;
|
|
pub(self) use crate::platform_impl::Fullscreen;
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
pub struct DeviceId;
|
|
|
|
impl DeviceId {
|
|
pub const unsafe fn dummy() -> Self {
|
|
DeviceId
|
|
}
|
|
}
|
|
|
|
// Constant device ID; to be removed when if backend is updated to report real device IDs.
|
|
pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);
|
|
|
|
pub(crate) struct Window {
|
|
pub(crate) window: Id<WinitWindow, Shared>,
|
|
// We keep this around so that it doesn't get dropped until the window does.
|
|
_delegate: Id<WinitWindowDelegate, Shared>,
|
|
}
|
|
|
|
impl Drop for Window {
|
|
fn drop(&mut self) {
|
|
// Ensure the window is closed
|
|
util::close_sync(&self.window);
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum OsError {
|
|
CGError(core_graphics::base::CGError),
|
|
CreationError(&'static str),
|
|
}
|
|
|
|
unsafe impl Send for Window {}
|
|
unsafe impl Sync for Window {}
|
|
|
|
impl Deref for Window {
|
|
type Target = WinitWindow;
|
|
#[inline]
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.window
|
|
}
|
|
}
|
|
|
|
impl Window {
|
|
pub(crate) fn new<T: 'static>(
|
|
_window_target: &EventLoopWindowTarget<T>,
|
|
attributes: WindowAttributes,
|
|
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
|
) -> Result<Self, RootOsError> {
|
|
let (window, _delegate) = autoreleasepool(|_| WinitWindow::new(attributes, pl_attribs))?;
|
|
Ok(Window { window, _delegate })
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for OsError {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
match self {
|
|
OsError::CGError(e) => f.pad(&format!("CGError {e}")),
|
|
OsError::CreationError(e) => f.pad(e),
|
|
}
|
|
}
|
|
}
|