Skip to content

Foundation: unmask Windows events on the main RunLoop #4759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Sources/Foundation/RunLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ open class RunLoop: NSObject {
get { unsafeBitCast(_cfRunLoopStorage, to: CFRunLoop?.self) }
set { _cfRunLoopStorage = newValue }
}

internal static var _mainRunLoop : RunLoop = {
return RunLoop(cfObject: CFRunLoopGetMain())

internal static var _mainRunLoop: RunLoop = {
let cfObject: CFRunLoop! = CFRunLoopGetMain()
#if os(Windows)
// Enable the main runloop on Windows to process the Windows UI events.
// Windows, similar to AppKit and UIKit, expects to process the UI
// events on the main thread.
_CFRunLoopSetWindowsMessageQueueMask(cfObject, QS_ALLINPUT, kCFRunLoopDefaultMode)
#endif
return RunLoop(cfObject: cfObject)
}()

internal init(cfObject : CFRunLoop) {
Expand All @@ -76,7 +83,7 @@ open class RunLoop: NSObject {
}

open class var main: RunLoop {
return _CFRunLoopGet2(CFRunLoopGetMain()) as! RunLoop
return _CFRunLoopGet2(_mainRunLoop._cfRunLoop) as! RunLoop
}

open var currentMode: RunLoop.Mode? {
Expand Down