summaryrefslogtreecommitdiff
path: root/kde-frameworks/plasma/files/plasma-5.26.0-activationTogglesExpanded.patch
blob: f32f2b426f4c0a4551dd484b54f120264d246b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
commit 65706d3878d556c7a1eac18984ec41b1a1d96d56
Author: Roman Gilg <subdiff@gmail.com>
Date:   Wed Oct 19 18:51:15 2016 +0200

    New bool to use activated signal as toggle of expanded
    
    The launcher applets couldn't be closed with Meta alone and on Wayland
    in general by any global shortcut, since we used for that the focusOutEvent
    triggered only on X and only on global shortcuts (on default Alt+F1).
    
    This patch introduces the new bool activationTogglesExpanded, which allowes
    QML applets to decide if they wish to use the activated signal also to end
    their expanded state.
    
    The default value is false, in order to not break any legacy applets.
    
    REVIEW: 129204
    BUG: 367685

diff --git a/src/plasmaquick/appletquickitem.cpp b/src/plasmaquick/appletquickitem.cpp
index ce2b82a..e2fd40e 100644
--- a/src/plasmaquick/appletquickitem.cpp
+++ b/src/plasmaquick/appletquickitem.cpp
@@ -48,7 +48,8 @@ AppletQuickItemPrivate::AppletQuickItemPrivate(Plasma::Applet *a, AppletQuickIte
       switchWidth(-1),
       switchHeight(-1),
       applet(a),
-      expanded(false)
+      expanded(false),
+      activationTogglesExpanded(false)
 {
 }
 
@@ -727,6 +728,20 @@ void AppletQuickItem::setExpanded(bool expanded)
     emit expandedChanged(expanded);
 }
 
+bool AppletQuickItem::isActivationTogglesExpanded() const
+{
+    return d->activationTogglesExpanded;
+}
+
+void AppletQuickItem::setActivationTogglesExpanded(bool activationTogglesExpanded)
+{
+    if (d->activationTogglesExpanded == activationTogglesExpanded) {
+        return;
+    }
+    d->activationTogglesExpanded = activationTogglesExpanded;
+    emit activationTogglesExpandedChanged(activationTogglesExpanded);
+}
+
 ////////////Internals
 
 KDeclarative::QmlObject *AppletQuickItem::qmlObject()
diff --git a/src/plasmaquick/appletquickitem.h b/src/plasmaquick/appletquickitem.h
index 943e227..7df364d 100644
--- a/src/plasmaquick/appletquickitem.h
+++ b/src/plasmaquick/appletquickitem.h
@@ -81,6 +81,12 @@ class PLASMAQUICK_EXPORT AppletQuickItem : public QQuickItem
     Q_PROPERTY(bool expanded WRITE setExpanded READ isExpanded NOTIFY expandedChanged)
 
     /**
+     * True when the applet wants the activation signal act in toggle mode, i.e. while being expanded
+     * the signal shrinks the applet to its not exanded state instead of reexpanding it.
+     */
+    Q_PROPERTY(bool activationTogglesExpanded WRITE setActivationTogglesExpanded READ isActivationTogglesExpanded NOTIFY activationTogglesExpandedChanged)
+
+    /**
      * the applet root QML item: sometimes is the same as fullRepresentationItem
      * if a fullrepresentation was not declared explicitly
      */
@@ -126,6 +132,9 @@ public:
     bool isExpanded() const;
     void setExpanded(bool expanded);
 
+    bool isActivationTogglesExpanded() const;
+    void setActivationTogglesExpanded(bool activationTogglesExpanded);
+
 ////NEEDED BY QML TO CREATE ATTACHED PROPERTIES
     static AppletQuickItem *qmlAttachedProperties(QObject *object);
 
@@ -135,6 +144,7 @@ Q_SIGNALS:
     void switchHeightChanged(int height);
 
     void expandedChanged(bool expanded);
+    void activationTogglesExpandedChanged(bool activationTogglesExpanded);
 
     void compactRepresentationChanged(QQmlComponent *compactRepresentation);
     void fullRepresentationChanged(QQmlComponent *fullRepresentation);
diff --git a/src/plasmaquick/private/appletquickitem_p.h b/src/plasmaquick/private/appletquickitem_p.h
index 1436935..ffd2bf2 100644
--- a/src/plasmaquick/private/appletquickitem_p.h
+++ b/src/plasmaquick/private/appletquickitem_p.h
@@ -104,6 +104,7 @@ public:
     Plasma::Package containmentPackage;
 
     bool expanded : 1;
+    bool activationTogglesExpanded : 1;
 
     static QHash<QObject *, AppletQuickItem *> s_rootObjects;
 };
diff --git a/src/scriptengines/qml/plasmoid/appletinterface.cpp b/src/scriptengines/qml/plasmoid/appletinterface.cpp
index 1cd6934..f24bc51 100644
--- a/src/scriptengines/qml/plasmoid/appletinterface.cpp
+++ b/src/scriptengines/qml/plasmoid/appletinterface.cpp
@@ -142,11 +142,16 @@ void AppletInterface::init()
     emit busyChanged();
 
     applet()->updateConstraints(Plasma::Types::UiReadyConstraint);
+
     connect(applet(), &Plasma::Applet::activated,
     [ = ]() {
-        setExpanded(true);
+        // in case the applet doesn't want to get shrinked on reactivation,
+        // we always expand it again (only in order to conform with legacy behaviour)
+        bool activate = !( isExpanded() && isActivationTogglesExpanded() );
+
+        setExpanded(activate);
         if (QQuickItem *i = qobject_cast<QQuickItem *>(fullRepresentationItem())) {
-            i->setFocus(true, Qt::ShortcutFocusReason);
+            i->setFocus(activate, Qt::ShortcutFocusReason);
         }
     });