Skip to content

Commit 7c2e130

Browse files
francesca64goddessfreya
authored andcommitted
Squashed commit of the following:
commit 5f4aa9f Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 21 17:14:14 2018 -0500 Protect against reentrancy (messily) commit b75073a Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 21 15:15:27 2018 -0500 Send resize events immediately commit 8e9fc01 Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 21 16:07:43 2018 -0500 Don't use struct for window delegate commit c6853b0 Author: Francesca Plebani <franplebani@gmail.com> Date: Wed Dec 19 21:17:48 2018 -0500 Split up util commit 262c46b Author: Francesca Plebani <franplebani@gmail.com> Date: Wed Dec 19 20:55:00 2018 -0500 Use dispatch crate commit 63152c2 Author: Francesca Plebani <franplebani@gmail.com> Date: Wed Dec 19 20:29:13 2018 -0500 RedrawRequested commit 27e475c Author: Francesca Plebani <franplebani@gmail.com> Date: Wed Dec 19 19:24:44 2018 -0500 User events commit 157418d Author: Francesca Plebani <franplebani@gmail.com> Date: Tue Dec 18 22:38:05 2018 -0500 Moved out cursor loading commit b492564 Author: Francesca Plebani <franplebani@gmail.com> Date: Tue Dec 18 21:32:12 2018 -0500 Fixed a bunch of threading issues commit 4aef63d Author: Francesca Plebani <franplebani@gmail.com> Date: Mon Dec 17 13:54:59 2018 -0500 Wait works commit 72ed426 Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 14 20:49:10 2018 -0500 Fixed drag and dropg commit 658209f Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 14 20:42:42 2018 -0500 Made mutexes finer for less deadlock risk commit 8e6b986 Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 14 16:45:06 2018 -0500 Dump (encapsulate) everything into AppState commit d2dc83d Author: Francesca Plebani <franplebani@gmail.com> Date: Thu Dec 13 17:36:47 2018 -0500 All window events work! commit 7c7fcc9 Author: Francesca Plebani <franplebani@gmail.com> Date: Wed Dec 12 17:11:09 2018 -0500 Very rough usage of CFRunLoop commit 3c7a52f Author: Francesca Plebani <franplebani@gmail.com> Date: Tue Dec 11 15:45:23 2018 -0500 Fixed deadlocks commit b74c7fe Author: Francesca Plebani <franplebani@gmail.com> Date: Mon Dec 10 18:59:46 2018 -0500 Fix keyDown deadlock commit 3798f9c Author: Francesca Plebani <franplebani@gmail.com> Date: Mon Dec 10 18:44:40 2018 -0500 It builds! commit 8c86202 Author: Francesca Plebani <franplebani@gmail.com> Date: Fri Dec 7 21:09:55 2018 -0500 Horribly broken so far commit 8269ed2 Author: Osspial <osspial@gmail.com> Date: Mon Nov 19 23:51:20 2018 -0500 Fix crash with runner refcell not getting dropped commit 54ce6a2 Author: Osspial <osspial@gmail.com> Date: Sun Nov 18 19:12:45 2018 -0500 Fix buffered events not getting dispatched commit 2c18b80 Author: Osspial <osspial@gmail.com> Date: Sun Nov 18 18:51:24 2018 -0500 Fix thread executor not executing closure when called from non-loop thread commit 5a3a5e2 Author: Osspial <osspial@gmail.com> Date: Thu Nov 15 22:43:59 2018 -0500 Fix some deadlocks that could occur when changing window state commit 2a3cefd Author: Osspial <osspial@gmail.com> Date: Thu Nov 15 16:45:17 2018 -0500 Document and implement Debug for EventLoopWindowTarget commit fa46825 Author: Osspial <osspial@gmail.com> Date: Thu Nov 15 16:40:48 2018 -0500 Replace &EventLoop in callback with &EventLoopWindowTarget commit 9f36a7a Author: Osspial <osspial@gmail.com> Date: Wed Nov 14 21:28:38 2018 -0500 Fix freeze when setting decorations commit d9c3dac Author: Osspial <osspial@gmail.com> Date: Fri Nov 9 20:41:15 2018 -0500 Fix 1.24.1 build commit 5289d22 Author: Osspial <osspial@gmail.com> Date: Fri Nov 9 00:00:27 2018 -0500 Remove serde implementations from ControlFlow commit 92ac3d6 Author: Osspial <osspial@gmail.com> Date: Thu Nov 8 23:46:41 2018 -0500 Remove crossbeam dependency and make drop events work again commit 8299eb2 Author: Osspial <osspial@gmail.com> Date: Thu Sep 13 22:39:40 2018 -0400 Fix crash when running in release mode commit bb6ab1b Author: Osspial <osspial@gmail.com> Date: Sun Sep 9 14:28:16 2018 -0400 Fix unreachable panic after setting ControlFlow to Poll during some RedrawRequested events. commit 5068ff4 Author: Osspial <osspial@gmail.com> Date: Sun Sep 9 14:14:28 2018 -0400 Improve clarity/fix typos in docs commit 8ed575f Author: Osspial <osspial@gmail.com> Date: Sun Sep 9 00:19:53 2018 -0400 Update send test and errors that broke some examples/APIs commit bf7bfa8 Author: Osspial <osspial@gmail.com> Date: Wed Sep 5 22:36:05 2018 -0400 Fix resize lag when waiting in some situations commit 70722cc Author: Osspial <osspial@gmail.com> Date: Wed Sep 5 19:58:52 2018 -1100 When SendEvent is called during event closure, buffer events commit 5337092 Author: Osspial <osspial@gmail.com> Date: Sun Aug 26 21:55:51 2018 -0400 Improve WaitUntil timer precision commit a654400 Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 21:06:19 2018 -0400 Add CHANGELOG entry commit deb7d37 Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 20:19:56 2018 -0400 Rename MonitorId to MonitorHandle commit 8d8d9b7 Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 20:16:52 2018 -0400 Change instances of "events_loop" to "event_loop" commit 0f34408 Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 20:13:53 2018 -0400 Improve docs for run and run_return commit fba41f7 Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 19:09:53 2018 -0400 Small changes to examples commit 42e8a0d Author: Osspial <osspial@gmail.com> Date: Thu Aug 23 19:09:19 2018 -0400 Improve documentation commit 4377680 Author: Osspial <osspial@gmail.com> Date: Wed Aug 22 23:01:36 2018 -0400 Re-organize into module structure commit f20fac9 Author: Osspial <osspial@gmail.com> Date: Wed Aug 22 22:07:39 2018 -0400 Add platform::desktop module with EventLoopExt::run_return commit dad24d0 Author: Osspial <osspial@gmail.com> Date: Wed Aug 22 18:03:41 2018 -0400 Rename os to platform, add Ext trait postfixes commit 7df59c6 Author: Osspial <osspial@gmail.com> Date: Wed Aug 22 17:59:36 2018 -0400 Rename platform to platform_impl commit 99c0f84 Author: Osspial <osspial@gmail.com> Date: Wed Aug 22 17:55:27 2018 -0400 Add request_redraw commit a0fef1a Author: Osspial <osspial@gmail.com> Date: Mon Aug 20 01:47:11 2018 -0400 Fully invert windows control flow so win32 calls into winit's callback commit 2c607ff Author: Osspial <osspial@gmail.com> Date: Sun Aug 19 13:44:22 2018 -0400 Add ability to send custom user events commit a0b2bb3 Author: Osspial <osspial@gmail.com> Date: Fri Aug 17 17:49:46 2018 -0400 Add StartCause::Init support, timer example commit 02f922f Author: Osspial <osspial@gmail.com> Date: Fri Aug 17 17:31:04 2018 -0400 Implement new ControlFlow and associated events commit 8b8a767 Author: Osspial <osspial@gmail.com> Date: Fri Jul 13 01:48:26 2018 -0400 Replace windows Mutex with parking_lot Mutex commit 9feada2 Author: Osspial <osspial@gmail.com> Date: Fri Jul 13 01:39:53 2018 -0400 Update run_forever to hijack thread commit 2e83bac Author: Osspial <osspial@gmail.com> Date: Thu Jul 12 23:43:58 2018 -0400 Remove second thread from win32 backend commit 64b8a9c Author: Osspial <osspial@gmail.com> Date: Thu Jul 12 22:13:07 2018 -0400 Rename WindowEvent::Refresh to WindowEvent::Redraw commit 529c085 Author: Osspial <osspial@gmail.com> Date: Thu Jul 12 22:04:38 2018 -0400 Rename EventsLoop and associated types to EventLoop Signed-off-by: Hal Gentz <zegentzy@protonmail.com> Co-authored-by: Hal Gentz <zegentzy@protonmail.com>
1 parent ab1dfaa commit 7c2e130

