Skip to content
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

Implement win.setIgnoreMouseEvents for Windows and Linux #5910

Merged
merged 3 commits into from Jun 7, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions atom/browser/native_window.cc
Expand Up @@ -281,9 +281,6 @@ bool NativeWindow::IsDocumentEdited() {
return false;
}

void NativeWindow::SetIgnoreMouseEvents(bool ignore) {
}

void NativeWindow::SetMenu(ui::MenuModel* menu) {
}

Expand Down
2 changes: 1 addition & 1 deletion atom/browser/native_window.h
Expand Up @@ -154,7 +154,7 @@ class NativeWindow : public base::SupportsUserData,
virtual std::string GetRepresentedFilename();
virtual void SetDocumentEdited(bool edited);
virtual bool IsDocumentEdited();
virtual void SetIgnoreMouseEvents(bool ignore);
virtual void SetIgnoreMouseEvents(bool ignore) = 0;
virtual void SetMenu(ui::MenuModel* menu);
virtual bool HasModalDialog();
virtual gfx::NativeWindow GetNativeWindow() = 0;
Expand Down
20 changes: 20 additions & 0 deletions atom/browser/native_window_views.cc
Expand Up @@ -672,6 +672,26 @@ bool NativeWindowViews::HasShadow() {
return wm::GetShadowType(GetNativeWindow()) != wm::SHADOW_TYPE_NONE;
}

void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) {
#if defined(OS_WIN)
LONG ex_style = ::GetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE);
if (ignore)
ex_style |= (WS_EX_TRANSPARENT | WS_EX_LAYERED);
else
ex_style &= ~(WS_EX_TRANSPARENT | WS_EX_LAYERED);
::SetWindowLong(GetAcceleratedWidget(), GWL_EXSTYLE, ex_style);
#elif defined(USE_X11)
if (ignore) {
XRectangle r = {0, 0, 1, 1};
XShapeCombineRectangles(gfx::GetXDisplay(), GetAcceleratedWidget(),
ShapeInput, 0, 0, &r, 1, ShapeSet, YXBanded);
} else {
XShapeCombineMask(gfx::GetXDisplay(), GetAcceleratedWidget(),
ShapeInput, 0, 0, None, ShapeSet);
}
#endif
}

void NativeWindowViews::SetMenu(ui::MenuModel* menu_model) {
if (menu_model == nullptr) {
// Remove accelerators
Expand Down
1 change: 1 addition & 0 deletions atom/browser/native_window_views.h
Expand Up @@ -91,6 +91,7 @@ class NativeWindowViews : public NativeWindow,
void SetBackgroundColor(const std::string& color_name) override;
void SetHasShadow(bool has_shadow) override;
bool HasShadow() override;
void SetIgnoreMouseEvents(bool ignore) override;
void SetMenu(ui::MenuModel* menu_model) override;
gfx::NativeWindow GetNativeWindow() override;
void SetOverlayIcon(const gfx::Image& overlay,
Expand Down
8 changes: 6 additions & 2 deletions docs/api/browser-window.md
Expand Up @@ -928,10 +928,14 @@ Returns whether the window is visible on all workspaces.

**Note:** This API always returns false on Windows.

### `win.setIgnoreMouseEvents(ignore)` _OS X_
### `win.setIgnoreMouseEvents(ignore)`

* `ignore` Boolean

Ignore all moused events that happened in the window.
Makes the window ignore all mouse events.

All mouse events happened in this window will be passed to the window bellow
Copy link

Choose a reason for hiding this comment

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

Small typo: below*. Also, this whole block reads awkwardly.

this window, but if this window has focus, it will still receive keyboard
events.

[blink-feature-string]: https://code.google.com/p/chromium/codesearch#chromium/src/out/Debug/gen/blink/platform/RuntimeEnabledFeatures.cpp&sq=package:chromium&type=cs&l=576
20 changes: 16 additions & 4 deletions docs/api/frameless-window.md
Expand Up @@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in


```javascript
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, frame: false});
const {BrowserWindow} = require('electron')
let win = new BrowserWindow({width: 800, height: 600, frame: false})
```

### Alternatives on OS X
Expand All @@ -28,7 +28,7 @@ the window controls ("traffic lights") for standard window actions.
You can do so by specifying the new `titleBarStyle` option:

```javascript
let win = new BrowserWindow({titleBarStyle: 'hidden'});
let win = new BrowserWindow({titleBarStyle: 'hidden'})
```

## Transparent window
Expand All @@ -37,7 +37,7 @@ By setting the `transparent` option to `true`, you can also make the frameless
window transparent:

```javascript
let win = new BrowserWindow({transparent: true, frame: false});
let win = new BrowserWindow({transparent: true, frame: false})
```

### Limitations
Expand All @@ -59,6 +59,16 @@ let win = new BrowserWindow({transparent: true, frame: false});
Linux.
* On Mac the native window shadow will not be shown on a transparent window.

## Click-through window

To create a click-through window, i.e. making the window ignore all mouse
events, you can call the [win.setIgnoreMouseEvents(ignore)][ignore-mouse-events]
API:

```javascript
win.setIgnoreMouseEvents(true)
```

## Draggable region

By default, the frameless window is non-draggable. Apps need to specify
Expand Down Expand Up @@ -108,3 +118,5 @@ On some platforms, the draggable area will be treated as a non-client frame, so
when you right click on it a system menu will pop up. To make the context menu
behave correctly on all platforms you should never use a custom context menu on
draggable areas.

[ignore-mouse-events]: browser-window.md#winsetignoremouseeventsignore