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

Added ability to take screenshot of a single window #193

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Mindar
Copy link

@Mindar Mindar commented Feb 3, 2021

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
Copy link
Author

Mindar commented Feb 6, 2021

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?

@bencevans
Copy link
Owner

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?

@augustnmonteiro
Copy link

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.

@kriakiku
Copy link

Hello! Is this MR blocked by something?

@bencevans
Copy link
Owner

Documentation and Tests

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

Successfully merging this pull request may close these issues.

4 participants