Browse Source

Fix losing input focus right after startup on Linux.

Lasse Öörni 10 years ago
parent
commit
79e89dfad3
2 changed files with 11 additions and 1 deletions
  1. 9 1
      Source/Urho3D/Input/Input.cpp
  2. 2 0
      Source/Urho3D/Input/Input.h

+ 9 - 1
Source/Urho3D/Input/Input.cpp

@@ -223,6 +223,7 @@ Input::Input(Context* context) :
     focusedThisFrame_(false),
     suppressNextMouseMove_(false),
     inResize_(false),
+    screenModeChanged_(false),
     initialized_(false)
 {
     for (int i = 0; i < TOUCHID_MAX; i++)
@@ -284,11 +285,14 @@ void Input::Update()
     {
         #ifdef REQUIRE_CLICK_TO_FOCUS
         // When using the "click to focus" mechanism, only focus automatically in fullscreen or non-hidden mouse mode
-        if (!inputFocus_ && (mouseVisible_ || graphics_->GetFullscreen()) && (flags & SDL_WINDOW_INPUT_FOCUS))
+        if (!inputFocus_ && (mouseVisible_ || graphics_->GetFullscreen() || screenModeChanged_) && (flags & SDL_WINDOW_INPUT_FOCUS))
         #else
         if (!inputFocus_ && (flags & SDL_WINDOW_INPUT_FOCUS))
         #endif
+        {
+            screenModeChanged_ = false;
             focusedThisFrame_ = true;
+        }
 
         if (focusedThisFrame_)
             GainFocus();
@@ -2022,6 +2026,10 @@ void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
 
     // After setting a new screen mode we should not be minimized
     minimized_ = (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0;
+
+    // Remember that screen mode changed in case we lose focus (needed on Linux)
+    if (!inResize_)
+        screenModeChanged_ = true;
 }
 
 void Input::HandleBeginFrame(StringHash eventType, VariantMap& eventData)

+ 2 - 0
Source/Urho3D/Input/Input.h

@@ -368,6 +368,8 @@ private:
     bool suppressNextMouseMove_;
     /// Handling a window resize event flag.
     bool inResize_;
+    /// Flag for automatic focus (without click inside window) after screen mode change, needed on Linux.
+    bool screenModeChanged_;
     /// Initialized flag.
     bool initialized_;
 #ifdef EMSCRIPTEN