screenshot-desktop
screenshot-desktop copied to clipboard
Added ability to take screenshot of a single window
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".
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?
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?
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.
Hello! Is this MR blocked by something?
Documentation and Tests