2021-03-01 20:03:25 +00:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
*/
|
2016-08-24 14:57:15 +00:00
|
|
|
|
|
|
|
|
#include "taskpanel.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QQuickItem>
|
|
|
|
|
#include <QQuickWindow>
|
|
|
|
|
#include <QtQml>
|
|
|
|
|
|
|
|
|
|
#include <KWayland/Client/connection_thread.h>
|
|
|
|
|
#include <KWayland/Client/plasmashell.h>
|
|
|
|
|
#include <KWayland/Client/plasmawindowmanagement.h>
|
|
|
|
|
#include <KWayland/Client/registry.h>
|
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
|
#include <Plasma/Package>
|
|
|
|
|
|
2021-02-24 01:05:41 +00:00
|
|
|
#include <virtualkeyboardinterface.h>
|
|
|
|
|
|
2016-08-24 14:57:15 +00:00
|
|
|
static const QString s_kwinService = QStringLiteral("org.kde.KWin");
|
2020-03-20 00:08:59 +00:00
|
|
|
constexpr int ACTIVE_WINDOW_UPDATE_INVERVAL = 250;
|
2016-08-24 14:57:15 +00:00
|
|
|
|
2021-02-24 01:05:41 +00:00
|
|
|
// helper class to expose the NOTIFY in the properties
|
|
|
|
|
class KwinVirtualKeyboardInterface : public OrgKdeKwinVirtualKeyboardInterface
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
|
|
|
|
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
2021-07-21 09:59:21 +00:00
|
|
|
Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
|
2021-02-24 01:05:41 +00:00
|
|
|
public:
|
|
|
|
|
KwinVirtualKeyboardInterface()
|
|
|
|
|
: OrgKdeKwinVirtualKeyboardInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-24 14:57:15 +00:00
|
|
|
TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
|
|
|
|
|
: Plasma::Containment(parent, args)
|
|
|
|
|
, m_showingDesktop(false)
|
|
|
|
|
, m_windowManagement(nullptr)
|
|
|
|
|
{
|
|
|
|
|
setHasConfigurationInterface(true);
|
2016-09-03 08:27:12 +00:00
|
|
|
m_activeTimer = new QTimer(this);
|
|
|
|
|
m_activeTimer->setSingleShot(true);
|
2020-03-20 00:08:59 +00:00
|
|
|
m_activeTimer->setInterval(ACTIVE_WINDOW_UPDATE_INVERVAL);
|
2016-09-03 08:27:12 +00:00
|
|
|
connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow);
|
2017-09-14 10:07:05 +00:00
|
|
|
initWayland();
|
2021-02-24 01:05:41 +00:00
|
|
|
|
|
|
|
|
qmlRegisterSingletonType<OrgKdeKwinVirtualKeyboardInterface>("org.kde.plasma.phone.taskpanel",
|
|
|
|
|
1,
|
|
|
|
|
0,
|
|
|
|
|
"KWinVirtualKeyboard",
|
|
|
|
|
[](QQmlEngine *, QJSEngine *) -> QObject * {
|
|
|
|
|
return new KwinVirtualKeyboardInterface;
|
|
|
|
|
});
|
2021-08-25 20:57:45 +00:00
|
|
|
|
|
|
|
|
connect(this, &Plasma::Containment::locationChanged, this, &TaskPanel::locationChanged);
|
|
|
|
|
connect(this, &Plasma::Containment::locationChanged, this, [this] {
|
|
|
|
|
auto l = location();
|
|
|
|
|
setFormFactor(l == Plasma::Types::LeftEdge || l == Plasma::Types::RightEdge ? Plasma::Types::Vertical : Plasma::Types::Horizontal);
|
|
|
|
|
});
|
2016-08-24 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
2020-03-20 00:08:59 +00:00
|
|
|
TaskPanel::~TaskPanel() = default;
|
2016-08-24 14:57:15 +00:00
|
|
|
|
|
|
|
|
void TaskPanel::requestShowingDesktop(bool showingDesktop)
|
|
|
|
|
{
|
|
|
|
|
if (!m_windowManagement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_windowManagement->setShowingDesktop(showingDesktop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::initWayland()
|
|
|
|
|
{
|
|
|
|
|
if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
ConnectionThread *connection = ConnectionThread::fromApplication(this);
|
2020-07-23 11:47:40 +00:00
|
|
|
|
2016-08-24 14:57:15 +00:00
|
|
|
if (!connection) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-03 14:19:31 +00:00
|
|
|
auto *registry = new Registry(this);
|
2016-08-24 14:57:15 +00:00
|
|
|
registry->create(connection);
|
|
|
|
|
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
|
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
|
2016-09-03 08:27:12 +00:00
|
|
|
qRegisterMetaType<QVector<int>>("QVector<int>");
|
|
|
|
|
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, [this](bool showing) {
|
2016-08-24 14:57:15 +00:00
|
|
|
if (showing == m_showingDesktop) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_showingDesktop = showing;
|
|
|
|
|
emit showingDesktopChanged(m_showingDesktop);
|
2021-03-19 07:52:22 +00:00
|
|
|
});
|
2016-08-24 14:57:15 +00:00
|
|
|
// FIXME
|
|
|
|
|
// connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow, Qt::QueuedConnection);
|
2021-03-19 07:52:22 +00:00
|
|
|
|
2016-08-24 14:57:15 +00:00
|
|
|
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged, m_activeTimer, qOverload<>(&QTimer::start));
|
2021-03-19 07:52:22 +00:00
|
|
|
|
2020-07-30 13:29:57 +00:00
|
|
|
m_activeTimer->start();
|
2021-03-19 07:52:22 +00:00
|
|
|
});
|
2016-08-24 14:57:15 +00:00
|
|
|
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
|
|
|
|
m_shellInterface = registry->createPlasmaShell(name, version, this);
|
2021-03-19 07:52:22 +00:00
|
|
|
|
2016-08-25 09:59:48 +00:00
|
|
|
if (!m_panel) {
|
|
|
|
|
return;
|
2016-08-24 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
Surface *s = Surface::fromWindow(m_panel);
|
|
|
|
|
if (!s) {
|
2021-03-19 07:52:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2016-08-24 14:57:15 +00:00
|
|
|
m_shellSurface = m_shellInterface->createSurface(s, this);
|
2016-08-25 09:59:48 +00:00
|
|
|
m_shellSurface->setSkipTaskbar(true);
|
2021-03-19 07:52:22 +00:00
|
|
|
});
|
2016-08-24 14:57:15 +00:00
|
|
|
registry->setup();
|
2017-09-14 09:41:15 +00:00
|
|
|
connection->roundtrip();
|
2016-08-24 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWindow *TaskPanel::panel()
|
|
|
|
|
{
|
|
|
|
|
return m_panel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::setPanel(QWindow *panel)
|
|
|
|
|
{
|
|
|
|
|
if (panel == m_panel) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 11:01:07 +00:00
|
|
|
if (m_panel) {
|
|
|
|
|
disconnect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility);
|
|
|
|
|
}
|
2016-08-24 14:57:15 +00:00
|
|
|
m_panel = panel;
|
2017-09-14 11:01:07 +00:00
|
|
|
connect(m_panel, &QWindow::visibilityChanged, this, &TaskPanel::updatePanelVisibility, Qt::QueuedConnection);
|
2016-08-24 14:57:15 +00:00
|
|
|
emit panelChanged();
|
2017-09-14 11:01:07 +00:00
|
|
|
updatePanelVisibility();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::updatePanelVisibility()
|
|
|
|
|
{
|
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
if (!m_panel->isVisible()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Surface *s = Surface::fromWindow(m_panel);
|
2016-08-24 14:57:15 +00:00
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-08-25 09:59:48 +00:00
|
|
|
|
2016-08-24 14:57:15 +00:00
|
|
|
m_shellSurface = m_shellInterface->createSurface(s, this);
|
2016-08-25 09:59:48 +00:00
|
|
|
if (m_shellSurface) {
|
|
|
|
|
m_shellSurface->setSkipTaskbar(true);
|
|
|
|
|
}
|
2016-08-24 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::updateActiveWindow()
|
|
|
|
|
{
|
2016-09-03 08:27:12 +00:00
|
|
|
if (!m_windowManagement || m_activeWindow == m_windowManagement->activeWindow()) {
|
2016-08-24 14:57:15 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (m_activeWindow) {
|
|
|
|
|
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
|
|
|
|
|
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
|
|
|
|
|
}
|
|
|
|
|
m_activeWindow = m_windowManagement->activeWindow();
|
|
|
|
|
|
2016-08-25 08:22:28 +00:00
|
|
|
if (m_activeWindow) {
|
|
|
|
|
connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
|
|
|
|
|
connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
|
|
|
|
|
}
|
2016-08-24 14:57:15 +00:00
|
|
|
|
2020-07-23 11:47:40 +00:00
|
|
|
bool newAllMinimized = true;
|
|
|
|
|
for (auto *w : m_windowManagement->windows()) {
|
|
|
|
|
if (!w->isMinimized() && !w->skipTaskbar() && !w->isFullscreen() /*&& w->appId() != QStringLiteral("org.kde.plasmashell")*/) {
|
|
|
|
|
newAllMinimized = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (newAllMinimized != m_allMinimized) {
|
|
|
|
|
m_allMinimized = newAllMinimized;
|
|
|
|
|
emit allMinimizedChanged();
|
|
|
|
|
}
|
2016-08-24 14:57:15 +00:00
|
|
|
// TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable
|
|
|
|
|
emit hasCloseableActiveWindowChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TaskPanel::hasCloseableActiveWindow() const
|
|
|
|
|
{
|
2016-09-03 08:27:12 +00:00
|
|
|
return m_activeWindow && m_activeWindow->isCloseable() /*&& !m_activeWindow->isMinimized()*/;
|
2016-08-24 14:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::forgetActiveWindow()
|
|
|
|
|
{
|
|
|
|
|
if (m_activeWindow) {
|
|
|
|
|
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
|
|
|
|
|
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
|
|
|
|
|
}
|
|
|
|
|
m_activeWindow.clear();
|
|
|
|
|
emit hasCloseableActiveWindowChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TaskPanel::closeActiveWindow()
|
|
|
|
|
{
|
|
|
|
|
if (m_activeWindow) {
|
|
|
|
|
m_activeWindow->requestClose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 04:52:49 +00:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(TaskPanel, "metadata.json")
|
2016-08-24 14:57:15 +00:00
|
|
|
|
|
|
|
|
#include "taskpanel.moc"
|