aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/window
diff options
context:
space:
mode:
authortomaka <pierre.krieger1708@gmail.com>2015-01-02 09:22:27 +0100
committertomaka <pierre.krieger1708@gmail.com>2015-01-02 09:22:27 +0100
commitebe32bb2d803bc22c4b309acbbd48f3dc2a12127 (patch)
treeb2cc041b67dd54f64c6123981bffbd0201f9620a /src/x11/window
parentf68bf85a85ceb416f714bc36ff5aa5c6ae65c008 (diff)
parenta698146943bcd6df2a61bbfd56badf3018662709 (diff)
downloadglutin-ebe32bb2d803bc22c4b309acbbd48f3dc2a12127.tar.gz
glutin-ebe32bb2d803bc22c4b309acbbd48f3dc2a12127.zip
Merge pull request #180 from TyOverby/event-change
Change the way that event iterators are represented.
Diffstat (limited to 'src/x11/window')
-rw-r--r--src/x11/window/mod.rs25
-rw-r--r--src/x11/window/monitor.rs11
2 files changed, 19 insertions, 17 deletions
diff --git a/src/x11/window/mod.rs b/src/x11/window/mod.rs
index fc622ea..768d480 100644
--- a/src/x11/window/mod.rs
+++ b/src/x11/window/mod.rs
@@ -5,6 +5,7 @@ use libc;
use std::{mem, ptr};
use std::cell::Cell;
use std::sync::atomic::AtomicBool;
+use std::collections::RingBuf;
use super::ffi;
use std::sync::{Arc, Once, ONCE_INIT};
@@ -424,10 +425,10 @@ impl Window {
}
}
- pub fn poll_events(&self) -> Vec<Event> {
+ pub fn poll_events(&self) -> RingBuf<Event> {
use std::mem;
- let mut events = Vec::new();
+ let mut events = RingBuf::new();
loop {
use std::num::Int;
@@ -456,9 +457,9 @@ impl Window {
if client_msg.l[0] == self.wm_delete_window as libc::c_long {
self.is_closed.store(true, Relaxed);
- events.push(Closed);
+ events.push_back(Closed);
} else {
- events.push(Awakened);
+ events.push_back(Awakened);
}
},
@@ -468,14 +469,14 @@ impl Window {
let (current_width, current_height) = self.current_size.get();
if current_width != cfg_event.width || current_height != cfg_event.height {
self.current_size.set((cfg_event.width, cfg_event.height));
- events.push(Resized(cfg_event.width as uint, cfg_event.height as uint));
+ events.push_back(Resized(cfg_event.width as uint, cfg_event.height as uint));
}
},
ffi::MotionNotify => {
use events::Event::MouseMoved;
let event: &ffi::XMotionEvent = unsafe { mem::transmute(&xev) };
- events.push(MouseMoved((event.x as int, event.y as int)));
+ events.push_back(MouseMoved((event.x as int, event.y as int)));
},
ffi::KeyPress | ffi::KeyRelease => {
@@ -504,7 +505,7 @@ impl Window {
};
for chr in written.as_slice().chars() {
- events.push(ReceivedCharacter(chr));
+ events.push_back(ReceivedCharacter(chr));
}
let keysym = unsafe {
@@ -513,7 +514,7 @@ impl Window {
let vkey = events::keycode_to_element(keysym as libc::c_uint);
- events.push(KeyboardInput(state, event.keycode as u8, vkey));
+ events.push_back(KeyboardInput(state, event.keycode as u8, vkey));
},
ffi::ButtonPress | ffi::ButtonRelease => {
@@ -530,11 +531,11 @@ impl Window {
ffi::Button2 => Some(MiddleMouseButton),
ffi::Button3 => Some(RightMouseButton),
ffi::Button4 => {
- events.push(MouseWheel(1));
+ events.push_back(MouseWheel(1));
None
}
ffi::Button5 => {
- events.push(MouseWheel(-1));
+ events.push_back(MouseWheel(-1));
None
}
_ => None
@@ -542,7 +543,7 @@ impl Window {
match button {
Some(button) =>
- events.push(MouseInput(state, button)),
+ events.push_back(MouseInput(state, button)),
None => ()
};
},
@@ -554,7 +555,7 @@ impl Window {
events
}
- pub fn wait_events(&self) -> Vec<Event> {
+ pub fn wait_events(&self) -> RingBuf<Event> {
use std::mem;
loop {
diff --git a/src/x11/window/monitor.rs b/src/x11/window/monitor.rs
index f62a8ef..596dca7 100644
--- a/src/x11/window/monitor.rs
+++ b/src/x11/window/monitor.rs
@@ -1,10 +1,11 @@
-use std::{ptr};
+use std::ptr;
+use std::collections::RingBuf;
use super::super::ffi;
use super::ensure_thread_init;
pub struct MonitorID(pub uint);
-pub fn get_available_monitors() -> Vec<MonitorID> {
+pub fn get_available_monitors() -> RingBuf<MonitorID> {
ensure_thread_init();
let nb_monitors = unsafe {
let display = ffi::XOpenDisplay(ptr::null());
@@ -16,9 +17,9 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
nb_monitors
};
- let mut vec = Vec::new();
- vec.grow_fn(nb_monitors as uint, |i| MonitorID(i));
- vec
+ let mut monitors = RingBuf::new();
+ monitors.extend(range(0, nb_monitors).map(|i| MonitorID(i as uint)));
+ monitors
}
pub fn get_primary_monitor() -> MonitorID {