Merge pull request #3509 from bengotow/macosx-desktop-window

Support the "desktop" window type on Mac OS X
This commit is contained in:
Cheng Zhao 2015-11-20 13:02:05 +08:00
commit c1d6d68783
2 changed files with 45 additions and 10 deletions

View file

@ -211,6 +211,8 @@ bool ScopedDisableResize::disable_resize_ = false;
} }
@property BOOL acceptsFirstMouse; @property BOOL acceptsFirstMouse;
@property BOOL disableAutoHideCursor; @property BOOL disableAutoHideCursor;
@property BOOL disableKeyOrMainWindow;
- (void)setShell:(atom::NativeWindowMac*)shell; - (void)setShell:(atom::NativeWindowMac*)shell;
- (void)setEnableLargerThanScreen:(bool)enable; - (void)setEnableLargerThanScreen:(bool)enable;
@end @end
@ -257,6 +259,16 @@ bool ScopedDisableResize::disable_resize_ = false;
return [children filteredArrayUsingPredicate:predicate]; return [children filteredArrayUsingPredicate:predicate];
} }
- (BOOL)canBecomeMainWindow
{
return !self.disableKeyOrMainWindow;
}
- (BOOL)canBecomeKeyWindow
{
return !self.disableKeyOrMainWindow;
}
@end @end
@interface ControlRegionView : NSView @interface ControlRegionView : NSView
@ -330,8 +342,6 @@ NativeWindowMac::NativeWindowMac(
width, width,
height); height);
bool useStandardWindow = true;
options.Get(options::kStandardWindow, &useStandardWindow);
bool resizable = true; bool resizable = true;
options.Get(options::kResizable, &resizable); options.Get(options::kResizable, &resizable);
@ -340,6 +350,17 @@ NativeWindowMac::NativeWindowMac(
if (base::mac::IsOSYosemiteOrLater()) if (base::mac::IsOSYosemiteOrLater())
options.Get(options::kTitleBarStyle, &titleBarStyle); options.Get(options::kTitleBarStyle, &titleBarStyle);
std::string windowType;
options.Get(options::kType, &windowType);
bool useStandardWindow = true;
// eventually deprecate separate "standardWindow" option in favor of
// standard / textured window types
options.Get(options::kStandardWindow, &useStandardWindow);
if (windowType == "textured") {
useStandardWindow = false;
}
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask |
NSMiniaturizableWindowMask; NSMiniaturizableWindowMask;
if (!useStandardWindow || transparent() || !has_frame()) { if (!useStandardWindow || transparent() || !has_frame()) {
@ -371,6 +392,15 @@ NativeWindowMac::NativeWindowMac(
[window_ setBackgroundColor:[NSColor clearColor]]; [window_ setBackgroundColor:[NSColor clearColor]];
} }
if (windowType == "desktop") {
[window_ setLevel:kCGDesktopWindowLevel - 1];
[window_ setDisableKeyOrMainWindow: YES];
[window_ setCollectionBehavior:
(NSWindowCollectionBehaviorCanJoinAllSpaces |
NSWindowCollectionBehaviorStationary |
NSWindowCollectionBehaviorIgnoresCycle)];
}
// Remove non-transparent corners, see http://git.io/vfonD. // Remove non-transparent corners, see http://git.io/vfonD.
if (!has_frame()) if (!has_frame())
[window_ setOpaque:NO]; [window_ setOpaque:NO];

View file

@ -66,11 +66,16 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
* `darkTheme` Boolean - Forces using dark theme for the window, only works on * `darkTheme` Boolean - Forces using dark theme for the window, only works on
some GTK+3 desktop environments. some GTK+3 desktop environments.
* `transparent` Boolean - Makes the window [transparent](frameless-window.md). * `transparent` Boolean - Makes the window [transparent](frameless-window.md).
* `type` String - Specifies the type of the window, possible types are * `type` String - Specifies the type of the window, which applies
`desktop`, `dock`, `toolbar`, `splash`, `notification`. This only works on additional platform-specific properties.
Linux. * On Linux, possible types are `desktop`, `dock`, `toolbar`, `splash`,
* `standardWindow` Boolean - Uses the OS X's standard window instead of the `notification`.
textured window. Defaults to `true`. * On OS X, possible types are `desktop`, `textured`. The `textured` type adds
metal gradient appearance (NSTexturedBackgroundWindowMask). The `desktop`
type places the window at the desktop background window level
(kCGDesktopWindowLevel - 1). Note that desktop window will not receive focus,
keyboard or mouse events, but you can use `globalShortcut` to receive input
sparingly.
* `titleBarStyle` String, OS X - specifies the style of window title bar. * `titleBarStyle` String, OS X - specifies the style of window title bar.
This option is supported on OS X 10.10 Yosemite and newer. There are three This option is supported on OS X 10.10 Yosemite and newer. There are three
possible values: possible values:
@ -86,11 +91,11 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
is `true`. is `true`.
* `preload` String - Specifies a script that will be loaded before other * `preload` String - Specifies a script that will be loaded before other
scripts run in the page. This script will always have access to node APIs scripts run in the page. This script will always have access to node APIs
no matter whether node integration is turned on or off. The value should no matter whether node integration is turned on or off. The value should
be the absolute file path to the script. be the absolute file path to the script.
When node integration is turned off, the preload script can reintroduce When node integration is turned off, the preload script can reintroduce
Node global symbols back to the global scope. See example Node global symbols back to the global scope. See example
[here](process.md#event-loaded). [here](process.md#event-loaded).
* `partition` String - Sets the session used by the page. If `partition` * `partition` String - Sets the session used by the page. If `partition`
starts with `persist:`, the page will use a persistent session available to starts with `persist:`, the page will use a persistent session available to