Fix window show/hide on desktop being incorrectly considered the same as app going into and out of the background/suspend on mobile

The app's Timers should still continue when a window is hidden. Especially since an app could have multiple windows, with some being shown and some being hidden. If only one were hidden, the other shown windows would clearly behave in a broken manner because the one hidden window would cause all app timers, even those associated with other windows, to be paused.

Introduces new WINDOW_SHOW AND WINDOW_HIDE events from C++ to Haxe, and new onShow and onHide events on Haxe Window.

Followup to 0918ee2381
This commit is contained in:
Josh Tynjala
2023-06-06 10:53:45 -07:00
parent f6e61b1bac
commit aebf139dc7
4 changed files with 14 additions and 16 deletions

View File

@@ -25,6 +25,8 @@ namespace lime {
WINDOW_MOVE, WINDOW_MOVE,
WINDOW_RESIZE, WINDOW_RESIZE,
WINDOW_RESTORE, WINDOW_RESTORE,
WINDOW_SHOW,
WINDOW_HIDE
}; };

View File

@@ -764,14 +764,9 @@ namespace lime {
switch (event->window.event) { switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_ACTIVATE; break; case SDL_WINDOWEVENT_SHOWN: windowEvent.type = WINDOW_SHOW; break;
case SDL_WINDOWEVENT_CLOSE: windowEvent.type = WINDOW_CLOSE; break; case SDL_WINDOWEVENT_CLOSE: windowEvent.type = WINDOW_CLOSE; break;
case SDL_WINDOWEVENT_HIDDEN: case SDL_WINDOWEVENT_HIDDEN: windowEvent.type = WINDOW_HIDE; break;
inBackground = true;
windowEvent.type = WINDOW_DEACTIVATE;
break;
case SDL_WINDOWEVENT_ENTER: windowEvent.type = WINDOW_ENTER; break; case SDL_WINDOWEVENT_ENTER: windowEvent.type = WINDOW_ENTER; break;
case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break; case SDL_WINDOWEVENT_FOCUS_GAINED: windowEvent.type = WINDOW_FOCUS_IN; break;
case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break; case SDL_WINDOWEVENT_FOCUS_LOST: windowEvent.type = WINDOW_FOCUS_OUT; break;
@@ -801,15 +796,6 @@ namespace lime {
windowEvent.windowID = event->window.windowID; windowEvent.windowID = event->window.windowID;
WindowEvent::Dispatch (&windowEvent); WindowEvent::Dispatch (&windowEvent);
switch (event->window.event) {
case SDL_WINDOWEVENT_SHOWN:
inBackground = false;
break;
}
} }
} }

View File

@@ -561,6 +561,12 @@ class NativeApplication
window.__fullscreen = false; window.__fullscreen = false;
window.__minimized = false; window.__minimized = false;
window.onRestore.dispatch(); window.onRestore.dispatch();
case WINDOW_SHOW:
window.onShow.dispatch();
case WINDOW_HIDE:
window.onHide.dispatch();
} }
} }
} }
@@ -967,4 +973,6 @@ class NativeApplication
var WINDOW_MOVE = 10; var WINDOW_MOVE = 10;
var WINDOW_RESIZE = 11; var WINDOW_RESIZE = 11;
var WINDOW_RESTORE = 12; var WINDOW_RESTORE = 12;
var WINDOW_SHOW = 13;
var WINDOW_HIDE = 14;
} }

View File

@@ -62,6 +62,7 @@ class Window
public var onFocusIn(default, null) = new Event<Void->Void>(); public var onFocusIn(default, null) = new Event<Void->Void>();
public var onFocusOut(default, null) = new Event<Void->Void>(); public var onFocusOut(default, null) = new Event<Void->Void>();
public var onFullscreen(default, null) = new Event<Void->Void>(); public var onFullscreen(default, null) = new Event<Void->Void>();
public var onHide(default, null) = new Event<Void->Void>();
public var onKeyDown(default, null) = new Event<KeyCode->KeyModifier->Void>(); public var onKeyDown(default, null) = new Event<KeyCode->KeyModifier->Void>();
public var onKeyUp(default, null) = new Event<KeyCode->KeyModifier->Void>(); public var onKeyUp(default, null) = new Event<KeyCode->KeyModifier->Void>();
public var onLeave(default, null) = new Event<Void->Void>(); public var onLeave(default, null) = new Event<Void->Void>();
@@ -78,6 +79,7 @@ class Window
public var onRenderContextRestored(default, null) = new Event<RenderContext->Void>(); public var onRenderContextRestored(default, null) = new Event<RenderContext->Void>();
public var onResize(default, null) = new Event<Int->Int->Void>(); public var onResize(default, null) = new Event<Int->Int->Void>();
public var onRestore(default, null) = new Event<Void->Void>(); public var onRestore(default, null) = new Event<Void->Void>();
public var onShow(default, null) = new Event<Void->Void>();
public var onTextEdit(default, null) = new Event<String->Int->Int->Void>(); public var onTextEdit(default, null) = new Event<String->Int->Int->Void>();
public var onTextInput(default, null) = new Event<String->Void>(); public var onTextInput(default, null) = new Event<String->Void>();
public var parameters:Dynamic; public var parameters:Dynamic;