Skip to content

Commit

Permalink
Experimenting with Window manipulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Sep 7, 2014
1 parent 29a293d commit ea34961
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <node.h>
#include <v8.h>
#include <vector>
#include "mouse.h"
#include "deadbeef_rand.h"
#include "screen.h"
Expand Down Expand Up @@ -125,6 +126,43 @@ Handle<Value> captureScreen(const Arguments& args)
//return scope.Close(String::New("1"));
}

Handle<Value> getWindows(const Arguments& args)
{
HandleScope scope;

CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
CFIndex windowNum = CFArrayGetCount(windowList);

std::vector<Object> windows;
Local<Object> obj = Object::New();


for (int i = 0; i < (int)windowNum; i++)
{
CFDictionaryRef info = (CFDictionaryRef)CFArrayGetValueAtIndex(windowList, i);
CFNumberRef currentPID = (CFNumberRef)CFDictionaryGetValue(info, kCGWindowOwnerPID);
CFNumberRef currentWindowNumber = (CFNumberRef)CFDictionaryGetValue(info, kCGWindowNumber);
CFStringRef currentTitle = (CFStringRef)CFDictionaryGetValue(info, kCGWindowName);
CFIndex length = CFStringGetLength(currentTitle);
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
char *buffer = (char *)malloc(maxSize);
CFStringGetCString(currentTitle, buffer, maxSize, kCFStringEncodingUTF8);
obj->Set(String::NewSymbol("title"), String::New(buffer));
obj->Set(String::NewSymbol("id"), Number::New(*(int *)currentWindowNumber));
printf(buffer);
printf("\n");
//windows.push_back(obj);

}



//return scope.Close(String::New("1"));

return scope.Close(String::New("1"));
}


void init(Handle<Object> target)
{
target->Set(String::NewSymbol("moveMouse"),
Expand All @@ -144,6 +182,9 @@ void init(Handle<Object> target)

target->Set(String::NewSymbol("captureScreen"),
FunctionTemplate::New(captureScreen)->GetFunction());

target->Set(String::NewSymbol("getWindows"),
FunctionTemplate::New(getWindows)->GetFunction());
}

NODE_MODULE(robotjs, init)

0 comments on commit ea34961

Please sign in to comment.