File indexing completed on 2024-12-22 05:15:47

0001 #pragma once
0002 
0003 /*
0004  * SPDX-FileCopyrightText: 2003-2007 Craig Drummond <craig@kde.org>
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include <QLatin1String>
0009 #include <X11/Xlib.h>
0010 #include <private/qtx11extras_p.h>
0011 
0012 //
0013 // *Very* hacky way to get some KDE dialogs to appear to be transient
0014 // for 'xid'
0015 //
0016 // Create's a QWidget with size 0/0 and no border, makes this transient
0017 // for xid, and all other widgets can use this as their parent...
0018 static QWidget *createParent(int xid)
0019 {
0020     if (!xid)
0021         return nullptr;
0022 
0023     QWidget *parent = new QWidget(nullptr, Qt::FramelessWindowHint);
0024 
0025     parent->resize(1, 1);
0026     parent->show();
0027 
0028     XWindowAttributes attr;
0029     int rx, ry;
0030     Window junkwin;
0031 
0032     XSetTransientForHint(QX11Info::display(), parent->winId(), xid);
0033     if (XGetWindowAttributes(QX11Info::display(), xid, &attr)) {
0034         XTranslateCoordinates(QX11Info::display(), xid, attr.root, -attr.border_width, -16, &rx, &ry, &junkwin);
0035 
0036         rx = (rx + (attr.width / 2));
0037         if (rx < 0)
0038             rx = 0;
0039         ry = (ry + (attr.height / 2));
0040         if (ry < 0)
0041             ry = 0;
0042         parent->move(rx, ry);
0043     }
0044     parent->setWindowOpacity(0);
0045     parent->setWindowTitle(QLatin1String("KFI"));
0046 
0047     return parent;
0048 }