Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getActiveWindow returns out-of-bounds coordinates for maximized windows #559

Closed
1 of 3 tasks
joel-duffie opened this issue Feb 7, 2024 · 2 comments
Closed
1 of 3 tasks

Comments

@joel-duffie
Copy link

Version
nut.js 3.1.2

Short overview
The region attribute of a full-screen window (returned by getActiveWindow()), stretches beyond the screen borders, causing problems.

Issue occurs on

  • Virtual machine
  • Docker container
  • Dev/Host system

node version:
16.20.2

OS type and version:
Windows 10

Detailed error description
I have an application in 'maximized' mode (full-screen).

const window = await getActiveWindow();
const window_region = await window.region;

screen.find(imageResource('my-image.png'), {
   searchRegion: window_region
});

After the above code is run, I get this error:

Error: [nut.js] - Error: Searching for C:\Users\---\nut-js-testing\images\windows\actionPalette.png failed. 
Reason: 'Error: Error: x coordinate outside of display'
    at ScreenClass.find (C:\Users\---\nut-js-testing\node_modules\@nut-tree\nut-js\dist\lib\screen.class.js:169:27)
    at async C:\Users\---\nut-js-testing\scripts\interactions.js:22:27

It says that the 'x coordinate' is 'outside' of the display.
I can make a slightly smaller region, adding 8px to the left and top to resolve this issue, however, I don't think this should be the permanent solution.

As far as I can tell, the result of getActiveWindow() should be bound by the current screen, specifically if the window is maximized.

Full code sample to reproduce

const nut = require('@nut-tree/nut-js');
require('@nut-tree/nl-matcher');

// * current window is maximized
(async () => {
    try {
        let reg = await (await nut.getActiveWindow()).region;
        await nut.screen.find(nut.imageResource(actionPalette), {
            searchRegion: reg
        });
    } catch (err) {
        console.error(err);
    }
})();

Additional content

Please provide any (mandatory) additional data to reproduce the error (Dockerfiles etc.)

@s1hofmann
Copy link
Member

Hi @joel-duffie 👋

this stems from the fact that window decorations are counted towards the window size, leading to out of bounds windows in case of full screen windows or windows close to the screen border.
That should be accounted for 👍

s1hofmann added a commit that referenced this issue Feb 16, 2024
It’ll now cut off window regions at the borders of the main screen, avoiding errors due to out of bounds regions
s1hofmann added a commit that referenced this issue Feb 16, 2024
* (#559) Adjust getRegion implementation

It’ll now cut off window regions at the borders of the main screen, avoiding errors due to out of bounds regions

* (#559) Moved window e2e test into dedicated e2e subpackage
@s1hofmann
Copy link
Member

Closed with release 4.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants