Unsolved How to grab screenshot in wayland?
-
I used to get screenshot via QScreen::grabWindow, but this interface is implemented by XCB. I can only get a black pixmap with it.
-
-
This post is deleted! -
@VRonin
Thanks for your answer. But It can only grab the pixmap of the widget, I need the entire screen -
-
take screenshot in wayland ,seems always give me a black screen.
-
@xiaoyifang Hi guys!
Yes I confirm that taking a screenshot under weston wayland just does not happen, here is the code that I use a connected signal onButtonReleased event:QScreen *screen = QGuiApplication::primaryScreen();
if (const QWindow *window = windowHandle()) {
qDebug() << "using screen from windowHandle()";
screen = window->screen();
}
if (!screen) {
qDebug() << "NO screen!!!";
return;
}
auto geom = screen->geometry();
qDebug() << geom;
QRect screenGeometry = qApp->primaryScreen()->virtualGeometry();
QPixmap screenGrab = qApp->primaryScreen()->grabWindow(qApp->desktop()->winId(), screenGeometry.x(), screenGeometry.y(), screenGeometry.width(), screenGeometry.height());
if (screenGrab.isNull())
{
qDebug() << "Grabbed: screenGrab.isNull() = " << screenGrab.isNull();
} else
{
QString fileName = "myshot.png";
screenGrab.save(fileName);
qDebug() << "Saved in " << fileName;
}And this is what I get under wayland:
onButtonReleased()
using screen from windowHandle()
QRect(0,0 1920x1080)
Grabbed: screenGrab.isNull() = trueThe same code works just fine under X11 (of course).
Is that a bug? Or a Wayland protocol behavior dur to its supposed safety improvement?
I have to say that: "QPixmap screenGrab = QPixmap::grabWidget(this)" WORKS!!!! but it takes a screenshot of the actual Gui app single window with button that I used to test the screenshot (I would like to take the whole Desktop...Any help welcomed :)
Thank you,
Sebastien. -
Hi,
KDE does run on top of Wayland, you might want to check the spectacle implementation to see how they do it.
-
Thanks for the suggestion, I've had a look and it uses a DBus request, same principle as weston-screenshooter but thisis a fairly slow process and I'm looking at ding at least 30 screenshot per seconds.
I've read somewhere Qt used libdrm under the hood to perform the screenshot, that's why I tried it.
-
So you are rather on the screen recording that shooting. Something like OBS does ?
-
@SGaist is there an issue or topic I can follow for the Wayland-implementation of
QScreen::grabWindow
? How is this generally done in the Qt-community? -
@tim-hilt I would go to the KDE folks. They likely have the most experience with Qt + Wayland.