forked from joejulian/gio
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:
@@ -16,6 +16,7 @@ __attribute__ ((visibility ("hidden"))) void gio_setDisplayLinkDisplay(CFTypeRef
|
|||||||
__attribute__ ((visibility ("hidden"))) void gio_hideCursor();
|
__attribute__ ((visibility ("hidden"))) void gio_hideCursor();
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
|
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
|
||||||
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
|
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
|
||||||
|
__attribute__ ((visibility ("hidden"))) bool gio_isMainThread();
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
@@ -55,6 +56,10 @@ var mainFuncs = make(chan func(), 1)
|
|||||||
|
|
||||||
// runOnMain runs the function on the main thread.
|
// runOnMain runs the function on the main thread.
|
||||||
func runOnMain(f func()) {
|
func runOnMain(f func()) {
|
||||||
|
if C.gio_isMainThread() {
|
||||||
|
f()
|
||||||
|
return
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
mainFuncs <- f
|
mainFuncs <- f
|
||||||
C.gio_wakeupMainThread()
|
C.gio_wakeupMainThread()
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ void gio_wakeupMainThread(void) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gio_isMainThread() {
|
||||||
|
return [NSThread isMainThread];
|
||||||
|
}
|
||||||
|
|
||||||
NSUInteger gio_nsstringLength(CFTypeRef cstr) {
|
NSUInteger gio_nsstringLength(CFTypeRef cstr) {
|
||||||
NSString *str = (__bridge NSString *)cstr;
|
NSString *str = (__bridge NSString *)cstr;
|
||||||
return [str length];
|
return [str length];
|
||||||
|
|||||||
Reference in New Issue
Block a user