Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

Commit

Permalink
Simplify DecoratedWindow
Browse files Browse the repository at this point in the history
Reduce the number of nested MouseAreas
  • Loading branch information
dandrader committed Jan 18, 2017
1 parent 6c5022c commit e73b43a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
79 changes: 36 additions & 43 deletions qml/Stage/DecoratedWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,19 @@ FocusScope {
]
}

MouseArea {
WindowDecoration {
id: decoration
closeButtonVisible: root.application.appId !== "unity8-dash"
objectName: "appWindowDecoration"

anchors { left: parent.left; top: parent.top; right: parent.right }
height: units.gu(3)

opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
title: applicationWindow.title

opacity: root.hasDecoration ? Math.min(1, root.showDecoration) : 0
Behavior on opacity { UbuntuNumberAnimation { } }

drag.target: Item {}
drag.filterChildren: true
drag.threshold: 0

onPressed: root.decorationPressed();
onPressedChanged: moveHandler.handlePressedChanged(pressed, pressedButtons, mouseX, mouseY)
onPositionChanged: moveHandler.handlePositionChanged(mouse)
Expand All @@ -216,47 +217,39 @@ FocusScope {
moveHandler.handleReleased();
}

WindowDecoration {
id: decoration
closeButtonVisible: root.application.appId !== "unity8-dash"
objectName: "appWindowDecoration"
anchors.fill: parent
title: applicationWindow.title

onCloseClicked: root.closeClicked();
onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
onMinimizeClicked: root.minimizeClicked();

enableMenus: {
return active &&
surface &&
(PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
}
menu: sharedAppModel.model
onCloseClicked: root.closeClicked();
onMaximizeClicked: { root.decorationPressed(); root.maximizeClicked(); }
onMaximizeHorizontallyClicked: { root.decorationPressed(); root.maximizeHorizontallyClicked(); }
onMaximizeVerticallyClicked: { root.decorationPressed(); root.maximizeVerticallyClicked(); }
onMinimizeClicked: root.minimizeClicked();

Indicators.SharedUnityMenuModel {
id: sharedAppModel
property var menus: surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : []
property var menuService: menus.length > 0 ? menus[0] : undefined
enableMenus: {
return active &&
surface &&
(PanelState.focusedPersistentSurfaceId === surface.persistentId && !PanelState.decorationsVisible)
}
menu: sharedAppModel.model

busName: menuService ? menuService.service : ""
menuObjectPath: menuService && menuService.menuPath ? menuService.menuPath : ""
actions: menuService && menuService.actionPath ? { "unity": menuService.actionPath } : {}
}
Indicators.SharedUnityMenuModel {
id: sharedAppModel
property var menus: surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : []
property var menuService: menus.length > 0 ? menus[0] : undefined

Connections {
target: ApplicationMenuRegistry
onSurfaceMenuRegistered: {
if (surface && surfaceId === surface.persistentId) {
sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
}
busName: menuService ? menuService.service : ""
menuObjectPath: menuService && menuService.menuPath ? menuService.menuPath : ""
actions: menuService && menuService.actionPath ? { "unity": menuService.actionPath } : {}
}

Connections {
target: ApplicationMenuRegistry
onSurfaceMenuRegistered: {
if (surface && surfaceId === surface.persistentId) {
sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
}
onSurfaceMenuUnregistered: {
if (surface && surfaceId === surface.persistentId) {
sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
}
}
onSurfaceMenuUnregistered: {
if (surface && surfaceId === surface.persistentId) {
sharedAppModel.menus = Qt.binding(function() { return surface ? ApplicationMenuRegistry.getMenusForSurface(surface.persistentId) : [] });
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions qml/Stage/WindowDecoration.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ MouseArea {
acceptedButtons: Qt.AllButtons // prevent leaking unhandled mouse events
hoverEnabled: true

drag.target: Item {}
drag.filterChildren: true
drag.threshold: 0

signal closeClicked()
signal minimizeClicked()
signal maximizeClicked()
Expand All @@ -64,8 +68,8 @@ MouseArea {
(menuBar.showRequested || root.containsMouse)
}

// We dont want touch events to fall through to parent,
// otherwise the containsMouse will not work.
// We dont want touch events to fall through to parent as it expect some child MouseArea to have them
// If not some MouseArea in the menu bar, it will be this one.
MouseArea {
anchors.fill: parent
propagateComposedEvents: true
Expand Down

0 comments on commit e73b43a

Please sign in to comment.