linux: Remove dead code from wayland & fix some trivial warnings.

This commit is contained in:
Victor Berger 2017-03-04 11:14:08 +01:00
parent 4e75c1e668
commit 9aaa788434
7 changed files with 25 additions and 89 deletions

View file

@ -11,21 +11,6 @@ use super::WaylandContext;
use super::wayland_window;
use super::wayland_window::DecoratedSurface;
#[derive(Clone)]
pub struct WindowProxy {
ctxt: Arc<WaylandContext>,
eviter: Arc<Mutex<VecDeque<Event>>>,
}
impl WindowProxy {
#[inline]
pub fn wakeup_event_loop(&self) {
// Send a sync event, so that any waiting "dispatch" will return
self.ctxt.display.sync();
self.eviter.lock().unwrap().push_back(Event::Awakened);
}
}
pub struct Window {
ctxt: Arc<WaylandContext>,
evq: Mutex<EventQueue>,
@ -48,18 +33,6 @@ impl<'a> Iterator for PollEventsIterator<'a> {
}
}
pub struct WaitEventsIterator<'a> {
window: &'a Window,
}
impl<'a> Iterator for WaitEventsIterator<'a> {
type Item = Event;
fn next(&mut self) -> Option<Event> {
self.window.next_event(true)
}
}
impl Window {
pub fn new(ctxt: Arc<WaylandContext>, attributes: &WindowAttributes) -> Result<Window, CreationError>
{
@ -107,24 +80,12 @@ impl Window {
}
fn process_resize(&self) {
use std::cmp::max;
let mut evq_guard = self.evq.lock().unwrap();
let mut state = evq_guard.state();
let newsize = {
let decorated = state.get_mut_handler::<DecoratedSurface<DecoratedHandler>>(self.decorated_id);
let newsize = decorated.handler().as_mut().and_then(|h| h.take_newsize());
if let Some((w, h)) = newsize {
decorated.resize(w as i32, h as i32);
*self.size.lock().unwrap() = (w, h);
}
newsize
};
// callback_resize if any
if let Some((w, h)) = newsize {
let mut handler = state.get_mut_handler::<WindowHandler>(self.handler_id);
if let Some(ref callback) = handler.resize_callback {
callback(w, h);
}
let decorated = state.get_mut_handler::<DecoratedSurface<DecoratedHandler>>(self.decorated_id);
if let Some((w, h)) = decorated.handler().as_mut().and_then(|h| h.take_newsize()) {
decorated.resize(w as i32, h as i32);
*self.size.lock().unwrap() = (w, h);
self.eviter.lock().unwrap().push_back(Event::Resized(w,h));
}
}
@ -143,18 +104,19 @@ impl Window {
// read some events if some are waiting & queue is empty
if let Some(guard) = self.evq.lock().unwrap().prepare_read() {
guard.read_events();
guard.read_events().expect("Wayland connection unexpectedly lost");
}
// try a pending dispatch
{
self.ctxt.dispatch_pending();
self.evq.lock().unwrap().dispatch_pending();
self.evq.lock().unwrap().dispatch_pending()
.expect("Wayland connection unexpectedly lost");
// some events were dispatched, need to process a potential resising
self.process_resize();
}
let mut evt = {
evt = {
let mut guard = self.eviter.lock().unwrap();
guard.pop_front()
};
@ -164,7 +126,8 @@ impl Window {
{
self.ctxt.flush();
self.ctxt.dispatch();
self.evq.lock().unwrap().dispatch_pending();
self.evq.lock().unwrap().dispatch_pending()
.expect("Wayland connection unexpectedly lost");
// some events were dispatched, need to process a potential resising
self.process_resize();
}
@ -178,7 +141,7 @@ impl Window {
pub fn set_title(&self, title: &str) {
let mut guard = self.evq.lock().unwrap();
let mut state = guard.state();
let mut decorated = state.get_mut_handler::<DecoratedSurface<DecoratedHandler>>(self.decorated_id);
let decorated = state.get_mut_handler::<DecoratedSurface<DecoratedHandler>>(self.decorated_id);
decorated.set_title(title.into())
}
@ -223,14 +186,6 @@ impl Window {
decorated.resize(x as i32, y as i32);
}
#[inline]
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy {
ctxt: self.ctxt.clone(),
eviter: self.eviter.clone()
}
}
#[inline]
pub fn poll_events(&self) -> PollEventsIterator {
PollEventsIterator {
@ -238,21 +193,6 @@ impl Window {
}
}
#[inline]
pub fn wait_events(&self) -> WaitEventsIterator {
WaitEventsIterator {
window: self
}
}
#[inline]
pub fn set_window_resize_callback(&mut self, callback: Option<fn(u32, u32)>) {
let mut guard = self.evq.lock().unwrap();
let mut state = guard.state();
let mut handler = state.get_mut_handler::<WindowHandler>(self.handler_id);
handler.resize_callback = callback;
}
#[inline]
pub fn set_cursor(&self, _cursor: MouseCursor) {
// TODO
@ -321,20 +261,18 @@ impl wayland_window::Handler for DecoratedHandler {
struct WindowHandler {
my_id: usize,
resize_callback: Option<fn(u32,u32)>,
}
impl WindowHandler {
fn new() -> WindowHandler {
WindowHandler {
my_id: 0,
resize_callback: None
}
}
}
impl Init for WindowHandler {
fn init(&mut self, evqh: &mut EventQueueHandle, index: usize) {
fn init(&mut self, _evqh: &mut EventQueueHandle, index: usize) {
self.my_id = index;
}
}