@@ -19,15 +19,14 @@ import Unity.Application 0.1 // For Mir singleton
1919import Ubuntu.Components 1.3
2020import Utils 0.1
2121import "../Components"
22−import "../Components/PanelState"
2322
2423QtObject {
2524 id: root
2625
2726 property Item target // appDelegate
28− property int stageWidth
29− property int stageHeight
3027 property real buttonsWidth: 0
28+ property Item boundsItem
29+ property real boundsTopMargin: 0
3130
3231 readonly property bool dragging: priv.dragging
3332
@@ -79,7 +78,10 @@ QtObject {
7978 // length of the triggerArea square diagonal
8079 var diagLength = Math.sqrt(2 * priv.triggerArea * priv.triggerArea);
8180 var ratio = 1 - (distance / diagLength);
82− return bx > 0 && bx <= stageWidth && by > 0 && by <= stageHeight ? ratio : 1; // everything "outside" of our square from the center is 1
81+
82+ // everything "outside" of our square from the center is 1
83+ var mousePosBoundsCoords = target.mapToItem(root.boundsItem, bx, by);
84+ return root.boundsItem.contains(mousePosBoundsCoords) ? ratio : 1;
8385 }
8486 property real progress: 0
8587 }
@@ -117,35 +119,38 @@ QtObject {
117119 target.requestRestore();
118120 }
119121
120− var pos = mapToItem(target.parent, mouse.x, mouse.y);
122+ var pos = mapToItem(target.parent, mouse.x, mouse.y); // How can that work if we're just a QtObject (not an Item)?
123+ var bounds = boundsItem.mapToItem(target.parent, 0, 0, boundsItem.width, boundsItem.height);
124+ bounds.y += boundsTopMargin;
125+ bounds.height -= boundsTopMargin;
121126 // Use integer coordinate values to ensure that target is left in a pixel-aligned
122127 // position. Mouse movement could have subpixel precision, yielding a fractional
123128 // mouse position.
124129 target.windowedX = Math.round(pos.x - priv.distanceX);
125− target.windowedY = Math.round(Math.max(pos.y - priv.distanceY, PanelState.panelHeight));
130+ target.windowedY = Math.round(Math.max(pos.y - priv.distanceY, bounds.top));
126131
127132 if (sensingPoints) { // edge/corner detection when dragging via the touch overlay
128− if (sensingPoints.topLeft.x < priv.triggerArea && sensingPoints.topLeft.y < PanelState.panelHeight + priv.triggerArea
133+ if (sensingPoints.topLeft.x < priv.triggerArea && sensingPoints.topLeft.y < bounds.top + priv.triggerArea
129134 && target.canBeCornerMaximized) { // top left
130− priv.progress = priv.progressInCorner(0, PanelState.panelHeight, sensingPoints.topLeft.x, sensingPoints.topLeft.y);
135+ priv.progress = priv.progressInCorner(bounds.left, bounds.top, sensingPoints.topLeft.x, sensingPoints.topLeft.y);
131136 priv.resetEdges();
132137 priv.nearTopLeftCorner = true;
133138 root.fakeMaximizeTopLeftAnimationRequested(priv.progress);
134− } else if (sensingPoints.topRight.x > stageWidth - priv.triggerArea && sensingPoints.topRight.y < PanelState.panelHeight + priv.triggerArea
139+ } else if (sensingPoints.topRight.x > bounds.right - priv.triggerArea && sensingPoints.topRight.y < bounds.top + priv.triggerArea
135140 && target.canBeCornerMaximized) { // top right
136− priv.progress = priv.progressInCorner(stageWidth, PanelState.panelHeight, sensingPoints.topRight.x, sensingPoints.topRight.y);
141+ priv.progress = priv.progressInCorner(bounds.right, bounds.top, sensingPoints.topRight.x, sensingPoints.topRight.y);
137142 priv.resetEdges();
138143 priv.nearTopRightCorner = true;
139144 root.fakeMaximizeTopRightAnimationRequested(priv.progress);
140− } else if (sensingPoints.bottomLeft.x < priv.triggerArea && sensingPoints.bottomLeft.y > stageHeight - priv.triggerArea
145+ } else if (sensingPoints.bottomLeft.x < priv.triggerArea && sensingPoints.bottomLeft.y > bounds.bottom - priv.triggerArea
141146 && target.canBeCornerMaximized) { // bottom left
142− priv.progress = priv.progressInCorner(0, stageHeight, sensingPoints.bottomLeft.x, sensingPoints.bottomLeft.y);
147+ priv.progress = priv.progressInCorner(bounds.left, bounds.bottom, sensingPoints.bottomLeft.x, sensingPoints.bottomLeft.y);
143148 priv.resetEdges();
144149 priv.nearBottomLeftCorner = true;
145150 root.fakeMaximizeBottomLeftAnimationRequested(priv.progress);
146− } else if (sensingPoints.bottomRight.x > stageWidth - priv.triggerArea && sensingPoints.bottomRight.y > stageHeight - priv.triggerArea
151+ } else if (sensingPoints.bottomRight.x > bounds.right - priv.triggerArea && sensingPoints.bottomRight.y > bounds.bottom - priv.triggerArea
147152 && target.canBeCornerMaximized) { // bottom right
148− priv.progress = priv.progressInCorner(stageWidth, stageHeight, sensingPoints.bottomRight.x, sensingPoints.bottomRight.y);
153+ priv.progress = priv.progressInCorner(bounds.right, bounds.bottom, sensingPoints.bottomRight.x, sensingPoints.bottomRight.y);
149154 priv.resetEdges();
150155 priv.nearBottomRightCorner = true;
151156 root.fakeMaximizeBottomRightAnimationRequested(priv.progress);
@@ -154,13 +159,13 @@ QtObject {
154159 priv.resetEdges();
155160 priv.nearLeftEdge = true;
156161 root.fakeMaximizeLeftAnimationRequested(priv.progress);
157− } else if (sensingPoints.right.x > stageWidth - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
158− priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, stageWidth - priv.triggerArea, stageWidth, 0, 1);
162+ } else if (sensingPoints.right.x > bounds.right - priv.triggerArea && target.canBeMaximizedLeftRight) { // right
163+ priv.progress = MathUtils.clampAndProject(sensingPoints.right.x, bounds.right - priv.triggerArea, bounds.right, 0, 1);
159164 priv.resetEdges();
160165 priv.nearRightEdge = true;
161166 root.fakeMaximizeRightAnimationRequested(priv.progress);
162− } else if (sensingPoints.top.y < PanelState.panelHeight + priv.triggerArea && target.canBeMaximized) { // top
163− priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, PanelState.panelHeight + priv.triggerArea, 0, 0, 1);
167+ } else if (sensingPoints.top.y < bounds.top + priv.triggerArea && target.canBeMaximized) { // top
168+ priv.progress = MathUtils.clampAndProject(sensingPoints.top.y, bounds.top + priv.triggerArea, 0, 0, 1);
164169 priv.resetEdges();
165170 priv.nearTopEdge = true;
166171 root.fakeMaximizeAnimationRequested(priv.progress);