15 files changed

+1931
-12
lines changed

CHANGELOG.md

+37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
# Unreleased
2+
- Changes below are considered **breaking**.
3+
- Change all occurrences of `EventsLoop` to `EventLoop`.
4+
- Previously flat API is now exposed through `event`, `event_loop`, `monitor`, and `window` modules.
5+
- `os` module changes:
6+
- Renamed to `platform`.
7+
- All traits now have platform-specific suffixes.
8+
- Exposes new `desktop` module on Windows, Mac, and Linux.
9+
- Changes to event loop types:
10+
- `EventLoopProxy::wakeup` has been removed in favor of `send_event`.
11+
- **Major:** New `run` method drives winit event loop.
12+
- Returns `!` to ensure API behaves identically across all supported platforms.
13+
- This allows `emscripten` implementation to work without lying about the API.
14+
- `ControlFlow`'s variants have been replaced with `Wait`, `WaitUntil(Instant)`, `Poll`, and `Exit`.
15+
- Is read after `EventsCleared` is processed.
16+
- `Wait` waits until new events are available.
17+
- `WaitUntil` waits until either new events are available or the provided time has been reached.
18+
- `Poll` instantly resumes the event loop.
19+
- `Exit` aborts the event loop.
20+
- Takes a closure that implements `'static + FnMut(Event<T>, &EventLoop<T>, &mut ControlFlow)`.
21+
- `&EventLoop<T>` is provided to allow new `Window`s to be created.
22+
- **Major:** `platform::desktop` module exposes `EventLoopExtDesktop` trait with `run_return` method.
23+
- Behaves identically to `run`, but returns control flow to the calling context can take non-`'static` closures.
24+
- `EventLoop`'s `poll_events` and `run_forever` methods have been removed in favor of `run` and `run_return`.
25+
- Changes to events:
26+
- Remove `Event::Awakened` in favor of `Event::UserEvent(T)`.
27+
- Can be sent with `EventLoopProxy::send_event`.
28+
- Rename `WindowEvent::Refresh` to `WindowEvent::RedrawRequested`.
29+
- `RedrawRequested` can be sent by the user with the `Window::request_redraw` method.
30+
- `EventLoop`, `EventLoopProxy`, and `Event` are now generic over `T`, for use in `UserEvent`.
31+
- **Major:** Add `NewEvents(StartCause)`, `EventsCleared`, and `LoopDestroyed` variants to `Event`.
32+
- `NewEvents` is emitted when new events are ready to be processed by event loop.
33+
- `StartCause` describes why new events are available, with `ResumeTimeReached`, `Poll`, `WaitCancelled`, and `Init` (sent once at start of loop).
34+
- `EventsCleared` is emitted when all available events have been processed.
35+
- Can be used to perform logic that depends on all events being processed (e.g. an iteration of a game loop).
36+
- `LoopDestroyed` is emitted when the `run` or `run_return` method is about to exit.
37+
- Rename `MonitorId` to `MonitorHandle`.
38+
- Removed `serde` implementations from `ControlFlow`.
239

