Skip to content

Commit

Permalink
add isMainDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
vinvol committed Jun 12, 2020
1 parent b80b20c commit fe1c09b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/robotjs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,16 @@ NAN_METHOD(getAllScreensSize)
{
Local<Object> obj = Nan::New<Object>();
Nan::Set(obj, Nan::New("displayID").ToLocalChecked(), Nan::New<Number>(displaySizes[i].displayID));
Nan::Set(obj, Nan::New("isMainDisplay").ToLocalChecked(), Nan::New<v8::Boolean>(displaySizes[i].isMainDisplay));

Nan::Set(obj, Nan::New("width").ToLocalChecked(), Nan::New<Number>(displaySizes[i].size.width));
Nan::Set(obj, Nan::New("height").ToLocalChecked(), Nan::New<Number>(displaySizes[i].size.height));

Nan::Set(obj, Nan::New("x").ToLocalChecked(), Nan::New<Number>(displaySizes[i].bounds.origin.x));
Nan::Set(obj, Nan::New("y").ToLocalChecked(), Nan::New<Number>(displaySizes[i].bounds.origin.y));
Nan::Set(obj, Nan::New("w").ToLocalChecked(), Nan::New<Number>(displaySizes[i].bounds.size.width));
Nan::Set(obj, Nan::New("h").ToLocalChecked(), Nan::New<Number>(displaySizes[i].bounds.size.height));

Nan::Set(list, i, obj);
}

Expand Down
7 changes: 6 additions & 1 deletion src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,19 @@ void getAllDisplaySize(uint32_t *_Nullable numDisplays, MMDisplaySize *_Nullable
#if defined(IS_MACOSX)

CGDirectDisplayID displays[10];
CGDirectDisplayID mainDisplayID = CGMainDisplayID();

CGGetOnlineDisplayList(10, displays, numDisplays);
for (uint32_t i = 0; i < *numDisplays; i++)
{
CGRect bounds = CGDisplayBounds(displays[i]);
displaySizes[i] = MMDisplaySizeMake(
displays[i],
mainDisplayID == displays[i],
CGDisplayPixelsWide(displays[i]),
CGDisplayPixelsHigh(displays[i]));
CGDisplayPixelsHigh(displays[i]),
MMRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height)
);
}

#endif
Expand Down
9 changes: 8 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ typedef struct _MMRect MMRect;
struct _MMDisplaySize
{
int32_t displayID;
int isMainDisplay;
MMSize size;
MMRect bounds;
};

typedef struct _MMDisplaySize MMDisplaySize;
Expand All @@ -62,12 +64,17 @@ H_INLINE MMSignedPoint MMSignedPointMake(int32_t x, int32_t y)
return point;
}

H_INLINE MMDisplaySize MMDisplaySizeMake(int32_t displayID, size_t width, size_t height)
H_INLINE MMDisplaySize MMDisplaySizeMake(int32_t displayID, int isMainDisplay, size_t width, size_t height, MMRect bounds)
{
MMDisplaySize diplaySize;
diplaySize.displayID = displayID;
diplaySize.isMainDisplay = isMainDisplay;
diplaySize.size.width = width;
diplaySize.size.height = height;
diplaySize.bounds.origin.x = bounds.origin.x;
diplaySize.bounds.origin.x = bounds.origin.x;
diplaySize.bounds.size.width = bounds.size.width;
diplaySize.bounds.size.height = bounds.size.height;
return diplaySize;
}

Expand Down

0 comments on commit fe1c09b

Please sign in to comment.