Run clang-format

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
This commit is contained in:
Alexander Lohnau 2021-03-19 08:52:22 +01:00
parent 88ef5ea9b7
commit 854742efcc
No known key found for this signature in database
GPG key ID: 6C45BA731AA2ED36
10 changed files with 159 additions and 177 deletions

View file

@ -9,9 +9,9 @@
// Qt // Qt
#include <QByteArray> #include <QByteArray>
#include <QDebug>
#include <QModelIndex> #include <QModelIndex>
#include <QProcess> #include <QProcess>
#include <QDebug>
#include <QQuickItem> #include <QQuickItem>
#include <QQuickWindow> #include <QQuickWindow>
@ -32,11 +32,10 @@
constexpr int MAX_FAVOURITES = 5; constexpr int MAX_FAVOURITES = 5;
ApplicationListModel::ApplicationListModel(HomeScreen *parent) ApplicationListModel::ApplicationListModel(HomeScreen *parent)
: QAbstractListModel(parent), : QAbstractListModel(parent)
m_applet(parent) , m_applet(parent)
{ {
connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged), connect(KSycoca::self(), qOverload<const QStringList &>(&KSycoca::databaseChanged), this, &ApplicationListModel::sycocaDbChanged);
this, &ApplicationListModel::sycocaDbChanged);
loadSettings(); loadSettings();
initWayland(); initWayland();
@ -65,7 +64,7 @@ void ApplicationListModel::loadSettings()
++i; ++i;
} }
//loadApplications(); // loadApplications();
} }
QHash<int, QByteArray> ApplicationListModel::roleNames() const QHash<int, QByteArray> ApplicationListModel::roleNames() const
@ -112,39 +111,36 @@ void ApplicationListModel::initWayland()
} }
auto *registry = new Registry(this); auto *registry = new Registry(this);
registry->create(connection); registry->create(connection);
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
[this, registry] (quint32 name, quint32 version) { m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this); qRegisterMetaType<QVector<int>>("QVector<int>");
qRegisterMetaType<QVector<int> >("QVector<int>");
connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated, connect(m_windowManagement, &KWayland::Client::PlasmaWindowManagement::windowCreated, this, [this](KWayland::Client::PlasmaWindow *window) {
this, [this] (KWayland::Client::PlasmaWindow *window) { if (window->appId() == QStringLiteral("org.kde.plasmashell")) {
if (window->appId() == QStringLiteral("org.kde.plasmashell")) { return;
return; }
} int idx = 0;
int idx = 0; for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) { if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) { (*i).window = window;
(*i).window = window; emit dataChanged(index(idx, 0), index(idx, 0));
emit dataChanged(index(idx, 0), index(idx, 0)); connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window]() {
connect(window, &KWayland::Client::PlasmaWindow::unmapped, this, [this, window] () { int idx = 0;
int idx = 0; for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) {
for (auto i = m_applicationList.begin(); i != m_applicationList.end(); i++) { if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) {
if ((*i).storageId == window->appId() + QStringLiteral(".desktop")) { (*i).window = nullptr;
(*i).window = nullptr; emit dataChanged(index(idx, 0), index(idx, 0));
emit dataChanged(index(idx, 0), index(idx, 0)); break;
break;
}
idx++;
} }
}); idx++;
break; }
} });
idx++; break;
} }
}); idx++;
} }
); });
});
registry->setup(); registry->setup();
connection->roundtrip(); connection->roundtrip();
@ -162,7 +158,8 @@ void ApplicationListModel::loadApplications()
m_applicationList.clear(); m_applicationList.clear();
KServiceGroup::Ptr group = KServiceGroup::root(); KServiceGroup::Ptr group = KServiceGroup::root();
if (!group || !group->isValid()) return; if (!group || !group->isValid())
return;
KServiceGroup::List subGroupList = group->entries(true); KServiceGroup::List subGroupList = group->entries(true);
QMap<int, ApplicationData> orderedList; QMap<int, ApplicationData> orderedList;
@ -180,7 +177,7 @@ void ApplicationListModel::loadApplications()
if (!serviceGroup->noDisplay()) { if (!serviceGroup->noDisplay()) {
KServiceGroup::List entryGroupList = serviceGroup->entries(true); KServiceGroup::List entryGroupList = serviceGroup->entries(true);
for(KServiceGroup::List::ConstIterator it = entryGroupList.constBegin(); it != entryGroupList.constEnd(); it++) { for (KServiceGroup::List::ConstIterator it = entryGroupList.constBegin(); it != entryGroupList.constEnd(); it++) {
KSycocaEntry::Ptr entry = (*it); KSycocaEntry::Ptr entry = (*it);
if (entry->isType(KST_KServiceGroup)) { if (entry->isType(KST_KServiceGroup)) {
@ -283,7 +280,7 @@ Qt::ItemFlags ApplicationListModel::flags(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return {}; return {};
return Qt::ItemIsDragEnabled|QAbstractListModel::flags(index); return Qt::ItemIsDragEnabled | QAbstractListModel::flags(index);
} }
int ApplicationListModel::rowCount(const QModelIndex &parent) const int ApplicationListModel::rowCount(const QModelIndex &parent) const
@ -295,7 +292,7 @@ int ApplicationListModel::rowCount(const QModelIndex &parent) const
return m_applicationList.count(); return m_applicationList.count();
} }
void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int sourceRow, const QModelIndex& /* destinationParent */, int destinationChild) void ApplicationListModel::moveRow(const QModelIndex & /* sourceParent */, int sourceRow, const QModelIndex & /* destinationParent */, int destinationChild)
{ {
moveItem(sourceRow, destinationChild); moveItem(sourceRow, destinationChild);
} }
@ -314,8 +311,7 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
if (location == Favorites) { if (location == Favorites) {
qWarning() << "favoriting" << row << data.name; qWarning() << "favoriting" << row << data.name;
// Deny favorites when full // Deny favorites when full
if (row >= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount || if (row >= m_maxFavoriteCount || m_favorites.count() >= m_maxFavoriteCount || m_favorites.contains(data.uniqueId)) {
m_favorites.contains(data.uniqueId)) {
return; return;
} }
@ -326,8 +322,8 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
} }
emit favoriteCountChanged(); emit favoriteCountChanged();
// Out of favorites // Out of favorites
} else if (data.location == Favorites) { } else if (data.location == Favorites) {
m_favorites.removeAll(data.uniqueId); m_favorites.removeAll(data.uniqueId);
if (m_applet) { if (m_applet) {
m_applet->config().writeEntry("Favorites", m_favorites); m_applet->config().writeEntry("Favorites", m_favorites);
@ -342,8 +338,8 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
m_applet->config().writeEntry("DesktopItems", m_desktopItems.values()); m_applet->config().writeEntry("DesktopItems", m_desktopItems.values());
} }
// Out of Desktop // Out of Desktop
} else if (data.location == Desktop) { } else if (data.location == Desktop) {
m_desktopItems.remove(data.uniqueId); m_desktopItems.remove(data.uniqueId);
if (m_applet) { if (m_applet) {
m_applet->config().writeEntry(QStringLiteral("DesktopItems"), m_desktopItems.values()); m_applet->config().writeEntry(QStringLiteral("DesktopItems"), m_desktopItems.values());
@ -359,8 +355,7 @@ void ApplicationListModel::setLocation(int row, LauncherLocation location)
void ApplicationListModel::moveItem(int row, int destination) void ApplicationListModel::moveItem(int row, int destination)
{ {
if (row < 0 || destination < 0 || row >= m_applicationList.length() || if (row < 0 || destination < 0 || row >= m_applicationList.length() || destination >= m_applicationList.length() || row == destination) {
destination >= m_applicationList.length() || row == destination) {
return; return;
} }
if (destination > row) { if (destination > row) {
@ -378,7 +373,6 @@ void ApplicationListModel::moveItem(int row, int destination)
m_applicationList.insert(destination, data); m_applicationList.insert(destination, data);
} }
m_appOrder.clear(); m_appOrder.clear();
m_appPositions.clear(); m_appPositions.clear();
int i = 0; int i = 0;
@ -483,7 +477,7 @@ void ApplicationListModel::setMinimizedDelegate(int row, QQuickItem *delegate)
return; return;
} }
QRect rect = delegate->mapRectToScene(QRectF(0,0, delegate->width(), delegate->height())).toRect(); QRect rect = delegate->mapRectToScene(QRectF(0, 0, delegate->width(), delegate->height())).toRect();
window->setMinimizedGeometry(surface, rect); window->setMinimizedGeometry(surface, rect);
} }
@ -516,4 +510,3 @@ void ApplicationListModel::unsetMinimizedDelegate(int row, QQuickItem *delegate)
} }
#include "moc_applicationlistmodel.cpp" #include "moc_applicationlistmodel.cpp"

