Remove api_transition macro (#279)

* Remove api_transition macro

* Rename Window2 to Window

* Try fix X11 code
This commit is contained in:
tomaka 2017-09-06 17:32:24 +02:00 committed by GitHub
parent 0ada6c15ea
commit 342d5d8587
13 changed files with 97 additions and 247 deletions

View file

@ -1,144 +0,0 @@
//! This temporary module generates types that wrap around the old API (winit v5 and below) and
//! expose the new API (winit v6 and above).
//!
//! This is temporary so that existing backends can smoothly transition. After all implementations
//! have finished transitionning, this module should disappear.
#[cfg(any(target_os = "android", target_os = "ios"))]
macro_rules! gen_api_transition {
() => {
pub struct EventsLoop {
windows: ::std::sync::Arc<::std::sync::Mutex<Vec<::std::sync::Arc<Window>>>>,
awakened: ::std::sync::Arc<::std::sync::atomic::AtomicBool>,
}
pub struct EventsLoopProxy {
awakened: ::std::sync::Weak<::std::sync::atomic::AtomicBool>,
}
impl EventsLoop {
pub fn new() -> EventsLoop {
EventsLoop {
windows: ::std::sync::Arc::new(::std::sync::Mutex::new(vec![])),
awakened: ::std::sync::Arc::new(::std::sync::atomic::AtomicBool::new(false)),
}
}
#[inline]
pub fn get_available_monitors(&self) -> ::std::collections::VecDeque<MonitorId> {
get_available_monitors()
}
#[inline]
pub fn get_primary_monitor(&self) -> MonitorId {
get_primary_monitor()
}
pub fn poll_events<F>(&mut self, mut callback: F)
where F: FnMut(::Event)
{
if self.awakened.load(::std::sync::atomic::Ordering::Relaxed) {
self.awakened.store(false, ::std::sync::atomic::Ordering::Relaxed);
callback(::Event::Awakened);
}
let windows = self.windows.lock().unwrap();
for window in windows.iter() {
for event in window.poll_events() {
callback(::Event::WindowEvent {
window_id: ::WindowId(WindowId(&**window as *const Window as usize)),
event: event,
})
}
}
}
pub fn run_forever<F>(&mut self, mut callback: F)
where F: FnMut(::Event) -> ::ControlFlow,
{
self.awakened.store(false, ::std::sync::atomic::Ordering::Relaxed);
// Yeah that's a very bad implementation.
loop {
let mut control_flow = ::ControlFlow::Continue;
self.poll_events(|e| {
if let ::ControlFlow::Break = callback(e) {
control_flow = ::ControlFlow::Break;
}
});
if let ::ControlFlow::Break = control_flow {
break;
}
::std::thread::sleep(::std::time::Duration::from_millis(5));
}
}
pub fn create_proxy(&self) -> EventsLoopProxy {
EventsLoopProxy {
awakened: ::std::sync::Arc::downgrade(&self.awakened),
}
}
}
impl EventsLoopProxy {
pub fn wakeup(&self) -> Result<(), ::EventsLoopClosed> {
match self.awakened.upgrade() {
None => Err(::EventsLoopClosed),
Some(awakened) => {
awakened.store(true, ::std::sync::atomic::Ordering::Relaxed);
Ok(())
},
}
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct WindowId(usize);
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId;
pub struct Window2 {
pub window: ::std::sync::Arc<Window>,
windows: ::std::sync::Weak<::std::sync::Mutex<Vec<::std::sync::Arc<Window>>>>
}
impl ::std::ops::Deref for Window2 {
type Target = Window;
#[inline]
fn deref(&self) -> &Window {
&*self.window
}
}
impl Window2 {
pub fn new(events_loop: &EventsLoop,
window: &::WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window2, CreationError>
{
let win = ::std::sync::Arc::new(try!(Window::new(window, pl_attribs)));
events_loop.windows.lock().unwrap().push(win.clone());
Ok(Window2 {
window: win,
windows: ::std::sync::Arc::downgrade(&events_loop.windows),
})
}
#[inline]
pub fn id(&self) -> WindowId {
WindowId(&*self.window as *const Window as usize)
}
}
impl Drop for Window2 {
fn drop(&mut self) {
if let Some(windows) = self.windows.upgrade() {
let mut windows = windows.lock().unwrap();
windows.retain(|w| &**w as *const Window != &*self.window as *const _);
}
}
}
};
}

View file

@ -115,9 +115,6 @@ extern crate wayland_client;
pub use events::*; pub use events::*;
pub use window::{AvailableMonitorsIter, MonitorId}; pub use window::{AvailableMonitorsIter, MonitorId};
#[macro_use]
mod api_transition;
mod platform; mod platform;
mod events; mod events;
mod window; mod window;
@ -144,7 +141,7 @@ pub mod os;
/// }); /// });
/// ``` /// ```
pub struct Window { pub struct Window {
window: platform::Window2, window: platform::Window,
} }
/// Identifier of a window. Unique for each window. /// Identifier of a window. Unique for each window.

View file

@ -7,7 +7,7 @@ use EventsLoop;
use MonitorId; use MonitorId;
use Window; use Window;
use platform::EventsLoop as LinuxEventsLoop; use platform::EventsLoop as LinuxEventsLoop;
use platform::Window2 as LinuxWindow; use platform::Window as LinuxWindow;
use WindowBuilder; use WindowBuilder;
use platform::x11::XConnection; use platform::x11::XConnection;
use platform::x11::ffi::XVisualInfo; use platform::x11::ffi::XVisualInfo;

View file

@ -133,7 +133,7 @@ pub struct WindowId;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; pub struct DeviceId;
pub struct Window2 { pub struct Window {
native_window: *const c_void, native_window: *const c_void,
} }
@ -159,10 +159,10 @@ pub struct PlatformSpecificWindowBuilderAttributes;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PlatformSpecificHeadlessBuilderAttributes; pub struct PlatformSpecificHeadlessBuilderAttributes;
impl Window2 { impl Window {
pub fn new(_: &EventsLoop, win_attribs: &WindowAttributes, pub fn new(_: &EventsLoop, win_attribs: &WindowAttributes,
_: &PlatformSpecificWindowBuilderAttributes) _: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window2, CreationError> -> Result<Window, CreationError>
{ {
// not implemented // not implemented
assert!(win_attribs.min_dimensions.is_none()); assert!(win_attribs.min_dimensions.is_none());
@ -175,7 +175,7 @@ impl Window2 {
android_glue::set_multitouch(win_attribs.multitouch); android_glue::set_multitouch(win_attribs.multitouch);
Ok(Window2 { Ok(Window {
native_window: native_window as *const _, native_window: native_window as *const _,
}) })
} }
@ -269,8 +269,8 @@ impl Window2 {
} }
} }
unsafe impl Send for Window2 {} unsafe impl Send for Window {}
unsafe impl Sync for Window2 {} unsafe impl Sync for Window {}
// Constant device ID, to be removed when this backend is updated to report real device IDs. // Constant device ID, to be removed when this backend is updated to report real device IDs.
const DEVICE_ID: ::DeviceId = ::DeviceId(DeviceId); const DEVICE_ID: ::DeviceId = ::DeviceId(DeviceId);

View file

@ -98,7 +98,7 @@ static mut jmpbuf: [c_int;27] = [0;27];
#[derive(Clone)] #[derive(Clone)]
pub struct MonitorId; pub struct MonitorId;
pub struct Window2 { pub struct Window {
delegate_state: *mut DelegateState delegate_state: *mut DelegateState
} }
@ -258,11 +258,11 @@ pub struct DeviceId;
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PlatformSpecificWindowBuilderAttributes; pub struct PlatformSpecificWindowBuilderAttributes;
impl Window2 { impl Window {
pub fn new(ev: &EventsLoop, _: &WindowAttributes, _: &PlatformSpecificWindowBuilderAttributes) pub fn new(ev: &EventsLoop, _: &WindowAttributes, _: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window2, CreationError> -> Result<Window, CreationError>
{ {
Ok(Window2 { Ok(Window {
delegate_state: ev.delegate_state, delegate_state: ev.delegate_state,
}) })
} }

View file

@ -38,8 +38,8 @@ lazy_static!(
}; };
); );
pub enum Window2 { pub enum Window {
X(x11::Window2), X(x11::Window),
Wayland(wayland::Window) Wayland(wayland::Window)
} }
@ -87,7 +87,7 @@ impl MonitorId {
} }
} }
impl Window2 { impl Window {
#[inline] #[inline]
pub fn new(events_loop: &EventsLoop, pub fn new(events_loop: &EventsLoop,
window: &::WindowAttributes, window: &::WindowAttributes,
@ -96,11 +96,11 @@ impl Window2 {
{ {
match *events_loop { match *events_loop {
EventsLoop::Wayland(ref evlp) => { EventsLoop::Wayland(ref evlp) => {
wayland::Window::new(evlp, window).map(Window2::Wayland) wayland::Window::new(evlp, window).map(Window::Wayland)
}, },
EventsLoop::X(ref el) => { EventsLoop::X(ref el) => {
x11::Window2::new(el, window, pl_attribs).map(Window2::X) x11::Window::new(el, window, pl_attribs).map(Window::X)
}, },
} }
} }
@ -108,104 +108,104 @@ impl Window2 {
#[inline] #[inline]
pub fn id(&self) -> WindowId { pub fn id(&self) -> WindowId {
match self { match self {
&Window2::X(ref w) => WindowId::X(w.id()), &Window::X(ref w) => WindowId::X(w.id()),
&Window2::Wayland(ref w) => WindowId::Wayland(w.id()) &Window::Wayland(ref w) => WindowId::Wayland(w.id())
} }
} }
#[inline] #[inline]
pub fn set_title(&self, title: &str) { pub fn set_title(&self, title: &str) {
match self { match self {
&Window2::X(ref w) => w.set_title(title), &Window::X(ref w) => w.set_title(title),
&Window2::Wayland(ref w) => w.set_title(title) &Window::Wayland(ref w) => w.set_title(title)
} }
} }
#[inline] #[inline]
pub fn show(&self) { pub fn show(&self) {
match self { match self {
&Window2::X(ref w) => w.show(), &Window::X(ref w) => w.show(),
&Window2::Wayland(ref w) => w.show() &Window::Wayland(ref w) => w.show()
} }
} }
#[inline] #[inline]
pub fn hide(&self) { pub fn hide(&self) {
match self { match self {
&Window2::X(ref w) => w.hide(), &Window::X(ref w) => w.hide(),
&Window2::Wayland(ref w) => w.hide() &Window::Wayland(ref w) => w.hide()
} }
} }
#[inline] #[inline]
pub fn get_position(&self) -> Option<(i32, i32)> { pub fn get_position(&self) -> Option<(i32, i32)> {
match self { match self {
&Window2::X(ref w) => w.get_position(), &Window::X(ref w) => w.get_position(),
&Window2::Wayland(ref w) => w.get_position() &Window::Wayland(ref w) => w.get_position()
} }
} }
#[inline] #[inline]
pub fn set_position(&self, x: i32, y: i32) { pub fn set_position(&self, x: i32, y: i32) {
match self { match self {
&Window2::X(ref w) => w.set_position(x, y), &Window::X(ref w) => w.set_position(x, y),
&Window2::Wayland(ref w) => w.set_position(x, y) &Window::Wayland(ref w) => w.set_position(x, y)
} }
} }
#[inline] #[inline]
pub fn get_inner_size(&self) -> Option<(u32, u32)> { pub fn get_inner_size(&self) -> Option<(u32, u32)> {
match self { match self {
&Window2::X(ref w) => w.get_inner_size(), &Window::X(ref w) => w.get_inner_size(),
&Window2::Wayland(ref w) => w.get_inner_size() &Window::Wayland(ref w) => w.get_inner_size()
} }
} }
#[inline] #[inline]
pub fn get_outer_size(&self) -> Option<(u32, u32)> { pub fn get_outer_size(&self) -> Option<(u32, u32)> {
match self { match self {
&Window2::X(ref w) => w.get_outer_size(), &Window::X(ref w) => w.get_outer_size(),
&Window2::Wayland(ref w) => w.get_outer_size() &Window::Wayland(ref w) => w.get_outer_size()
} }
} }
#[inline] #[inline]
pub fn set_inner_size(&self, x: u32, y: u32) { pub fn set_inner_size(&self, x: u32, y: u32) {
match self { match self {
&Window2::X(ref w) => w.set_inner_size(x, y), &Window::X(ref w) => w.set_inner_size(x, y),
&Window2::Wayland(ref w) => w.set_inner_size(x, y) &Window::Wayland(ref w) => w.set_inner_size(x, y)
} }
} }
#[inline] #[inline]
pub fn set_cursor(&self, cursor: MouseCursor) { pub fn set_cursor(&self, cursor: MouseCursor) {
match self { match self {
&Window2::X(ref w) => w.set_cursor(cursor), &Window::X(ref w) => w.set_cursor(cursor),
&Window2::Wayland(ref w) => w.set_cursor(cursor) &Window::Wayland(ref w) => w.set_cursor(cursor)
} }
} }
#[inline] #[inline]
pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> { pub fn set_cursor_state(&self, state: CursorState) -> Result<(), String> {
match self { match self {
&Window2::X(ref w) => w.set_cursor_state(state), &Window::X(ref w) => w.set_cursor_state(state),
&Window2::Wayland(ref w) => w.set_cursor_state(state) &Window::Wayland(ref w) => w.set_cursor_state(state)
} }
} }
#[inline] #[inline]
pub fn hidpi_factor(&self) -> f32 { pub fn hidpi_factor(&self) -> f32 {
match self { match self {
&Window2::X(ref w) => w.hidpi_factor(), &Window::X(ref w) => w.hidpi_factor(),
&Window2::Wayland(ref w) => w.hidpi_factor() &Window::Wayland(ref w) => w.hidpi_factor()
} }
} }
#[inline] #[inline]
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> { pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
match self { match self {
&Window2::X(ref w) => w.set_cursor_position(x, y), &Window::X(ref w) => w.set_cursor_position(x, y),
&Window2::Wayland(ref w) => w.set_cursor_position(x, y) &Window::Wayland(ref w) => w.set_cursor_position(x, y)
} }
} }
@ -213,8 +213,8 @@ impl Window2 {
pub fn platform_display(&self) -> *mut libc::c_void { pub fn platform_display(&self) -> *mut libc::c_void {
use wayland_client::Proxy; use wayland_client::Proxy;
match self { match self {
&Window2::X(ref w) => w.platform_display(), &Window::X(ref w) => w.platform_display(),
&Window2::Wayland(ref w) => w.get_display().ptr() as *mut _ &Window::Wayland(ref w) => w.get_display().ptr() as *mut _
} }
} }
@ -222,24 +222,24 @@ impl Window2 {
pub fn platform_window(&self) -> *mut libc::c_void { pub fn platform_window(&self) -> *mut libc::c_void {
use wayland_client::Proxy; use wayland_client::Proxy;
match self { match self {
&Window2::X(ref w) => w.platform_window(), &Window::X(ref w) => w.platform_window(),
&Window2::Wayland(ref w) => w.get_surface().ptr() as *mut _ &Window::Wayland(ref w) => w.get_surface().ptr() as *mut _
} }
} }
#[inline] #[inline]
pub fn set_maximized(&self, maximized: bool) { pub fn set_maximized(&self, maximized: bool) {
match self { match self {
&Window2::X(ref w) => w.set_maximized(maximized), &Window::X(ref w) => w.set_maximized(maximized),
&Window2::Wayland(ref _w) => {}, &Window::Wayland(ref _w) => {},
} }
} }
#[inline] #[inline]
pub fn set_fullscreen(&self, state: FullScreenState) { pub fn set_fullscreen(&self, state: FullScreenState) {
match self { match self {
&Window2::X(ref w) => w.set_fullscreen(state), &Window::X(ref w) => w.set_fullscreen(state),
&Window2::Wayland(ref _w) => {}, &Window::Wayland(ref _w) => {},
} }
} }
} }

View file

@ -1,7 +1,7 @@
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor}; pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
pub use self::window::{Window, XWindow}; pub use self::window::{Window2, XWindow};
pub use self::xdisplay::{XConnection, XNotSupported, XError}; pub use self::xdisplay::{XConnection, XNotSupported, XError};
pub mod ffi; pub mod ffi;
@ -655,16 +655,16 @@ pub struct WindowId(ffi::Window);
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId(c_int); pub struct DeviceId(c_int);
pub struct Window2 { pub struct Window {
pub window: Arc<Window>, pub window: Arc<Window2>,
display: Weak<XConnection>, display: Weak<XConnection>,
windows: Weak<Mutex<HashMap<WindowId, WindowData>>>, windows: Weak<Mutex<HashMap<WindowId, WindowData>>>,
} }
impl ::std::ops::Deref for Window2 { impl ::std::ops::Deref for Window {
type Target = Window; type Target = Window2;
#[inline] #[inline]
fn deref(&self) -> &Window { fn deref(&self) -> &Window2 {
&*self.window &*self.window
} }
} }
@ -674,13 +674,13 @@ lazy_static! { // TODO: use a static mutex when that's possible, and put me
static ref GLOBAL_XOPENIM_LOCK: Mutex<()> = Mutex::new(()); static ref GLOBAL_XOPENIM_LOCK: Mutex<()> = Mutex::new(());
} }
impl Window2 { impl Window {
pub fn new(x_events_loop: &EventsLoop, pub fn new(x_events_loop: &EventsLoop,
window: &::WindowAttributes, window: &::WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes) pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Self, CreationError> -> Result<Self, CreationError>
{ {
let win = ::std::sync::Arc::new(try!(Window::new(&x_events_loop, window, pl_attribs))); let win = ::std::sync::Arc::new(try!(Window2::new(&x_events_loop, window, pl_attribs)));
// creating IM // creating IM
let im = unsafe { let im = unsafe {
@ -716,7 +716,7 @@ impl Window2 {
cursor_pos: None, cursor_pos: None,
}); });
Ok(Window2 { Ok(Window {
window: win, window: win,
windows: Arc::downgrade(&x_events_loop.windows), windows: Arc::downgrade(&x_events_loop.windows),
display: Arc::downgrade(&x_events_loop.display), display: Arc::downgrade(&x_events_loop.display),
@ -749,7 +749,7 @@ impl Window2 {
} }
} }
impl Drop for Window2 { impl Drop for Window {
fn drop(&mut self) { fn drop(&mut self) {
if let (Some(windows), Some(display)) = (self.windows.upgrade(), self.display.upgrade()) { if let (Some(windows), Some(display)) = (self.windows.upgrade(), self.display.upgrade()) {
let mut windows = windows.lock().unwrap(); let mut windows = windows.lock().unwrap();

View file

@ -40,8 +40,8 @@ pub struct XWindow {
unsafe impl Send for XWindow {} unsafe impl Send for XWindow {}
unsafe impl Sync for XWindow {} unsafe impl Sync for XWindow {}
unsafe impl Send for Window {} unsafe impl Send for Window2 {}
unsafe impl Sync for Window {} unsafe impl Sync for Window2 {}
impl XWindow { impl XWindow {
fn switch_to_fullscreen_mode(&self, monitor: i32, width: u16, height: u16) { fn switch_to_fullscreen_mode(&self, monitor: i32, width: u16, height: u16) {
@ -141,15 +141,15 @@ impl Drop for XWindow {
} }
} }
pub struct Window { pub struct Window2 {
pub x: Arc<XWindow>, pub x: Arc<XWindow>,
cursor_state: Mutex<CursorState>, cursor_state: Mutex<CursorState>,
} }
impl Window { impl Window2 {
pub fn new(ctx: &EventsLoop, window_attrs: &WindowAttributes, pub fn new(ctx: &EventsLoop, window_attrs: &WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes) pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError> -> Result<Window2, CreationError>
{ {
let display = &ctx.display; let display = &ctx.display;
let dimensions = { let dimensions = {
@ -306,7 +306,7 @@ impl Window {
}; };
} }
let window = Window { let window = Window2 {
x: Arc::new(XWindow { x: Arc::new(XWindow {
display: display.clone(), display: display.clone(),
window: window, window: window,
@ -402,16 +402,16 @@ impl Window {
match state { match state {
FullScreenState::None => { FullScreenState::None => {
self.x.switch_from_fullscreen_mode(); self.x.switch_from_fullscreen_mode();
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", false); Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", false);
}, },
FullScreenState::Windowed => { FullScreenState::Windowed => {
self.x.switch_from_fullscreen_mode(); self.x.switch_from_fullscreen_mode();
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true); Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
}, },
FullScreenState::Exclusive(RootMonitorId { inner: PlatformMonitorId::X(X11MonitorId(_, monitor)) }) => { FullScreenState::Exclusive(RootMonitorId { inner: PlatformMonitorId::X(X11MonitorId(_, monitor)) }) => {
if let Some(dimensions) = self.get_inner_size() { if let Some(dimensions) = self.get_inner_size() {
self.x.switch_to_fullscreen_mode(monitor as i32, dimensions.0 as u16, dimensions.1 as u16); self.x.switch_to_fullscreen_mode(monitor as i32, dimensions.0 as u16, dimensions.1 as u16);
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true); Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_FULLSCREEN", true);
} else { } else {
eprintln!("[winit] Couldn't get window dimensions to go fullscreen"); eprintln!("[winit] Couldn't get window dimensions to go fullscreen");
} }
@ -421,8 +421,8 @@ impl Window {
} }
pub fn set_maximized(&self, maximized: bool) { pub fn set_maximized(&self, maximized: bool) {
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_HORZ", maximized); Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_HORZ", maximized);
Window::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_VERT", maximized); Window2::set_netwm(&self.x.display, self.x.window, self.x.root, "_NET_WM_STATE_MAXIMIZED_VERT", maximized);
} }
pub fn set_title(&self, title: &str) { pub fn set_title(&self, title: &str) {

View file

@ -4,7 +4,7 @@ use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow};
use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput}; use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, DeviceEvent, ModifiersState, KeyboardInput};
use std::collections::VecDeque; use std::collections::VecDeque;
use std::sync::{Arc, Mutex, Weak}; use std::sync::{Arc, Mutex, Weak};
use super::window::Window; use super::window::Window2;
use std; use std;
use super::DeviceId; use super::DeviceId;
@ -16,7 +16,7 @@ pub struct EventsLoop {
// State shared between the `EventsLoop` and its registered windows. // State shared between the `EventsLoop` and its registered windows.
pub struct Shared { pub struct Shared {
pub windows: Mutex<Vec<Weak<Window>>>, pub windows: Mutex<Vec<Weak<Window2>>>,
pub pending_events: Mutex<VecDeque<Event>>, pub pending_events: Mutex<VecDeque<Event>>,
// The user event callback given via either of the `poll_events` or `run_forever` methods. // The user event callback given via either of the `poll_events` or `run_forever` methods.
// //

View file

@ -2,7 +2,7 @@
pub use self::events_loop::{EventsLoop, Proxy as EventsLoopProxy}; pub use self::events_loop::{EventsLoop, Proxy as EventsLoopProxy};
pub use self::monitor::MonitorId; pub use self::monitor::MonitorId;
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window}; pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window2};
use std::sync::Arc; use std::sync::Arc;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
@ -10,29 +10,29 @@ pub struct DeviceId;
use {CreationError}; use {CreationError};
pub struct Window2 { pub struct Window {
pub window: Arc<Window>, pub window: Arc<Window2>,
} }
impl ::std::ops::Deref for Window2 { impl ::std::ops::Deref for Window {
type Target = Window; type Target = Window2;
#[inline] #[inline]
fn deref(&self) -> &Window { fn deref(&self) -> &Window2 {
&*self.window &*self.window
} }
} }
impl Window2 { impl Window {
pub fn new(events_loop: &EventsLoop, pub fn new(events_loop: &EventsLoop,
attributes: &::WindowAttributes, attributes: &::WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError> pl_attribs: &PlatformSpecificWindowBuilderAttributes) -> Result<Self, CreationError>
{ {
let weak_shared = Arc::downgrade(&events_loop.shared); let weak_shared = Arc::downgrade(&events_loop.shared);
let window = Arc::new(try!(Window::new(weak_shared, attributes, pl_attribs))); let window = Arc::new(try!(Window2::new(weak_shared, attributes, pl_attribs)));
let weak_window = Arc::downgrade(&window); let weak_window = Arc::downgrade(&window);
events_loop.shared.windows.lock().unwrap().push(weak_window); events_loop.shared.windows.lock().unwrap().push(weak_window);
Ok(Window2 { window: window }) Ok(Window { window: window })
} }
} }

View file

@ -256,16 +256,16 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub activation_policy: ActivationPolicy, pub activation_policy: ActivationPolicy,
} }
pub struct Window { pub struct Window2 {
pub view: IdRef, pub view: IdRef,
pub window: IdRef, pub window: IdRef,
pub delegate: WindowDelegate, pub delegate: WindowDelegate,
} }
unsafe impl Send for Window {} unsafe impl Send for Window2 {}
unsafe impl Sync for Window {} unsafe impl Sync for Window2 {}
impl Drop for Window { impl Drop for Window2 {
fn drop(&mut self) { fn drop(&mut self) {
// Remove this window from the `EventLoop`s list of windows. // Remove this window from the `EventLoop`s list of windows.
let id = self.id(); let id = self.id();
@ -283,7 +283,7 @@ impl Drop for Window {
} }
} }
impl WindowExt for Window { impl WindowExt for Window2 {
#[inline] #[inline]
fn get_nswindow(&self) -> *mut c_void { fn get_nswindow(&self) -> *mut c_void {
*self.window as *mut c_void *self.window as *mut c_void
@ -295,11 +295,11 @@ impl WindowExt for Window {
} }
} }
impl Window { impl Window2 {
pub fn new(shared: Weak<Shared>, pub fn new(shared: Weak<Shared>,
win_attribs: &WindowAttributes, win_attribs: &WindowAttributes,
pl_attribs: &PlatformSpecificWindowBuilderAttributes) pl_attribs: &PlatformSpecificWindowBuilderAttributes)
-> Result<Window, CreationError> -> Result<Window2, CreationError>
{ {
unsafe { unsafe {
if !msg_send![cocoa::base::class("NSThread"), isMainThread] { if !msg_send![cocoa::base::class("NSThread"), isMainThread] {
@ -307,17 +307,17 @@ impl Window {
} }
} }
let app = match Window::create_app(pl_attribs.activation_policy) { let app = match Window2::create_app(pl_attribs.activation_policy) {
Some(app) => app, Some(app) => app,
None => { return Err(OsError(format!("Couldn't create NSApplication"))); }, None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
}; };
let window = match Window::create_window(win_attribs) let window = match Window2::create_window(win_attribs)
{ {
Some(window) => window, Some(window) => window,
None => { return Err(OsError(format!("Couldn't create NSWindow"))); }, None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
}; };
let view = match Window::create_view(*window) { let view = match Window2::create_view(*window) {
Some(view) => view, Some(view) => view,
None => { return Err(OsError(format!("Couldn't create NSView"))); }, None => { return Err(OsError(format!("Couldn't create NSView"))); },
}; };
@ -355,7 +355,7 @@ impl Window {
shared: shared, shared: shared,
}; };
let window = Window { let window = Window2 {
view: view, view: view,
window: window, window: window,
delegate: WindowDelegate::new(ds), delegate: WindowDelegate::new(ds),
@ -422,11 +422,11 @@ impl Window {
appkit::NSBorderlessWindowMask | appkit::NSResizableWindowMask | appkit::NSBorderlessWindowMask | appkit::NSResizableWindowMask |
appkit::NSTitledWindowMask appkit::NSTitledWindowMask
} else if attrs.decorations { } else if attrs.decorations {
// Window with a titlebar // Window2 with a titlebar
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask | appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
appkit::NSResizableWindowMask | appkit::NSTitledWindowMask appkit::NSResizableWindowMask | appkit::NSTitledWindowMask
} else { } else {
// Window without a titlebar // Window2 without a titlebar
appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask | appkit::NSClosableWindowMask | appkit::NSMiniaturizableWindowMask |
appkit::NSResizableWindowMask | appkit::NSResizableWindowMask |
appkit::NSFullSizeContentViewWindowMask appkit::NSFullSizeContentViewWindowMask

View file

@ -17,9 +17,6 @@ unsafe impl Sync for PlatformSpecificWindowBuilderAttributes {}
// TODO: document what this means // TODO: document what this means
pub type Cursor = *const winapi::wchar_t; pub type Cursor = *const winapi::wchar_t;
// TODO: remove
pub type Window2 = Window;
// Constant device ID, to be removed when this backend is updated to report real device IDs. // Constant device ID, to be removed when this backend is updated to report real device IDs.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct DeviceId; pub struct DeviceId;

View file

@ -118,7 +118,7 @@ impl WindowBuilder {
} }
// building // building
let w = try!(platform::Window2::new(&events_loop.events_loop, &self.window, &self.platform_specific)); let w = try!(platform::Window::new(&events_loop.events_loop, &self.window, &self.platform_specific));
Ok(Window { window: w }) Ok(Window { window: w })
} }