|
7 | 7 | #include "mouse.h" |
8 | 8 | #include "screen.h" |
9 | 9 | #include "screengrab.h" |
| 10 | +#include "window_manager.h" |
10 | 11 |
|
11 | 12 | int mouseDelay = 10; |
12 | 13 | int keyboardDelay = 10; |
@@ -668,6 +669,48 @@ Napi::Number _highlight(const Napi::CallbackInfo &info) |
668 | 669 | return Napi::Number::New(env, 1); |
669 | 670 | } |
670 | 671 |
|
| 672 | +Napi::Number _getActiveWindow(const Napi::CallbackInfo &info) { |
| 673 | + Napi::Env env = info.Env(); |
| 674 | + |
| 675 | + WindowHandle windowHandle = getActiveWindow(); |
| 676 | + return Napi::Number::New(env, windowHandle); |
| 677 | +} |
| 678 | + |
| 679 | +Napi::Array _getWindows(const Napi::CallbackInfo &info) { |
| 680 | + Napi::Env env = info.Env(); |
| 681 | + |
| 682 | + std::vector<WindowHandle> windowHandles = getWindows(); |
| 683 | + auto arr = Napi::Array::New(env, windowHandles.size()); |
| 684 | + |
| 685 | + for (size_t idx = 0; idx < windowHandles.size(); ++idx) { |
| 686 | + arr[idx] = windowHandles[idx]; |
| 687 | + } |
| 688 | + |
| 689 | + return arr; |
| 690 | +} |
| 691 | + |
| 692 | +Napi::Object _getWindowRect(const Napi::CallbackInfo &info) { |
| 693 | + Napi::Env env = info.Env(); |
| 694 | + |
| 695 | + WindowHandle windowHandle = info[0].As<Napi::Number>().Int64Value(); |
| 696 | + MMRect windowRect = getWindowRect(windowHandle); |
| 697 | + |
| 698 | + Napi::Object obj = Napi::Object::New(env); |
| 699 | + obj.Set(Napi::String::New(env, "x"), Napi::Number::New(env, windowRect.origin.x)); |
| 700 | + obj.Set(Napi::String::New(env, "y"), Napi::Number::New(env, windowRect.origin.y)); |
| 701 | + obj.Set(Napi::String::New(env, "width"), Napi::Number::New(env, windowRect.size.width)); |
| 702 | + obj.Set(Napi::String::New(env, "height"), Napi::Number::New(env, windowRect.size.height)); |
| 703 | + |
| 704 | + return obj; |
| 705 | +} |
| 706 | + |
| 707 | +Napi::String _getWindowTitle(const Napi::CallbackInfo &info) { |
| 708 | + Napi::Env env = info.Env(); |
| 709 | + |
| 710 | + WindowHandle windowHandle = info[0].As<Napi::Number>().Int64Value(); |
| 711 | + return Napi::String::New(env, getWindowTitle(windowHandle)); |
| 712 | +} |
| 713 | + |
671 | 714 | Napi::Object _captureScreen(const Napi::CallbackInfo &info) |
672 | 715 | { |
673 | 716 | Napi::Env env = info.Env(); |
@@ -749,6 +792,10 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { |
749 | 792 |
|
750 | 793 | exports.Set(Napi::String::New(env, "getScreenSize"), Napi::Function::New(env, _getScreenSize)); |
751 | 794 | exports.Set(Napi::String::New(env, "highlight"), Napi::Function::New(env, _highlight)); |
| 795 | + exports.Set(Napi::String::New(env, "getWindows"), Napi::Function::New(env, _getWindows)); |
| 796 | + exports.Set(Napi::String::New(env, "getActiveWindow"), Napi::Function::New(env, _getActiveWindow)); |
| 797 | + exports.Set(Napi::String::New(env, "getWindowRect"), Napi::Function::New(env, _getWindowRect)); |
| 798 | + exports.Set(Napi::String::New(env, "getWindowTitle"), Napi::Function::New(env, _getWindowTitle)); |
752 | 799 | exports.Set(Napi::String::New(env, "captureScreen"), Napi::Function::New(env, _captureScreen)); |
753 | 800 | exports.Set(Napi::String::New(env, "getXDisplayName"), Napi::Function::New(env, _getXDisplayName)); |
754 | 801 | exports.Set(Napi::String::New(env, "setXDisplayName"), Napi::Function::New(env, _setXDisplayName)); |
|
0 commit comments