Skip to content

Commit 8f81ad9

Browse files
authored
Merge pull request #46 from nut-tree/bugfix/45/whole_screen_region_screenshots
Bugfix/45/whole screen region screenshots
2 parents 8485345 + 879cb8c commit 8f81ad9

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## @next
6+
7+
- Bugfix: Fix off-by-one error when specifying the full screen region in `screen.capture` [(#45)](https://github.com/nut-tree/libnut/issues/45)
8+
59
## 2.1.0
610

711
- Enhancement: Retrieve coordinates of current active window [(#15)](https://github.com/nut-tree/libnut/issues/15)

src/main.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -715,33 +715,33 @@ Napi::Object _captureScreen(const Napi::CallbackInfo &info)
715715
{
716716
Napi::Env env = info.Env();
717717

718-
size_t x;
719-
size_t y;
720-
size_t w;
721-
size_t h;
718+
int64_t x;
719+
int64_t y;
720+
int64_t w;
721+
int64_t h;
722722

723723
MMSize displaySize = getMainDisplaySize();
724724
//If user has provided screen coords, use them!
725725
if (info.Length() == 4)
726726
{
727-
x = info[0].As<Napi::Number>().Int32Value();
728-
y = info[1].As<Napi::Number>().Int32Value();
729-
w = info[2].As<Napi::Number>().Int32Value();
730-
h = info[3].As<Napi::Number>().Int32Value();
727+
x = info[0].As<Napi::Number>().Int64Value();
728+
y = info[1].As<Napi::Number>().Int64Value();
729+
w = info[2].As<Napi::Number>().Int64Value();
730+
h = info[3].As<Napi::Number>().Int64Value();
731731

732-
if (!(x >= 0 && x < displaySize.width))
732+
if (!(x >= 0 && x <= displaySize.width))
733733
{
734734
throw Napi::Error::New(env, "Error: x coordinate outside of display");
735735
}
736-
if (!(y >= 0 && y < displaySize.height))
736+
if (!(y >= 0 && y <= displaySize.height))
737737
{
738738
throw Napi::Error::New(env, "Error: y coordinate outside of display");
739739
}
740-
if (!((x + w) >= 0 && (x + w) < displaySize.width))
740+
if (!((x + w) >= 0 && (x + w) <= displaySize.width))
741741
{
742742
throw Napi::Error::New(env, "Error: Given width exceeds display dimensions");
743743
}
744-
if (!((y + h) >= 0 && (y + h) < displaySize.height))
744+
if (!((y + h) >= 0 && (y + h) <= displaySize.height))
745745
{
746746
throw Napi::Error::New(env, "Error: Given height exceeds display dimensions");
747747
}

test/screen.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,16 @@ describe("Screen", () => {
88
expect(screenSize.height !== undefined).toBeTruthy();
99
});
1010
});
11+
12+
describe("Capture", () => {
13+
it("fullScreen capture", () => {
14+
// GIVEN
15+
const screenSize = libnut.getScreenSize()
16+
17+
// WHEN
18+
const capture = () => libnut.screen.capture(0, 0, screenSize.width, screenSize.height);
19+
20+
// THEN
21+
expect(capture).not.toThrowError("Error: Given width exceeds display dimensions");
22+
});
23+
});

0 commit comments

Comments
 (0)