Hi, I thought it might be cool to be able to hit a keyboard shortcut to copy whatever your program is drawing and then paste it online somewhere. The usual approach is tedious: save a screenshot, go to the website where you want to post, click on “add image” then find and select the image on your drive. I wish it was just ctrl+c and ctrl+v.
OPENRNDR does offer Clipboard access thanks to GLFW, but they never got to implement images on the clipboard. There’s a 7 year old issue waiting there.
I asked myself about what could be done as a workaround, and I found that the Linux xclip
program can place an image into the clipboard, so I wrote this simple extension that enables the feature with just one line of code in your program:
import org.openrndr.Extension
import org.openrndr.Program
import org.openrndr.extensions.Screenshots
/**
* OPENRNDR extension to enable
* CTRL+C to copy the visible content to the clipboard on Linux or
* other OSes providing the `xclip` command line program.
*
* Usage: `extend(ClipboardScreenshot())`
* then press CTRL+C to copy what you see, paste the image somewhere.
*/
class ClipboardScreenshot : Extension {
override var enabled: Boolean = true
val screenshots = Screenshots().also {
it.name = "/tmp/openrndr-screenshot.png"
it.async = false
it.afterScreenshot.listen { _ ->
Runtime.getRuntime().exec(
"xclip -selection clip -t image/png ${it.name}"
)
}
}
override fun setup(program: Program) {
program.extend(screenshots)
program.keyboard.keyDown.listen {
if (program.keyboard.pressedKeys.contains("left-control") &&
it.name == "c"
) screenshots.trigger()
}
}
}
Unfortunately it’s Linux-only for now. If you’re using a different platform and find out a way to make this extension work for you, please share how you did it!