Skip to content

Commit

Permalink
docs: apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kchibisov committed May 21, 2024
1 parent 4ac84e5 commit aa5b67b
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/child_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn main() -> Result<(), impl std::error::Error> {
event_loop.create_window(window_attributes).unwrap()
}

let event_loop: EventLoop = EventLoop::new().unwrap();
let event_loop = EventLoop::new().unwrap();
let mut app = Application::default();
event_loop.run_app(&mut app)
}
Expand Down
12 changes: 8 additions & 4 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ changelog entry.

### Changed

- `ApplicationHandler::user_event` changed to `user_wake_up` removing the
generic user event. Users are now free to use their own ways of polling
events where winit will just indicate that wake up happened.
- `EventLoopProxy::send_event` to `EventLoopProxy::wake_up` to just wake up the loop.
- Changed `ApplicationHandler::user_event` to `user_wake_up`, removing the
generic user event.

Winit will now only indicate that wake up happened, you will have to pair
this with an external mechanism like `std::sync::mpsc::channel` if you want
to send specific data to be processed on the main thread.
- Changed `EventLoopProxy::send_event` to `EventLoopProxy::wake_up`, it now
only wakes up the loop.

### Removed

Expand Down
2 changes: 2 additions & 0 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ impl EventLoopProxy {
///
/// When multiple wake ups are sent they'll result only in a single [`user_wake_up`] call.
///
/// If the event loop has is no longer running, this is effectively a no-op.
///
/// [`user_wake_up`]: crate::application::ApplicationHandler::user_wake_up
pub fn wake_up(&self) {
self.event_loop_proxy.wake_up();
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
//!
//! You can retrieve events by calling [`EventLoop::run_app()`]. This function will
//! dispatch events for every [`Window`] that was created with that particular [`EventLoop`], and
//! will run until [`exit()`] is used, at which point [`exiting`] is called.
//! will run until [`exit()`] is used, at which point [`exiting()`] is called.
//!
//! Winit no longer uses a `EventLoop::poll_events() -> impl Iterator<Event>`-based event loop
//! model, since that can't be implemented properly on some platforms (e.g web, iOS) and works
Expand Down Expand Up @@ -162,7 +162,7 @@
//! [`WindowEvent`]: event::WindowEvent
//! [`DeviceEvent`]: event::DeviceEvent
//! [`Event::UserEvent`]: event::Event::UserEvent
//! [`exiting`]: crate::application::ApplicationHandler::exiting
//! [`exiting()`]: crate::application::ApplicationHandler::exiting
//! [`raw_window_handle`]: ./window/struct.Window.html#method.raw_window_handle
//! [`raw_display_handle`]: ./window/struct.Window.html#method.raw_display_handle
//! [^1]: `EventLoopExtPumpEvents::pump_app_events()` is only available on Windows, macOS, Android, X11 and Wayland.
Expand Down
7 changes: 6 additions & 1 deletion src/platform_impl/macos/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ pub(crate) struct EventHandler {

impl fmt::Debug for EventHandler {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("EventHandler").finish_non_exhaustive()
let state = match self.inner.try_borrow() {
Ok(Some(_)) => "<available>",
Ok(None) => "<not set>",
Err(_) => "<in use>",
};
f.debug_struct("EventHandler").field("state", &state).finish_non_exhaustive()
}
}

Expand Down
17 changes: 5 additions & 12 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,14 @@ use crate::platform_impl::platform::{
use crate::window::{
CustomCursor as RootCustomCursor, CustomCursorSource, WindowId as RootWindowId,
};
use runner::{EventLoopRunner, EventLoopRunnerShared};
use runner::EventLoopRunner;

use super::window::set_skip_taskbar;
use super::SelectedCursor;

// here below, the generic `EventLoopRunnerShared<T>` is replaced with
// `EventLoopRunnerShared<UserEventPlaceholder>` so we can get rid
// of the generic parameter T in types which don't depend on T.
// this is the approach which requires minimum changes to current
// backend implementation. it should be considered transitional
// and should be refactored and cleaned up eventually, I hope.

pub(crate) struct WindowData {
pub window_state: Arc<Mutex<WindowState>>,
pub event_loop_runner: EventLoopRunnerShared,
pub event_loop_runner: Rc<EventLoopRunner>,
pub key_event_builder: KeyEventBuilder,
pub _file_drop_handler: Option<FileDropHandler>,
pub userdata_removed: Cell<bool>,
Expand All @@ -115,7 +108,7 @@ impl WindowData {
}

struct ThreadMsgTargetData {
event_loop_runner: EventLoopRunnerShared,
event_loop_runner: Rc<EventLoopRunner>,
}

impl ThreadMsgTargetData {
Expand Down Expand Up @@ -151,7 +144,7 @@ impl Default for PlatformSpecificEventLoopAttributes {
pub struct ActiveEventLoop {
thread_id: u32,
thread_msg_target: HWND,
pub(crate) runner_shared: EventLoopRunnerShared,
pub(crate) runner_shared: Rc<EventLoopRunner>,
}

impl EventLoop {
Expand Down Expand Up @@ -847,7 +840,7 @@ fn create_event_target_window() -> HWND {

fn insert_event_target_window_data(
thread_msg_target: HWND,
event_loop_runner: EventLoopRunnerShared,
event_loop_runner: Rc<EventLoopRunner>,
) {
let userdata = ThreadMsgTargetData { event_loop_runner };
let input_ptr = Box::into_raw(Box::new(userdata));
Expand Down
3 changes: 0 additions & 3 deletions src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::any::Any;
use std::cell::{Cell, RefCell};
use std::collections::VecDeque;
use std::rc::Rc;
use std::sync::{Arc, Mutex};
use std::time::Instant;
use std::{mem, panic};
Expand All @@ -16,8 +15,6 @@ use crate::window::WindowId;

use super::ControlFlow;

pub(crate) type EventLoopRunnerShared = Rc<EventLoopRunner>;

type EventHandler = Cell<Option<Box<dyn FnMut(Event)>>>;

pub(crate) struct EventLoopRunner {
Expand Down
3 changes: 0 additions & 3 deletions tests/send_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ fn needs_send<T: Send>() {}

#[test]
fn event_loop_proxy_send() {
// Ensures that `winit::Window` implements `Send`.
needs_send::<winit::event_loop::EventLoopProxy>();
}

#[test]
fn window_send() {
// Ensures that `winit::Window` implements `Send`.
needs_send::<winit::window::Window>();
}

Expand All @@ -20,7 +18,6 @@ fn window_builder_send() {

#[test]
fn ids_send() {
// Ensures that the various `..Id` types implement `Send`.
needs_send::<winit::window::WindowId>();
needs_send::<winit::event::DeviceId>();
needs_send::<winit::monitor::MonitorHandle>();
Expand Down
2 changes: 0 additions & 2 deletions tests/sync_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ fn needs_sync<T: Sync>() {}

#[test]
fn event_loop_proxy_send() {
// Ensures that `winit::EventLoopProxy<T: Send>` implements `Sync`.
needs_sync::<winit::event_loop::EventLoopProxy>();
}

#[test]
fn window_sync() {
// Ensures that `winit::Window` implements `Sync`.
needs_sync::<winit::window::Window>();
}

Expand Down

0 comments on commit aa5b67b

Please sign in to comment.