diff options
author | Joe Wilm <jwilm@users.noreply.github.com> | 2017-01-06 21:51:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-06 21:51:24 -0800 |
commit | 852c2d8f15bfc11f0222fa08626c38724accd35a (patch) | |
tree | 0880b8e38d76ae4ba0fb1772fbd11cae53168729 /src/window.rs | |
parent | 62739bd226974358a811b4680b4b74c268418f5b (diff) | |
parent | 4e1f4c8cd7180606156b71ad0222f60e4559f2b3 (diff) | |
download | r-alacritty-852c2d8f15bfc11f0222fa08626c38724accd35a.tar.gz r-alacritty-852c2d8f15bfc11f0222fa08626c38724accd35a.tar.bz2 r-alacritty-852c2d8f15bfc11f0222fa08626c38724accd35a.zip |
Merge pull request #131 from Manishearth/stable
Make it compile on stable Rust (almost)
Diffstat (limited to 'src/window.rs')
-rw-r--r-- | src/window.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/window.rs b/src/window.rs index b56b28a0..40729e99 100644 --- a/src/window.rs +++ b/src/window.rs @@ -14,6 +14,7 @@ use std::convert::From; use std::fmt::{self, Display}; use std::ops::Deref; +use std::sync::Mutex; use gl; use glutin; @@ -26,13 +27,13 @@ use glutin; /// /// This will fail horribly if more than one window is created. Don't do that :) fn window_resize_handler(width: u32, height: u32) { - unsafe { - RESIZE_CALLBACK.as_ref().map(|func| func(width, height)); - } + RESIZE_CALLBACK.lock().unwrap().as_ref().map(|func| (*func)(width, height)); } -/// The resize callback invoked by `window_resize_handler` -static mut RESIZE_CALLBACK: Option<Box<Fn(u32, u32)>> = None; +lazy_static! { + /// The resize callback invoked by `window_resize_handler` + static ref RESIZE_CALLBACK: Mutex<Option<Box<Fn(u32, u32) + 'static + Send>>> = Mutex::new(None); +} /// Window errors #[derive(Debug)] @@ -238,10 +239,9 @@ impl Window { /// /// This method takes self mutably to ensure there's no race condition /// setting the callback. - pub fn set_resize_callback<F: Fn(u32, u32) + 'static>(&mut self, func: F) { - unsafe { - RESIZE_CALLBACK = Some(Box::new(func)); - } + pub fn set_resize_callback<F: Fn(u32, u32) + 'static + Send>(&mut self, func: F) { + let mut guard = RESIZE_CALLBACK.lock().unwrap(); + *guard = Some(Box::new(func)); } pub fn inner_size_pixels(&self) -> Option<Size<Pixels<u32>>> { |