From 9aaa78843495608684428943ffada15ea1bf73e3 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Sat, 4 Mar 2017 11:14:08 +0100 Subject: [PATCH] linux: Remove dead code from wayland & fix some trivial warnings. --- src/platform/linux/mod.rs | 2 - src/platform/linux/wayland/context.rs | 12 ++-- src/platform/linux/wayland/mod.rs | 7 +-- src/platform/linux/wayland/window.rs | 86 ++++----------------------- src/platform/linux/x11/mod.rs | 4 +- src/platform/linux/x11/window.rs | 2 +- src/platform/linux/x11/xdisplay.rs | 1 - 7 files changed, 25 insertions(+), 89 deletions(-) diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 0712469f..3669a3ce 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -5,9 +5,7 @@ use std::sync::Arc; use CreationError; use CursorState; -use WindowEvent as Event; use MouseCursor; -use WindowAttributes; use libc; use self::x11::XConnection; diff --git a/src/platform/linux/wayland/context.rs b/src/platform/linux/wayland/context.rs index c767056a..90b4027a 100644 --- a/src/platform/linux/wayland/context.rs +++ b/src/platform/linux/wayland/context.rs @@ -94,7 +94,9 @@ impl WaylandEnv { fn get_seat(&self) -> Option { for &(name, ref interface, version) in self.inner.globals() { if interface == "wl_seat" { - // this "expect" cannot trigger (see https://github.com/vberger/wayland-client-rs/issues/69) + if version < 5 { + panic!("Winit requires at least version 5 of the wl_seat global."); + } let seat = self.registry.bind::(5, name).expect("Seat cannot be destroyed"); return Some(seat) } @@ -209,7 +211,7 @@ impl WaylandContext { // this handles both "no libwayland" and "no compositor" cases let (display, mut event_queue) = match default_connect() { Ok(ret) => ret, - Err(e) => return None + Err(_) => return None }; // this "expect" cannot trigger (see https://github.com/vberger/wayland-client-rs/issues/69) @@ -237,7 +239,7 @@ impl WaylandContext { } pub fn flush(&self) { - self.display.flush(); + let _ = self.display.flush(); } pub fn with_output(&self, id: MonitorId, f: F) where F: FnOnce(&wl_output::WlOutput) { @@ -512,7 +514,7 @@ impl wl_pointer::Handler for WaylandEnv { fn axis_source(&mut self, _evqh: &mut EventQueueHandle, _proxy: &wl_pointer::WlPointer, - axis_source: wl_pointer::AxisSource) + _axis_source: wl_pointer::AxisSource) { } @@ -520,7 +522,7 @@ impl wl_pointer::Handler for WaylandEnv { _evqh: &mut EventQueueHandle, _proxy: &wl_pointer::WlPointer, _time: u32, - axis: wl_pointer::Axis) + _axis: wl_pointer::Axis) { self.axis_state = TouchPhase::Ended; } diff --git a/src/platform/linux/wayland/mod.rs b/src/platform/linux/wayland/mod.rs index 9cf6751c..c3ab1c4b 100644 --- a/src/platform/linux/wayland/mod.rs +++ b/src/platform/linux/wayland/mod.rs @@ -1,13 +1,12 @@ #![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] -pub use self::window::{PollEventsIterator, WaitEventsIterator, Window, WindowProxy}; +use self::window::Window; pub use self::context::{WaylandContext, MonitorId, get_available_monitors, get_primary_monitor}; extern crate wayland_kbd; extern crate wayland_window; -use platform::PlatformSpecificWindowBuilderAttributes; use CreationError; use std::sync::Arc; @@ -43,7 +42,7 @@ impl EventsLoop { pub fn poll_events(&self, mut callback: F) where F: FnMut(::Event) { - let mut windows = self.windows.lock().unwrap(); + let windows = self.windows.lock().unwrap(); for window in windows.iter() { for event in window.poll_events() { callback(::Event::WindowEvent { @@ -62,7 +61,7 @@ impl EventsLoop { // Yeah that's a very bad implementation. loop { self.poll_events(|e| callback(e)); - ::std::thread::sleep_ms(5); + ::std::thread::sleep(::std::time::Duration::from_millis(5)); if self.interrupted.load(::std::sync::atomic::Ordering::Relaxed) { break; } diff --git a/src/platform/linux/wayland/window.rs b/src/platform/linux/wayland/window.rs index f4977451..9994cf09 100644 --- a/src/platform/linux/wayland/window.rs +++ b/src/platform/linux/wayland/window.rs @@ -11,21 +11,6 @@ use super::WaylandContext; use super::wayland_window; use super::wayland_window::DecoratedSurface; -#[derive(Clone)] -pub struct WindowProxy { - ctxt: Arc, - eviter: Arc>>, -} - -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, evq: Mutex, @@ -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 { - self.window.next_event(true) - } -} - impl Window { pub fn new(ctxt: Arc, attributes: &WindowAttributes) -> Result { @@ -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::>(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::(self.handler_id); - if let Some(ref callback) = handler.resize_callback { - callback(w, h); - } + let decorated = state.get_mut_handler::>(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::>(self.decorated_id); + let decorated = state.get_mut_handler::>(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) { - let mut guard = self.evq.lock().unwrap(); - let mut state = guard.state(); - let mut handler = state.get_mut_handler::(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, } 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; } } diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index a4f59c8a..43721b7b 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -44,7 +44,7 @@ impl EventsLoop { pub fn poll_events(&self, mut callback: F) where F: FnMut(::Event) { - let mut windows = self.windows.lock().unwrap(); + let windows = self.windows.lock().unwrap(); for window in windows.iter() { for event in window.poll_events() { callback(::Event::WindowEvent { @@ -63,7 +63,7 @@ impl EventsLoop { // Yeah that's a very bad implementation. loop { self.poll_events(|e| callback(e)); - ::std::thread::sleep_ms(5); + ::std::thread::sleep(::std::time::Duration::from_millis(5)); if self.interrupted.load(::std::sync::atomic::Ordering::Relaxed) { break; } diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 7bf0a9fc..233892f9 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -793,7 +793,7 @@ impl Window { // differs on the desktop environments or themes. // // Try the better looking (or more suiting) names first. - let mut xcursor = match cursor { + let xcursor = match cursor { MouseCursor::Alias => load("link"), MouseCursor::Arrow => load("arrow"), MouseCursor::Cell => load("plus"), diff --git a/src/platform/linux/x11/xdisplay.rs b/src/platform/linux/x11/xdisplay.rs index 14e058f8..05a29f40 100644 --- a/src/platform/linux/x11/xdisplay.rs +++ b/src/platform/linux/x11/xdisplay.rs @@ -1,7 +1,6 @@ use std::ptr; use std::fmt; use std::error::Error; -use std::ffi::CString; use std::sync::Mutex; use libc;