nut-tree/nut.js

`getActiveWindow` returns out-of-bounds coordinates for maximized windows

joel-duffie opened this issue · 2 comments

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.)

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 👍

Closed with release 4.0.0