aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml24
-rw-r--r--build.rs4
-rw-r--r--examples-disabled/fullscreen.rs (renamed from examples/fullscreen.rs)2
-rw-r--r--examples/cursor.rs2
-rw-r--r--examples/multiwindow.rs2
-rw-r--r--examples/vsync.rs2
-rw-r--r--examples/window.rs2
-rw-r--r--src/cocoa/mod.rs140
-rw-r--r--src/lib.rs15
-rw-r--r--src/win32/callback.rs8
-rw-r--r--src/win32/init.rs2
-rw-r--r--src/win32/mod.rs1
-rw-r--r--src/win32/monitor.rs10
-rw-r--r--src/window.rs2
14 files changed, 94 insertions, 122 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3b0317a..7b50fc7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "glutin"
-version = "0.0.13"
+version = "0.0.14"
authors = ["tomaka <pierre.krieger1708@gmail.com>"]
description = "Cross-plaform OpenGL context provider."
keywords = ["windowing", "opengl"]
@@ -30,23 +30,11 @@ clock_ticks = "*"
[target.arm-linux-androideabi.dependencies.android_glue]
version = "0"
-[target.i686-apple-darwin.dependencies.glutin_cocoa]
-version = "0"
-
-[target.x86_64-apple-darwin.dependencies.glutin_cocoa]
-version = "0"
-
-[target.i686-apple-darwin.dependencies.glutin_core_graphics]
-version = "0"
-
-[target.x86_64-apple-darwin.dependencies.glutin_core_graphics]
-version = "0"
-
-[target.i686-apple-darwin.dependencies.glutin_core_foundation]
-version = "0"
-
-[target.x86_64-apple-darwin.dependencies.glutin_core_foundation]
-version = "0"
+[target.x86_64-apple-darwin.dependencies]
+objc = "0.1"
+glutin_cocoa = "0"
+glutin_core_graphics = "0"
+glutin_core_foundation = "0"
[target.i686-pc-windows-gnu.dependencies]
winapi = "0.1"
diff --git a/build.rs b/build.rs
index 7137d3e..2a42179 100644
--- a/build.rs
+++ b/build.rs
@@ -1,3 +1,5 @@
+#![feature(convert)]
+
extern crate gl_generator;
extern crate khronos_api;
@@ -7,7 +9,7 @@ use std::path::PathBuf;
fn main() {
let target = env::var("TARGET").unwrap();
- let dest = PathBuf::new(&env::var("OUT_DIR").unwrap());
+ let dest = PathBuf::from(&env::var("OUT_DIR").unwrap());
if target.contains("windows") {
let mut file = File::create(&dest.join("wgl_bindings.rs")).unwrap();
diff --git a/examples/fullscreen.rs b/examples-disabled/fullscreen.rs
index 3b9e2c1..37ea366 100644
--- a/examples/fullscreen.rs
+++ b/examples-disabled/fullscreen.rs
@@ -1,3 +1,5 @@
+#![feature(std_misc)]
+
#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
diff --git a/examples/cursor.rs b/examples/cursor.rs
index 0dced66..c5bcbd6 100644
--- a/examples/cursor.rs
+++ b/examples/cursor.rs
@@ -1,3 +1,5 @@
+#![feature(std_misc)]
+
#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs
index 115d5f2..a7680b8 100644
--- a/examples/multiwindow.rs
+++ b/examples/multiwindow.rs
@@ -1,3 +1,5 @@
+#![feature(std_misc)]
+
#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
diff --git a/examples/vsync.rs b/examples/vsync.rs
index ec9ea79..768bfc0 100644
--- a/examples/vsync.rs
+++ b/examples/vsync.rs
@@ -1,3 +1,5 @@
+#![feature(std_misc)]
+
#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
diff --git a/examples/window.rs b/examples/window.rs
index 1d3b615..0e2a3cf 100644
--- a/examples/window.rs
+++ b/examples/window.rs
@@ -1,3 +1,5 @@
+#![feature(std_misc)]
+
#[cfg(target_os = "android")]
#[macro_use]
extern crate android_glue;
diff --git a/src/cocoa/mod.rs b/src/cocoa/mod.rs
index 5e13a77..c150be0 100644
--- a/src/cocoa/mod.rs
+++ b/src/cocoa/mod.rs
@@ -10,9 +10,10 @@ use BuilderAttribs;
use GlRequest;
use native_monitor::NativeMonitorId;
-use cocoa::base::{Class, id, YES, NO, NSUInteger, nil, objc_allocateClassPair, class, objc_registerClassPair};
-use cocoa::base::{selector, msg_send, msg_send_stret, class_addMethod, class_addIvar};
-use cocoa::base::{object_setInstanceVariable, object_getInstanceVariable};
+use objc::runtime::{Class, Object, Sel, BOOL, YES, NO};
+use objc::declare::ClassDecl;
+
+use cocoa::base::{id, nil, NSUInteger};
use cocoa::appkit;
use cocoa::appkit::*;
use cocoa::appkit::NSEventSubtype::*;
@@ -22,8 +23,7 @@ use core_foundation::string::CFString;
use core_foundation::bundle::{CFBundleGetBundleWithIdentifier, CFBundleGetFunctionPointerForName};
use std::cell::Cell;
-use std::ffi::{CString, CStr};
-use std::mem;
+use std::ffi::CStr;
use std::ptr;
use std::collections::VecDeque;
use std::str::FromStr;
@@ -63,35 +63,25 @@ struct WindowDelegate {
}
impl WindowDelegate {
- fn class_name() -> &'static [u8] {
- b"GlutinWindowDelegate\0"
- }
-
- fn state_ivar_name() -> &'static [u8] {
- b"glutinState"
- }
-
/// Get the delegate class, initiailizing it neccessary
- fn class() -> Class {
+ fn class() -> *const Class {
use std::sync::{Once, ONCE_INIT};
- use std::rt;
- extern fn window_should_close(this: id, _: id) -> id {
+ extern fn window_should_close(this: &Object, _: Sel, _: id) -> BOOL {
unsafe {
- let delegate = WindowDelegate { this: this };
- (*delegate.get_state()).is_closed = true;
- mem::forget(delegate);
+ let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state = state as *mut DelegateState;
+ (*state).is_closed = true;
}
- 0
+ NO
}
- extern fn window_did_resize(this: id, _: id) -> id {
+ extern fn window_did_resize(this: &Object, _: Sel, _: id) {
unsafe {
- let delegate = WindowDelegate { this: this };
- let state = &mut *delegate.get_state();
- mem::forget(delegate);
+ let state: *mut libc::c_void = *this.get_ivar("glutinState");
+ let state = &mut *(state as *mut DelegateState);
- let _: id = msg_send()(*state.context, selector("update"));
+ let _: id = msg_send![*state.context, update];
if let Some(handler) = state.handler {
let rect = NSView::frame(*state.view);
@@ -100,64 +90,43 @@ impl WindowDelegate {
(scale_factor * rect.size.height as f32) as u32);
}
}
- 0
}
- static mut delegate_class: Class = nil;
- static mut init: Once = ONCE_INIT;
+ static mut delegate_class: *const Class = 0 as *const Class;
+ static INIT: Once = ONCE_INIT;
+
+ INIT.call_once(|| unsafe {
+ // Create new NSWindowDelegate
+ let superclass = Class::get("NSObject").unwrap();
+ let mut decl = ClassDecl::new(superclass, "GlutinWindowDelegate").unwrap();
+
+ // Add callback methods
+ decl.add_method(sel!(windowShouldClose:),
+ window_should_close as extern fn(&Object, Sel, id) -> BOOL);
+ decl.add_method(sel!(windowDidResize:),
+ window_did_resize as extern fn(&Object, Sel, id));
+
+ // Store internal state as user data
+ decl.add_ivar::<*mut libc::c_void>("glutinState");
+
+ delegate_class = decl.register();
+ });
unsafe {
- init.call_once(|| {
- let ptr_size = mem::size_of::<libc::intptr_t>();
- // Create new NSWindowDelegate
- delegate_class = objc_allocateClassPair(
- class("NSObject"),
- WindowDelegate::class_name().as_ptr() as *const i8, 0);
- // Add callback methods
- class_addMethod(delegate_class,
- selector("windowShouldClose:"),
- window_should_close,
- CString::new("B@:@").unwrap().as_ptr());
- class_addMethod(delegate_class,
- selector("windowDidResize:"),
- window_did_resize,
- CString::new("V@:@").unwrap().as_ptr());
- // Store internal state as user data
- class_addIvar(delegate_class, WindowDelegate::state_ivar_name().as_ptr() as *const i8,
- ptr_size as u64, 3,
- CString::new("?").unwrap().as_ptr());
- objc_registerClassPair(delegate_class);
- // Free class at exit
- rt::at_exit(|| {
- // objc_disposeClassPair(delegate_class);
- });
- });
delegate_class
}
}
fn new(window: id) -> WindowDelegate {
unsafe {
- let delegate: id = msg_send()(WindowDelegate::class(), selector("new"));
- let _: id = msg_send()(window, selector("setDelegate:"), delegate);
+ let delegate: id = msg_send![WindowDelegate::class(), new];
+ let _: id = msg_send![window, setDelegate:delegate];
WindowDelegate { this: delegate }
}
}
unsafe fn set_state(&self, state: *mut DelegateState) {
- object_setInstanceVariable(self.this,
- WindowDelegate::state_ivar_name().as_ptr() as *const i8,
- state as *mut libc::c_void);
- }
-
- fn get_state(&self) -> *mut DelegateState {
- unsafe {
- let mut state = ptr::null_mut();
- object_getInstanceVariable(self.this,
- WindowDelegate::state_ivar_name().as_ptr() as *const i8,
- &mut state);
- state as *mut DelegateState
- }
+ (&mut *self.this).set_ivar("glutinState", state as *mut libc::c_void);
}
}
@@ -234,7 +203,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
self.window.is_closed.set(ds.is_closed);
}
- let event = match msg_send()(event, selector("type")) {
+ let event = match msg_send![event, type] {
NSLeftMouseDown => { Some(MouseInput(Pressed, MouseButton::Left)) },
NSLeftMouseUp => { Some(MouseInput(Released, MouseButton::Left)) },
NSRightMouseDown => { Some(MouseInput(Pressed, MouseButton::Right)) },
@@ -244,8 +213,8 @@ impl<'a> Iterator for PollEventsIterator<'a> {
NSOtherMouseDragged |
NSRightMouseDragged => {
let window_point = event.locationInWindow();
- let window: id = msg_send()(event, selector("window"));
- let view_point = if window == 0 {
+ let window: id = msg_send![event, window];
+ let view_point = if window == nil {
let window_rect = self.window.window.convertRectFromScreen_(NSRect::new(window_point, NSSize::new(0.0, 0.0)));
self.window.view.convertPoint_fromView_(window_rect.origin, nil)
} else {
@@ -416,15 +385,15 @@ impl Window {
};
let matching_screen = {
let screens = NSScreen::screens(nil);
- let count: NSUInteger = msg_send()(screens, selector("count"));
+ let count: NSUInteger = msg_send![screens, count];
let key = IdRef::new(NSString::alloc(nil).init_str("NSScreenNumber"));
let mut matching_screen: Option<id> = None;
for i in (0..count) {
- let screen = msg_send()(screens, selector("objectAtIndex:"), i as NSUInteger);
+ let screen = msg_send![screens, objectAtIndex:i as NSUInteger];
let device_description = NSScreen::deviceDescription(screen);
- let value = msg_send()(device_description, selector("objectForKey:"), *key);
+ let value = msg_send![device_description, objectForKey:*key];
if value != nil {
- let screen_number: NSUInteger = msg_send()(value, selector("unsignedIntValue"));
+ let screen_number: NSUInteger = msg_send![value, unsignedIntValue];
if screen_number as u32 == native_id {
matching_screen = Some(screen);
break;
@@ -605,7 +574,7 @@ impl Window {
}
pub unsafe fn make_current(&self) {
- let _: id = msg_send()(*self.context, selector("update"));
+ let _: id = msg_send![*self.context, update];
self.context.makeCurrentContext();
}
@@ -613,7 +582,7 @@ impl Window {
unsafe {
let current = NSOpenGLContext::currentContext(nil);
if current != nil {
- let is_equal: bool = msg_send()(current, selector("isEqual:"), *self.context);
+ let is_equal: bool = msg_send![current, isEqual:*self.context];
is_equal
} else {
false
@@ -683,9 +652,12 @@ impl Window {
MouseCursor::Move | MouseCursor::AllScroll | MouseCursor::ZoomIn |
MouseCursor::ZoomOut => "arrowCursor",
};
+ let sel = Sel::register(cursor_name);
+ let cls = Class::get("NSCursor").unwrap();
unsafe {
- let cursor : id = msg_send()(class("NSCursor"), selector(cursor_name));
- let _ : id = msg_send()(cursor, selector("set"));
+ use objc::MessageArguments;
+ let cursor: id = ().send(cls as *const _ as id, sel);
+ let _: id = msg_send![cursor, set];
}
}
@@ -709,7 +681,7 @@ impl IdRef {
fn retain(i: id) -> IdRef {
if i != nil {
- unsafe { msg_send::<()>()(i, selector("retain")) };
+ unsafe { msg_send![i, retain] }
}
IdRef(i)
}
@@ -722,7 +694,7 @@ impl IdRef {
impl Drop for IdRef {
fn drop(&mut self) {
if self.0 != nil {
- unsafe { msg_send::<()>()(self.0, selector("release")) };
+ unsafe { msg_send![self.0, release] }
}
}
}
@@ -737,17 +709,17 @@ impl Deref for IdRef {
impl Clone for IdRef {
fn clone(&self) -> IdRef {
if self.0 != nil {
- unsafe { msg_send::<()>()(self.0, selector("retain")) };
+ unsafe { msg_send![self.0, retain] }
}
IdRef(self.0)
}
fn clone_from(&mut self, source: &IdRef) {
if source.0 != nil {
- unsafe { msg_send::<()>()(source.0, selector("retain")) };
+ unsafe { msg_send![source.0, retain] }
}
if self.0 != nil {
- unsafe { msg_send::<()>()(self.0, selector("release")) };
+ unsafe { msg_send![self.0, release] }
}
self.0 = source.0;
}
diff --git a/src/lib.rs b/src/lib.rs
index c0de089..bdf7975 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-#![feature(unsafe_destructor,core,std_misc)]
+#![feature(collections, unsafe_destructor, os, core, std_misc, alloc)]
#![unstable]
//! The purpose of this library is to provide an OpenGL context on as many
@@ -32,17 +32,20 @@ extern crate libc;
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(target_os = "windows")]
-extern crate "kernel32-sys" as kernel32;
+extern crate kernel32_sys as kernel32;
#[cfg(target_os = "windows")]
-extern crate "gdi32-sys" as gdi32;
+extern crate gdi32_sys as gdi32;
#[cfg(target_os = "windows")]
-extern crate "user32-sys" as user32;
+extern crate user32_sys as user32;
+#[cfg(target_os = "macos")]
+#[macro_use]
+extern crate objc;
#[cfg(target_os = "macos")]
extern crate cocoa;
#[cfg(target_os = "macos")]
extern crate core_foundation;
#[cfg(target_os = "macos")]
-extern crate "glutin_core_graphics" as core_graphics;
+extern crate glutin_core_graphics as core_graphics;
pub use events::*;
#[cfg(feature = "headless")]
@@ -86,7 +89,7 @@ pub enum CreationError {
impl CreationError {
fn to_string(&self) -> &str {
match *self {
- CreationError::OsError(ref text) => text.as_slice(),
+ CreationError::OsError(ref text) => &text,
CreationError::NotSupported => "Some of the requested attributes are not supported",
}
}
diff --git a/src/win32/callback.rs b/src/win32/callback.rs
index f9ec653..bbf5b55 100644
--- a/src/win32/callback.rs
+++ b/src/win32/callback.rs
@@ -1,6 +1,6 @@
use std::rc::Rc;
use std::cell::RefCell;
-use std::sync::mpsc::{Sender, Receiver, channel};
+use std::sync::mpsc::Sender;
use Event;
use super::event;
@@ -52,7 +52,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
};
if win == &window {
- unsafe { user32::PostQuitMessage(0); }
+ user32::PostQuitMessage(0);
}
});
@@ -83,7 +83,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
winapi::WM_CHAR => {
use std::mem;
use events::Event::ReceivedCharacter;
- let chr: char = unsafe { mem::transmute(wparam as u32) };
+ let chr: char = mem::transmute(wparam as u32);
send_event(window, ReceivedCharacter(chr));
0
},
@@ -188,7 +188,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
0
},
- _ => unsafe {
+ _ => {
user32::DefWindowProcW(window, msg, wparam, lparam)
}
}
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 8d2eb1e..5266ae4 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -235,7 +235,7 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
// handling vsync
if builder.vsync {
if extra_functions.SwapIntervalEXT.is_loaded() {
- let guard = try!(CurrentContextGuard::make_current(&real_window, &context));
+ let _guard = try!(CurrentContextGuard::make_current(&real_window, &context));
if extra_functions.SwapIntervalEXT(1) == 0 {
return Err(OsError(format!("wglSwapIntervalEXT failed")));
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 6b90f65..9daf0c3 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -1,7 +1,6 @@
use std::sync::atomic::AtomicBool;
use std::ptr;
use std::ffi::CString;
-use std::collections::VecDeque;
use std::sync::mpsc::Receiver;
use libc;
use {CreationError, Event, MouseCursor};
diff --git a/src/win32/monitor.rs b/src/win32/monitor.rs
index b5ffe2d..886d0bf 100644
--- a/src/win32/monitor.rs
+++ b/src/win32/monitor.rs
@@ -2,6 +2,7 @@ use winapi;
use user32;
use std::collections::VecDeque;
+use std::mem;
use native_monitor::NativeMonitorId;
@@ -83,15 +84,12 @@ impl Iterator for DeviceEnumerator {
fn wchar_as_string(wchar: &[winapi::WCHAR]) -> String {
String::from_utf16_lossy(wchar)
- .as_slice()
.trim_right_matches(0 as char)
.to_string()
}
/// Win32 implementation of the main `get_available_monitors` function.
pub fn get_available_monitors() -> VecDeque<MonitorID> {
- use std::{iter, mem, ptr};
-
// return value
let mut result = VecDeque::new();
@@ -120,8 +118,8 @@ pub fn get_available_monitors() -> VecDeque<MonitorID> {
// adding to the resulting list
result.push_back(MonitorID {
adapter_name: adapter.DeviceName,
- monitor_name: wchar_as_string(monitor.DeviceName.as_slice()),
- readable_name: wchar_as_string(monitor.DeviceString.as_slice()),
+ monitor_name: wchar_as_string(&monitor.DeviceName),
+ readable_name: wchar_as_string(&monitor.DeviceString),
flags: monitor.StateFlags,
position: position,
dimensions: dimensions,
@@ -165,7 +163,7 @@ impl MonitorID {
/// This is a Win32-only function for `MonitorID` that returns the system name of the adapter
/// device.
pub fn get_adapter_name(&self) -> &[winapi::WCHAR] {
- self.adapter_name.as_slice()
+ &self.adapter_name
}
/// This is a Win32-only function for `MonitorID` that returns the position of the
diff --git a/src/window.rs b/src/window.rs
index ad12e30..22fd400 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -249,7 +249,7 @@ impl Window {
/// Returns the position of the top-left hand corner of the window relative to the
/// top-left hand corner of the desktop.
///
- /// Note that the top-left hand corner of the desktop is not necessarly the same as
+ /// Note that the top-left hand corner of the desktop is not necessarily the same as
/// the screen. If the user uses a desktop with multiple monitors, the top-left hand corner
/// of the desktop is the top-left hand corner of the monitor at the top-left of the desktop.
///