aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32
diff options
context:
space:
mode:
Diffstat (limited to 'src/win32')
-rw-r--r--src/win32/callback.rs18
-rw-r--r--src/win32/init.rs43
-rw-r--r--src/win32/make_current_guard.rs5
-rw-r--r--src/win32/mod.rs10
4 files changed, 34 insertions, 42 deletions
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 c296a9d..d83c90f 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;
@@ -23,7 +20,8 @@ use CursorState;
use GlRequest;
use PixelFormat;
-use std::ffi::{CStr, CString};
+use std::ffi::{CStr, CString, OsStr};
+use std::os::windows::ffi::OsStrExt;
use std::sync::mpsc::channel;
use libc;
@@ -41,8 +39,9 @@ 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()
- .chain(Some(0).into_iter()).collect::<Vec<u16>>(); // title to utf16
+
+ let title = OsStr::from_str(&builder.title).encode_wide().chain(Some(0).into_iter())
+ .collect::<Vec<_>>();
let (tx, rx) = channel();
@@ -125,13 +124,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 +190,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)
@@ -268,8 +267,8 @@ unsafe fn init(title: Vec<u16>, builder: BuilderAttribs<'static>,
}
unsafe fn register_window_class() -> Vec<u16> {
- let class_name: Vec<u16> = "Window Class".utf16_units().chain(Some(0).into_iter())
- .collect::<Vec<u16>>();
+ let class_name = OsStr::from_str("Window Class").encode_wide().chain(Some(0).into_iter())
+ .collect::<Vec<_>>();
let class = winapi::WNDCLASSEXW {
cbSize: mem::size_of::<winapi::WNDCLASSEXW>() as winapi::UINT,
@@ -377,7 +376,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 +398,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))
@@ -519,26 +518,26 @@ 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(())
}
unsafe fn load_opengl32_dll() -> Result<winapi::HMODULE, CreationError> {
- let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter())
- .collect::<Vec<u16>>().as_ptr();
+ let name = OsStr::from_str("opengl32.dll").encode_wide().chain(Some(0).into_iter())
+ .collect::<Vec<_>>();
- let lib = kernel32::LoadLibraryW(name);
+ let lib = kernel32::LoadLibraryW(name.as_ptr());
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..8983899 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 {
@@ -42,7 +42,6 @@ impl<'a, 'b> CurrentContextGuard<'a, 'b> {
}
}
-#[unsafe_destructor]
impl<'a, 'b> Drop for CurrentContextGuard<'a, 'b> {
fn drop(&mut self) {
unsafe {
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index 2769bf1..be72d53 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -2,6 +2,8 @@ use std::sync::atomic::AtomicBool;
use std::mem;
use std::ptr;
use std::ffi::CString;
+use std::ffi::OsStr;
+use std::os::windows::ffi::OsStrExt;
use std::sync::{
Arc,
Mutex
@@ -109,10 +111,11 @@ impl Window {
///
/// Calls SetWindowText on the HWND.
pub fn set_title(&self, text: &str) {
+ let text = OsStr::from_str(text).encode_wide().chain(Some(0).into_iter())
+ .collect::<Vec<_>>();
+
unsafe {
- user32::SetWindowTextW(self.window.0,
- text.utf16_units().chain(Some(0).into_iter())
- .collect::<Vec<u16>>().as_ptr() as winapi::LPCWSTR);
+ user32::SetWindowTextW(self.window.0, text.as_ptr() as winapi::LPCWSTR);
}
}
@@ -395,7 +398,6 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
}
}
-#[unsafe_destructor]
impl Drop for Window {
fn drop(&mut self) {
unsafe {