Format everything and add rustfmt to travis (#951)
* Format everything and add rustfmt to travis * Remove extern crate winit from examples and add force_multiline_blocks * Format the code properly * Fix inconsistent period in PULL_REQUEST_TEMPLATE.md * Only run rustfmt on nightly * Travis fixings
This commit is contained in:
parent
b1b5aefc4b
commit
e2c84725de
109 changed files with 4787 additions and 3679 deletions
|
|
@ -1,25 +1,30 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Instant;
|
||||
|
||||
use crate::event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW};
|
||||
use crate::event::ModifiersState;
|
||||
use crate::dpi::{PhysicalPosition, PhysicalSize};
|
||||
use crate::platform_impl::platform::sticky_exit_callback;
|
||||
use crate::monitor::VideoMode;
|
||||
|
||||
use super::window::WindowStore;
|
||||
use super::WindowId;
|
||||
|
||||
use smithay_client_toolkit::output::OutputMgr;
|
||||
use smithay_client_toolkit::reexports::client::protocol::{
|
||||
wl_keyboard, wl_output, wl_pointer, wl_registry, wl_seat, wl_touch,
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
collections::VecDeque,
|
||||
fmt,
|
||||
rc::Rc,
|
||||
sync::{Arc, Mutex},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
dpi::{PhysicalPosition, PhysicalSize},
|
||||
event::ModifiersState,
|
||||
event_loop::{ControlFlow, EventLoopClosed, EventLoopWindowTarget as RootELW},
|
||||
monitor::VideoMode,
|
||||
platform_impl::platform::sticky_exit_callback,
|
||||
};
|
||||
|
||||
use super::{window::WindowStore, WindowId};
|
||||
|
||||
use smithay_client_toolkit::{
|
||||
output::OutputMgr,
|
||||
reexports::client::{
|
||||
protocol::{wl_keyboard, wl_output, wl_pointer, wl_registry, wl_seat, wl_touch},
|
||||
ConnectError, Display, EventQueue, GlobalEvent,
|
||||
},
|
||||
Environment,
|
||||
};
|
||||
use smithay_client_toolkit::reexports::client::{ConnectError, Display, EventQueue, GlobalEvent};
|
||||
use smithay_client_toolkit::Environment;
|
||||
|
||||
pub struct WindowEventsSink {
|
||||
buffer: VecDeque<(crate::event::WindowEvent, crate::window::WindowId)>,
|
||||
|
|
@ -33,7 +38,10 @@ impl WindowEventsSink {
|
|||
}
|
||||
|
||||
pub fn send_event(&mut self, evt: crate::event::WindowEvent, wid: WindowId) {
|
||||
self.buffer.push_back((evt, crate::window::WindowId(crate::platform_impl::WindowId::Wayland(wid))));
|
||||
self.buffer.push_back((
|
||||
evt,
|
||||
crate::window::WindowId(crate::platform_impl::WindowId::Wayland(wid)),
|
||||
));
|
||||
}
|
||||
|
||||
fn empty_with<F, T>(&mut self, mut callback: F)
|
||||
|
|
@ -41,7 +49,10 @@ impl WindowEventsSink {
|
|||
F: FnMut(crate::event::Event<T>),
|
||||
{
|
||||
for (evt, wid) in self.buffer.drain(..) {
|
||||
callback(crate::event::Event::WindowEvent { event: evt, window_id: wid})
|
||||
callback(crate::event::Event::WindowEvent {
|
||||
event: evt,
|
||||
window_id: wid,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,8 +69,10 @@ pub struct EventLoop<T: 'static> {
|
|||
pending_user_events: Rc<RefCell<VecDeque<T>>>,
|
||||
_user_source: ::calloop::Source<::calloop::channel::Channel<T>>,
|
||||
user_sender: ::calloop::channel::Sender<T>,
|
||||
_kbd_source: ::calloop::Source<::calloop::channel::Channel<(crate::event::WindowEvent, super::WindowId)>>,
|
||||
window_target: RootELW<T>
|
||||
_kbd_source: ::calloop::Source<
|
||||
::calloop::channel::Channel<(crate::event::WindowEvent, super::WindowId)>,
|
||||
>,
|
||||
window_target: RootELW<T>,
|
||||
}
|
||||
|
||||
// A handle that can be sent across threads and used to wake up the `EventLoop`.
|
||||
|
|
@ -67,7 +80,7 @@ pub struct EventLoop<T: 'static> {
|
|||
// We should only try and wake up the `EventLoop` if it still exists, so we hold Weak ptrs.
|
||||
#[derive(Clone)]
|
||||
pub struct EventLoopProxy<T: 'static> {
|
||||
user_sender: ::calloop::channel::Sender<T>
|
||||
user_sender: ::calloop::channel::Sender<T>,
|
||||
}
|
||||
|
||||
pub struct EventLoopWindowTarget<T> {
|
||||
|
|
@ -83,7 +96,7 @@ pub struct EventLoopWindowTarget<T> {
|
|||
pub display: Arc<Display>,
|
||||
// The list of seats
|
||||
pub seats: Arc<Mutex<Vec<(u32, wl_seat::WlSeat)>>>,
|
||||
_marker: ::std::marker::PhantomData<T>
|
||||
_marker: ::std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T: 'static> EventLoopProxy<T> {
|
||||
|
|
@ -105,11 +118,14 @@ impl<T: 'static> EventLoop<T> {
|
|||
|
||||
let (kbd_sender, kbd_channel) = ::calloop::channel::channel();
|
||||
let kbd_sink = sink.clone();
|
||||
let kbd_source = inner_loop.handle().insert_source(kbd_channel, move |evt, &mut()| {
|
||||
if let ::calloop::channel::Event::Msg((evt, wid)) = evt {
|
||||
kbd_sink.lock().unwrap().send_event(evt, wid);
|
||||
}
|
||||
}).unwrap();
|
||||
let kbd_source = inner_loop
|
||||
.handle()
|
||||
.insert_source(kbd_channel, move |evt, &mut ()| {
|
||||
if let ::calloop::channel::Event::Msg((evt, wid)) = evt {
|
||||
kbd_sink.lock().unwrap().send_event(evt, wid);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
let mut seat_manager = SeatManager {
|
||||
sink: sink.clone(),
|
||||
|
|
@ -123,7 +139,11 @@ impl<T: 'static> EventLoop<T> {
|
|||
&mut event_queue,
|
||||
move |event, registry| {
|
||||
match event {
|
||||
GlobalEvent::New { id, ref interface, version } => {
|
||||
GlobalEvent::New {
|
||||
id,
|
||||
ref interface,
|
||||
version,
|
||||
} => {
|
||||
if interface == "wl_seat" {
|
||||
seat_manager.add_seat(id, version, registry)
|
||||
}
|
||||
|
|
@ -135,20 +155,27 @@ impl<T: 'static> EventLoop<T> {
|
|||
},
|
||||
}
|
||||
},
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let source = inner_loop.handle().insert_source(event_queue, |(), &mut ()| {}).unwrap();
|
||||
let source = inner_loop
|
||||
.handle()
|
||||
.insert_source(event_queue, |(), &mut ()| {})
|
||||
.unwrap();
|
||||
|
||||
let pending_user_events = Rc::new(RefCell::new(VecDeque::new()));
|
||||
let pending_user_events2 = pending_user_events.clone();
|
||||
|
||||
let (user_sender, user_channel) = ::calloop::channel::channel();
|
||||
|
||||
let user_source = inner_loop.handle().insert_source(user_channel, move |evt, &mut()| {
|
||||
if let ::calloop::channel::Event::Msg(msg) = evt {
|
||||
pending_user_events2.borrow_mut().push_back(msg);
|
||||
}
|
||||
}).unwrap();
|
||||
let user_source = inner_loop
|
||||
.handle()
|
||||
.insert_source(user_channel, move |evt, &mut ()| {
|
||||
if let ::calloop::channel::Event::Msg(msg) = evt {
|
||||
pending_user_events2.borrow_mut().push_back(msg);
|
||||
}
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
Ok(EventLoop {
|
||||
inner_loop,
|
||||
|
|
@ -167,28 +194,30 @@ impl<T: 'static> EventLoop<T> {
|
|||
cleanup_needed: Arc::new(Mutex::new(false)),
|
||||
seats,
|
||||
display,
|
||||
_marker: ::std::marker::PhantomData
|
||||
_marker: ::std::marker::PhantomData,
|
||||
}),
|
||||
_marker: ::std::marker::PhantomData
|
||||
}
|
||||
_marker: ::std::marker::PhantomData,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
pub fn create_proxy(&self) -> EventLoopProxy<T> {
|
||||
EventLoopProxy {
|
||||
user_sender: self.user_sender.clone()
|
||||
user_sender: self.user_sender.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run<F>(mut self, callback: F) -> !
|
||||
where F: 'static + FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow)
|
||||
where
|
||||
F: 'static + FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow),
|
||||
{
|
||||
self.run_return(callback);
|
||||
::std::process::exit(0);
|
||||
}
|
||||
|
||||
pub fn run_return<F>(&mut self, mut callback: F)
|
||||
where F: FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow)
|
||||
where
|
||||
F: FnMut(crate::event::Event<T>, &RootELW<T>, &mut ControlFlow),
|
||||
{
|
||||
// send pending events to the server
|
||||
self.display.flush().expect("Wayland connection lost.");
|
||||
|
|
@ -198,7 +227,11 @@ impl<T: 'static> EventLoop<T> {
|
|||
let sink = self.sink.clone();
|
||||
let user_events = self.pending_user_events.clone();
|
||||
|
||||
callback(crate::event::Event::NewEvents(crate::event::StartCause::Init), &self.window_target, &mut control_flow);
|
||||
callback(
|
||||
crate::event::Event::NewEvents(crate::event::StartCause::Init),
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
);
|
||||
|
||||
loop {
|
||||
self.post_dispatch_triggers();
|
||||
|
|
@ -207,7 +240,12 @@ impl<T: 'static> EventLoop<T> {
|
|||
{
|
||||
let mut guard = sink.lock().unwrap();
|
||||
guard.empty_with(|evt| {
|
||||
sticky_exit_callback(evt, &self.window_target, &mut control_flow, &mut callback);
|
||||
sticky_exit_callback(
|
||||
evt,
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
);
|
||||
});
|
||||
}
|
||||
// empty user events
|
||||
|
|
@ -218,7 +256,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
crate::event::Event::UserEvent(evt),
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
&mut callback
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -228,7 +266,12 @@ impl<T: 'static> EventLoop<T> {
|
|||
{
|
||||
let mut guard = sink.lock().unwrap();
|
||||
guard.empty_with(|evt| {
|
||||
sticky_exit_callback(evt, &self.window_target, &mut control_flow, &mut callback);
|
||||
sticky_exit_callback(
|
||||
evt,
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
&mut callback,
|
||||
);
|
||||
});
|
||||
}
|
||||
// send Events cleared
|
||||
|
|
@ -237,7 +280,7 @@ impl<T: 'static> EventLoop<T> {
|
|||
crate::event::Event::EventsCleared,
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
&mut callback
|
||||
&mut callback,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -248,18 +291,24 @@ impl<T: 'static> EventLoop<T> {
|
|||
ControlFlow::Exit => break,
|
||||
ControlFlow::Poll => {
|
||||
// non-blocking dispatch
|
||||
self.inner_loop.dispatch(Some(::std::time::Duration::from_millis(0)), &mut ()).unwrap();
|
||||
callback(crate::event::Event::NewEvents(crate::event::StartCause::Poll), &self.window_target, &mut control_flow);
|
||||
self.inner_loop
|
||||
.dispatch(Some(::std::time::Duration::from_millis(0)), &mut ())
|
||||
.unwrap();
|
||||
callback(
|
||||
crate::event::Event::NewEvents(crate::event::StartCause::Poll),
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
);
|
||||
},
|
||||
ControlFlow::Wait => {
|
||||
self.inner_loop.dispatch(None, &mut ()).unwrap();
|
||||
callback(
|
||||
crate::event::Event::NewEvents(crate::event::StartCause::WaitCancelled {
|
||||
start: Instant::now(),
|
||||
requested_resume: None
|
||||
requested_resume: None,
|
||||
}),
|
||||
&self.window_target,
|
||||
&mut control_flow
|
||||
&mut control_flow,
|
||||
);
|
||||
},
|
||||
ControlFlow::WaitUntil(deadline) => {
|
||||
|
|
@ -274,28 +323,36 @@ impl<T: 'static> EventLoop<T> {
|
|||
let now = Instant::now();
|
||||
if now < deadline {
|
||||
callback(
|
||||
crate::event::Event::NewEvents(crate::event::StartCause::WaitCancelled {
|
||||
start,
|
||||
requested_resume: Some(deadline)
|
||||
}),
|
||||
crate::event::Event::NewEvents(
|
||||
crate::event::StartCause::WaitCancelled {
|
||||
start,
|
||||
requested_resume: Some(deadline),
|
||||
},
|
||||
),
|
||||
&self.window_target,
|
||||
&mut control_flow
|
||||
&mut control_flow,
|
||||
);
|
||||
} else {
|
||||
callback(
|
||||
crate::event::Event::NewEvents(crate::event::StartCause::ResumeTimeReached {
|
||||
start,
|
||||
requested_resume: deadline
|
||||
}),
|
||||
crate::event::Event::NewEvents(
|
||||
crate::event::StartCause::ResumeTimeReached {
|
||||
start,
|
||||
requested_resume: deadline,
|
||||
},
|
||||
),
|
||||
&self.window_target,
|
||||
&mut control_flow
|
||||
&mut control_flow,
|
||||
);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
callback(crate::event::Event::LoopDestroyed, &self.window_target, &mut control_flow);
|
||||
callback(
|
||||
crate::event::Event::LoopDestroyed,
|
||||
&self.window_target,
|
||||
&mut control_flow,
|
||||
);
|
||||
}
|
||||
|
||||
pub fn primary_monitor(&self) -> MonitorHandle {
|
||||
|
|
@ -324,7 +381,7 @@ impl<T> EventLoop<T> {
|
|||
let mut sink = self.sink.lock().unwrap();
|
||||
let window_target = match self.window_target.p {
|
||||
crate::platform_impl::EventLoopWindowTarget::Wayland(ref wt) => wt,
|
||||
_ => unreachable!()
|
||||
_ => unreachable!(),
|
||||
};
|
||||
// prune possible dead windows
|
||||
{
|
||||
|
|
@ -355,7 +412,10 @@ impl<T> EventLoop<T> {
|
|||
}
|
||||
}
|
||||
if let Some(dpi) = new_dpi {
|
||||
sink.send_event(crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64), wid);
|
||||
sink.send_event(
|
||||
crate::event::WindowEvent::HiDpiFactorChanged(dpi as f64),
|
||||
wid,
|
||||
);
|
||||
}
|
||||
if refresh {
|
||||
sink.send_event(crate::event::WindowEvent::RedrawRequested, wid);
|
||||
|
|
@ -376,7 +436,7 @@ struct SeatManager {
|
|||
sink: Arc<Mutex<WindowEventsSink>>,
|
||||
store: Arc<Mutex<WindowStore>>,
|
||||
seats: Arc<Mutex<Vec<(u32, wl_seat::WlSeat)>>>,
|
||||
kbd_sender: ::calloop::channel::Sender<(crate::event::WindowEvent, super::WindowId)>
|
||||
kbd_sender: ::calloop::channel::Sender<(crate::event::WindowEvent, super::WindowId)>,
|
||||
}
|
||||
|
||||
impl SeatManager {
|
||||
|
|
@ -394,9 +454,7 @@ impl SeatManager {
|
|||
};
|
||||
let seat = registry
|
||||
.bind(min(version, 5), id, move |seat| {
|
||||
seat.implement_closure(move |event, seat| {
|
||||
seat_data.receive(event, seat)
|
||||
}, ())
|
||||
seat.implement_closure(move |event, seat| seat_data.receive(event, seat), ())
|
||||
})
|
||||
.unwrap();
|
||||
self.store.lock().unwrap().new_seat(&seat);
|
||||
|
|
@ -479,7 +537,7 @@ impl SeatData {
|
|||
}
|
||||
}
|
||||
},
|
||||
_ => unreachable!()
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -566,7 +624,8 @@ impl MonitorHandle {
|
|||
}) {
|
||||
Some(Some((w, h))) => (w as u32, h as u32),
|
||||
_ => (0, 0),
|
||||
}.into()
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn position(&self) -> PhysicalPosition {
|
||||
|
|
@ -584,16 +643,17 @@ impl MonitorHandle {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode>
|
||||
{
|
||||
pub fn video_modes(&self) -> impl Iterator<Item = VideoMode> {
|
||||
self.mgr
|
||||
.with_info(&self.proxy, |_, info| info.modes.clone())
|
||||
.unwrap_or(vec![])
|
||||
.into_iter()
|
||||
.map(|x| VideoMode {
|
||||
size: (x.dimensions.0 as u32, x.dimensions.1 as u32),
|
||||
refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16,
|
||||
bit_depth: 32
|
||||
.map(|x| {
|
||||
VideoMode {
|
||||
size: (x.dimensions.0 as u32, x.dimensions.1 as u32),
|
||||
refresh_rate: (x.refresh_rate as f32 / 1000.0).round() as u16,
|
||||
bit_depth: 32,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -614,9 +674,11 @@ pub fn primary_monitor(outputs: &OutputMgr) -> MonitorHandle {
|
|||
pub fn available_monitors(outputs: &OutputMgr) -> VecDeque<MonitorHandle> {
|
||||
outputs.with_all(|list| {
|
||||
list.iter()
|
||||
.map(|&(_, ref proxy, _)| MonitorHandle {
|
||||
proxy: proxy.clone(),
|
||||
mgr: outputs.clone(),
|
||||
.map(|&(_, ref proxy, _)| {
|
||||
MonitorHandle {
|
||||
proxy: proxy.clone(),
|
||||
mgr: outputs.clone(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue