How to control X11 app level window stacking?

291 Views Asked by At

Is there any way to have 2 windows in X11, with the following criteria:

  • Second window always stays on top of the first one
  • Second window doesn't stay on top of other applications' windows
  • No flickering when switching windows
  • Both windows need to be top level windows (not parented under each other) and not blocking

Making the second one modal almost works, but it blocks the first one, which is not desired.

1

There are 1 best solutions below

5
On

Here's how one may do this in Qt by creating non-modal QDialog widgets.

#include <QObject>
#include <QApplication>
#include <QPushButton>
#include <QDialog>

int main(int argc, char **argv)
{
    QApplication a(argc, argv);

    QPushButton p1("moo", 0);

    QDialog d1(&p1);
    QPushButton p2("roo", &d1);

    QDialog d2(&p1);
    QPushButton p3("goo", &d2);

    QObject::connect(&p1, &QPushButton::clicked, [&](){p2.setText("w00t!");});
    QObject::connect(&p2, &QPushButton::clicked, [&](){p1.setText("n00t!");});
    QObject::connect(&p3, &QPushButton::clicked, [&](){p1.setText("eh?"); p2.setText("meh!");});

    p1.resize(400, 400);
    p2.resize(200, 200);
    p3.resize(200, 200);

    p1.show();
    p2.show();
    p3.show();
    d1.show();
    d2.show();

    return a.exec();
}

All of your conditions are met as far as I can tell.