File indexing completed on 2024-04-28 05:47:26
0001 /***************************************************************************** 0002 * Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com> * 0003 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU Lesser General Public License as * 0007 * published by the Free Software Foundation; either version 2.1 of the * 0008 * License, or (at your option) version 3, or any later version accepted * 0009 * by the membership of KDE e.V. (or its successor approved by the * 0010 * membership of KDE e.V.), which shall act as a proxy defined in * 0011 * Section 6 of version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, * 0014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 0016 * Lesser General Public License for more details. * 0017 * * 0018 * You should have received a copy of the GNU Lesser General Public * 0019 * License along with this library. If not, * 0020 * see <http://www.gnu.org/licenses/>. * 0021 *****************************************************************************/ 0022 0023 #include <qtcurve-utils/log.h> 0024 #include "utils.h" 0025 #include <qtcurve-utils/x11utils.h> 0026 #include <qtcurve-utils/qtutils.h> 0027 #include <QApplication> 0028 #include <QDesktopWidget> 0029 #include <QWindow> 0030 0031 #ifdef QTC_QT5_ENABLE_KDE 0032 # include <kwindowsystem.h> 0033 #endif 0034 0035 namespace QtCurve { 0036 namespace Utils { 0037 0038 bool 0039 compositingActive() 0040 { 0041 #ifndef QTC_QT5_ENABLE_KDE 0042 // DO NOT condition compile on QTC_ENABLE_X11. 0043 // There's no direct linkage on X11 and the following code will just do 0044 // nothing if X11 is not enabled (either at compile time or at run time). 0045 return qtcX11CompositingActive(); 0046 #else 0047 return KWindowSystem::compositingActive(); 0048 #endif 0049 } 0050 0051 static inline WId 0052 findWid(const QWidget *w) 0053 { 0054 do { 0055 WId wid = qtcGetWid(w); 0056 if (wid || w->isWindow()) { 0057 return wid; 0058 } 0059 } while ((w = w->parentWidget())); 0060 return (WId)0; 0061 } 0062 0063 static QWindow* 0064 findWindowHandle(const QWidget *w) 0065 { 0066 do { 0067 QWindow *window = w->windowHandle(); 0068 if (window || w->isWindow()) { 0069 return window; 0070 } 0071 } while ((w = w->parentWidget())); 0072 return nullptr; 0073 } 0074 0075 bool 0076 hasAlphaChannel(const QWidget *widget) 0077 { 0078 if (!widget) 0079 return false; 0080 if (QWindow *window = findWindowHandle(widget)) { 0081 return window->format().alphaBufferSize() > 0; 0082 } 0083 // DO NOT condition compile on QTC_ENABLE_X11. 0084 // There's no direct linkage on X11 and the following code will just do 0085 // nothing if X11 is not enabled (either at compile time or at run time). 0086 if (qtcX11Enabled()) { 0087 if (WId wid = findWid(widget)) { 0088 return qtcX11HasAlpha(wid); 0089 } 0090 } 0091 return compositingActive(); 0092 } 0093 0094 } 0095 }