screenshot-desktop icon indicating copy to clipboard operation
screenshot-desktop copied to clipboard

Added ability to take screenshot of a single window

Open Mindar opened this issue 4 years ago • 5 comments

I added the ability to take screenshots of a window using the X-Server window ID (as talked about in #121 ). Obviously this only works on linux (so far).

I also added the function screenshot.listWindows(), which works similar to screenshot.listDisplays(). This function can be used to get a list of all windows' IDs. Windows returned by screenshot.listWindows() are ordered by X's "stacking order" (whatever that is supposed to mean... (I didn't research it further)).

Example:

const availableWindows = await screenshot.listWindows()
// availableWindows = ['0x4600001', '0x5600008', '0x360067a', '0x4800007', '0x4e00017', '0x3600003', ...]

const randomWindowId = availableWindows[4] // 4 was randomly chosen by fair dice roll

screenshot({windowId: randomWindowId}).then((img) => {
    // img: Buffer filled with jpg of the window
})

I'll try to add the same functionality for windows in the near future. Unfortunately I can't add it for Mac, because I don't own one.

Lastly, I added the actual MIT license text, so the project actually complies with its own license:

... The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. ...

Feel free to change the attribution line. For now I set it to "Copyright (c) 2020 Ben Evans and screenshot-desktop contributors".

Mindar avatar Feb 03 '21 21:02 Mindar

It works on windows too now. I also found a pretty easy way to add window screenshots for MacOS, but I didn't find an easy way to get a list of Window IDs.

@bencevans Is there any chance of this getting merged without Mac support?

Mindar avatar Feb 06 '21 22:02 Mindar

That's great @Mindar. Would you mind adding some tests (spawning notepad.exe on windows? spawning firefox on Linux maybe?) and adding a bit of documentation to the README with an example and mentioning that support is windows/Linux with an OSX pull-request welcome?

bencevans avatar Mar 01 '21 16:03 bencevans

does this work if the window is minimized? like when we share something in a google meet,zoom,.. even if the window is minimized everyone else keeps seeing it.

augustnmonteiro avatar Jul 30 '21 21:07 augustnmonteiro

Hello! Is this MR blocked by something?

kriakiku avatar Jul 21 '23 12:07 kriakiku

Documentation and Tests

bencevans avatar Jul 24 '23 10:07 bencevans