api: unify error handling

Make error infrastructure more backend agnostic and let backends
just forward the os errors opaquely.
This commit is contained in:
Kirill Chibisov 2024-09-06 17:20:11 +03:00 committed by GitHub
parent 8db3e0e043
commit b674d20edf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
35 changed files with 507 additions and 630 deletions

View file

@ -17,7 +17,7 @@ use rwh_06::{DisplayHandle, HasDisplayHandle};
use softbuffer::{Context, Surface}; use softbuffer::{Context, Surface};
use winit::application::ApplicationHandler; use winit::application::ApplicationHandler;
use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize}; use winit::dpi::{LogicalSize, PhysicalPosition, PhysicalSize};
use winit::error::ExternalError; use winit::error::RequestError;
use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent}; use winit::event::{DeviceEvent, DeviceId, Ime, MouseButton, MouseScrollDelta, WindowEvent};
use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::keyboard::{Key, ModifiersState}; use winit::keyboard::{Key, ModifiersState};
@ -76,7 +76,7 @@ struct Application {
receiver: Receiver<Action>, receiver: Receiver<Action>,
sender: Sender<Action>, sender: Sender<Action>,
/// Custom cursors assets. /// Custom cursors assets.
custom_cursors: Result<Vec<CustomCursor>, ExternalError>, custom_cursors: Result<Vec<CustomCursor>, RequestError>,
/// Application icon. /// Application icon.
icon: Icon, icon: Icon,
windows: HashMap<WindowId, WindowState>, windows: HashMap<WindowId, WindowState>,

View file

@ -1,45 +1,40 @@
use std::{error, fmt}; use std::error::Error;
use std::fmt::{self, Display};
use crate::platform_impl; /// A general error that may occur while running or creating
/// the event loop.
// TODO: Rename
/// An error that may be generated when requesting Winit state
#[derive(Debug)]
pub enum ExternalError {
/// The operation is not supported by the backend.
NotSupported(NotSupportedError),
/// The operation was ignored.
Ignored,
/// The OS cannot perform the operation.
Os(OsError),
}
/// The error type for when the requested operation is not supported by the backend.
#[derive(Clone, Copy, Default, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct NotSupportedError {
_marker: (),
}
/// The error type for when the OS cannot perform the requested operation.
#[derive(Debug)]
pub struct OsError {
line: u32,
file: &'static str,
error: platform_impl::OsError,
}
/// A general error that may occur while running the Winit event loop
#[derive(Debug)] #[derive(Debug)]
#[non_exhaustive]
pub enum EventLoopError { pub enum EventLoopError {
/// The operation is not supported by the backend.
NotSupported(NotSupportedError),
/// The OS cannot perform the operation.
Os(OsError),
/// The event loop can't be re-created. /// The event loop can't be re-created.
RecreationAttempt, RecreationAttempt,
/// Application has exit with an error status. /// Application has exit with an error status.
ExitFailure(i32), ExitFailure(i32),
/// Got unspecified OS-specific error during the request.
Os(OsError),
/// Creating the event loop with the requested configuration is not supported.
NotSupported(NotSupportedError),
}
impl fmt::Display for EventLoopError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::RecreationAttempt => write!(f, "EventLoop can't be recreated"),
Self::Os(err) => err.fmt(f),
Self::ExitFailure(status) => write!(f, "Exit Failure: {status}"),
Self::NotSupported(err) => err.fmt(f),
}
}
}
impl Error for EventLoopError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
if let Self::Os(err) = self {
err.source()
} else {
None
}
}
} }
impl From<OsError> for EventLoopError { impl From<OsError> for EventLoopError {
@ -48,18 +43,102 @@ impl From<OsError> for EventLoopError {
} }
} }
impl NotSupportedError { impl From<NotSupportedError> for EventLoopError {
#[inline] fn from(value: NotSupportedError) -> Self {
#[allow(dead_code)] Self::NotSupported(value)
pub(crate) fn new() -> NotSupportedError {
NotSupportedError { _marker: () }
} }
} }
/// A general error that may occur during a request to the windowing system.
#[derive(Debug)]
#[non_exhaustive]
pub enum RequestError {
/// The request is not supported.
NotSupported(NotSupportedError),
/// The request was ignored by the operating system.
Ignored,
/// Got unspecified OS specific error during the request.
Os(OsError),
}
impl Display for RequestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotSupported(err) => err.fmt(f),
Self::Ignored => write!(f, "The request was ignored"),
Self::Os(err) => err.fmt(f),
}
}
}
impl Error for RequestError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
if let Self::Os(err) = self {
err.source()
} else {
None
}
}
}
impl From<NotSupportedError> for RequestError {
fn from(value: NotSupportedError) -> Self {
Self::NotSupported(value)
}
}
impl From<OsError> for RequestError {
fn from(value: OsError) -> Self {
Self::Os(value)
}
}
/// The requested operation is not supported.
#[derive(Debug)]
pub struct NotSupportedError {
/// The reason why a certain operation is not supported.
reason: &'static str,
}
impl NotSupportedError {
pub(crate) fn new(reason: &'static str) -> Self {
Self { reason }
}
}
impl fmt::Display for NotSupportedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Operation is not supported: {}", self.reason)
}
}
impl Error for NotSupportedError {}
/// Unclassified error from the OS.
#[derive(Debug)]
pub struct OsError {
line: u32,
file: &'static str,
error: Box<dyn Error + Send + Sync + 'static>,
}
impl OsError { impl OsError {
#[allow(dead_code)] #[allow(dead_code)]
pub(crate) fn new(line: u32, file: &'static str, error: platform_impl::OsError) -> OsError { pub(crate) fn new(
OsError { line, file, error } line: u32,
file: &'static str,
error: impl Into<Box<dyn Error + Send + Sync + 'static>>,
) -> Self {
Self { line, file, error: error.into() }
}
}
impl Display for OsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad(&format!("os error at {}:{}: {}", self.file, self.line, self.error))
}
}
impl Error for OsError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(self.error.as_ref())
} }
} }
@ -69,64 +148,3 @@ macro_rules! os_error {
crate::error::OsError::new(line!(), file!(), $error) crate::error::OsError::new(line!(), file!(), $error)
}}; }};
} }
impl fmt::Display for OsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.pad(&format!("os error at {}:{}: {}", self.file, self.line, self.error))
}
}
impl fmt::Display for ExternalError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
ExternalError::NotSupported(e) => e.fmt(f),
ExternalError::Ignored => write!(f, "Operation was ignored"),
ExternalError::Os(e) => e.fmt(f),
}
}
}
impl fmt::Debug for NotSupportedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.debug_struct("NotSupportedError").finish()
}
}
impl fmt::Display for NotSupportedError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.pad("the requested operation is not supported by Winit")
}
}
impl fmt::Display for EventLoopError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
EventLoopError::RecreationAttempt => write!(f, "EventLoop can't be recreated"),
EventLoopError::NotSupported(e) => e.fmt(f),
EventLoopError::Os(e) => e.fmt(f),
EventLoopError::ExitFailure(status) => write!(f, "Exit Failure: {status}"),
}
}
}
impl error::Error for OsError {}
impl error::Error for ExternalError {}
impl error::Error for NotSupportedError {}
impl error::Error for EventLoopError {}
#[cfg(test)]
#[allow(clippy::redundant_clone)]
mod tests {
use super::*;
// Eat attributes for testing
#[test]
fn ensure_fmt_does_not_panic() {
let _ = format!("{:?}, {}", NotSupportedError::new(), NotSupportedError::new().clone());
let _ = format!(
"{:?}, {}",
ExternalError::NotSupported(NotSupportedError::new()),
ExternalError::NotSupported(NotSupportedError::new())
);
}
}

View file

@ -46,7 +46,7 @@ use smol_str::SmolStr;
use web_time::Instant; use web_time::Instant;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::error::ExternalError; use crate::error::RequestError;
use crate::event_loop::AsyncRequestSerial; use crate::event_loop::AsyncRequestSerial;
use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState}; use crate::keyboard::{self, ModifiersKeyState, ModifiersKeys, ModifiersState};
use crate::platform_impl; use crate::platform_impl;
@ -1016,12 +1016,12 @@ impl SurfaceSizeWriter {
pub fn request_surface_size( pub fn request_surface_size(
&mut self, &mut self,
new_surface_size: PhysicalSize<u32>, new_surface_size: PhysicalSize<u32>,
) -> Result<(), ExternalError> { ) -> Result<(), RequestError> {
if let Some(inner) = self.new_surface_size.upgrade() { if let Some(inner) = self.new_surface_size.upgrade() {
*inner.lock().unwrap() = new_surface_size; *inner.lock().unwrap() = new_surface_size;
Ok(()) Ok(())
} else { } else {
Err(ExternalError::Ignored) Err(RequestError::Ignored)
} }
} }
} }

View file

@ -20,7 +20,7 @@ use std::time::{Duration, Instant};
use web_time::{Duration, Instant}; use web_time::{Duration, Instant};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, ExternalError, OsError}; use crate::error::{EventLoopError, RequestError};
use crate::monitor::MonitorHandle; use crate::monitor::MonitorHandle;
use crate::platform_impl; use crate::platform_impl;
use crate::utils::AsAny; use crate::utils::AsAny;
@ -268,7 +268,7 @@ impl EventLoop {
pub fn create_custom_cursor( pub fn create_custom_cursor(
&self, &self,
custom_cursor: CustomCursorSource, custom_cursor: CustomCursorSource,
) -> Result<CustomCursor, ExternalError> { ) -> Result<CustomCursor, RequestError> {
self.event_loop.window_target().create_custom_cursor(custom_cursor) self.event_loop.window_target().create_custom_cursor(custom_cursor)
} }
} }
@ -324,7 +324,7 @@ pub trait ActiveEventLoop: AsAny {
fn create_window( fn create_window(
&self, &self,
window_attributes: WindowAttributes, window_attributes: WindowAttributes,
) -> Result<Box<dyn Window>, OsError>; ) -> Result<Box<dyn Window>, RequestError>;
/// Create custom cursor. /// Create custom cursor.
/// ///
@ -334,7 +334,7 @@ pub trait ActiveEventLoop: AsAny {
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
custom_cursor: CustomCursorSource, custom_cursor: CustomCursorSource,
) -> Result<CustomCursor, ExternalError>; ) -> Result<CustomCursor, RequestError>;
/// Returns the list of all the monitors available on the system. /// Returns the list of all the monitors available on the system.
/// ///

View file

@ -23,7 +23,7 @@
use std::env; use std::env;
use crate::error::NotSupportedError; use crate::error::{NotSupportedError, RequestError};
use crate::event_loop::{ActiveEventLoop, AsyncRequestSerial}; use crate::event_loop::{ActiveEventLoop, AsyncRequestSerial};
#[cfg(wayland_platform)] #[cfg(wayland_platform)]
use crate::platform::wayland::ActiveEventLoopExtWayland; use crate::platform::wayland::ActiveEventLoopExtWayland;
@ -46,7 +46,7 @@ pub trait WindowExtStartupNotify {
/// Request a new activation token. /// Request a new activation token.
/// ///
/// The token will be delivered inside /// The token will be delivered inside
fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError>; fn request_activation_token(&self) -> Result<AsyncRequestSerial, RequestError>;
} }
pub trait WindowAttributesExtStartupNotify { pub trait WindowAttributesExtStartupNotify {
@ -73,7 +73,7 @@ impl EventLoopExtStartupNotify for dyn ActiveEventLoop + '_ {
} }
impl WindowExtStartupNotify for dyn Window + '_ { impl WindowExtStartupNotify for dyn Window + '_ {
fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError> { fn request_activation_token(&self) -> Result<AsyncRequestSerial, RequestError> {
#[cfg(wayland_platform)] #[cfg(wayland_platform)]
if let Some(window) = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>() if let Some(window) = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>()
{ {
@ -87,7 +87,7 @@ impl WindowExtStartupNotify for dyn Window + '_ {
return window.request_activation_token(); return window.request_activation_token();
} }
Err(NotSupportedError::new()) Err(NotSupportedError::new("startup notify is not supported").into())
} }
} }

View file

@ -14,7 +14,7 @@ use tracing::{debug, trace, warn};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{self, EventLoopError, ExternalError, NotSupportedError}; use crate::error::{EventLoopError, NotSupportedError, RequestError};
use crate::event::{self, Force, StartCause, SurfaceSizeWriter}; use crate::event::{self, Force, StartCause, SurfaceSizeWriter};
use crate::event_loop::{ use crate::event_loop::{
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
@ -592,15 +592,15 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: WindowAttributes, window_attributes: WindowAttributes,
) -> Result<Box<dyn CoreWindow>, error::OsError> { ) -> Result<Box<dyn CoreWindow>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
_source: CustomCursorSource, _source: CustomCursorSource,
) -> Result<CustomCursor, ExternalError> { ) -> Result<CustomCursor, RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("create_custom_cursor is not supported").into())
} }
fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> { fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> {
@ -715,7 +715,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
el: &ActiveEventLoop, el: &ActiveEventLoop,
_window_attrs: window::WindowAttributes, _window_attrs: window::WindowAttributes,
) -> Result<Self, error::OsError> { ) -> Result<Self, RequestError> {
// FIXME this ignores requested window attributes // FIXME this ignores requested window attributes
Ok(Self { app: el.app.clone(), redraw_requester: el.redraw_requester.clone() }) Ok(Self { app: el.app.clone(), redraw_requester: el.redraw_requester.clone() })
@ -796,12 +796,12 @@ impl CoreWindow for Window {
fn pre_present_notify(&self) {} fn pre_present_notify(&self) {}
fn inner_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Err(error::NotSupportedError::new()) Err(NotSupportedError::new("inner_position is not supported").into())
} }
fn outer_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Err(error::NotSupportedError::new()) Err(NotSupportedError::new("outer_position is not supported").into())
} }
fn set_outer_position(&self, _position: Position) { fn set_outer_position(&self, _position: Position) {
@ -896,29 +896,29 @@ impl CoreWindow for Window {
fn set_cursor(&self, _: Cursor) {} fn set_cursor(&self, _: Cursor) {}
fn set_cursor_position(&self, _: Position) -> Result<(), error::ExternalError> { fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_position is not supported").into())
} }
fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), error::ExternalError> { fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_grab is not supported").into())
} }
fn set_cursor_visible(&self, _: bool) {} fn set_cursor_visible(&self, _: bool) {}
fn drag_window(&self) -> Result<(), error::ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("drag_window is not supported").into())
} }
fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), error::ExternalError> { fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("drag_resize_window").into())
} }
#[inline] #[inline]
fn show_window_menu(&self, _position: Position) {} fn show_window_menu(&self, _position: Position) {}
fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), error::ExternalError> { fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_hittest is not supported").into())
} }
fn set_theme(&self, _theme: Option<Theme>) {} fn set_theme(&self, _theme: Option<Theme>) {}

View file

