aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2014-10-24 12:31:33 +0200
committertomaka <pierre.krieger1708@gmail.com>2014-10-24 12:31:33 +0200
commit2c9eaf86512a77da5f20acc87d9c5cd949078a85 (patch)
tree9afb2be42ba29021699d5b2611be0cd4e11e53cb /src/x11
parentfe8646c55681d6ecbd290010ab702f8f0feecc00 (diff)
parent97c471dc05b2b9c928758ae23f2f8cafd9d36dda (diff)
downloadglutin-2c9eaf86512a77da5f20acc87d9c5cd949078a85.tar.gz
glutin-2c9eaf86512a77da5f20acc87d9c5cd949078a85.zip
Merge pull request #65 from glennw/x-threads
Add an interface for providing system wide initialization options to the windowing system.
Diffstat (limited to 'src/x11')
-rw-r--r--src/x11/ffi.rs1
-rw-r--r--src/x11/window/mod.rs12
-rw-r--r--src/x11/window/monitor.rs3
3 files changed, 16 insertions, 0 deletions
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 3d69a3e..99cbf9d 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 465d132..013b48b 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() {