@@ -72,6 +72,9 @@ extern crate serde;
7272
7373#[ cfg( target_os = "windows" ) ]
7474extern crate winapi;
75+ #[ cfg( target_os = "windows" ) ]
76+ #[ macro_use]
77+ extern crate crossbeam_channel;
7578#[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ]
7679#[ macro_use]
7780extern crate objc;
@@ -163,12 +166,12 @@ pub struct DeviceId(platform::DeviceId);
163166/// forbiding it), as such it is neither `Send` nor `Sync`. If you need cross-thread access, the
164167/// `Window` created from this `EventLoop` _can_ be sent to an other thread, and the
165168/// `EventLoopProxy` allows you to wakeup an `EventLoop` from an other thread.
166- pub struct EventLoop {
167- events_loop : platform:: EventLoop ,
169+ pub struct EventLoop < T > {
170+ events_loop : platform:: EventLoop < T > ,
168171 _marker : :: std:: marker:: PhantomData < * mut ( ) > // Not Send nor Sync
169172}
170173
171- impl std:: fmt:: Debug for EventLoop {
174+ impl < T > std:: fmt:: Debug for EventLoop < T > {
172175 fn fmt ( & self , fmtr : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
173176 fmtr. pad ( "EventLoop { .. }" )
174177 }
@@ -199,14 +202,20 @@ impl Default for ControlFlow {
199202 }
200203}
201204
202- impl EventLoop {
205+ impl EventLoop < ( ) > {
206+ pub fn new ( ) -> EventLoop < ( ) > {
207+ EventLoop :: < ( ) > :: new_user_event ( )
208+ }
209+ }
210+
211+ impl < T > EventLoop < T > {
203212 /// Builds a new events loop.
204213 ///
205214 /// Usage will result in display backend initialisation, this can be controlled on linux
206215 /// using an environment variable `WINIT_UNIX_BACKEND`. Legal values are `x11` and `wayland`.
207216 /// If it is not set, winit will try to connect to a wayland connection, and if it fails will
208217 /// fallback on x11. If this variable is set with any other value, winit will panic.
209- pub fn new ( ) -> EventLoop {
218+ pub fn new_user_event ( ) -> EventLoop < T > {
210219 EventLoop {
211220 events_loop : platform:: EventLoop :: new ( ) ,
212221 _marker : :: std:: marker:: PhantomData ,
@@ -234,14 +243,14 @@ impl EventLoop {
234243 /// Any values not passed to this function will *not* be dropped.
235244 #[ inline]
236245 pub fn run < F > ( self , event_handler : F ) -> !
237- where F : ' static + FnMut ( Event , & EventLoop , & mut ControlFlow )
246+ where F : ' static + FnMut ( Event < T > , & EventLoop < T > , & mut ControlFlow )
238247 {
239248 self . events_loop . run ( event_handler)
240249 }
241250
242251 /// Creates an `EventLoopProxy` that can be used to wake up the `EventLoop` from another
243252 /// thread.
244- pub fn create_proxy ( & self ) -> EventLoopProxy {
253+ pub fn create_proxy ( & self ) -> EventLoopProxy < T > {
245254 EventLoopProxy {
246255 events_loop_proxy : self . events_loop . create_proxy ( ) ,
247256 }
@@ -250,24 +259,24 @@ impl EventLoop {
250259
251260/// Used to wake up the `EventLoop` from another thread.
252261#[ derive( Clone ) ]
253- pub struct EventLoopProxy {
254- events_loop_proxy : platform:: EventLoopProxy ,
262+ pub struct EventLoopProxy < T > {
263+ events_loop_proxy : platform:: EventLoopProxy < T > ,
255264}
256265
257- impl std:: fmt:: Debug for EventLoopProxy {
266+ impl < T > std:: fmt:: Debug for EventLoopProxy < T > {
258267 fn fmt ( & self , fmtr : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
259268 fmtr. pad ( "EventLoopProxy { .. }" )
260269 }
261270}
262271
263- impl EventLoopProxy {
264- /// Wake up the `EventLoop` from which this proxy was created.
265- ///
266- /// This causes the `EventLoop` to emit an `Awakened` event .
272+ impl < T > EventLoopProxy < T > {
273+ /// Send an event to the `EventLoop` from which this proxy was created. This emits a
274+ /// `UserEvent(event)` event in the event loop, where `event` is the value passed to this
275+ /// function .
267276 ///
268277 /// Returns an `Err` if the associated `EventLoop` no longer exists.
269- pub fn wakeup ( & self ) -> Result < ( ) , EventLoopClosed > {
270- self . events_loop_proxy . wakeup ( )
278+ pub fn send_event ( & self , event : T ) -> Result < ( ) , EventLoopClosed > {
279+ self . events_loop_proxy . send_event ( event )
271280 }
272281}
273282
0 commit comments