on xenial help sign in
Simplify DecoratedWindow

Reduce the number of nested MouseAreas

commite73b43aa0633d1e9a7d696a6f2cd4231f6add595 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateWed 18 Jan 2017, 15:34 (10 years ago) parent6c5022c
2 files changed+42−45
qml/Stage/DecoratedWindow.qml+36−43 qml/Stage/WindowDecoration.qml+6−2
qml/Stage/DecoratedWindow.qml+36−43
@@ -196,18 +196,19 @@ FocusScope {
196196 ]
197197 }
198198
199− MouseArea {
199+ WindowDecoration {
200+ id: decoration
201+ closeButtonVisible: root.application.appId !== "unity8-dash"
202+ objectName: "appWindowDecoration"
203+
200204 anchors { left: parent.left; top: parent.top; right: parent.right }
201205 height: units.gu(3)
202206
203− opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
207+ title: applicationWindow.title
204208
209+ opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
205210 Behavior on opacity { UbuntuNumberAnimation { } }
206211
207− drag.target: Item {}
208− drag.filterChildren: true
209− drag.threshold: 0
210−
211212 onPressed: root.decorationPressed();
212213 onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
213214 onPositionChanged: moveHandler.handlePositionChanged(mouse)
@@ -216,47 +217,39 @@ FocusScope {
216217 moveHandler.handleReleased();
217218 }
218219
219− WindowDecoration {
220− id: decoration
221− closeButtonVisible: root.application.appId !== "unity8-dash"
222− objectName: "appWindowDecoration"
223− anchors.fill: parent
224− title: applicationWindow.title
225−
226− onCloseClicked: root.closeClicked();
227− onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
228− onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
229− onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
230− onMinimizeClicked: root.minimizeClicked();
231−
232− enableMenus: {
233− return active &&
234− surface &&
235− (PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
236− }
237− menu: sharedAppModel.model
220+ onCloseClicked: root.closeClicked();
221+ onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
222+ onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
223+ onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
224+ onMinimizeClicked: root.minimizeClicked();
238225
239− Indicators.SharedUnityMenuModel {
240− id: sharedAppModel
241− property var menus: surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : []
242− property var menuService: menus.length > 0 ? menus[0] : undefined
226+ enableMenus: {
227+ return active &&
228+ surface &&
229+ (PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
230+ }
231+ menu: sharedAppModel.model
243232
244− busName: menuService ? menuService.service : ""
245− menuObjectPath: menuService && menuService.menuPath ? menuService.menuPath : ""
246− actions: menuService && menuService.actionPath ? { "unity": menuService.actionPath } : {}
247− }
233+ Indicators.SharedUnityMenuModel {
234+ id: sharedAppModel
235+ property var menus: surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : []
236+ property var menuService: menus.length > 0 ? menus[0] : undefined
248237
249− Connections {
250− target: ApplicationMenuRegistry
251− onSurfaceMenuRegistered: {
252− if (surface && surfaceId === surface.persistentId) {
253− sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
254− }
238+ busName: menuService ? menuService.service : ""
239+ menuObjectPath: menuService && menuService.menuPath ? menuService.menuPath : ""
240+ actions: menuService && menuService.actionPath ? { "unity": menuService.actionPath } : {}
241+ }
242+
243+ Connections {
244+ target: ApplicationMenuRegistry
245+ onSurfaceMenuRegistered: {
246+ if (surface && surfaceId === surface.persistentId) {
247+ sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
255248 }
256− onSurfaceMenuUnregistered: {
257− if (surface && surfaceId === surface.persistentId) {
258− sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
259− }
249+ }
250+ onSurfaceMenuUnregistered: {
251+ if (surface && surfaceId === surface.persistentId) {
252+ sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
260253 }
261254 }
262255 }
qml/Stage/WindowDecoration.qml+6−2
@@ -38,6 +38,10 @@ MouseArea {
3838 acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
3939 hoverEnabled: true
4040
41+ drag.target: Item {}
42+ drag.filterChildren: true
43+ drag.threshold: 0
44+
4145 signal closeClicked()
4246 signal minimizeClicked()
4347 signal maximizeClicked()
@@ -64,8 +68,8 @@ MouseArea {
6468 (menuBar.showRequested || root.containsMouse)
6569 }
6670
67− // We dont want touch events to fall through to parent,
68− // otherwise the containsMouse will not work.
71+ // We dont want touch events to fall through to parent as it expect some child MouseArea to have them
72+ // If not some MouseArea in the menu bar, it will be this one.
6973 MouseArea {
7074 anchors.fill: parent
7175 propagateComposedEvents: true