mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
Mark extensible enums in winit-core as #[non_exhaustive]
Event, input source, error, data transfer, native key, IME request, scroll delta and fullscreen enums can now gain variants without a breaking change. Backends and examples get wildcard arms where they matched exhaustively; unknown IME requests are reported as ImeRequestError::NotSupported and unknown fullscreen modes behave like Fullscreen::Borderless(None).
This commit is contained in:
@@ -977,6 +977,7 @@ impl CoreWindow for Window {
|
||||
*current_caps = None;
|
||||
self.app.hide_soft_input(true);
|
||||
},
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -34,7 +34,7 @@ impl CustomCursor {
|
||||
pub(crate) fn new(cursor: CustomCursorSource) -> Result<CustomCursor, RequestError> {
|
||||
let cursor = match cursor {
|
||||
CustomCursorSource::Image(cursor_image) => cursor_image,
|
||||
CustomCursorSource::Animation { .. } | CustomCursorSource::Url { .. } => {
|
||||
_ => {
|
||||
return Err(NotSupportedError::new("unsupported cursor kind").into());
|
||||
},
|
||||
};
|
||||
|
||||
@@ -453,6 +453,7 @@ impl PasteboardWriterState {
|
||||
SendData::Uris(_) => None,
|
||||
SendData::String(string) => Some(NSString::from_str(&string).into()),
|
||||
SendData::Bytes(binary) => Some(NSData::from_vec(binary).into()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,6 +248,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
|
||||
.chain(Vec::new().into_iter().map(ns_url_from_str)),
|
||||
),
|
||||
SendData::Bytes(_) => None,
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
.into_iter()
|
||||
|
||||
@@ -227,6 +227,7 @@ define_class!(
|
||||
// in fullscreen, so we must've reached here by `set_fullscreen`
|
||||
// as it updates the state
|
||||
Some(Fullscreen::Borderless(_)) => (),
|
||||
Some(_) => (),
|
||||
// Otherwise, we must've reached fullscreen by the user clicking
|
||||
// on the green fullscreen button. Update state!
|
||||
None => {
|
||||
@@ -667,6 +668,7 @@ fn new_window(
|
||||
monitor.ns_screen(mtm).or_else(|| NSScreen::mainScreen(mtm))
|
||||
},
|
||||
Some(Fullscreen::Borderless(None)) => NSScreen::mainScreen(mtm),
|
||||
Some(_) => NSScreen::mainScreen(mtm),
|
||||
None => None,
|
||||
};
|
||||
let frame = match &screen {
|
||||
@@ -1683,7 +1685,7 @@ impl WindowDelegate {
|
||||
let monitor = monitor.cast_ref::<MonitorHandle>().unwrap();
|
||||
monitor.ns_screen(mtm)
|
||||
},
|
||||
Fullscreen::Borderless(None) => {
|
||||
_ => {
|
||||
if let Some(monitor) = self.current_monitor_inner() {
|
||||
monitor.ns_screen(mtm)
|
||||
} else {
|
||||
@@ -1928,6 +1930,7 @@ impl WindowDelegate {
|
||||
self.view().disable_ime();
|
||||
return Ok(());
|
||||
},
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
};
|
||||
|
||||
if let Some((spot, size)) = request_data.cursor_area {
|
||||
|
||||
@@ -111,6 +111,7 @@ impl_dyn_casting!(CustomCursorProvider);
|
||||
///
|
||||
/// See [`CustomCursor`] for more details.
|
||||
#[derive(Debug, Clone, Eq, Hash, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum CustomCursorSource {
|
||||
/// Cursor that is backed by RGBA image.
|
||||
///
|
||||
@@ -167,6 +168,7 @@ impl CustomCursorSource {
|
||||
/// An error produced when using [`CustomCursorSource::from_rgba`] with invalid arguments.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum BadImage {
|
||||
/// Produced when the image dimensions are larger than [`MAX_CURSOR_SIZE`]. This doesn't
|
||||
/// guarantee that the cursor will work, but should avoid many platform and device specific
|
||||
@@ -217,6 +219,7 @@ impl Error for BadImage {}
|
||||
/// An error produced when using [`CustomCursorSource::from_animation`] with invalid arguments.
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum BadAnimation {
|
||||
/// Produced when no cursors were supplied.
|
||||
Empty,
|
||||
|
||||
@@ -127,6 +127,7 @@ impl DataTransferId {
|
||||
|
||||
/// The set of types supported cross-platform.
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum TypeHint {
|
||||
/// Plain UTF-8 text (see [`TypedData::try_as_string`]).
|
||||
///
|
||||
@@ -381,6 +382,7 @@ impl_dyn_casting!(DataTransfer);
|
||||
/// different encoding on different platforms. To allow this to be represented, we allow
|
||||
/// supplying strings and URIs separately from binary blobs.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum SendData {
|
||||
/// List of URIs.
|
||||
///
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::window::{ActivationToken, Theme};
|
||||
|
||||
/// Describes the reason the event loop is resuming.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
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
|
||||
@@ -44,6 +45,7 @@ pub enum StartCause {
|
||||
|
||||
/// Describes an event from a [`Window`].
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum WindowEvent {
|
||||
/// The activation token was delivered back and now could be used.
|
||||
ActivationTokenDone { serial: AsyncRequestSerial, token: ActivationToken },
|
||||
@@ -531,6 +533,7 @@ pub enum WindowEvent {
|
||||
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
|
||||
/// system.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum PointerKind {
|
||||
Mouse,
|
||||
/// See [`PointerSource::Touch`] for more details.
|
||||
@@ -548,6 +551,7 @@ pub enum PointerKind {
|
||||
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
|
||||
/// system.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum PointerSource {
|
||||
Mouse,
|
||||
/// Represents a touch event.
|
||||
@@ -616,6 +620,7 @@ impl From<PointerSource> for PointerKind {
|
||||
/// **Wayland/X11:** [`Unknown`](Self::Unknown) device types are converted to known variants by the
|
||||
/// system.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ButtonSource {
|
||||
/// ## Platform-specific
|
||||
///
|
||||
@@ -730,6 +735,7 @@ impl FingerId {
|
||||
///
|
||||
/// [window events]: WindowEvent
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum DeviceEvent {
|
||||
/// Change in physical position of a pointing device.
|
||||
///
|
||||
@@ -1052,6 +1058,7 @@ impl From<ModifiersState> for Modifiers {
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum Ime {
|
||||
/// Notifies when the IME was enabled.
|
||||
///
|
||||
@@ -1576,6 +1583,7 @@ impl From<TabletToolButton> for Option<MouseButton> {
|
||||
/// Describes a difference in the mouse scroll wheel state.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum MouseScrollDelta {
|
||||
/// Amount in lines or rows to scroll in the horizontal
|
||||
/// and vertical directions.
|
||||
|
||||
@@ -282,6 +282,7 @@ impl From<Icon> for DragIcon {
|
||||
/// are expected to provide some kind of order of preference.
|
||||
#[repr(u8)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub enum DndAction {
|
||||
/// Move the dragged item from the source to the destination.
|
||||
///
|
||||
|
||||
@@ -26,6 +26,7 @@ impl_dyn_casting!(IconProvider);
|
||||
|
||||
#[derive(Debug)]
|
||||
/// An error produced when using [`RgbaIcon::new`] with invalid arguments.
|
||||
#[non_exhaustive]
|
||||
pub enum BadIcon {
|
||||
/// Produced when the length of the `rgba` argument isn't divisible by 4, thus `rgba` can't be
|
||||
/// safely interpreted as 32bpp RGBA pixels.
|
||||
|
||||
@@ -19,6 +19,7 @@ pub use smol_str::SmolStr;
|
||||
/// - On non-Web platforms, support assigning keybinds to virtually any key through a UI.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum NativeKeyCode {
|
||||
Unidentified,
|
||||
/// An Android "scancode".
|
||||
@@ -78,6 +79,7 @@ impl std::fmt::Debug for NativeKeyCode {
|
||||
/// define keybinds which work in the presence of identifiers we haven't mapped for you yet.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[non_exhaustive]
|
||||
pub enum NativeKey {
|
||||
Unidentified,
|
||||
/// An Android "keycode", which is similar to a "virtual-key code" on Windows.
|
||||
|
||||
@@ -183,6 +183,7 @@ impl fmt::Display for VideoMode {
|
||||
|
||||
/// Fullscreen modes.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum Fullscreen {
|
||||
Exclusive(MonitorHandle, VideoMode),
|
||||
|
||||
|
||||
@@ -1756,6 +1756,7 @@ bitflags! {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum ImeSurroundingTextError {
|
||||
/// Text exceeds 4000 bytes
|
||||
TextTooLong,
|
||||
@@ -1868,6 +1869,7 @@ impl ImeSurroundingText {
|
||||
|
||||
/// Request to send to IME.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[non_exhaustive]
|
||||
pub enum ImeRequest {
|
||||
/// Enable the IME with the [`ImeCapabilities`] and [`ImeRequestData`] as initial state. When
|
||||
/// the [`ImeRequestData`] is **not** matching capabilities fully, the default values will be
|
||||
|
||||
@@ -342,6 +342,7 @@ impl CoreWindow for Window {
|
||||
None => {
|
||||
let _ = self.set_flag(ORBITAL_FLAG_FULLSCREEN, false);
|
||||
},
|
||||
Some(_) => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -323,9 +323,7 @@ impl Inner {
|
||||
Some(Fullscreen::Borderless(Some(monitor))) => {
|
||||
monitor.cast_ref::<MonitorHandle>().unwrap().ui_screen(mtm).clone()
|
||||
},
|
||||
Some(Fullscreen::Borderless(None)) => {
|
||||
self.current_monitor_inner().ui_screen(mtm).clone()
|
||||
},
|
||||
Some(_) => self.current_monitor_inner().ui_screen(mtm).clone(),
|
||||
None => {
|
||||
warn!("`Window::set_fullscreen(None)` ignored on iOS");
|
||||
return;
|
||||
@@ -405,6 +403,7 @@ impl Inner {
|
||||
*current_caps = None;
|
||||
self.view.resignFirstResponder();
|
||||
},
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -522,7 +521,7 @@ impl Window {
|
||||
let monitor = monitor.cast_ref::<MonitorHandle>().unwrap();
|
||||
monitor.ui_screen(mtm)
|
||||
},
|
||||
Some(Fullscreen::Borderless(None)) | None => &main_screen,
|
||||
_ => &main_screen,
|
||||
};
|
||||
|
||||
let screen_bounds = screen.bounds();
|
||||
|
||||
@@ -85,6 +85,7 @@ impl DataSourceHandler for WinitState {
|
||||
},
|
||||
},
|
||||
SendData::Bytes(binary) => Cursor::new(binary),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let _ = self.loop_handle.insert_source(fd, move |_, file, _| {
|
||||
|
||||
@@ -694,7 +694,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
|
||||
) -> Result<CoreCustomCursor, RequestError> {
|
||||
let cursor_image = match cursor {
|
||||
CustomCursorSource::Image(cursor_image) => cursor_image,
|
||||
CustomCursorSource::Animation { .. } | CustomCursorSource::Url { .. } => {
|
||||
_ => {
|
||||
return Err(NotSupportedError::new("unsupported cursor kind").into());
|
||||
},
|
||||
};
|
||||
|
||||
@@ -453,9 +453,6 @@ impl CoreWindow for Window {
|
||||
|
||||
fn set_fullscreen(&self, fullscreen: Option<Fullscreen>) {
|
||||
match fullscreen {
|
||||
Some(Fullscreen::Exclusive(..)) => {
|
||||
warn!("`Fullscreen::Exclusive` is ignored on Wayland");
|
||||
},
|
||||
Some(Fullscreen::Borderless(monitor)) => {
|
||||
let output = monitor.as_ref().and_then(|monitor| {
|
||||
monitor.cast_ref::<output::MonitorHandle>().map(|handle| &handle.proxy)
|
||||
@@ -463,6 +460,9 @@ impl CoreWindow for Window {
|
||||
|
||||
self.window.set_fullscreen(output)
|
||||
},
|
||||
Some(_) => {
|
||||
warn!("this fullscreen mode is ignored on Wayland");
|
||||
},
|
||||
None => self.window.unset_fullscreen(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1269,6 +1269,7 @@ impl WindowState {
|
||||
self.text_input_state = None;
|
||||
true
|
||||
},
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
};
|
||||
|
||||
// Only one input method may be active per (seat, surface),
|
||||
|
||||
@@ -54,6 +54,7 @@ impl CustomCursor {
|
||||
true,
|
||||
)
|
||||
},
|
||||
_ => unimplemented!("unknown `CustomCursorSource` variant"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ pub fn pointer_source(event: &PointerEvent, kind: PointerKind) -> PointerSource
|
||||
|
||||
PointerSource::TabletTool { kind: tool, data }
|
||||
},
|
||||
PointerKind::Unknown => PointerSource::Unknown,
|
||||
_ => PointerSource::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ pub(crate) fn request_fullscreen(
|
||||
canvas.webkit_request_fullscreen();
|
||||
}
|
||||
},
|
||||
_ => error!("This full screen mode is not supported"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ impl PointerHandler {
|
||||
PointerSource::TabletTool { kind, data } => {
|
||||
ButtonSource::TabletTool { kind, button: event::tool_button(button), data }
|
||||
},
|
||||
PointerSource::Unknown => ButtonSource::Unknown(button),
|
||||
_ => ButtonSource::Unknown(button),
|
||||
};
|
||||
|
||||
handler(
|
||||
@@ -152,7 +152,7 @@ impl PointerHandler {
|
||||
|
||||
ButtonSource::TabletTool { kind, button: event::tool_button(button), data }
|
||||
},
|
||||
PointerSource::Unknown => ButtonSource::Unknown(button),
|
||||
_ => ButtonSource::Unknown(button),
|
||||
};
|
||||
|
||||
handler(
|
||||
@@ -229,7 +229,7 @@ impl PointerHandler {
|
||||
button: event::tool_button(button),
|
||||
data,
|
||||
},
|
||||
PointerSource::Unknown => ButtonSource::Unknown(button),
|
||||
_ => ButtonSource::Unknown(button),
|
||||
};
|
||||
|
||||
button_handler(
|
||||
|
||||
@@ -247,6 +247,7 @@ impl TypedData for WinTypedData {
|
||||
},
|
||||
// Windows URI drag-and-drop can't be neatly expressed as a binary blob.
|
||||
SendData::Uris(_) => None,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,6 +925,7 @@ unsafe fn send_data_to_stgmedium(data: SendData, hint: TypeHint) -> Option<STGME
|
||||
hglobal
|
||||
},
|
||||
SendData::Bytes(b) => alloc_hglobal_from(&b)?,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let mut medium = unsafe { std::mem::zeroed::<STGMEDIUM>() };
|
||||
|
||||
@@ -431,7 +431,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
|
||||
) -> Result<CustomCursor, RequestError> {
|
||||
let cursor = match source {
|
||||
CustomCursorSource::Image(cursor) => cursor,
|
||||
CustomCursorSource::Animation { .. } | CustomCursorSource::Url { .. } => {
|
||||
_ => {
|
||||
return Err(NotSupportedError::new("unsupported cursor kind").into());
|
||||
},
|
||||
};
|
||||
@@ -1397,6 +1397,7 @@ unsafe fn public_window_callback_inner(
|
||||
window_pos.cy = old_monitor_rect.bottom - old_monitor_rect.top;
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -967,7 +967,7 @@ impl CoreWindow for Window {
|
||||
| Fullscreen::Borderless(Some(monitor)) => {
|
||||
Some(Cow::Borrowed(monitor.cast_ref::<MonitorHandle>().unwrap()))
|
||||
},
|
||||
Fullscreen::Borderless(None) => None,
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let monitor = monitor
|
||||
@@ -1068,7 +1068,8 @@ impl CoreWindow for Window {
|
||||
match &request {
|
||||
ImeRequest::Enable(..) if cap.is_some() => return Err(ImeRequestError::AlreadyEnabled),
|
||||
ImeRequest::Update(_) if cap.is_none() => return Err(ImeRequestError::NotEnabled),
|
||||
_ => (),
|
||||
ImeRequest::Enable(..) | ImeRequest::Update(_) | ImeRequest::Disable => (),
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
}
|
||||
|
||||
let window = self.window;
|
||||
@@ -1096,6 +1097,7 @@ impl CoreWindow for Window {
|
||||
ImeContext::set_ime_allowed(window.hwnd(), false);
|
||||
return;
|
||||
},
|
||||
_ => return,
|
||||
};
|
||||
|
||||
if let Some((spot, size)) = request_data.cursor_area {
|
||||
|
||||
@@ -199,7 +199,7 @@ impl CustomCursor {
|
||||
) -> Result<CustomCursor, RequestError> {
|
||||
let mut cursor = match cursor {
|
||||
CustomCursorSource::Image(cursor_image) => cursor_image,
|
||||
CustomCursorSource::Animation { .. } | CustomCursorSource::Url { .. } => {
|
||||
_ => {
|
||||
return Err(NotSupportedError::new("unsupported cursor kind").into());
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1105,9 +1105,7 @@ impl UnownedWindow {
|
||||
let monitor = monitor.cast_ref::<X11MonitorHandle>().unwrap();
|
||||
(Cow::Borrowed(monitor), None)
|
||||
},
|
||||
Fullscreen::Borderless(None) => {
|
||||
(Cow::Owned(self.shared_state_lock().last_monitor.clone()), None)
|
||||
},
|
||||
_ => (Cow::Owned(self.shared_state_lock().last_monitor.clone()), None),
|
||||
};
|
||||
|
||||
// Don't set fullscreen on an invalid dummy monitor handle
|
||||
@@ -2144,6 +2142,7 @@ impl UnownedWindow {
|
||||
self.set_ime_allowed(false);
|
||||
return Ok(());
|
||||
},
|
||||
_ => return Err(ImeRequestError::NotSupported),
|
||||
};
|
||||
|
||||
if let Some((position, size)) = state.cursor_area {
|
||||
|
||||
@@ -457,6 +457,7 @@ impl ApplicationHandler for Application {
|
||||
MouseScrollDelta::PixelDelta(px) => {
|
||||
info!("Mouse wheel Pixel Delta: ({},{})", px.x, px.y);
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
WindowEvent::KeyboardInput { event, is_synthetic: false, .. } => {
|
||||
let mods = window.modifiers;
|
||||
|
||||
@@ -248,6 +248,7 @@ impl App {
|
||||
}
|
||||
},
|
||||
Ime::Disabled => info!("IME disabled for Window={:?}", surface.window().id()),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user