2022-04-06 21:18:20 +00:00
|
|
|
/*
|
2022-04-07 14:52:12 +00:00
|
|
|
* SPDX-FileCopyrightText: 2014 Antonis Tsiapaliokas <antonis.tsiapaliokas@kde.org>
|
2022-04-06 21:18:20 +00:00
|
|
|
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QPointer>
|
2022-04-11 20:19:16 +00:00
|
|
|
#include <QQuickItem>
|
|
|
|
|
#include <QQuickWindow>
|
2022-04-06 21:18:20 +00:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
2022-04-07 14:52:12 +00:00
|
|
|
/**
|
|
|
|
|
* Utility class that provides useful functions related to windows and KWin+KWayland.
|
|
|
|
|
*
|
2022-04-11 15:55:56 +00:00
|
|
|
* TODO: Add per-screen support
|
|
|
|
|
*
|
2022-04-07 14:52:12 +00:00
|
|
|
* @author Devin Lin <devin@kde.org>
|
|
|
|
|
**/
|
2022-04-06 21:18:20 +00:00
|
|
|
class WindowUtil : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
|
|
|
|
|
Q_PROPERTY(bool allWindowsMinimized READ allWindowsMinimized NOTIFY allWindowsMinimizedChanged)
|
2022-04-07 01:18:47 +00:00
|
|
|
Q_PROPERTY(bool allWindowsMinimizedExcludingShell READ allWindowsMinimizedExcludingShell NOTIFY allWindowsMinimizedExcludingShellChanged)
|
2022-04-06 21:18:20 +00:00
|
|
|
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
|
2022-04-06 21:59:36 +00:00
|
|
|
Q_PROPERTY(bool activeWindowIsShell READ activeWindowIsShell NOTIFY activeWindowIsShellChanged)
|
2022-04-06 21:18:20 +00:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
WindowUtil(QObject *parent = nullptr);
|
|
|
|
|
static WindowUtil *instance();
|
|
|
|
|
|
2022-04-07 01:18:47 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the shell is in "desktop showing" mode, where all windows
|
|
|
|
|
* are moved aside.
|
|
|
|
|
*/
|
2022-04-06 21:18:20 +00:00
|
|
|
bool isShowingDesktop() const;
|
2022-04-07 01:18:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether all windows are minimized, including shell windows.
|
|
|
|
|
*/
|
2022-04-06 21:18:20 +00:00
|
|
|
bool allWindowsMinimized() const;
|
2022-04-07 01:18:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether all windows are minimized, ignoring shell windows.
|
|
|
|
|
*/
|
|
|
|
|
bool allWindowsMinimizedExcludingShell() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the active window being shown is a shell window.
|
|
|
|
|
*/
|
2022-04-06 21:59:36 +00:00
|
|
|
bool activeWindowIsShell() const;
|
2022-04-06 21:18:20 +00:00
|
|
|
|
2022-04-07 01:18:47 +00:00
|
|
|
/**
|
|
|
|
|
* Whether the current active window can be closed.
|
|
|
|
|
*/
|
2022-04-06 21:18:20 +00:00
|
|
|
bool hasCloseableActiveWindow() const;
|
2022-04-07 01:18:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Close the current active window.
|
|
|
|
|
*/
|
2022-04-06 21:18:20 +00:00
|
|
|
Q_INVOKABLE void closeActiveWindow();
|
2022-04-07 01:18:47 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle whether we are in the "desktop showing" mode.
|
2022-04-07 14:52:12 +00:00
|
|
|
*
|
|
|
|
|
* @param showingDesktop Whether "desktop showing" mode should be enabled.
|
2022-04-07 01:18:47 +00:00
|
|
|
*/
|
2022-04-06 21:18:20 +00:00
|
|
|
Q_INVOKABLE void requestShowingDesktop(bool showingDesktop);
|
|
|
|
|
|
2022-04-11 20:19:16 +00:00
|
|
|
/**
|
2022-04-11 20:47:20 +00:00
|
|
|
* Minimize all windows.
|
|
|
|
|
*/
|
|
|
|
|
Q_INVOKABLE void minimizeAll();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unset minimized geometries of all windows for an item's window.
|
2022-04-11 20:19:16 +00:00
|
|
|
*
|
|
|
|
|
* @param parent The parent item, which is of the same window that will have geometries unset.
|
|
|
|
|
*/
|
2022-04-11 20:47:20 +00:00
|
|
|
Q_INVOKABLE void unsetAllMinimizedGeometries(QQuickItem *parent);
|
2022-04-11 20:19:16 +00:00
|
|
|
|
2022-04-06 21:18:20 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
|
void windowCreated(KWayland::Client::PlasmaWindow *window);
|
|
|
|
|
void showingDesktopChanged(bool showingDesktop);
|
|
|
|
|
void allWindowsMinimizedChanged();
|
2022-04-07 01:18:47 +00:00
|
|
|
void allWindowsMinimizedExcludingShellChanged();
|
2022-04-06 21:18:20 +00:00
|
|
|
void hasCloseableActiveWindowChanged();
|
2022-04-06 21:59:36 +00:00
|
|
|
void activeWindowChanged();
|
|
|
|
|
void activeWindowIsShellChanged();
|
2022-04-06 21:18:20 +00:00
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2022-04-06 21:59:36 +00:00
|
|
|
void updateActiveWindowIsShell();
|
2022-04-06 21:18:20 +00:00
|
|
|
void forgetActiveWindow();
|
|
|
|
|
void updateShowingDesktop(bool showing);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void initWayland();
|
|
|
|
|
void updateActiveWindow();
|
|
|
|
|
|
|
|
|
|
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
|
|
|
|
|
QPointer<KWayland::Client::PlasmaWindow> m_activeWindow;
|
|
|
|
|
QTimer *m_activeWindowTimer;
|
|
|
|
|
|
|
|
|
|
bool m_showingDesktop = false;
|
2022-04-06 21:59:36 +00:00
|
|
|
bool m_allWindowsMinimized = true;
|
2022-04-07 01:18:47 +00:00
|
|
|
bool m_allWindowsMinimizedExcludingShell = true;
|
2022-04-06 21:59:36 +00:00
|
|
|
bool m_activeWindowIsShell = false;
|
2022-04-06 21:18:20 +00:00
|
|
|
};
|