Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
  • Loading branch information
goddessfreya committed Apr 24, 2019
1 parent 7933209 commit ab1dfaa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/platform/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ pub trait EventLoopExtUnix {
#[doc(hidden)]
fn get_xlib_xconnection(&self) -> Option<Arc<XConnection>>;

/// Returns a pointer to the `wl_display` object of wayland that is used by this `EventsLoop`.
/// Returns a pointer to the `wl_display` object of wayland that is used by this `EventLoop`.
///
/// Returns `None` if the `EventsLoop` doesn't use wayland (if it uses xlib for example).
/// Returns `None` if the `EventLoop` doesn't use wayland (if it uses xlib for example).
///
/// The pointer will become invalid when the glutin `EventsLoop` is destroyed.
/// The pointer will become invalid when the glutin `EventLoop` is destroyed.
fn get_wayland_display(&self) -> Option<*mut raw::c_void>;
}

Expand Down
64 changes: 24 additions & 40 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,75 +221,59 @@ impl<T: 'static> EventLoop<T> {
&self.target
}

fn sticky_callback<F>(&self, evt: Event<T>, control_flow: &mut ControlFlow, dummy: &mut ControlFlow, mut callback: F)
where F: FnMut(Event<T>, &RootELW<T>, &mut ControlFlow) {
let cf = if *control_flow == ControlFlow::Exit {
dummy
} else {
control_flow
};
callback(evt, &self.target, cf);
}

pub fn run_return<F>(&mut self, mut callback: F)
where F: FnMut(Event<T>, &RootELW<T>, &mut ControlFlow)
{
let mut control_flow = ControlFlow::default();
// make ControlFlow::Exit sticky by providing a dummy
// control flow reference if it is already Exit.
let mut dummy = ControlFlow::Exit;

let wt = get_xtarget(&self.target);

loop {
// Empty the event buffer
{
let mut guard = self.pending_events.borrow_mut();
for evt in guard.drain(..) {
// make ControlFlow::Exit sticky by providing a dummy
// control flow reference if it is already Exit.
let mut dummy = ControlFlow::Exit;
let cf = if control_flow == ControlFlow::Exit {
&mut dummy
} else {
&mut control_flow
};
// user callback
callback(evt, &self.target, cf);
self.sticky_callback(evt, &mut control_flow, &mut dummy, &mut callback);
}
}

// Empty the user event buffer
{
let mut guard = self.pending_user_events.borrow_mut();
for evt in guard.drain(..) {
// make ControlFlow::Exit sticky
let mut dummy = ControlFlow::Exit;
let cf = if control_flow == ControlFlow::Exit {
&mut dummy
} else {
&mut control_flow
};
// user callback
callback(::event::Event::UserEvent(evt), &self.target, cf);
self.sticky_callback(::event::Event::UserEvent(evt), &mut control_flow, &mut dummy, &mut callback);
}
}

// send Events cleared
{
// make ControlFlow::Exit sticky
let mut dummy = ControlFlow::Exit;
let cf = if control_flow == ControlFlow::Exit {
&mut dummy
} else {
&mut control_flow
};
// user callback
callback(::event::Event::EventsCleared, &self.target, cf);
}
self.sticky_callback(::event::Event::EventsCleared, &mut control_flow, &mut dummy, &mut callback);

// Empty the redraw requests
{
let mut guard = wt.pending_redraws.lock().unwrap();
for wid in guard.drain(..) {
// make ControlFlow::Exit sticky
let mut dummy = ControlFlow::Exit;
let cf = if control_flow == ControlFlow::Exit {
&mut dummy
} else {
&mut control_flow
};
// user callback
callback(
self.sticky_callback(
Event::WindowEvent {
window_id: ::window::WindowId(super::WindowId::X(wid)),
event: WindowEvent::RedrawRequested
},
&self.target,
cf
&mut control_flow,
&mut dummy,
&mut callback,
);
}
}
Expand Down

0 comments on commit ab1dfaa

Please sign in to comment.