Beispiel #1
0
void screenAdded(QScreen* screen)
{
    screen->setOrientationUpdateMask((Qt::ScreenOrientations)0x0F);
    qDebug("\nscreenAdded %s siblings %d first %s", qPrintable(screen->name()), screen->virtualSiblings().count(),
        (screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
    PropertyWatcher *w = new PropertyWatcher(screen, QString::number(i++));
    QLineEdit *siblingsField = new QLineEdit();
    siblingsField->setObjectName("siblings");
    siblingsField->setReadOnly(true);
    w->layout()->insertRow(0, "virtualSiblings", siblingsField);
    updateSiblings(w);

    // This doesn't work.  If the multiple screens are part of
    // a virtual desktop (i.e. they are virtual siblings), then
    // setScreen has no effect, and we need the code below to
    // change the window geometry.  If on the other hand the
    // screens are really separate, so that windows are not
    // portable between them, XCreateWindow needs to have not just
    // a different root Window but also a different Display, in order to
    // put the window on the other screen.  That would require a
    // different QXcbConnection.  So this setScreen call doesn't seem useful.
    //w->windowHandle()->setScreen(screen);

    // But this works as long as the screens are all virtual siblings
    w->show();
    QRect geom = w->geometry();
    geom.moveCenter(screen->geometry().center());
    w->move(geom.topLeft());

    // workaround for the fact that virtualSiblings is not a property,
    // thus there is no change notification:
    // allow the user to update the field manually
    QObject::connect(w, &PropertyWatcher::updatedAllFields, &updateSiblings);
}
Beispiel #2
0
void screenAdded(QScreen* screen)
{
    screen->setOrientationUpdateMask((Qt::ScreenOrientations)0x0F);
    qDebug("\nscreenAdded %s siblings %d first %s", qPrintable(screen->name()), screen->virtualSiblings().count(),
        (screen->virtualSiblings().isEmpty() ? "none" : qPrintable(screen->virtualSiblings().first()->name())));
    PropertyWatcher *w = new PropertyWatcher(screen, QString::number(i++));
    QLineEdit *siblingsField = new QLineEdit();
    siblingsField->setObjectName("siblings");
    siblingsField->setReadOnly(true);
    w->layout()->insertRow(0, "virtualSiblings", siblingsField);
    updateSiblings(w);

    // Set the screen via QDesktopWidget. This corresponds to setScreen() for the underlying
    // QWindow. This is essential when having separate X screens since the the positioning below is
    // not sufficient to get the windows show up on the desired screen.
    QList<QScreen *> screens = QGuiApplication::screens();
    int screenNumber = screens.indexOf(screen);
    Q_ASSERT(screenNumber >= 0);
    w->setParent(qApp->desktop()->screen(screenNumber));

    w->show();

    // Position the windows so that they end up at the center of the corresponding screen.
    QRect geom = w->geometry();
    geom.setSize(w->sizeHint());
    if (geom.height() > screen->geometry().height())
        geom.setHeight(screen->geometry().height() * 9 / 10);
    geom.moveCenter(screen->geometry().center());
    w->setGeometry(geom);

    props->insert(screen, w);

    // workaround for the fact that virtualSiblings is not a property,
    // thus there is no change notification:
    // allow the user to update the field manually
    QObject::connect(w, &PropertyWatcher::updatedAllFields, &updateSiblings);
}