diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index e443dcd5566..0247c0bd0a6 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -635,6 +635,10 @@ void Window::SetOpacity(const double opacity) { window_->SetOpacity(opacity); } +double Window::GetOpacity() { + return window_->GetOpacity(); +} + void Window::FocusOnWebView() { window_->FocusOnWebView(); } @@ -1061,6 +1065,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("setHasShadow", &Window::SetHasShadow) .SetMethod("hasShadow", &Window::HasShadow) .SetMethod("setOpacity", &Window::SetOpacity) + .SetMethod("getOpacity", &Window::GetOpacity) .SetMethod("setRepresentedFilename", &Window::SetRepresentedFilename) .SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename) .SetMethod("setDocumentEdited", &Window::SetDocumentEdited) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 50c549b45dd..15f50cd0a42 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -162,6 +162,7 @@ class Window : public mate::TrackableObject, void SetHasShadow(bool has_shadow); bool HasShadow(); void SetOpacity(const double opacity); + double GetOpacity(); void FocusOnWebView(); void BlurWebView(); bool IsWebViewFocused(); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 23e0d0ddf08..c8f3339ba2e 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -142,6 +142,7 @@ class NativeWindow : public base::SupportsUserData, virtual void SetHasShadow(bool has_shadow) = 0; virtual bool HasShadow() = 0; virtual void SetOpacity(const double opacity) = 0; + virtual double GetOpacity() = 0; virtual void SetRepresentedFilename(const std::string& filename); virtual std::string GetRepresentedFilename(); virtual void SetDocumentEdited(bool edited); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index e2c9105fcc0..6efb7d80b58 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -84,6 +84,7 @@ class NativeWindowMac : public NativeWindow, void SetHasShadow(bool has_shadow) override; bool HasShadow() override; void SetOpacity(const double opacity) override; + double GetOpacity() override; void SetRepresentedFilename(const std::string& filename) override; std::string GetRepresentedFilename() override; void SetDocumentEdited(bool edited) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 3baf00cb39b..2cd341bbd2c 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1507,6 +1507,10 @@ void NativeWindowMac::SetOpacity(const double opacity) { [window_ setAlphaValue:opacity]; } +double NativeWindowMac::GetOpacity() { + return [window_ alphaValue]; +} + void NativeWindowMac::SetRepresentedFilename(const std::string& filename) { [window_ setRepresentedFilename:base::SysUTF8ToNSString(filename)]; } diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 6b75e24612d..444b8fc753a 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -825,6 +825,11 @@ void NativeWindowViews::SetOpacity(const double opacity) { } ::SetLayeredWindowAttributes(hwnd, 0, opacity * 255, LWA_ALPHA); #endif + opacity_ = opacity; +} + +double NativeWindowViews::GetOpacity() { + return opacity_; } void NativeWindowViews::SetIgnoreMouseEvents(bool ignore, bool forward) { diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 64aeb1ec885..0f14f35c8f3 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -105,6 +105,7 @@ class NativeWindowViews : public NativeWindow, void SetHasShadow(bool has_shadow) override; bool HasShadow() override; void SetOpacity(const double opacity) override; + double GetOpacity() override; void SetIgnoreMouseEvents(bool ignore, bool forward) override; void SetContentProtection(bool enable) override; void SetFocusable(bool focusable) override; @@ -295,6 +296,7 @@ class NativeWindowViews : public NativeWindow, bool fullscreenable_; std::string title_; gfx::Size widget_size_; + double opacity_ = 1.0; DISALLOW_COPY_AND_ASSIGN(NativeWindowViews); }; diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index b99efc0d7e2..5c684b210c9 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -205,7 +205,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. `#FFF` (white). * `hasShadow` Boolean (optional) - Whether window should have a shadow. This is only implemented on macOS. Default is `true`. - * `opacity` Double (optional) - Set the initial opacity of the window, between 0.0 (fully + * `opacity` Number (optional) - Set the initial opacity of the window, between 0.0 (fully transparent) and 1.0 (fully opaque). This is only implemented on Windows and macOS. * `darkTheme` Boolean (optional) - Forces using dark theme for the window, only works on some GTK+3 desktop environments. Default is `false`. @@ -1210,10 +1210,14 @@ On Windows and Linux always returns #### `win.setOpacity(opacity)` _Windows_ _macOS_ -* `opacity` Double - between 0.0 (fully transparent) and 1.0 (fully opaque) +* `opacity` Number - between 0.0 (fully transparent) and 1.0 (fully opaque) Sets the opacity of the window. On Linux does nothing. +#### `win.getOpacity()` _Windows_ _macOS_ + +Returns `Number` - between 0.0 (fully transparent) and 1.0 (fully opaque) + #### `win.setThumbarButtons(buttons)` _Windows_ * `buttons` [ThumbarButton[]](structures/thumbar-button.md) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 6df7443ea90..d2b44aa3146 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -804,13 +804,17 @@ describe('BrowserWindow module', function () { height: 400, opacity: 0.5 }) + assert.equal(w.getOpacity(), 0.5) }) it('allows setting the opacity', function () { assert.doesNotThrow(function () { w.setOpacity(0.0) + assert.equal(w.getOpacity(), 0.0) w.setOpacity(0.5) + assert.equal(w.getOpacity(), 0.5) w.setOpacity(1.0) + assert.equal(w.getOpacity(), 1.0) }) }) })