~sil2100/unity-2d/precise-security

« back to all changes in this revision

Viewing changes to shell/Shell.qml

  • Committer: Aurelien Gateau
  • Date: 2010-11-10 08:57:29 UTC
  • mto: This revision was merged to the branch mainline in revision 284.
  • Revision ID: aurelien.gateau@canonical.com-20101110085729-fl1ye7impkqhm0w6
Added a section about const correct-ness

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of unity-2d
3
 
 *
4
 
 * Copyright 2012 Canonical Ltd.
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; version 3.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
import QtQuick 1.1
20
 
import Unity2d 1.0
21
 
import "launcher"
22
 
import "common/utils.js" as Utils
23
 
 
24
 
Item {
25
 
    id: shell
26
 
    /* Space reserved by strutManager is taken off screen.availableGeometry but
27
 
       we want the shell to take all the available space, including the one we
28
 
       reserved ourselves via strutManager. */
29
 
    height: declarativeView.screen.availableGeometry.height
30
 
    width: declarativeView.screen.availableGeometry.width + (strutManager.enabled ? strutManager.width : 0)
31
 
 
32
 
    Accessible.name: "shell"
33
 
 
34
 
    LauncherLoader {
35
 
        id: launcherLoader
36
 
        anchors.top: parent.top
37
 
        anchors.bottom: parent.bottom
38
 
        width: 65
39
 
        x: {
40
 
            if (Utils.isLeftToRight()) {
41
 
                return visibilityController.shown ? 0 : -width
42
 
            } else {
43
 
                return visibilityController.shown ? shell.width - width : shell.width
44
 
            }
45
 
        }
46
 
 
47
 
        KeyNavigation.right: dashLoader
48
 
 
49
 
        Binding {
50
 
            target: launcherLoader.item
51
 
            property: "showMenus"
52
 
            value: !dashLoader.item.active
53
 
        }
54
 
 
55
 
        Behavior on x { NumberAnimation { duration: 125 } }
56
 
 
57
 
        Connections {
58
 
            target: declarativeView
59
 
            onDashActiveChanged: {
60
 
                if (declarativeView.dashActive) launcherLoader.visibilityController.beginForceVisible("dash")
61
 
                else {
62
 
                    launcherLoader.visibilityController.endForceVisible("dash")
63
 
                    if (dashLoader.status == Loader.Ready) dashLoader.item.deactivateAllLenses()
64
 
                }
65
 
            }
66
 
        }
67
 
 
68
 
        SpreadMonitor {
69
 
            id: spread
70
 
            onShownChanged: if (shown) {
71
 
                                /* The the spread grabs input and Qt can't properly
72
 
                                   detect we've lost input, so explicitly hide the menus */
73
 
                                launcherLoader.item.hideMenu()
74
 
                                launcherLoader.visibilityController.beginForceVisible("spread")
75
 
                            }
76
 
                            else launcherLoader.visibilityController.endForceVisible("spread")
77
 
        }
78
 
    }
79
 
 
80
 
 
81
 
    Loader {
82
 
        id: dashLoader
83
 
        source: "dash/Dash.qml"
84
 
        anchors.top: parent.top
85
 
        x: Utils.isLeftToRight() ? launcherLoader.width : shell.width - width - launcherLoader.width
86
 
        onLoaded: item.focus = true
87
 
        opacity: item.active ? 1.0 : 0.0
88
 
        focus: item.active
89
 
 
90
 
        Binding {
91
 
            target: dashLoader.item
92
 
            property: "fullscreenWidth"
93
 
            value: shell.width - launcherLoader.width
94
 
        }
95
 
    }
96
 
 
97
 
    Connections {
98
 
        target: declarativeView
99
 
        onLauncherFocusRequested: {
100
 
            launcherLoader.focus = true
101
 
            launcherLoader.item.focusBFB()
102
 
        }
103
 
        onFocusChanged: {
104
 
            /* FIXME: The launcher is forceVisible while it has activeFocus. However even though
105
 
               the documentation says that setting focus=false will make an item lose activeFocus
106
 
               if it has it, this doesn't happen with FocusScopes (and Launcher is a FocusScope).
107
 
               Therefore I'm working around this by giving focus to the shell, which is safe since
108
 
               the shell doesn't react to activeFocus at all.
109
 
               See: https://bugreports.qt.nokia.com/browse/QTBUG-19688 */
110
 
            if (!declarativeView.focus && launcherLoader.activeFocus) shell.focus = true
111
 
        }
112
 
    }
113
 
 
114
 
    Component.onCompleted: declarativeView.show()
115
 
 
116
 
    Keys.onPressed: {
117
 
        if (event.key == Qt.Key_Escape) {
118
 
            declarativeView.forceDeactivateWindow()
119
 
        }
120
 
    }
121
 
 
122
 
    InputShapeManager {
123
 
        target: declarativeView
124
 
 
125
 
        InputShapeRectangle {
126
 
            rectangle: {
127
 
                // FIXME: this results in a 1px wide white rectangle on the launcher edge, we should switch
128
 
                //        to cpp-based edge detection, and later XFixes barriers to get rid of that completely
129
 
                var somewhatShown = Utils.isLeftToRight() ? -launcherLoader.x < launcherLoader.width : launcherLoader.x < shell.width
130
 
                if (somewhatShown) {
131
 
                    return Qt.rect(launcherLoader.x,
132
 
                                   launcherLoader.y,
133
 
                                   launcherLoader.width,
134
 
                                   launcherLoader.height)
135
 
                } else {
136
 
                    // The outerEdgeMouseArea is one pixel bigger on each side so use it
137
 
                    // when the launcher is hidden to have that extra pixel in the border
138
 
                    return Qt.rect(launcherLoader.x + launcherLoader.outerEdgeMouseArea.x,
139
 
                                   launcherLoader.y,
140
 
                                   launcherLoader.outerEdgeMouseArea.width,
141
 
                                   launcherLoader.height)
142
 
                }
143
 
            }
144
 
            enabled: launcherLoader.status == Loader.Ready
145
 
        }
146
 
 
147
 
        InputShapeRectangle {
148
 
            rectangle: if (desktop.isCompositingManagerRunning) {
149
 
                Qt.rect(dashLoader.x, dashLoader.y, dashLoader.width, dashLoader.height)
150
 
            } else {
151
 
                Qt.rect(dashLoader.x, dashLoader.y, dashLoader.width - 7, dashLoader.height - 9)
152
 
            }
153
 
            enabled: dashLoader.status == Loader.Ready && dashLoader.item.active
154
 
            mirrorHorizontally: Utils.isRightToLeft()
155
 
 
156
 
            InputShapeMask {
157
 
                id: shape1
158
 
                source: "shell/dash/artwork/desktop_dash_background_no_transparency.png"
159
 
                color: "red"
160
 
                position: Qt.point(dashLoader.width - 50, dashLoader.height - 49)
161
 
                enabled: declarativeView.dashMode == ShellDeclarativeView.DesktopMode
162
 
            }
163
 
        }
164
 
    }
165
 
 
166
 
    StrutManager {
167
 
        id: strutManager
168
 
        edge: Unity2dPanel.LeftEdge
169
 
        widget: declarativeView
170
 
        height: launcherLoader.height
171
 
        width: launcherLoader.width
172
 
        enabled: Utils.clamp(launcher2dConfiguration.hideMode, 0, 2) == 0
173
 
    }
174
 
}