File: activationtest.cpp

package info (click to toggle)
kf6-kwindowsystem 6.20.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,292 kB
  • sloc: cpp: 18,421; ansic: 35; makefile: 11; sh: 1
file content (47 lines) | stat: -rw-r--r-- 1,297 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
/*
    This file is part of the KDE libraries
    SPDX-FileCopyrightText: 2024 Nicolas Fella <nicolas.fella@gmx.de>

    SPDX-License-Identifier: LGPL-2.1-or-later
*/

#include <kwindowsystem.h>

#include <QApplication>
#include <QLayout>
#include <QMainWindow>
#include <QPushButton>

#include <kwaylandextras.h>

class MainWindow : public QMainWindow
{
public:
    MainWindow()
        : QMainWindow()
    {
        QMainWindow *otherWindow = new QMainWindow(this);
        otherWindow->show();
        otherWindow->setWindowState(Qt::WindowMinimized);

        QPushButton *pushButton = new QPushButton(otherWindow);
        pushButton->setText("Raise other");
        layout()->addWidget(pushButton);

        connect(pushButton, &QPushButton::clicked, this, [this, otherWindow] {
            KWaylandExtras::xdgActivationToken(windowHandle(), KWaylandExtras::lastInputSerial(windowHandle()), QString())
                .then(otherWindow, [otherWindow](const QString &token) {
                    KWindowSystem::setCurrentXdgActivationToken(token);
                    KWindowSystem::activateWindow(otherWindow->windowHandle());
                });
        });
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
}