aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--build.rs1
-rw-r--r--src/android/mod.rs3
-rw-r--r--src/events.rs8
-rw-r--r--src/lib.rs24
-rw-r--r--src/x11/window/mod.rs8
5 files changed, 32 insertions, 12 deletions
diff --git a/build.rs b/build.rs
index 15a0f6d..a154868 100644
--- a/build.rs
+++ b/build.rs
@@ -1,3 +1,4 @@
+#![allow(unstable)]
extern crate gl_generator;
extern crate khronos_api;
diff --git a/src/android/mod.rs b/src/android/mod.rs
index bde2417..7c4f186 100644
--- a/src/android/mod.rs
+++ b/src/android/mod.rs
@@ -263,7 +263,8 @@ impl Window {
}
pub fn get_proc_address(&self, addr: &str) -> *const () {
- let addr = CString::from_slice(addr.as_bytes()).as_slice_with_nul().as_ptr();
+ let addr = CString::from_slice(addr.as_bytes());
+ let addr = addr.as_slice_with_nul().as_ptr();
unsafe {
ffi::egl::GetProcAddress(addr) as *const ()
}
diff --git a/src/events.rs b/src/events.rs
index 34234b2..680a077 100644
--- a/src/events.rs
+++ b/src/events.rs
@@ -1,4 +1,4 @@
-#[derive(Clone, Show, Copy)]
+#[derive(Clone, Debug, Copy)]
pub enum Event {
/// The size of the window has changed.
Resized(u32, u32),
@@ -38,13 +38,13 @@ pub enum Event {
pub type ScanCode = u8;
-#[derive(Show, Hash, PartialEq, Eq, Clone, Copy)]
+#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum ElementState {
Pressed,
Released,
}
-#[derive(Show, Hash, PartialEq, Eq, Clone, Copy)]
+#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum MouseButton {
LeftMouseButton,
RightMouseButton,
@@ -52,7 +52,7 @@ pub enum MouseButton {
OtherMouseButton(u8),
}
-#[derive(Show, Hash, PartialEq, Eq, Clone, Copy)]
+#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)]
pub enum VirtualKeyCode {
/// The '1' key over the letters.
Key1,
diff --git a/src/lib.rs b/src/lib.rs
index 436c0cf..f31edfe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,6 @@
#![feature(unsafe_destructor)]
#![unstable]
+#![allow(unstable)]
//! The purpose of this library is to provide an OpenGL context on as many
//! platforms as possible.
@@ -66,14 +67,14 @@ mod events;
pub struct MonitorID(winimpl::MonitorID);
/// Error that can happen while creating a window or a headless renderer.
-#[derive(Clone, Show, PartialEq, Eq)]
+#[derive(Clone, Debug, PartialEq, Eq)]
pub enum CreationError {
OsError(String),
NotSupported,
}
-impl std::error::Error for CreationError {
- fn description(&self) -> &str {
+impl CreationError {
+ fn to_string(&self) -> &str {
match self {
&CreationError::OsError(ref text) => text.as_slice(),
&CreationError::NotSupported => "Some of the requested attributes are not supported",
@@ -81,8 +82,20 @@ impl std::error::Error for CreationError {
}
}
+impl std::fmt::Display for CreationError {
+ fn fmt(&self, formatter: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ formatter.write_str(self.to_string())
+ }
+}
+
+impl std::error::Error for CreationError {
+ fn description(&self) -> &str {
+ self.to_string()
+ }
+}
+
/// All APIs related to OpenGL that you can possibly get while using glutin.
-#[derive(Show, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Api {
/// The classical OpenGL. Available on Windows, Linux, OS/X.
OpenGl,
@@ -90,7 +103,7 @@ pub enum Api {
OpenGlEs,
}
-#[derive(Show, Copy)]
+#[derive(Debug, Copy)]
pub enum MouseCursor {
/// The platform-dependent default cursor.
Default,
@@ -154,6 +167,7 @@ pub struct WindowBuilder<'a> {
/// Attributes
struct BuilderAttribs<'a> {
+ #[allow(dead_code)]
headless: bool,
strict: bool,
sharing: Option<&'a winimpl::Window>,
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index d3c5163..efdc759 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -8,6 +8,7 @@ use std::sync::atomic::AtomicBool;
use std::collections::RingBuf;
use super::ffi;
use std::sync::{Arc, Once, ONCE_INIT};
+use std::sync::{StaticMutex, MUTEX_INIT};
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
@@ -262,6 +263,10 @@ 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());
if im.is_null() {
return Err(OsError(format!("XOpenIM failed")));
@@ -562,8 +567,7 @@ impl Window {
mem::transmute(buffer.as_mut_ptr()),
buffer.len() as libc::c_int, ptr::null_mut(), ptr::null_mut());
- str::from_utf8(buffer.as_slice().slice_to(count as usize))
- .unwrap_or("").to_string()
+ str::from_utf8(&buffer.as_slice()[..count as usize]).unwrap_or("").to_string()
};
for chr in written.as_slice().chars() {