]> khamidou — GitHub mirrors - electron.git/commitdiff
views: Make transparent window work
authorCheng Zhao <zcbenz@gmail.com>
Wed, 24 Dec 2014 00:55:57 +0000 (16:55 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 24 Dec 2014 00:55:57 +0000 (16:55 -0800)
atom/browser/native_window_views.cc

index 52184e8620e98fcc9cbea7371b33790adace21b3..2700fe574b0531e1bc882d914c680e9bda8d8208 100644 (file)
@@ -28,6 +28,7 @@
 #include "ui/views/window/client_view.h"
 #include "ui/views/widget/native_widget_private.h"
 #include "ui/views/widget/widget.h"
+#include "ui/wm/core/shadow_types.h"
 
 #if defined(USE_X11)
 #include "atom/browser/browser.h"
@@ -183,6 +184,9 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
   params.type = views::Widget::InitParams::TYPE_WINDOW;
   params.remove_standard_frame = !has_frame_;
 
+  if (transparent_)
+    params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
+
 #if defined(USE_X11)
   std::string name = Browser::Get()->GetName();
   // Set WM_WINDOW_ROLE.
@@ -232,13 +236,20 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
     bounds = ContentBoundsToWindowBounds(bounds);
 
 #if defined(OS_WIN)
-  if (!has_frame_) {
+  if (!transparent_ && !has_frame_) {
     // Set Window style so that we get a minimize and maximize animation when
     // frameless.
     DWORD frame_style = WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX |
                         WS_CAPTION;
     ::SetWindowLong(GetAcceleratedWidget(), GWL_STYLE, frame_style);
   }
+
+  if (transparent_) {
+    // Transparent window on Windows has to have WS_EX_COMPOSITED style.
+    LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
+    ex_style |= WS_EX_COMPOSITED;
+    ::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
+  }
 #endif
 
   // TODO(zcbenz): This was used to force using native frame on Windows 2003, we
@@ -248,6 +259,11 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
     window_->FrameTypeChanged();
   }
 
+  // The given window is most likely not rectangular since it uses
+  // transparency and has no standard frame, don't show a shadow for it.
+  if (transparent_ && !has_frame_)
+    wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE);
+
   window_->UpdateWindowIcon();
   window_->CenterWindow(bounds.size());
   Layout();