@ -11,9 +11,8 @@ use objc2_foundation::{
NSString, NSString,
}; };
use super::OsError;
use crate::cursor::{CursorImage, OnlyCursorImageSource}; use crate::cursor::{CursorImage, OnlyCursorImageSource};
use crate::error::ExternalError; use crate::error::RequestError;
use crate::window::CursorIcon; use crate::window::CursorIcon;
#[derive(Clone, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Debug, PartialEq, Eq, Hash)]
@ -25,12 +24,12 @@ unsafe impl Send for CustomCursor {}
unsafe impl Sync for CustomCursor {} unsafe impl Sync for CustomCursor {}
impl CustomCursor { impl CustomCursor {
pub(crate) fn new(cursor: OnlyCursorImageSource) -> Result<CustomCursor, ExternalError> { pub(crate) fn new(cursor: OnlyCursorImageSource) -> Result<CustomCursor, RequestError> {
cursor_from_image(&cursor.0).map(Self) cursor_from_image(&cursor.0).map(Self)
} }
} }
pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Result<Retained<NSCursor>, ExternalError> { pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Result<Retained<NSCursor>, RequestError> {
let width = cursor.width; let width = cursor.width;
let height = cursor.height; let height = cursor.height;
@ -48,7 +47,7 @@ pub(crate) fn cursor_from_image(cursor: &CursorImage) -> Result<Retained<NSCurso
width as isize * 4, width as isize * 4,
32, 32,
) )
}.ok_or_else(|| ExternalError::Os(os_error!(OsError::CreationError("parent view should be installed in a window"))))?; }.ok_or_else(|| os_error!("parent view should be installed in a window"))?;
let bitmap_data = unsafe { slice::from_raw_parts_mut(bitmap.bitmapData(), cursor.rgba.len()) }; let bitmap_data = unsafe { slice::from_raw_parts_mut(bitmap.bitmapData(), cursor.rgba.len()) };
bitmap_data.copy_from_slice(&cursor.rgba); bitmap_data.copy_from_slice(&cursor.rgba);

View file

@ -29,7 +29,7 @@ use super::event::dummy_event;
use super::monitor; use super::monitor;
use super::observer::setup_control_flow_observers; use super::observer::setup_control_flow_observers;
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, ExternalError}; use crate::error::{EventLoopError, RequestError};
use crate::event_loop::{ use crate::event_loop::{
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle, EventLoopProxy as RootEventLoopProxy, OwnedDisplayHandle as RootOwnedDisplayHandle,
@ -103,14 +103,14 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: crate::window::WindowAttributes, window_attributes: crate::window::WindowAttributes,
) -> Result<Box<dyn crate::window::Window>, crate::error::OsError> { ) -> Result<Box<dyn crate::window::Window>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
source: CustomCursorSource, source: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Ok(RootCustomCursor { inner: CustomCursor::new(source.inner)? }) Ok(RootCustomCursor { inner: CustomCursor::new(source.inner)? })
} }

View file

@ -14,8 +14,6 @@ mod view;
mod window; mod window;
mod window_delegate; mod window_delegate;
use std::fmt;
pub(crate) use self::cursor::CustomCursor as PlatformCustomCursor; pub(crate) use self::cursor::CustomCursor as PlatformCustomCursor;
pub(crate) use self::event::{physicalkey_to_scancode, scancode_to_physicalkey, KeyEventExtra}; pub(crate) use self::event::{physicalkey_to_scancode, scancode_to_physicalkey, KeyEventExtra};
pub(crate) use self::event_loop::{ pub(crate) use self::event_loop::{
@ -50,18 +48,3 @@ impl FingerId {
FingerId FingerId
} }
} }
#[derive(Debug)]
pub enum OsError {
CGError(core_graphics::base::CGError),
CreationError(&'static str),
}
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),
}
}
}

View file

