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

Implements #2734 “New API to configure BrowserWindow title bar on Mac” #2776

Merged
merged 1 commit into from Sep 14, 2015
Merged

Implements #2734 “New API to configure BrowserWindow title bar on Mac” #2776

merged 1 commit into from Sep 14, 2015

Conversation

jaanus
Copy link
Contributor

@jaanus jaanus commented Sep 14, 2015

New API supported on Yosemite 10.10 and newer.

Two new title bar styles:

window = new BrowserWindow({width: 600, height: 400, 'title-bar-style': 'hidden'});

screen shot 2015-09-14 at 14 17 23

window = new BrowserWindow({width: 600, height: 400, 'title-bar-style': 'hidden-inset'});

screen shot 2015-09-14 at 14 17 59

@lipis
Copy link

lipis commented Sep 14, 2015

💃


```javascript
var BrowserWindow = require('browser-window');
var win = new BrowserWindow({ width: 800, height: 600, title-bar-style: "hidden" });
Copy link

Choose a reason for hiding this comment

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

'title-bar-style': 'hidden'

@jaanus
Copy link
Contributor Author

jaanus commented Sep 14, 2015

About the failing tests…

I don’t understand why the Linux tests fail, or rather, why are the two new tests run on Linux? I have a condition to bail out from those tests when the OS is not Mac—why is that not respected?

The Mac tests fail because I think Travis OSX runtime is 10.9. Should I make the tests conditional on 10.9 so they are not run (how?), or is there a way to make Travis use 10.10 runtime?

std::string titleBarStyle = "default";
options.Get(switches::kTitleBarStyle, &titleBarStyle);

if (floor(NSAppKitVersionNumber) >= 1343) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For checking OS X version, you can use base::mac::IsOSYosemiteOrLater() instead.

@zcbenz
Copy link
Member

zcbenz commented Sep 14, 2015

The Mac tests fail because I think Travis OSX runtime is 10.9. Should I make the tests conditional on 10.9 so they are not run (how?), or is there a way to make Travis use 10.10 runtime?

You can use os.release() to check the version of current operating system, I believe Yosemite is 14.x.x.

### Alternatives on Mac

On Mac OS X 10.10 Yosemite and newer, there’s an alternative way to specify a chromeless window. Instead of setting `frame` to `false` which disables both the titlebar and window controls, you may want to have the title bar hidden and your content extend to the full window size, yet still preserve the window controls (“traffic lights”) for standard window actions. You can do so by specifying the new `title-bar-style` option:

Copy link

Choose a reason for hiding this comment

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

Break lines as the rest of the file mostly <= 80

@jaanus
Copy link
Contributor Author

jaanus commented Sep 14, 2015

OK, tests don’t fail any more (they are not run on Travis but are run correctly if you run them locally on a Yosemite machine), I addressed all the comments, and made a squash commit.

if (titleBarStyle == "hidden-inset") {
NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"];
toolbar.showsBaselineSeparator = NO;
[window_ setToolbar:toolbar];
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is a memory leak here.
From apple's API document, the parameter of setToolbar is descripted as strong property, so we need to release toolbar here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad. Thanks for pointing this out. I assumed ARC, but apparently not, been a while since I worked on a non-ARC codebase. :)

New API supported on Yosemite 10.10 and newer.
@zcbenz
Copy link
Member

zcbenz commented Sep 14, 2015

Awesome, thanks! ✨

zcbenz added a commit that referenced this pull request Sep 14, 2015
Implements #2734 “New API to configure BrowserWindow title bar on Mac”
@zcbenz zcbenz merged commit 6bae0ba into electron:master Sep 14, 2015
@jaanus jaanus deleted the osx-window-titlebar branch September 14, 2015 16:00
@anaisbetts
Copy link
Contributor

Ooh, snazzy

@lipis
Copy link

lipis commented Sep 14, 2015

Now we just have to wait for the release :)

// Configure title bar look on Yosemite or newer
if (base::mac::IsOSYosemiteOrLater()) {
if ((titleBarStyle == "hidden") || (titleBarStyle == "hidden-inset")) {
[window_ setTitlebarAppearsTransparent:YES];
Copy link
Contributor

Choose a reason for hiding this comment

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

This throws on OS X Mavericks with Electron 0.32.3 when titleBarStyle == "hidden-inset". I thought the base::mac::IsOSYosemiteOrLater() would guard against that?

image

Copy link
Member

Choose a reason for hiding this comment

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

Can you create a new issue for this? I'm wondering if it is caused by me setting MACOSX_DEPLOYMENT_TARGET to 10.10.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done: #2790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants