2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-01-07 20:00:25 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-01-04 22:27:02 -08:00
|
|
|
#include "atom/browser/browser.h"
|
2014-10-24 12:48:52 +08:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2014-04-17 13:45:14 +08:00
|
|
|
#include "atom/common/node_includes.h"
|
2014-01-07 20:00:25 +08:00
|
|
|
|
2014-04-15 16:25:39 +08:00
|
|
|
namespace {
|
2014-01-07 20:15:55 +08:00
|
|
|
|
2015-01-04 22:27:02 -08:00
|
|
|
const char* kRequireAppReadyMessage =
|
|
|
|
"APIs of \"screen\" module can only be used after the \"ready\" event of "
|
|
|
|
"\"app\" module gets emitted.";
|
|
|
|
|
|
|
|
gfx::Point GetCursorScreenPoint(mate::Arguments* args) {
|
|
|
|
if (!atom::Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowError(kRequireAppReadyMessage);
|
|
|
|
return gfx::Point();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
|
|
|
|
return screen->GetCursorScreenPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Display GetPrimaryDisplay(mate::Arguments* args) {
|
|
|
|
if (!atom::Browser::Get()->is_ready()) {
|
|
|
|
args->ThrowError(kRequireAppReadyMessage);
|
|
|
|
return gfx::Display();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Screen* screen = gfx::Screen::GetNativeScreen();
|
|
|
|
return screen->GetPrimaryDisplay();
|
|
|
|
}
|
|
|
|
|
2014-06-29 20:48:44 +08:00
|
|
|
void Initialize(v8::Handle<v8::Object> exports, v8::Handle<v8::Value> unused,
|
|
|
|
v8::Handle<v8::Context> context, void* priv) {
|
|
|
|
mate::Dictionary dict(context->GetIsolate(), exports);
|
2015-01-04 22:27:02 -08:00
|
|
|
dict.SetMethod("getCursorScreenPoint", &GetCursorScreenPoint);
|
|
|
|
dict.SetMethod("getPrimaryDisplay", &GetPrimaryDisplay);
|
2014-01-07 20:00:25 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 16:25:39 +08:00
|
|
|
} // namespace
|
2014-01-07 20:00:25 +08:00
|
|
|
|
2014-06-29 20:48:44 +08:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_common_screen, Initialize)
|