@ -8,7 +8,7 @@ use objc2_foundation::{MainThreadBound, MainThreadMarker, NSObject};
use super::event_loop::ActiveEventLoop; use super::event_loop::ActiveEventLoop;
use super::window_delegate::WindowDelegate; use super::window_delegate::WindowDelegate;
use crate::error::OsError as RootOsError; use crate::error::RequestError;
use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{ use crate::window::{
Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow, Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow,
@ -25,7 +25,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
window_target: &ActiveEventLoop, window_target: &ActiveEventLoop,
attributes: WindowAttributes, attributes: WindowAttributes,
) -> Result<Self, RootOsError> { ) -> Result<Self, RequestError> {
let mtm = window_target.mtm; let mtm = window_target.mtm;
let delegate = let delegate =
autoreleasepool(|_| WindowDelegate::new(&window_target.app_state, attributes, mtm))?; autoreleasepool(|_| WindowDelegate::new(&window_target.app_state, attributes, mtm))?;
@ -111,16 +111,12 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys()); self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys());
} }
fn inner_position( fn inner_position(&self) -> Result<dpi::PhysicalPosition<i32>, RequestError> {
&self, Ok(self.maybe_wait_on_main(|delegate| delegate.inner_position()))
) -> Result<dpi::PhysicalPosition<i32>, crate::error::NotSupportedError> {
self.maybe_wait_on_main(|delegate| delegate.inner_position())
} }
fn outer_position( fn outer_position(&self) -> Result<dpi::PhysicalPosition<i32>, RequestError> {
&self, Ok(self.maybe_wait_on_main(|delegate| delegate.outer_position()))
) -> Result<dpi::PhysicalPosition<i32>, crate::error::NotSupportedError> {
self.maybe_wait_on_main(|delegate| delegate.outer_position())
} }
fn set_outer_position(&self, position: Position) { fn set_outer_position(&self, position: Position) {
@ -275,14 +271,11 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor));
} }
fn set_cursor_position(&self, position: Position) -> Result<(), crate::error::ExternalError> { fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position)) self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position))
} }
fn set_cursor_grab( fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> {
&self,
mode: crate::window::CursorGrabMode,
) -> Result<(), crate::error::ExternalError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode)) self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode))
} }
@ -290,23 +283,25 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible))
} }
fn drag_window(&self) -> Result<(), crate::error::ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.drag_window()) self.maybe_wait_on_main(|delegate| delegate.drag_window());
Ok(())
} }
fn drag_resize_window( fn drag_resize_window(
&self, &self,
direction: crate::window::ResizeDirection, direction: crate::window::ResizeDirection,
) -> Result<(), crate::error::ExternalError> { ) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.drag_resize_window(direction)) Ok(self.maybe_wait_on_main(|delegate| delegate.drag_resize_window(direction))?)
} }
fn show_window_menu(&self, position: Position) { fn show_window_menu(&self, position: Position) {
self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position))
} }
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), crate::error::ExternalError> { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest)) self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest));
Ok(())
} }
fn current_monitor(&self) -> Option<CoreMonitorHandle> { fn current_monitor(&self) -> Option<CoreMonitorHandle> {

View file

@ -33,9 +33,9 @@ use super::monitor::{self, flip_window_screen_coordinates, get_display_id};
use super::observer::RunLoop; use super::observer::RunLoop;
use super::view::WinitView; use super::view::WinitView;
use super::window::WinitWindow; use super::window::WinitWindow;
use super::{ffi, Fullscreen, MonitorHandle, OsError, WindowId}; use super::{ffi, Fullscreen, MonitorHandle, WindowId};
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{NotSupportedError, RequestError};
use crate::event::{SurfaceSizeWriter, WindowEvent}; use crate::event::{SurfaceSizeWriter, WindowEvent};
use crate::platform::macos::{OptionAsAlt, WindowExtMacOS}; use crate::platform::macos::{OptionAsAlt, WindowExtMacOS};
use crate::window::{ use crate::window::{
@ -677,9 +677,9 @@ impl WindowDelegate {
app_state: &Rc<AppState>, app_state: &Rc<AppState>,
attrs: WindowAttributes, attrs: WindowAttributes,
mtm: MainThreadMarker, mtm: MainThreadMarker,
) -> Result<Retained<Self>, RootOsError> { ) -> Result<Retained<Self>, RequestError> {
let window = new_window(app_state, &attrs, mtm) let window = new_window(app_state, &attrs, mtm)
.ok_or_else(|| os_error!(OsError::CreationError("couldn't create `NSWindow`")))?; .ok_or_else(|| os_error!("couldn't create `NSWindow`"))?;
#[cfg(feature = "rwh_06")] #[cfg(feature = "rwh_06")]
match attrs.parent_window.map(|handle| handle.0) { match attrs.parent_window.map(|handle| handle.0) {
@ -688,9 +688,9 @@ impl WindowDelegate {
// Unwrap is fine, since the pointer comes from `NonNull`. // Unwrap is fine, since the pointer comes from `NonNull`.
let parent_view: Retained<NSView> = let parent_view: Retained<NSView> =
unsafe { Retained::retain(handle.ns_view.as_ptr().cast()) }.unwrap(); unsafe { Retained::retain(handle.ns_view.as_ptr().cast()) }.unwrap();
let parent = parent_view.window().ok_or_else(|| { let parent = parent_view
os_error!(OsError::CreationError("parent view should be installed in a window")) .window()
})?; .ok_or_else(|| os_error!("parent view should be installed in a window"))?;
// SAFETY: We know that there are no parent -> child -> parent cycles since the only // SAFETY: We know that there are no parent -> child -> parent cycles since the only
// place in `winit` where we allow making a window a child window is // place in `winit` where we allow making a window a child window is
@ -925,15 +925,15 @@ impl WindowDelegate {
#[inline] #[inline]
pub fn pre_present_notify(&self) {} pub fn pre_present_notify(&self) {}
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn outer_position(&self) -> PhysicalPosition<i32> {
let position = flip_window_screen_coordinates(self.window().frame()); let position = flip_window_screen_coordinates(self.window().frame());
Ok(LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor())) LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor())
} }
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn inner_position(&self) -> PhysicalPosition<i32> {
let content_rect = self.window().contentRectForFrameRect(self.window().frame()); let content_rect = self.window().contentRectForFrameRect(self.window().frame());
let position = flip_window_screen_coordinates(content_rect); let position = flip_window_screen_coordinates(content_rect);
Ok(LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor())) LogicalPosition::new(position.x, position.y).to_physical(self.scale_factor())
} }
pub fn set_outer_position(&self, position: Position) { pub fn set_outer_position(&self, position: Position) {
@ -1125,18 +1125,18 @@ impl WindowDelegate {
} }
#[inline] #[inline]
pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
let associate_mouse_cursor = match mode { let associate_mouse_cursor = match mode {
CursorGrabMode::Locked => false, CursorGrabMode::Locked => false,
CursorGrabMode::None => true, CursorGrabMode::None => true,
CursorGrabMode::Confined => { CursorGrabMode::Confined => {
return Err(ExternalError::NotSupported(NotSupportedError::new())) return Err(NotSupportedError::new("confined cursor is not supported").into())
}, },
}; };
// TODO: Do this for real https://stackoverflow.com/a/40922095/5435443 // TODO: Do this for real https://stackoverflow.com/a/40922095/5435443
CGDisplay::associate_mouse_and_mouse_cursor_position(associate_mouse_cursor) CGDisplay::associate_mouse_and_mouse_cursor_position(associate_mouse_cursor)
.map_err(|status| ExternalError::Os(os_error!(OsError::CGError(status)))) .map_err(|status| os_error!(format!("CGError {status}")).into())
} }
#[inline] #[inline]
@ -1154,8 +1154,8 @@ impl WindowDelegate {
} }
#[inline] #[inline]
pub fn set_cursor_position(&self, cursor_position: Position) -> Result<(), ExternalError> { pub fn set_cursor_position(&self, cursor_position: Position) -> Result<(), RequestError> {
let physical_window_position = self.inner_position().unwrap(); let physical_window_position = self.inner_position();
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let window_position = physical_window_position.to_logical::<CGFloat>(scale_factor); let window_position = physical_window_position.to_logical::<CGFloat>(scale_factor);
let logical_cursor_position = cursor_position.to_logical::<CGFloat>(scale_factor); let logical_cursor_position = cursor_position.to_logical::<CGFloat>(scale_factor);
@ -1164,33 +1164,31 @@ impl WindowDelegate {
y: logical_cursor_position.y + window_position.y, y: logical_cursor_position.y + window_position.y,
}; };
CGDisplay::warp_mouse_cursor_position(point) CGDisplay::warp_mouse_cursor_position(point)
.map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?; .map_err(|status| os_error!(format!("CGError {status}")))?;
CGDisplay::associate_mouse_and_mouse_cursor_position(true) CGDisplay::associate_mouse_and_mouse_cursor_position(true)
.map_err(|e| ExternalError::Os(os_error!(OsError::CGError(e))))?; .map_err(|status| os_error!(format!("CGError {status}")))?;
Ok(()) Ok(())
} }
#[inline] #[inline]
pub fn drag_window(&self) -> Result<(), ExternalError> { pub fn drag_window(&self) {
let mtm = MainThreadMarker::from(self); let mtm = MainThreadMarker::from(self);
let event = NSApplication::sharedApplication(mtm).currentEvent().unwrap(); let event = NSApplication::sharedApplication(mtm).currentEvent().unwrap();
self.window().performWindowDragWithEvent(&event); self.window().performWindowDragWithEvent(&event);
Ok(())
} }
#[inline] #[inline]
pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("drag_resize_window is not supported"))
} }
#[inline] #[inline]
pub fn show_window_menu(&self, _position: Position) {} pub fn show_window_menu(&self, _position: Position) {}
#[inline] #[inline]
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { pub fn set_cursor_hittest(&self, hittest: bool) {
self.window().setIgnoresMouseEvents(!hittest); self.window().setIgnoresMouseEvents(!hittest);
Ok(())
} }
pub(crate) fn is_zoomed(&self) -> bool { pub(crate) fn is_zoomed(&self) -> bool {

View file

@ -25,7 +25,7 @@ use super::super::notification_center::create_observer;
use super::app_state::{send_occluded_event_for_all_windows, AppState, EventWrapper}; use super::app_state::{send_occluded_event_for_all_windows, AppState, EventWrapper};
use super::{app_state, monitor, MonitorHandle}; use super::{app_state, monitor, MonitorHandle};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, ExternalError, NotSupportedError, OsError}; use crate::error::{EventLoopError, NotSupportedError, RequestError};
use crate::event::Event; use crate::event::Event;
use crate::event_loop::{ use crate::event_loop::{
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
@ -49,15 +49,15 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: crate::window::WindowAttributes, window_attributes: crate::window::WindowAttributes,
) -> Result<Box<dyn CoreWindow>, OsError> { ) -> Result<Box<dyn CoreWindow>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
_source: CustomCursorSource, _source: CustomCursorSource,
) -> Result<CustomCursor, ExternalError> { ) -> Result<CustomCursor, RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("create_custom_cursor is not supported").into())
} }
fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> { fn available_monitors(&self) -> Box<dyn Iterator<Item = RootMonitorHandle>> {

View file

@ -20,7 +20,7 @@ use super::view_controller::WinitViewController;
use super::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle}; use super::{app_state, monitor, ActiveEventLoop, Fullscreen, MonitorHandle};
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{NotSupportedError, RequestError};
use crate::event::{Event, WindowEvent}; use crate::event::{Event, WindowEvent};
use crate::icon::Icon; use crate::icon::Icon;
use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::monitor::MonitorHandle as CoreMonitorHandle;
@ -159,20 +159,20 @@ impl Inner {
pub fn pre_present_notify(&self) {} pub fn pre_present_notify(&self) {}
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn inner_position(&self) -> PhysicalPosition<i32> {
let safe_area = self.safe_area_screen_space(); let safe_area = self.safe_area_screen_space();
let position = let position =
LogicalPosition { x: safe_area.origin.x as f64, y: safe_area.origin.y as f64 }; LogicalPosition { x: safe_area.origin.x as f64, y: safe_area.origin.y as f64 };
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
Ok(position.to_physical(scale_factor)) position.to_physical(scale_factor)
} }
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn outer_position(&self) -> PhysicalPosition<i32> {
let screen_frame = self.screen_frame(); let screen_frame = self.screen_frame();
let position = let position =
LogicalPosition { x: screen_frame.origin.x as f64, y: screen_frame.origin.y as f64 }; LogicalPosition { x: screen_frame.origin.x as f64, y: screen_frame.origin.y as f64 };
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
Ok(position.to_physical(scale_factor)) position.to_physical(scale_factor)
} }
pub fn set_outer_position(&self, physical_position: Position) { pub fn set_outer_position(&self, physical_position: Position) {
@ -256,31 +256,31 @@ impl Inner {
debug!("`Window::set_cursor` ignored on iOS") debug!("`Window::set_cursor` ignored on iOS")
} }
pub fn set_cursor_position(&self, _position: Position) -> Result<(), ExternalError> { pub fn set_cursor_position(&self, _position: Position) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_position is not supported"))
} }
pub fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), ExternalError> { pub fn set_cursor_grab(&self, _: CursorGrabMode) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_grab is not supported"))
} }
pub fn set_cursor_visible(&self, _visible: bool) { pub fn set_cursor_visible(&self, _visible: bool) {
debug!("`Window::set_cursor_visible` is ignored on iOS") debug!("`Window::set_cursor_visible` is ignored on iOS")
} }
pub fn drag_window(&self) -> Result<(), ExternalError> { pub fn drag_window(&self) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("drag_window is not supported"))
} }
pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, _direction: ResizeDirection) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("drag_resize_window is not supported"))
} }
#[inline] #[inline]
pub fn show_window_menu(&self, _position: Position) {} pub fn show_window_menu(&self, _position: Position) {}
pub fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), ExternalError> { pub fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), NotSupportedError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_hittest is not supported"))
} }
pub fn set_minimized(&self, _minimized: bool) { pub fn set_minimized(&self, _minimized: bool) {
@ -466,7 +466,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
window_attributes: WindowAttributes, window_attributes: WindowAttributes,
) -> Result<Window, RootOsError> { ) -> Result<Window, RequestError> {
let mtm = event_loop.mtm; let mtm = event_loop.mtm;
if window_attributes.min_surface_size.is_some() { if window_attributes.min_surface_size.is_some() {
@ -606,31 +606,27 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys()); self.maybe_wait_on_main(|delegate| delegate.reset_dead_keys());
} }
fn inner_position( fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
&self, Ok(self.maybe_wait_on_main(|delegate| delegate.inner_position()))
) -> Result<dpi::PhysicalPosition<i32>, crate::error::NotSupportedError> {
self.maybe_wait_on_main(|delegate| delegate.inner_position())
} }
fn outer_position( fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
&self, Ok(self.maybe_wait_on_main(|delegate| delegate.outer_position()))
) -> Result<dpi::PhysicalPosition<i32>, crate::error::NotSupportedError> {
self.maybe_wait_on_main(|delegate| delegate.outer_position())
} }
fn set_outer_position(&self, position: Position) { fn set_outer_position(&self, position: Position) {
self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position)); self.maybe_wait_on_main(|delegate| delegate.set_outer_position(position));
} }
fn surface_size(&self) -> dpi::PhysicalSize<u32> { fn surface_size(&self) -> PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.surface_size()) self.maybe_wait_on_main(|delegate| delegate.surface_size())
} }
fn request_surface_size(&self, size: Size) -> Option<dpi::PhysicalSize<u32>> { fn request_surface_size(&self, size: Size) -> Option<PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size)) self.maybe_wait_on_main(|delegate| delegate.request_surface_size(size))
} }
fn outer_size(&self) -> dpi::PhysicalSize<u32> { fn outer_size(&self) -> PhysicalSize<u32> {
self.maybe_wait_on_main(|delegate| delegate.outer_size()) self.maybe_wait_on_main(|delegate| delegate.outer_size())
} }
@ -642,7 +638,7 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size)); self.maybe_wait_on_main(|delegate| delegate.set_max_surface_size(max_size));
} }
fn surface_resize_increments(&self) -> Option<dpi::PhysicalSize<u32>> { fn surface_resize_increments(&self) -> Option<PhysicalSize<u32>> {
self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments()) self.maybe_wait_on_main(|delegate| delegate.surface_resize_increments())
} }
@ -770,38 +766,35 @@ impl CoreWindow for Window {
self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor)); self.maybe_wait_on_main(|delegate| delegate.set_cursor(cursor));
} }
fn set_cursor_position(&self, position: Position) -> Result<(), crate::error::ExternalError> { fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position)) Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_position(position))?)
} }
fn set_cursor_grab( fn set_cursor_grab(&self, mode: crate::window::CursorGrabMode) -> Result<(), RequestError> {
&self, Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode))?)
mode: crate::window::CursorGrabMode,
) -> Result<(), crate::error::ExternalError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_grab(mode))
} }
fn set_cursor_visible(&self, visible: bool) { fn set_cursor_visible(&self, visible: bool) {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible)) self.maybe_wait_on_main(|delegate| delegate.set_cursor_visible(visible))
} }
fn drag_window(&self) -> Result<(), crate::error::ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.drag_window()) Ok(self.maybe_wait_on_main(|delegate| delegate.drag_window())?)
} }
fn drag_resize_window( fn drag_resize_window(
&self, &self,
direction: crate::window::ResizeDirection, direction: crate::window::ResizeDirection,
) -> Result<(), crate::error::ExternalError> { ) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.drag_resize_window(direction)) Ok(self.maybe_wait_on_main(|delegate| delegate.drag_resize_window(direction))?)
} }
fn show_window_menu(&self, position: Position) { fn show_window_menu(&self, position: Position) {
self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position)) self.maybe_wait_on_main(|delegate| delegate.show_window_menu(position))
} }
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), crate::error::ExternalError> { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest)) Ok(self.maybe_wait_on_main(|delegate| delegate.set_cursor_hittest(hittest))?)
} }
fn current_monitor(&self) -> Option<CoreMonitorHandle> { fn current_monitor(&self) -> Option<CoreMonitorHandle> {

View file

@ -3,25 +3,24 @@
#[cfg(all(not(x11_platform), not(wayland_platform)))] #[cfg(all(not(x11_platform), not(wayland_platform)))]
compile_error!("Please select a feature to build for unix: `x11`, `wayland`"); compile_error!("Please select a feature to build for unix: `x11`, `wayland`");
use std::env;
use std::num::{NonZeroU16, NonZeroU32}; use std::num::{NonZeroU16, NonZeroU32};
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd}; use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, RawFd};
use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use std::{env, fmt};
#[cfg(x11_platform)] #[cfg(x11_platform)]
use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Mutex}; use std::{ffi::CStr, mem::MaybeUninit, os::raw::*, sync::Arc, sync::Mutex};
use smol_str::SmolStr; use smol_str::SmolStr;
pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey}; pub(crate) use self::common::xkb::{physicalkey_to_scancode, scancode_to_physicalkey};
#[cfg(x11_platform)] #[cfg(x11_platform)]
use self::x11::{X11Error, XConnection, XError, XNotSupported}; use self::x11::{XConnection, XError, XNotSupported};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource; pub(crate) use crate::cursor::OnlyCursorImageSource as PlatformCustomCursorSource;
#[cfg(x11_platform)] #[cfg(x11_platform)]
use crate::dpi::Size; use crate::dpi::Size;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::error::EventLoopError; use crate::error::{EventLoopError, NotSupportedError};
use crate::event_loop::ActiveEventLoop; use crate::event_loop::ActiveEventLoop;
pub(crate) use crate::icon::RgbaIcon as PlatformIcon; pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
use crate::keyboard::Key; use crate::keyboard::Key;
@ -108,31 +107,6 @@ impl Default for PlatformSpecificWindowAttributes {
pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> = pub(crate) static X11_BACKEND: Lazy<Mutex<Result<Arc<XConnection>, XNotSupported>>> =
Lazy::new(|| Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new))); Lazy::new(|| Mutex::new(XConnection::new(Some(x_error_callback)).map(Arc::new)));
#[derive(Debug, Clone)]
pub enum OsError {
Misc(&'static str),
#[cfg(x11_platform)]
XNotSupported(XNotSupported),
#[cfg(x11_platform)]
XError(Arc<X11Error>),
#[cfg(wayland_platform)]
WaylandError(Arc<wayland::WaylandError>),
}
impl fmt::Display for OsError {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match *self {
OsError::Misc(e) => _f.pad(e),
#[cfg(x11_platform)]
OsError::XNotSupported(ref e) => fmt::Display::fmt(e, _f),
#[cfg(x11_platform)]
OsError::XError(ref e) => fmt::Display::fmt(e, _f),
#[cfg(wayland_platform)]
OsError::WaylandError(ref e) => fmt::Display::fmt(e, _f),
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(u64); pub struct WindowId(u64);
@ -411,7 +385,7 @@ impl EventLoop {
} else { } else {
"neither WAYLAND_DISPLAY nor WAYLAND_SOCKET nor DISPLAY is set." "neither WAYLAND_DISPLAY nor WAYLAND_SOCKET nor DISPLAY is set."
}; };
return Err(EventLoopError::Os(os_error!(OsError::Misc(msg)))); return Err(NotSupportedError::new(msg).into());
}, },
}; };
@ -433,9 +407,7 @@ impl EventLoop {
fn new_x11_any_thread() -> Result<EventLoop, EventLoopError> { fn new_x11_any_thread() -> Result<EventLoop, EventLoopError> {
let xconn = match X11_BACKEND.lock().unwrap_or_else(|e| e.into_inner()).as_ref() { let xconn = match X11_BACKEND.lock().unwrap_or_else(|e| e.into_inner()).as_ref() {
Ok(xconn) => xconn.clone(), Ok(xconn) => xconn.clone(),
Err(err) => { Err(err) => return Err(os_error!(err.clone()).into()),
return Err(EventLoopError::Os(os_error!(OsError::XNotSupported(err.clone()))))
},
}; };
Ok(EventLoop::X(x11::EventLoop::new(xconn))) Ok(EventLoop::X(x11::EventLoop::new(xconn)))

View file

@ -8,19 +8,18 @@ use std::sync::atomic::Ordering;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use sctk::reexports::calloop::Error as CalloopError;
use sctk::reexports::calloop_wayland_source::WaylandSource; use sctk::reexports::calloop_wayland_source::WaylandSource;
use sctk::reexports::client::{globals, Connection, QueueHandle}; use sctk::reexports::client::{globals, Connection, QueueHandle};
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::cursor::OnlyCursorImage; use crate::cursor::OnlyCursorImage;
use crate::dpi::LogicalSize; use crate::dpi::LogicalSize;
use crate::error::{EventLoopError, ExternalError, OsError as RootOsError}; use crate::error::{EventLoopError, OsError, RequestError};
use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent}; use crate::event::{Event, StartCause, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::event_loop::{ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents};
use crate::platform::pump_events::PumpStatus; use crate::platform::pump_events::PumpStatus;
use crate::platform_impl::platform::min_timeout; use crate::platform_impl::platform::min_timeout;
use crate::platform_impl::{OsError, PlatformCustomCursor}; use crate::platform_impl::PlatformCustomCursor;
use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme}; use crate::window::{CustomCursor as RootCustomCursor, CustomCursorSource, Theme};
mod proxy; mod proxy;
@ -31,7 +30,7 @@ use sink::EventSink;
use super::state::{WindowCompositorUpdate, WinitState}; use super::state::{WindowCompositorUpdate, WinitState};
use super::window::state::FrameCallbackState; use super::window::state::FrameCallbackState;
use super::{logical_to_physical_rounded, DeviceId, WaylandError, WindowId}; use super::{logical_to_physical_rounded, DeviceId, WindowId};
type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>, WinitState>; type WaylandDispatcher = calloop::Dispatcher<'static, WaylandSource<WinitState>, WinitState>;
@ -61,27 +60,20 @@ pub struct EventLoop {
impl EventLoop { impl EventLoop {
pub fn new() -> Result<EventLoop, EventLoopError> { pub fn new() -> Result<EventLoop, EventLoopError> {
macro_rules! map_err { let connection = Connection::connect_to_env().map_err(|err| os_error!(err))?;
($e:expr, $err:expr) => {
$e.map_err(|error| os_error!($err(error).into()))
};
}
let connection = map_err!(Connection::connect_to_env(), WaylandError::Connection)?;
let (globals, mut event_queue) = let (globals, mut event_queue) =
map_err!(globals::registry_queue_init(&connection), WaylandError::Global)?; globals::registry_queue_init(&connection).map_err(|err| os_error!(err))?;
let queue_handle = event_queue.handle(); let queue_handle = event_queue.handle();
let event_loop = let event_loop =
map_err!(calloop::EventLoop::<WinitState>::try_new(), WaylandError::Calloop)?; calloop::EventLoop::<WinitState>::try_new().map_err(|err| os_error!(err))?;
let mut winit_state = WinitState::new(&globals, &queue_handle, event_loop.handle()) let mut winit_state = WinitState::new(&globals, &queue_handle, event_loop.handle())?;
.map_err(|error| os_error!(error))?;
// NOTE: do a roundtrip after binding the globals to prevent potential // NOTE: do a roundtrip after binding the globals to prevent potential
// races with the server. // races with the server.
map_err!(event_queue.roundtrip(&mut winit_state), WaylandError::Dispatch)?; event_queue.roundtrip(&mut winit_state).map_err(|err| os_error!(err))?;
// Register Wayland source. // Register Wayland source.
let wayland_source = WaylandSource::new(connection.clone(), event_queue); let wayland_source = WaylandSource::new(connection.clone(), event_queue);
@ -97,37 +89,32 @@ impl EventLoop {
result result
}); });
map_err!( event_loop
event_loop.handle().register_dispatcher(wayland_dispatcher.clone()), .handle()
WaylandError::Calloop .register_dispatcher(wayland_dispatcher.clone())
)?; .map_err(|err| os_error!(err))?;
// Setup the user proxy. // Setup the user proxy.
let (ping, ping_source) = calloop::ping::make_ping().unwrap(); let (ping, ping_source) = calloop::ping::make_ping().unwrap();
let result = event_loop event_loop
.handle() .handle()
.insert_source(ping_source, move |_, _, winit_state: &mut WinitState| { .insert_source(ping_source, move |_, _, winit_state: &mut WinitState| {
winit_state.dispatched_events = true; winit_state.dispatched_events = true;
winit_state.proxy_wake_up = true; winit_state.proxy_wake_up = true;
}) })
.map_err(|error| error.error); .map_err(|err| os_error!(err))?;
map_err!(result, WaylandError::Calloop)?;
// An event's loop awakener to wake up for window events from winit's windows. // An event's loop awakener to wake up for window events from winit's windows.
let (event_loop_awakener, event_loop_awakener_source) = map_err!( let (event_loop_awakener, event_loop_awakener_source) =
calloop::ping::make_ping() calloop::ping::make_ping().map_err(|err| os_error!(err))?;
.map_err(|error| CalloopError::OtherError(Box::new(error).into())),
WaylandError::Calloop
)?;
let result = event_loop event_loop
.handle() .handle()
.insert_source(event_loop_awakener_source, move |_, _, winit_state: &mut WinitState| { .insert_source(event_loop_awakener_source, move |_, _, winit_state: &mut WinitState| {
// Mark that we have something to dispatch. // Mark that we have something to dispatch.
winit_state.dispatched_events = true; winit_state.dispatched_events = true;
}) })
.map_err(|error| error.error); .map_err(|err| os_error!(err))?;
map_err!(result, WaylandError::Calloop)?;
let active_event_loop = ActiveEventLoop { let active_event_loop = ActiveEventLoop {
connection: connection.clone(), connection: connection.clone(),
@ -517,14 +504,12 @@ impl EventLoop {
}) })
} }
fn roundtrip(&mut self) -> Result<usize, RootOsError> { fn roundtrip(&mut self) -> Result<usize, OsError> {
let state = &mut self.active_event_loop.state.get_mut(); let state = &mut self.active_event_loop.state.get_mut();
let mut wayland_source = self.wayland_dispatcher.as_source_mut(); let mut wayland_source = self.wayland_dispatcher.as_source_mut();
let event_queue = wayland_source.queue(); let event_queue = wayland_source.queue();
event_queue.roundtrip(state).map_err(|error| { event_queue.roundtrip(state).map_err(|err| os_error!(err))
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(error))))
})
} }
fn control_flow(&self) -> ControlFlow { fn control_flow(&self) -> ControlFlow {
@ -614,7 +599,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
cursor: CustomCursorSource, cursor: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Ok(RootCustomCursor { Ok(RootCustomCursor {
inner: PlatformCustomCursor::Wayland(OnlyCursorImage(Arc::from(cursor.inner.0))), inner: PlatformCustomCursor::Wayland(OnlyCursorImage(Arc::from(cursor.inner.0))),
}) })
@ -628,7 +613,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: crate::window::WindowAttributes, window_attributes: crate::window::WindowAttributes,
) -> Result<Box<dyn crate::window::Window>, RootOsError> { ) -> Result<Box<dyn crate::window::Window>, RequestError> {
let window = crate::platform_impl::wayland::Window::new(self, window_attributes)?; let window = crate::platform_impl::wayland::Window::new(self, window_attributes)?;
Ok(Box::new(window)) Ok(Box::new(window))
} }

