mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
mobileshell: Move KWayland related window functions to utility class
This commit is contained in:
parent
5e807a555b
commit
f861e2df3f
11 changed files with 255 additions and 182 deletions
|
|
@ -12,6 +12,7 @@ set(mobileshellplugin_SRCS
|
|||
savedquicksettings.cpp
|
||||
savedquicksettingsmodel.cpp
|
||||
shellutil.cpp
|
||||
windowutil.cpp
|
||||
notifications/notificationthumbnailer.cpp
|
||||
notifications/notificationfilemenu.cpp
|
||||
homescreen/applicationlistmodel.cpp
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
// Self
|
||||
#include "applicationlistmodel.h"
|
||||
#include "../windowutil.h"
|
||||
|
||||
// Qt
|
||||
#include <QByteArray>
|
||||
|
|
@ -36,12 +37,12 @@ constexpr int MAX_FAVOURITES = 5;
|
|||
|
||||
ApplicationListModel::ApplicationListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
// m_applet(parent)
|
||||
{
|
||||
connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged), this, &ApplicationListModel::sycocaDbChanged);
|
||||
|
||||
connect(WindowUtil::instance(), &WindowUtil::windowCreated, this, &ApplicationListModel::windowCreated);
|
||||
|
||||
loadSettings();
|
||||
initWayland();
|
||||
}
|
||||
|
||||
ApplicationListModel::~ApplicationListModel() = default;
|
||||
|
|
@ -94,59 +95,38 @@ void ApplicationListModel::sycocaDbChanged(const QStringList &changes)
|
|||
loadApplications();
|
||||
}
|
||||
|
||||
void ApplicationListModel::windowCreated(KWayland::Client::PlasmaWindow *window)
|
||||
{
|
||||
if (window->appId() == QStringLiteral("org.kde.plasmashell")) {
|
||||
return;
|
||||
}
|
||||
int idx = 0;
|
||||
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
|
||||
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
|
||||
(*i).window = window;
|
||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||
connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window]() {
|
||||
int idx = 0;
|
||||
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
|
||||
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
|
||||
(*i).window = nullptr;
|
||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
bool appNameLessThan(const ApplicationListModel::ApplicationData &a1, const ApplicationListModel::ApplicationData &a2)
|
||||
{
|
||||
return a1.name.compare(a2.name, Qt::CaseInsensitive) < 0;
|
||||
}
|
||||
|
||||
void ApplicationListModel::initWayland()
|
||||
{
|
||||
if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
|
||||
return;
|
||||
}
|
||||
using namespace KWayland::Client;
|
||||
ConnectionThread *connection = ConnectionThread::fromApplication(this);
|
||||
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
auto *registry = new Registry(this);
|
||||
registry->create(connection);
|
||||
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
||||
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
|
||||
qRegisterMetaType<QVector<int>>("QVector<int>");
|
||||
|
||||
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated, this, [this](KWayland::Client::PlasmaWindow *window) {
|
||||
if (window->appId() == QStringLiteral("org.kde.plasmashell")) {
|
||||
return;
|
||||
}
|
||||
int idx = 0;
|
||||
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
|
||||
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
|
||||
(*i).window = window;
|
||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||
connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window]() {
|
||||
int idx = 0;
|
||||
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
|
||||
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
|
||||
(*i).window = nullptr;
|
||||
emit dataChanged(index(idx, 0), index(idx, 0));
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
registry->setup();
|
||||
connection->roundtrip();
|
||||
}
|
||||
|
||||
void ApplicationListModel::loadApplications()
|
||||
{
|
||||
auto cfg = KSharedConfig::openConfig(QStringLiteral("applications-blacklistrc"));
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ public:
|
|||
|
||||
public Q_SLOTS:
|
||||
void sycocaDbChanged(const QStringList &change);
|
||||
void windowCreated(KWayland::Client::PlasmaWindow *window);
|
||||
|
||||
Q_SIGNALS:
|
||||
void countChanged();
|
||||
|
|
@ -128,11 +129,8 @@ Q_SIGNALS:
|
|||
void launchError(const QString &msg);
|
||||
|
||||
protected:
|
||||
void initWayland();
|
||||
|
||||
QList<ApplicationData> m_applicationList;
|
||||
|
||||
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
|
||||
PlasmaQuick::AppletQuickItem *m_applet = nullptr;
|
||||
int m_maxFavoriteCount = 0;
|
||||
QStringList m_appOrder;
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@
|
|||
#include "homescreen/favoritesmodel.h"
|
||||
#include "homescreen/homescreenutils.h"
|
||||
|
||||
#include "taskswitcher/displaysmodel.h"
|
||||
|
||||
#include "mobileshellsettings.h"
|
||||
#include "quicksetting.h"
|
||||
#include "quicksettingsmodel.h"
|
||||
#include "shellutil.h"
|
||||
#include "taskswitcher/displaysmodel.h"
|
||||
#include "windowutil.h"
|
||||
|
||||
QUrl resolvePath(std::string str)
|
||||
{
|
||||
|
|
@ -43,6 +45,9 @@ void MobileShellPlugin::registerTypes(const char *uri)
|
|||
qmlRegisterType<QuickSettingsModel>(uri, 1, 0, "QuickSettingsModel");
|
||||
qmlRegisterType<SavedQuickSettings>(uri, 1, 0, "SavedQuickSettings");
|
||||
qmlRegisterType<SavedQuickSettingsModel>(uri, 1, 0, "SavedQuickSettingsModel");
|
||||
qmlRegisterSingletonType<WindowUtil>(uri, 1, 0, "WindowUtil", [](QQmlEngine *, QJSEngine *) -> QObject * {
|
||||
return WindowUtil::instance();
|
||||
});
|
||||
|
||||
// taskswitcher
|
||||
qmlRegisterType<DisplaysModel>(uri, 1, 0, "DisplaysModel");
|
||||
|
|
|
|||
145
components/mobileshell/windowutil.cpp
Normal file
145
components/mobileshell/windowutil.cpp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "windowutil.h"
|
||||
|
||||
#include <QGuiApplication>
|
||||
|
||||
constexpr int ACTIVE_WINDOW_UPDATE_INVERVAL = 250;
|
||||
|
||||
WindowUtil::WindowUtil(QObject *parent)
|
||||
: QObject{parent}
|
||||
, m_activeWindowTimer{new QTimer{this}}
|
||||
{
|
||||
m_activeWindowTimer->setSingleShot(true);
|
||||
m_activeWindowTimer->setInterval(ACTIVE_WINDOW_UPDATE_INVERVAL);
|
||||
connect(m_activeWindowTimer, &QTimer::timeout, this, &WindowUtil::updateActiveWindow);
|
||||
|
||||
initWayland();
|
||||
}
|
||||
|
||||
WindowUtil *WindowUtil::instance()
|
||||
{
|
||||
static WindowUtil *inst = new WindowUtil();
|
||||
return inst;
|
||||
}
|
||||
|
||||
bool WindowUtil::isShowingDesktop() const
|
||||
{
|
||||
return m_showingDesktop;
|
||||
}
|
||||
|
||||
bool WindowUtil::allWindowsMinimized() const
|
||||
{
|
||||
return m_allWindowsMinimized;
|
||||
}
|
||||
|
||||
void WindowUtil::initWayland()
|
||||
{
|
||||
if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
|
||||
return;
|
||||
}
|
||||
|
||||
using namespace KWayland::Client;
|
||||
ConnectionThread *connection = ConnectionThread::fromApplication(this);
|
||||
|
||||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *registry = new Registry(this);
|
||||
registry->create(connection);
|
||||
|
||||
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
||||
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
|
||||
qRegisterMetaType<QVector<int>>("QVector<int>");
|
||||
|
||||
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated, this, [this](KWayland::Client::PlasmaWindow *window) {
|
||||
Q_EMIT windowCreated(window);
|
||||
});
|
||||
|
||||
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, &WindowUtil::updateShowingDesktop);
|
||||
connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, m_activeWindowTimer, qOverload<>(&QTimer::start));
|
||||
|
||||
m_activeWindowTimer->start();
|
||||
});
|
||||
|
||||
registry->setup();
|
||||
connection->roundtrip();
|
||||
}
|
||||
|
||||
void WindowUtil::updateActiveWindow()
|
||||
{
|
||||
if (!m_windowManagement || m_activeWindow == m_windowManagement->activeWindow()) {
|
||||
return;
|
||||
}
|
||||
|
||||
using namespace KWayland::Client;
|
||||
if (m_activeWindow) {
|
||||
disconnect(m_activeWindow.data(), &PlasmaWindow::closeableChanged, this, &WindowUtil::hasCloseableActiveWindowChanged);
|
||||
disconnect(m_activeWindow.data(), &PlasmaWindow::unmapped, this, &WindowUtil::forgetActiveWindow);
|
||||
}
|
||||
m_activeWindow = m_windowManagement->activeWindow();
|
||||
|
||||
if (m_activeWindow) {
|
||||
connect(m_activeWindow.data(), &PlasmaWindow::closeableChanged, this, &WindowUtil::hasCloseableActiveWindowChanged);
|
||||
connect(m_activeWindow.data(), &PlasmaWindow::unmapped, this, &WindowUtil::forgetActiveWindow);
|
||||
}
|
||||
|
||||
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_allWindowsMinimized) {
|
||||
m_allWindowsMinimized = newAllMinimized;
|
||||
Q_EMIT allWindowsMinimizedChanged();
|
||||
}
|
||||
// TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable
|
||||
Q_EMIT hasCloseableActiveWindowChanged();
|
||||
}
|
||||
|
||||
bool WindowUtil::hasCloseableActiveWindow() const
|
||||
{
|
||||
return m_activeWindow && m_activeWindow->isCloseable() /*&& !m_activeWindow->isMinimized()*/;
|
||||
}
|
||||
|
||||
void WindowUtil::closeActiveWindow()
|
||||
{
|
||||
if (m_activeWindow) {
|
||||
m_activeWindow->requestClose();
|
||||
}
|
||||
}
|
||||
|
||||
void WindowUtil::requestShowingDesktop(bool showingDesktop)
|
||||
{
|
||||
if (!m_windowManagement) {
|
||||
return;
|
||||
}
|
||||
m_windowManagement->setShowingDesktop(showingDesktop);
|
||||
}
|
||||
|
||||
void WindowUtil::updateShowingDesktop(bool showing)
|
||||
{
|
||||
if (showing != m_showingDesktop) {
|
||||
m_showingDesktop = showing;
|
||||
Q_EMIT showingDesktopChanged(m_showingDesktop);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowUtil::forgetActiveWindow()
|
||||
{
|
||||
using namespace KWayland::Client;
|
||||
if (m_activeWindow) {
|
||||
disconnect(m_activeWindow.data(), &PlasmaWindow::closeableChanged, this, &WindowUtil::hasCloseableActiveWindowChanged);
|
||||
disconnect(m_activeWindow.data(), &PlasmaWindow::unmapped, this, &WindowUtil::forgetActiveWindow);
|
||||
}
|
||||
m_activeWindow.clear();
|
||||
Q_EMIT hasCloseableActiveWindowChanged();
|
||||
}
|
||||
59
components/mobileshell/windowutil.h
Normal file
59
components/mobileshell/windowutil.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2022 Devin Lin <devin@kde.org>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
#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>
|
||||
|
||||
class WindowUtil : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
|
||||
Q_PROPERTY(bool allWindowsMinimized READ allWindowsMinimized NOTIFY allWindowsMinimizedChanged)
|
||||
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
|
||||
|
||||
public:
|
||||
WindowUtil(QObject *parent = nullptr);
|
||||
static WindowUtil *instance();
|
||||
|
||||
bool isShowingDesktop() const;
|
||||
bool allWindowsMinimized() const;
|
||||
|
||||
bool hasCloseableActiveWindow() const;
|
||||
Q_INVOKABLE void closeActiveWindow();
|
||||
Q_INVOKABLE void requestShowingDesktop(bool showingDesktop);
|
||||
|
||||
Q_SIGNALS:
|
||||
void windowCreated(KWayland::Client::PlasmaWindow *window);
|
||||
void showingDesktopChanged(bool showingDesktop);
|
||||
void allWindowsMinimizedChanged();
|
||||
void hasCloseableActiveWindowChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
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;
|
||||
bool m_allWindowsMinimized;
|
||||
};
|
||||
|
|
@ -104,7 +104,6 @@ Repeater {
|
|||
|
||||
onLaunch: (x, y, icon, title) => {
|
||||
if (icon !== "") {
|
||||
print(delegate.iconItem)
|
||||
MobileShell.HomeScreenControls.openAppLaunchAnimation(
|
||||
icon,
|
||||
title,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
|||
|
||||
MobileShell.NavigationPanel {
|
||||
id: root
|
||||
property bool appIsShown: !plasmoid.nativeInterface.allMinimized
|
||||
property bool appIsShown: !MobileShell.WindowUtil.allWindowsMinimized
|
||||
|
||||
// background is:
|
||||
// - opaque if an app is shown or vkbd is shown
|
||||
|
|
@ -48,7 +48,7 @@ MobileShell.NavigationPanel {
|
|||
iconSizeFactor: 0.75
|
||||
|
||||
onTriggered: {
|
||||
plasmoid.nativeInterface.showDesktop = false;
|
||||
MobileShell.WindowUtil.showDesktop = false;
|
||||
|
||||
if (!root.taskSwitcher.visible) {
|
||||
root.taskSwitcher.show(true);
|
||||
|
|
@ -74,7 +74,7 @@ MobileShell.NavigationPanel {
|
|||
|
||||
onTriggered: {
|
||||
MobileShell.HomeScreenControls.openHomeScreen();
|
||||
plasmoid.nativeInterface.allMinimizedChanged();
|
||||
MobileShell.WindowUtil.allWindowsMinimizedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ MobileShell.NavigationPanel {
|
|||
rightAction: MobileShell.NavigationPanelAction {
|
||||
id: closeAppAction
|
||||
|
||||
enabled: Keyboards.KWinVirtualKeyboard.visible || root.taskSwitcher.visible || plasmoid.nativeInterface.hasCloseableActiveWindow
|
||||
enabled: Keyboards.KWinVirtualKeyboard.visible || root.taskSwitcher.visible || MobileShell.WindowUtil.hasCloseableActiveWindow
|
||||
iconSource: Keyboards.KWinVirtualKeyboard.visible ? "go-down-symbolic" : "mobile-close-app"
|
||||
// mobile-close-app (from plasma-frameworks) seems to have less margins than icons from breeze-icons
|
||||
iconSizeFactor: Keyboards.KWinVirtualKeyboard.visible ? 1 : 0.75
|
||||
|
|
@ -96,7 +96,7 @@ MobileShell.NavigationPanel {
|
|||
let indexToClose = root.taskSwitcher.tasksModel.index(root.taskSwitcher.currentTaskIndex, 0);
|
||||
root.taskSwitcher.tasksModel.requestClose(indexToClose);
|
||||
|
||||
} else if (plasmoid.nativeInterface.hasCloseableActiveWindow) {
|
||||
} else if (MobileShell.WindowUtil.hasCloseableActiveWindow) {
|
||||
// if task switcher is closed, but there is an active window
|
||||
if (root.taskSwitcher.tasksModel.activeTask !== 0) {
|
||||
root.taskSwitcher.tasksModel.requestClose(root.taskSwitcher.tasksModel.activeTask);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ PlasmaCore.ColorScope {
|
|||
width: 360
|
||||
|
||||
// contrasting colour
|
||||
colorGroup: !plasmoid.nativeInterface.allMinimized ? PlasmaCore.Theme.NormalColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
|
||||
colorGroup: !MobileShell.WindowUtil.allWindowsMinimized ? PlasmaCore.Theme.NormalColorGroup : PlasmaCore.Theme.ComplementaryColorGroup
|
||||
|
||||
readonly property color backgroundColor: PlasmaCore.ColorScope.backgroundColor
|
||||
|
||||
|
|
@ -66,9 +66,9 @@ PlasmaCore.ColorScope {
|
|||
}
|
||||
|
||||
Connections {
|
||||
target: plasmoid.nativeInterface
|
||||
function onAllMinimizedChanged() {
|
||||
MobileShell.HomeScreenControls.homeScreenVisible = plasmoid.nativeInterface.allMinimized
|
||||
target: MobileShell.WindowUtil
|
||||
function onAllWindowsMinimizedChanged() {
|
||||
MobileShell.HomeScreenControls.homeScreenVisible = MobileShell.WindowUtil.allWindowsMinimized
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -79,9 +79,9 @@ PlasmaCore.ColorScope {
|
|||
return;
|
||||
|
||||
// ensure that Plasma sets the correct offset
|
||||
Window.window.offset = Qt.binding(() => {
|
||||
return (plasmoid.formFactor === PlasmaCore.Types.Vertical) ? MobileShell.TopPanelControls.panelHeight : MobileShell.TopPanelControls.panelWidth
|
||||
});
|
||||
//Window.window.offset = Qt.binding(() => {
|
||||
//return (plasmoid.formFactor !== PlasmaCore.Types.Vertical) ? MobileShell.TaskPanelControls.panelHeight : MobileShell.TaskPanelControls.panelWidth
|
||||
//});
|
||||
}
|
||||
|
||||
// bottom navigation panel component
|
||||
|
|
|
|||
|
|
@ -21,19 +21,10 @@
|
|||
|
||||
#include <virtualkeyboardinterface.h>
|
||||
|
||||
static const QString s_kwinService = QStringLiteral("org.kde.KWin");
|
||||
constexpr int ACTIVE_WINDOW_UPDATE_INVERVAL = 250;
|
||||
|
||||
TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
|
||||
: Plasma::Containment(parent, args)
|
||||
, m_showingDesktop(false)
|
||||
, m_windowManagement(nullptr)
|
||||
{
|
||||
setHasConfigurationInterface(true);
|
||||
m_activeTimer = new QTimer(this);
|
||||
m_activeTimer->setSingleShot(true);
|
||||
m_activeTimer->setInterval(ACTIVE_WINDOW_UPDATE_INVERVAL);
|
||||
connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow);
|
||||
initWayland();
|
||||
|
||||
qmlRegisterUncreatableType<KWayland::Client::Output>("org.kde.plasma.phone.taskpanel", 1, 0, "Output", "nope");
|
||||
|
|
@ -45,16 +36,6 @@ TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
|
|||
});
|
||||
}
|
||||
|
||||
TaskPanel::~TaskPanel() = default;
|
||||
|
||||
void TaskPanel::requestShowingDesktop(bool showingDesktop)
|
||||
{
|
||||
if (!m_windowManagement) {
|
||||
return;
|
||||
}
|
||||
m_windowManagement->setShowingDesktop(showingDesktop);
|
||||
}
|
||||
|
||||
void TaskPanel::initWayland()
|
||||
{
|
||||
if (!QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
|
||||
|
|
@ -66,22 +47,10 @@ void TaskPanel::initWayland()
|
|||
if (!connection) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto *registry = new Registry(this);
|
||||
registry->create(connection);
|
||||
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
||||
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
|
||||
qRegisterMetaType<QVector<int>>("QVector<int>");
|
||||
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, [this](bool showing) {
|
||||
if (showing == m_showingDesktop) {
|
||||
return;
|
||||
}
|
||||
m_showingDesktop = showing;
|
||||
Q_EMIT showingDesktopChanged(m_showingDesktop);
|
||||
});
|
||||
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::activeWindowChanged, m_activeTimer, qOverload<>(&QTimer::start));
|
||||
|
||||
m_activeTimer->start();
|
||||
});
|
||||
connect(registry, &Registry::plasmaShellAnnounced, this, [this, registry](quint32 name, quint32 version) {
|
||||
m_shellInterface = registry->createPlasmaShell(name, version, this);
|
||||
|
||||
|
|
@ -145,59 +114,6 @@ void TaskPanel::updatePanelVisibility()
|
|||
}
|
||||
}
|
||||
|
||||
void TaskPanel::updateActiveWindow()
|
||||
{
|
||||
if (!m_windowManagement || m_activeWindow == m_windowManagement->activeWindow()) {
|
||||
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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
Q_EMIT allMinimizedChanged();
|
||||
}
|
||||
// TODO: connect to closeableChanged, not needed right now as KWin doesn't provide this changeable
|
||||
Q_EMIT hasCloseableActiveWindowChanged();
|
||||
}
|
||||
|
||||
bool TaskPanel::hasCloseableActiveWindow() const
|
||||
{
|
||||
return m_activeWindow && m_activeWindow->isCloseable() /*&& !m_activeWindow->isMinimized()*/;
|
||||
}
|
||||
|
||||
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();
|
||||
Q_EMIT hasCloseableActiveWindowChanged();
|
||||
}
|
||||
|
||||
void TaskPanel::closeActiveWindow()
|
||||
{
|
||||
if (m_activeWindow) {
|
||||
m_activeWindow->requestClose();
|
||||
}
|
||||
}
|
||||
|
||||
K_PLUGIN_CLASS_WITH_JSON(TaskPanel, "metadata.json")
|
||||
|
||||
#include "taskpanel.moc"
|
||||
|
|
|
|||
|
|
@ -28,60 +28,30 @@ class Surface;
|
|||
class TaskPanel : public Plasma::Containment
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool showDesktop READ isShowingDesktop WRITE requestShowingDesktop NOTIFY showingDesktopChanged)
|
||||
Q_PROPERTY(bool allMinimized READ allMinimized NOTIFY allMinimizedChanged)
|
||||
Q_PROPERTY(bool hasCloseableActiveWindow READ hasCloseableActiveWindow NOTIFY hasCloseableActiveWindowChanged)
|
||||
Q_PROPERTY(QWindow *panel READ panel WRITE setPanel NOTIFY panelChanged)
|
||||
Q_PROPERTY(Plasma::Types::Location location READ location WRITE setLocation NOTIFY locationChanged)
|
||||
|
||||
public:
|
||||
TaskPanel(QObject *parent, const QVariantList &args);
|
||||
~TaskPanel() override;
|
||||
|
||||
QWindow *panel();
|
||||
void setPanel(QWindow *panel);
|
||||
|
||||
Q_INVOKABLE void setPanelHeight(qreal height);
|
||||
|
||||
Q_INVOKABLE void closeActiveWindow();
|
||||
|
||||
bool isShowingDesktop() const
|
||||
{
|
||||
return m_showingDesktop;
|
||||
}
|
||||
void requestShowingDesktop(bool showingDesktop);
|
||||
|
||||
bool allMinimized() const
|
||||
{
|
||||
return m_allMinimized;
|
||||
}
|
||||
bool hasCloseableActiveWindow() const;
|
||||
|
||||
QAbstractItemModel *outputs() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void forgetActiveWindow();
|
||||
|
||||
Q_SIGNALS:
|
||||
void showingDesktopChanged(bool);
|
||||
void hasCloseableActiveWindowChanged();
|
||||
void panelChanged();
|
||||
void allMinimizedChanged();
|
||||
void locationChanged();
|
||||
|
||||
private:
|
||||
void initWayland();
|
||||
void updateActiveWindow();
|
||||
void updatePanelVisibility();
|
||||
bool m_showingDesktop = false;
|
||||
bool m_allMinimized = true;
|
||||
QWindow *m_panel = nullptr;
|
||||
KWayland::Client::PlasmaShellSurface *m_shellSurface = nullptr;
|
||||
KWayland::Client::Surface *m_surface = nullptr;
|
||||
KWayland::Client::PlasmaShell *m_shellInterface = nullptr;
|
||||
KWayland::Client::PlasmaWindowManagement *m_windowManagement = nullptr;
|
||||
QPointer<KWayland::Client::PlasmaWindow> m_activeWindow;
|
||||
QTimer *m_activeTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in a new issue