aboutsummaryrefslogtreecommitdiffstats
path: root/src/win32
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/win32
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/win32')
-rw-r--r--src/win32/mod.rs17
-rw-r--r--src/win32/monitor.rs10
2 files changed, 15 insertions, 12 deletions
diff --git a/src/win32/mod.rs b/src/win32/mod.rs
index e90f93f..75706f6 100644
--- a/src/win32/mod.rs
+++ b/src/win32/mod.rs
@@ -1,5 +1,6 @@
use std::sync::atomic::AtomicBool;
use std::ptr;
+use std::collections::RingBuf;
use libc;
use {CreationError, Event};
@@ -14,7 +15,7 @@ mod gl;
mod init;
mod monitor;
-///
+///
pub struct HeadlessContext(Window);
impl HeadlessContext {
@@ -105,7 +106,7 @@ impl Window {
}
/// See the docs in the crate root file.
- ///
+ ///
/// Calls SetWindowText on the HWND.
pub fn set_title(&self, text: &str) {
unsafe {
@@ -200,11 +201,11 @@ impl Window {
/// See the docs in the crate root file.
// TODO: return iterator
- pub fn poll_events(&self) -> Vec<Event> {
- let mut events = Vec::new();
+ pub fn poll_events(&self) -> RingBuf<Event> {
+ let mut events = RingBuf::new();
loop {
match self.events_receiver.try_recv() {
- Ok(ev) => events.push(ev),
+ Ok(ev) => events.push_back(ev),
Err(_) => break
}
}
@@ -214,13 +215,13 @@ impl Window {
use std::sync::atomic::Relaxed;
self.is_closed.store(true, Relaxed);
}
-
+
events
}
/// See the docs in the crate root file.
// TODO: return iterator
- pub fn wait_events(&self) -> Vec<Event> {
+ pub fn wait_events(&self) -> RingBuf<Event> {
match self.events_receiver.recv_opt() {
Ok(ev) => {
// if the received event is `Closed`, setting `is_closed` to true
@@ -241,7 +242,7 @@ impl Window {
Err(_) => {
use std::sync::atomic::Relaxed;
self.is_closed.store(true, Relaxed);
- vec![]
+ RingBuf::new()
}
}
}
diff --git a/src/win32/monitor.rs b/src/win32/monitor.rs
index f841f1e..82ee02a 100644
--- a/src/win32/monitor.rs
+++ b/src/win32/monitor.rs
@@ -1,5 +1,7 @@
use winapi;
+use std::collections::RingBuf;
+
/// Win32 implementation of the main `MonitorID` object.
pub struct MonitorID {
/// The system name of the monitor.
@@ -22,11 +24,11 @@ pub struct MonitorID {
}
/// Win32 implementation of the main `get_available_monitors` function.
-pub fn get_available_monitors() -> Vec<MonitorID> {
+pub fn get_available_monitors() -> RingBuf<MonitorID> {
use std::{iter, mem, ptr};
// return value
- let mut result = Vec::new();
+ let mut result = RingBuf::new();
// enumerating the devices is done by querying device 0, then device 1, then device 2, etc.
// until the query function returns null
@@ -78,7 +80,7 @@ pub fn get_available_monitors() -> Vec<MonitorID> {
};
// adding to the resulting list
- result.push(MonitorID {
+ result.push_back(MonitorID {
name: output.DeviceName,
readable_name: readable_name,
flags: output.StateFlags,
@@ -123,7 +125,7 @@ impl MonitorID {
}
/// This is a Win32-only function for `MonitorID` that returns the position of the
- /// monitor on the desktop.
+ /// monitor on the desktop.
/// A window that is positionned at these coordinates will overlap the monitor.
pub fn get_position(&self) -> (uint, uint) {
self.position