2 * Copyright (C) 2016 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
26 property int screenWidth: 0
27 property int screenHeight: 0
28 property int leftMargin: 0
29 property int minimumY: 0
32 var defaultWidth = units.gu(60);
33 var defaultHeight = units.gu(50);
34 var windowGeometry = WindowStateStorage.getGeometry(target.appId,
35 Qt.rect(target.windowedX, target.windowedY, defaultWidth, defaultHeight));
37 target.windowedWidth = Qt.binding(function() { return Math.min(Math.max(windowGeometry.width, target.minimumWidth), screenWidth - root.leftMargin); });
38 target.windowedHeight = Qt.binding(function() { return Math.min(Math.max(windowGeometry.height, target.minimumHeight),
39 screenHeight - (target.fullscreen ? 0 : minimumY)); });
40 target.windowedX = Qt.binding(function() { return Math.max(Math.min(windowGeometry.x, screenWidth - root.leftMargin - target.windowedWidth),
41 (target.fullscreen ? 0 : root.leftMargin)); });
42 target.windowedY = Qt.binding(function() { return Math.max(Math.min(windowGeometry.y, screenHeight - target.windowedHeight), minimumY); });
44 var windowState = WindowStateStorage.getState(target.appId, WindowStateStorage.WindowStateNormal)
45 target.restore(false /* animated */, windowState);
47 target.updateNormalGeometry();
49 // initialize the x/y to restore to
50 target.restoredX = target.normalX;
51 target.restoredY = target.normalY;
55 var state = target.windowState;
56 if (state === WindowStateStorage.WindowStateRestored) {
57 state = WindowStateStorage.WindowStateNormal;
60 WindowStateStorage.saveState(target.appId, state & ~WindowStateStorage.WindowStateMinimized); // clear the minimized bit when saving
61 WindowStateStorage.saveGeometry(target.appId, Qt.rect(target.normalX, target.normalY, target.normalWidth, target.normalHeight));