From 17163cdb0d326753d69741a653f84d14eb2bd73f Mon Sep 17 00:00:00 2001 From: cnlohr Date: Fri, 8 Sep 2023 13:29:27 -0700 Subject: [PATCH] Make handledestroy about to cancel. --- CNFG.h | 2 +- CNFGEGLDriver.c | 4 ++-- CNFGWinDriver.c | 4 ++-- README.md | 2 +- examples/fontsize.c | 3 ++- ogltest.c | 3 ++- osdtest.c | 3 ++- rawdraw.c | 3 ++- simple.c | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CNFG.h b/CNFG.h index bd295fa..23954ba 100644 --- a/CNFG.h +++ b/CNFG.h @@ -132,7 +132,7 @@ int CNFGHandleInput(); void HandleKey( int keycode, int bDown ); void HandleButton( int x, int y, int button, int bDown ); void HandleMotion( int x, int y, int mask ); -void HandleDestroy(); +int HandleDestroy(); // Return nonzero if you want to cancel destroy. #ifdef ANDROID_WANT_WINDOW_TERMINATION void HandleWindowTermination(); #endif diff --git a/CNFGEGLDriver.c b/CNFGEGLDriver.c index e74cf35..047efce 100644 --- a/CNFGEGLDriver.c +++ b/CNFGEGLDriver.c @@ -473,8 +473,8 @@ void handle_cmd(struct android_app* app, int32_t cmd) { case APP_CMD_DESTROY: //This gets called initially after back. - HandleDestroy(); - ANativeActivity_finish( gapp->activity ); + if( !HandleDestroy() ) + ANativeActivity_finish( gapp->activity ); break; case APP_CMD_INIT_WINDOW: //When returning from a back button suspension, this isn't called. diff --git a/CNFGWinDriver.c b/CNFGWinDriver.c index cf1a18e..209c701 100644 --- a/CNFGWinDriver.c +++ b/CNFGWinDriver.c @@ -137,8 +137,8 @@ LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) break; #endif case WM_DESTROY: - HandleDestroy(); - CNFGTearDown(); + if( !HandleDestroy() ) + CNFGTearDown(); return 0; } return DefWindowProc(hwnd, msg, wParam, lParam); diff --git a/README.md b/README.md index 41cf950..b5a3555 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ is as follows: void HandleKey( int keycode, int bDown ) { } void HandleButton( int x, int y, int button, int bDown ) { } void HandleMotion( int x, int y, int mask ) { } -void HandleDestroy() { } +int HandleDestroy() { reutrn 0; } int main() { CNFGSetup( "Example App", 1024, 768 ); diff --git a/examples/fontsize.c b/examples/fontsize.c index 5391849..841f013 100644 --- a/examples/fontsize.c +++ b/examples/fontsize.c @@ -30,10 +30,11 @@ void HandleMotion( int x, int y, int mask ) // printf( "Motion: %d,%d (%d)\n", x, y, mask ); } -void HandleDestroy() +int HandleDestroy() { printf( "Destroying\n" ); exit(10); + return 0; } int main() diff --git a/ogltest.c b/ogltest.c index e69003d..3ae8f5d 100644 --- a/ogltest.c +++ b/ogltest.c @@ -17,9 +17,10 @@ void HandleMotion( int x, int y, int mask ) { } -void HandleDestroy() +int HandleDestroy() { exit(10); + return 0; } int main() diff --git a/osdtest.c b/osdtest.c index 2b73051..dda9761 100644 --- a/osdtest.c +++ b/osdtest.c @@ -26,10 +26,11 @@ void HandleMotion( int x, int y, int mask ) } -void HandleDestroy() +int HandleDestroy() { printf( "Destroying\n" ); exit(10); + return 0; } diff --git a/rawdraw.c b/rawdraw.c index 2196581..ee2ed65 100644 --- a/rawdraw.c +++ b/rawdraw.c @@ -153,10 +153,11 @@ void DrawHeightmap() } -void HandleDestroy() +int HandleDestroy() { printf( "Destroying\n" ); exit(10); + return 0; } uint32_t randomtexturedata[65536]; diff --git a/simple.c b/simple.c index 99139d6..f5d8e05 100644 --- a/simple.c +++ b/simple.c @@ -9,7 +9,7 @@ void HandleKey( int keycode, int bDown ) { } void HandleButton( int x, int y, int button, int bDown ) { } void HandleMotion( int x, int y, int mask ) { } -void HandleDestroy() { } +int HandleDestroy() { return 0; } int main() { CNFGSetup( "Example App", 1024, 768 );