Skip to content

Commit

Permalink
Rename EventsLoop and associated types to EventLoop
Browse files Browse the repository at this point in the history
  • Loading branch information
Osspial committed Nov 9, 2018
1 parent 30aa5a5 commit 529c085
Show file tree
Hide file tree
Showing 38 changed files with 246 additions and 247 deletions.
2 changes: 1 addition & 1 deletion examples/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate winit;
use winit::{Event, ElementState, MouseCursor, WindowEvent, KeyboardInput, ControlFlow};

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();
window.set_title("A fantastic window!");
Expand Down
2 changes: 1 addition & 1 deletion examples/cursor_grab.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let window = winit::WindowBuilder::new()
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
Expand Down
2 changes: 1 addition & 1 deletion examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::{self, Write};
use winit::{ControlFlow, Event, WindowEvent};

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

// enumerating monitors
let monitor = {
Expand Down
2 changes: 1 addition & 1 deletion examples/handling_close.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let _window = winit::WindowBuilder::new()
.with_title("Your faithful window")
Expand Down
2 changes: 1 addition & 1 deletion examples/min_max_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate winit;
use winit::dpi::LogicalSize;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let window = winit::WindowBuilder::new()
.build(&events_loop)
Expand Down
2 changes: 1 addition & 1 deletion examples/monitor_list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let event_loop = winit::EventsLoop::new();
let event_loop = winit::EventLoop::new();
let window = winit::WindowBuilder::new().build(&event_loop).unwrap();
println!("{:#?}\nPrimary: {:#?}", window.get_available_monitors(), window.get_primary_monitor());
}
2 changes: 1 addition & 1 deletion examples/multiwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ extern crate winit;
use std::collections::HashMap;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let mut windows = HashMap::new();
for _ in 0..3 {
Expand Down
2 changes: 1 addition & 1 deletion examples/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let _window = winit::WindowBuilder::new()
.with_title("A fantastic window!")
Expand Down
2 changes: 1 addition & 1 deletion examples/resizable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let mut resizable = false;

Expand Down
2 changes: 1 addition & 1 deletion examples/transparent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let window = winit::WindowBuilder::new().with_decorations(false)
.with_transparency(true)
Expand Down
2 changes: 1 addition & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate winit;

fn main() {
let mut events_loop = winit::EventsLoop::new();
let mut events_loop = winit::EventLoop::new();

let _window = winit::WindowBuilder::new()
.with_title("A fantastic window!")
Expand Down
2 changes: 1 addition & 1 deletion examples/window_icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
// feature enabled).
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()
.with_title("An iconic window!")
Expand Down
86 changes: 43 additions & 43 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
//!
//! # Building a window
//!
//! Before you can build a window, you first need to build an `EventsLoop`. This is done with the
//! `EventsLoop::new()` function. Example:
//! Before you can build a window, you first need to build an `EventLoop`. This is done with the
//! `EventLoop::new()` function. Example:
//!
//! ```no_run
//! use winit::EventsLoop;
//! let events_loop = EventsLoop::new();
//! use winit::EventLoop;
//! let events_loop = EventLoop::new();
//! ```
//!
//! Once this is done there are two ways to create a window:
Expand All @@ -25,7 +25,7 @@
//! 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 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.
//!
//! There are two ways to do so. The first is to call `events_loop.poll_events(...)`, which will
Expand All @@ -36,8 +36,8 @@
//! ```no_run
//! use winit::{Event, WindowEvent};
//! use winit::dpi::LogicalSize;
//! # use winit::EventsLoop;
//! # let mut events_loop = EventsLoop::new();
//! # use winit::EventLoop;
//! # let mut events_loop = EventLoop::new();
//!
//! loop {
//! events_loop.poll_events(|event| {
Expand All @@ -59,8 +59,8 @@
//!
//! ```no_run
//! use winit::{ControlFlow, Event, WindowEvent};
//! # use winit::EventsLoop;
//! # let mut events_loop = EventsLoop::new();
//! # use winit::EventLoop;
//! # let mut events_loop = EventLoop::new();
//!
//! events_loop.run_forever(|event| {
//! match event {
Expand Down Expand Up @@ -134,9 +134,9 @@ pub mod os;
/// # Example
///
/// ```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();
///
/// events_loop.run_forever(|event| {
Expand Down Expand Up @@ -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
/// 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
/// 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
/// `Window` created from this `EventsLoop` _can_ be sent to an other thread, and the
/// `EventsLoopProxy` allows you to wakeup an `EventsLoop` from an other thread.
pub struct EventsLoop {
events_loop: platform::EventsLoop,
/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
/// `EventLoopProxy` allows you to wakeup an `EventLoop` from an other thread.
pub struct EventLoop {
events_loop: platform::EventLoop,
_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 {
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.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
Expand All @@ -211,16 +211,16 @@ pub enum ControlFlow {
Break,
}

impl EventsLoop {
impl EventLoop {
/// Builds a new events loop.
///
/// 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`.
/// 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.
pub fn new() -> EventsLoop {
EventsLoop {
events_loop: platform::EventsLoop::new(),
pub fn new() -> EventLoop {
EventLoop {
events_loop: platform::EventLoop::new(),
_marker: ::std::marker::PhantomData,
}
}
Expand Down Expand Up @@ -264,52 +264,52 @@ impl EventsLoop {
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.
pub fn create_proxy(&self) -> EventsLoopProxy {
EventsLoopProxy {
pub fn create_proxy(&self) -> EventLoopProxy {
EventLoopProxy {
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)]
pub struct EventsLoopProxy {
events_loop_proxy: platform::EventsLoopProxy,
pub struct EventLoopProxy {
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 {
fmtr.pad("EventsLoopProxy { .. }")
fmtr.pad("EventLoopProxy { .. }")
}
}

impl EventsLoopProxy {
/// Wake up the `EventsLoop` from which this proxy was created.
impl EventLoopProxy {
/// 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.
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
/// Returns an `Err` if the associated `EventLoop` no longer exists.
pub fn wakeup(&self) -> Result<(), EventLoopClosed> {
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.
#[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 {
write!(f, "{}", std::error::Error::description(self))
}
}

impl std::error::Error for EventsLoopClosed {
impl std::error::Error for EventLoopClosed {
fn description(&self) -> &str {
"Tried to wake up a closed `EventsLoop`"
"Tried to wake up a closed `EventLoop`"
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/os/android.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#![cfg(any(target_os = "android"))]

use std::os::raw::c_void;
use EventsLoop;
use EventLoop;
use Window;
use WindowBuilder;

/// Additional methods on `EventsLoop` that are specific to Android.
pub trait EventsLoopExt {
/// Additional methods on `EventLoop` that are specific to Android.
pub trait EventLoopExt {
/// 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) -> ()>>);
}

impl EventsLoopExt for EventsLoop {
impl EventLoopExt for EventLoop {
fn set_suspend_callback(&self, cb: Option<Box<Fn(bool) -> ()>>) {
self.events_loop.set_suspend_callback(cb);
}
Expand Down
26 changes: 13 additions & 13 deletions src/os/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use std::ptr;
use std::sync::Arc;

use {
EventsLoop,
EventLoop,
LogicalSize,
MonitorId,
Window,
WindowBuilder,
};
use platform::{
EventsLoop as LinuxEventsLoop,
EventLoop as LinuxEventLoop,
Window as LinuxWindow,
};
use platform::x11::XConnection;
Expand All @@ -25,31 +25,31 @@ pub use platform::x11;
pub use platform::XNotSupported;
pub use platform::x11::util::WindowType as XWindowType;

/// Additional methods on `EventsLoop` that are specific to Linux.
pub trait EventsLoopExt {
/// Builds a new `EventsLoop` that is forced to use X11.
/// Additional methods on `EventLoop` that are specific to Linux.
pub trait EventLoopExt {
/// Builds a new `EventLoop` that is forced to use X11.
fn new_x11() -> Result<Self, XNotSupported>
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
where Self: Sized;

/// True if the `EventsLoop` uses Wayland.
/// True if the `EventLoop` uses Wayland.
fn is_wayland(&self) -> bool;

/// True if the `EventsLoop` uses X11.
/// True if the `EventLoop` uses X11.
fn is_x11(&self) -> bool;

#[doc(hidden)]
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>>;
}

impl EventsLoopExt for EventsLoop {
impl EventLoopExt for EventLoop {
#[inline]
fn new_x11() -> Result<Self, XNotSupported> {
LinuxEventsLoop::new_x11().map(|ev|
EventsLoop {
LinuxEventLoop::new_x11().map(|ev|
EventLoop {
events_loop: ev,
_marker: ::std::marker::PhantomData,
}
Expand All @@ -58,8 +58,8 @@ impl EventsLoopExt for EventsLoop {

#[inline]
fn new_wayland() -> Self {
EventsLoop {
events_loop: match LinuxEventsLoop::new_wayland() {
EventLoop {
events_loop: match LinuxEventLoop::new_wayland() {
Ok(e) => e,
Err(_) => panic!() // TODO: propagate
},
Expand Down
Loading

0 comments on commit 529c085

Please sign in to comment.