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

Wayland Support #220

Open
weiameili opened this issue Sep 21, 2021 · 11 comments
Open

Wayland Support #220

weiameili opened this issue Sep 21, 2021 · 11 comments

Comments

@weiameili
Copy link

No description provided.

@bencevans
Copy link
Owner

I can't say I've ever tested it, but I would be interested to hear if you try it.

@weiameili
Copy link
Author

Nope I don't think it does. I get the following error:

Error: Command failed: import -silent -window root -crop 1920x1080+0+0 -screen png:"/home/wali/Pictures/demo.png" 
import-im6.q16: unable to read X window image `root': Resource temporarily unavailable @ error/xwindow.c/XImportImage/4977.
import-im6.q16: missing an image filename `png:/home/wali/Pictures/demo.png' @ error/import.c/ImportImageCommand/1276.

Are there any plans to support it?

@bencevans
Copy link
Owner

Ah, that's a shame. A pull request would be very welcome, but I won't be working on it myself, at least not for the foreseeable future.

@blurymind
Copy link

blurymind commented Oct 4, 2022

I suppose that for wayland this line needs to change?
https://github.com/bencevans/screenshot-desktop/blob/main/lib/linux/index.js#L170

some more info here https://imagemagick.org/discourse-server/viewtopic.php?t=30759
https://bbs.archlinux.org/viewtopic.php?pid=1662309

it looks like imagemagick is catching up with wayland, but surely there must be a way.

To detect wayland
https://support.hubstaff.com/screenshot-capture-support-wayland-linux/
echo $XDG_SESSION_TYPE$

then how does one screenshot
https://stackoverflow.com/questions/68341253/how-can-i-take-a-screenshot-on-wayland

here is a bash script that supposedly does it for you
https://gist.github.com/LeaPhant/b74d15af9749ad85e6e1a7d146dbe6bd

theres some cmd line tools too
https://github.com/emersion/grim

@blurymind
Copy link

blurymind commented Oct 4, 2022

You could use this tool
https://www.npmjs.com/package/img-clipboard

which does support wayland. Perhaps copy their solution and refactor it

heres one that works for gnome
https://stackoverflow.com/questions/59619045/programmatically-make-a-screenshot-of-a-terminal-window-in-gnome-wayland

orr scrap these scripts and add ksnip as a dependency. From there on you could do

function screenshot (options = {}) {
  return new Promise((resolve, reject) => {
    // listDisplays().then((screens) => {
      // const screen = screens.find(options.screen ? screen => screen.id === options.screen : screen => screen.primary || screen.id === 'default') || screens[0]

      const filename = options.filename ? (options.filename.replace(/"/g, '\\"')) : '-'
      const execOptions = {};
      const commandLine = `ksnip -f --saveto ${options.filename}`
      exec(
        commandLine,
        execOptions,
        (err, stdout) => {
          if (err) {
            return reject(err)
          } else {
            return resolve(options.filename ? path.resolve(options.filename) : stdout)
          }
        })
    // })
  })
}

@valueerrorx
Copy link

ksnip is actually an interesting idea because it also is able to return the image as "buffer" like imagemagick.
unfortunately it triggers a desktop notification per default setting and it isn't possible to turn this off from a terminal

it also works on gnome wayland but it uses the screenshot portal which again makes it difficult to use from a terminal because it triggers a new window to pop up...

gnome-screenshot could also be an option but it flashes the screen everytime it takes a screenshot and i didn't find a way to return the image as buffer

@SteveCruise
Copy link

关注解决
care when to solve it

@camhart
Copy link

camhart commented Jul 30, 2024

Could I make a donation to get this issue resolve?

@valueerrorx
Copy link

valueerrorx commented Sep 24, 2024

after a long time playing around (again) i figured out that spectacle can take quiet screenshots of the whole desktop now:

spectacle
spectacle --background --nonotify -o test1.jpg

imagemagick can now import a window without interaction as long as you provide the id or the name:
import -silent -window "window_name" output.png
i couldn't figure out a name/id for the root window (which isn't provided anymore)
also -screen waited for a click on a window

flameshot can also capture the whole screen and with the -r switch deliver the raw image information (this is most likely the option we need)
flameshot full --raw > test.png

in any case this would be an additional dependency BUT you could switch entirely to flameshot instead of imagemagic

@bencevans
Copy link
Owner

Super! Could certainly add some form of checking for availability if a library hasn't been strictly specified. I'm not able to work on this anytime soon but PR welcome :)

@valueerrorx
Copy link

#300

have a look at this.. very basic but works for me

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

No branches or pull requests

6 participants