340
- Changes below are considered **breaking**.
441
- Change all occurrences of `EventsLoop` to `EventLoop`.

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ serde = { version = "1", optional = true, features = ["serde_derive"] }
2121

2222
[dev-dependencies]
2323
image = "0.21"
24+
env_logger = "0.5"
2425

2526
[target.'cfg(target_os = "android")'.dependencies.android_glue]
2627
version = "0.2"
@@ -29,10 +30,11 @@ version = "0.2"
2930
objc = "0.2.3"
3031

3132
[target.'cfg(target_os = "macos")'.dependencies]
32-
objc = "0.2.3"
3333
cocoa = "0.18.4"
3434
core-foundation = "0.6"
3535
core-graphics = "0.17.3"
36+
dispatch = "0.1.4"
37+
objc = "0.2.3"
3638

3739
[target.'cfg(target_os = "windows")'.dependencies]
3840
backtrace = "0.3"

examples/multithreaded.rs

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
extern crate env_logger;
2+
extern crate winit;
3+
4+
use std::{collections::HashMap, sync::mpsc, thread, time::Duration};
5+
6+
use winit::{
7+
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
8+
event_loop::{ControlFlow, EventLoop}, window::{MouseCursor, WindowBuilder},
9+
};
10+
11+
const WINDOW_COUNT: usize = 3;
12+
const WINDOW_SIZE: (u32, u32) = (600, 400);
13+
14+
fn main() {
15+
env_logger::init();
16+
let event_loop = EventLoop::new();
17+
let mut window_senders = HashMap::with_capacity(WINDOW_COUNT);
18+
for _ in 0..WINDOW_COUNT {
19+
let window = WindowBuilder::new()
20+
.with_dimensions(WINDOW_SIZE.into())
21+
.build(&event_loop)
22+
.unwrap();
23+
let (tx, rx) = mpsc::channel();
24+
window_senders.insert(window.id(), tx);
25+
thread::spawn(move || {
26+
while let Ok(event) = rx.recv() {
27+
match event {
28+
WindowEvent::KeyboardInput { input: KeyboardInput {
29+
state: ElementState::Released,
30+
virtual_keycode: Some(key),
31+
modifiers,
32+
..
33+
}, .. } => {
34+
window.set_title(&format!("{:?}", key));
35+
let state = !modifiers.shift;
36+
use self::VirtualKeyCode::*;
37+
match key {
38+
A => window.set_always_on_top(state),
39+
C => window.set_cursor(match state {
40+
true => MouseCursor::Progress,
41+
false => MouseCursor::Default,
42+
}),
43+
D => window.set_decorations(!state),
44+
F => window.set_fullscreen(match state {
45+
true => Some(window.get_current_monitor()),
46+
false => None,
47+
}),
48+
G => window.grab_cursor(state).unwrap(),
49+
H => window.hide_cursor(state),
50+
I => {
51+
println!("Info:");
52+
println!("-> position : {:?}", window.get_position());
53+
println!("-> inner_position : {:?}", window.get_inner_position());
54+
println!("-> outer_size : {:?}", window.get_outer_size());
55+
println!("-> inner_size : {:?}", window.get_inner_size());
56+
},
57+
L => window.set_min_dimensions(match state {
58+
true => Some(WINDOW_SIZE.into()),
59+
false => None,
60+
}),
61+
M => window.set_maximized(state),
62+
P => window.set_position({
63+
let mut position = window.get_position().unwrap();
64+
let sign = if state { 1.0 } else { -1.0 };
65+
position.x += 10.0 * sign;
66+
position.y += 10.0 * sign;
67+
position
68+
}),
69+
Q => window.request_redraw(),
70+
R => window.set_resizable(state),
71+
S => window.set_inner_size(match state {
72+
true => (WINDOW_SIZE.0 + 100, WINDOW_SIZE.1 + 100),
73+
false => WINDOW_SIZE,
74+
}.into()),
75+
W => window.set_cursor_position((
76+
WINDOW_SIZE.0 as i32 / 2,
77+
WINDOW_SIZE.1 as i32 / 2,
78+
).into()).unwrap(),
79+
Z => {
80+
window.hide();
81+
thread::sleep(Duration::from_secs(1));
82+
window.show();
83+
},
84+
_ => (),
85+
}
86+
},
87+
_ => (),
88+
}
89+
}
90+
});
91+
}
92+
event_loop.run(move |event, _event_loop, control_flow| {
93+
*control_flow = match !window_senders.is_empty() {
94+
true => ControlFlow::Wait,
95+
false => ControlFlow::Exit,
96+
};
97+
match event {
98+
Event::WindowEvent { event, window_id } => {
99+
match event {
100+
WindowEvent::CloseRequested
101+
| WindowEvent::Destroyed
102+
| WindowEvent::KeyboardInput { input: KeyboardInput {
103+
virtual_keycode: Some(VirtualKeyCode::Escape),
104+
.. }, .. } => {
105+
window_senders.remove(&window_id);
106+
},
107+
_ => if let Some(tx) = window_senders.get(&window_id) {
108+
tx.send(event).unwrap();
109+
},
110+
}
111+
}
112+
_ => (),
113+
}
114+
})
115+
}

