mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
d667a395b6
Fixes #79 #414 This changes the implementation of Drop for Window to send a WM_DELETE_WINDOW ClientMessage, offloading all the cleanup and window destruction to the event loop. Unsurprisingly, this entails that the event loop now handles WM_DELETE_WINDOW using the behavior that was previously contained in Window's Drop implementation, along with destroying the Window. Not only does this mean that dropped windows are closed, but also that clicking the × button on the window actually closes it now. The previous implemention of Drop was also broken, as the event loop would be (seemingly permenanently) frozen after its invocation. That was caused specifically by the mutex locking, and is no longer an issue now that the locking is done in the event loop. While I don't have full confidence that it makes sense for the Drop implementation to behave this way, this is nonetheless a significant improvement. The previous behavior led to inconsistent state, panics, and event loop breakage, along with not actually destroying the window. This additionally makes the assumption that users don't need Focused or CursorLeft events for the destroyed window, as Closed is adequate to indicate unfocus, and users may not expect to receive events for closed/dropped windows. In my testing, those specific events were sent immediately after the window was destroyed, though this sort of behavior could be WM-specific. I've opted to explicitly suppress those events in the case of the window no longer existing. |
||
---|---|---|
.circleci | ||
examples | ||
src | ||
tests | ||
.gitattributes | ||
.gitignore | ||
.gitmodules | ||
.travis.yml | ||
appveyor.yml | ||
Cargo.toml | ||
CHANGELOG.md | ||
LICENSE | ||
README.md |
winit - Cross-platform window creation and management in Rust
[dependencies]
winit = "0.7"
Documentation
Usage
Winit is a window creation and management library. It can create windows and lets you handle events (for example: the window being resized, a key being pressed, a mouse movement, etc.) produced by window.
Winit is designed to be a low-level brick in a hierarchy of libraries. Consequently, in order to show something on the window you need to use the platform-specific getters provided by winit, or another library.
extern crate winit;
fn main() {
let mut events_loop = winit::EventsLoop::new();
let window = winit::Window::new(&events_loop).unwrap();
events_loop.run_forever(|event| {
match event {
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => {
winit::ControlFlow::Break
},
_ => winit::ControlFlow::Continue,
}
});
}
Platform-specific usage
Emscripten and WebAssembly
Building a binary will yield a .js
file. In order to use it in an HTML file, you need to:
- Put a
<canvas id="my_id"></canvas>
element somewhere. A canvas corresponds to a winit "window". - Write a Javascript code that creates a global variable named
Module
. SetModule.canvas
to the element of the<canvas>
element (in the example you would retrieve it viadocument.getElementById("my_id")
). More information here. - Make sure that you insert the
.js
file generated by Rust after theModule
variable is created.