diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index f1f61c66752..c05c1475d0b 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -571,6 +571,10 @@ double TopLevelWindow::GetOpacity() { return window_->GetOpacity(); } +void TopLevelWindow::SetShape(const std::vector& rects) { + window_->widget()->SetShape(std::make_unique>(rects)); +} + void TopLevelWindow::SetRepresentedFilename(const std::string& filename) { window_->SetRepresentedFilename(filename); } @@ -993,6 +997,7 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate, .SetMethod("hasShadow", &TopLevelWindow::HasShadow) .SetMethod("setOpacity", &TopLevelWindow::SetOpacity) .SetMethod("getOpacity", &TopLevelWindow::GetOpacity) + .SetMethod("setShape", &TopLevelWindow::SetShape) .SetMethod("setRepresentedFilename", &TopLevelWindow::SetRepresentedFilename) .SetMethod("getRepresentedFilename", diff --git a/atom/browser/api/atom_api_top_level_window.h b/atom/browser/api/atom_api_top_level_window.h index 5a76fd229c6..641f4b320ef 100644 --- a/atom/browser/api/atom_api_top_level_window.h +++ b/atom/browser/api/atom_api_top_level_window.h @@ -146,6 +146,7 @@ class TopLevelWindow : public mate::TrackableObject, bool HasShadow(); void SetOpacity(const double opacity); double GetOpacity(); + void SetShape(const std::vector& rects); void SetRepresentedFilename(const std::string& filename); std::string GetRepresentedFilename(); void SetDocumentEdited(bool edited); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 16657f6d55f..bf3fea3b554 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1264,6 +1264,17 @@ Sets the opacity of the window. On Linux does nothing. Returns `Number` - between 0.0 (fully transparent) and 1.0 (fully opaque) +#### `win.setShape(rects)` _Windows_ _Linux_ _Experimental_ + +* `rects` [Rectangle[]](structures/rectangle.md) - Sets a shape on the window. + Passing an empty list reverts the window to being rectangular. + +Setting a window shape determines the area within the window where the system +permits drawing and user interaction. Outside of the given region, no pixels +will be drawn and no mouse events will be registered. Mouse events outside of +the region will not be received by that window, but will fall through to +whatever is behind the window. + #### `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 8349bbd4d5b..f69071e66af 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -893,6 +893,17 @@ describe('BrowserWindow module', () => { }) }) + describe('BrowserWindow.setShape(rects)', () => { + it('allows setting shape', () => { + assert.doesNotThrow(() => { + w.setShape([]) + w.setShape([{x: 0, y: 0, width: 100, height: 100}]) + w.setShape([{x: 0, y: 0, width: 100, height: 100}, {x: 0, y: 200, width: 1000, height: 100}]) + w.setShape([]) + }) + }) + }) + describe('"useContentSize" option', () => { it('make window created with content size when used', () => { w.destroy()