2
0
mirror of synced 2025-02-23 06:48:15 +00:00

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:
Denis Bernard 2015-02-27 20:13:18 +01:00 committed by David Crawshaw
parent 7b45e52f8c
commit d26ae0184c
2 changed files with 30 additions and 0 deletions

View File

@ -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;
}
}
}

View File

@ -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()
}
}