File indexing completed on 2024-05-05 05:49:58
0001 /***************************************************************************** 0002 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU Lesser General Public License as * 0006 * published by the Free Software Foundation; either version 2.1 of the * 0007 * License, or (at your option) version 3, or any later version accepted * 0008 * by the membership of KDE e.V. (or its successor approved by the * 0009 * membership of KDE e.V.), which shall act as a proxy defined in * 0010 * Section 6 of version 3 of the license. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, * 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0015 * Lesser General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU Lesser General Public * 0018 * License along with this library. If not, * 0019 * see <http://www.gnu.org/licenses/>. * 0020 *****************************************************************************/ 0021 0022 #include "config.h" 0023 #include "argbhelper.h" 0024 #include <QDesktopWidget> 0025 #include <QApplication> 0026 0027 #include <vector> 0028 0029 // Copied from qt_x11_p.h. 0030 // This is not part of the public API but should be stable enough to use 0031 // because it had never changed since the first git commit of Qt. 0032 struct QX11InfoData { 0033 uint ref; 0034 int screen; 0035 int dpiX; 0036 int dpiY; 0037 int depth; 0038 int cells; 0039 unsigned long colormap; 0040 void *visual; 0041 bool defaultColormap; 0042 bool defaultVisual; 0043 int subpixel; 0044 }; 0045 0046 namespace QtCurve { 0047 bool QtcX11Info::creatingDummy = false; 0048 0049 #ifdef Q_WS_X11 0050 inline QtcX11Info* 0051 QtcX11Info::getInfo(const QWidget *w) 0052 { 0053 return static_cast<QtcX11Info*>(const_cast<QX11Info*>(&w->x11Info())); 0054 } 0055 0056 // Qt uses XCreateSimpleWindow when defaultVisual and defaultColormap 0057 // are true. This confuses QGLWidget when recreating window caused by 0058 // reparenting to a widget with different depth, result in a mismatch 0059 // in x11info and native window. 0060 inline void 0061 QtcX11Info::fixVisual() 0062 { 0063 if (qtcUnlikely(!x11data)) 0064 setX11Data(getX11Data(true)); 0065 x11data->defaultVisual = false; 0066 x11data->defaultColormap = false; 0067 } 0068 0069 inline void 0070 QtcX11Info::setRgba() 0071 { 0072 #if 1 0073 setX11Data(getInfo(rgbaDummy())->x11data); 0074 #else 0075 // It seems that VirtualBox is doing something special to Qt so that 0076 // a TranslucentBackground Widget will NOT have a related 32bit window. 0077 // The following code enables translucent background in Virtualbox by 0078 // setting rgba visual on the widget anyway. However, this breaks 0079 // the display of the virtual machine. Since Gammaray does not work either 0080 // on VirtualBox, it is hard to figure out what is wrong and which are 0081 // the widgets need to be blacklist. Disable the code for now unless a 0082 // workaround is found. 0083 QX11InfoData *xd = getX11Data(true); 0084 xd->visual = qtcX11RgbaVisual(&xd->colormap, &xd->cells, xd->screen); 0085 xd->depth = 32; 0086 xd->defaultVisual = false; 0087 xd->defaultColormap = false; 0088 setX11Data(xd); 0089 #endif 0090 } 0091 0092 inline QWidget* 0093 QtcX11Info::rgbaDummy() 0094 { 0095 QDesktopWidget *desktop = qApp->desktop(); 0096 static std::vector<QWidget*> dummies(desktop->screenCount(), nullptr); 0097 int scrno = screen(); 0098 if (qtcUnlikely(!dummies[scrno])) { 0099 creatingDummy = true; 0100 dummies[scrno] = new QWidget(desktop->screen(scrno)); 0101 dummies[scrno]->setAttribute(Qt::WA_TranslucentBackground); 0102 dummies[scrno]->setAttribute(Qt::WA_WState_Polished); 0103 dummies[scrno]->winId(); 0104 creatingDummy = false; 0105 } 0106 return dummies[scrno]; 0107 } 0108 0109 void 0110 fixVisual(QWidget *widget) 0111 { 0112 // Don't use XCreateSimpleWindow 0113 QtcX11Info::getInfo(widget)->fixVisual(); 0114 } 0115 0116 void 0117 addAlphaChannel(QWidget *widget) 0118 { 0119 QtcX11Info::getInfo(widget)->setRgba(); 0120 } 0121 #else 0122 void 0123 fixVisual(QWidget*) 0124 { 0125 } 0126 0127 void 0128 addAlphaChannel(QWidget*) 0129 { 0130 } 0131 #endif 0132 0133 }