Skip to content

Commit 1e1108c

Browse files
author
Simon Hofmann
committedAug 3, 2020
(#17) Export getWindows and getWindowRect functions
1 parent 5b8b55e commit 1e1108c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

Diff for: ‎src/main.cc

+29
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "mouse.h"
88
#include "screen.h"
99
#include "screengrab.h"
10+
#include "window_manager.h"
1011

1112
int mouseDelay = 10;
1213
int keyboardDelay = 10;
@@ -668,6 +669,32 @@ Napi::Number _highlight(const Napi::CallbackInfo &info)
668669
return Napi::Number::New(env, 1);
669670
}
670671

672+
Napi::Array _getWindows(const Napi::CallbackInfo &info) {
673+
Napi::Env env = info.Env();
674+
675+
std::vector<int32_t> windowHandles = getWindows();
676+
auto arr = Napi::Array::New(env, windowHandles.size());
677+
678+
for (size_t idx = 0; idx < windowHandles.size(); ++idx) {
679+
arr[idx] = windowHandles[idx];
680+
}
681+
682+
return arr;
683+
}
684+
685+
Napi::Object _getWindowRect(const Napi::CallbackInfo &info) {
686+
Napi::Env env = info.Env();
687+
688+
MMRect windowRect = getWindowRect(info[0].As<Napi::Number>().Int32Value());
689+
Napi::Object obj = Napi::Object::New(env);
690+
obj.Set(Napi::String::New(env, "x"), Napi::Number::New(env, windowRect.origin.x));
691+
obj.Set(Napi::String::New(env, "y"), Napi::Number::New(env, windowRect.origin.y));
692+
obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, windowRect.size.width));
693+
obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, windowRect.size.height));
694+
695+
return obj;
696+
}
697+
671698
Napi::Object _captureScreen(const Napi::CallbackInfo &info)
672699
{
673700
Napi::Env env = info.Env();
@@ -749,6 +776,8 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
749776

750777
exports.Set(Napi::String::New(env, "getScreenSize"), Napi::Function::New(env, _getScreenSize));
751778
exports.Set(Napi::String::New(env, "highlight"), Napi::Function::New(env, _highlight));
779+
exports.Set(Napi::String::New(env, "getWindows"), Napi::Function::New(env, _getWindows));
780+
exports.Set(Napi::String::New(env, "getWindowRect"), Napi::Function::New(env, _getWindowRect));
752781
exports.Set(Napi::String::New(env, "captureScreen"), Napi::Function::New(env, _captureScreen));
753782
exports.Set(Napi::String::New(env, "getXDisplayName"), Napi::Function::New(env, _getXDisplayName));
754783
exports.Set(Napi::String::New(env, "setXDisplayName"), Napi::Function::New(env, _setXDisplayName));

0 commit comments

Comments
 (0)
Please sign in to comment.