File indexing completed on 2024-05-12 17:09:55
0001 /* 0002 SPDX-FileCopyrightText: 2010 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "splashwindow.h" 0008 #include "splashapp.h" 0009 0010 #include <KConfigGroup> 0011 #include <KSharedConfig> 0012 #include <QKeyEvent> 0013 #include <QMouseEvent> 0014 #include <QQmlContext> 0015 #include <QQuickItem> 0016 #include <QStandardPaths> 0017 #include <QSurfaceFormat> 0018 #include <QTimer> 0019 0020 #include <LayerShellQt/Window> 0021 0022 #include <KPackage/Package> 0023 #include <KPackage/PackageLoader> 0024 0025 #include <KWindowSystem> 0026 0027 SplashWindow::SplashWindow(bool testing, bool window, const QString &theme, QScreen *screen) 0028 : KQuickAddons::QuickViewSharedEngine() 0029 , m_stage(0) 0030 , m_testing(testing) 0031 , m_window(window) 0032 , m_theme(theme) 0033 { 0034 if (KWindowSystem::isPlatformWayland()) { 0035 if (auto layerShellWindow = LayerShellQt::Window::get(this)) { 0036 layerShellWindow->setScope(QStringLiteral("ksplashqml")); 0037 layerShellWindow->setLayer(LayerShellQt::Window::LayerOverlay); 0038 layerShellWindow->setExclusiveZone(-1); 0039 layerShellWindow->setDesiredOutput(screen); 0040 } 0041 } 0042 0043 setCursor(Qt::BlankCursor); 0044 setScreen(screen); 0045 setColor(Qt::transparent); 0046 setDefaultAlphaBuffer(true); 0047 setResizeMode(KQuickAddons::QuickViewSharedEngine::SizeRootObjectToView); 0048 0049 if (!m_window) { 0050 setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); 0051 } 0052 0053 if (!m_testing && !m_window) { 0054 if (KWindowSystem::isPlatformX11()) { 0055 // X11 specific hint only on X11 0056 setFlags(Qt::BypassWindowManagerHint); 0057 } else if (!KWindowSystem::isPlatformWayland()) { 0058 // on other platforms go fullscreen 0059 // on Wayland we cannot go fullscreen due to QTBUG 54883 0060 setWindowState(Qt::WindowFullScreen); 0061 } 0062 } 0063 0064 if (m_testing && !m_window && !KWindowSystem::isPlatformWayland()) { 0065 setWindowState(Qt::WindowFullScreen); 0066 } 0067 0068 // be sure it will be eventually closed 0069 // FIXME: should never be stuck 0070 QTimer::singleShot(30000, this, &QWindow::close); 0071 } 0072 0073 void SplashWindow::setStage(int stage) 0074 { 0075 m_stage = stage; 0076 0077 rootObject()->setProperty("stage", stage); 0078 } 0079 0080 void SplashWindow::keyPressEvent(QKeyEvent *event) 0081 { 0082 KQuickAddons::QuickViewSharedEngine::keyPressEvent(event); 0083 if (m_testing && !event->isAccepted() && event->key() == Qt::Key_Escape) { 0084 close(); 0085 } 0086 } 0087 0088 void SplashWindow::mousePressEvent(QMouseEvent *event) 0089 { 0090 KQuickAddons::QuickViewSharedEngine::mousePressEvent(event); 0091 if (m_testing && !event->isAccepted()) { 0092 close(); 0093 } 0094 } 0095 0096 void SplashWindow::setGeometry(const QRect &rect) 0097 { 0098 bool oldGeometryEmpty = geometry().isNull(); 0099 KQuickAddons::QuickViewSharedEngine::setGeometry(rect); 0100 0101 if (oldGeometryEmpty) { 0102 KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); 0103 KConfigGroup cg(KSharedConfig::openConfig(), "KDE"); 0104 const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); 0105 if (!packageName.isEmpty()) { 0106 package.setPath(packageName); 0107 } 0108 0109 if (!m_theme.isEmpty()) { 0110 package.setPath(m_theme); 0111 } 0112 0113 Q_ASSERT(package.isValid()); 0114 setSource(QUrl::fromLocalFile(package.filePath("splashmainscript"))); 0115 } 0116 }