Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ export interface WindowInfo {
*/
handle: number;

/**
* The window bounding box minX position
*/
rectLeft: number;

/**
* The window bounding box maxX position
*/
rectRight: number;

/**
* The window bounding box minY position
*/
rectTop: number;

/**
* The window bounding box maxY position
*/
rectBottom: number;


/**
* The window position in z-order
*/
Expand Down
12 changes: 11 additions & 1 deletion src/list-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ static int getZorder(HWND hwnd) {
return z;
}

static RECT getRect(HWND hwnd) {
RECT rect;
GetWindowRect(hwnd, &rect);
return rect;
}

/**
* Get a list of currently open windows. The list holds structs of type of
* window_info_t.
Expand All @@ -150,9 +156,13 @@ WindowList listWindows() {

for (const HWND hwnd : hwnds) {
window_info_t window;

window.handle = hwnd;
window.zOrder = getZorder(hwnd);
RECT rect = getRect(hwnd);
window.rectLeft = rect.left;
window.rectRight = rect.right;
window.rectTop = rect.top;
window.rectBottom = rect.bottom;
GetClassName(hwnd, window.className, MAX_STRING_LENGTH);
GetWindowText(hwnd, window.caption, MAX_STRING_LENGTH);
GetWindowThreadProcessId(hwnd, &window.processId);
Expand Down
46 changes: 44 additions & 2 deletions src/list-windows.js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
napi_value jsListWindows(napi_env env, napi_callback_info info) {
// The array of windows, a single window object and properties
napi_value jsWindows, jsWindow, jsHandle, jsZOrder, jsClassName, jsCaption,
napi_value jsWindows, jsWindow, jsHandle, jsZOrder, jsClassName, jsCaption, jsRectLeft, jsRectBottom, jsRectRight, jsRectTop,
jsProcessId, jsProcessPath;
napi_status status;

Expand Down Expand Up @@ -43,6 +43,28 @@ napi_value jsListWindows(napi_env env, napi_callback_info info) {
napi_throw_error(env, NULL, "Failed to create int 'jsZOrder'");
}

// const jsRectLeft = ...
status = napi_create_int32(env, (uint32_t)window.rectLeft, &jsRectLeft);
if (status != napi_ok) {
napi_throw_error(env, NULL, "Failed to create int 'jsRectLeft'");
}
// const jsRectRight = ...
status = napi_create_int32(env, (uint32_t)window.rectRight, &jsRectRight);
if (status != napi_ok) {
napi_throw_error(env, NULL, "Failed to create int 'jsRectRight'");
}
// const jsRectTop = ...
status = napi_create_int32(env, (uint32_t)window.rectTop, &jsRectTop);
if (status != napi_ok) {
napi_throw_error(env, NULL, "Failed to create int 'jsRectTop'");
}
// const jsRectBottom = ...
status = napi_create_int32(env, (uint32_t)window.rectBottom, &jsRectBottom);
if (status != napi_ok) {
napi_throw_error(env, NULL, "Failed to create int 'jsRectBottom'");
}


// const jsClassName = '...'
status = napi_create_string_utf16(env, (char16_t *)window.className,
NAPI_AUTO_LENGTH, &jsClassName);
Expand Down Expand Up @@ -77,13 +99,33 @@ napi_value jsListWindows(napi_env env, napi_callback_info info) {
"Failed to set property 'handle' on object 'jsWindow'");
}

// jsWindow.handle = jsZOrder
// jsWindow.zOrder = jsZOrder
status = napi_set_named_property(env, jsWindow, "zOrder", jsZOrder);
if (status != napi_ok) {
napi_throw_error(env, NULL,
"Failed to set property 'zOrder' on object 'jsWindow'");
}

status = napi_set_named_property(env, jsWindow, "rectLeft", jsRectLeft);
if (status != napi_ok) {
napi_throw_error(env, NULL,
"Failed to set property 'rectLeft' on object 'jsWindow'");
}
status = napi_set_named_property(env, jsWindow, "rectRight", jsRectRight);
if (status != napi_ok) {
napi_throw_error(env, NULL,
"Failed to set property 'rectRight' on object 'jsWindow'");
}
status = napi_set_named_property(env, jsWindow, "rectTop", jsRectTop);
if (status != napi_ok) {
napi_throw_error(env, NULL,
"Failed to set property 'rectTop' on object 'jsWindow'");
}
status = napi_set_named_property(env, jsWindow, "rectBottom", jsRectBottom);
if (status != napi_ok) {
napi_throw_error(env, NULL,
"Failed to set property 'rectBottom' on object 'jsWindow'");
}
// jsWindow.className = jsClassName
status = napi_set_named_property(env, jsWindow, "className", jsClassName);
if (status != napi_ok) {
Expand Down