Skip to content

Commit

Permalink
Cleaning up the code, moving window code to new branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
octalmage committed Jan 19, 2015
1 parent c5da2d2 commit 16f67af
Showing 1 changed file with 10 additions and 41 deletions.
51 changes: 10 additions & 41 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace v8;
| |\/| |/ _ \| | | / __|/ _ \
| | | | (_) | |_| \__ \ __/
|_| |_|\___/ \__,_|___/\___|
*/

Handle<Value> moveMouse(const Arguments& args)
Expand Down Expand Up @@ -107,7 +108,15 @@ Handle<Value> typeString(const Arguments& args)
return scope.Close(String::New("1"));
}

//Screen
/*
_____
/ ____|
| (___ ___ _ __ ___ ___ _ __
\___ \ / __| '__/ _ \/ _ \ '_ \
____) | (__| | | __/ __/ | | |
|_____/ \___|_| \___|\___|_| |_|
*/

Handle<Value> captureScreen(const Arguments& args)
{
Expand All @@ -126,43 +135,6 @@ 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 @@ -182,9 +154,6 @@ 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 16f67af

Please sign in to comment.