File: fullscreenoverlay.cpp

package info (click to toggle)
plasma-nano 6.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 540 kB
  • sloc: cpp: 209; javascript: 18; makefile: 3; sh: 2
file content (104 lines) | stat: -rw-r--r-- 3,063 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 *   SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
 *
 *   SPDX-License-Identifier: LGPL-2.0-or-later
 */

#include "fullscreenoverlay.h"

#include <QStandardPaths>

#include <KX11Extras>
#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
#include <kwindowsystem.h>

#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>

FullScreenOverlay::FullScreenOverlay(QQuickWindow *parent)
    : QQuickWindow(parent)
{
    setFlags(Qt::FramelessWindowHint);
    setWindowState(Qt::WindowFullScreen);
    initWayland();
    setWindowStates(Qt::WindowFullScreen);
}

FullScreenOverlay::~FullScreenOverlay()
{
}

void FullScreenOverlay::initWayland()
{
    if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
        return;
    }
    using namespace KWayland::Client;
    ConnectionThread *connection = ConnectionThread::fromApplication(this);
    if (!connection) {
        return;
    }
    Registry *registry = new Registry(this);
    registry->create(connection);

    m_surface = Surface::fromWindow(this);
    if (!m_surface) {
        return;
    }
    connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
        m_plasmaShellInterface = registry->createPlasmaShell(name, version, this);

        m_plasmaShellSurface = m_plasmaShellInterface->createSurface(m_surface, this);
        m_plasmaShellSurface->setSkipTaskbar(true);
    });

    registry->setup();
    connection->roundtrip();
    // HACK: why the first time is shown fullscreen won't work?
    showFullScreen();
    hide();
}

bool FullScreenOverlay::event(QEvent *e)
{
    if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut) {
        emit activeChanged();
    } else if (e->type() == QEvent::PlatformSurface) {
        QPlatformSurfaceEvent *pe = static_cast<QPlatformSurfaceEvent *>(e);

        if (pe->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
            if (m_plasmaShellSurface) {
                m_plasmaShellSurface->setSkipTaskbar(true);
            }

            if (!m_acceptsFocus) {
                setFlags(flags() | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
            } else {
                setFlags(flags() | Qt::FramelessWindowHint);
            }
        }
    } else if (e->type() == QEvent::Show) {
        if (m_plasmaShellSurface) {
            m_plasmaShellSurface->setSkipTaskbar(true);
        }
    } else if (e->type() == QEvent::Expose) {
        if (KWindowSystem::isPlatformX11()) {
            KX11Extras::setState(winId(), NET::SkipTaskbar | NET::SkipPager);
        } else {
            if (m_plasmaShellSurface) {
                m_plasmaShellSurface->setSkipTaskbar(true);
                m_plasmaShellSurface->setSkipSwitcher(true);
            }
        }
    }

    return QQuickWindow::event(e);
}

#include "fullscreenoverlay.moc"

#include "moc_fullscreenoverlay.cpp"