From 1a34e09a450bb15058a52b74953e139970f4724f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 23 Dec 2014 16:55:57 -0800 Subject: [PATCH] views: Make transparent window work --- atom/browser/native_window_views.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 52184e8620e9..2700fe574b05 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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();