8000 feat: allow setting window shape by nornagon · Pull Request #13789 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: allow setting window shape #13789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions atom/browser/api/atom_api_top_level_window.cc
< 8000 /tr>
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,10 @@ double TopLevelWindow::GetOpacity() {
return window_->GetOpacity();
}

void TopLevelWindow::SetShape(const std::vector<gfx::Rect>& rects) {
window_->widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
}

void TopLevelWindow::SetRepresentedFilename(const std::string& filename) {
window_->SetRepresentedFilename(filename);
}
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions atom/browser/api/atom_api_top_level_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
bool HasShadow();
void SetOpacity(const double opacity);
double GetOpacity();
void SetShape(const std::vector<gfx::Rect>& rects);
void SetRepresentedFilename(const std::string& filename);
std::string GetRepresentedFilename();
void SetDocumentEdited(bool edited);
Expand Down
11 changes: 11 additions & 0 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand this documentation a bit to explain what shapes are and why you'd want to use them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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)
Expand Down
11 changes: 11 additions & 0 deletions spec/api-browser-window-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
0