on xenial help sign in
fixed surface visibility
commit6d92157f2481b0b7562fa6f70a2df89715e930e6 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 20 Oct 2015, 17:48 (11 years ago) parent0e7e1bf
5 files changed+84−44
qml/Stages/DesktopStage.qml+25−5 tests/mocks/Unity/Application/MirSurface.cpp+35−26 tests/mocks/Unity/Application/MirSurface.h+11−6 tests/mocks/Unity/Application/MirSurfaceItem.cpp+12−7 tests/mocks/Unity/Application/MirSurfaceItem.h+1
qml/Stages/DesktopStage.qml+25−5
@@ -150,13 +150,16 @@ Rectangle {
150150 property bool maximized: false
151151 property bool minimized: false
152152
153+ property bool visuallyMaximized: false
154+ property bool visuallyMinimized: false
155+
153156 onFocusChanged: {
154157 if (focus && ApplicationManager.focusedApplicationId !== model.appId) {
155158 ApplicationManager.focusApplication(model.appId);
156159 }
157160 }
158161
159− readonly property bool foregroundMaximized: maximized && index == 0
162+ readonly property bool foregroundMaximized: visuallyMaximized && index == 0
160163 onForegroundMaximizedChanged: {
161164 if (foregroundMaximized) {
162165 priv.foregroundMaximizedAppId = model.appId;
@@ -165,8 +168,9 @@ Rectangle {
165168 }
166169 }
167170
168− visible: !minimized &&
171+ visible: !visuallyMinimized &&
169172 (priv.foregroundMaximizedAppId === "" || priv.foregroundMaximizedAppId === model.appId)
173+ || (spread.focus && index === spread.highlightedIndex)
170174
171175 Binding {
172176 target: ApplicationManager.get(index)
@@ -207,9 +211,25 @@ Rectangle {
207211 ]
208212 transitions: [
209213 Transition {
210− from: "maximized,minimized,normal,"
211− to: "maximized,minimized,normal,"
212− PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
214+ to: "normal"
215+ PropertyAction { target: appDelegate; properties: "visuallyMinimized,visuallyMaximized"; value: false }
216+ PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale," }
217+ },
218+ Transition {
219+ to: "maximized"
220+ SequentialAnimation {
221+ PropertyAction { target: appDelegate; property: "visuallyMinimized"; value: false }
222+ PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
223+ PropertyAction { target: appDelegate; property: "visuallyMaximized"; value: true }
224+ }
225+ },
226+ Transition {
227+ to: "minimized"
228+ SequentialAnimation {
229+ PropertyAction { target: appDelegate; property: "visuallyMaximized"; value: false }
230+ PropertyAnimation { target: appDelegate; properties: "x,y,opacity,width,height,scale" }
231+ PropertyAction { target: appDelegate; property: "visuallyMinimized"; value: true }
232+ }
213233 },
214234 Transition {
215235 from: ""
tests/mocks/Unity/Application/MirSurface.cpp+35−26
@@ -32,7 +32,6 @@ MirSurface::MirSurface(const QString& name,
3232 , m_qmlFilePath(qmlFilePath)
3333 , m_live(true)
3434 , m_visible(true)
35− , m_viewCount(0)
3635 , m_activeFocus(false)
3736 , m_width(-1)
3837 , m_height(-1)
@@ -88,7 +87,7 @@ void MirSurface::setLive(bool live)
8887 m_live = live;
8988 Q_EMIT liveChanged(live);
9089
91− if (!m_live && m_viewCount == 0) {
90+ if (!m_live && m_views.count() == 0) {
9291 deleteLater();
9392 }
9493}
@@ -126,27 +125,49 @@ void MirSurface::setOrientationAngle(Mir::OrientationAngle angle)
126125 Q_EMIT orientationAngleChanged(angle);
127126}
128127
129−void MirSurface::incrementViewCount()
128+
129+
130+void MirSurface::registerView(qintptr viewId)
130131{
131− ++m_viewCount;
132−// qDebug().nospace() << "MirSurface::incrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
132+ m_views.insert(viewId, MirSurface::View{false});
133+ qDebug().nospace() << "MirSurface[" << name() << "]::registerView(" << viewId << ")"
134+ << " after=" << m_views.count();
133135}
134136
135−void MirSurface::decrementViewCount()
137+void MirSurface::unregisterView(qintptr viewId)
136138{
137− --m_viewCount;
138−// qDebug().nospace() << "MirSurface::decrementViewCount() viewCount(after)=" << m_viewCount << " " << name();
139−
140− Q_ASSERT(m_viewCount >= 0);
141−
142− if (!m_live && m_viewCount == 0) {
139+ qDebug().nospace() << "MirSurface[" << name() << "]::unregisterView(" << viewId << ")"
140+ << " after=" << m_views.count() << " live=" << m_live;
141+ m_views.remove(viewId);
142+ if (!m_live && m_views.count() == 0) {
143143 deleteLater();
144144 }
145+ updateVisibility();
145146}
146147
147−int MirSurface::viewCount() const
148+void MirSurface::setViewVisibility(qintptr viewId, bool visible)
148149{
149− return m_viewCount;
150+ if (!m_views.contains(viewId)) return;
151+
152+ m_views[viewId].visible = visible;
153+ updateVisibility();
154+}
155+
156+void MirSurface::updateVisibility()
157+{
158+ bool newVisible = false;
159+ QHashIterator<qintptr, View> i(m_views);
160+ while (i.hasNext()) {
161+ i.next();
162+ newVisible |= i.value().visible;
163+ }
164+
165+ if (newVisible != visible()) {
166+// qDebug().nospace() << "MirSurface[" << name() << "]::updateVisibility(" << newVisible << ")";
167+
168+ m_visible = newVisible;
169+ Q_EMIT visibleChanged(m_visible);
170+ }
150171}
151172
152173bool MirSurface::activeFocus() const
@@ -164,18 +185,6 @@ void MirSurface::setActiveFocus(bool value)
164185 Q_EMIT activeFocusChanged(value);
165186}
166187
167−void MirSurface::setVisible(bool visible)
168−{
169− qDebug() << "MirSurface::setVisible(visible=" << visible << ")";
170−
171− if (m_visible == visible)
172− return;
173−
174− m_visible = visible;
175−
176− Q_EMIT visibleChanged(m_visible);
177−}
178−
179188int MirSurface::width() const
180189{
181190 return m_width;
tests/mocks/Unity/Application/MirSurface.h+11−6
@@ -19,6 +19,7 @@
1919
2020#include <QObject>
2121#include <QUrl>
22+#include <QHash>
2223
2324// unity-api
2425#include <unity/shell/application/MirSurfaceInterface.h>
@@ -68,9 +69,10 @@ public:
6869
6970 Q_INVOKABLE void setLive(bool live);
7071
71− void incrementViewCount();
72− void decrementViewCount();
73− int viewCount() const;
72+ void registerView(qintptr viewId);
73+ void unregisterView(qintptr viewId);
74+ void setViewVisibility(qintptr viewId, bool visible);
75+ int viewCount() const { return m_views.count(); }
7476
7577 int width() const;
7678 int height() const;
@@ -86,8 +88,6 @@ public:
8688 bool activeFocus() const;
8789 void setActiveFocus(bool);
8890
89− void setVisible(bool visible);
90−
9191Q_SIGNALS:
9292 void stateChanged(Mir::State);
9393 void liveChanged(bool live);
@@ -101,6 +101,8 @@ Q_SIGNALS:
101101 void activeFocusChanged(bool);
102102
103103private:
104+ void updateVisibility();
105+
104106 const QString m_name;
105107 const Mir::Type m_type;
106108 Mir::State m_state;
@@ -109,10 +111,13 @@ private:
109111 QUrl m_qmlFilePath;
110112 bool m_live;
111113 bool m_visible;
112− int m_viewCount;
113114 bool m_activeFocus;
114115 int m_width;
115116 int m_height;
117+ struct View {
118+ bool visible;
119+ };
120+ QHash<qintptr, View> m_views;
116121};
117122
118123#endif // MOCK_MIR_SURFACE_H
tests/mocks/Unity/Application/MirSurfaceItem.cpp+12−7
@@ -44,6 +44,8 @@ MirSurfaceItem::MirSurfaceItem(QQuickItem *parent)
4444 Qt::ExtraButton5 | Qt::ExtraButton6 | Qt::ExtraButton7 | Qt::ExtraButton8 |
4545 Qt::ExtraButton9 | Qt::ExtraButton10 | Qt::ExtraButton11 |
4646 Qt::ExtraButton12 | Qt::ExtraButton13);
47+
48+ connect(this, &QQuickItem::visibleChanged, this, &MirSurfaceItem::updateMirSurfaceVisibility);
4749}
4850
4951MirSurfaceItem::~MirSurfaceItem()
@@ -194,18 +196,18 @@ void MirSurfaceItem::setSurface(MirSurfaceInterface* surface)
194196 m_qmlContentComponent = nullptr;
195197
196198 disconnect(m_qmlSurface, nullptr, this, nullptr);
197− m_qmlSurface->decrementViewCount();
199+ m_qmlSurface->unregisterView((qintptr)this);
198200 }
199201
200202 m_qmlSurface = static_cast<MirSurface*>(surface);
201203
202204 if (m_qmlSurface) {
203− m_qmlSurface->incrementViewCount();
205+ m_qmlSurface->registerView((qintptr)this);
204206
205207 m_qmlSurface->setActiveFocus(hasActiveFocus());
206− m_qmlSurface->setVisible(isVisible());
207208
208209 updateSurfaceSize();
210+ updateMirSurfaceVisibility();
209211
210212 connect(m_qmlSurface, &MirSurface::orientationAngleChanged, this, &MirSurfaceItem::orientationAngleChanged);
211213 connect(m_qmlSurface, &MirSurface::screenshotUrlChanged, this, &MirSurfaceItem::updateScreenshot);
@@ -251,13 +253,16 @@ void MirSurfaceItem::itemChange(ItemChange change, const ItemChangeData & value)
251253 if (m_qmlSurface) {
252254 m_qmlSurface->setActiveFocus(value.boolValue);
253255 }
254− } else if (change == QQuickItem::ItemVisibleHasChanged) {
255− if (m_qmlSurface) {
256− m_qmlSurface->setVisible(value.boolValue);
257− }
258256 }
259257}
260258
259+void MirSurfaceItem::updateMirSurfaceVisibility()
260+{
261+ if (!m_qmlSurface) return;
262+
263+ m_qmlSurface->setViewVisibility((qintptr)this, isVisible());
264+}
265+
261266void MirSurfaceItem::setConsumesInput(bool value)
262267{
263268 if (m_consumesInput != value) {
tests/mocks/Unity/Application/MirSurfaceItem.h+1
@@ -87,6 +87,7 @@ protected:
8787private Q_SLOTS:
8888 void onComponentStatusChanged(QQmlComponent::Status status);
8989 void updateScreenshot(QUrl screenshot);
90+ void updateMirSurfaceVisibility();
9091
9192private:
9293 void createQmlContentItem();