View file

@ -8,9 +8,9 @@
#define APPLICATIONLISTMODEL_H #define APPLICATIONLISTMODEL_H
// Qt // Qt
#include <QObject>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QList> #include <QList>
#include <QObject>
#include <QSet> #include <QSet>
#include "homescreen.h" #include "homescreen.h"
@ -28,7 +28,8 @@ class PlasmaWindow;
class ApplicationListModel; class ApplicationListModel;
class ApplicationListModel : public QAbstractListModel { class ApplicationListModel : public QAbstractListModel
{
Q_OBJECT Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(int count READ count NOTIFY countChanged)
@ -75,8 +76,14 @@ public:
void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild); void moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild);
int count() const { return m_applicationList.count(); } int count() const
int favoriteCount() const { return m_favorites.count();} {
return m_applicationList.count();
}
int favoriteCount() const
{
return m_favorites.count();
}
int maxFavoriteCount() const; int maxFavoriteCount() const;
void setMaxFavoriteCount(int count); void setMaxFavoriteCount(int count);
@ -102,7 +109,7 @@ public:
Q_INVOKABLE void unsetMinimizedDelegate(int row, QQuickItem *delegate); Q_INVOKABLE void unsetMinimizedDelegate(int row, QQuickItem *delegate);
public Q_SLOTS: public Q_SLOTS:
void sycocaDbChanged(const QStringList &change); void sycocaDbChanged(const QStringList &change);
Q_SIGNALS: Q_SIGNALS:
void countChanged(); void countChanged();