View file

@ -1,18 +1,14 @@
//! Winit's Wayland backend. //! Winit's Wayland backend.
use std::fmt::Display;
use std::sync::Arc;
pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy}; pub use event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy};
pub use output::{MonitorHandle, VideoModeHandle}; pub use output::{MonitorHandle, VideoModeHandle};
use sctk::reexports::client::globals::{BindError, GlobalError};
use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::protocol::wl_surface::WlSurface;
use sctk::reexports::client::{self, ConnectError, DispatchError, Proxy}; use sctk::reexports::client::Proxy;
pub use window::Window; pub use window::Window;
pub(super) use crate::cursor::OnlyCursorImage as CustomCursor; pub(super) use crate::cursor::OnlyCursorImage as CustomCursor;
use crate::dpi::{LogicalSize, PhysicalSize}; use crate::dpi::{LogicalSize, PhysicalSize};
pub use crate::platform_impl::platform::{OsError, WindowId}; pub use crate::platform_impl::platform::WindowId;
mod event_loop; mod event_loop;
mod output; mod output;
@ -21,46 +17,6 @@ mod state;
mod types; mod types;
mod window; mod window;
#[derive(Debug)]
pub enum WaylandError {
/// Error connecting to the socket.
Connection(ConnectError),
/// Error binding the global.
Global(GlobalError),
// Bind error.
Bind(BindError),
/// Error during the dispatching the event queue.
Dispatch(DispatchError),
/// Calloop error.
Calloop(calloop::Error),
/// Wayland
Wire(client::backend::WaylandError),
}
impl Display for WaylandError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WaylandError::Connection(error) => error.fmt(f),
WaylandError::Global(error) => error.fmt(f),
WaylandError::Bind(error) => error.fmt(f),
WaylandError::Dispatch(error) => error.fmt(f),
WaylandError::Calloop(error) => error.fmt(f),
WaylandError::Wire(error) => error.fmt(f),
}
}
}
impl From<WaylandError> for OsError {
fn from(value: WaylandError) -> Self {
Self::WaylandError(Arc::new(value))
}
}
/// Dummy device id, since Wayland doesn't have device events. /// Dummy device id, since Wayland doesn't have device events.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; pub struct DeviceId;

View file

