aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPierre Krieger <pierre.krieger1708@gmail.com>2015-04-02 22:04:17 +0200
committerPierre Krieger <pierre.krieger1708@gmail.com>2015-04-02 22:41:35 +0200
commitd33c138164d069f025439f97920771f1f8c7775e (patch)
treed54b6953a9540d3b9e93c7a76ac48814be8c9773 /src
parent2e1fe8283f82208375737674a731d2fe3c5e4539 (diff)
downloadglutin-d33c138164d069f025439f97920771f1f8c7775e.tar.gz
glutin-d33c138164d069f025439f97920771f1f8c7775e.zip
Rustup
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs2
-rw-r--r--src/win32/callback.rs18
-rw-r--r--src/win32/init.rs27
-rw-r--r--src/win32/make_current_guard.rs4
-rw-r--r--src/x11/headless.rs12
-rw-r--r--src/x11/window/mod.rs4
6 files changed, 25 insertions, 42 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c97f769..cf06b7b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,4 @@
-#![feature(collections, unsafe_destructor, os, core, std_misc, alloc)]
+#![feature(collections, unsafe_destructor, core, std_misc, alloc)]
#![unstable]
//! The purpose of this library is to provide an OpenGL context on as many
diff --git a/src/win32/callback.rs b/src/win32/callback.rs
index 66d88e7..e852eeb 100644
--- a/src/win32/callback.rs
+++ b/src/win32/callback.rs
@@ -1,12 +1,8 @@
use std::mem;
use std::ptr;
-use std::rc::Rc;
use std::cell::RefCell;
use std::sync::mpsc::Sender;
-use std::sync::{
- Arc,
- Mutex
-};
+use std::sync::{Arc, Mutex};
use CursorState;
use Event;
@@ -232,16 +228,12 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
if let Ok(cursor_state) = cstash.cursor_state.lock() {
match *cursor_state {
CursorState::Normal => {
- unsafe {
- user32::SetCursor(user32::LoadCursorW(
- ptr::null_mut(),
- winapi::IDC_ARROW));
- }
+ user32::SetCursor(user32::LoadCursorW(
+ ptr::null_mut(),
+ winapi::IDC_ARROW));
},
CursorState::Grab | CursorState::Hide => {
- unsafe {
- user32::SetCursor(ptr::null_mut());
- }
+ user32::SetCursor(ptr::null_mut());
}
}
}
diff --git a/src/win32/init.rs b/src/win32/init.rs
index d0012e2..0a77cb7 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -1,11 +1,8 @@
use std::sync::atomic::AtomicBool;
-use std::sync::{
- Arc,
- Mutex
-};
+use std::sync::{Arc, Mutex};
+use std::io;
use std::ptr;
use std::mem;
-use std::os;
use std::thread;
use super::callback;
@@ -41,7 +38,7 @@ pub fn new_window(builder: BuilderAttribs<'static>, builder_sharelists: Option<C
-> Result<Window, CreationError>
{
// initializing variables to be sent to the task
- let title = builder.title.as_slice().utf16_units()
+ let title = builder.title.utf16_units()
.chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
let (tx, rx) = channel();
@@ -125,13 +122,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
if handle.is_null() {
return Err(OsError(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
let hdc = user32::GetDC(handle);
if hdc.is_null() {
let err = Err(OsError(format!("GetDC function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
return err;
}
@@ -191,13 +188,13 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
if handle.is_null() {
return Err(OsError(format!("CreateWindowEx function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
let hdc = user32::GetDC(handle);
if hdc.is_null() {
return Err(OsError(format!("GetDC function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
WindowWrapper(handle, hdc)
@@ -377,7 +374,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
Some(extra_functions.CreateContextAttribsARB(hdc.1 as *const libc::c_void,
share as *const libc::c_void,
- attributes.as_slice().as_ptr()))
+ attributes.as_ptr()))
} else {
None
@@ -399,7 +396,7 @@ unsafe fn create_context(extra: Option<(&gl::wgl_extra::Wgl, &BuilderAttribs<'st
if ctxt.is_null() {
return Err(OsError(format!("OpenGL context creation failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(ContextWrapper(ctxt as winapi::HGLRC))
@@ -506,12 +503,12 @@ unsafe fn set_pixel_format(hdc: &WindowWrapper, id: libc::c_int) -> Result<(), C
as winapi::UINT, &mut output) == 0
{
return Err(OsError(format!("DescribePixelFormat function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
if gdi32::SetPixelFormat(hdc.1, id, &output) == 0 {
return Err(OsError(format!("SetPixelFormat function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(())
@@ -525,7 +522,7 @@ unsafe fn load_opengl32_dll() -> Result<winapi::HMODULE, CreationError> {
if lib.is_null() {
return Err(OsError(format!("LoadLibrary function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(lib)
diff --git a/src/win32/make_current_guard.rs b/src/win32/make_current_guard.rs
index d6bcc8e..2435454 100644
--- a/src/win32/make_current_guard.rs
+++ b/src/win32/make_current_guard.rs
@@ -1,5 +1,5 @@
use std::marker::PhantomData;
-use std::os;
+use std::io;
use libc;
use winapi;
@@ -30,7 +30,7 @@ impl<'a, 'b> CurrentContextGuard<'a, 'b> {
if result == 0 {
return Err(CreationError::OsError(format!("wglMakeCurrent function failed: {}",
- os::error_string(os::errno()))));
+ format!("{}", io::Error::last_os_error()))));
}
Ok(CurrentContextGuard {
diff --git a/src/x11/headless.rs b/src/x11/headless.rs
index e23dfa7..291f04d 100644
--- a/src/x11/headless.rs
+++ b/src/x11/headless.rs
@@ -5,12 +5,6 @@ use libc;
use std::{mem, ptr};
use super::ffi;
-fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
- use std::ffi::CString;
- let c_str = CString::from_slice(s.as_bytes());
- f(c_str.as_ptr())
-}
-
pub struct HeadlessContext {
context: ffi::OSMesaContext,
buffer: Vec<u32>,
@@ -53,9 +47,9 @@ impl HeadlessContext {
pub fn get_proc_address(&self, addr: &str) -> *const () {
unsafe {
- with_c_str(addr, |s| {
- ffi::OSMesaGetProcAddress(mem::transmute(s)) as *const ()
- })
+ use std::ffi::CString;
+ let c_str = CString::new(addr.as_bytes().to_vec()).unwrap();
+ ffi::OSMesaGetProcAddress(mem::transmute(c_str.as_ptr())) as *const ()
}
}
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 7c93ad3..0188386 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -39,7 +39,7 @@ fn ensure_thread_init() {
fn with_c_str<F, T>(s: &str, f: F) -> T where F: FnOnce(*const libc::c_char) -> T {
use std::ffi::CString;
- let c_str = CString::from_slice(s.as_bytes());
+ let c_str = CString::new(s.as_bytes().to_vec()).unwrap();
f(c_str.as_ptr())
}
@@ -778,7 +778,7 @@ impl Window {
MouseCursor::AllScroll | MouseCursor::ZoomIn |
MouseCursor::ZoomOut => "left_ptr",
};
- let c_string = CString::from_slice(cursor_name.as_bytes());
+ let c_string = CString::new(cursor_name.as_bytes().to_vec()).unwrap();
let xcursor = ffi::XcursorLibraryLoadCursor(self.x.display, c_string.as_ptr());
ffi::XDefineCursor (self.x.display, self.x.window, xcursor);
ffi::XFlush(self.x.display);