diff --git a/CHANGELOG.md b/CHANGELOG.md index 824a5e7c9..26b5fee45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,14 @@ Unreleased` header. - On Wayland, fix `Window::set_{min,max}_inner_size` not always applied. - On Windows, fix inconsistent resizing behavior with multi-monitor setups when repositioning outside the event loop. - On Wayland, fix `WAYLAND_SOCKET` not used when detecting platform. +- **Breaking:** Move some types to the `winit-core` crate. Most types are + re-exported verbatim; however: + - `Event`, `WindowEvent` and `KeyEvent` now take a generic that `winit` + implements. + - `ActivationToken` and `InnerSizeWriter` expose new methods to make them + useful. + - `InnerSizeWriter::request_inner_size` returns an `InnerSizeIgnored` error + instead of an `ExternalError`. # 0.29.10 diff --git a/Cargo.toml b/Cargo.toml index da7f2b1ee..122c8e244 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,9 @@ resolver = "2" [workspace.dependencies] bitflags = "2" +cfg_aliases = "0.2.0" cursor-icon = "1.1.0" serde = { version = "1", features = ["serde_derive"] } smol_str = "0.2.0" +web-time = "1" winit-core = { path = "./winit-core", default-features = false, features = ["std"] } diff --git a/winit-core/Cargo.toml b/winit-core/Cargo.toml index da345d173..ec6f2864b 100644 --- a/winit-core/Cargo.toml +++ b/winit-core/Cargo.toml @@ -21,9 +21,12 @@ serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde"] [dependencies] bitflags.workspace = true cursor-icon.workspace = true +mint = { version = "0.5.6", optional = true } serde = { workspace = true, optional = true } smol_str.workspace = true -web-time = "1" + +[target.'cfg(target_family = "wasm")'.dependencies] +web-time.workspace = true [build-dependencies] -cfg_aliases = "0.2.0" +cfg_aliases.workspace = true diff --git a/winit-core/src/event.rs b/winit-core/src/event.rs index ba6444002..94f6d6ec8 100644 --- a/winit-core/src/event.rs +++ b/winit-core/src/event.rs @@ -14,6 +14,9 @@ use std::time::Instant; #[cfg(web_platform)] use web_time::Instant; +#[cfg(feature = "serde")] +pub use serde::{Serialize, Deserialize}; + use smol_str::SmolStr; /// Identifier of an input device. @@ -778,6 +781,7 @@ pub struct Modifiers { } impl Modifiers { + /// Only `winit` should instantiate this! #[doc(hidden)] pub fn new(state: ModifiersState, pressed_mods: ModifiersKeys) -> Self { Self { @@ -1120,6 +1124,7 @@ impl InnerSizeWriter { } } + /// Get the underlying size. pub fn get(&self) -> PhysicalSize { *self.new_inner_size.upgrade().unwrap().lock().unwrap() } diff --git a/winit-core/src/window.rs b/winit-core/src/window.rs index 5f5e7627d..f2daf0715 100644 --- a/winit-core/src/window.rs +++ b/winit-core/src/window.rs @@ -3,6 +3,9 @@ #[doc(inline)] pub use cursor_icon::{CursorIcon, ParseError as CursorIconParseError}; +#[cfg(feature = "serde")] +pub use serde::{Serialize, Deserialize}; + /// Identifier of a window. Unique for each window. /// /// Can be obtained with [`window.id()`](`Window::id`). @@ -192,7 +195,7 @@ impl Default for ImePurpose { } } -/// An opaque token used to activate the [`Window`]. +/// An stringly-typed token used to activate the [`Window`]. /// /// [`Window`]: crate::window::Window #[derive(Debug, PartialEq, Eq, Clone)] @@ -201,14 +204,17 @@ pub struct ActivationToken { } impl ActivationToken { - pub fn new(_token: String) -> Self { - Self { token: _token } + /// Create a new [`ActivationToken`]. + pub fn new(token: String) -> Self { + Self { token } } + /// Get the underlying token. pub fn token(&self) -> &str { &self.token } + /// Convert into the underlying token. pub fn into_token(self) -> String { self.token } diff --git a/winit/Cargo.toml b/winit/Cargo.toml index 8db59ef37..2ce501e4b 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -52,19 +52,19 @@ wayland-csd-adwaita-crossfont = ["sctk-adwaita", "sctk-adwaita/crossfont"] wayland-csd-adwaita-notitle = ["sctk-adwaita"] android-native-activity = ["android-activity/native-activity"] android-game-activity = ["android-activity/game-activity"] -serde = ["dep:serde", "cursor-icon/serde", "smol_str/serde"] +mint = ["winit-core/mint"] +serde = ["dep:serde", "winit-core/serde", "cursor-icon/serde", "smol_str/serde"] rwh_04 = ["dep:rwh_04", "ndk/rwh_04"] rwh_05 = ["dep:rwh_05", "ndk/rwh_05"] rwh_06 = ["dep:rwh_06", "ndk/rwh_06"] [build-dependencies] -cfg_aliases = "0.2.0" +cfg_aliases.workspace = true [dependencies] bitflags.workspace = true cursor-icon.workspace = true log = "0.4" -mint = { version = "0.5.6", optional = true } once_cell = "1.12" rwh_04 = { package = "raw-window-handle", version = "0.4", optional = true } rwh_05 = { package = "raw-window-handle", version = "0.5.2", features = ["std"], optional = true } @@ -246,7 +246,7 @@ js-sys = "0.3.64" pin-project = "1" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -web-time = "1" +web-time.workspace = true [target.'cfg(all(target_family = "wasm", target_feature = "atomics"))'.dependencies] atomic-waker = "1" diff --git a/winit/src/error.rs b/winit/src/error.rs index af2b0e616..6a2b8367f 100644 --- a/winit/src/error.rs +++ b/winit/src/error.rs @@ -16,6 +16,12 @@ pub enum ExternalError { Os(OsError), } +impl From for ExternalError { + fn from(_: winit_core::event::InnerSizeIgnored) -> Self { + Self::Ignored + } +} + /// The error type for when the OS cannot perform the requested operation. #[derive(Debug)] pub struct OsError { diff --git a/winit/src/window.rs b/winit/src/window.rs index 7a8d7b763..6a4562894 100644 --- a/winit/src/window.rs +++ b/winit/src/window.rs @@ -14,9 +14,6 @@ pub use crate::icon::{BadIcon, Icon}; #[doc(inline)] pub use winit_core::window::*; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; - /// Represents a window. /// /// The window is closed when dropped.