From 0f7bd9071e9b64acb9f13e253d49c3790e50d560 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 3 Apr 2015 08:33:51 +0200 Subject: Remove all features for 1.0 beta --- src/android/mod.rs | 1 - src/lib.rs | 6 ++--- src/win32/init.rs | 18 +++++++------- src/win32/make_current_guard.rs | 1 - src/win32/mod.rs | 10 ++++---- src/x11/window/mod.rs | 53 +++++++++++++++++++---------------------- 6 files changed, 43 insertions(+), 46 deletions(-) (limited to 'src') 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 Result { // initializing variables to be sent to the task - let title = builder.title.utf16_units() - .chain(Some(0).into_iter()).collect::>(); // title to utf16 + + let title = OsStr::from_str(&builder.title).encode_wide().chain(Some(0).into_iter()) + .collect::>(); let (tx, rx) = channel(); @@ -265,8 +267,8 @@ unsafe fn init(title: Vec, builder: BuilderAttribs<'static>, } unsafe fn register_window_class() -> Vec { - let class_name: Vec = "Window Class".utf16_units().chain(Some(0).into_iter()) - .collect::>(); + let class_name = OsStr::from_str("Window Class").encode_wide().chain(Some(0).into_iter()) + .collect::>(); let class = winapi::WNDCLASSEXW { cbSize: mem::size_of::() 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 { - let name = "opengl32.dll".utf16_units().chain(Some(0).into_iter()) - .collect::>().as_ptr(); + let name = OsStr::from_str("opengl32.dll").encode_wide().chain(Some(0).into_iter()) + .collect::>(); - 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::>(); + unsafe { - user32::SetWindowTextW(self.window.0, - text.utf16_units().chain(Some(0).into_iter()) - .collect::>().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, + x: Arc, } 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 { - 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!(); } } -- cgit v1.2.3