hedgewars/hwengine.pas
changeset 5521 3be9fda5c3c2
parent 5505 a55aab592950
child 5530 25d4118056e1
child 5562 8056d82b4d23
--- a/hedgewars/hwengine.pas	Sun Aug 07 13:32:28 2011 -0400
+++ b/hedgewars/hwengine.pas	Sun Aug 07 22:18:51 2011 +0400
@@ -145,6 +145,7 @@
 const event: TSDL_Event = ();
 {$WARNINGS ON}
 var PrevTime, CurrTime: Longword;
+    prevFocusState: boolean;
 begin
     PrevTime:= SDL_GetTicks;
     while isTerminated = false do
@@ -159,14 +160,22 @@
                     KeyPressChat(event.key.keysym.sym);
                 SDL_WINDOWEVENT:
                     if event.window.event = SDL_WINDOWEVENT_SHOWN then
+                        begin
                         cHasFocus:= true;
+                        onFocusStateChanged()
+                        end;
 {$ELSE}
                     KeyPressChat(event.key.keysym.unicode);
                 SDL_MOUSEBUTTONDOWN: if event.button.button = SDL_BUTTON_WHEELDOWN then wheelDown:= true;
                 SDL_MOUSEBUTTONUP: if event.button.button = SDL_BUTTON_WHEELUP then wheelUp:= true;
                 SDL_ACTIVEEVENT:
                     if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
+                        begin
+                        prevFocusState:= cHasFocus;
                         cHasFocus:= event.active.gain = 1;
+                        if prevFocusState xor cHasFocus then
+                            onFocusStateChanged()
+                        end;
 {$ENDIF}
                 SDL_JOYAXISMOTION: ControllerAxisEvent(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
                 SDL_JOYHATMOTION: ControllerHatEvent(event.jhat.which, event.jhat.hat, event.jhat.value);