Merge pull request #5910 from electron/win-click-through
Implement win.setIgnoreMouseEvents for Windows and Linux
This commit is contained in:
commit
4948bcc806
6 changed files with 44 additions and 10 deletions
|
@ -281,9 +281,6 @@ bool NativeWindow::IsDocumentEdited() {
|
|||
return false;
|
||||
}
|
||||
|
||||
void NativeWindow::SetIgnoreMouseEvents(bool ignore) {
|
||||
}
|
||||
|
||||
void NativeWindow::SetMenu(ui::MenuModel* menu) {
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue