fullscreenoverlay.cpp 3.01 KB
Newer Older
1
2
3
4
5
/*
 *   SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
 *
 *   SPDX-License-Identifier: LGPL-2.0-or-later
 */
6

7
#include "fullscreenoverlay.h"
8
9
10
11
12

#include <QStandardPaths>

#include <QDebug>
#include <QGuiApplication>
Marco Martin's avatar
Marco Martin committed
13
#include <QScreen>
14
15
16
17
18
19
20
#include <kwindowsystem.h>

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

21
FullScreenOverlay::FullScreenOverlay(QQuickWindow *parent)
22
23
24
25
    : QQuickWindow(parent)
{
    setFlags(Qt::FramelessWindowHint);
    setWindowState(Qt::WindowFullScreen);
Alexander Lohnau's avatar
Alexander Lohnau committed
26
    // connect(this, &FullScreenOverlay::activeFocusItemChanged, this, [this]() {qWarning()<<"hide()";});
27
    initWayland();
28
    setWindowStates(Qt::WindowFullScreen);
29
30
}

31
FullScreenOverlay::~FullScreenOverlay()
32
33
34
{
}

35
void FullScreenOverlay::initWayland()
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{
    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;
    }
Alexander Lohnau's avatar
Alexander Lohnau committed
52
53
    connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
        m_plasmaShellInterface = registry->createPlasmaShell(name, version, this);
54

Alexander Lohnau's avatar
Alexander Lohnau committed
55
56
57
        m_plasmaShellSurface = m_plasmaShellInterface->createSurface(m_surface, this);
        m_plasmaShellSurface->setSkipTaskbar(true);
    });
58
59
60

    registry->setup();
    connection->roundtrip();
Alexander Lohnau's avatar
Alexander Lohnau committed
61
    // HACK: why the first time is shown fullscreen won't work?
Marco Martin's avatar
Marco Martin committed
62
63
    showFullScreen();
    hide();
64
65
}

66
bool FullScreenOverlay::event(QEvent *e)
Marco Martin's avatar
Marco Martin committed
67
{
Marco Martin's avatar
Marco Martin committed
68
69
70
    if (e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut) {
        emit activeChanged();
    } else if (e->type() == QEvent::PlatformSurface) {
Alexander Lohnau's avatar
Alexander Lohnau committed
71
        QPlatformSurfaceEvent *pe = static_cast<QPlatformSurfaceEvent *>(e);
Marco Martin's avatar
Marco Martin committed
72
73

        if (pe->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated) {
Alexander Lohnau's avatar
Alexander Lohnau committed
74
75
            // KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager | NET::FullScreen);
            // setWindowStates(Qt::WindowFullScreen);
Marco Martin's avatar
Marco Martin committed
76
77
78
79
            if (m_plasmaShellSurface) {
                m_plasmaShellSurface->setSkipTaskbar(true);
            }

Marco Martin's avatar
Marco Martin committed
80
            if (!m_acceptsFocus) {
Alexander Lohnau's avatar
Alexander Lohnau committed
81
82
                setFlags(flags() | Qt::FramelessWindowHint | Qt::WindowDoesNotAcceptFocus);
                // KWindowSystem::setType(winId(), NET::Dock);
Marco Martin's avatar
Marco Martin committed
83
            } else {
Marco Martin's avatar
Marco Martin committed
84
                setFlags(flags() | Qt::FramelessWindowHint);
Marco Martin's avatar
Marco Martin committed
85
            }
Marco Martin's avatar
Marco Martin committed
86
        }
Marco Martin's avatar
Marco Martin committed
87
88
89
90
    } else if (e->type() == QEvent::Show) {
        if (m_plasmaShellSurface) {
            m_plasmaShellSurface->setSkipTaskbar(true);
        }
91
92
    } else if (e->type() == QEvent::Expose) {
        KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager);
Marco Martin's avatar
Marco Martin committed
93
94
95
96
97
    }

    return QQuickWindow::event(e);
}

98
#include "fullscreenoverlay.moc"