View file

@ -9,14 +9,13 @@
// Qt // Qt
#include <QByteArray> #include <QByteArray>
#include <QModelIndex>
#include <QDebug> #include <QDebug>
#include <QModelIndex>
// KDE // KDE
#include <KService> #include <KService>
#include <KSharedConfig> #include <KSharedConfig>
constexpr int MAX_FAVOURITES = 5; constexpr int MAX_FAVOURITES = 5;
FavoritesModel::FavoritesModel(HomeScreen *parent) FavoritesModel::FavoritesModel(HomeScreen *parent)
@ -26,7 +25,6 @@ FavoritesModel::FavoritesModel(HomeScreen *parent)
FavoritesModel::~FavoritesModel() = default; FavoritesModel::~FavoritesModel() = default;
QString FavoritesModel::storageToUniqueId(const QString &storageId) const QString FavoritesModel::storageToUniqueId(const QString &storageId) const
{ {
if (storageId.isEmpty()) { if (storageId.isEmpty()) {
@ -52,10 +50,8 @@ QString FavoritesModel::uniqueToStorageId(const QString &uniqueId) const
return uniqueId.split(QLatin1Char('-')).first(); return uniqueId.split(QLatin1Char('-')).first();
} }
void FavoritesModel::loadApplications() void FavoritesModel::loadApplications()
{ {
beginResetModel(); beginResetModel();
m_applicationList.clear(); m_applicationList.clear();
@ -183,4 +179,3 @@ void FavoritesModel::removeFavorite(int row)
} }
#include "moc_favoritesmodel.cpp" #include "moc_favoritesmodel.cpp"

View file

@ -7,13 +7,13 @@
#pragma once #pragma once
// Qt // Qt
#include <QObject>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QList> #include <QList>
#include <QObject>
#include <QSet> #include <QSet>
#include "homescreen.h"
#include "applicationlistmodel.h" #include "applicationlistmodel.h"
#include "homescreen.h"
class QString; class QString;
@ -28,14 +28,14 @@ class PlasmaWindow;
class FavoritesModel; class FavoritesModel;
class FavoritesModel : public ApplicationListModel { class FavoritesModel : public ApplicationListModel
{
Q_OBJECT Q_OBJECT
public: public:
FavoritesModel(HomeScreen *parent = nullptr); FavoritesModel(HomeScreen *parent = nullptr);
~FavoritesModel() override; ~FavoritesModel() override;
QString storageToUniqueId(const QString &storageId) const; QString storageToUniqueId(const QString &storageId) const;
QString uniqueToStorageId(const QString &uniqueId) const; QString uniqueToStorageId(const QString &uniqueId) const;
@ -43,7 +43,4 @@ public:
Q_INVOKABLE void removeFavorite(int row); Q_INVOKABLE void removeFavorite(int row);
Q_INVOKABLE void loadApplications() override; Q_INVOKABLE void loadApplications() override;
}; };

View file

@ -7,9 +7,9 @@
#include "applicationlistmodel.h" #include "applicationlistmodel.h"
#include "favoritesmodel.h" #include "favoritesmodel.h"
#include <QtQml>
#include <QDebug> #include <QDebug>
#include <QQuickItem> #include <QQuickItem>
#include <QtQml>
HomeScreen::HomeScreen(QObject *parent, const QVariantList &args) HomeScreen::HomeScreen(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args) : Plasma::Containment(parent, args)

View file

@ -7,7 +7,6 @@
#ifndef HOMESCREEN_H #ifndef HOMESCREEN_H
#define HOMESCREEN_H #define HOMESCREEN_H
#include <Plasma/Containment> #include <Plasma/Containment>
class QQuickItem; class QQuickItem;
@ -20,7 +19,7 @@ class HomeScreen : public Plasma::Containment
Q_PROPERTY(ApplicationListModel *applicationListModel READ applicationListModel CONSTANT) Q_PROPERTY(ApplicationListModel *applicationListModel READ applicationListModel CONSTANT)
public: public:
HomeScreen( QObject *parent, const QVariantList &args ); HomeScreen(QObject *parent, const QVariantList &args);
~HomeScreen() override; ~HomeScreen() override;
void configChanged() override; void configChanged() override;
@ -31,7 +30,7 @@ public:
Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2); Q_INVOKABLE void stackAfter(QQuickItem *item1, QQuickItem *item2);
protected: protected:
// void configChanged() override; // void configChanged() override;
private: private:
ApplicationListModel *m_applicationListModel = nullptr; ApplicationListModel *m_applicationListModel = nullptr;

View file

@ -7,22 +7,22 @@
#include "phonepanel.h" #include "phonepanel.h"
#include <qplatformdefs.h>
#include <fcntl.h> #include <fcntl.h>
#include <qplatformdefs.h>
#include <unistd.h> #include <unistd.h>
#include <KNotification>
#include <KLocalizedString>
#include <KConfigGroup> #include <KConfigGroup>
#include <KLocalizedString>
#include <KNotification>
#include <QDateTime>
#include <QDBusPendingReply> #include <QDBusPendingReply>
#include <QFile> #include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QStandardPaths> #include <QFile>
#include <QProcess> #include <QProcess>
#include <QtConcurrent/QtConcurrent>
#include <QScreen> #include <QScreen>
#include <QStandardPaths>
#include <QtConcurrent/QtConcurrent>
#define FORMAT24H "HH:mm:ss" #define FORMAT24H "HH:mm:ss"
@ -33,8 +33,8 @@ constexpr int SCREENSHOT_DELAY = 200;
static int readData(int theFile, QByteArray &theDataOut) static int readData(int theFile, QByteArray &theDataOut)
{ {
// implementation based on QtWayland file qwaylanddataoffer.cpp // implementation based on QtWayland file qwaylanddataoffer.cpp
char lBuffer[4096]; char lBuffer[4096];
int lRetryCount = 0; int lRetryCount = 0;
ssize_t lBytesRead = 0; ssize_t lBytesRead = 0;
do { do {
@ -73,7 +73,7 @@ static QImage readImage(int thePipeFd)
PhonePanel::PhonePanel(QObject *parent, const QVariantList &args) PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
: Plasma::Containment(parent, args) : Plasma::Containment(parent, args)
{ {
//setHasConfigurationInterface(true); // setHasConfigurationInterface(true);
m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this); m_kscreenInterface = new org::kde::KScreen(QStringLiteral("org.kde.kded5"), QStringLiteral("/modules/kscreen"), QDBusConnection::sessionBus(), this);
m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this); m_screenshotInterface = new org::kde::kwin::Screenshot(QStringLiteral("org.kde.KWin"), QStringLiteral("/Screenshot"), QDBusConnection::sessionBus(), this);
@ -81,14 +81,13 @@ PhonePanel::PhonePanel(QObject *parent, const QVariantList &args)
m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig); m_localeConfigWatcher = KConfigWatcher::create(m_localeConfig);
// watch for changes to locale config, to update 12/24 hour time // watch for changes to locale config, to update 12/24 hour time
connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged, connect(m_localeConfigWatcher.data(), &KConfigWatcher::configChanged, this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void {
this, [this](const KConfigGroup &group, const QByteArrayList &names) -> void { if (group.name() == "Locale") {
if (group.name() == "Locale") { // we have to reparse for new changes (from system settings)
// we have to reparse for new changes (from system settings) m_localeConfig->reparseConfiguration();
m_localeConfig->reparseConfiguration(); Q_EMIT isSystem24HourFormatChanged();
Q_EMIT isSystem24HourFormatChanged(); }
} });
});
} }
PhonePanel::~PhonePanel() = default; PhonePanel::~PhonePanel() = default;
@ -152,9 +151,7 @@ void PhonePanel::takeScreenshot()
} }
QDir picturesDir(filePath); QDir picturesDir(filePath);
if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) { if (!picturesDir.mkpath(QStringLiteral("Screenshots"))) {
qWarning() << "Couldn't create folder at" qWarning() << "Couldn't create folder at" << picturesDir.path() + QStringLiteral("/Screenshots") << "to take screenshot.";
<< picturesDir.path() + QStringLiteral("/Screenshots")
<< "to take screenshot.";
return; return;
} }
filePath += QStringLiteral("/Screenshots/Screenshot_%1.png").arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss"))); filePath += QStringLiteral("/Screenshots/Screenshot_%1.png").arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_hhmmss")));
@ -162,14 +159,14 @@ void PhonePanel::takeScreenshot()
// wait ~200 ms to wait for rest of animations // wait ~200 ms to wait for rest of animations
QTimer::singleShot(SCREENSHOT_DELAY, [=]() { QTimer::singleShot(SCREENSHOT_DELAY, [=]() {
int lPipeFds[2]; int lPipeFds[2];
if (pipe2(lPipeFds, O_CLOEXEC|O_NONBLOCK) != 0) { if (pipe2(lPipeFds, O_CLOEXEC | O_NONBLOCK) != 0) {
qWarning() << "Could not take screenshot"; qWarning() << "Could not take screenshot";
return; return;
} }
// Take fullscreen screenshot, and no pointer // Take fullscreen screenshot, and no pointer
QDBusPendingCall pcall = m_screenshotInterface->screenshotFullscreen(QDBusUnixFileDescriptor(lPipeFds[1]), false, true); QDBusPendingCall pcall = m_screenshotInterface->screenshotFullscreen(QDBusUnixFileDescriptor(lPipeFds[1]), false, true);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [](QDBusPendingCallWatcher* watcher) { QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [](QDBusPendingCallWatcher *watcher) {
if (watcher->isError()) { if (watcher->isError()) {
const auto error = watcher->error(); const auto error = watcher->error();
qWarning() << "Error calling KWin DBus interface:" << error.name() << error.message(); qWarning() << "Error calling KWin DBus interface:" << error.name() << error.message();
@ -177,23 +174,21 @@ void PhonePanel::takeScreenshot()
watcher->deleteLater(); watcher->deleteLater();
}); });
const auto lWatcher = new QFutureWatcher<QImage>(this); const auto lWatcher = new QFutureWatcher<QImage>(this);
QObject::connect(lWatcher, &QFutureWatcher<QImage>::finished, this, QObject::connect(lWatcher, &QFutureWatcher<QImage>::finished, this, [lWatcher, filePath]() {
[lWatcher, filePath] () { lWatcher->deleteLater();
lWatcher->deleteLater(); const QImage lImage = lWatcher->result();
const QImage lImage = lWatcher->result(); qDebug() << lImage;
qDebug() << lImage; if (!lImage.save(filePath, "PNG")) {
if(!lImage.save(filePath, "PNG")) { qWarning() << "Failed to save screenshot to" << filePath;
qWarning() << "Failed to save screenshot to" << filePath; } else {
} else { KNotification *notif = new KNotification("captured");
KNotification *notif = new KNotification("captured"); notif->setComponentName(QStringLiteral("plasma_phone_components"));
notif->setComponentName(QStringLiteral("plasma_phone_components")); notif->setTitle(i18n("New Screenshot"));
notif->setTitle(i18n("New Screenshot")); notif->setUrls({filePath});
notif->setUrls({filePath}); notif->setText(i18n("New screenshot saved to %1", filePath));
notif->setText(i18n("New screenshot saved to %1", filePath)); notif->sendEvent();
notif->sendEvent();
}
} }
); });
lWatcher->setFuture(QtConcurrent::run(readImage, lPipeFds[0])); lWatcher->setFuture(QtConcurrent::run(readImage, lPipeFds[0]));
close(lPipeFds[1]); close(lPipeFds[1]);
}); });

