File fix-activating-appmenu.patch of Package plasmoid-active-window-control
From 933ab3d9d83124124ce3a91ffa32a506e7e6bb4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Kostoln=C3=BD?= <clearmartin@zoho.com>
Date: Sun, 28 Jan 2018 23:31:08 +0100
Subject: [PATCH] Fix proper enabling & diabling appmenu
Do not register to appmenu service on creation of the applet. Instead register only when appmenu is actually enabled. Unregister when disabled.
---
lib/appmenuapplet.cpp | 63 ++++++++++++++++++++++++++++++-----------
lib/appmenuapplet.h | 13 +++++++--
package/contents/ui/AppMenu.qml | 4 +++
3 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/lib/appmenuapplet.cpp b/lib/appmenuapplet.cpp
index 082ead3..ca66df4 100644
--- a/lib/appmenuapplet.cpp
+++ b/lib/appmenuapplet.cpp
@@ -42,13 +42,6 @@ static const QString s_viewService(QStringLiteral("org.kde.kappmenuview"));
AppMenuApplet::AppMenuApplet(QObject *parent, const QVariantList &data)
: Plasma::Applet(parent, data)
{
- ++s_refs;
- //if we're the first, regster the service
- if (s_refs == 1) {
- QDBusConnection::sessionBus().interface()->registerService(s_viewService,
- QDBusConnectionInterface::QueueService,
- QDBusConnectionInterface::DontAllowReplacement);
- }
/*it registers or unregisters the service when the destroyed value of the applet change,
and not in the dtor, because:
when we "delete" an applet, it just hides it for about a minute setting its status
@@ -58,17 +51,9 @@ AppMenuApplet::AppMenuApplet(QObject *parent, const QVariantList &data)
will have to be registered again*/
connect(this, &Applet::destroyedChanged, this, [this](bool destroyed) {
if (destroyed) {
- //if we were the last, unregister
- if (--s_refs == 0) {
- QDBusConnection::sessionBus().interface()->unregisterService(s_viewService);
- }
+ unregisterService();
} else {
- //if we're the first, regster the service
- if (++s_refs == 1) {
- QDBusConnection::sessionBus().interface()->registerService(s_viewService,
- QDBusConnectionInterface::QueueService,
- QDBusConnectionInterface::DontAllowReplacement);
- }
+ registerService();
}
});
}
@@ -84,6 +69,50 @@ AppMenuModel *AppMenuApplet::model() const
return m_model;
}
+void AppMenuApplet::registerService()
+{
+ qDebug() << "registering appmenu service";
+ ++s_refs;
+ //if we're the first, regster the service
+ if (s_refs == 1) {
+ qDebug() << " -> connecting to DBus";
+ QDBusConnection::sessionBus().interface()->registerService(s_viewService,
+ QDBusConnectionInterface::QueueService,
+ QDBusConnectionInterface::DontAllowReplacement);
+ }
+}
+
+void AppMenuApplet::unregisterService()
+{
+ qDebug() << "unregistering from appmenu service";
+ //if we were the last, unregister
+ if (--s_refs == 0) {
+ qDebug() << " -> disconnecting from DBus";
+ QDBusConnection::sessionBus().interface()->unregisterService(s_viewService);
+ }
+ if (s_refs < 0) {
+ s_refs = 0;
+ }
+}
+
+bool AppMenuApplet::enabled() const
+{
+ return m_enabled;
+}
+
+void AppMenuApplet::setEnabled(bool enabled)
+{
+ if (enabled == m_enabled) {
+ return;
+ }
+ if (enabled) {
+ registerService();
+ } else {
+ unregisterService();
+ }
+ m_enabled = enabled;
+}
+
void AppMenuApplet::setModel(AppMenuModel *model)
{
if (m_model != model) {
diff --git a/lib/appmenuapplet.h b/lib/appmenuapplet.h
index 0633c32..ab0f5f2 100644
--- a/lib/appmenuapplet.h
+++ b/lib/appmenuapplet.h
@@ -35,6 +35,8 @@ class AppMenuApplet : public Plasma::Applet
Q_PROPERTY(AppMenuModel* model READ model WRITE setModel NOTIFY modelChanged)
+ Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
+
Q_PROPERTY(int view READ view WRITE setView NOTIFY viewChanged)
Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
@@ -60,11 +62,18 @@ class AppMenuApplet : public Plasma::Applet
AppMenuModel *model() const;
void setModel(AppMenuModel *model);
+ bool enabled() const;
+ void setEnabled(bool enabled);
+
int view() const;
void setView(int type);
+ void registerService();
+ void unregisterService();
+
signals:
void modelChanged();
+ void enabledChanged();
void viewChanged();
void currentIndexChanged();
void buttonGridChanged();
@@ -74,15 +83,15 @@ public slots:
void trigger(QQuickItem *ctx, int idx);
protected:
- bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
+ bool eventFilter(QObject *watched, QEvent *event) override;
private:
QMenu *createMenu(int idx) const;
void setCurrentIndex(int currentIndex);
void onMenuAboutToHide();
-
int m_currentIndex = -1;
+ bool m_enabled = false;
int m_viewType = FullView;
QPointer<QMenu> m_currentMenu;
QPointer<QQuickItem> m_buttonGrid;
diff --git a/package/contents/ui/AppMenu.qml b/package/contents/ui/AppMenu.qml
index 5413e1f..36a5ba5 100644
--- a/package/contents/ui/AppMenu.qml
+++ b/package/contents/ui/AppMenu.qml
@@ -45,6 +45,7 @@ Item {
Component.onCompleted: {
plasmoid.nativeInterface.buttonGrid = buttonGrid
+ plasmoid.nativeInterface.enabled = appmenuEnabled
}
Connections {
@@ -163,6 +164,9 @@ Item {
onAppmenuEnabledChanged: {
appmenu.resetAppmenuModel()
+ if (appMenuModel !== null) {
+ plasmoid.nativeInterface.enabled = appmenuEnabled
+ }
}
}
\ No newline at end of file