Make window.close cancelable (resolve #817)

This commit is contained in:
Joshua Granick
2017-01-11 15:23:50 -08:00
parent 0f41f2555b
commit 21c52bb29f
4 changed files with 36 additions and 14 deletions

View File

@@ -56,25 +56,27 @@ class NativeWindow {
closing = true;
parent.onClose.dispatch ();
}
if (!parent.onClose.canceled) {
if (handle != null) {
if (!parent.onClose.canceled) {
#if !macro
NativeCFFI.lime_window_close (handle);
#end
handle = null;
if (handle != null) {
#if !macro
NativeCFFI.lime_window_close (handle);
#end
handle = null;
}
} else {
closing = false;
}
} else {
closing = false;
}
}

View File

@@ -3,6 +3,7 @@ package lime.app;
import lime.graphics.Renderer;
import lime.graphics.RenderContext;
import lime.system.System;
import lime.ui.Gamepad;
import lime.ui.GamepadAxis;
import lime.ui.GamepadButton;
@@ -269,6 +270,12 @@ class Application extends Module {
}
if (__windows.length == 0) {
System.exit (0);
}
}
}

View File

@@ -55,7 +55,7 @@ class Module implements IModule {
@:noCompletion public function addWindow (window:Window):Void {
window.onActivate.add (onWindowActivate.bind (window));
window.onClose.add (__onWindowClose.bind (window));
window.onClose.add (__onWindowClose.bind (window), false, -10000);
window.onCreate.add (onWindowCreate.bind (window));
window.onDeactivate.add (onWindowDeactivate.bind (window));
window.onDropFile.add (onWindowDropFile.bind (window));

View File

@@ -265,6 +265,19 @@ namespace lime {
case SDL_WINDOWEVENT_CLOSE:
ProcessWindowEvent (event);
// Avoid handling SDL_QUIT if in response to window.close
SDL_Event event;
if (SDL_PollEvent (&event)) {
if (event.type != SDL_QUIT) {
HandleEvent (&event);
}
}
break;
}