Skip to content

Commit

Permalink
Merge pull request electron#9572 from shubham2892/api-height-menubar-…
Browse files Browse the repository at this point in the history
…macos

API height menubar macos
  • Loading branch information
kevinsawicki authored Jun 5, 2017
2 parents 352a926 + 653ef6f commit 9a362ee
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions atom/browser/api/atom_api_screen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ void Screen::BuildPrototype(
.SetMethod("getPrimaryDisplay", &Screen::GetPrimaryDisplay)
.SetMethod("getAllDisplays", &Screen::GetAllDisplays)
.SetMethod("getDisplayNearestPoint", &Screen::GetDisplayNearestPoint)
#if defined(OS_MACOSX)
.SetMethod("getMenuBarHeight", &Screen::getMenuBarHeight)
#endif
.SetMethod("getDisplayMatching", &Screen::GetDisplayMatching);
}

Expand Down
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class Screen : public mate::EventEmitter<Screen>,
display::Display GetDisplayNearestPoint(const gfx::Point& point);
display::Display GetDisplayMatching(const gfx::Rect& match_rect);

#if defined(OS_MACOSX)
int getMenuBarHeight();
#endif

// display::DisplayObserver:
void OnDisplayAdded(const display::Display& new_display) override;
void OnDisplayRemoved(const display::Display& old_display) override;
Expand Down
18 changes: 18 additions & 0 deletions atom/browser/api/atom_api_screen_mac.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.

#import "atom/browser/api/atom_api_screen.h"
#import <Cocoa/Cocoa.h>

namespace atom {

namespace api {

int Screen::getMenuBarHeight() {
return [[NSApp mainMenu] menuBarHeight];
}

}// namespace api

}// namespace atom
4 changes: 4 additions & 0 deletions docs/api/screen.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Returns [`Point`](structures/point.md)

The current absolute position of the mouse pointer.

### `screen.getMenuBarHeight()` _macOS_

Returns `Integer` - The height of the menu bar in pixels.

### `screen.getPrimaryDisplay()`

Returns [`Display`](structures/display.md) - The primary display.
Expand Down
1 change: 1 addition & 0 deletions filenames.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
'atom/browser/api/atom_api_render_process_preferences.h',
'atom/browser/api/atom_api_screen.cc',
'atom/browser/api/atom_api_screen.h',
'atom/browser/api/atom_api_screen_mac.mm',
'atom/browser/api/atom_api_session.cc',
'atom/browser/api/atom_api_session.h',
'atom/browser/api/atom_api_system_preferences.cc',
Expand Down
11 changes: 11 additions & 0 deletions spec/api-screen-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ describe('screen module', function () {
assert(display.size.height > 0)
})
})

describe('screen.getMenuBarHeight()', function () {
if (process.platform !== 'darwin') {
return
}

it('returns an integer', function () {
var screenHeight = screen.getMenuBarHeight()
assert.equal(typeof screenHeight, 'number')
})
})
})

0 comments on commit 9a362ee

Please sign in to comment.