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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
|
/*
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <QObject>
#include <QPointer>
#include <QQuickItem>
#include <QQuickWindow>
#include <QTimer>
#include <qqmlregistration.h>
#include <KConfigWatcher>
#include <KSharedConfig>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>
/**
* Utility class that provides useful functions related to windows and KWin+KWayland.
*
* @author Devin Lin <devin@kde.org>
**/
class WindowUtil : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(bool isShowingDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
Q_PROPERTY(bool activeWindowIsShell READ activeWindowIsShell NOTIFY activeWindowIsShellChanged)
public:
WindowUtil(QObject *parent = nullptr);
/**
* Whether the shell is in "desktop showing" mode, where all windows
* are moved aside.
*/
bool isShowingDesktop() const;
/**
* Whether the active window being shown is a shell window.
*/
bool activeWindowIsShell() const;
/**
* Whether the current active window can be closed.
*/
bool hasCloseableActiveWindow() const;
/**
* Get the list of windows associated to a storage id.
*/
QList<KWayland::Client::PlasmaWindow *> windowsFromStorageId(const QString &storageId) const;
/**
* Activates the first window by its associated storage id.
*
* @param storageId the window's storage id
* @returns whether a window was activated
*/
Q_INVOKABLE bool activateWindowByStorageId(const QString &storageId);
/**
* Close the current active window.
*/
Q_INVOKABLE void closeActiveWindow();
/**
* Toggle whether we are in the "desktop showing" mode.
*
* @param showingDesktop Whether "desktop showing" mode should be enabled.
*/
Q_INVOKABLE void requestShowingDesktop(bool showingDesktop);
/**
* Minimize all windows.
*/
Q_INVOKABLE void minimizeAll();
/**
* Unset minimized geometries of all windows for an item's window.
*
* @param parent The parent item, which is of the same window that will have geometries unset.
*/
Q_INVOKABLE void unsetAllMinimizedGeometries(QQuickItem *parent);
Q_SIGNALS:
// Emitted when a window has been opened
void windowCreated(KWayland::Client::PlasmaWindow *window);
void showingDesktopChanged(bool showingDesktop);
void hasCloseableActiveWindowChanged();
void activeWindowChanged();
void activeWindowIsShellChanged();
// Emitted on window open or close
void windowChanged(QString storageId);
// Emitted when an application is launched
void appActivationStarted(const QString &appId, const QString &iconName);
// Emitted when an application has finished launching
void appActivationFinished(const QString &appId, const QString &iconName);
private Q_SLOTS:
void updateActiveWindowIsShell();
void forgetActiveWindow();
void updateShowingDesktop(bool showing);
void windowCreatedSlot(KWayland::Client::PlasmaWindow *window);
private:
void initWayland();
void updateActiveWindow();
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
QPointer<KWayland::Client::PlasmaWindow> m_activeWindow;
QTimer *m_activeWindowTimer;
bool m_showingDesktop = false;
bool m_activeWindowIsShell = false;
QHash<QString, QList<KWayland::Client::PlasmaWindow *>> m_windows; // <storageId, window>
};
|