1
1
#include < node.h>
2
2
#include < v8.h>
3
+ #include < vector>
3
4
#include " mouse.h"
4
5
#include " deadbeef_rand.h"
5
6
#include " screen.h"
@@ -125,6 +126,43 @@ Handle<Value> captureScreen(const Arguments& args)
125
126
// return scope.Close(String::New("1"));
126
127
}
127
128
129
+ Handle <Value> getWindows (const Arguments& args)
130
+ {
131
+ HandleScope scope;
132
+
133
+ CFArrayRef windowList = CGWindowListCopyWindowInfo (kCGWindowListOptionOnScreenOnly , kCGNullWindowID );
134
+ CFIndex windowNum = CFArrayGetCount (windowList);
135
+
136
+ std::vector<Object> windows;
137
+ Local<Object> obj = Object::New ();
138
+
139
+
140
+ for (int i = 0 ; i < (int )windowNum; i++)
141
+ {
142
+ CFDictionaryRef info = (CFDictionaryRef )CFArrayGetValueAtIndex (windowList, i);
143
+ CFNumberRef currentPID = (CFNumberRef )CFDictionaryGetValue (info, kCGWindowOwnerPID );
144
+ CFNumberRef currentWindowNumber = (CFNumberRef )CFDictionaryGetValue (info, kCGWindowNumber );
145
+ CFStringRef currentTitle = (CFStringRef )CFDictionaryGetValue (info, kCGWindowName );
146
+ CFIndex length = CFStringGetLength (currentTitle);
147
+ CFIndex maxSize = CFStringGetMaximumSizeForEncoding (length, kCFStringEncodingUTF8 );
148
+ char *buffer = (char *)malloc (maxSize);
149
+ CFStringGetCString (currentTitle, buffer, maxSize, kCFStringEncodingUTF8 );
150
+ obj->Set (String::NewSymbol (" title" ), String::New (buffer));
151
+ obj->Set (String::NewSymbol (" id" ), Number::New (*(int *)currentWindowNumber));
152
+ printf (buffer);
153
+ printf (" \n " );
154
+ // windows.push_back(obj);
155
+
156
+ }
157
+
158
+
159
+
160
+ // return scope.Close(String::New("1"));
161
+
162
+ return scope.Close (String::New (" 1" ));
163
+ }
164
+
165
+
128
166
void init (Handle <Object> target)
129
167
{
130
168
target->Set (String::NewSymbol (" moveMouse" ),
@@ -144,6 +182,9 @@ void init(Handle<Object> target)
144
182
145
183
target->Set (String::NewSymbol (" captureScreen" ),
146
184
FunctionTemplate::New (captureScreen)->GetFunction ());
185
+
186
+ target->Set (String::NewSymbol (" getWindows" ),
187
+ FunctionTemplate::New (getWindows)->GetFunction ());
147
188
}
148
189
149
190
NODE_MODULE (robotjs, init)
0 commit comments