Browse Source

Send event when window minimized status changes.

Lasse Öörni 13 years ago
parent
commit
2de9b0a6bd
2 changed files with 25 additions and 29 deletions
  1. 23 29
      Engine/Input/Input.cpp
  2. 2 0
      Engine/Input/Input.h

+ 23 - 29
Engine/Input/Input.cpp

@@ -139,19 +139,25 @@ void Input::Update()
     SDL_Window* window = graphics_->GetImpl()->GetWindow();
     SDL_Window* window = graphics_->GetImpl()->GetWindow();
     if (window)
     if (window)
     {
     {
-        unsigned flags = SDL_GetWindowFlags(window) & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
+        unsigned flags = SDL_GetWindowFlags(window);
+        bool oldMinimized = minimized_;
+        minimized_ = (flags & SDL_WINDOW_MINIMIZED) != 0;
+        
+        flags &= (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS);
         if (!active_ && graphics_->GetFullscreen() && flags == (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS))
         if (!active_ && graphics_->GetFullscreen() && flags == (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS))
             activated_ = true;
             activated_ = true;
         else if (active_ && (flags & SDL_WINDOW_INPUT_FOCUS) == 0)
         else if (active_ && (flags & SDL_WINDOW_INPUT_FOCUS) == 0)
             MakeInactive();
             MakeInactive();
+        else if (minimized_ != oldMinimized)
+            SendActivationEvent();
+        
+        // Activate input now if necessary
+        if (activated_)
+            MakeActive();
     }
     }
     else
     else
         return;
         return;
     
     
-    // Activate input now if necessary
-    if (activated_)
-        MakeActive();
-    
     // Check for mouse move
     // Check for mouse move
     if (active_)
     if (active_)
     {
     {
@@ -306,13 +312,7 @@ void Input::MakeActive()
     SDL_ShowCursor(SDL_FALSE);
     SDL_ShowCursor(SDL_FALSE);
     suppressNextMouseMove_ = true;
     suppressNextMouseMove_ = true;
     
     
-    using namespace Activation;
-    
-    VariantMap eventData;
-    
-    eventData[P_ACTIVE] = active_;
-    eventData[P_MINIMIZED] = minimized_;
-    SendEvent(E_ACTIVATION, eventData);
+    SendActivationEvent();
 }
 }
 
 
 void Input::MakeInactive()
 void Input::MakeInactive()
@@ -328,12 +328,7 @@ void Input::MakeInactive()
     // Show the mouse cursor when inactive
     // Show the mouse cursor when inactive
     SDL_ShowCursor(SDL_TRUE);
     SDL_ShowCursor(SDL_TRUE);
     
     
-    using namespace Activation;
-    
-    VariantMap eventData;
-    eventData[P_ACTIVE] = active_;
-    eventData[P_MINIMIZED] = minimized_;
-    SendEvent(E_ACTIVATION, eventData);
+    SendActivationEvent();
 }
 }
 
 
 void Input::ResetState()
 void Input::ResetState()
@@ -366,6 +361,16 @@ void Input::ResetState()
     mouseButtonPress_ = 0;
     mouseButtonPress_ = 0;
 }
 }
 
 
+void Input::SendActivationEvent()
+{
+    using namespace Activation;
+    
+    VariantMap eventData;
+    eventData[P_ACTIVE] = IsActive();
+    eventData[P_MINIMIZED] = IsMinimized();
+    SendEvent(E_ACTIVATION, eventData);
+}
+
 void Input::SetMouseButton(int button, bool newState)
 void Input::SetMouseButton(int button, bool newState)
 {
 {
     // After deactivation in windowed mode, activate by a left-click inside the window
     // After deactivation in windowed mode, activate by a left-click inside the window
@@ -618,14 +623,6 @@ void Input::HandleSDLEvent(void* sdlEvent)
                 input->GetSubsystem<Graphics>()->Close();
                 input->GetSubsystem<Graphics>()->Close();
                 break;
                 break;
                 
                 
-            case SDL_WINDOWEVENT_MINIMIZED:
-                input->minimized_ = true;
-                break;
-                
-            case SDL_WINDOWEVENT_RESTORED:
-                input->minimized_ = false;
-                break;
-                
             #ifdef ANDROID
             #ifdef ANDROID
             case SDL_WINDOWEVENT_SURFACE_LOST:
             case SDL_WINDOWEVENT_SURFACE_LOST:
                 // Mark GPU objects lost
                 // Mark GPU objects lost
@@ -666,9 +663,6 @@ void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
     SetCursorPosition(center);
     SetCursorPosition(center);
     lastCursorPosition_ = center;
     lastCursorPosition_ = center;
     activated_ = true;
     activated_ = true;
-    
-    // After setting new screen mode we should not be minimized
-    minimized_ = false;
 }
 }
 
 
 void Input::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
 void Input::HandleBeginFrame(StringHash eventType, VariantMap& eventData)

+ 2 - 0
Engine/Input/Input.h

@@ -103,6 +103,8 @@ private:
     void MakeInactive();
     void MakeInactive();
     /// Clear input state.
     /// Clear input state.
     void ResetState();
     void ResetState();
+    /// Send an activation event. Called when minimized or active status changes.
+    void SendActivationEvent();
     /// Handle a mouse button change.
     /// Handle a mouse button change.
     void SetMouseButton(int button, bool newState);
     void SetMouseButton(int button, bool newState);
     /// Handle a key change.
     /// Handle a key change.