mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-02 16:06:19 +00:00
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_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()
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user