app/internal/wm: [macOS] run closure on main thread earlier if possible

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-04-02 18:08:22 +02:00
committed by Elias Naur
parent 662cd2e97a
commit b77c1628f3
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -16,6 +16,7 @@ __attribute__ ((visibility ("hidden"))) void gio_setDisplayLinkDisplay(CFTypeRef
__attribute__ ((visibility ("hidden"))) void gio_hideCursor();
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
__attribute__ ((visibility ("hidden"))) bool gio_isMainThread();
*/
import "C"
import (
@@ -55,6 +56,10 @@ var mainFuncs = make(chan func(), 1)
// runOnMain runs the function on the main thread.
func runOnMain(f func()) {
if C.gio_isMainThread() {
f()
return
}
go func() {
mainFuncs <- f
C.gio_wakeupMainThread()
+4
View File
@@ -11,6 +11,10 @@ void gio_wakeupMainThread(void) {
});
}
bool gio_isMainThread() {
return [NSThread isMainThread];
}
NSUInteger gio_nsstringLength(CFTypeRef cstr) {
NSString *str = (__bridge NSString *)cstr;
return [str length];