File: windowsystem.cpp

package info (click to toggle)
plasma-workspace 4%3A6.3.6-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 104,900 kB
  • sloc: cpp: 125,434; xml: 31,579; python: 3,976; perl: 572; sh: 234; javascript: 74; ruby: 39; ansic: 13; makefile: 9
file content (81 lines) | stat: -rw-r--r-- 1,701 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
/*
    SPDX-FileCopyrightText: 2014 Eike Hein <hein@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "windowsystem.h"

#include <QQuickItem>

#include <KWindowSystem>
#include <KX11Extras>

WindowSystem::WindowSystem(QObject *parent)
    : QObject(parent)
{
}

WindowSystem::~WindowSystem()
{
}

bool WindowSystem::eventFilter(QObject *watched, QEvent *event)
{
    if (event->type() == QEvent::FocusIn) {
        removeEventFilter(watched);
        Q_EMIT focusIn(qobject_cast<QQuickWindow *>(watched));
    }

    return false;
}

void WindowSystem::forceActive(QQuickItem *item)
{
    if (item) {
        if (auto window = item->window()) {
            KX11Extras::forceActiveWindow(window->winId());
        }
    }
}

bool WindowSystem::isActive(QQuickItem *item)
{
    if (item) {
        if (auto window = item->window()) {
            return window->isActive();
        }
    }

    return false;
}

void WindowSystem::monitorWindowFocus(QQuickItem *item)
{
    if (item) {
        if (auto window = item->window()) {
            window->installEventFilter(this);
        }
    }
}

void WindowSystem::monitorWindowVisibility(QQuickItem *item)
{
    if (item) {
        if (auto window = item->window()) {
            connect(window, &QQuickWindow::visibilityChanged, this, &WindowSystem::monitoredWindowVisibilityChanged, Qt::UniqueConnection);
        }
    }
}

void WindowSystem::monitoredWindowVisibilityChanged(QWindow::Visibility visibility) const
{
    const bool visible = (visibility != QWindow::Hidden);
    QQuickWindow *w = static_cast<QQuickWindow *>(QObject::sender());

    if (!visible) {
        Q_EMIT hidden(w);
    }
}

#include "moc_windowsystem.cpp"