From ea34961b502bfd76dd6302105f53b88ded995736 Mon Sep 17 00:00:00 2001 From: Jason Stallings Date: Sun, 7 Sep 2014 10:58:51 -0500 Subject: [PATCH] Experimenting with Window manipulation. --- src/robotjs.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/robotjs.cc b/src/robotjs.cc index aafc798e..d6616d21 100644 --- a/src/robotjs.cc +++ b/src/robotjs.cc @@ -1,5 +1,6 @@ #include #include +#include #include "mouse.h" #include "deadbeef_rand.h" #include "screen.h" @@ -125,6 +126,43 @@ Handle captureScreen(const Arguments& args) //return scope.Close(String::New("1")); } +Handle getWindows(const Arguments& args) +{ + HandleScope scope; + + CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); + CFIndex windowNum = CFArrayGetCount(windowList); + + std::vector windows; + Local 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 target) { target->Set(String::NewSymbol("moveMouse"), @@ -144,6 +182,9 @@ void init(Handle target) target->Set(String::NewSymbol("captureScreen"), FunctionTemplate::New(captureScreen)->GetFunction()); + + target->Set(String::NewSymbol("getWindows"), + FunctionTemplate::New(getWindows)->GetFunction()); } NODE_MODULE(robotjs, init)