aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Watson <gw@intuitionlibrary.com>2014-10-24 14:49:07 +1000
committerGlenn Watson <gw@intuitionlibrary.com>2014-10-24 19:58:19 +1000
commit97c471dc05b2b9c928758ae23f2f8cafd9d36dda (patch)
treeeacc999375ca034e173a32a80c5415a0b998a97a
parentd8ca679a6ec92ea8428ad5e3733a65b2e045d02c (diff)
downloadglutin-97c471dc05b2b9c928758ae23f2f8cafd9d36dda.tar.gz
glutin-97c471dc05b2b9c928758ae23f2f8cafd9d36dda.zip
Add an interface for providing system wide initialization options to the windowing system.
This allows setting up Linux based systems which use multithreaded OpenGL contexts.
-rw-r--r--src/lib.rs2
-rw-r--r--src/x11/ffi.rs1
-rw-r--r--src/x11/window/mod.rs12
-rw-r--r--src/x11/window/monitor.rs3
4 files changed, 18 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 041ebeb..b443ab7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,6 +37,8 @@ extern crate libc;
extern crate cocoa;
#[cfg(target_os = "macos")]
extern crate core_foundation;
+#[cfg(target_os = "linux")]
+extern crate sync;
pub use events::*;
diff --git a/src/x11/ffi.rs b/src/x11/ffi.rs
index 822f755..f9dc3ad 100644
--- a/src/x11/ffi.rs
+++ b/src/x11/ffi.rs
@@ -1410,6 +1410,7 @@ extern "C" {
pub fn XMoveWindow(display: *mut Display, w: Window, x: libc::c_int, y: libc::c_int);
pub fn XMapWindow(display: *mut Display, w: Window);
pub fn XNextEvent(display: *mut Display, event_return: *mut XEvent);
+ pub fn XInitThreads() -> Status;
pub fn XOpenDisplay(display_name: *const libc::c_char) -> *mut Display;
pub fn XPeekEvent(display: *mut Display, event_return: *mut XEvent);
pub fn XRefreshKeyboardMapping(event_map: *const XEvent);
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index cb73958..9d29c07 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -3,12 +3,23 @@ use libc;
use std::{mem, ptr};
use std::sync::atomic::AtomicBool;
use super::ffi;
+use sync::one::{Once, ONCE_INIT};
pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor};
mod events;
mod monitor;
+static THREAD_INIT: Once = ONCE_INIT;
+
+fn ensure_thread_init() {
+ THREAD_INIT.doit(|| {
+ unsafe {
+ ffi::XInitThreads();
+ }
+ });
+}
+
pub struct Window {
display: *mut ffi::Display,
window: ffi::Window,
@@ -24,6 +35,7 @@ pub struct Window {
impl Window {
pub fn new(builder: WindowBuilder) -> Result<Window, String> {
+ ensure_thread_init();
let dimensions = builder.dimensions.unwrap_or((800, 600));
// calling XOpenDisplay
diff --git a/src/x11/window/monitor.rs b/src/x11/window/monitor.rs
index b72ed15..a9e77d7 100644
--- a/src/x11/window/monitor.rs
+++ b/src/x11/window/monitor.rs
@@ -1,9 +1,11 @@
use std::{ptr};
use super::super::ffi;
+use super::ensure_thread_init;
pub struct MonitorID(pub uint);
pub fn get_available_monitors() -> Vec<MonitorID> {
+ ensure_thread_init();
let nb_monitors = unsafe {
let display = ffi::XOpenDisplay(ptr::null());
if display.is_null() {
@@ -20,6 +22,7 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
}
pub fn get_primary_monitor() -> MonitorID {
+ ensure_thread_init();
let primary_monitor = unsafe {
let display = ffi::XOpenDisplay(ptr::null());
if display.is_null() {