Skip to content

Commit c2aed19

Browse files
murarthOsspial
andauthored
X11: Fix ResumeTimeReached being fired early (#1505)
* X11: Fix `ResumeTimeReached` being fired early * Update CHANGELOG.md Co-authored-by: Osspial <osspial@gmail.com>
1 parent 7e04273 commit c2aed19

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- On X11, fix `ResumeTimeReached` being fired too early.
4+
35
# 0.22.0 (2020-03-09)
46

57
- On Windows, fix minor timing issue in wait_until_time_or_msg

src/platform_impl/linux/x11/mod.rs

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,16 @@ impl<T: 'static> EventLoop<T> {
268268
{
269269
let mut control_flow = ControlFlow::default();
270270
let mut events = Events::with_capacity(8);
271-
272-
callback(
273-
crate::event::Event::NewEvents(crate::event::StartCause::Init),
274-
&self.target,
275-
&mut control_flow,
276-
);
271+
let mut cause = StartCause::Init;
277272

278273
loop {
274+
sticky_exit_callback(
275+
crate::event::Event::NewEvents(cause),
276+
&self.target,
277+
&mut control_flow,
278+
&mut callback,
279+
);
280+
279281
// Process all pending events
280282
self.drain_events(&mut callback, &mut control_flow);
281283

@@ -326,7 +328,7 @@ impl<T: 'static> EventLoop<T> {
326328
}
327329

328330
let start = Instant::now();
329-
let (mut cause, deadline, timeout);
331+
let (deadline, timeout);
330332

331333
match control_flow {
332334
ControlFlow::Exit => break,
@@ -357,38 +359,20 @@ impl<T: 'static> EventLoop<T> {
357359
}
358360
}
359361

360-
if self.event_processor.poll() {
361-
// If the XConnection already contains buffered events, we don't
362-
// need to wait for data on the socket.
363-
// However, we still need to check for user events.
364-
self.poll
365-
.poll(&mut events, Some(Duration::from_millis(0)))
366-
.unwrap();
367-
events.clear();
368-
369-
callback(
370-
crate::event::Event::NewEvents(cause),
371-
&self.target,
372-
&mut control_flow,
373-
);
374-
} else {
362+
// If the XConnection already contains buffered events, we don't
363+
// need to wait for data on the socket.
364+
if !self.event_processor.poll() {
375365
self.poll.poll(&mut events, timeout).unwrap();
376366
events.clear();
367+
}
377368

378-
let wait_cancelled = deadline.map_or(false, |deadline| Instant::now() < deadline);
369+
let wait_cancelled = deadline.map_or(false, |deadline| Instant::now() < deadline);
379370

380-
if wait_cancelled {
381-
cause = StartCause::WaitCancelled {
382-
start,
383-
requested_resume: deadline,
384-
};
385-
}
386-
387-
callback(
388-
crate::event::Event::NewEvents(cause),
389-
&self.target,
390-
&mut control_flow,
391-
);
371+
if wait_cancelled {
372+
cause = StartCause::WaitCancelled {
373+
start,
374+
requested_resume: deadline,
375+
};
392376
}
393377
}
394378

0 commit comments

Comments
 (0)