winit-core: move application
This commit is contained in:
parent
79fa4061cb
commit
c0b737de4a
7 changed files with 68 additions and 68 deletions
|
|
@ -25,9 +25,7 @@ use winit::icon::{Icon, RgbaIcon};
|
||||||
use winit::keyboard::{Key, ModifiersState};
|
use winit::keyboard::{Key, ModifiersState};
|
||||||
use winit::monitor::Fullscreen;
|
use winit::monitor::Fullscreen;
|
||||||
#[cfg(macos_platform)]
|
#[cfg(macos_platform)]
|
||||||
use winit::platform::macos::{
|
use winit::platform::macos::{OptionAsAlt, WindowAttributesMacOS, WindowExtMacOS};
|
||||||
ApplicationHandlerExtMacOS, OptionAsAlt, WindowAttributesMacOS, WindowExtMacOS,
|
|
||||||
};
|
|
||||||
#[cfg(any(x11_platform, wayland_platform))]
|
#[cfg(any(x11_platform, wayland_platform))]
|
||||||
use winit::platform::startup_notify::{self, EventLoopExtStartupNotify, WindowExtStartupNotify};
|
use winit::platform::startup_notify::{self, EventLoopExtStartupNotify, WindowExtStartupNotify};
|
||||||
#[cfg(wayland_platform)]
|
#[cfg(wayland_platform)]
|
||||||
|
|
@ -37,6 +35,7 @@ use winit::platform::web::{ActiveEventLoopExtWeb, WindowAttributesWeb};
|
||||||
#[cfg(x11_platform)]
|
#[cfg(x11_platform)]
|
||||||
use winit::platform::x11::{ActiveEventLoopExtX11, WindowAttributesX11};
|
use winit::platform::x11::{ActiveEventLoopExtX11, WindowAttributesX11};
|
||||||
use winit::window::{CursorGrabMode, ResizeDirection, Theme, Window, WindowAttributes, WindowId};
|
use winit::window::{CursorGrabMode, ResizeDirection, Theme, Window, WindowAttributes, WindowId};
|
||||||
|
use winit_core::application::macos::ApplicationHandlerExtMacOS;
|
||||||
|
|
||||||
#[path = "util/tracing.rs"]
|
#[path = "util/tracing.rs"]
|
||||||
mod tracing;
|
mod tracing;
|
||||||
|
|
@ -577,7 +576,6 @@ impl ApplicationHandler for Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
fn macos_handler(&mut self) -> Option<&mut dyn ApplicationHandlerExtMacOS> {
|
fn macos_handler(&mut self) -> Option<&mut dyn ApplicationHandlerExtMacOS> {
|
||||||
Some(self)
|
Some(self)
|
||||||
}
|
}
|
||||||
|
|
@ -589,7 +587,6 @@ impl Drop for Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
impl ApplicationHandlerExtMacOS for Application {
|
impl ApplicationHandlerExtMacOS for Application {
|
||||||
fn standard_key_binding(
|
fn standard_key_binding(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
||||||
|
|
@ -296,11 +296,10 @@
|
||||||
pub use dpi;
|
pub use dpi;
|
||||||
pub use rwh_06 as raw_window_handle;
|
pub use rwh_06 as raw_window_handle;
|
||||||
|
|
||||||
pub mod application;
|
|
||||||
#[cfg(any(doc, doctest, test))]
|
#[cfg(any(doc, doctest, test))]
|
||||||
pub mod changelog;
|
pub mod changelog;
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub use winit_core::{cursor, error, event, icon, keyboard, monitor, window};
|
pub use winit_core::{application, cursor, error, event, icon, keyboard, monitor, window};
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod os_error;
|
mod os_error;
|
||||||
mod platform_impl;
|
mod platform_impl;
|
||||||
|
|
|
||||||
|
|
@ -69,13 +69,14 @@ use std::os::raw::c_void;
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use winit_core::application::macos::ApplicationHandlerExtMacOS;
|
||||||
use winit_core::window::PlatformWindowAttributes;
|
use winit_core::window::PlatformWindowAttributes;
|
||||||
|
|
||||||
use crate::application::ApplicationHandler;
|
|
||||||
use crate::event_loop::{ActiveEventLoop, EventLoopBuilder};
|
use crate::event_loop::{ActiveEventLoop, EventLoopBuilder};
|
||||||
use crate::monitor::MonitorHandle;
|
use crate::monitor::MonitorHandle;
|
||||||
use crate::platform_impl::MonitorHandle as MacOsMonitorHandle;
|
use crate::platform_impl::MonitorHandle as MacOsMonitorHandle;
|
||||||
use crate::window::{Window, WindowId};
|
use crate::window::Window;
|
||||||
|
|
||||||
/// Additional methods on [`Window`] that are specific to MacOS.
|
/// Additional methods on [`Window`] that are specific to MacOS.
|
||||||
pub trait WindowExtMacOS {
|
pub trait WindowExtMacOS {
|
||||||
|
|
@ -610,52 +611,3 @@ pub enum OptionAsAlt {
|
||||||
#[default]
|
#[default]
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional events on [`ApplicationHandler`] that are specific to macOS.
|
|
||||||
///
|
|
||||||
/// This can be registered with [`ApplicationHandler::macos_handler`].
|
|
||||||
pub trait ApplicationHandlerExtMacOS: ApplicationHandler {
|
|
||||||
/// The system interpreted a keypress as a standard key binding command.
|
|
||||||
///
|
|
||||||
/// Examples include inserting tabs and newlines, or moving the insertion point, see
|
|
||||||
/// [`NSStandardKeyBindingResponding`] for the full list of key bindings. They are often text
|
|
||||||
/// editing related.
|
|
||||||
///
|
|
||||||
/// This corresponds to the [`doCommandBySelector:`] method on `NSTextInputClient`.
|
|
||||||
///
|
|
||||||
/// The `action` parameter contains the string representation of the selector. Examples include
|
|
||||||
/// `"insertBacktab:"`, `"indent:"` and `"noop:"`.
|
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```ignore
|
|
||||||
/// impl ApplicationHandlerExtMacOS for App {
|
|
||||||
/// fn standard_key_binding(
|
|
||||||
/// &mut self,
|
|
||||||
/// event_loop: &dyn ActiveEventLoop,
|
|
||||||
/// window_id: WindowId,
|
|
||||||
/// action: &str,
|
|
||||||
/// ) {
|
|
||||||
/// match action {
|
|
||||||
/// "moveBackward:" => self.cursor.position -= 1,
|
|
||||||
/// "moveForward:" => self.cursor.position += 1,
|
|
||||||
/// _ => {} // Ignore other actions
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// [`NSStandardKeyBindingResponding`]: https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding?language=objc
|
|
||||||
/// [`doCommandBySelector:`]: https://developer.apple.com/documentation/appkit/nstextinputclient/1438256-docommandbyselector?language=objc
|
|
||||||
#[doc(alias = "doCommandBySelector:")]
|
|
||||||
fn standard_key_binding(
|
|
||||||
&mut self,
|
|
||||||
event_loop: &dyn ActiveEventLoop,
|
|
||||||
window_id: WindowId,
|
|
||||||
action: &str,
|
|
||||||
) {
|
|
||||||
let _ = event_loop;
|
|
||||||
let _ = window_id;
|
|
||||||
let _ = action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
52
winit-core/src/application/macos.rs
Normal file
52
winit-core/src/application/macos.rs
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
use crate::application::ApplicationHandler;
|
||||||
|
use crate::event_loop::ActiveEventLoop;
|
||||||
|
use crate::window::WindowId;
|
||||||
|
|
||||||
|
/// Additional events on [`ApplicationHandler`] that are specific to macOS.
|
||||||
|
///
|
||||||
|
/// This can be registered with [`ApplicationHandler::macos_handler`].
|
||||||
|
pub trait ApplicationHandlerExtMacOS: ApplicationHandler {
|
||||||
|
/// The system interpreted a keypress as a standard key binding command.
|
||||||
|
///
|
||||||
|
/// Examples include inserting tabs and newlines, or moving the insertion point, see
|
||||||
|
/// [`NSStandardKeyBindingResponding`] for the full list of key bindings. They are often text
|
||||||
|
/// editing related.
|
||||||
|
///
|
||||||
|
/// This corresponds to the [`doCommandBySelector:`] method on `NSTextInputClient`.
|
||||||
|
///
|
||||||
|
/// The `action` parameter contains the string representation of the selector. Examples include
|
||||||
|
/// `"insertBacktab:"`, `"indent:"` and `"noop:"`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// impl ApplicationHandlerExtMacOS for App {
|
||||||
|
/// fn standard_key_binding(
|
||||||
|
/// &mut self,
|
||||||
|
/// event_loop: &dyn ActiveEventLoop,
|
||||||
|
/// window_id: WindowId,
|
||||||
|
/// action: &str,
|
||||||
|
/// ) {
|
||||||
|
/// match action {
|
||||||
|
/// "moveBackward:" => self.cursor.position -= 1,
|
||||||
|
/// "moveForward:" => self.cursor.position += 1,
|
||||||
|
/// _ => {} // Ignore other actions
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// [`NSStandardKeyBindingResponding`]: https://developer.apple.com/documentation/appkit/nsstandardkeybindingresponding?language=objc
|
||||||
|
/// [`doCommandBySelector:`]: https://developer.apple.com/documentation/appkit/nstextinputclient/1438256-docommandbyselector?language=objc
|
||||||
|
#[doc(alias = "doCommandBySelector:")]
|
||||||
|
fn standard_key_binding(
|
||||||
|
&mut self,
|
||||||
|
event_loop: &dyn ActiveEventLoop,
|
||||||
|
window_id: WindowId,
|
||||||
|
action: &str,
|
||||||
|
) {
|
||||||
|
let _ = event_loop;
|
||||||
|
let _ = window_id;
|
||||||
|
let _ = action;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
use crate::event::{DeviceEvent, DeviceId, StartCause, WindowEvent};
|
use crate::event::{DeviceEvent, DeviceId, StartCause, WindowEvent};
|
||||||
use crate::event_loop::ActiveEventLoop;
|
use crate::event_loop::ActiveEventLoop;
|
||||||
#[cfg(macos_platform)]
|
|
||||||
use crate::platform::macos::ApplicationHandlerExtMacOS;
|
|
||||||
use crate::window::WindowId;
|
use crate::window::WindowId;
|
||||||
|
|
||||||
|
pub mod macos;
|
||||||
|
|
||||||
/// The handler of application-level events.
|
/// The handler of application-level events.
|
||||||
///
|
///
|
||||||
/// See [the top-level docs] for example usage, and [`EventLoop::run_app`] for an overview of when
|
/// See [the top-level docs] for example usage, and [`EventLoop::run_app`] for an overview of when
|
||||||
|
|
@ -135,8 +135,9 @@ pub trait ApplicationHandler {
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
/// use std::time::Duration;
|
/// use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// use winit::application::ApplicationHandler;
|
/// use winit::event_loop::EventLoop;
|
||||||
/// use winit::event_loop::{ActiveEventLoop, EventLoop};
|
/// use winit_core::application::ApplicationHandler;
|
||||||
|
/// use winit_core::event_loop::ActiveEventLoop;
|
||||||
///
|
///
|
||||||
/// struct MyApp {
|
/// struct MyApp {
|
||||||
/// receiver: mpsc::Receiver<u64>,
|
/// receiver: mpsc::Receiver<u64>,
|
||||||
|
|
@ -350,9 +351,8 @@ pub trait ApplicationHandler {
|
||||||
/// The macOS-specific handler.
|
/// The macOS-specific handler.
|
||||||
///
|
///
|
||||||
/// The return value from this should not change at runtime.
|
/// The return value from this should not change at runtime.
|
||||||
#[cfg(macos_platform)]
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn macos_handler(&mut self) -> Option<&mut dyn ApplicationHandlerExtMacOS> {
|
fn macos_handler(&mut self) -> Option<&mut dyn macos::ApplicationHandlerExtMacOS> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -419,9 +419,8 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for &mut A {
|
||||||
(**self).memory_warning(event_loop);
|
(**self).memory_warning(event_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(macos_platform)]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn macos_handler(&mut self) -> Option<&mut dyn ApplicationHandlerExtMacOS> {
|
fn macos_handler(&mut self) -> Option<&mut dyn macos::ApplicationHandlerExtMacOS> {
|
||||||
(**self).macos_handler()
|
(**self).macos_handler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -488,9 +487,8 @@ impl<A: ?Sized + ApplicationHandler> ApplicationHandler for Box<A> {
|
||||||
(**self).memory_warning(event_loop);
|
(**self).memory_warning(event_loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(macos_platform)]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn macos_handler(&mut self) -> Option<&mut dyn ApplicationHandlerExtMacOS> {
|
fn macos_handler(&mut self) -> Option<&mut dyn macos::ApplicationHandlerExtMacOS> {
|
||||||
(**self).macos_handler()
|
(**self).macos_handler()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1133,6 +1133,7 @@ mod tests {
|
||||||
use std::collections::{BTreeSet, HashSet};
|
use std::collections::{BTreeSet, HashSet};
|
||||||
|
|
||||||
use dpi::PhysicalPosition;
|
use dpi::PhysicalPosition;
|
||||||
|
|
||||||
use crate::event;
|
use crate::event;
|
||||||
|
|
||||||
macro_rules! foreach_event {
|
macro_rules! foreach_event {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ pub mod as_any;
|
||||||
pub mod cursor;
|
pub mod cursor;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
pub mod application;
|
||||||
pub mod event;
|
pub mod event;
|
||||||
pub mod event_loop;
|
pub mod event_loop;
|
||||||
pub mod icon;
|
pub mod icon;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue