File indexing completed on 2025-03-23 05:05:55
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "fullscreenoverlay.h" 0008 0009 #include <QStandardPaths> 0010 0011 #include <KX11Extras> 0012 #include <QDebug> 0013 #include <QGuiApplication> 0014 #include <QScreen> 0015 #include <kwindowsystem.h> 0016 0017 #include <KWayland/Client/connection_thread.h> 0018 #include <KWayland/Client/plasmashell.h> 0019 #include <KWayland/Client/registry.h> 0020 #include <KWayland/Client/surface.h> 0021 0022 FullScreenOverlay::FullScreenOverlay(QQuickWindow *parent) 0023 : QQuickWindow(parent) 0024 { 0025 setFlags(Qt::FramelessWindowHint); 0026 setWindowState(Qt::WindowFullScreen); 0027 initWayland(); 0028 setWindowStates(Qt::WindowFullScreen); 0029 } 0030 0031 FullScreenOverlay::~FullScreenOverlay() 0032 { 0033 } 0034 0035 void FullScreenOverlay::initWayland() 0036 { 0037 if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) { 0038 return; 0039 } 0040 using namespace KWayland::Client; 0041 ConnectionThread *connection = ConnectionThread::fromApplication(this); 0042 if (!connection) { 0043 return; 0044 } 0045 Registry *registry = new Registry(this); 0046 registry->create(connection); 0047 0048 m_surface = Surface::fromWindow(this); 0049 if (!m_surface) { 0050 return; 0051 } 0052 connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) { 0053 m_plasmaShellInterface = registry->createPlasmaShell(name, version, this); 0054 0055 m_plasmaShellSurface = m_plasmaShellInterface->createSurface(m_surface, this); 0056 m_plasmaShellSurface->setSkipTaskbar(true); 0057 }); 0058 0059 registry->setup(); 0060 connection->roundtrip(); 0061 // HACK: why the first time is shown fullscreen won't work? 0062 showFullScreen(); 0063 hide(); 0064 } 0065 0066 bool FullScreenOverlay::event(QEvent *e) 0067 { 0068 if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut) { 0069 emit activeChanged(); 0070 } else if (e->type() == QEvent::PlatformSurface) { 0071 QPlatformSurfaceEvent *pe = static_cast<QPlatformSurfaceEvent *>(e); 0072 0073 if (pe->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) { 0074 if (m_plasmaShellSurface) { 0075 m_plasmaShellSurface->setSkipTaskbar(true); 0076 } 0077 0078 if (!m_acceptsFocus) { 0079 setFlags(flags() | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus); 0080 } else { 0081 setFlags(flags() | Qt::FramelessWindowHint); 0082 } 0083 } 0084 } else if (e->type() == QEvent::Show) { 0085 if (m_plasmaShellSurface) { 0086 m_plasmaShellSurface->setSkipTaskbar(true); 0087 } 0088 } else if (e->type() == QEvent::Expose) { 0089 if (KWindowSystem::isPlatformX11()) { 0090 KX11Extras::setState(winId(), NET::SkipTaskbar | NET::SkipPager); 0091 } else { 0092 if (m_plasmaShellSurface) { 0093 m_plasmaShellSurface->setSkipTaskbar(true); 0094 m_plasmaShellSurface->setSkipSwitcher(true); 0095 } 0096 } 0097 } 0098 0099 return QQuickWindow::event(e); 0100 } 0101 0102 #include "fullscreenoverlay.moc"