mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 06:40:06 -04:00
Rename EventsLoop and associated types to EventLoop
This commit is contained in:
@@ -3,7 +3,7 @@ extern crate winit;
|
|||||||
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};
|
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
||||||
window.set_title("A fantastic window!");
|
window.set_title("A fantastic window!");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new()
|
let window = winit::WindowBuilder::new()
|
||||||
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::io::{self, Write};
|
|||||||
use winit::{ControlFlow, Event, WindowEvent};
|
use winit::{ControlFlow, Event, WindowEvent};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
// enumerating monitors
|
// enumerating monitors
|
||||||
let monitor = {
|
let monitor = {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let _window = winit::WindowBuilder::new()
|
let _window = winit::WindowBuilder::new()
|
||||||
.with_title("Your faithful window")
|
.with_title("Your faithful window")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extern crate winit;
|
|||||||
use winit::dpi::LogicalSize;
|
use winit::dpi::LogicalSize;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new()
|
let window = winit::WindowBuilder::new()
|
||||||
.build(&events_loop)
|
.build(&events_loop)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let event_loop = winit::EventsLoop::new();
|
let event_loop = winit::EventLoop::new();
|
||||||
let window = winit::WindowBuilder::new().build(&event_loop).unwrap();
|
let window = winit::WindowBuilder::new().build(&event_loop).unwrap();
|
||||||
println!("{:#?}\nPrimary: {:#?}", window.get_available_monitors(), window.get_primary_monitor());
|
println!("{:#?}\nPrimary: {:#?}", window.get_available_monitors(), window.get_primary_monitor());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ extern crate winit;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let mut windows = HashMap::new();
|
let mut windows = HashMap::new();
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let _window = winit::WindowBuilder::new()
|
let _window = winit::WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let mut resizable = false;
|
let mut resizable = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new().with_decorations(false)
|
let window = winit::WindowBuilder::new().with_decorations(false)
|
||||||
.with_transparency(true)
|
.with_transparency(true)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
extern crate winit;
|
extern crate winit;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let _window = winit::WindowBuilder::new()
|
let _window = winit::WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ fn main() {
|
|||||||
// feature enabled).
|
// feature enabled).
|
||||||
let icon = Icon::from_path(path).expect("Failed to open icon");
|
let icon = Icon::from_path(path).expect("Failed to open icon");
|
||||||
|
|
||||||
let mut events_loop = winit::EventsLoop::new();
|
let mut events_loop = winit::EventLoop::new();
|
||||||
|
|
||||||
let window = winit::WindowBuilder::new()
|
let window = winit::WindowBuilder::new()
|
||||||
.with_title("An iconic window!")
|
.with_title("An iconic window!")
|
||||||
|
|||||||
86
src/lib.rs
86
src/lib.rs
@@ -2,12 +2,12 @@
|
|||||||
//!
|
//!
|
||||||
//! # Building a window
|
//! # Building a window
|
||||||
//!
|
//!
|
||||||
//! Before you can build a window, you first need to build an `EventsLoop`. This is done with the
|
//! Before you can build a window, you first need to build an `EventLoop`. This is done with the
|
||||||
//! `EventsLoop::new()` function. Example:
|
//! `EventLoop::new()` function. Example:
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::EventsLoop;
|
//! use winit::EventLoop;
|
||||||
//! let events_loop = EventsLoop::new();
|
//! let events_loop = EventLoop::new();
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Once this is done there are two ways to create a window:
|
//! Once this is done there are two ways to create a window:
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
//! Once a window has been created, it will *generate events*. For example whenever the user moves
|
//! Once a window has been created, it will *generate events*. For example whenever the user moves
|
||||||
//! the window, resizes the window, moves the mouse, etc. an event is generated.
|
//! the window, resizes the window, moves the mouse, etc. an event is generated.
|
||||||
//!
|
//!
|
||||||
//! The events generated by a window can be retrieved from the `EventsLoop` the window was created
|
//! The events generated by a window can be retreived from the `EventLoop` the window was created
|
||||||
//! with.
|
//! with.
|
||||||
//!
|
//!
|
||||||
//! There are two ways to do so. The first is to call `events_loop.poll_events(...)`, which will
|
//! There are two ways to do so. The first is to call `events_loop.poll_events(...)`, which will
|
||||||
@@ -36,8 +36,8 @@
|
|||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::{Event, WindowEvent};
|
//! use winit::{Event, WindowEvent};
|
||||||
//! use winit::dpi::LogicalSize;
|
//! use winit::dpi::LogicalSize;
|
||||||
//! # use winit::EventsLoop;
|
//! # use winit::EventLoop;
|
||||||
//! # let mut events_loop = EventsLoop::new();
|
//! # let mut events_loop = EventLoop::new();
|
||||||
//!
|
//!
|
||||||
//! loop {
|
//! loop {
|
||||||
//! events_loop.poll_events(|event| {
|
//! events_loop.poll_events(|event| {
|
||||||
@@ -59,8 +59,8 @@
|
|||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! use winit::{ControlFlow, Event, WindowEvent};
|
//! use winit::{ControlFlow, Event, WindowEvent};
|
||||||
//! # use winit::EventsLoop;
|
//! # use winit::EventLoop;
|
||||||
//! # let mut events_loop = EventsLoop::new();
|
//! # let mut events_loop = EventLoop::new();
|
||||||
//!
|
//!
|
||||||
//! events_loop.run_forever(|event| {
|
//! events_loop.run_forever(|event| {
|
||||||
//! match event {
|
//! match event {
|
||||||
@@ -134,9 +134,9 @@ pub mod os;
|
|||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use winit::{Event, EventsLoop, Window, WindowEvent, ControlFlow};
|
/// use winit::{Event, EventLoop, Window, WindowEvent, ControlFlow};
|
||||||
///
|
///
|
||||||
/// let mut events_loop = EventsLoop::new();
|
/// let mut events_loop = EventLoop::new();
|
||||||
/// let window = Window::new(&events_loop).unwrap();
|
/// let window = Window::new(&events_loop).unwrap();
|
||||||
///
|
///
|
||||||
/// events_loop.run_forever(|event| {
|
/// events_loop.run_forever(|event| {
|
||||||
@@ -178,28 +178,28 @@ pub struct DeviceId(platform::DeviceId);
|
|||||||
/// Provides a way to retrieve events from the system and from the windows that were registered to
|
/// Provides a way to retrieve events from the system and from the windows that were registered to
|
||||||
/// the events loop.
|
/// the events loop.
|
||||||
///
|
///
|
||||||
/// An `EventsLoop` can be seen more or less as a "context". Calling `EventsLoop::new()`
|
/// An `EventLoop` can be seen more or less as a "context". Calling `EventLoop::new()`
|
||||||
/// initializes everything that will be required to create windows. For example on Linux creating
|
/// initializes everything that will be required to create windows. For example on Linux creating
|
||||||
/// an events loop opens a connection to the X or Wayland server.
|
/// an events loop opens a connection to the X or Wayland server.
|
||||||
///
|
///
|
||||||
/// To wake up an `EventsLoop` from a another thread, see the `EventsLoopProxy` docs.
|
/// To wake up an `EventLoop` from a another thread, see the `EventLoopProxy` docs.
|
||||||
///
|
///
|
||||||
/// Note that the `EventsLoop` cannot be shared accross threads (due to platform-dependant logic
|
/// Note that the `EventLoop` cannot be shared accross threads (due to platform-dependant logic
|
||||||
/// forbiding it), as such it is neither `Send` nor `Sync`. If you need cross-thread access, the
|
/// forbiding it), as such it is neither `Send` nor `Sync`. If you need cross-thread access, the
|
||||||
/// `Window` created from this `EventsLoop` _can_ be sent to an other thread, and the
|
/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
|
||||||
/// `EventsLoopProxy` allows you to wakeup an `EventsLoop` from an other thread.
|
/// `EventLoopProxy` allows you to wakeup an `EventLoop` from an other thread.
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
events_loop: platform::EventsLoop,
|
events_loop: platform::EventLoop,
|
||||||
_marker: ::std::marker::PhantomData<*mut ()> // Not Send nor Sync
|
_marker: ::std::marker::PhantomData<*mut ()> // Not Send nor Sync
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for EventsLoop {
|
impl std::fmt::Debug for EventLoop {
|
||||||
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
fmtr.pad("EventsLoop { .. }")
|
fmtr.pad("EventLoop { .. }")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returned by the user callback given to the `EventsLoop::run_forever` method.
|
/// Returned by the user callback given to the `EventLoop::run_forever` method.
|
||||||
///
|
///
|
||||||
/// Indicates whether the `run_forever` method should continue or complete.
|
/// Indicates whether the `run_forever` method should continue or complete.
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
@@ -211,16 +211,16 @@ pub enum ControlFlow {
|
|||||||
Break,
|
Break,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
/// Builds a new events loop.
|
/// Builds a new events loop.
|
||||||
///
|
///
|
||||||
/// Usage will result in display backend initialisation, this can be controlled on linux
|
/// Usage will result in display backend initialisation, this can be controlled on linux
|
||||||
/// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`.
|
/// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`.
|
||||||
/// If it is not set, winit will try to connect to a wayland connection, and if it fails will
|
/// If it is not set, winit will try to connect to a wayland connection, and if it fails will
|
||||||
/// fallback on x11. If this variable is set with any other value, winit will panic.
|
/// fallback on x11. If this variable is set with any other value, winit will panic.
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
events_loop: platform::EventsLoop::new(),
|
events_loop: platform::EventLoop::new(),
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,52 +264,52 @@ impl EventsLoop {
|
|||||||
self.events_loop.run_forever(callback)
|
self.events_loop.run_forever(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an `EventsLoopProxy` that can be used to wake up the `EventsLoop` from another
|
/// Creates an `EventLoopProxy` that can be used to wake up the `EventLoop` from another
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy {
|
EventLoopProxy {
|
||||||
events_loop_proxy: self.events_loop.create_proxy(),
|
events_loop_proxy: self.events_loop.create_proxy(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to wake up the `EventsLoop` from another thread.
|
/// Used to wake up the `EventLoop` from another thread.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy {
|
pub struct EventLoopProxy {
|
||||||
events_loop_proxy: platform::EventsLoopProxy,
|
events_loop_proxy: platform::EventLoopProxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for EventsLoopProxy {
|
impl std::fmt::Debug for EventLoopProxy {
|
||||||
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, fmtr: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
fmtr.pad("EventsLoopProxy { .. }")
|
fmtr.pad("EventLoopProxy { .. }")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
/// Wake up the `EventsLoop` from which this proxy was created.
|
/// Wake up the `EventLoop` from which this proxy was created.
|
||||||
///
|
///
|
||||||
/// This causes the `EventsLoop` to emit an `Awakened` event.
|
/// This causes the `EventLoop` to emit an `Awakened` event.
|
||||||
///
|
///
|
||||||
/// Returns an `Err` if the associated `EventsLoop` no longer exists.
|
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
self.events_loop_proxy.wakeup()
|
self.events_loop_proxy.wakeup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The error that is returned when an `EventsLoopProxy` attempts to wake up an `EventsLoop` that
|
/// The error that is returned when an `EventLoopProxy` attempts to wake up an `EventLoop` that
|
||||||
/// no longer exists.
|
/// no longer exists.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct EventsLoopClosed;
|
pub struct EventLoopClosed;
|
||||||
|
|
||||||
impl std::fmt::Display for EventsLoopClosed {
|
impl std::fmt::Display for EventLoopClosed {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||||
write!(f, "{}", std::error::Error::description(self))
|
write!(f, "{}", std::error::Error::description(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for EventsLoopClosed {
|
impl std::error::Error for EventLoopClosed {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Tried to wake up a closed `EventsLoop`"
|
"Tried to wake up a closed `EventLoop`"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#![cfg(any(target_os = "android"))]
|
#![cfg(any(target_os = "android"))]
|
||||||
|
|
||||||
use std::os::raw::c_void;
|
use std::os::raw::c_void;
|
||||||
use EventsLoop;
|
use EventLoop;
|
||||||
use Window;
|
use Window;
|
||||||
use WindowBuilder;
|
use WindowBuilder;
|
||||||
|
|
||||||
/// Additional methods on `EventsLoop` that are specific to Android.
|
/// Additional methods on `EventLoop` that are specific to Android.
|
||||||
pub trait EventsLoopExt {
|
pub trait EventLoopExt {
|
||||||
/// Makes it possible for glutin to register a callback when a suspend event happens on Android
|
/// Makes it possible for glutin to register a callback when a suspend event happens on Android
|
||||||
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>);
|
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopExt for EventsLoop {
|
impl EventLoopExt for EventLoop {
|
||||||
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>) {
|
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>) {
|
||||||
self.events_loop.set_suspend_callback(cb);
|
self.events_loop.set_suspend_callback(cb);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ use std::ptr;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
EventsLoop,
|
EventLoop,
|
||||||
LogicalSize,
|
LogicalSize,
|
||||||
MonitorId,
|
MonitorId,
|
||||||
Window,
|
Window,
|
||||||
WindowBuilder,
|
WindowBuilder,
|
||||||
};
|
};
|
||||||
use platform::{
|
use platform::{
|
||||||
EventsLoop as LinuxEventsLoop,
|
EventLoop as LinuxEventLoop,
|
||||||
Window as LinuxWindow,
|
Window as LinuxWindow,
|
||||||
};
|
};
|
||||||
use platform::x11::XConnection;
|
use platform::x11::XConnection;
|
||||||
@@ -25,31 +25,31 @@ pub use platform::x11;
|
|||||||
pub use platform::XNotSupported;
|
pub use platform::XNotSupported;
|
||||||
pub use platform::x11::util::WindowType as XWindowType;
|
pub use platform::x11::util::WindowType as XWindowType;
|
||||||
|
|
||||||
/// Additional methods on `EventsLoop` that are specific to Linux.
|
/// Additional methods on `EventLoop` that are specific to Linux.
|
||||||
pub trait EventsLoopExt {
|
pub trait EventLoopExt {
|
||||||
/// Builds a new `EventsLoop` that is forced to use X11.
|
/// Builds a new `EventLoop` that is forced to use X11.
|
||||||
fn new_x11() -> Result<Self, XNotSupported>
|
fn new_x11() -> Result<Self, XNotSupported>
|
||||||
where Self: Sized;
|
where Self: Sized;
|
||||||
|
|
||||||
/// Builds a new `EventsLoop` that is forced to use Wayland.
|
/// Builds a new `EventLoop` that is forced to use Wayland.
|
||||||
fn new_wayland() -> Self
|
fn new_wayland() -> Self
|
||||||
where Self: Sized;
|
where Self: Sized;
|
||||||
|
|
||||||
/// True if the `EventsLoop` uses Wayland.
|
/// True if the `EventLoop` uses Wayland.
|
||||||
fn is_wayland(&self) -> bool;
|
fn is_wayland(&self) -> bool;
|
||||||
|
|
||||||
/// True if the `EventsLoop` uses X11.
|
/// True if the `EventLoop` uses X11.
|
||||||
fn is_x11(&self) -> bool;
|
fn is_x11(&self) -> bool;
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>>;
|
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopExt for EventsLoop {
|
impl EventLoopExt for EventLoop {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_x11() -> Result<Self, XNotSupported> {
|
fn new_x11() -> Result<Self, XNotSupported> {
|
||||||
LinuxEventsLoop::new_x11().map(|ev|
|
LinuxEventLoop::new_x11().map(|ev|
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
events_loop: ev,
|
events_loop: ev,
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
@@ -58,8 +58,8 @@ impl EventsLoopExt for EventsLoop {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_wayland() -> Self {
|
fn new_wayland() -> Self {
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
events_loop: match LinuxEventsLoop::new_wayland() {
|
events_loop: match LinuxEventLoop::new_wayland() {
|
||||||
Ok(e) => e,
|
Ok(e) => e,
|
||||||
Err(_) => panic!() // TODO: propagate
|
Err(_) => panic!() // TODO: propagate
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ use std::os::raw::c_void;
|
|||||||
use libc;
|
use libc;
|
||||||
use winapi::shared::windef::HWND;
|
use winapi::shared::windef::HWND;
|
||||||
|
|
||||||
use {DeviceId, EventsLoop, Icon, MonitorId, Window, WindowBuilder};
|
use {DeviceId, EventLoop, Icon, MonitorId, Window, WindowBuilder};
|
||||||
use platform::EventsLoop as WindowsEventsLoop;
|
use platform::EventLoop as WindowsEventLoop;
|
||||||
|
|
||||||
/// Additional methods on `EventsLoop` that are specific to Windows.
|
/// Additional methods on `EventLoop` that are specific to Windows.
|
||||||
pub trait EventsLoopExt {
|
pub trait EventLoopExt {
|
||||||
/// By default, winit on Windows will attempt to enable process-wide DPI awareness. If that's
|
/// By default, winit on Windows will attempt to enable process-wide DPI awareness. If that's
|
||||||
/// undesirable, you can create an `EventsLoop` using this function instead.
|
/// undesirable, you can create an `EventLoop` using this function instead.
|
||||||
fn new_dpi_unaware() -> Self where Self: Sized;
|
fn new_dpi_unaware() -> Self where Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopExt for EventsLoop {
|
impl EventLoopExt for EventLoop {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn new_dpi_unaware() -> Self {
|
fn new_dpi_unaware() -> Self {
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
events_loop: WindowsEventsLoop::with_dpi_awareness(false),
|
events_loop: WindowsEventLoop::with_dpi_awareness(false),
|
||||||
_marker: ::std::marker::PhantomData,
|
_marker: ::std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,19 +26,19 @@ use CreationError::OsError;
|
|||||||
use events::{Touch, TouchPhase};
|
use events::{Touch, TouchPhase};
|
||||||
use window::MonitorId as RootMonitorId;
|
use window::MonitorId as RootMonitorId;
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
event_rx: Receiver<android_glue::Event>,
|
event_rx: Receiver<android_glue::Event>,
|
||||||
suspend_callback: RefCell<Option<Box<Fn(bool) -> ()>>>,
|
suspend_callback: RefCell<Option<Box<Fn(bool) -> ()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy;
|
pub struct EventLoopProxy;
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
android_glue::add_sender(tx);
|
android_glue::add_sender(tx);
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
event_rx: rx,
|
event_rx: rx,
|
||||||
suspend_callback: Default::default(),
|
suspend_callback: Default::default(),
|
||||||
}
|
}
|
||||||
@@ -155,13 +155,13 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy
|
EventLoopProxy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), ::EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), ::EventLoopClosed> {
|
||||||
android_glue::wake_event_loop();
|
android_glue::wake_event_loop();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ pub struct PlatformSpecificWindowBuilderAttributes;
|
|||||||
pub struct PlatformSpecificHeadlessBuilderAttributes;
|
pub struct PlatformSpecificHeadlessBuilderAttributes;
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(_: &EventsLoop, win_attribs: WindowAttributes,
|
pub fn new(_: &EventLoop, win_attribs: WindowAttributes,
|
||||||
_: PlatformSpecificWindowBuilderAttributes)
|
_: PlatformSpecificWindowBuilderAttributes)
|
||||||
-> Result<Window, CreationError>
|
-> Result<Window, CreationError>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,22 +75,22 @@ pub fn set_main_loop_callback<F>(callback : F) where F : FnMut() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy;
|
pub struct EventLoopProxy;
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), ::EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), ::EventLoopClosed> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
window: Mutex<Option<Arc<Window2>>>,
|
window: Mutex<Option<Arc<Window2>>>,
|
||||||
interrupted: AtomicBool,
|
interrupted: AtomicBool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
window: Mutex::new(None),
|
window: Mutex::new(None),
|
||||||
interrupted: AtomicBool::new(false),
|
interrupted: AtomicBool::new(false),
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,7 +366,7 @@ fn em_try(res: ffi::EMSCRIPTEN_RESULT) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(events_loop: &EventsLoop, attribs: ::WindowAttributes,
|
pub fn new(events_loop: &EventLoop, attribs: ::WindowAttributes,
|
||||||
_pl_attribs: PlatformSpecificWindowBuilderAttributes)
|
_pl_attribs: PlatformSpecificWindowBuilderAttributes)
|
||||||
-> Result<Window, ::CreationError>
|
-> Result<Window, ::CreationError>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -204,13 +204,13 @@ pub struct EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy;
|
pub struct EventLoopProxy;
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
unsafe {
|
unsafe {
|
||||||
if !msg_send![class!(NSThread), isMainThread] {
|
if !msg_send![class!(NSThread), isMainThread] {
|
||||||
panic!("`EventsLoop` can only be created on the main thread on iOS");
|
panic!("`EventLoop` can only be created on the main thread on iOS");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventsLoop { events_queue: Default::default() }
|
EventsLoop { events_queue: Default::default() }
|
||||||
@@ -276,13 +276,13 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy
|
EventLoopProxy
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), ::EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), ::EventLoopClosed> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ impl Default for PlatformSpecificWindowBuilderAttributes {
|
|||||||
// so to be consistent with other platforms we have to change that.
|
// so to be consistent with other platforms we have to change that.
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
ev: &EventsLoop,
|
ev: &EventLoop,
|
||||||
_attributes: WindowAttributes,
|
_attributes: WindowAttributes,
|
||||||
pl_attributes: PlatformSpecificWindowBuilderAttributes,
|
pl_attributes: PlatformSpecificWindowBuilderAttributes,
|
||||||
) -> Result<Window, CreationError> {
|
) -> Result<Window, CreationError> {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use sctk::reexports::client::ConnectError;
|
|||||||
|
|
||||||
use {
|
use {
|
||||||
CreationError,
|
CreationError,
|
||||||
EventsLoopClosed,
|
EventLoopClosed,
|
||||||
Icon,
|
Icon,
|
||||||
MouseCursor,
|
MouseCursor,
|
||||||
ControlFlow,
|
ControlFlow,
|
||||||
@@ -122,15 +122,15 @@ impl MonitorId {
|
|||||||
impl Window {
|
impl Window {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
events_loop: &EventsLoop,
|
events_loop: &EventLoop,
|
||||||
attribs: WindowAttributes,
|
attribs: WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||||
) -> Result<Self, CreationError> {
|
) -> Result<Self, CreationError> {
|
||||||
match *events_loop {
|
match *events_loop {
|
||||||
EventsLoop::Wayland(ref events_loop) => {
|
EventLoop::Wayland(ref events_loop) => {
|
||||||
wayland::Window::new(events_loop, attribs).map(Window::Wayland)
|
wayland::Window::new(events_loop, attribs).map(Window::Wayland)
|
||||||
},
|
},
|
||||||
EventsLoop::X(ref events_loop) => {
|
EventLoop::X(ref events_loop) => {
|
||||||
x11::Window::new(events_loop, attribs, pl_attribs).map(Window::X)
|
x11::Window::new(events_loop, attribs, pl_attribs).map(Window::X)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -389,27 +389,27 @@ unsafe extern "C" fn x_error_callback(
|
|||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum EventsLoop {
|
pub enum EventLoop {
|
||||||
Wayland(wayland::EventsLoop),
|
Wayland(wayland::EventLoop),
|
||||||
X(x11::EventsLoop)
|
X(x11::EventLoop)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum EventsLoopProxy {
|
pub enum EventLoopProxy {
|
||||||
X(x11::EventsLoopProxy),
|
X(x11::EventLoopProxy),
|
||||||
Wayland(wayland::EventsLoopProxy),
|
Wayland(wayland::EventLoopProxy),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
if let Ok(env_var) = env::var(BACKEND_PREFERENCE_ENV_VAR) {
|
if let Ok(env_var) = env::var(BACKEND_PREFERENCE_ENV_VAR) {
|
||||||
match env_var.as_str() {
|
match env_var.as_str() {
|
||||||
"x11" => {
|
"x11" => {
|
||||||
// TODO: propagate
|
// TODO: propagate
|
||||||
return EventsLoop::new_x11().expect("Failed to initialize X11 backend");
|
return EventLoop::new_x11().expect("Failed to initialize X11 backend");
|
||||||
},
|
},
|
||||||
"wayland" => {
|
"wayland" => {
|
||||||
return EventsLoop::new_wayland()
|
return EventLoop::new_wayland()
|
||||||
.expect("Failed to initialize Wayland backend");
|
.expect("Failed to initialize Wayland backend");
|
||||||
},
|
},
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
@@ -419,12 +419,12 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let wayland_err = match EventsLoop::new_wayland() {
|
let wayland_err = match EventLoop::new_wayland() {
|
||||||
Ok(event_loop) => return event_loop,
|
Ok(event_loop) => return event_loop,
|
||||||
Err(err) => err,
|
Err(err) => err,
|
||||||
};
|
};
|
||||||
|
|
||||||
let x11_err = match EventsLoop::new_x11() {
|
let x11_err = match EventLoop::new_x11() {
|
||||||
Ok(event_loop) => return event_loop,
|
Ok(event_loop) => return event_loop,
|
||||||
Err(err) => err,
|
Err(err) => err,
|
||||||
};
|
};
|
||||||
@@ -437,30 +437,30 @@ impl EventsLoop {
|
|||||||
panic!(err_string);
|
panic!(err_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_wayland() -> Result<EventsLoop, ConnectError> {
|
pub fn new_wayland() -> Result<EventLoop, ConnectError> {
|
||||||
wayland::EventsLoop::new()
|
wayland::EventLoop::new()
|
||||||
.map(EventsLoop::Wayland)
|
.map(EventLoop::Wayland)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_x11() -> Result<EventsLoop, XNotSupported> {
|
pub fn new_x11() -> Result<EventLoop, XNotSupported> {
|
||||||
X11_BACKEND
|
X11_BACKEND
|
||||||
.lock()
|
.lock()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(Arc::clone)
|
.map(Arc::clone)
|
||||||
.map(x11::EventsLoop::new)
|
.map(x11::EventLoop::new)
|
||||||
.map(EventsLoop::X)
|
.map(EventLoop::X)
|
||||||
.map_err(|err| err.clone())
|
.map_err(|err| err.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(ref evlp) => evlp
|
EventLoop::Wayland(ref evlp) => evlp
|
||||||
.get_available_monitors()
|
.get_available_monitors()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(MonitorId::Wayland)
|
.map(MonitorId::Wayland)
|
||||||
.collect(),
|
.collect(),
|
||||||
EventsLoop::X(ref evlp) => evlp
|
EventLoop::X(ref evlp) => evlp
|
||||||
.x_connection()
|
.x_connection()
|
||||||
.get_available_monitors()
|
.get_available_monitors()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -472,15 +472,15 @@ impl EventsLoop {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_primary_monitor(&self) -> MonitorId {
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(ref evlp) => MonitorId::Wayland(evlp.get_primary_monitor()),
|
EventLoop::Wayland(ref evlp) => MonitorId::Wayland(evlp.get_primary_monitor()),
|
||||||
EventsLoop::X(ref evlp) => MonitorId::X(evlp.x_connection().get_primary_monitor()),
|
EventLoop::X(ref evlp) => MonitorId::X(evlp.x_connection().get_primary_monitor()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(ref evlp) => EventsLoopProxy::Wayland(evlp.create_proxy()),
|
EventLoop::Wayland(ref evlp) => EventLoopProxy::Wayland(evlp.create_proxy()),
|
||||||
EventsLoop::X(ref evlp) => EventsLoopProxy::X(evlp.create_proxy()),
|
EventLoop::X(ref evlp) => EventLoopProxy::X(evlp.create_proxy()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,8 +488,8 @@ impl EventsLoop {
|
|||||||
where F: FnMut(::Event)
|
where F: FnMut(::Event)
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(ref mut evlp) => evlp.poll_events(callback),
|
EventLoop::Wayland(ref mut evlp) => evlp.poll_events(callback),
|
||||||
EventsLoop::X(ref mut evlp) => evlp.poll_events(callback)
|
EventLoop::X(ref mut evlp) => evlp.poll_events(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -497,33 +497,33 @@ impl EventsLoop {
|
|||||||
where F: FnMut(::Event) -> ControlFlow
|
where F: FnMut(::Event) -> ControlFlow
|
||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(ref mut evlp) => evlp.run_forever(callback),
|
EventLoop::Wayland(ref mut evlp) => evlp.run_forever(callback),
|
||||||
EventsLoop::X(ref mut evlp) => evlp.run_forever(callback)
|
EventLoop::X(ref mut evlp) => evlp.run_forever(callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_wayland(&self) -> bool {
|
pub fn is_wayland(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(_) => true,
|
EventLoop::Wayland(_) => true,
|
||||||
EventsLoop::X(_) => false,
|
EventLoop::X(_) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn x_connection(&self) -> Option<&Arc<XConnection>> {
|
pub fn x_connection(&self) -> Option<&Arc<XConnection>> {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoop::Wayland(_) => None,
|
EventLoop::Wayland(_) => None,
|
||||||
EventsLoop::X(ref ev) => Some(ev.x_connection()),
|
EventLoop::X(ref ev) => Some(ev.x_connection()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
match *self {
|
match *self {
|
||||||
EventsLoopProxy::Wayland(ref proxy) => proxy.wakeup(),
|
EventLoopProxy::Wayland(ref proxy) => proxy.wakeup(),
|
||||||
EventsLoopProxy::X(ref proxy) => proxy.wakeup(),
|
EventLoopProxy::X(ref proxy) => proxy.wakeup(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::fmt;
|
|||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Mutex, Weak};
|
use std::sync::{Arc, Mutex, Weak};
|
||||||
|
|
||||||
use {ControlFlow, EventsLoopClosed, PhysicalPosition, PhysicalSize};
|
use {ControlFlow, EventLoopClosed, PhysicalPosition, PhysicalSize};
|
||||||
|
|
||||||
use super::window::WindowStore;
|
use super::window::WindowStore;
|
||||||
use super::WindowId;
|
use super::WindowId;
|
||||||
@@ -21,13 +21,13 @@ use sctk::reexports::client::protocol::wl_surface::RequestsTrait;
|
|||||||
|
|
||||||
use ModifiersState;
|
use ModifiersState;
|
||||||
|
|
||||||
pub struct EventsLoopSink {
|
pub struct EventLoopSink {
|
||||||
buffer: VecDeque<::Event>,
|
buffer: VecDeque<::Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopSink {
|
impl EventLoopSink {
|
||||||
pub fn new() -> EventsLoopSink {
|
pub fn new() -> EventLoopSink {
|
||||||
EventsLoopSink {
|
EventLoopSink {
|
||||||
buffer: VecDeque::new(),
|
buffer: VecDeque::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,11 +54,11 @@ impl EventsLoopSink {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
// The Event Queue
|
// The Event Queue
|
||||||
pub evq: RefCell<EventQueue>,
|
pub evq: RefCell<EventQueue>,
|
||||||
// our sink, shared with some handlers, buffering the events
|
// our sink, shared with some handlers, buffering the events
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
// Whether or not there is a pending `Awakened` event to be emitted.
|
// Whether or not there is a pending `Awakened` event to be emitted.
|
||||||
pending_wakeup: Arc<AtomicBool>,
|
pending_wakeup: Arc<AtomicBool>,
|
||||||
// The window store
|
// The window store
|
||||||
@@ -73,43 +73,43 @@ pub struct EventsLoop {
|
|||||||
pub seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
pub seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// A handle that can be sent across threads and used to wake up the `EventsLoop`.
|
// A handle that can be sent across threads and used to wake up the `EventLoop`.
|
||||||
//
|
//
|
||||||
// We should only try and wake up the `EventsLoop` if it still exists, so we hold Weak ptrs.
|
// We should only try and wake up the `EventLoop` if it still exists, so we hold Weak ptrs.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy {
|
pub struct EventLoopProxy {
|
||||||
display: Weak<Display>,
|
display: Weak<Display>,
|
||||||
pending_wakeup: Weak<AtomicBool>,
|
pending_wakeup: Weak<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
// Causes the `EventsLoop` to stop blocking on `run_forever` and emit an `Awakened` event.
|
// Causes the `EventLoop` to stop blocking on `run_forever` and emit an `Awakened` event.
|
||||||
//
|
//
|
||||||
// Returns `Err` if the associated `EventsLoop` no longer exists.
|
// Returns `Err` if the associated `EventLoop` no longer exists.
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
let display = self.display.upgrade();
|
let display = self.display.upgrade();
|
||||||
let wakeup = self.pending_wakeup.upgrade();
|
let wakeup = self.pending_wakeup.upgrade();
|
||||||
match (display, wakeup) {
|
match (display, wakeup) {
|
||||||
(Some(display), Some(wakeup)) => {
|
(Some(display), Some(wakeup)) => {
|
||||||
// Update the `EventsLoop`'s `pending_wakeup` flag.
|
// Update the `EventLoop`'s `pending_wakeup` flag.
|
||||||
wakeup.store(true, Ordering::Relaxed);
|
wakeup.store(true, Ordering::Relaxed);
|
||||||
// Cause the `EventsLoop` to break from `dispatch` if it is currently blocked.
|
// Cause the `EventLoop` to break from `dispatch` if it is currently blocked.
|
||||||
let _ = display.sync(|callback| callback.implement(|_, _| {}, ()));
|
let _ = display.sync(|callback| callback.implement(|_, _| {}, ()));
|
||||||
display.flush().map_err(|_| EventsLoopClosed)?;
|
display.flush().map_err(|_| EventLoopClosed)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
_ => Err(EventsLoopClosed),
|
_ => Err(EventLoopClosed),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> Result<EventsLoop, ConnectError> {
|
pub fn new() -> Result<EventLoop, ConnectError> {
|
||||||
let (display, mut event_queue) = Display::connect_to_env()?;
|
let (display, mut event_queue) = Display::connect_to_env()?;
|
||||||
|
|
||||||
let display = Arc::new(display);
|
let display = Arc::new(display);
|
||||||
let pending_wakeup = Arc::new(AtomicBool::new(false));
|
let pending_wakeup = Arc::new(AtomicBool::new(false));
|
||||||
let sink = Arc::new(Mutex::new(EventsLoopSink::new()));
|
let sink = Arc::new(Mutex::new(EventLoopSink::new()));
|
||||||
let store = Arc::new(Mutex::new(WindowStore::new()));
|
let store = Arc::new(Mutex::new(WindowStore::new()));
|
||||||
let seats = Arc::new(Mutex::new(Vec::new()));
|
let seats = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
@@ -143,8 +143,8 @@ impl EventsLoop {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy {
|
EventLoopProxy {
|
||||||
display: Arc::downgrade(&self.display),
|
display: Arc::downgrade(&self.display),
|
||||||
pending_wakeup: Arc::downgrade(&self.pending_wakeup),
|
pending_wakeup: Arc::downgrade(&self.pending_wakeup),
|
||||||
}
|
}
|
||||||
@@ -221,10 +221,10 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Private EventsLoop Internals
|
* Private EventLoop Internals
|
||||||
*/
|
*/
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
fn post_dispatch_triggers(&mut self) {
|
fn post_dispatch_triggers(&mut self) {
|
||||||
let mut sink = self.sink.lock().unwrap();
|
let mut sink = self.sink.lock().unwrap();
|
||||||
// process a possible pending wakeup call
|
// process a possible pending wakeup call
|
||||||
@@ -279,7 +279,7 @@ impl EventsLoop {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct SeatManager {
|
struct SeatManager {
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
store: Arc<Mutex<WindowStore>>,
|
store: Arc<Mutex<WindowStore>>,
|
||||||
seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
seats: Arc<Mutex<Vec<(u32, Proxy<wl_seat::WlSeat>)>>>,
|
||||||
events_loop_proxy: EventsLoopProxy,
|
events_loop_proxy: EventsLoopProxy,
|
||||||
@@ -332,7 +332,7 @@ impl SeatManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct SeatData {
|
struct SeatData {
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
store: Arc<Mutex<WindowStore>>,
|
store: Arc<Mutex<WindowStore>>,
|
||||||
pointer: Option<Proxy<wl_pointer::WlPointer>>,
|
pointer: Option<Proxy<wl_pointer::WlPointer>>,
|
||||||
keyboard: Option<Proxy<wl_keyboard::WlKeyboard>>,
|
keyboard: Option<Proxy<wl_keyboard::WlKeyboard>>,
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ use {ElementState, KeyboardInput, ModifiersState, VirtualKeyCode, WindowEvent};
|
|||||||
|
|
||||||
pub fn init_keyboard(
|
pub fn init_keyboard(
|
||||||
seat: &Proxy<wl_seat::WlSeat>,
|
seat: &Proxy<wl_seat::WlSeat>,
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
events_loop_proxy: EventsLoopProxy,
|
events_loop_proxy: EventLoopProxy,
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
||||||
) -> Proxy<wl_keyboard::WlKeyboard> {
|
) -> Proxy<wl_keyboard::WlKeyboard> {
|
||||||
// { variables to be captured by the closures
|
// { variables to be captured by the closures
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
target_os = "netbsd", target_os = "openbsd"))]
|
target_os = "netbsd", target_os = "openbsd"))]
|
||||||
|
|
||||||
pub use self::window::Window;
|
pub use self::window::Window;
|
||||||
pub use self::event_loop::{EventsLoop, EventsLoopProxy, EventsLoopSink, MonitorId};
|
pub use self::event_loop::{EventLoop, EventLoopProxy, EventLoopSink, MonitorId};
|
||||||
|
|
||||||
use sctk::reexports::client::protocol::wl_surface;
|
use sctk::reexports::client::protocol::wl_surface;
|
||||||
use sctk::reexports::client::Proxy;
|
use sctk::reexports::client::Proxy;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use {ElementState, MouseButton, MouseScrollDelta, TouchPhase, WindowEvent};
|
|||||||
use events::ModifiersState;
|
use events::ModifiersState;
|
||||||
|
|
||||||
use super::DeviceId;
|
use super::DeviceId;
|
||||||
use super::event_loop::EventsLoopSink;
|
use super::event_loop::EventLoopSink;
|
||||||
use super::window::WindowStore;
|
use super::window::WindowStore;
|
||||||
|
|
||||||
use sctk::reexports::client::Proxy;
|
use sctk::reexports::client::Proxy;
|
||||||
@@ -14,7 +14,7 @@ use sctk::reexports::client::protocol::wl_seat::RequestsTrait as SeatRequests;
|
|||||||
|
|
||||||
pub fn implement_pointer(
|
pub fn implement_pointer(
|
||||||
seat: &Proxy<wl_seat::WlSeat>,
|
seat: &Proxy<wl_seat::WlSeat>,
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
store: Arc<Mutex<WindowStore>>,
|
store: Arc<Mutex<WindowStore>>,
|
||||||
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
modifiers_tracker: Arc<Mutex<ModifiersState>>,
|
||||||
) -> Proxy<WlPointer> {
|
) -> Proxy<WlPointer> {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use {TouchPhase, WindowEvent};
|
use {TouchPhase, WindowEvent};
|
||||||
|
|
||||||
use super::{DeviceId, WindowId};
|
use super::{DeviceId, WindowId};
|
||||||
use super::event_loop::EventsLoopSink;
|
use super::event_loop::EventLoopSink;
|
||||||
use super::window::WindowStore;
|
use super::window::WindowStore;
|
||||||
|
|
||||||
use sctk::reexports::client::Proxy;
|
use sctk::reexports::client::Proxy;
|
||||||
@@ -19,7 +19,7 @@ struct TouchPoint {
|
|||||||
|
|
||||||
pub(crate) fn implement_touch(
|
pub(crate) fn implement_touch(
|
||||||
seat: &Proxy<wl_seat::WlSeat>,
|
seat: &Proxy<wl_seat::WlSeat>,
|
||||||
sink: Arc<Mutex<EventsLoopSink>>,
|
sink: Arc<Mutex<EventLoopSink>>,
|
||||||
store: Arc<Mutex<WindowStore>>,
|
store: Arc<Mutex<WindowStore>>,
|
||||||
) -> Proxy<WlTouch> {
|
) -> Proxy<WlTouch> {
|
||||||
let mut pending_ids = Vec::new();
|
let mut pending_ids = Vec::new();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ use sctk::reexports::client::protocol::wl_compositor::RequestsTrait as Composito
|
|||||||
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
|
use sctk::reexports::client::protocol::wl_surface::RequestsTrait as SurfaceRequests;
|
||||||
use sctk::output::OutputMgr;
|
use sctk::output::OutputMgr;
|
||||||
|
|
||||||
use super::{make_wid, EventsLoop, MonitorId, WindowId};
|
use super::{make_wid, EventLoop, MonitorId, WindowId};
|
||||||
use platform::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor};
|
use platform::platform::wayland::event_loop::{get_available_monitors, get_primary_monitor};
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
@@ -28,7 +28,7 @@ pub struct Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(evlp: &EventsLoop, attributes: WindowAttributes) -> Result<Window, CreationError> {
|
pub fn new(evlp: &EventLoop, attributes: WindowAttributes) -> Result<Window, CreationError> {
|
||||||
let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600));
|
let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600));
|
||||||
// Create the window
|
// Create the window
|
||||||
let size = Arc::new(Mutex::new((width, height)));
|
let size = Arc::new(Mutex::new((width, height)));
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ use {
|
|||||||
CreationError,
|
CreationError,
|
||||||
DeviceEvent,
|
DeviceEvent,
|
||||||
Event,
|
Event,
|
||||||
EventsLoopClosed,
|
EventLoopClosed,
|
||||||
KeyboardInput,
|
KeyboardInput,
|
||||||
LogicalPosition,
|
LogicalPosition,
|
||||||
LogicalSize,
|
LogicalSize,
|
||||||
@@ -41,7 +41,7 @@ use platform::PlatformSpecificWindowBuilderAttributes;
|
|||||||
use self::dnd::{Dnd, DndState};
|
use self::dnd::{Dnd, DndState};
|
||||||
use self::ime::{ImeReceiver, ImeSender, ImeCreationError, Ime};
|
use self::ime::{ImeReceiver, ImeSender, ImeCreationError, Ime};
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
xconn: Arc<XConnection>,
|
xconn: Arc<XConnection>,
|
||||||
wm_delete_window: ffi::Atom,
|
wm_delete_window: ffi::Atom,
|
||||||
dnd: Dnd,
|
dnd: Dnd,
|
||||||
@@ -60,14 +60,14 @@ pub struct EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy {
|
pub struct EventLoopProxy {
|
||||||
pending_wakeup: Weak<AtomicBool>,
|
pending_wakeup: Weak<AtomicBool>,
|
||||||
xconn: Weak<XConnection>,
|
xconn: Weak<XConnection>,
|
||||||
wakeup_dummy_window: ffi::Window,
|
wakeup_dummy_window: ffi::Window,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new(xconn: Arc<XConnection>) -> EventsLoop {
|
pub fn new(xconn: Arc<XConnection>) -> EventLoop {
|
||||||
let root = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };
|
let root = unsafe { (xconn.xlib.XDefaultRootWindow)(xconn.display) };
|
||||||
|
|
||||||
let wm_delete_window = unsafe { xconn.get_atom_unchecked(b"WM_DELETE_WINDOW\0") };
|
let wm_delete_window = unsafe { xconn.get_atom_unchecked(b"WM_DELETE_WINDOW\0") };
|
||||||
@@ -142,7 +142,7 @@ impl EventsLoop {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = EventsLoop {
|
let result = EventLoop {
|
||||||
xconn,
|
xconn,
|
||||||
wm_delete_window,
|
wm_delete_window,
|
||||||
dnd,
|
dnd,
|
||||||
@@ -177,8 +177,8 @@ impl EventsLoop {
|
|||||||
&self.xconn
|
&self.xconn
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy {
|
EventLoopProxy {
|
||||||
pending_wakeup: Arc::downgrade(&self.pending_wakeup),
|
pending_wakeup: Arc::downgrade(&self.pending_wakeup),
|
||||||
xconn: Arc::downgrade(&self.xconn),
|
xconn: Arc::downgrade(&self.xconn),
|
||||||
wakeup_dummy_window: self.wakeup_dummy_window,
|
wakeup_dummy_window: self.wakeup_dummy_window,
|
||||||
@@ -1181,15 +1181,15 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
// Update the `EventsLoop`'s `pending_wakeup` flag.
|
// Update the `EventLoop`'s `pending_wakeup` flag.
|
||||||
let display = match (self.pending_wakeup.upgrade(), self.xconn.upgrade()) {
|
let display = match (self.pending_wakeup.upgrade(), self.xconn.upgrade()) {
|
||||||
(Some(wakeup), Some(display)) => {
|
(Some(wakeup), Some(display)) => {
|
||||||
wakeup.store(true, atomic::Ordering::Relaxed);
|
wakeup.store(true, atomic::Ordering::Relaxed);
|
||||||
display
|
display
|
||||||
},
|
},
|
||||||
_ => return Err(EventsLoopClosed),
|
_ => return Err(EventLoopClosed),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Push an event on the X event queue so that methods run_forever will advance.
|
// Push an event on the X event queue so that methods run_forever will advance.
|
||||||
@@ -1269,7 +1269,7 @@ impl Deref for Window {
|
|||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
event_loop: &EventsLoop,
|
event_loop: &EventLoop,
|
||||||
attribs: WindowAttributes,
|
attribs: WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes
|
pl_attribs: PlatformSpecificWindowBuilderAttributes
|
||||||
) -> Result<Self, CreationError> {
|
) -> Result<Self, CreationError> {
|
||||||
@@ -1354,7 +1354,7 @@ enum ScrollOrientation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Device {
|
impl Device {
|
||||||
fn new(el: &EventsLoop, info: &ffi::XIDeviceInfo) -> Self {
|
fn new(el: &EventLoop, info: &ffi::XIDeviceInfo) -> Self {
|
||||||
let name = unsafe { CStr::from_ptr(info.name).to_string_lossy() };
|
let name = unsafe { CStr::from_ptr(info.name).to_string_lossy() };
|
||||||
let mut scroll_axes = Vec::new();
|
let mut scroll_axes = Vec::new();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use platform::PlatformSpecificWindowBuilderAttributes;
|
|||||||
use platform::x11::MonitorId as X11MonitorId;
|
use platform::x11::MonitorId as X11MonitorId;
|
||||||
use window::MonitorId as RootMonitorId;
|
use window::MonitorId as RootMonitorId;
|
||||||
|
|
||||||
use super::{ffi, util, ImeSender, XConnection, XError, WindowId, EventsLoop};
|
use super::{ffi, util, ImeSender, XConnection, XError, WindowId, EventLoop};
|
||||||
|
|
||||||
unsafe extern "C" fn visibility_predicate(
|
unsafe extern "C" fn visibility_predicate(
|
||||||
_display: *mut ffi::Display,
|
_display: *mut ffi::Display,
|
||||||
@@ -70,7 +70,7 @@ pub struct UnownedWindow {
|
|||||||
|
|
||||||
impl UnownedWindow {
|
impl UnownedWindow {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
event_loop: &EventsLoop,
|
event_loop: &EventLoop,
|
||||||
window_attrs: WindowAttributes,
|
window_attrs: WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||||
) -> Result<UnownedWindow, CreationError> {
|
) -> Result<UnownedWindow, CreationError> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use {ControlFlow, EventsLoopClosed};
|
use {ControlFlow, EventLoopClosed};
|
||||||
use cocoa::{self, appkit, foundation};
|
use cocoa::{self, appkit, foundation};
|
||||||
use cocoa::appkit::{NSApplication, NSEvent, NSEventMask, NSEventModifierFlags, NSEventPhase, NSView, NSWindow};
|
use cocoa::appkit::{NSApplication, NSEvent, NSEventMask, NSEventModifierFlags, NSEventPhase, NSView, NSWindow};
|
||||||
use events::{self, ElementState, Event, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
|
use events::{self, ElementState, Event, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
|
||||||
@@ -9,12 +9,12 @@ use std;
|
|||||||
use std::os::raw::*;
|
use std::os::raw::*;
|
||||||
use super::DeviceId;
|
use super::DeviceId;
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
modifiers: Modifiers,
|
modifiers: Modifiers,
|
||||||
pub shared: Arc<Shared>,
|
pub shared: Arc<Shared>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// State shared between the `EventsLoop` and its registered windows.
|
// State shared between the `EventLoop` and its registered windows.
|
||||||
pub struct Shared {
|
pub struct Shared {
|
||||||
pub windows: Mutex<Vec<Weak<Window2>>>,
|
pub windows: Mutex<Vec<Weak<Window2>>>,
|
||||||
pub pending_events: Mutex<VecDeque<Event>>,
|
pub pending_events: Mutex<VecDeque<Event>>,
|
||||||
@@ -42,7 +42,7 @@ struct Modifiers {
|
|||||||
// Wrapping the user callback in a type allows us to:
|
// Wrapping the user callback in a type allows us to:
|
||||||
//
|
//
|
||||||
// - ensure the callback pointer is never accidentally cloned
|
// - ensure the callback pointer is never accidentally cloned
|
||||||
// - ensure that only the `EventsLoop` can `store` and `drop` the callback pointer
|
// - ensure that only the `EventLoop` can `store` and `drop` the callback pointer
|
||||||
// - Share access to the user callback with the NSWindow callbacks.
|
// - Share access to the user callback with the NSWindow callbacks.
|
||||||
pub struct UserCallback {
|
pub struct UserCallback {
|
||||||
mutex: Mutex<Option<*mut FnMut(Event)>>,
|
mutex: Mutex<Option<*mut FnMut(Event)>>,
|
||||||
@@ -160,17 +160,17 @@ impl UserCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
// Mark this thread as the main thread of the Cocoa event system.
|
// Mark this thread as the main thread of the Cocoa event system.
|
||||||
//
|
//
|
||||||
// This must be done before any worker threads get a chance to call it
|
// This must be done before any worker threads get a chance to call it
|
||||||
// (e.g., via `EventsLoopProxy::wakeup()`), causing a wrong thread to be
|
// (e.g., via `EventLoopProxy::wakeup()`), causing a wrong thread to be
|
||||||
// marked as the main thread.
|
// marked as the main thread.
|
||||||
unsafe { appkit::NSApp(); }
|
unsafe { appkit::NSApp(); }
|
||||||
|
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
shared: Arc::new(Shared::new()),
|
shared: Arc::new(Shared::new()),
|
||||||
modifiers: Modifiers::new(),
|
modifiers: Modifiers::new(),
|
||||||
}
|
}
|
||||||
@@ -521,7 +521,7 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Proxy {
|
impl Proxy {
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
// Awaken the event loop by triggering `NSApplicationActivatedEventType`.
|
// Awaken the event loop by triggering `NSApplicationActivatedEventType`.
|
||||||
unsafe {
|
unsafe {
|
||||||
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
|
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![cfg(target_os = "macos")]
|
#![cfg(target_os = "macos")]
|
||||||
|
|
||||||
pub use self::events_loop::{EventsLoop, Proxy as EventsLoopProxy};
|
pub use self::events_loop::{EventLoop, Proxy as EventLoopProxy};
|
||||||
pub use self::monitor::MonitorId;
|
pub use self::monitor::MonitorId;
|
||||||
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
|
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -24,7 +24,7 @@ impl ::std::ops::Deref for Window {
|
|||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
|
|
||||||
pub fn new(events_loop: &EventsLoop,
|
pub fn new(events_loop: &EventLoop,
|
||||||
attributes: ::WindowAttributes,
|
attributes: ::WindowAttributes,
|
||||||
pl_attribs: PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError>
|
pl_attribs: PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use cocoa::foundation::{NSString, NSUInteger};
|
|||||||
use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds};
|
use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds};
|
||||||
|
|
||||||
use {PhysicalPosition, PhysicalSize};
|
use {PhysicalPosition, PhysicalSize};
|
||||||
use super::EventsLoop;
|
use super::EventLoop;
|
||||||
use super::window::{IdRef, Window2};
|
use super::window::{IdRef, Window2};
|
||||||
|
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
@@ -30,7 +30,7 @@ pub fn get_primary_monitor() -> MonitorId {
|
|||||||
id
|
id
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
||||||
get_available_monitors()
|
get_available_monitors()
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ use {
|
|||||||
use CreationError::OsError;
|
use CreationError::OsError;
|
||||||
use os::macos::{ActivationPolicy, WindowExt};
|
use os::macos::{ActivationPolicy, WindowExt};
|
||||||
use platform::platform::{ffi, util};
|
use platform::platform::{ffi, util};
|
||||||
use platform::platform::events_loop::{EventsLoop, Shared};
|
use platform::platform::events_loop::{EventLoop, Shared};
|
||||||
use platform::platform::view::{new_view, set_ime_spot};
|
use platform::platform::view::{new_view, set_ime_spot};
|
||||||
use window::MonitorId as RootMonitorId;
|
use window::MonitorId as RootMonitorId;
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ pub struct WindowDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WindowDelegate {
|
impl WindowDelegate {
|
||||||
// Emits an event via the `EventsLoop`'s callback or stores it in the pending queue.
|
// Emits an event via the `EventLoop`'s callback or stores it in the pending queue.
|
||||||
pub fn emit_event(state: &mut DelegateState, window_event: WindowEvent) {
|
pub fn emit_event(state: &mut DelegateState, window_event: WindowEvent) {
|
||||||
let window_id = get_window_id(*state.window);
|
let window_id = get_window_id(*state.window);
|
||||||
let event = Event::WindowEvent {
|
let event = Event::WindowEvent {
|
||||||
@@ -543,7 +543,7 @@ unsafe fn get_current_monitor(window: id) -> RootMonitorId {
|
|||||||
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
|
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
|
||||||
let value = NSDictionary::valueForKey_(desc, *key);
|
let value = NSDictionary::valueForKey_(desc, *key);
|
||||||
let display_id = msg_send![value, unsignedIntegerValue];
|
let display_id = msg_send![value, unsignedIntegerValue];
|
||||||
RootMonitorId { inner: EventsLoop::make_monitor_from_display(display_id) }
|
RootMonitorId { inner: EventLoop::make_monitor_from_display(display_id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Window2 {
|
impl Drop for Window2 {
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ use winapi::um::winnt::{LONG, LPCSTR, SHORT};
|
|||||||
use {
|
use {
|
||||||
ControlFlow,
|
ControlFlow,
|
||||||
Event,
|
Event,
|
||||||
EventsLoopClosed,
|
EventLoopClosed,
|
||||||
KeyboardInput,
|
KeyboardInput,
|
||||||
LogicalPosition,
|
LogicalPosition,
|
||||||
LogicalSize,
|
LogicalSize,
|
||||||
@@ -133,19 +133,19 @@ impl Inserter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventsLoop {
|
pub struct EventLoop {
|
||||||
// Id of the background thread from the Win32 API.
|
// Id of the background thread from the Win32 API.
|
||||||
thread_id: DWORD,
|
thread_id: DWORD,
|
||||||
// Receiver for the events. The sender is in the background thread.
|
// Receiver for the events. The sender is in the background thread.
|
||||||
receiver: mpsc::Receiver<Event>,
|
receiver: mpsc::Receiver<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
pub fn new() -> EventsLoop {
|
pub fn new() -> EventLoop {
|
||||||
Self::with_dpi_awareness(true)
|
Self::with_dpi_awareness(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_dpi_awareness(dpi_aware: bool) -> EventsLoop {
|
pub fn with_dpi_awareness(dpi_aware: bool) -> EventLoop {
|
||||||
become_dpi_aware(dpi_aware);
|
become_dpi_aware(dpi_aware);
|
||||||
|
|
||||||
// The main events transfer channel.
|
// The main events transfer channel.
|
||||||
@@ -211,7 +211,7 @@ impl EventsLoop {
|
|||||||
processthreadsapi::GetThreadId(handle)
|
processthreadsapi::GetThreadId(handle)
|
||||||
};
|
};
|
||||||
|
|
||||||
EventsLoop {
|
EventLoop {
|
||||||
thread_id,
|
thread_id,
|
||||||
receiver: rx,
|
receiver: rx,
|
||||||
}
|
}
|
||||||
@@ -247,8 +247,8 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_proxy(&self) -> EventsLoopProxy {
|
pub fn create_proxy(&self) -> EventLoopProxy {
|
||||||
EventsLoopProxy {
|
EventLoopProxy {
|
||||||
thread_id: self.thread_id,
|
thread_id: self.thread_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ impl EventsLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for EventsLoop {
|
impl Drop for EventLoop {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Posting `WM_QUIT` will cause `GetMessage` to stop.
|
// Posting `WM_QUIT` will cause `GetMessage` to stop.
|
||||||
@@ -277,12 +277,12 @@ impl Drop for EventsLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EventsLoopProxy {
|
pub struct EventLoopProxy {
|
||||||
thread_id: DWORD,
|
thread_id: DWORD,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if winuser::PostThreadMessageA(self.thread_id, *WAKEUP_MSG_ID, 0, 0) != 0 {
|
if winuser::PostThreadMessageA(self.thread_id, *WAKEUP_MSG_ID, 0, 0) != 0 {
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -294,7 +294,7 @@ impl EventsLoopProxy {
|
|||||||
// > idThread does not have a message queue. GetLastError returns
|
// > idThread does not have a message queue. GetLastError returns
|
||||||
// > ERROR_NOT_ENOUGH_QUOTA when the message limit is hit.
|
// > ERROR_NOT_ENOUGH_QUOTA when the message limit is hit.
|
||||||
// TODO: handle ERROR_NOT_ENOUGH_QUOTA
|
// TODO: handle ERROR_NOT_ENOUGH_QUOTA
|
||||||
Err(EventsLoopClosed)
|
Err(EventLoopClosed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,7 +335,7 @@ impl EventsLoopProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
// Message sent by the `EventsLoopProxy` when we want to wake up the thread.
|
// Message sent by the `EventLoopProxy` when we want to wake up the thread.
|
||||||
// WPARAM and LPARAM are unused.
|
// WPARAM and LPARAM are unused.
|
||||||
static ref WAKEUP_MSG_ID: u32 = {
|
static ref WAKEUP_MSG_ID: u32 = {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use winapi;
|
use winapi;
|
||||||
use winapi::shared::windef::HWND;
|
use winapi::shared::windef::HWND;
|
||||||
|
|
||||||
pub use self::events_loop::{EventsLoop, EventsLoopProxy};
|
pub use self::events_loop::{EventLoop, EventLoopProxy};
|
||||||
pub use self::monitor::MonitorId;
|
pub use self::monitor::MonitorId;
|
||||||
pub use self::window::Window;
|
pub use self::window::Window;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use winapi::um::winuser;
|
|||||||
use std::{mem, ptr};
|
use std::{mem, ptr};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
use super::{EventsLoop, util};
|
use super::{EventLoop, util};
|
||||||
use dpi::{PhysicalPosition, PhysicalSize};
|
use dpi::{PhysicalPosition, PhysicalSize};
|
||||||
use platform::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi};
|
use platform::platform::dpi::{dpi_to_scale_factor, get_monitor_dpi};
|
||||||
use platform::platform::window::Window;
|
use platform::platform::window::Window;
|
||||||
@@ -71,7 +71,7 @@ pub fn get_primary_monitor() -> MonitorId {
|
|||||||
MonitorId::from_hmonitor(hmonitor)
|
MonitorId::from_hmonitor(hmonitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventsLoop {
|
impl EventLoop {
|
||||||
// TODO: Investigate opportunities for caching
|
// TODO: Investigate opportunities for caching
|
||||||
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
pub fn get_available_monitors(&self) -> VecDeque<MonitorId> {
|
||||||
get_available_monitors()
|
get_available_monitors()
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ use {
|
|||||||
};
|
};
|
||||||
use platform::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId};
|
use platform::platform::{Cursor, PlatformSpecificWindowBuilderAttributes, WindowId};
|
||||||
use platform::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi};
|
use platform::platform::dpi::{dpi_to_scale_factor, get_hwnd_dpi};
|
||||||
use platform::platform::events_loop::{self, EventsLoop, DESTROY_MSG_ID, INITIAL_DPI_MSG_ID};
|
use platform::platform::events_loop::{self, DESTROY_MSG_ID, EventLoop, INITIAL_DPI_MSG_ID, WindowState};
|
||||||
use platform::platform::events_loop::WindowState;
|
|
||||||
use platform::platform::icon::{self, IconType, WinIcon};
|
use platform::platform::icon::{self, IconType, WinIcon};
|
||||||
use platform::platform::monitor::get_available_monitors;
|
use platform::platform::monitor::get_available_monitors;
|
||||||
use platform::platform::raw_input::register_all_mice_and_keyboards_for_raw_input;
|
use platform::platform::raw_input::register_all_mice_and_keyboards_for_raw_input;
|
||||||
@@ -46,7 +45,7 @@ pub struct Window {
|
|||||||
window_state: Arc<Mutex<WindowState>>,
|
window_state: Arc<Mutex<WindowState>>,
|
||||||
|
|
||||||
// The events loop proxy.
|
// The events loop proxy.
|
||||||
events_loop_proxy: events_loop::EventsLoopProxy,
|
events_loop_proxy: events_loop::EventLoopProxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903
|
// https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903
|
||||||
@@ -73,7 +72,7 @@ unsafe fn unjust_window_rect(prc: &mut RECT, style: DWORD, ex_style: DWORD) -> B
|
|||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
events_loop: &EventsLoop,
|
events_loop: &EventLoop,
|
||||||
w_attr: WindowAttributes,
|
w_attr: WindowAttributes,
|
||||||
pl_attr: PlatformSpecificWindowBuilderAttributes,
|
pl_attr: PlatformSpecificWindowBuilderAttributes,
|
||||||
) -> Result<Window, CreationError> {
|
) -> Result<Window, CreationError> {
|
||||||
@@ -728,7 +727,7 @@ impl Window {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_current_monitor(&self) -> RootMonitorId {
|
pub fn get_current_monitor(&self) -> RootMonitorId {
|
||||||
RootMonitorId {
|
RootMonitorId {
|
||||||
inner: EventsLoop::get_current_monitor(self.window.0),
|
inner: EventLoop::get_current_monitor(self.window.0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -807,7 +806,7 @@ unsafe fn init(
|
|||||||
mut attributes: WindowAttributes,
|
mut attributes: WindowAttributes,
|
||||||
mut pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
mut pl_attribs: PlatformSpecificWindowBuilderAttributes,
|
||||||
inserter: events_loop::Inserter,
|
inserter: events_loop::Inserter,
|
||||||
events_loop_proxy: events_loop::EventsLoopProxy,
|
events_loop_proxy: events_loop::EventLoopProxy,
|
||||||
) -> Result<Window, CreationError> {
|
) -> Result<Window, CreationError> {
|
||||||
let title = OsStr::new(&attributes.title)
|
let title = OsStr::new(&attributes.title)
|
||||||
.encode_wide()
|
.encode_wide()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::collections::vec_deque::IntoIter as VecDequeIter;
|
|||||||
|
|
||||||
use {
|
use {
|
||||||
CreationError,
|
CreationError,
|
||||||
EventsLoop,
|
EventLoop,
|
||||||
Icon,
|
Icon,
|
||||||
LogicalPosition,
|
LogicalPosition,
|
||||||
LogicalSize,
|
LogicalSize,
|
||||||
@@ -142,7 +142,7 @@ impl WindowBuilder {
|
|||||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||||
/// out of memory, etc.
|
/// out of memory, etc.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn build(mut self, events_loop: &EventsLoop) -> Result<Window, CreationError> {
|
pub fn build(mut self, events_loop: &EventLoop) -> Result<Window, CreationError> {
|
||||||
self.window.dimensions = Some(self.window.dimensions.unwrap_or_else(|| {
|
self.window.dimensions = Some(self.window.dimensions.unwrap_or_else(|| {
|
||||||
if let Some(ref monitor) = self.window.fullscreen {
|
if let Some(ref monitor) = self.window.fullscreen {
|
||||||
// resizing the window to the dimensions of the monitor when fullscreen
|
// resizing the window to the dimensions of the monitor when fullscreen
|
||||||
@@ -170,7 +170,7 @@ impl Window {
|
|||||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||||
/// out of memory, etc.
|
/// out of memory, etc.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(events_loop: &EventsLoop) -> Result<Window, CreationError> {
|
pub fn new(events_loop: &EventLoop) -> Result<Window, CreationError> {
|
||||||
let builder = WindowBuilder::new();
|
let builder = WindowBuilder::new();
|
||||||
builder.build(events_loop)
|
builder.build(events_loop)
|
||||||
}
|
}
|
||||||
@@ -408,7 +408,7 @@ impl Window {
|
|||||||
|
|
||||||
/// Returns the list of all the monitors available on the system.
|
/// Returns the list of all the monitors available on the system.
|
||||||
///
|
///
|
||||||
/// This is the same as `EventsLoop::get_available_monitors`, and is provided for convenience.
|
/// This is the same as `EventLoop::get_available_monitors`, and is provided for convenience.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_available_monitors(&self) -> AvailableMonitorsIter {
|
pub fn get_available_monitors(&self) -> AvailableMonitorsIter {
|
||||||
let data = self.window.get_available_monitors();
|
let data = self.window.get_available_monitors();
|
||||||
@@ -417,7 +417,7 @@ impl Window {
|
|||||||
|
|
||||||
/// Returns the primary monitor of the system.
|
/// Returns the primary monitor of the system.
|
||||||
///
|
///
|
||||||
/// This is the same as `EventsLoop::get_primary_monitor`, and is provided for convenience.
|
/// This is the same as `EventLoop::get_primary_monitor`, and is provided for convenience.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_primary_monitor(&self) -> MonitorId {
|
pub fn get_primary_monitor(&self) -> MonitorId {
|
||||||
MonitorId { inner: self.window.get_primary_monitor() }
|
MonitorId { inner: self.window.get_primary_monitor() }
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ fn needs_send<T:Send>() {}
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn events_loop_proxy_send() {
|
fn events_loop_proxy_send() {
|
||||||
// ensures that `winit::EventsLoopProxy` implements `Send`
|
// ensures that `winit::EventLoopProxy` implements `Send`
|
||||||
needs_send::<winit::EventsLoopProxy>();
|
needs_send::<winit::EventLoopProxy>();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user