]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix restore/unmaximize wrong window size
authorEran Tiktin <eran.t@mce-sys.com>
Mon, 5 Oct 2015 00:29:02 +0000 (03:29 +0300)
committerEran Tiktin <eran.t@mce-sys.com>
Mon, 5 Oct 2015 00:29:02 +0000 (03:29 +0300)
This resolves #2498.

atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index e9db97e195d15ab43ece6c56347f180ee7a2ef1d..7117142cf006c527d14c0347ced58c9e42338ca4 100644 (file)
@@ -283,6 +283,8 @@ NativeWindowViews::NativeWindowViews(
   else
     last_window_state_ = ui::SHOW_STATE_NORMAL;
 
+  last_normal_size_ = gfx::Size(widget_size_);
+
   if (!has_frame()) {
     // Set Window style so that we get a minimize and maximize animation when
     // frameless.
@@ -851,23 +853,35 @@ void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
       NotifyWindowMinimize();
       break;
     case SIZE_RESTORED:
-      if (last_window_state_ == ui::SHOW_STATE_NORMAL)
-        return;
-
-      switch (last_window_state_) {
-        case ui::SHOW_STATE_MAXIMIZED:
-          last_window_state_ = ui::SHOW_STATE_NORMAL;
-          NotifyWindowUnmaximize();
-          break;
-        case ui::SHOW_STATE_MINIMIZED:
-          if (IsFullscreen()) {
-            last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
-            NotifyWindowEnterFullScreen();
-          } else {
+      if (last_window_state_ == ui::SHOW_STATE_NORMAL) {
+        // Window was resized so we save it's new size.
+        last_normal_size_ = GetSize();
+      } else {
+        switch (last_window_state_) {
+          case ui::SHOW_STATE_MAXIMIZED:
             last_window_state_ = ui::SHOW_STATE_NORMAL;
-            NotifyWindowRestore();
-          }
-          break;
+
+            // When the window is restored we resize it to the previous known
+            // normal size.
+            NativeWindow::SetSize(last_normal_size_);
+
+            NotifyWindowUnmaximize();
+            break;
+          case ui::SHOW_STATE_MINIMIZED:
+            if (IsFullscreen()) {
+              last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
+              NotifyWindowEnterFullScreen();
+            } else {
+              last_window_state_ = ui::SHOW_STATE_NORMAL;
+
+              // When the window is restored we resize it to the previous known
+              // normal size.
+              NativeWindow::SetSize(last_normal_size_);
+
+              NotifyWindowRestore();
+            }
+            break;
+        }
       }
       break;
   }
index 71e122d3814f10c04913f26e67d424839309aaee..f93a9e2f7f9a1eaecd91418fc0442bffa9f1b0af 100644 (file)
@@ -176,6 +176,12 @@ class NativeWindowViews : public NativeWindow,
 
   ui::WindowShowState last_window_state_;
 
+  // There's an issue with restore on Windows, that sometimes causes the Window
+  // to receive the wrong size (#2498). To circumvent that, we keep tabs on the
+  // size of the window while in the normal state (not maximized, minimized or
+  // fullscreen), so we restore it correctly.
+  gfx::Size last_normal_size_;
+
   // In charge of running taskbar related APIs.
   TaskbarHost taskbar_host_;
 #endif