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

@ -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;

View file

@ -94,7 +94,9 @@ impl WaylandEnv {
fn get_seat(&self) -> Option<wl_seat::WlSeat> {
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::<wl_seat::WlSeat>(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<F>(&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;
}

View file

@ -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<F>(&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;
}

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 {
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);
}
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);
}
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;
}
}

View file

@ -44,7 +44,7 @@ impl EventsLoop {
pub fn poll_events<F>(&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;
}

View file

@ -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"),

View file

@ -1,7 +1,6 @@
use std::ptr;
use std::fmt;
use std::error::Error;
use std::ffi::CString;
use std::sync::Mutex;
use libc;