~fboucault/unity-2d/windowimageprovider_remove_timestamp_hack

« back to all changes in this revision

Viewing changes to spread/Windows.qml

  • Committer: Tarmac
  • Author(s): Alberto Mardegan, LDS
  • Date: 2011-11-29 16:58:14 UTC
  • mfrom: (768.7.6 spread-a11y-geometry)
  • Revision ID: tarmac-20111129165814-yg8oqlq28hnn4yeb
[spread] Allow keyboard navigation between workspaces

Turn the Workspace repeater into a GridView, which takes care of giving the
keyboard focus to the proper child element.

Contributed by Alberto Mardegan (mardy). Fixes: 744978. Reviewed by Gerry Boland.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
   The context property called control is the initiator of the entire spread process, and
34
34
   is triggered by D-Bus calls on the C++ side.
35
 
 
36
 
   The ScreenInfo's property availableGeometry represents the available space on the screen (i.e.
37
 
   screen minus launcher, panels, etc.).
38
35
*/
39
36
 
40
37
GridView {
41
38
    id: windows
42
39
 
43
40
    signal clicked
 
41
    signal entered
44
42
    signal windowActivated(variant window)
45
43
 
 
44
    keyNavigationWraps: state == "zoomed"
 
45
 
46
46
    MouseArea {
47
47
        anchors.fill: parent
48
48
        onClicked: windows.clicked()
49
49
        /* Eating all mouse events so that they are not passed beneath the workspace */
50
50
        hoverEnabled: true
 
51
        onEntered: windows.entered()
51
52
    }
52
53
 
53
54
    /* This proxy model takes care of removing all windows that are not on
79
80
    cellWidth: Math.floor(width / columns)
80
81
    cellHeight: height / rows
81
82
 
82
 
    model: filteredByApplication
 
83
    /* Set the model only when the component is ready; otherwise, the
 
84
     * initialization gets somehow messed up and the "columns" and "rows"
 
85
     * variables are set to those of the first workspace. */
 
86
    Component.onCompleted: {
 
87
        model = filteredByApplication
 
88
    }
83
89
 
84
90
    delegate:
85
91
        Item {
93
99
                itemHeight: window.size.height
94
100
                parent: windows
95
101
            }
 
102
            /* We are not using GridView.isCurrentItem because it mysteriously
 
103
             * returns "false" the first time the spread is activated. Couldn't
 
104
             * reproduce the same behaviour with simpler test cases.
 
105
             */
 
106
            focus: GridView.view.currentIndex == index
96
107
 
97
108
            /* Workaround http://bugreports.qt.nokia.com/browse/QTBUG-15642 where onAdd is not called for the first item */
98
109
            //GridView.onAdd:
106
117
                switch (event.key) {
107
118
                    case Qt.Key_Enter:
108
119
                    case Qt.Key_Return:
 
120
                    {
109
121
                        windows.windowActivated(spreadWindow)
110
122
                        event.accepted = true
 
123
                    }
111
124
                }
112
125
            }
113
126
 
121
134
 
122
135
                onEntered: {
123
136
                    windows.currentIndex = index
124
 
                    cell.forceActiveFocus()
 
137
                    /* Make sure the workspace is notified as well */
 
138
                    windows.entered()
125
139
                }
126
140
 
127
141
                onClicked: windows.windowActivated(spreadWindow)
141
155
                Behavior on height { enabled: spreadWindow.animateFollow; NumberAnimation { duration: Utils.transitionDuration; easing.type: Easing.InOutQuad } }
142
156
 
143
157
                windowInfo: window
144
 
                state: windows.state
 
158
                state: windows.state == "screen" ? "screen" : "spread"
145
159
                states: [
146
160
                    State {
147
161
                        name: "screen"
148
162
                        PropertyChanges {
149
163
                            target: spreadWindow
150
 
                            /* Note that we subtract the availableGeometry x and y since window.location is
151
 
                            expressed in global screen coordinates. */
152
164
                            x: window.position.x - declarativeView.globalPosition.x
153
165
                            y: window.position.y - declarativeView.globalPosition.y
154
166
                            width: window.size.width