mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 01:15:35 +00:00
app: [macOS] implement custom event dispatching
To get rid of app.Main, we need to control the main thread. The macOS [NSApp run] must be called on the main goroutine and never yields control. Implement the escape hatch which is calling [NSApp stop] to force [NSApp run] to return and allow us to fetch and dispatch events one at a time. This change is separate from the larger change removing app.Main to ease bisecting. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-10
@@ -15,8 +15,8 @@ __attribute__ ((visibility ("hidden"))) void gio_hideCursor();
|
||||
__attribute__ ((visibility ("hidden"))) void gio_showCursor();
|
||||
__attribute__ ((visibility ("hidden"))) void gio_setCursor(NSUInteger curID);
|
||||
|
||||
static bool isMainThread() {
|
||||
return [NSThread isMainThread];
|
||||
static int isMainThread() {
|
||||
return [NSThread isMainThread] ? 1 : 0;
|
||||
}
|
||||
|
||||
static NSUInteger nsstringLength(CFTypeRef cstr) {
|
||||
@@ -77,7 +77,7 @@ var mainFuncs = make(chan func(), 1)
|
||||
|
||||
// runOnMain runs the function on the main thread.
|
||||
func runOnMain(f func()) {
|
||||
if C.isMainThread() {
|
||||
if isMainThread() {
|
||||
f()
|
||||
return
|
||||
}
|
||||
@@ -87,6 +87,10 @@ func runOnMain(f func()) {
|
||||
}()
|
||||
}
|
||||
|
||||
func isMainThread() bool {
|
||||
return C.isMainThread() != 0
|
||||
}
|
||||
|
||||
//export gio_dispatchMainFuncs
|
||||
func gio_dispatchMainFuncs() {
|
||||
for {
|
||||
@@ -259,10 +263,3 @@ func windowSetCursor(from, to pointer.Cursor) pointer.Cursor {
|
||||
C.gio_setCursor(C.NSUInteger(macosCursorID[to]))
|
||||
return to
|
||||
}
|
||||
|
||||
func (w *window) wakeup() {
|
||||
runOnMain(func() {
|
||||
w.loop.Wakeup()
|
||||
w.loop.FlushEvents()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user