1 /*****************************************************************************
2 * Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com> *
3 * Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Lesser General Public License as *
7 * published by the Free Software Foundation; either version 2.1 of the *
8 * License, or (at your option) version 3, or any later version accepted *
9 * by the membership of KDE e.V. (or its successor approved by the *
10 * membership of KDE e.V.), which shall act as a proxy defined in *
11 * Section 6 of version 3 of the license. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library. If not, *
20 * see <http://www.gnu.org/licenses/>. *
21 *****************************************************************************/
22
23 #include "config.h"
24 #include <qtcurve-utils/x11utils.h>
25 #include <qtcurve-utils/log.h>
26
27 #include "utils.h"
28 #include <QDir>
29
30 #ifdef Q_WS_X11
31 # include <QX11Info>
32 #endif
33
34 #ifndef QTC_QT4_ENABLE_KDE
35 # undef KDE_IS_VERSION
36 # define KDE_IS_VERSION(A, B, C) 0
37 #else
38 # include <kdeversion.h>
39 # include <KDE/KWindowSystem>
40 #endif
41
42 namespace QtCurve {
43 namespace Utils {
44
45 bool
compositingActive()46 compositingActive()
47 {
48 #if !defined QTC_QT4_ENABLE_KDE || !KDE_IS_VERSION(4, 4, 0)
49 return qtcX11CompositingActive();
50 #else // QTC_QT4_ENABLE_KDE
51 return KWindowSystem::compositingActive();
52 #endif // QTC_QT4_ENABLE_KDE
53 }
54
55 bool
hasAlphaChannel(const QWidget * widget)56 hasAlphaChannel(const QWidget *widget)
57 {
58 QTC_RET_IF_FAIL(widget, false);
59 #ifdef Q_WS_X11
60 return widget->x11Info().depth() == 32;
61 #else
62 return compositingActive();
63 #endif
64 }
65
kdeHome()66 QString kdeHome()
67 {
68 static QString kdeHomePath;
69 if (kdeHomePath.isEmpty()) {
70 kdeHomePath = QString::fromLocal8Bit(qgetenv("KDEHOME"));
71 if (kdeHomePath.isEmpty()) {
72 const QString homePath = QDir::homePath();
73 const QDir homeDir = QDir(homePath);
74 if (homeDir.exists(QLatin1String(".kde4"))) {
75 kdeHomePath = homePath + "/.kde4";
76 } else {
77 kdeHomePath = homePath + "/.kde";
78 }
79 }
80 }
81 return kdeHomePath;
82 }
83
84 }
85 }
86