aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml1
-rw-r--r--src/android/mod.rs1
-rw-r--r--src/lib.rs6
-rw-r--r--src/win32/init.rs18
-rw-r--r--src/win32/make_current_guard.rs1
-rw-r--r--src/win32/mod.rs10
-rw-r--r--src/x11/window/mod.rs53
7 files changed, 44 insertions, 46 deletions
diff --git a/Cargo.toml b/Cargo.toml
index cf0f69d..3dcb660 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,6 +17,7 @@ headless = []
[dependencies]
gl_common = "*"
+lazy_static = "0.1"
libc = "*"
[build-dependencies]
diff --git a/src/android/mod.rs b/src/android/mod.rs
index 79590f4..5c7096c 100644
--- a/src/android/mod.rs
+++ b/src/android/mod.rs
@@ -385,7 +385,6 @@ impl WindowProxy {
}
}
-#[unsafe_destructor]
impl Drop for Window {
fn drop(&mut self) {
use std::ptr;
diff --git a/src/lib.rs b/src/lib.rs
index cf06b7b..1eea9a4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,6 +1,3 @@
-#![feature(collections, unsafe_destructor, core, std_misc, alloc)]
-#![unstable]
-
//! The purpose of this library is to provide an OpenGL context on as many
//! platforms as possible.
//!
@@ -26,6 +23,9 @@
//!
//! By default only `window` is enabled.
+#[macro_use]
+extern crate lazy_static;
+
extern crate gl_common;
extern crate libc;
diff --git a/src/win32/init.rs b/src/win32/init.rs
index 0a77cb7..5cf4021 100644
--- a/src/win32/init.rs
+++ b/src/win32/init.rs
@@ -20,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;
@@ -38,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.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();
@@ -265,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,
@@ -515,10 +517,10 @@ unsafe fn set_pixel_format(hdc: &WindowWrapper, id: libc::c_int) -> Result<(), C
}
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: {}",
diff --git a/src/win32/make_current_guard.rs b/src/win32/make_current_guard.rs
index 2435454..8983899 100644
--- a/src/win32/make_current_guard.rs
+++ b/src/win32/make_current_guard.rs
@@ -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 {
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index 0188386..fa8f91c 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -8,7 +8,6 @@ use std::sync::atomic::AtomicBool;
use std::collections::VecDeque;
use super::ffi;
use std::sync::{Arc, Mutex, Once, ONCE_INIT, Weak};
-use std::sync::{StaticMutex, MUTEX_INIT};
use Api;
use CursorState;
@@ -21,6 +20,11 @@ mod monitor;
static THREAD_INIT: Once = ONCE_INIT;
+// XOpenIM doesn't seem to be thread-safe
+lazy_static! { // TODO: use a static mutex when that's possible, and put me back in my function
+ static ref GLOBAL_XOPENIM_LOCK: Mutex<()> = Mutex::new(());
+}
+
fn x_error_callback(_: *mut ffi::Display, event: *mut ffi::XErrorEvent) -> libc::c_int {
unsafe {
println!("[glutin] x error code={} major={} minor={}!", (*event).error_code, (*event).request_code, (*event).minor_code);
@@ -82,30 +86,25 @@ impl Drop for XWindow {
#[derive(Clone)]
pub struct WindowProxy {
- x: Weak<XWindow>,
+ x: Arc<XWindow>,
}
impl WindowProxy {
pub fn wakeup_event_loop(&self) {
- match self.x.upgrade() {
- Some(x) => {
- let mut xev = ffi::XClientMessageEvent {
- type_: ffi::ClientMessage,
- window: x.window,
- format: 32,
- message_type: 0,
- serial: 0,
- send_event: 0,
- display: x.display,
- l: [0, 0, 0, 0, 0],
- };
+ let mut xev = ffi::XClientMessageEvent {
+ type_: ffi::ClientMessage,
+ window: self.x.window,
+ format: 32,
+ message_type: 0,
+ serial: 0,
+ send_event: 0,
+ display: self.x.display,
+ l: [0, 0, 0, 0, 0],
+ };
- unsafe {
- ffi::XSendEvent(x.display, x.window, 0, 0, mem::transmute(&mut xev));
- ffi::XFlush(x.display);
- }
- }
- None => {}
+ unsafe {
+ ffi::XSendEvent(self.x.display, self.x.window, 0, 0, mem::transmute(&mut xev));
+ ffi::XFlush(self.x.display);
}
}
}
@@ -118,15 +117,13 @@ impl<'a> Iterator for PollEventsIterator<'a> {
type Item = Event;
fn next(&mut self) -> Option<Event> {
- use std::num::Int;
-
if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() {
return Some(ev);
}
loop {
let mut xev = unsafe { mem::uninitialized() };
- let res = unsafe { ffi::XCheckMaskEvent(self.window.x.display, Int::max_value(), &mut xev) };
+ let res = unsafe { ffi::XCheckMaskEvent(self.window.x.display, -1, &mut xev) };
if res == 0 {
let res = unsafe { ffi::XCheckTypedEvent(self.window.x.display, ffi::ClientMessage, &mut xev) };
@@ -192,12 +189,12 @@ impl<'a> Iterator for PollEventsIterator<'a> {
mem::transmute(buffer.as_mut_ptr()),
buffer.len() as libc::c_int, ptr::null_mut(), ptr::null_mut());
- str::from_utf8(&buffer.as_slice()[..count as usize]).unwrap_or("").to_string()
+ str::from_utf8(&buffer[..count as usize]).unwrap_or("").to_string()
};
{
let mut pending = self.window.pending_events.lock().unwrap();
- for chr in written.as_slice().chars() {
+ for chr in written.chars() {
pending.push_back(ReceivedCharacter(chr));
}
}
@@ -445,8 +442,6 @@ impl Window {
// creating IM
let im = unsafe {
- // XOpenIM doesn't seem to be thread-safe
- static GLOBAL_XOPENIM_LOCK: StaticMutex = MUTEX_INIT;
let _lock = GLOBAL_XOPENIM_LOCK.lock().unwrap();
let im = ffi::XOpenIM(display, ptr::null(), ptr::null_mut(), ptr::null_mut());
@@ -681,7 +676,7 @@ impl Window {
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy {
- x: self.x.downgrade()
+ x: self.x.clone()
}
}
@@ -828,7 +823,7 @@ impl Window {
1.0
}
- pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
+ pub fn set_cursor_position(&self, _x: i32, _y: i32) -> Result<(), ()> {
unimplemented!();
}
}