File indexing completed on 2024-04-28 16:52:28

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