Use system timer/wait functions for frame delay when screen reader is active.

This commit is contained in:
Pāvels Nadtočajevs 2025-04-12 16:21:01 +03:00
parent 1b37dacc18
commit 98f377d9d0
No known key found for this signature in database
GPG key ID: 8413210218EF35D2
9 changed files with 70 additions and 13 deletions

View file

@ -49,6 +49,28 @@
#include <os/log.h>
#include <sys/sysctl.h>
void OS_MacOS::add_frame_delay(bool p_can_draw, bool p_wake_for_events) {
if (p_wake_for_events) {
uint64_t delay = get_frame_delay(p_can_draw);
if (delay == 0) {
return;
}
if (wait_timer) {
CFRunLoopTimerInvalidate(wait_timer);
CFRelease(wait_timer);
}
wait_timer = CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + (double(delay) / 1000000.0), 0, 0, 0,
^(CFRunLoopTimerRef timer) {
CFRunLoopTimerInvalidate(wait_timer);
CFRelease(wait_timer);
wait_timer = nil;
});
CFRunLoopAddTimer(CFRunLoopGetCurrent(), wait_timer, kCFRunLoopCommonModes);
return;
}
OS_Unix::add_frame_delay(p_can_draw, p_wake_for_events);
}
void OS_MacOS::initialize() {
crash_handler.initialize();
@ -995,8 +1017,9 @@ void OS_MacOS_NSApp::start_main() {
ERR_PRINT("NSException: " + String::utf8([exception reason].UTF8String));
}
}
CFRunLoopWakeUp(CFRunLoopGetCurrent()); // Prevent main loop from sleeping.
if (wait_timer == nil) {
CFRunLoopWakeUp(CFRunLoopGetCurrent()); // Prevent main loop from sleeping.
}
});
CFRunLoopAddObserver(CFRunLoopGetCurrent(), pre_wait_observer, kCFRunLoopCommonModes);
return;