예제 #1
0
// A very simple implementation where we assume that there's only one window and that it's a
// QQuickWindow. Thus the id parameter is irrelevant.
//
// Idea: Make the id contain the objectName of the QQuickWindow once we care about a multi-display
//       compositor?
//       Strictly speaking that could be the actual QWindow::winId(), but that's mostly a
//       meaningless arbitrary number.
QImage WindowScreenshotProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
    Q_UNUSED(id);
    Q_UNUSED(requestedSize);

    QWindowList windows = QGuiApplication::topLevelWindows();

    if (windows.count() != 1) {
        size->rwidth() = 0;
        size->rheight() = 0;
        return QImage();
    }

    QQuickWindow *quickWindow = qobject_cast<QQuickWindow *>(windows[0]);

    if (!quickWindow) {
        size->rwidth() = 0;
        size->rheight() = 0;
        return QImage();
    }

    QImage image = quickWindow->grabWindow();
    size->rwidth() = image.width();
    size->rheight() = image.height();
    return image;
}
예제 #2
0
QT_BEGIN_NAMESPACE

#ifndef QT_NO_DRAGANDDROP

static QWindow* topLevelAt(const QPoint &pos)
{
    QWindowList list = QGuiApplication::topLevelWindows();
    for (int i = list.count()-1; i >= 0; --i) {
        QWindow *w = list.at(i);
        if (w->isVisible() && w->geometry().contains(pos) && !qobject_cast<QShapedPixmapWindow*>(w))
            return w;
    }
    return 0;
}
QWindow *MouseTouchAdaptor::findQWindowWithXWindowID(WId windowId)
{
    QWindowList windowList = QGuiApplication::topLevelWindows();
    QWindow *foundWindow = nullptr;

    int i = 0;
    while (!foundWindow && i < windowList.count()) {
        QWindow *window = windowList[i];
        if (window->winId() == windowId) {
            foundWindow = window;
        } else {
            ++i;
        }
    }

    Q_ASSERT(foundWindow);
    return foundWindow;
}