Have EventLoopClosed contain the original event (#1294)
* Fix issue #1292 * Remove "optionally" from changelog entry
This commit is contained in:
parent
1a514dff38
commit
830d47a5f7
10 changed files with 43 additions and 20 deletions
|
|
@ -9,6 +9,7 @@
|
||||||
- On X11, fix window creation hanging when another window is fullscreen.
|
- On X11, fix window creation hanging when another window is fullscreen.
|
||||||
- On Windows, fix focusing unfocused windows when switching from fullscreen to windowed.
|
- On Windows, fix focusing unfocused windows when switching from fullscreen to windowed.
|
||||||
- On X11, fix reporting incorrect DPI factor when waking from suspend.
|
- On X11, fix reporting incorrect DPI factor when waking from suspend.
|
||||||
|
- Change `EventLoopClosed` to contain the original event.
|
||||||
|
|
||||||
# 0.20.0 Alpha 4 (2019-10-18)
|
# 0.20.0 Alpha 4 (2019-10-18)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -199,7 +199,7 @@ impl<T: 'static> EventLoopProxy<T> {
|
||||||
/// function.
|
/// function.
|
||||||
///
|
///
|
||||||
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
/// Returns an `Err` if the associated `EventLoop` no longer exists.
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.event_loop_proxy.send_event(event)
|
self.event_loop_proxy.send_event(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -211,17 +211,17 @@ impl<T: 'static> fmt::Debug for EventLoopProxy<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The error that is returned when an `EventLoopProxy` attempts to wake up an `EventLoop` that
|
/// The error that is returned when an `EventLoopProxy` attempts to wake up an `EventLoop` that
|
||||||
/// no longer exists.
|
/// no longer exists. Contains the original event given to `send_event`.
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||||
pub struct EventLoopClosed;
|
pub struct EventLoopClosed<T>(pub T);
|
||||||
|
|
||||||
impl fmt::Display for EventLoopClosed {
|
impl<T: fmt::Debug> fmt::Display for EventLoopClosed<T> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", error::Error::description(self))
|
write!(f, "{}", error::Error::description(self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl error::Error for EventLoopClosed {
|
impl<T: fmt::Debug> error::Error for EventLoopClosed<T> {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
"Tried to wake up a closed `EventLoop`"
|
"Tried to wake up a closed `EventLoop`"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ impl EventLoop {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventLoopProxy {
|
impl EventLoopProxy {
|
||||||
pub fn wakeup(&self) -> Result<(), ::EventLoopClosed> {
|
pub fn wakeup(&self) -> Result<(), ::EventLoopClosed<()>> {
|
||||||
android_glue::wake_event_loop();
|
android_glue::wake_event_loop();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -165,8 +165,10 @@ impl<T> EventLoopProxy<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.sender.send(event).map_err(|_| EventLoopClosed)?;
|
self.sender
|
||||||
|
.send(event)
|
||||||
|
.map_err(|::std::sync::mpsc::SendError(x)| EventLoopClosed(x))?;
|
||||||
unsafe {
|
unsafe {
|
||||||
// let the main thread know there's a new event
|
// let the main thread know there's a new event
|
||||||
CFRunLoopSourceSignal(self.source);
|
CFRunLoopSourceSignal(self.source);
|
||||||
|
|
|
||||||
|
|
@ -650,7 +650,7 @@ impl<T: 'static> EventLoop<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
impl<T: 'static> EventLoopProxy<T> {
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
match *self {
|
match *self {
|
||||||
EventLoopProxy::Wayland(ref proxy) => proxy.send_event(event),
|
EventLoopProxy::Wayland(ref proxy) => proxy.send_event(event),
|
||||||
EventLoopProxy::X(ref proxy) => proxy.send_event(event),
|
EventLoopProxy::X(ref proxy) => proxy.send_event(event),
|
||||||
|
|
|
||||||
|
|
@ -282,8 +282,14 @@ impl<T: 'static> Clone for EventLoopProxy<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
impl<T: 'static> EventLoopProxy<T> {
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.user_sender.send(event).map_err(|_| EventLoopClosed)
|
self.user_sender.send(event).map_err(|e| {
|
||||||
|
EventLoopClosed(if let ::calloop::channel::SendError::Disconnected(x) = e {
|
||||||
|
x
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
|
#![cfg(any(
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
))]
|
||||||
|
|
||||||
mod dnd;
|
mod dnd;
|
||||||
mod event_processor;
|
mod event_processor;
|
||||||
|
|
@ -425,8 +431,14 @@ impl<T> EventLoopWindowTarget<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
impl<T: 'static> EventLoopProxy<T> {
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.user_sender.send(event).map_err(|_| EventLoopClosed)
|
self.user_sender.send(event).map_err(|e| {
|
||||||
|
EventLoopClosed(if let ::calloop::channel::SendError::Disconnected(x) = e {
|
||||||
|
x
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -142,8 +142,10 @@ impl<T> Proxy<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.sender.send(event).map_err(|_| EventLoopClosed)?;
|
self.sender
|
||||||
|
.send(event)
|
||||||
|
.map_err(|mpsc::SendError(x)| EventLoopClosed(x))?;
|
||||||
unsafe {
|
unsafe {
|
||||||
// let the main thread know there's a new event
|
// let the main thread know there's a new event
|
||||||
CFRunLoopSourceSignal(self.source);
|
CFRunLoopSourceSignal(self.source);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ impl<T: 'static> Proxy<T> {
|
||||||
Proxy { runner }
|
Proxy { runner }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
self.runner.send_event(Event::UserEvent(event));
|
self.runner.send_event(Event::UserEvent(event));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -742,13 +742,13 @@ impl<T: 'static> Clone for EventLoopProxy<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: 'static> EventLoopProxy<T> {
|
impl<T: 'static> EventLoopProxy<T> {
|
||||||
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed> {
|
pub fn send_event(&self, event: T) -> Result<(), EventLoopClosed<T>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
if winuser::PostMessageW(self.target_window, *USER_EVENT_MSG_ID, 0, 0) != 0 {
|
if winuser::PostMessageW(self.target_window, *USER_EVENT_MSG_ID, 0, 0) != 0 {
|
||||||
self.event_send.send(event).ok();
|
self.event_send.send(event).ok();
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(EventLoopClosed)
|
Err(EventLoopClosed(event))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue