devdraw: cocoa: set window title on main thread

Change-Id: Ie818f9246f749a9d3293019a1e01be4ce7e368b9
Reviewed-on: https://plan9port-review.googlesource.com/1400
Reviewed-by: Russ Cox <rsc@swtch.com>
diff --git a/src/cmd/devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m
index fc73814..3607ab4 100644
--- a/src/cmd/devdraw/cocoa-screen.m
+++ b/src/cmd/devdraw/cocoa-screen.m
@@ -137,6 +137,7 @@
 static void makemenu(void);
 static void makewin(char*);
 static void sendmouse(void);
+static void kicklabel0(char*);
 static void setcursor0(Cursor*);
 static void togglefs(void);
 static void acceptresizing(int);
@@ -232,6 +233,7 @@
 + (void)callflushimg:(NSValue*)v{ flushimg([v rectValue]);}
 + (void)callmakewin:(NSValue*)v{ makewin([v pointerValue]);}
 + (void)callsetcursor0:(NSValue*)v{ setcursor0([v pointerValue]);}
++ (void)callkicklabel0:(NSValue*)v{ kicklabel0([v pointerValue]);}
 @end
 
 static Memimage* initimg(void);
@@ -1358,11 +1360,19 @@
 void
 kicklabel(char *label)
 {
-	NSString *s;
-
 	if(label == nil)
 		return;
 
+	[appdelegate
+		performSelectorOnMainThread:@selector(callkicklabel0:)
+		withObject:[NSValue valueWithPointer:label]
+		waitUntilDone:YES];
+}
+
+static void
+kicklabel0(char *label) {
+	NSString *s;
+
 	s = [[NSString alloc] initWithUTF8String:label];
 	[win.ofs[0] setTitle:s];
 	[win.ofs[1] setTitle:s];