mobile/app: call the Start/Stop callbacks in x11.go
Fixes #9534 Change-Id: I6a2f9ffb7626a243c501cb50c5b523d927d80e9e Reviewed-on: https://go-review.googlesource.com/6262 Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
parent
7b45e52f8c
commit
d26ae0184c
16
app/x11.c
16
app/x11.c
@ -12,6 +12,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static Atom wm_delete_window;
|
||||
|
||||
static Window
|
||||
new_window(Display *x_dpy, EGLDisplay e_dpy, int w, int h, EGLContext *ctx, EGLSurface *surf) {
|
||||
static const EGLint attribs[] = {
|
||||
@ -99,12 +101,20 @@ runApp(void) {
|
||||
EGLContext e_ctx;
|
||||
EGLSurface e_surf;
|
||||
Window win = new_window(x_dpy, e_dpy, 400, 400, &e_ctx, &e_surf);
|
||||
|
||||
wm_delete_window = XInternAtom(x_dpy, "WM_DELETE_WINDOW", True);
|
||||
if (wm_delete_window != None) {
|
||||
XSetWMProtocols(x_dpy, win, &wm_delete_window, 1);
|
||||
}
|
||||
|
||||
XMapWindow(x_dpy, win);
|
||||
if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) {
|
||||
fprintf(stderr, "eglMakeCurrent failed\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
onStart();
|
||||
|
||||
while (1) {
|
||||
XEvent ev;
|
||||
XNextEvent(x_dpy, &ev);
|
||||
@ -137,6 +147,12 @@ runApp(void) {
|
||||
onResize(ev.xconfigure.width, ev.xconfigure.height);
|
||||
glViewport(0, 0, (GLint)ev.xconfigure.width, (GLint)ev.xconfigure.height);
|
||||
break;
|
||||
case ClientMessage:
|
||||
if (wm_delete_window != None && (Atom)ev.xclient.data.l[0] == wm_delete_window) {
|
||||
onStop();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
app/x11.go
14
app/x11.go
@ -88,3 +88,17 @@ func onDraw() {
|
||||
cb.Draw()
|
||||
}
|
||||
}
|
||||
|
||||
//export onStart
|
||||
func onStart() {
|
||||
if cb.Start != nil {
|
||||
cb.Start()
|
||||
}
|
||||
}
|
||||
|
||||
//export onStop
|
||||
func onStop() {
|
||||
if cb.Stop != nil {
|
||||
cb.Stop()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user