Update the macOS backend to the new futures-compatible API.#132
Merged
tomaka merged 14 commits intorust-windowing:masterfrom Feb 14, 2017
Merged
Update the macOS backend to the new futures-compatible API.#132tomaka merged 14 commits intorust-windowing:masterfrom
tomaka merged 14 commits intorust-windowing:masterfrom
Conversation
This is a follow up to the new API introduced in rust-windowing#20. This also fixes the issue where window resize events would not be emitted until the end of the resize. This PR fixese rust-windowing#39 by ensuring that the user callback given to either `EventsLoop::poll_events` or `EventsLoop::run_forever` can be called by each window delegate's resize callback directly.
… and run_forever methods
invariants This also removes the need for "box"ing the callback in favour of storing a raw `*mut` pointer. We can do this by ensuring that we never store the pointer for longer than the lifetime of the user callback, which is the duration of a call to `poll_events` or `run_forever`. Also removes old commented out event code from the window module.
Fix issue where key window would lose all mouse events once mouse left that window. Make sure that only window under mouse receives mouse scroll wheel events.
the NSApplication is in focus. This NSEvent produces an undocumented NSEventType value `21` that has no associated variant within the cocoa-rs crate's `NSEventType` enum, thus causing a segfault when attemptingt to match on the value. This commit adds a check for `21` to avoid the segfault. This fixes rust-windowing#104.
Contributor
Author
mitchmindtree
commented
Feb 6, 2017
| fn new(state: DelegateState) -> WindowDelegate { | ||
| // Box the state so we can give a pointer to it | ||
| let mut state = Box::new(state); | ||
| let state_ptr: *mut DelegateState = &mut *state; |
Contributor
Author
There was a problem hiding this comment.
Just noticed this in some of the old code. This should probably use Box::into_raw, otherwise I'm pretty sure state gets freed at the end of this scope when drop is called on the Box. Seems to me that this has just been "working" by pure chance that the memory at the address hasn't been over-written?
Contributor
Author
There was a problem hiding this comment.
Ah never mind, I thought the WindowDelegate was only storing the pointer, but it takes ownership of the Box itself.
Contributor
Author
|
Now that #126 has been merged I've rebased this against the |
varphone
added a commit
to varphone/winit
that referenced
this pull request
May 13, 2025
…ons < 17763
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll` also returns a non-null pointer.
However, the function does not match the expected `extern "system" fn() -> bool` prototype,
which causes a crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such crashes on older Windows versions.
varphone
added a commit
to varphone/winit
that referenced
this pull request
May 13, 2025
…ons < 17763
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll` also returns a non-null pointer.
However, the function does not match the expected `extern "system" fn() -> bool` prototype,
which causes a crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such crashes on older Windows versions.
varphone
added a commit
to varphone/winit
that referenced
this pull request
May 13, 2025
…ons < 17763
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll` also returns a non-null pointer.
However, the function does not match the expected `extern "system" fn() -> bool` prototype,
which causes a crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such crashes on older Windows versions.
kchibisov
pushed a commit
that referenced
this pull request
May 14, 2025
In Windows versions < 17763, `GetProcAddress("#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
kchibisov
pushed a commit
to kchibisov/winit
that referenced
this pull request
May 17, 2025
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
kchibisov
pushed a commit
to kchibisov/winit
that referenced
this pull request
May 17, 2025
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
kchibisov
pushed a commit
to kchibisov/winit
that referenced
this pull request
May 17, 2025
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
kchibisov
pushed a commit
to kchibisov/winit
that referenced
this pull request
May 17, 2025
In Windows versions < 17763, `GetProcAddress("rust-windowing#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
kchibisov
pushed a commit
that referenced
this pull request
May 21, 2025
In Windows versions < 17763, `GetProcAddress("#132")` from `uxtheme.dll`
also returns a non-null pointer. However, the function does not match
the expected `extern "system" fn() -> bool` prototype, which causes a
crash when it is called.
This fix ensures compatibility by adding proper checks to prevent such
crashes on older Windows versions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a follow up to the new API introduced in #126.
Summary of Changes
events_loop. Most event handling code from the oldmod.rshas been moved into this module. TheNSEventToEventfunction has been moved to a privatens_event_to_eventmethod on theEventsLoopitself.static mutkey modifier trackers (SHIFT_PRESSED,ALT_PRESSED, etc) have been removed in favour aModifiersstruct which is owned by theEventsLoopinstance.eventmodule was removed in favour of moving the one function that was inside of it (used for converting cocoa key codes toVirtualKeyCodes) to the newevents_loopmodule.Window,WindowDelegate,DelegateStateand related items have been moved frommod.rsinto a newwindow.rsmodule.PollEventsIteratorandWaitEventsIterators have been removed in favour of the newEventsLoop::poll_eventsandEventsLoop::run_forevermethods respectively.WindowProxywas removed in favour of the new API. Its logic for waking up the waiting event loop was moved to theEventsLoop::interruptmethod.EventsLoopisSend+Sync. This should make it clearer to contributors that the backend that they're working on must beSend+Sync.Fixes
EventsLoop::poll_eventsorEventsLoop::run_forevercan be called by each window delegate's resize callback directly.Event::Awakenedwas emitted on every unknownNSEvent. Instead, we now only returnEvent::AwakenedonNSApplicationActivated, a change that was approved for glutin but was never merged due to the changeover of event handling to winit.panic!s if a user attempts to poll for events or create a window on a non-main thread.poll_eventsandrun_foreverwill nowpanic!if a user attempts to call either method on a non-main thread.unsafecodeUnsafe code was necessary in order to share the user-given callback between each of the window delegate callbacks. A
*mut FnMut(Event)is stored behind aMutexin order to do this. I've explained the behaviour in detailed comments on theUserCallbackand its methods. If someone could review the newUserCallbacktype and its usage, that would be greatly appreciated!WIP todo:
interruptedproperly. At the moment it causesrun_foreverto return ASAP after the next event, however it should actually wake-up the "awaiting event" function.Send+Syncare safelyimpld forEventsLoopwithout usingunsafe impl. Currently neither are implemented as theEventsLoop'scallbackfield is notSendorSync:UserCallbacktype andimplingSendandSyncfor it.Fix mouseThis seems to require setting up tracking areas which seems like a more involved fix. Going to leave this for a future PR.Enter/Leaveevents. At the moment,Enteris only triggered when the mouse is over the resize bar andLeavetriggers when leaving the resize bar 😖.@tomaka feel free to merge #126 in the meantime if this PR is not yet ready. In that case, I'll just close this and re-open against master.