1

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.

martin
  • 1,007
  • 2
  • 16
  • 32
  • Looks like XY problem. What are you trying to achieve? – n. m. could be an AI Jun 26 '17 at 18:39
  • I am writing an app in Qt and I would like the main app window to always be behind any subsequent windows, but I still want those additional windows to be treated like regular windows (not for them to hide when, for example, I show all windows in Gnome), but since Qt doesn't have a way of listening to X11 events, I'm wondering how to do that in X11. – martin Jun 26 '17 at 18:49
  • There's no need in any of this. In Qt you just create a non-modal QDialog widget. – n. m. could be an AI Jun 26 '17 at 21:39

1 Answers1

1

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.

n. m. could be an AI
  • 112,515
  • 14
  • 128
  • 243
  • Thank you for the answer, however, because the dialogs are parented (4th condition) under the button, they get hidden when the "Show all windows" action gets run on gnome (for example), can't be minimized/maximized and (as far as I'm aware) don't play well with moving to other workspaces/desktops individually – martin Jun 27 '17 at 00:45
  • A working example of the behavior I'm looking for can be reproduced by opening gimp and then clicking File-->New. This brings up a window which is standalone, but would also never go behind the main window and it doesn't block the main window either (not modal) – martin Jun 27 '17 at 00:56
  • 1
    It is not a parent in the X11 sense, it's a "transient parent" which is quite a different thing. I'm not sure about the other things you wrote, I think they work for me but I'll need to check them (can't get to the machine at the moment). Stay tuned. The gimo dialog cannot be minimised either on my machine. – n. m. could be an AI Jun 27 '17 at 06:25
  • 1
    @Martin on my machine, these dialogs can be minimised (to a common taskbar entry) and maximised, none are hidden, and all can be moved to other desktops. When the main window is minimised, restored, or moved to another desktop, they are minimised, restored, or move along. I'm using KDE though. – n. m. could be an AI Jun 27 '17 at 17:37
  • 1
    @Martin OTOH on my machine the gimp File ---> New window doesn't work like you describe at all. The subordinate window doesn't stay above anything, and cannot be maximised. It does have its own taskbar entry though. Perhaps this is a GIMP bug (I use an unstable version). File ---> Open window however behaves *exactly* like my example. – n. m. could be an AI Jun 27 '17 at 17:39