src/platform/macos.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![cfg(target_os = "macos")]
22

33
use std::os::raw::c_void;
4-
use {LogicalSize, MonitorHandle, Window, WindowBuilder};
4+
5+
use crate::dpi::LogicalSize;
6+
use crate::monitor::MonitorHandle;
7+
use crate::window::{Window, WindowBuilder};
58

69
/// Additional methods on `Window` that are specific to MacOS.
710
pub trait WindowExtMacOS {

src/platform_impl/macos/app.rs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
use std::collections::VecDeque;
2+
3+
use cocoa::{appkit::{self, NSEvent}, base::id};
4+
use objc::{declare::ClassDecl, runtime::{Class, Object, Sel}};
5+
6+
use event::{DeviceEvent, Event};
7+
use platform_impl::platform::{app_state::AppState, DEVICE_ID, util};
8+
9+
pub struct AppClass(pub *const Class);
10+
unsafe impl Send for AppClass {}
11+
unsafe impl Sync for AppClass {}
12+
13+
lazy_static! {
14+
pub static ref APP_CLASS: AppClass = unsafe {
15+
let superclass = class!(NSApplication);
16+
let mut decl = ClassDecl::new("WinitApp", superclass).unwrap();
17+
18+
decl.add_method(
19+
sel!(sendEvent:),
20+
send_event as extern fn(&Object, Sel, id),
21+
);
22+
23+
AppClass(decl.register())
24+
};
25+
}
26+
27+
// Normally, holding Cmd + any key never sends us a `keyUp` event for that key.
28+
// Overriding `sendEvent:` like this fixes that. (https://stackoverflow.com/a/15294196)
29+
// Fun fact: Firefox still has this bug! (https://bugzilla.mozilla.org/show_bug.cgi?id=1299553)
30+
extern fn send_event(this: &Object, _sel: Sel, event: id) {
31+
unsafe {
32+
// For posterity, there are some undocumented event types
33+
// (https://github.com/servo/cocoa-rs/issues/155)
34+
// but that doesn't really matter here.
35+
let event_type = event.eventType();
36+
let modifier_flags = event.modifierFlags();
37+
if event_type == appkit::NSKeyUp && util::has_flag(
38+
modifier_flags,
39+
appkit::NSEventModifierFlags::NSCommandKeyMask,
40+
) {
41+
let key_window: id = msg_send![this, keyWindow];
42+
let _: () = msg_send![key_window, sendEvent:event];
43+
} else {
44+
maybe_dispatch_device_event(event);
45+
let superclass = util::superclass(this);
46+
let _: () = msg_send![super(this, superclass), sendEvent:event];
47+
}
48+
}
49+
}
50+
51+
unsafe fn maybe_dispatch_device_event(event: id) {
52+
let event_type = event.eventType();
53+
match event_type {
54+
appkit::NSMouseMoved |
55+
appkit::NSLeftMouseDragged |
56+
appkit::NSOtherMouseDragged |
57+
appkit::NSRightMouseDragged => {
58+
let mut events = VecDeque::with_capacity(3);
59+
60+
let delta_x = event.deltaX() as f64;
61+
let delta_y = event.deltaY() as f64;
62+
63+
if delta_x != 0.0 {
64+
events.push_back(Event::DeviceEvent {
65+
device_id: DEVICE_ID,
66+
event: DeviceEvent::Motion { axis: 0, value: delta_x },
67+
});
68+
}
69+
70+
if delta_y != 0.0 {
71+
events.push_back(Event::DeviceEvent {
72+
device_id: DEVICE_ID,
73+
event: DeviceEvent::Motion { axis: 1, value: delta_y },
74+
});
75+
}
76+
77+
if delta_x != 0.0 || delta_y != 0.0 {
78+
events.push_back(Event::DeviceEvent {
79+
device_id: DEVICE_ID,
80+
event: DeviceEvent::MouseMotion { delta: (delta_x, delta_y) },
81+
});
82+
}
83+
84+
AppState::queue_events(events);
85+
},
86+
_ => (),
87+
}
88+
}
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
use cocoa::base::id;
2+
use objc::{runtime::{Class, Object, Sel, BOOL, YES}, declare::ClassDecl};
3+
4+
use platform_impl::platform::app_state::AppState;
5+
6+
pub struct AppDelegateClass(pub *const Class);
7+
unsafe impl Send for AppDelegateClass {}
8+
unsafe impl Sync for AppDelegateClass {}
9+
10+
lazy_static! {
11+
pub static ref APP_DELEGATE_CLASS: AppDelegateClass = unsafe {
12+
let superclass = class!(NSResponder);
13+
let mut decl = ClassDecl::new("WinitAppDelegate", superclass).unwrap();
14+
15+
decl.add_method(
16+
sel!(applicationDidFinishLaunching:),
17+
did_finish_launching as extern fn(&Object, Sel, id) -> BOOL,
18+
);
19+
decl.add_method(
20+
sel!(applicationDidBecomeActive:),
21+
did_become_active as extern fn(&Object, Sel, id),
22+
);
23+
decl.add_method(
24+
sel!(applicationWillResignActive:),
25+
will_resign_active as extern fn(&Object, Sel, id),
26+
);
27+
decl.add_method(
28+
sel!(applicationWillEnterForeground:),
29+
will_enter_foreground as extern fn(&Object, Sel, id),
30+
);
31+
decl.add_method(
32+
sel!(applicationDidEnterBackground:),
33+
did_enter_background as extern fn(&Object, Sel, id),
34+
);
35+
decl.add_method(
36+
sel!(applicationWillTerminate:),
37+
will_terminate as extern fn(&Object, Sel, id),
38+
);
39+
40+
AppDelegateClass(decl.register())
41+
};
42+
}
43+
44+
extern fn did_finish_launching(_: &Object, _: Sel, _: id) -> BOOL {
45+
trace!("Triggered `didFinishLaunching`");
46+
AppState::launched();
47+
trace!("Completed `didFinishLaunching`");
48+
YES
49+
}
50+
51+
extern fn did_become_active(_: &Object, _: Sel, _: id) {
52+
trace!("Triggered `didBecomeActive`");
53+
/*unsafe {
54+
HANDLER.lock().unwrap().handle_nonuser_event(Event::Suspended(false))
55+
}*/
56+
trace!("Completed `didBecomeActive`");
57+
}
58+
59+
extern fn will_resign_active(_: &Object, _: Sel, _: id) {
60+
trace!("Triggered `willResignActive`");
61+
/*unsafe {
62+
HANDLER.lock().unwrap().handle_nonuser_event(Event::Suspended(true))
63+
}*/
64+
trace!("Completed `willResignActive`");
65+
}
66+
67+
extern fn will_enter_foreground(_: &Object, _: Sel, _: id) {
68+
trace!("Triggered `willEnterForeground`");
69+
trace!("Completed `willEnterForeground`");
70+
}
71+
72+
extern fn did_enter_background(_: &Object, _: Sel, _: id) {
73+
trace!("Triggered `didEnterBackground`");
74+
trace!("Completed `didEnterBackground`");
75+
}
76+
77+
extern fn will_terminate(_: &Object, _: Sel, _: id) {
78+
trace!("Triggered `willTerminate`");
79+
/*unsafe {
80+
let app: id = msg_send![class!(UIApplication), sharedApplication];
81+
let windows: id = msg_send![app, windows];
82+
let windows_enum: id = msg_send![windows, objectEnumerator];
83+
let mut events = Vec::new();
84+
loop {
85+
let window: id = msg_send![windows_enum, nextObject];
86+
if window == nil {
87+
break
88+
}
89+
let is_winit_window: BOOL = msg_send![window, isKindOfClass:class!(WinitUIWindow)];
90+
if is_winit_window == YES {
91+
events.push(Event::WindowEvent {
92+
window_id: RootWindowId(window.into()),
93+
event: WindowEvent::Destroyed,
94+
});
95+
}
96+
}
97+
HANDLER.lock().unwrap().handle_nonuser_events(events);
98+
HANDLER.lock().unwrap().terminated();
99+
}*/
100+
trace!("Completed `willTerminate`");
101+
}

0 commit comments

Comments
 (0)