PDA

View Full Version : QScreen::grabWindow() not working on Ubuntu Touch/Phone



liripiri
November 13th, 2013, 10:48 AM
Hi everyone. I'm developing an app for Ubuntu Touch (13.10) running on Nexus 4 that has a feature that can take a screenshot of my running app. However this is not working on the device but IS working when I run my app on Ubuntu desktop. This is a C++ plugin that is loaded to my QML application. Here's the code in short:



QScreen *screen = QGuiApplication::primaryScreen();
QPixmap pxm = screen->grabWindow(qApp->focusWindow()->winId());


pxm QSize is always (0, 0). However on Desktop, it returns a valid screenshot.

I've also tried this, but it's not working:


QWindow *topWin = qApp->topLevelAt(QPoint(360/2,640/2));
WId id = topWin->winId(); // <--- returns 1 (device)

QPixmap pxm = screen->grabWindow(id);


How do I get the correct winId? I assume the problem is with that since grabWindow is working on desktop.

liripiri
November 13th, 2013, 02:56 PM
Just realized that maybe this is not implemented or is not yet working on Ubuntu Touch since it uses the new Mir display server and is it so that Ubuntu desktop is using something else?

liripiri
November 14th, 2013, 10:30 AM
Tried also:


QWindow *topwin = NULL;
foreach(QWindow *win, qApp->topLevelWindows()) {
qDebug() << "winid:" << win->winId();

qDebug() << "winisactive:" << win->isActive();
qDebug() << "winistoplevel:" << win->isTopLevel();
qDebug() << "winsize:" <<win->size();
if (win->isActive() && win->isTopLevel()) {
topwin = win;
break;


}

}

if (topwin != NULL) {

QPixmap pxm = m_screen->grabWindow(topwin->winId());

}


.. which works again on Desktop but not on device. WId seems to be correct, but grabWindow() must be buggy...

nidzo732
November 14th, 2013, 10:56 AM
I haven't done much programming for Ubuntu Touch but i think that the problem is that Ubuntu Touch doesn't have an actual window manager like the one used on desktop.
This is just a wild guess, I'm not familiar with the internals of Qt. grabWindow probaly relies on window manager or X to give it some kind of pointer to the actual window but those don't exist on the phone (might be that Mir hasn't implemented it yet).
Maybe you should check out the Qt sources and see what grabWindow relies on.

Edit

I've checked out the Qt source, it seems that grabWindow relies on OS specific implementation, you can find the actual code of grabWindow in Qt source in /src/gui/image/gpixmap_*.cpp, replace the asterisk with the actual graphics implementation (X11, Windows, Mac).
The X11 version is used on Desktop linux and it relies on the functions from X11 API which are available on the desktop, but the phone uses Mir, try contacting Qt or Mir developers to see if this will be implemented for Mir in the future.
Here's the link for the X11 implementation:
https://qt.gitorious.org/qt/qt/source/a18d932b09137bb0f20e254dec5bb2313863d3e4:src/gui/image/qpixmap_x11.cpp#L2108