View file

@ -7,11 +7,10 @@
#ifndef PHONEPANEL_H #ifndef PHONEPANEL_H
#define PHONEPANEL_H #define PHONEPANEL_H
#include <Plasma/Containment> #include <Plasma/Containment>
#include <KSharedConfig>
#include <KConfigWatcher> #include <KConfigWatcher>
#include <KSharedConfig>
#include "kscreeninterface.h" #include "kscreeninterface.h"
#include "screenshotinterface.h" #include "screenshotinterface.h"
@ -22,8 +21,9 @@ class PhonePanel : public Plasma::Containment
Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged); Q_PROPERTY(bool autoRotateEnabled READ autoRotate WRITE setAutoRotate NOTIFY autoRotateChanged);
Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged); Q_PROPERTY(bool torchEnabled READ torchEnabled NOTIFY torchChanged);
Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged); Q_PROPERTY(bool isSystem24HourFormat READ isSystem24HourFormat NOTIFY isSystem24HourFormatChanged);
public: public:
PhonePanel( QObject *parent, const QVariantList &args ); PhonePanel(QObject *parent, const QVariantList &args);
~PhonePanel() override; ~PhonePanel() override;
public Q_SLOTS: public Q_SLOTS:

View file

@ -6,18 +6,18 @@
#include "taskpanel.h" #include "taskpanel.h"
#include <QtQml>
#include <QDebug> #include <QDebug>
#include <QQuickItem> #include <QQuickItem>
#include <QQuickWindow> #include <QQuickWindow>
#include <QtQml>
#include <Plasma/Package>
#include <KWayland/Client/connection_thread.h> #include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/plasmawindowmanagement.h> #include <KWayland/Client/plasmawindowmanagement.h>
#include <KWayland/Client/plasmawindowmodel.h> #include <KWayland/Client/plasmawindowmodel.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/registry.h> #include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h> #include <KWayland/Client/surface.h>
#include <Plasma/Package>
#include <virtualkeyboardinterface.h> #include <virtualkeyboardinterface.h>
@ -31,9 +31,10 @@ class KwinVirtualKeyboardInterface : public OrgKdeKwinVirtualKeyboardInterface
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
public: public:
KwinVirtualKeyboardInterface() : KwinVirtualKeyboardInterface()
OrgKdeKwinVirtualKeyboardInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus()) : OrgKdeKwinVirtualKeyboardInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/VirtualKeyboard"), QDBusConnection::sessionBus())
{} {
}
}; };
TaskPanel::TaskPanel(QObject *parent, const QVariantList &args) TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
@ -48,9 +49,13 @@ TaskPanel::TaskPanel(QObject *parent, const QVariantList &args)
connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow); connect(m_activeTimer, &QTimer::timeout, this, &TaskPanel::updateActiveWindow);
initWayland(); initWayland();
qmlRegisterSingletonType<OrgKdeKwinVirtualKeyboardInterface>("org.kde.plasma.phone.taskpanel", 1, 0, "KWinVirtualKeyboard", [](QQmlEngine *, QJSEngine *) -> QObject * { qmlRegisterSingletonType<OrgKdeKwinVirtualKeyboardInterface>("org.kde.plasma.phone.taskpanel",
return new KwinVirtualKeyboardInterface; 1,
}); 0,
"KWinVirtualKeyboard",
[](QQmlEngine *, QJSEngine *) -> QObject * {
return new KwinVirtualKeyboardInterface;
});
} }
TaskPanel::~TaskPanel() = default; TaskPanel::~TaskPanel() = default;
@ -76,44 +81,36 @@ void TaskPanel::initWayland()
} }
auto *registry = new Registry(this); auto *registry = new Registry(this);
registry->create(connection); registry->create(connection);
connect(registry, &Registry::plasmaWindowManagementAnnounced, this, connect(registry, &Registry::plasmaWindowManagementAnnounced, this, [this, registry](quint32 name, quint32 version) {
[this, registry] (quint32 name, quint32 version) { m_windowManagement = registry->createPlasmaWindowManagement(name, version, this);
m_windowManagement = registry->createPlasmaWindowManagement(name, version, this); qRegisterMetaType<QVector<int>>("QVector<int>");
qRegisterMetaType<QVector<int> >("QVector<int>"); connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, [this](bool showing) {
connect(m_windowManagement, &PlasmaWindowManagement::showingDesktopChanged, this, if (showing == m_showingDesktop) {
[this] (bool showing) {
if (showing == m_showingDesktop) {
return;
}
m_showingDesktop = showing;
emit showingDesktopChanged(m_showingDesktop);
}
);
//FIXME
//connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow, Qt::QueuedConnection);
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);
if (!m_panel) {
return; return;
} }
Surface *s = Surface::fromWindow(m_panel); m_showingDesktop = showing;
if (!s) { emit showingDesktopChanged(m_showingDesktop);
return; });
} // FIXME
m_shellSurface = m_shellInterface->createSurface(s, this); // connect(m_windowManagement, &PlasmaWindowManagement::activeWindowChanged, this, &TaskPanel::updateActiveWindow, Qt::QueuedConnection);
m_shellSurface->setSkipTaskbar(true);
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);
if (!m_panel) {
return;
} }
); Surface *s = Surface::fromWindow(m_panel);
if (!s) {
return;
}
m_shellSurface = m_shellInterface->createSurface(s, this);
m_shellSurface->setSkipTaskbar(true);
});
registry->setup(); registry->setup();
connection->roundtrip(); connection->roundtrip();
} }
@ -164,15 +161,13 @@ void TaskPanel::updateActiveWindow()
} }
if (m_activeWindow) { if (m_activeWindow) {
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
this, &TaskPanel::forgetActiveWindow);
} }
m_activeWindow = m_windowManagement->activeWindow(); m_activeWindow = m_windowManagement->activeWindow();
if (m_activeWindow) { if (m_activeWindow) {
connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, connect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
this, &TaskPanel::forgetActiveWindow);
} }
bool newAllMinimized = true; bool newAllMinimized = true;
@ -199,8 +194,7 @@ void TaskPanel::forgetActiveWindow()
{ {
if (m_activeWindow) { if (m_activeWindow) {
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged); disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::closeableChanged, this, &TaskPanel::hasCloseableActiveWindowChanged);
disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, disconnect(m_activeWindow.data(), &KWayland::Client::PlasmaWindow::unmapped, this, &TaskPanel::forgetActiveWindow);
this, &TaskPanel::forgetActiveWindow);
} }
m_activeWindow.clear(); m_activeWindow.clear();
emit hasCloseableActiveWindowChanged(); emit hasCloseableActiveWindowChanged();

View file

@ -33,7 +33,7 @@ class TaskPanel : public Plasma::Containment
Q_PROPERTY(QWindow *panel READ panel WRITE setPanel NOTIFY panelChanged) Q_PROPERTY(QWindow *panel READ panel WRITE setPanel NOTIFY panelChanged)
public: public:
TaskPanel( QObject *parent, const QVariantList &args ); TaskPanel(QObject *parent, const QVariantList &args);
~TaskPanel() override; ~TaskPanel() override;
QWindow *panel(); QWindow *panel();
@ -41,12 +41,14 @@ public:
Q_INVOKABLE void closeActiveWindow(); Q_INVOKABLE void closeActiveWindow();
bool isShowingDesktop() const { bool isShowingDesktop() const
{
return m_showingDesktop; return m_showingDesktop;
} }
void requestShowingDesktop(bool showingDesktop); void requestShowingDesktop(bool showingDesktop);
bool allMinimized() const { bool allMinimized() const
{
return m_allMinimized; return m_allMinimized;
} }
bool hasCloseableActiveWindow() const; bool hasCloseableActiveWindow() const;