@ -21,6 +21,7 @@ use sctk::shm::slot::SlotPool;
use sctk::shm::{Shm, ShmHandler}; use sctk::shm::{Shm, ShmHandler};
use sctk::subcompositor::SubcompositorState; use sctk::subcompositor::SubcompositorState;
use crate::error::OsError;
use crate::platform_impl::wayland::event_loop::sink::EventSink; use crate::platform_impl::wayland::event_loop::sink::EventSink;
use crate::platform_impl::wayland::output::MonitorHandle; use crate::platform_impl::wayland::output::MonitorHandle;
use crate::platform_impl::wayland::seat::{ use crate::platform_impl::wayland::seat::{
@ -32,8 +33,7 @@ use crate::platform_impl::wayland::types::wp_fractional_scaling::FractionalScali
use crate::platform_impl::wayland::types::wp_viewporter::ViewporterState; use crate::platform_impl::wayland::types::wp_viewporter::ViewporterState;
use crate::platform_impl::wayland::types::xdg_activation::XdgActivationState; use crate::platform_impl::wayland::types::xdg_activation::XdgActivationState;
use crate::platform_impl::wayland::window::{WindowRequests, WindowState}; use crate::platform_impl::wayland::window::{WindowRequests, WindowState};
use crate::platform_impl::wayland::{WaylandError, WindowId}; use crate::platform_impl::wayland::WindowId;
use crate::platform_impl::OsError;
/// Winit's Wayland state. /// Winit's Wayland state.
pub struct WinitState { pub struct WinitState {
@ -126,7 +126,7 @@ impl WinitState {
) -> Result<Self, OsError> { ) -> Result<Self, OsError> {
let registry_state = RegistryState::new(globals); let registry_state = RegistryState::new(globals);
let compositor_state = let compositor_state =
CompositorState::bind(globals, queue_handle).map_err(WaylandError::Bind)?; CompositorState::bind(globals, queue_handle).map_err(|err| os_error!(err))?;
let subcompositor_state = match SubcompositorState::bind( let subcompositor_state = match SubcompositorState::bind(
compositor_state.wl_compositor().clone(), compositor_state.wl_compositor().clone(),
globals, globals,
@ -156,7 +156,7 @@ impl WinitState {
(None, None) (None, None)
}; };
let shm = Shm::bind(globals, queue_handle).map_err(WaylandError::Bind)?; let shm = Shm::bind(globals, queue_handle).map_err(|err| os_error!(err))?;
let custom_cursor_pool = Arc::new(Mutex::new(SlotPool::new(2, &shm).unwrap())); let custom_cursor_pool = Arc::new(Mutex::new(SlotPool::new(2, &shm).unwrap()));
Ok(Self { Ok(Self {
@ -168,7 +168,7 @@ impl WinitState {
shm, shm,
custom_cursor_pool, custom_cursor_pool,
xdg_shell: XdgShell::bind(globals, queue_handle).map_err(WaylandError::Bind)?, xdg_shell: XdgShell::bind(globals, queue_handle).map_err(|err| os_error!(err))?,
xdg_activation: XdgActivationState::bind(globals, queue_handle).ok(), xdg_activation: XdgActivationState::bind(globals, queue_handle).ok(),
windows: Default::default(), windows: Default::default(),

View file

@ -16,13 +16,13 @@ use super::event_loop::sink::EventSink;
use super::output::MonitorHandle; use super::output::MonitorHandle;
use super::state::WinitState; use super::state::WinitState;
use super::types::xdg_activation::XdgActivationTokenData; use super::types::xdg_activation::XdgActivationTokenData;
use super::{ActiveEventLoop, WaylandError, WindowId}; use super::{ActiveEventLoop, WindowId};
use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{LogicalSize, PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{NotSupportedError, RequestError};
use crate::event::{Ime, WindowEvent}; use crate::event::{Ime, WindowEvent};
use crate::event_loop::AsyncRequestSerial; use crate::event_loop::AsyncRequestSerial;
use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError}; use crate::platform_impl::{Fullscreen, MonitorHandle as PlatformMonitorHandle};
use crate::window::{ use crate::window::{
Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme, Cursor, CursorGrabMode, Fullscreen as CoreFullscreen, ImePurpose, ResizeDirection, Theme,
UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons, UserAttentionType, Window as CoreWindow, WindowAttributes, WindowButtons,
@ -77,7 +77,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
event_loop_window_target: &ActiveEventLoop, event_loop_window_target: &ActiveEventLoop,
attributes: WindowAttributes, attributes: WindowAttributes,
) -> Result<Self, RootOsError> { ) -> Result<Self, RequestError> {
let queue_handle = event_loop_window_target.queue_handle.clone(); let queue_handle = event_loop_window_target.queue_handle.clone();
let mut state = event_loop_window_target.state.borrow_mut(); let mut state = event_loop_window_target.state.borrow_mut();
@ -190,15 +190,11 @@ impl Window {
let event_queue = wayland_source.queue(); let event_queue = wayland_source.queue();
// Do a roundtrip. // Do a roundtrip.
event_queue.roundtrip(&mut state).map_err(|error| { event_queue.roundtrip(&mut state).map_err(|err| os_error!(err))?;
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(error))))
})?;
// XXX Wait for the initial configure to arrive. // XXX Wait for the initial configure to arrive.
while !window_state.lock().unwrap().is_configured() { while !window_state.lock().unwrap().is_configured() {
event_queue.blocking_dispatch(&mut state).map_err(|error| { event_queue.blocking_dispatch(&mut state).map_err(|err| os_error!(err))?;
os_error!(OsError::WaylandError(Arc::new(WaylandError::Dispatch(error))))
})?;
} }
// Wake-up event loop, so it'll send initial redraw requested. // Wake-up event loop, so it'll send initial redraw requested.
@ -223,10 +219,10 @@ impl Window {
} }
impl Window { impl Window {
pub fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError> { pub fn request_activation_token(&self) -> Result<AsyncRequestSerial, RequestError> {
let xdg_activation = match self.xdg_activation.as_ref() { let xdg_activation = match self.xdg_activation.as_ref() {
Some(xdg_activation) => xdg_activation, Some(xdg_activation) => xdg_activation,
None => return Err(NotSupportedError::new()), None => return Err(NotSupportedError::new("xdg_activation_v1 is not available").into()),
}; };
let serial = AsyncRequestSerial::get(); let serial = AsyncRequestSerial::get();
@ -309,12 +305,14 @@ impl CoreWindow for Window {
crate::platform_impl::common::xkb::reset_dead_keys() crate::platform_impl::common::xkb::reset_dead_keys()
} }
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Err(NotSupportedError::new()) Err(NotSupportedError::new("window position information is not available on Wayland")
.into())
} }
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Err(NotSupportedError::new()) Err(NotSupportedError::new("window position information is not available on Wayland")
.into())
} }
fn set_outer_position(&self, _position: Position) { fn set_outer_position(&self, _position: Position) {
@ -576,7 +574,7 @@ impl CoreWindow for Window {
} }
} }
fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> { fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let position = position.to_logical(scale_factor); let position = position.to_logical(scale_factor);
self.window_state self.window_state
@ -587,7 +585,7 @@ impl CoreWindow for Window {
.map(|_| self.request_redraw()) .map(|_| self.request_redraw())
} }
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
self.window_state.lock().unwrap().set_cursor_grab(mode) self.window_state.lock().unwrap().set_cursor_grab(mode)
} }
@ -595,11 +593,11 @@ impl CoreWindow for Window {
self.window_state.lock().unwrap().set_cursor_visible(visible); self.window_state.lock().unwrap().set_cursor_visible(visible);
} }
fn drag_window(&self) -> Result<(), ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
self.window_state.lock().unwrap().drag_window() self.window_state.lock().unwrap().drag_window()
} }
fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
self.window_state.lock().unwrap().drag_resize_window(direction) self.window_state.lock().unwrap().drag_resize_window(direction)
} }
@ -609,16 +607,14 @@ impl CoreWindow for Window {
self.window_state.lock().unwrap().show_window_menu(position); self.window_state.lock().unwrap().show_window_menu(position);
} }
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
let surface = self.window.wl_surface(); let surface = self.window.wl_surface();
if hittest { if hittest {
surface.set_input_region(None); surface.set_input_region(None);
Ok(()) Ok(())
} else { } else {
let region = Region::new(&*self.compositor).map_err(|_| { let region = Region::new(&*self.compositor).map_err(|err| os_error!(err))?;
ExternalError::Os(os_error!(OsError::Misc("failed to set input region.")))
})?;
region.add(0, 0, 0, 0); region.add(0, 0, 0, 0);
surface.set_input_region(Some(region.wl_region())); surface.set_input_region(Some(region.wl_region()));
Ok(()) Ok(())

View file

@ -30,7 +30,7 @@ use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur;
use crate::cursor::CustomCursor as RootCustomCursor; use crate::cursor::CustomCursor as RootCustomCursor;
use crate::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size}; use crate::dpi::{LogicalPosition, LogicalSize, PhysicalSize, Size};
use crate::error::{ExternalError, NotSupportedError}; use crate::error::{NotSupportedError, RequestError};
use crate::platform_impl::wayland::logical_to_physical_rounded; use crate::platform_impl::wayland::logical_to_physical_rounded;
use crate::platform_impl::wayland::seat::{ use crate::platform_impl::wayland::seat::{
PointerConstraintsState, WinitPointerData, WinitPointerDataExt, ZwpTextInputV3Ext, PointerConstraintsState, WinitPointerData, WinitPointerDataExt, ZwpTextInputV3Ext,
@ -388,7 +388,7 @@ impl WindowState {
} }
/// Start interacting drag resize. /// Start interacting drag resize.
pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
let xdg_toplevel = self.window.xdg_toplevel(); let xdg_toplevel = self.window.xdg_toplevel();
// TODO(kchibisov) handle touch serials. // TODO(kchibisov) handle touch serials.
@ -402,7 +402,7 @@ impl WindowState {
} }
/// Start the window drag. /// Start the window drag.
pub fn drag_window(&self) -> Result<(), ExternalError> { pub fn drag_window(&self) -> Result<(), RequestError> {
let xdg_toplevel = self.window.xdg_toplevel(); let xdg_toplevel = self.window.xdg_toplevel();
// TODO(kchibisov) handle touch serials. // TODO(kchibisov) handle touch serials.
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {
@ -799,7 +799,7 @@ impl WindowState {
} }
/// Set the cursor grabbing state on the top-level. /// Set the cursor grabbing state on the top-level.
pub fn set_cursor_grab(&mut self, mode: CursorGrabMode) -> Result<(), ExternalError> { pub fn set_cursor_grab(&mut self, mode: CursorGrabMode) -> Result<(), RequestError> {
if self.cursor_grab_mode.user_grab_mode == mode { if self.cursor_grab_mode.user_grab_mode == mode {
return Ok(()); return Ok(());
} }
@ -817,11 +817,15 @@ impl WindowState {
} }
/// Set the grabbing state on the surface. /// Set the grabbing state on the surface.
fn set_cursor_grab_inner(&mut self, mode: CursorGrabMode) -> Result<(), ExternalError> { fn set_cursor_grab_inner(&mut self, mode: CursorGrabMode) -> Result<(), RequestError> {
let pointer_constraints = match self.pointer_constraints.as_ref() { let pointer_constraints = match self.pointer_constraints.as_ref() {
Some(pointer_constraints) => pointer_constraints, Some(pointer_constraints) => pointer_constraints,
None if mode == CursorGrabMode::None => return Ok(()), None if mode == CursorGrabMode::None => return Ok(()),
None => return Err(ExternalError::NotSupported(NotSupportedError::new())), None => {
return Err(
NotSupportedError::new("zwp_pointer_constraints is not available").into()
)
},
}; };
// Replace the current mode. // Replace the current mode.
@ -865,16 +869,17 @@ impl WindowState {
} }
/// Set the position of the cursor. /// Set the position of the cursor.
pub fn set_cursor_position(&self, position: LogicalPosition<f64>) -> Result<(), ExternalError> { pub fn set_cursor_position(&self, position: LogicalPosition<f64>) -> Result<(), RequestError> {
if self.pointer_constraints.is_none() { if self.pointer_constraints.is_none() {
return Err(ExternalError::NotSupported(NotSupportedError::new())); return Err(NotSupportedError::new("zwp_pointer_constraints is not available").into());
} }
// Position can be set only for locked cursor. // Position can be set only for locked cursor.
if self.cursor_grab_mode.current_grab_mode != CursorGrabMode::Locked { if self.cursor_grab_mode.current_grab_mode != CursorGrabMode::Locked {
return Err(ExternalError::Os(os_error!(crate::platform_impl::OsError::Misc( return Err(NotSupportedError::new(
"cursor position can be set only for locked cursor." "cursor position could only be changed for locked pointer",
)))); )
.into());
} }
self.apply_on_pointer(|_, data| { self.apply_on_pointer(|_, data| {

View file

@ -1,7 +1,8 @@
use std::error::Error;
use std::ffi::CStr; use std::ffi::CStr;
use std::os::raw::c_short; use std::os::raw::c_short;
use std::sync::Arc; use std::sync::Arc;
use std::{mem, ptr}; use std::{fmt, mem, ptr};
use x11_dl::xlib::{XIMCallback, XIMPreeditCaretCallbackStruct, XIMPreeditDrawCallbackStruct}; use x11_dl::xlib::{XIMCallback, XIMPreeditCaretCallbackStruct, XIMPreeditDrawCallbackStruct};
@ -19,6 +20,19 @@ pub enum ImeContextCreationError {
Null, Null,
} }
impl fmt::Display for ImeContextCreationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ImeContextCreationError::XError(err) => err.fmt(f),
ImeContextCreationError::Null => {
write!(f, "got null pointer from Xlib without exact reason")
},
}
}
}
impl Error for ImeContextCreationError {}
/// The callback used by XIM preedit functions. /// The callback used by XIM preedit functions.
type XIMProcNonnull = unsafe extern "C" fn(ffi::XIM, ffi::XPointer, ffi::XPointer); type XIMProcNonnull = unsafe extern "C" fn(ffi::XIM, ffi::XPointer, ffi::XPointer);

View file

@ -23,7 +23,7 @@ use x11rb::x11_utils::X11Error as LogicalError;
use x11rb::xcb_ffi::ReplyOrIdError; use x11rb::xcb_ffi::ReplyOrIdError;
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, ExternalError, OsError as RootOsError}; use crate::error::{EventLoopError, RequestError};
use crate::event::{Event, StartCause, WindowEvent}; use crate::event::{Event, StartCause, WindowEvent};
use crate::event_loop::{ use crate::event_loop::{
ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents,
@ -33,7 +33,7 @@ use crate::platform::pump_events::PumpStatus;
use crate::platform_impl::common::xkb::Context; use crate::platform_impl::common::xkb::Context;
use crate::platform_impl::platform::{min_timeout, WindowId}; use crate::platform_impl::platform::{min_timeout, WindowId};
use crate::platform_impl::x11::window::Window; use crate::platform_impl::x11::window::Window;
use crate::platform_impl::{OsError, OwnedDisplayHandle, PlatformCustomCursor}; use crate::platform_impl::{OwnedDisplayHandle, PlatformCustomCursor};
use crate::window::{ use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow, CustomCursor as RootCustomCursor, CustomCursorSource, Theme, Window as CoreWindow,
WindowAttributes, WindowAttributes,
@ -399,9 +399,11 @@ impl EventLoop {
// `run_on_demand` calls but if they have only just dropped their // `run_on_demand` calls but if they have only just dropped their
// windows we need to make sure those last requests are sent to the // windows we need to make sure those last requests are sent to the
// X Server. // X Server.
self.event_processor.target.x_connection().sync_with_server().map_err(|x_err| { self.event_processor
EventLoopError::Os(os_error!(OsError::XError(Arc::new(X11Error::Xlib(x_err))))) .target
})?; .x_connection()
.sync_with_server()
.map_err(|x_err| EventLoopError::Os(os_error!(X11Error::Xlib(x_err))))?;
exit exit
} }
@ -688,14 +690,14 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: WindowAttributes, window_attributes: WindowAttributes,
) -> Result<Box<dyn CoreWindow>, RootOsError> { ) -> Result<Box<dyn CoreWindow>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
custom_cursor: CustomCursorSource, custom_cursor: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Ok(RootCustomCursor { Ok(RootCustomCursor {
inner: PlatformCustomCursor::X(CustomCursor::new(self, custom_cursor.inner)?), inner: PlatformCustomCursor::X(CustomCursor::new(self, custom_cursor.inner)?),
}) })

View file

@ -9,8 +9,8 @@ use x11rb::protocol::xproto;
use super::super::ActiveEventLoop; use super::super::ActiveEventLoop;
use super::*; use super::*;
use crate::error::ExternalError; use crate::error::RequestError;
use crate::platform_impl::{OsError, PlatformCustomCursorSource}; use crate::platform_impl::PlatformCustomCursorSource;
use crate::window::CursorIcon; use crate::window::CursorIcon;
impl XConnection { impl XConnection {
@ -193,7 +193,7 @@ impl CustomCursor {
pub(crate) fn new( pub(crate) fn new(
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
mut cursor: PlatformCustomCursorSource, mut cursor: PlatformCustomCursorSource,
) -> Result<CustomCursor, ExternalError> { ) -> Result<CustomCursor, RequestError> {
// Reverse RGBA order to BGRA. // Reverse RGBA order to BGRA.
cursor.0.rgba.chunks_mut(4).for_each(|chunk| { cursor.0.rgba.chunks_mut(4).for_each(|chunk| {
let chunk: &mut [u8; 4] = chunk.try_into().unwrap(); let chunk: &mut [u8; 4] = chunk.try_into().unwrap();
@ -215,7 +215,7 @@ impl CustomCursor {
cursor.0.hotspot_y, cursor.0.hotspot_y,
&cursor.0.rgba, &cursor.0.rgba,
) )
.map_err(|err| ExternalError::Os(os_error!(OsError::XError(err.into()))))?; .map_err(|err| os_error!(err))?;
Ok(Self { inner: Arc::new(CustomCursorInner { xconn: event_loop.xconn.clone(), cursor }) }) Ok(Self { inner: Arc::new(CustomCursorInner { xconn: event_loop.xconn.clone(), cursor }) })
} }

View file

@ -22,7 +22,7 @@ use super::{
}; };
use crate::cursor::{Cursor, CustomCursor as RootCustomCursor}; use crate::cursor::{Cursor, CustomCursor as RootCustomCursor};
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{NotSupportedError, RequestError};
use crate::event::{Event, SurfaceSizeWriter, WindowEvent}; use crate::event::{Event, SurfaceSizeWriter, WindowEvent};
use crate::event_loop::AsyncRequestSerial; use crate::event_loop::AsyncRequestSerial;
use crate::platform::x11::WindowType; use crate::platform::x11::WindowType;
@ -31,8 +31,8 @@ use crate::platform_impl::x11::{
xinput_fp1616_to_float, MonitorHandle as X11MonitorHandle, WakeSender, X11Error, xinput_fp1616_to_float, MonitorHandle as X11MonitorHandle, WakeSender, X11Error,
}; };
use crate::platform_impl::{ use crate::platform_impl::{
common, Fullscreen, MonitorHandle as PlatformMonitorHandle, OsError, PlatformCustomCursor, common, Fullscreen, MonitorHandle as PlatformMonitorHandle, PlatformCustomCursor, PlatformIcon,
PlatformIcon, VideoModeHandle as PlatformVideoModeHandle, VideoModeHandle as PlatformVideoModeHandle,
}; };
use crate::window::{ use crate::window::{
CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow, CursorGrabMode, ImePurpose, ResizeDirection, Theme, UserAttentionType, Window as CoreWindow,
@ -54,7 +54,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
attribs: WindowAttributes, attribs: WindowAttributes,
) -> Result<Self, RootOsError> { ) -> Result<Self, RequestError> {
let window = Arc::new(UnownedWindow::new(event_loop, attribs)?); let window = Arc::new(UnownedWindow::new(event_loop, attribs)?);
event_loop.windows.borrow_mut().insert(window.id(), Arc::downgrade(&window)); event_loop.windows.borrow_mut().insert(window.id(), Arc::downgrade(&window));
Ok(Window(window)) Ok(Window(window))
@ -82,11 +82,11 @@ impl CoreWindow for Window {
common::xkb::reset_dead_keys(); common::xkb::reset_dead_keys();
} }
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
self.0.inner_position() self.0.inner_position()
} }
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
self.0.outer_position() self.0.outer_position()
} }
@ -242,11 +242,11 @@ impl CoreWindow for Window {
self.0.set_cursor(cursor); self.0.set_cursor(cursor);
} }
fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> { fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
self.0.set_cursor_position(position) self.0.set_cursor_position(position)
} }
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
self.0.set_cursor_grab(mode) self.0.set_cursor_grab(mode)
} }
@ -254,11 +254,11 @@ impl CoreWindow for Window {
self.0.set_cursor_visible(visible); self.0.set_cursor_visible(visible);
} }
fn drag_window(&self) -> Result<(), ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
self.0.drag_window() self.0.drag_window()
} }
fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
self.0.drag_resize_window(direction) self.0.drag_resize_window(direction)
} }
@ -266,7 +266,7 @@ impl CoreWindow for Window {
self.0.show_window_menu(position); self.0.show_window_menu(position);
} }
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
self.0.set_cursor_hittest(hittest) self.0.set_cursor_hittest(hittest)
} }
@ -427,13 +427,9 @@ pub struct UnownedWindow {
redraw_sender: WakeSender<WindowId>, redraw_sender: WakeSender<WindowId>,
activation_sender: WakeSender<super::ActivationToken>, activation_sender: WakeSender<super::ActivationToken>,
} }
macro_rules! leap { macro_rules! leap {
($e:expr) => { ($e:expr) => {
match $e { $e.map_err(|err| os_error!(err))?
Ok(x) => x,
Err(err) => return Err(os_error!(OsError::XError(X11Error::from(err).into()))),
}
}; };
} }
@ -442,7 +438,7 @@ impl UnownedWindow {
pub(crate) fn new( pub(crate) fn new(
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
window_attrs: WindowAttributes, window_attrs: WindowAttributes,
) -> Result<UnownedWindow, RootOsError> { ) -> Result<UnownedWindow, RequestError> {
let xconn = &event_loop.xconn; let xconn = &event_loop.xconn;
let atoms = xconn.atoms(); let atoms = xconn.atoms();
#[cfg(feature = "rwh_06")] #[cfg(feature = "rwh_06")]
@ -527,10 +523,9 @@ impl UnownedWindow {
match window_attrs.platform_specific.x11.visual_id { match window_attrs.platform_specific.x11.visual_id {
Some(vi) => { Some(vi) => {
// Find this specific visual. // Find this specific visual.
let (visualtype, depth) = let (visualtype, depth) = all_visuals
all_visuals.find(|(visual, _)| visual.visual_id == vi).ok_or_else( .find(|(visual, _)| visual.visual_id == vi)
|| os_error!(OsError::XError(X11Error::NoSuchVisual(vi).into())), .ok_or_else(|| os_error!(X11Error::NoSuchVisual(vi)))?;
)?;
(Some(visualtype), depth, true) (Some(visualtype), depth, true)
}, },
@ -828,7 +823,7 @@ impl UnownedWindow {
&mut supported_ptr, &mut supported_ptr,
); );
if supported_ptr == ffi::False { if supported_ptr == ffi::False {
return Err(os_error!(OsError::Misc("`XkbSetDetectableAutoRepeat` failed"))); return Err(os_error!("`XkbSetDetectableAutoRepeat` failed").into());
} }
} }
@ -848,14 +843,16 @@ impl UnownedWindow {
// Try to create input context for the window. // Try to create input context for the window.
if let Some(ime) = event_loop.ime.as_ref() { if let Some(ime) = event_loop.ime.as_ref() {
let result = ime.borrow_mut().create_context(window.xwindow as ffi::Window, false); ime.borrow_mut()
leap!(result); .create_context(window.xwindow as ffi::Window, false)
.map_err(|err| os_error!(err))?;
} }
// These properties must be set after mapping // These properties must be set after mapping
if window_attrs.maximized { if window_attrs.maximized {
leap!(window.set_maximized_inner(window_attrs.maximized)).ignore_error(); leap!(window.set_maximized_inner(window_attrs.maximized)).ignore_error();
} }
if window_attrs.fullscreen.is_some() { if window_attrs.fullscreen.is_some() {
if let Some(flusher) = if let Some(flusher) =
leap!(window leap!(window
@ -888,7 +885,7 @@ impl UnownedWindow {
} }
/// Embed this window into a parent window. /// Embed this window into a parent window.
pub(super) fn embed_window(&self) -> Result<(), RootOsError> { pub(super) fn embed_window(&self) -> Result<(), RequestError> {
let atoms = self.xconn.atoms(); let atoms = self.xconn.atoms();
leap!(leap!(self.xconn.change_property( leap!(leap!(self.xconn.change_property(
self.xwindow, self.xwindow,
@ -1500,7 +1497,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
let extents = self.shared_state_lock().frame_extents.clone(); let extents = self.shared_state_lock().frame_extents.clone();
if let Some(extents) = extents { if let Some(extents) = extents {
let (x, y) = self.inner_position_physical(); let (x, y) = self.inner_position_physical();
@ -1521,7 +1518,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { pub fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
Ok(self.inner_position_physical().into()) Ok(self.inner_position_physical().into())
} }
@ -1815,7 +1812,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { pub fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
let mut grabbed_lock = self.cursor_grabbed_mode.lock().unwrap(); let mut grabbed_lock = self.cursor_grabbed_mode.lock().unwrap();
if mode == *grabbed_lock { if mode == *grabbed_lock {
return Ok(()); return Ok(());
@ -1829,9 +1826,10 @@ impl UnownedWindow {
.expect_then_ignore_error("Failed to call `xcb_ungrab_pointer`"); .expect_then_ignore_error("Failed to call `xcb_ungrab_pointer`");
let result = match mode { let result = match mode {
CursorGrabMode::None => self.xconn.flush_requests().map_err(|err| { CursorGrabMode::None => self
ExternalError::Os(os_error!(OsError::XError(X11Error::Xlib(err).into()))) .xconn
}), .flush_requests()
.map_err(|err| RequestError::Os(os_error!(X11Error::Xlib(err)))),
CursorGrabMode::Confined => { CursorGrabMode::Confined => {
let result = { let result = {
self.xconn self.xconn
@ -1878,10 +1876,12 @@ impl UnownedWindow {
}, },
_ => unreachable!(), _ => unreachable!(),
} }
.map_err(|err| ExternalError::Os(os_error!(OsError::Misc(err)))) .map_err(|err| RequestError::Os(os_error!(err)))
}, },
CursorGrabMode::Locked => { CursorGrabMode::Locked => {
return Err(ExternalError::NotSupported(NotSupportedError::new())); return Err(
NotSupportedError::new("locked cursor is not implemented on X11").into()
);
}, },
}; };
@ -1923,28 +1923,23 @@ impl UnownedWindow {
self.shared_state_lock().last_monitor.scale_factor self.shared_state_lock().last_monitor.scale_factor
} }
pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), ExternalError> { pub fn set_cursor_position_physical(&self, x: i32, y: i32) -> Result<(), RequestError> {
{ self.xconn
self.xconn .xcb_connection()
.xcb_connection() .warp_pointer(x11rb::NONE, self.xwindow, 0, 0, 0, 0, x as _, y as _)
.warp_pointer(x11rb::NONE, self.xwindow, 0, 0, 0, 0, x as _, y as _) .map_err(|err| os_error!(X11Error::from(err)))?;
.map_err(|e| { self.xconn.flush_requests().map_err(|err| os_error!(X11Error::Xlib(err)))?;
ExternalError::Os(os_error!(OsError::XError(X11Error::from(e).into()))) Ok(())
})?;
self.xconn.flush_requests().map_err(|e| {
ExternalError::Os(os_error!(OsError::XError(X11Error::Xlib(e).into())))
})
}
} }
#[inline] #[inline]
pub fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> { pub fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
let (x, y) = position.to_physical::<i32>(self.scale_factor()).into(); let (x, y) = position.to_physical::<i32>(self.scale_factor()).into();
self.set_cursor_position_physical(x, y) self.set_cursor_position_physical(x, y)
} }
#[inline] #[inline]
pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { pub fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
let mut rectangles: Vec<Rectangle> = Vec::new(); let mut rectangles: Vec<Rectangle> = Vec::new();
if hittest { if hittest {
let size = self.surface_size(); let size = self.surface_size();
@ -1956,17 +1951,17 @@ impl UnownedWindow {
}) })
} }
let region = RegionWrapper::create_region(self.xconn.xcb_connection(), &rectangles) let region = RegionWrapper::create_region(self.xconn.xcb_connection(), &rectangles)
.map_err(|_e| ExternalError::Ignored)?; .map_err(|_e| RequestError::Ignored)?;
self.xconn self.xconn
.xcb_connection() .xcb_connection()
.xfixes_set_window_shape_region(self.xwindow, SK::INPUT, 0, 0, region.region()) .xfixes_set_window_shape_region(self.xwindow, SK::INPUT, 0, 0, region.region())
.map_err(|_e| ExternalError::Ignored)?; .map_err(|_e| RequestError::Ignored)?;
self.shared_state_lock().cursor_hittest = Some(hittest); self.shared_state_lock().cursor_hittest = Some(hittest);
Ok(()) Ok(())
} }
/// Moves the window while it is being dragged. /// Moves the window while it is being dragged.
pub fn drag_window(&self) -> Result<(), ExternalError> { pub fn drag_window(&self) -> Result<(), RequestError> {
self.drag_initiate(util::MOVERESIZE_MOVE) self.drag_initiate(util::MOVERESIZE_MOVE)
} }
@ -1974,7 +1969,7 @@ impl UnownedWindow {
pub fn show_window_menu(&self, _position: Position) {} pub fn show_window_menu(&self, _position: Position) {}
/// Resizes the window while it is being dragged. /// Resizes the window while it is being dragged.
pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { pub fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
self.drag_initiate(match direction { self.drag_initiate(match direction {
ResizeDirection::East => util::MOVERESIZE_RIGHT, ResizeDirection::East => util::MOVERESIZE_RIGHT,
ResizeDirection::North => util::MOVERESIZE_TOP, ResizeDirection::North => util::MOVERESIZE_TOP,
@ -1988,13 +1983,13 @@ impl UnownedWindow {
} }
/// Initiates a drag operation while the left mouse button is pressed. /// Initiates a drag operation while the left mouse button is pressed.
fn drag_initiate(&self, action: isize) -> Result<(), ExternalError> { fn drag_initiate(&self, action: isize) -> Result<(), RequestError> {
let pointer = self let pointer = self
.xconn .xconn
.query_pointer(self.xwindow, util::VIRTUAL_CORE_POINTER) .query_pointer(self.xwindow, util::VIRTUAL_CORE_POINTER)
.map_err(|err| ExternalError::Os(os_error!(OsError::XError(err.into()))))?; .map_err(|err| os_error!(err))?;
let window = self.inner_position().map_err(ExternalError::NotSupported)?; let window_position = self.inner_position()?;
let atoms = self.xconn.atoms(); let atoms = self.xconn.atoms();
let message = atoms[_NET_WM_MOVERESIZE]; let message = atoms[_NET_WM_MOVERESIZE];
@ -2005,13 +2000,9 @@ impl UnownedWindow {
self.xconn self.xconn
.xcb_connection() .xcb_connection()
.ungrab_pointer(x11rb::CURRENT_TIME) .ungrab_pointer(x11rb::CURRENT_TIME)
.map_err(|err| { .map_err(|err| os_error!(X11Error::from(err)))?
ExternalError::Os(os_error!(OsError::XError(X11Error::from(err).into())))
})?
.ignore_error(); .ignore_error();
self.xconn.flush_requests().map_err(|err| { self.xconn.flush_requests().map_err(|err| os_error!(X11Error::Xlib(err)))?;
ExternalError::Os(os_error!(OsError::XError(X11Error::Xlib(err).into())))
})?;
*grabbed_lock = CursorGrabMode::None; *grabbed_lock = CursorGrabMode::None;
// we keep the lock until we are done // we keep the lock until we are done
@ -2025,18 +2016,18 @@ impl UnownedWindow {
| xproto::EventMask::SUBSTRUCTURE_NOTIFY, | xproto::EventMask::SUBSTRUCTURE_NOTIFY,
), ),
[ [
(window.x + xinput_fp1616_to_float(pointer.win_x) as i32) as u32, (window_position.x + xinput_fp1616_to_float(pointer.win_x) as i32) as u32,
(window.y + xinput_fp1616_to_float(pointer.win_y) as i32) as u32, (window_position.y + xinput_fp1616_to_float(pointer.win_y) as i32) as u32,
action.try_into().unwrap(), action.try_into().unwrap(),
1, // Button 1 1, // Button 1
1, 1,
], ],
) )
.map_err(|err| ExternalError::Os(os_error!(OsError::XError(err.into()))))?; .map_err(|err| os_error!(err))?;
self.xconn.flush_requests().map_err(|err| { self.xconn.flush_requests().map_err(|err| os_error!(X11Error::Xlib(err)))?;
ExternalError::Os(os_error!(OsError::XError(X11Error::Xlib(err).into())))
}) Ok(())
} }
#[inline] #[inline]
@ -2135,7 +2126,7 @@ impl UnownedWindow {
} }
#[inline] #[inline]
pub fn request_activation_token(&self) -> Result<AsyncRequestSerial, NotSupportedError> { pub fn request_activation_token(&self) -> Result<AsyncRequestSerial, RequestError> {
let serial = AsyncRequestSerial::get(); let serial = AsyncRequestSerial::get();
self.activation_sender.send((self.id(), serial)); self.activation_sender.send((self.id(), serial));
Ok(serial) Ok(serial)

View file

@ -12,11 +12,11 @@ use orbclient::{
use smol_str::SmolStr; use smol_str::SmolStr;
use super::{ use super::{
DeviceId, KeyEventExtra, MonitorHandle, OsError, PlatformSpecificEventLoopAttributes, DeviceId, KeyEventExtra, MonitorHandle, PlatformSpecificEventLoopAttributes, RedoxSocket,
RedoxSocket, TimeSocket, WindowId, WindowProperties, TimeSocket, WindowId, WindowProperties,
}; };
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::error::{EventLoopError, ExternalError, NotSupportedError}; use crate::error::{EventLoopError, NotSupportedError, RequestError};
use crate::event::{self, Ime, Modifiers, StartCause}; use crate::event::{self, Ime, Modifiers, StartCause};
use crate::event_loop::{self, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents}; use crate::event_loop::{self, ActiveEventLoop as RootActiveEventLoop, ControlFlow, DeviceEvents};
use crate::keyboard::{ use crate::keyboard::{
@ -284,17 +284,11 @@ impl EventLoop {
// events. // events.
let (user_events_sender, user_events_receiver) = mpsc::sync_channel(1); let (user_events_sender, user_events_receiver) = mpsc::sync_channel(1);
let event_socket = Arc::new( let event_socket =
RedoxSocket::event() Arc::new(RedoxSocket::event().map_err(|error| os_error!(format!("{error}")))?);
.map_err(OsError::new)
.map_err(|error| EventLoopError::Os(os_error!(error)))?,
);
let wake_socket = Arc::new( let wake_socket =
TimeSocket::open() Arc::new(TimeSocket::open().map_err(|error| os_error!(format!("{error}")))?);
.map_err(OsError::new)
.map_err(|error| EventLoopError::Os(os_error!(error)))?,
);
event_socket event_socket
.write(&syscall::Event { .write(&syscall::Event {
@ -302,8 +296,7 @@ impl EventLoop {
flags: syscall::EventFlags::EVENT_READ, flags: syscall::EventFlags::EVENT_READ,
data: wake_socket.0.fd, data: wake_socket.0.fd,
}) })
.map_err(OsError::new) .map_err(|error| os_error!(format!("{error}")))?;
.map_err(|error| EventLoopError::Os(os_error!(error)))?;
Ok(Self { Ok(Self {
windows: Vec::new(), windows: Vec::new(),
@ -731,15 +724,15 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: crate::window::WindowAttributes, window_attributes: crate::window::WindowAttributes,
) -> Result<Box<dyn CoreWindow>, crate::error::OsError> { ) -> Result<Box<dyn CoreWindow>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
_: CustomCursorSource, _: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("create_custom_cursor is not supported").into())
} }
fn available_monitors(&self) -> Box<dyn Iterator<Item = crate::monitor::MonitorHandle>> { fn available_monitors(&self) -> Box<dyn Iterator<Item = crate::monitor::MonitorHandle>> {

View file

@ -1,9 +1,7 @@
#![cfg(target_os = "redox")] #![cfg(target_os = "redox")]
use std::fmt::{self, Display, Formatter};
use std::num::{NonZeroU16, NonZeroU32}; use std::num::{NonZeroU16, NonZeroU32};
use std::str; use std::{fmt, str};
use std::sync::Arc;
use smol_str::SmolStr; use smol_str::SmolStr;
@ -15,6 +13,11 @@ mod event_loop;
pub use self::window::Window; pub use self::window::Window;
mod window; mod window;
pub(crate) use crate::cursor::{
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
};
pub(crate) use crate::icon::NoIcon as PlatformIcon;
struct RedoxSocket { struct RedoxSocket {
fd: usize, fd: usize,
} }
@ -173,26 +176,6 @@ impl<'a> fmt::Display for WindowProperties<'a> {
} }
} }
#[derive(Clone, Debug)]
pub struct OsError(Arc<syscall::Error>);
impl OsError {
fn new(error: syscall::Error) -> Self {
Self(Arc::new(error))
}
}
impl Display for OsError {
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
self.0.fmt(fmt)
}
}
pub(crate) use crate::cursor::{
NoCustomCursor as PlatformCustomCursor, NoCustomCursor as PlatformCustomCursorSource,
};
pub(crate) use crate::icon::NoIcon as PlatformIcon;
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct MonitorHandle; pub struct MonitorHandle;

View file

@ -1,12 +1,10 @@
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use super::{ use super::{ActiveEventLoop, MonitorHandle, RedoxSocket, TimeSocket, WindowId, WindowProperties};
ActiveEventLoop, MonitorHandle, OsError, RedoxSocket, TimeSocket, WindowId, WindowProperties,
};
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error; use crate::error::{NotSupportedError, RequestError};
use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId as CoreWindowId}; use crate::window::{self, Fullscreen, ImePurpose, Window as CoreWindow, WindowId as CoreWindowId};
@ -32,7 +30,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
el: &ActiveEventLoop, el: &ActiveEventLoop,
attrs: window::WindowAttributes, attrs: window::WindowAttributes,
) -> Result<Self, error::OsError> { ) -> Result<Self, RequestError> {
let scale = MonitorHandle.scale_factor(); let scale = MonitorHandle.scale_factor();
let (x, y) = if let Some(pos) = attrs.position { let (x, y) = if let Some(pos) = attrs.position {
@ -125,20 +123,17 @@ impl Window {
}) })
} }
fn get_flag(&self, flag: char) -> Result<bool, error::ExternalError> { fn get_flag(&self, flag: char) -> Result<bool, RequestError> {
let mut buf: [u8; 4096] = [0; 4096]; let mut buf: [u8; 4096] = [0; 4096];
let path = self let path = self.window_socket.fpath(&mut buf).map_err(|err| os_error!(format!("{err}")))?;
.window_socket
.fpath(&mut buf)
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?;
let properties = WindowProperties::new(path); let properties = WindowProperties::new(path);
Ok(properties.flags.contains(flag)) Ok(properties.flags.contains(flag))
} }
fn set_flag(&self, flag: char, value: bool) -> Result<(), error::ExternalError> { fn set_flag(&self, flag: char, value: bool) -> Result<(), RequestError> {
self.window_socket self.window_socket
.write(format!("F,{flag},{}", if value { 1 } else { 0 }).as_bytes()) .write(format!("F,{flag},{}", if value { 1 } else { 0 }).as_bytes())
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?; .map_err(|err| os_error!(format!("{err}")))?;
Ok(()) Ok(())
} }
@ -204,7 +199,7 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn inner_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
let mut buf: [u8; 4096] = [0; 4096]; let mut buf: [u8; 4096] = [0; 4096];
let path = self.window_socket.fpath(&mut buf).expect("failed to read properties"); let path = self.window_socket.fpath(&mut buf).expect("failed to read properties");
let properties = WindowProperties::new(path); let properties = WindowProperties::new(path);
@ -212,7 +207,7 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn outer_position(&self) -> Result<PhysicalPosition<i32>, error::NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
// TODO: adjust for window decorations // TODO: adjust for window decorations
self.inner_position() self.inner_position()
} }
@ -372,12 +367,12 @@ impl CoreWindow for Window {
fn set_cursor(&self, _: Cursor) {} fn set_cursor(&self, _: Cursor) {}
#[inline] #[inline]
fn set_cursor_position(&self, _: Position) -> Result<(), error::ExternalError> { fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_position is not supported").into())
} }
#[inline] #[inline]
fn set_cursor_grab(&self, mode: window::CursorGrabMode) -> Result<(), error::ExternalError> { fn set_cursor_grab(&self, mode: window::CursorGrabMode) -> Result<(), RequestError> {
let (grab, relative) = match mode { let (grab, relative) = match mode {
window::CursorGrabMode::None => (false, false), window::CursorGrabMode::None => (false, false),
window::CursorGrabMode::Confined => (true, false), window::CursorGrabMode::Confined => (true, false),
@ -385,10 +380,10 @@ impl CoreWindow for Window {
}; };
self.window_socket self.window_socket
.write(format!("M,G,{}", if grab { 1 } else { 0 }).as_bytes()) .write(format!("M,G,{}", if grab { 1 } else { 0 }).as_bytes())
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?; .map_err(|err| os_error!(format!("{err}")))?;
self.window_socket self.window_socket
.write(format!("M,R,{}", if relative { 1 } else { 0 }).as_bytes()) .write(format!("M,R,{}", if relative { 1 } else { 0 }).as_bytes())
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?; .map_err(|err| os_error!(format!("{err}")))?;
Ok(()) Ok(())
} }
@ -398,18 +393,13 @@ impl CoreWindow for Window {
} }
#[inline] #[inline]
fn drag_window(&self) -> Result<(), error::ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
self.window_socket self.window_socket.write(b"D").map_err(|err| os_error!(format!("{err}")))?;
.write(b"D")
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?;
Ok(()) Ok(())
} }
#[inline] #[inline]
fn drag_resize_window( fn drag_resize_window(&self, direction: window::ResizeDirection) -> Result<(), RequestError> {
&self,
direction: window::ResizeDirection,
) -> Result<(), error::ExternalError> {
let arg = match direction { let arg = match direction {
window::ResizeDirection::East => "R", window::ResizeDirection::East => "R",
window::ResizeDirection::North => "T", window::ResizeDirection::North => "T",
@ -422,7 +412,7 @@ impl CoreWindow for Window {
}; };
self.window_socket self.window_socket
.write(format!("D,{}", arg).as_bytes()) .write(format!("D,{}", arg).as_bytes())
.map_err(|err| error::ExternalError::Os(os_error!(OsError::new(err))))?; .map_err(|err| os_error!(format!("{err}")))?;
Ok(()) Ok(())
} }
@ -430,8 +420,8 @@ impl CoreWindow for Window {
fn show_window_menu(&self, _position: Position) {} fn show_window_menu(&self, _position: Position) {}
#[inline] #[inline]
fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), error::ExternalError> { fn set_cursor_hittest(&self, _hittest: bool) -> Result<(), RequestError> {
Err(error::ExternalError::NotSupported(error::NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_hittest is not supported").into())
} }
#[inline] #[inline]

View file

@ -11,7 +11,7 @@ use super::event::DeviceId;
use super::runner::{EventWrapper, WeakShared}; use super::runner::{EventWrapper, WeakShared};
use super::window::WindowId; use super::window::WindowId;
use super::{backend, runner, EventLoopProxy}; use super::{backend, runner, EventLoopProxy};
use crate::error::{ExternalError, NotSupportedError}; use crate::error::{NotSupportedError, RequestError};
use crate::event::{ use crate::event::{
DeviceId as RootDeviceId, ElementState, Event, FingerId as RootFingerId, KeyEvent, Touch, DeviceId as RootDeviceId, ElementState, Event, FingerId as RootFingerId, KeyEvent, Touch,
TouchPhase, WindowEvent, TouchPhase, WindowEvent,
@ -606,7 +606,10 @@ impl ActiveEventLoop {
} }
pub(crate) fn has_multiple_screens(&self) -> Result<bool, NotSupportedError> { pub(crate) fn has_multiple_screens(&self) -> Result<bool, NotSupportedError> {
self.runner.monitor().is_extended().ok_or(NotSupportedError::new()) self.runner
.monitor()
.is_extended()
.ok_or(NotSupportedError::new("has_multiple_screens is not supported"))
} }
pub(crate) fn request_detailed_monitor_permission(&self) -> MonitorPermissionFuture { pub(crate) fn request_detailed_monitor_permission(&self) -> MonitorPermissionFuture {
@ -631,7 +634,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: crate::window::WindowAttributes, window_attributes: crate::window::WindowAttributes,
) -> Result<Box<dyn crate::window::Window>, crate::error::OsError> { ) -> Result<Box<dyn crate::window::Window>, RequestError> {
let window = Window::new(self, window_attributes)?; let window = Window::new(self, window_attributes)?;
Ok(Box::new(window)) Ok(Box::new(window))
} }
@ -639,7 +642,7 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
source: CustomCursorSource, source: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Ok(RootCustomCursor { inner: CustomCursor::new(self, source.inner) }) Ok(RootCustomCursor { inner: CustomCursor::new(self, source.inner) })
} }

View file

@ -37,7 +37,6 @@ pub(crate) use cursor::{
CustomCursorSource as PlatformCustomCursorSource, CustomCursorSource as PlatformCustomCursorSource,
}; };
pub use self::error::OsError;
pub use self::event::{DeviceId, FingerId}; pub use self::event::{DeviceId, FingerId};
pub(crate) use self::event_loop::{ pub(crate) use self::event_loop::{
ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle, ActiveEventLoop, EventLoop, EventLoopProxy, OwnedDisplayHandle,

View file

@ -22,10 +22,10 @@ use super::media_query_handle::MediaQueryListHandle;
use super::pointer::PointerHandler; use super::pointer::PointerHandler;
use super::{event, fullscreen, ButtonsState, ResizeScaleHandle}; use super::{event, fullscreen, ButtonsState, ResizeScaleHandle};
use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize}; use crate::dpi::{LogicalPosition, PhysicalPosition, PhysicalSize};
use crate::error::OsError as RootOE; use crate::error::RequestError;
use crate::event::{Force, MouseButton, MouseScrollDelta, SurfaceSizeWriter}; use crate::event::{Force, MouseButton, MouseScrollDelta, SurfaceSizeWriter};
use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey}; use crate::keyboard::{Key, KeyLocation, ModifiersState, PhysicalKey};
use crate::platform_impl::{Fullscreen, OsError}; use crate::platform_impl::Fullscreen;
use crate::window::{WindowAttributes, WindowId as RootWindowId}; use crate::window::{WindowAttributes, WindowId as RootWindowId};
#[allow(dead_code)] #[allow(dead_code)]
@ -83,13 +83,13 @@ impl Canvas {
navigator: Navigator, navigator: Navigator,
document: Document, document: Document,
attr: WindowAttributes, attr: WindowAttributes,
) -> Result<Self, RootOE> { ) -> Result<Self, RequestError> {
let canvas = match attr.platform_specific.canvas.map(Arc::try_unwrap) { let canvas = match attr.platform_specific.canvas.map(Arc::try_unwrap) {
Some(Ok(canvas)) => canvas.into_inner(main_thread), Some(Ok(canvas)) => canvas.into_inner(main_thread),
Some(Err(canvas)) => canvas.get(main_thread).clone(), Some(Err(canvas)) => canvas.get(main_thread).clone(),
None => document None => document
.create_element("canvas") .create_element("canvas")
.map_err(|_| os_error!(OsError("Failed to create canvas element".to_owned())))? .map_err(|_| os_error!("Failed to create canvas element"))?
.unchecked_into(), .unchecked_into(),
}; };
@ -109,7 +109,7 @@ impl Canvas {
if attr.platform_specific.focusable { if attr.platform_specific.focusable {
canvas canvas
.set_attribute("tabindex", "0") .set_attribute("tabindex", "0")
.map_err(|_| os_error!(OsError("Failed to set a tabindex".to_owned())))?; .map_err(|_| os_error!("Failed to set a tabindex"))?;
} }
let style = Style::new(&window, &canvas); let style = Style::new(&window, &canvas);

View file

@ -9,7 +9,7 @@ use super::monitor::MonitorHandler;
use super::r#async::Dispatcher; use super::r#async::Dispatcher;
use super::{backend, lock, ActiveEventLoop}; use super::{backend, lock, ActiveEventLoop};
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOE}; use crate::error::{NotSupportedError, RequestError};
use crate::icon::Icon; use crate::icon::Icon;
use crate::monitor::MonitorHandle as RootMonitorHandle; use crate::monitor::MonitorHandle as RootMonitorHandle;
use crate::window::{ use crate::window::{
@ -31,7 +31,10 @@ pub struct Inner {
} }
impl Window { impl Window {
pub(crate) fn new(target: &ActiveEventLoop, attr: WindowAttributes) -> Result<Self, RootOE> { pub(crate) fn new(
target: &ActiveEventLoop,
attr: WindowAttributes,
) -> Result<Self, RequestError> {
let id = target.generate_id(); let id = target.generate_id();
let window = target.runner.window(); let window = target.runner.window();
@ -106,13 +109,13 @@ impl RootWindow for Window {
// Not supported // Not supported
} }
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
// Note: the canvas element has no window decorations, so this is equal to `outer_position`. // Note: the canvas element has no window decorations, so this is equal to `outer_position`.
self.outer_position() self.outer_position()
} }
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
self.inner.queue(|inner| Ok(inner.canvas.position().to_physical(inner.scale_factor()))) Ok(self.inner.queue(|inner| inner.canvas.position().to_physical(inner.scale_factor())))
} }
fn set_outer_position(&self, position: Position) { fn set_outer_position(&self, position: Position) {
@ -315,12 +318,12 @@ impl RootWindow for Window {
self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor(cursor)) self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor(cursor))
} }
fn set_cursor_position(&self, _: Position) -> Result<(), ExternalError> { fn set_cursor_position(&self, _: Position) -> Result<(), RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_position is not supported").into())
} }
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
self.inner.queue(|inner| { Ok(self.inner.queue(|inner| {
match mode { match mode {
CursorGrabMode::None => inner.canvas.document().exit_pointer_lock(), CursorGrabMode::None => inner.canvas.document().exit_pointer_lock(),
CursorGrabMode::Locked => lock::request_pointer_lock( CursorGrabMode::Locked => lock::request_pointer_lock(
@ -329,30 +332,30 @@ impl RootWindow for Window {
inner.canvas.raw(), inner.canvas.raw(),
), ),
CursorGrabMode::Confined => { CursorGrabMode::Confined => {
return Err(ExternalError::NotSupported(NotSupportedError::new())) return Err(NotSupportedError::new("confined cursor mode is not supported"))
}, },
} }
Ok(()) Ok(())
}) })?)
} }
fn set_cursor_visible(&self, visible: bool) { fn set_cursor_visible(&self, visible: bool) {
self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor_visible(visible)) self.inner.dispatch(move |inner| inner.canvas.cursor.set_cursor_visible(visible))
} }
fn drag_window(&self) -> Result<(), ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("drag_window is not supported").into())
} }
fn drag_resize_window(&self, _: ResizeDirection) -> Result<(), ExternalError> { fn drag_resize_window(&self, _: ResizeDirection) -> Result<(), RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("drag_resize_window is not supported").into())
} }
fn show_window_menu(&self, _: Position) {} fn show_window_menu(&self, _: Position) {}
fn set_cursor_hittest(&self, _: bool) -> Result<(), ExternalError> { fn set_cursor_hittest(&self, _: bool) -> Result<(), RequestError> {
Err(ExternalError::NotSupported(NotSupportedError::new())) Err(NotSupportedError::new("set_cursor_hittest is not supported").into())
} }
fn current_monitor(&self) -> Option<RootMonitorHandle> { fn current_monitor(&self) -> Option<RootMonitorHandle> {

View file

@ -56,7 +56,7 @@ use super::window::set_skip_taskbar;
use super::SelectedCursor; use super::SelectedCursor;
use crate::application::ApplicationHandler; use crate::application::ApplicationHandler;
use crate::dpi::{PhysicalPosition, PhysicalSize}; use crate::dpi::{PhysicalPosition, PhysicalSize};
use crate::error::{EventLoopError, ExternalError, OsError}; use crate::error::{EventLoopError, RequestError};
use crate::event::{ use crate::event::{
Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, Touch, TouchPhase, Event, FingerId as RootFingerId, Force, Ime, RawKeyEvent, SurfaceSizeWriter, Touch, TouchPhase,
WindowEvent, WindowEvent,
@ -521,14 +521,14 @@ impl RootActiveEventLoop for ActiveEventLoop {
fn create_window( fn create_window(
&self, &self,
window_attributes: WindowAttributes, window_attributes: WindowAttributes,
) -> Result<Box<dyn CoreWindow>, OsError> { ) -> Result<Box<dyn CoreWindow>, RequestError> {
Ok(Box::new(Window::new(self, window_attributes)?)) Ok(Box::new(Window::new(self, window_attributes)?))
} }
fn create_custom_cursor( fn create_custom_cursor(
&self, &self,
source: CustomCursorSource, source: CustomCursorSource,
) -> Result<RootCustomCursor, ExternalError> { ) -> Result<RootCustomCursor, RequestError> {
Ok(RootCustomCursor { inner: WinCursor::new(&source.inner.0)? }) Ok(RootCustomCursor { inner: WinCursor::new(&source.inner.0)? })
} }

View file

@ -17,7 +17,7 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{
use super::util; use super::util;
use crate::cursor::CursorImage; use crate::cursor::CursorImage;
use crate::dpi::PhysicalSize; use crate::dpi::PhysicalSize;
use crate::error::ExternalError; use crate::error::RequestError;
use crate::icon::*; use crate::icon::*;
impl Pixel { impl Pixel {
@ -179,7 +179,7 @@ impl Default for SelectedCursor {
pub struct WinCursor(pub(super) Arc<RaiiCursor>); pub struct WinCursor(pub(super) Arc<RaiiCursor>);
impl WinCursor { impl WinCursor {
pub(crate) fn new(image: &CursorImage) -> Result<Self, ExternalError> { pub(crate) fn new(image: &CursorImage) -> Result<Self, RequestError> {
let mut bgra = image.rgba.clone(); let mut bgra = image.rgba.clone();
bgra.chunks_exact_mut(4).for_each(|chunk| chunk.swap(0, 2)); bgra.chunks_exact_mut(4).for_each(|chunk| chunk.swap(0, 2));
@ -189,16 +189,16 @@ impl WinCursor {
unsafe { unsafe {
let hdc_screen = GetDC(0); let hdc_screen = GetDC(0);
if hdc_screen == 0 { if hdc_screen == 0 {
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
let hbm_color = CreateCompatibleBitmap(hdc_screen, w, h); let hbm_color = CreateCompatibleBitmap(hdc_screen, w, h);
ReleaseDC(0, hdc_screen); ReleaseDC(0, hdc_screen);
if hbm_color == 0 { if hbm_color == 0 {
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void) == 0 { if SetBitmapBits(hbm_color, bgra.len() as u32, bgra.as_ptr() as *const c_void) == 0 {
DeleteObject(hbm_color); DeleteObject(hbm_color);
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
}; };
// Mask created according to https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap#parameters // Mask created according to https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap#parameters
@ -206,7 +206,7 @@ impl WinCursor {
let hbm_mask = CreateBitmap(w, h, 1, 1, mask_bits.as_ptr() as *const _); let hbm_mask = CreateBitmap(w, h, 1, 1, mask_bits.as_ptr() as *const _);
if hbm_mask == 0 { if hbm_mask == 0 {
DeleteObject(hbm_color); DeleteObject(hbm_color);
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
let icon_info = ICONINFO { let icon_info = ICONINFO {
@ -221,7 +221,7 @@ impl WinCursor {
DeleteObject(hbm_color); DeleteObject(hbm_color);
DeleteObject(hbm_mask); DeleteObject(hbm_mask);
if handle == 0 { if handle == 0 {
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
Ok(Self(Arc::new(RaiiCursor { handle }))) Ok(Self(Arc::new(RaiiCursor { handle })))

View file

@ -103,8 +103,6 @@ fn wrap_device_id(id: u32) -> RootDeviceId {
RootDeviceId(DeviceId(id)) RootDeviceId(DeviceId(id))
} }
pub type OsError = std::io::Error;
#[derive(Debug, Clone, Eq, PartialEq, Hash)] #[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct KeyEventExtra { pub struct KeyEventExtra {
pub text_with_all_modifiers: Option<SmolStr>, pub text_with_all_modifiers: Option<SmolStr>,

View file

@ -47,7 +47,7 @@ use windows_sys::Win32::UI::WindowsAndMessaging::{
use crate::cursor::Cursor; use crate::cursor::Cursor;
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError, OsError as RootOsError}; use crate::error::{NotSupportedError, RequestError};
use crate::icon::Icon; use crate::icon::Icon;
use crate::monitor::MonitorHandle as CoreMonitorHandle; use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::platform::windows::{BackdropType, Color, CornerPreference}; use crate::platform::windows::{BackdropType, Color, CornerPreference};
@ -89,7 +89,7 @@ impl Window {
pub(crate) fn new( pub(crate) fn new(
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
w_attr: WindowAttributes, w_attr: WindowAttributes,
) -> Result<Window, RootOsError> { ) -> Result<Window, RequestError> {
// We dispatch an `init` function because of code style. // We dispatch an `init` function because of code style.
// First person to remove the need for cloning here gets a cookie! // First person to remove the need for cloning here gets a cookie!
// //
@ -411,7 +411,7 @@ impl CoreWindow for Window {
fn pre_present_notify(&self) {} fn pre_present_notify(&self) {}
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
util::WindowArea::Outer util::WindowArea::Outer
.get_rect(self.hwnd()) .get_rect(self.hwnd())
.map(|rect| Ok(PhysicalPosition::new(rect.left, rect.top))) .map(|rect| Ok(PhysicalPosition::new(rect.left, rect.top)))
@ -421,7 +421,7 @@ impl CoreWindow for Window {
) )
} }
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError> { fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError> {
let mut position: POINT = unsafe { mem::zeroed() }; let mut position: POINT = unsafe { mem::zeroed() };
if unsafe { ClientToScreen(self.hwnd(), &mut position) } == false.into() { if unsafe { ClientToScreen(self.hwnd(), &mut position) } == false.into() {
panic!( panic!(
@ -588,12 +588,12 @@ impl CoreWindow for Window {
} }
} }
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError> { fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError> {
let confine = match mode { let confine = match mode {
CursorGrabMode::None => false, CursorGrabMode::None => false,
CursorGrabMode::Confined => true, CursorGrabMode::Confined => true,
CursorGrabMode::Locked => { CursorGrabMode::Locked => {
return Err(ExternalError::NotSupported(NotSupportedError::new())) return Err(NotSupportedError::new("locked cursor is not supported").into())
}, },
}; };
@ -608,9 +608,10 @@ impl CoreWindow for Window {
.unwrap() .unwrap()
.mouse .mouse
.set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine)) .set_cursor_flags(window, |f| f.set(CursorFlags::GRABBED, confine))
.map_err(|e| ExternalError::Os(os_error!(e))); .map_err(|err| os_error!(err).into());
let _ = tx.send(result); let _ = tx.send(result);
}); });
rx.recv().unwrap() rx.recv().unwrap()
} }
@ -636,23 +637,23 @@ impl CoreWindow for Window {
self.window_state_lock().scale_factor self.window_state_lock().scale_factor
} }
fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError> { fn set_cursor_position(&self, position: Position) -> Result<(), RequestError> {
let scale_factor = self.scale_factor(); let scale_factor = self.scale_factor();
let (x, y) = position.to_physical::<i32>(scale_factor).into(); let (x, y) = position.to_physical::<i32>(scale_factor).into();
let mut point = POINT { x, y }; let mut point = POINT { x, y };
unsafe { unsafe {
if ClientToScreen(self.hwnd(), &mut point) == false.into() { if ClientToScreen(self.hwnd(), &mut point) == false.into() {
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
if SetCursorPos(point.x, point.y) == false.into() { if SetCursorPos(point.x, point.y) == false.into() {
return Err(ExternalError::Os(os_error!(io::Error::last_os_error()))); return Err(os_error!(io::Error::last_os_error()).into());
} }
} }
Ok(()) Ok(())
} }
fn drag_window(&self) -> Result<(), ExternalError> { fn drag_window(&self) -> Result<(), RequestError> {
unsafe { unsafe {
self.handle_os_dragging(HTCAPTION as WPARAM); self.handle_os_dragging(HTCAPTION as WPARAM);
} }
@ -660,7 +661,7 @@ impl CoreWindow for Window {
Ok(()) Ok(())
} }
fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError> { fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError> {
unsafe { unsafe {
self.handle_os_dragging(match direction { self.handle_os_dragging(match direction {
ResizeDirection::East => HTRIGHT, ResizeDirection::East => HTRIGHT,
@ -683,7 +684,7 @@ impl CoreWindow for Window {
} }
} }
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError> { fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError> {
let window = self.window; let window = self.window;
let window_state = Arc::clone(&self.window_state); let window_state = Arc::clone(&self.window_state);
self.thread_executor.execute_in_thread(move || { self.thread_executor.execute_in_thread(move || {
@ -1249,7 +1250,7 @@ impl<'a> InitData<'a> {
unsafe fn init( unsafe fn init(
attributes: WindowAttributes, attributes: WindowAttributes,
event_loop: &ActiveEventLoop, event_loop: &ActiveEventLoop,
) -> Result<Window, RootOsError> { ) -> Result<Window, RequestError> {
let title = util::encode_wide(&attributes.title); let title = util::encode_wide(&attributes.title);
let class_name = util::encode_wide(&attributes.platform_specific.class_name); let class_name = util::encode_wide(&attributes.platform_specific.class_name);
@ -1332,7 +1333,7 @@ unsafe fn init(
} }
if handle == 0 { if handle == 0 {
return Err(os_error!(io::Error::last_os_error())); return Err(os_error!(io::Error::last_os_error()).into());
} }
// If the handle is non-null, then window creation must have succeeded, which means // If the handle is non-null, then window creation must have succeeded, which means

View file

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorSource, MAX_CURSOR_SIZE}; pub use crate::cursor::{BadImage, Cursor, CustomCursor, CustomCursorSource, MAX_CURSOR_SIZE};
use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size}; use crate::dpi::{PhysicalPosition, PhysicalSize, Position, Size};
use crate::error::{ExternalError, NotSupportedError}; use crate::error::RequestError;
pub use crate::icon::{BadIcon, Icon}; pub use crate::icon::{BadIcon, Icon};
use crate::monitor::{MonitorHandle, VideoModeHandle}; use crate::monitor::{MonitorHandle, VideoModeHandle};
use crate::platform_impl::{self, PlatformSpecificWindowAttributes}; use crate::platform_impl::{self, PlatformSpecificWindowAttributes};
@ -601,10 +601,10 @@ pub trait Window: AsAny + Send + Sync {
/// coordinate system. /// coordinate system.
/// - **Web:** Returns the top-left coordinates relative to the viewport. _Note: this returns /// - **Web:** Returns the top-left coordinates relative to the viewport. _Note: this returns
/// the same value as [`Window::outer_position`]._ /// the same value as [`Window::outer_position`]._
/// - **Android / Wayland:** Always returns [`NotSupportedError`]. /// - **Android / Wayland:** Always returns [`RequestError::NotSupported`].
/// ///
/// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc /// [safe area]: https://developer.apple.com/documentation/uikit/uiview/2891103-safeareainsets?language=objc
fn inner_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError>; fn inner_position(&self) -> Result<PhysicalPosition<i32>, RequestError>;
/// Returns the position of the top-left hand corner of the window relative to the /// Returns the position of the top-left hand corner of the window relative to the
/// top-left hand corner of the desktop. /// top-left hand corner of the desktop.
@ -621,8 +621,8 @@ pub trait Window: AsAny + Send + Sync {
/// - **iOS:** Returns the top left coordinates of the window in the screen space coordinate /// - **iOS:** Returns the top left coordinates of the window in the screen space coordinate
/// system. /// system.
/// - **Web:** Returns the top-left coordinates relative to the viewport. /// - **Web:** Returns the top-left coordinates relative to the viewport.
/// - **Android / Wayland:** Always returns [`NotSupportedError`]. /// - **Android / Wayland:** Always returns [`RequestError::NotSupported`].
fn outer_position(&self) -> Result<PhysicalPosition<i32>, NotSupportedError>; fn outer_position(&self) -> Result<PhysicalPosition<i32>, RequestError>;
/// Modifies the position of the window. /// Modifies the position of the window.
/// ///
@ -1160,8 +1160,8 @@ pub trait Window: AsAny + Send + Sync {
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **Wayland**: Cursor must be in [`CursorGrabMode::Locked`]. /// - **Wayland**: Cursor must be in [`CursorGrabMode::Locked`].
/// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`].
fn set_cursor_position(&self, position: Position) -> Result<(), ExternalError>; fn set_cursor_position(&self, position: Position) -> Result<(), RequestError>;
/// Set grabbing [mode][CursorGrabMode] on the cursor preventing it from leaving the window. /// Set grabbing [mode][CursorGrabMode] on the cursor preventing it from leaving the window.
/// ///
@ -1178,7 +1178,7 @@ pub trait Window: AsAny + Send + Sync {
/// .unwrap(); /// .unwrap();
/// # } /// # }
/// ``` /// ```
fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), ExternalError>; fn set_cursor_grab(&self, mode: CursorGrabMode) -> Result<(), RequestError>;
/// Modifies the cursor's visibility. /// Modifies the cursor's visibility.
/// ///
@ -1204,8 +1204,8 @@ pub trait Window: AsAny + Send + Sync {
/// - **X11:** Un-grabs the cursor. /// - **X11:** Un-grabs the cursor.
/// - **Wayland:** Requires the cursor to be inside the window to be dragged. /// - **Wayland:** Requires the cursor to be inside the window to be dragged.
/// - **macOS:** May prevent the button release event to be triggered. /// - **macOS:** May prevent the button release event to be triggered.
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android / Web:** Always returns an [`RequestError::NotSupported`].
fn drag_window(&self) -> Result<(), ExternalError>; fn drag_window(&self) -> Result<(), RequestError>;
/// Resizes the window with the left mouse button until the button is released. /// Resizes the window with the left mouse button until the button is released.
/// ///
@ -1214,9 +1214,9 @@ pub trait Window: AsAny + Send + Sync {
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **macOS:** Always returns an [`ExternalError::NotSupported`] /// - **macOS:** Always returns an [`RequestError::NotSupported`]
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android / Web:** Always returns an [`RequestError::NotSupported`].
fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), ExternalError>; fn drag_resize_window(&self, direction: ResizeDirection) -> Result<(), RequestError>;
/// Show [window menu] at a specified position . /// Show [window menu] at a specified position .
/// ///
@ -1237,8 +1237,8 @@ pub trait Window: AsAny + Send + Sync {
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **iOS / Android / Web / Orbital:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android / Web / Orbital:** Always returns an [`RequestError::NotSupported`].
fn set_cursor_hittest(&self, hittest: bool) -> Result<(), ExternalError>; fn set_cursor_hittest(&self, hittest: bool) -> Result<(), RequestError>;
/// Returns the monitor on which the window currently resides. /// Returns the monitor on which the window currently resides.
/// ///
@ -1345,8 +1345,8 @@ pub enum CursorGrabMode {
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **macOS:** Not implemented. Always returns [`ExternalError::NotSupported`] for now. /// - **macOS:** Not implemented. Always returns [`RequestError::NotSupported`] for now.
/// - **iOS / Android / Web:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android / Web:** Always returns an [`RequestError::NotSupported`].
Confined, Confined,
/// The cursor is locked inside the window area to the certain position. /// The cursor is locked inside the window area to the certain position.
@ -1356,9 +1356,9 @@ pub enum CursorGrabMode {
/// ///
/// ## Platform-specific /// ## Platform-specific
/// ///
/// - **X11 / Windows:** Not implemented. Always returns [`ExternalError::NotSupported`] for /// - **X11 / Windows:** Not implemented. Always returns [`RequestError::NotSupported`] for
/// now. /// now.
/// - **iOS / Android:** Always returns an [`ExternalError::NotSupported`]. /// - **iOS / Android:** Always returns an [`RequestError::NotSupported`].
Locked, Locked,
} }