| 1 |
/* |
| 2 |
KWin - the KDE window manager |
| 3 |
This file is part of the KDE project. |
| 4 |
|
| 5 |
SPDX-FileCopyrightText: 2012, 2013 Martin Gräßlin <[email protected]> |
| 6 |
|
| 7 |
SPDX-License-Identifier: GPL-2.0-or-later |
| 8 |
*/ |
| 9 |
import QtQuick |
| 10 |
import QtQuick.Window |
| 11 |
import org.kde.plasma.core as PlasmaCore |
| 12 |
import org.kde.kirigami 2.20 as Kirigami |
| 13 |
import org.kde.ksvg 1.0 as KSvg |
| 14 |
import org.kde.kwin |
| 15 |
|
| 16 |
PlasmaCore.Window { |
| 17 |
id: dialog |
| 18 |
visible: false |
| 19 |
flags: Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint |
| 20 |
|
| 21 |
width: mainItem.implicitWidth + leftPadding + rightPadding |
| 22 |
height: mainItem.implicitHeight + topPadding + bottomPadding |
| 23 |
|
| 24 |
mainItem: Item { |
| 25 |
function loadConfig() { |
| 26 |
dialogItem.animationDuration = KWin.readConfig("PopupHideDelay", 1000); |
| 27 |
if (KWin.readConfig("TextOnly", "false") == "true") { |
| 28 |
dialogItem.showGrid = false; |
| 29 |
} else { |
| 30 |
dialogItem.showGrid = true; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
id: dialogItem |
| 35 |
property int screenWidth: 0 |
| 36 |
property int screenHeight: 0 |
| 37 |
property int currentIndex: 0 |
| 38 |
property int previousIndex: 0 |
| 39 |
property int animationDuration: 1000 |
| 40 |
property bool showGrid: true |
| 41 |
|
| 42 |
implicitWidth: dialogItem.showGrid ? view.itemWidth * view.columns : Math.ceil(textElement.implicitWidth) |
| 43 |
implicitHeight: dialogItem.showGrid ? view.itemHeight * view.rows + textElement.implicitHeight : textElement.implicitHeight |
| 44 |
|
| 45 |
Kirigami.Heading { |
| 46 |
id: textElement |
| 47 |
anchors.top: dialogItem.showGrid ? parent.top : undefined |
| 48 |
anchors.left: parent.left |
| 49 |
anchors.right: parent.right |
| 50 |
horizontalAlignment: Text.AlignHCenter |
| 51 |
wrapMode: Text.NoWrap |
| 52 |
elide: Text.ElideRight |
| 53 |
text: Workspace.currentDesktop.name |
| 54 |
} |
| 55 |
|
| 56 |
Grid { |
| 57 |
id: view |
| 58 |
columns: 1 |
| 59 |
rows: 1 |
| 60 |
property int itemWidth: dialogItem.screenWidth * Math.min(0.8/columns, 0.1) |
| 61 |
property int itemHeight: Math.min(itemWidth * (dialogItem.screenHeight / dialogItem.screenWidth), dialogItem.screenHeight * Math.min(0.8/rows, 0.1)) |
| 62 |
anchors { |
| 63 |
top: textElement.bottom |
| 64 |
left: parent.left |
| 65 |
right: parent.right |
| 66 |
bottom: parent.bottom |
| 67 |
} |
| 68 |
visible: dialogItem.showGrid |
| 69 |
Repeater { |
| 70 |
id: repeater |
| 71 |
model: Workspace.desktops |
| 72 |
Item { |
| 73 |
width: view.itemWidth |
| 74 |
height: view.itemHeight |
| 75 |
KSvg.FrameSvgItem { |
| 76 |
anchors.fill: parent |
| 77 |
imagePath: "widgets/pager" |
| 78 |
prefix: "normal" |
| 79 |
} |
| 80 |
KSvg.FrameSvgItem { |
| 81 |
id: activeElement |
| 82 |
anchors.fill: parent |
| 83 |
imagePath: "widgets/pager" |
| 84 |
prefix: "active" |
| 85 |
opacity: 0.0 |
| 86 |
Behavior on opacity { |
| 87 |
NumberAnimation { duration: dialogItem.animationDuration/2 } |
| 88 |
} |
| 89 |
} |
| 90 |
Item { |
| 91 |
id: arrowsContainer |
| 92 |
anchors.fill: parent |
| 93 |
Kirigami.Icon { |
| 94 |
anchors.fill: parent |
| 95 |
source: "go-up" |
| 96 |
visible: false |
| 97 |
} |
| 98 |
Kirigami.Icon { |
| 99 |
anchors.fill: parent |
| 100 |
source: "go-down" |
| 101 |
visible: { |
| 102 |
if (dialogItem.currentIndex <= index) { |
| 103 |
// don't show for target desktop |
| 104 |
return false; |
| 105 |
} |
| 106 |
if (index < dialogItem.previousIndex) { |
| 107 |
return false; |
| 108 |
} |
| 109 |
if (dialogItem.currentIndex < dialogItem.previousIndex) { |
| 110 |
// we only go down if the new desktop is higher |
| 111 |
return false; |
| 112 |
} |
| 113 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 114 |
// don't show icons in same row as target desktop |
| 115 |
return false; |
| 116 |
} |
| 117 |
if (dialogItem.previousIndex % view.columns == index % view.columns) { |
| 118 |
// show arrows for icons in same column as the previous desktop |
| 119 |
return true; |
| 120 |
} |
| 121 |
return false; |
| 122 |
} |
| 123 |
} |
| 124 |
Kirigami.Icon { |
| 125 |
anchors.fill: parent |
| 126 |
source: "go-up" |
| 127 |
visible: { |
| 128 |
if (dialogItem.currentIndex >= index) { |
| 129 |
// don't show for target desktop |
| 130 |
return false; |
| 131 |
} |
| 132 |
if (index > dialogItem.previousIndex) { |
| 133 |
return false; |
| 134 |
} |
| 135 |
if (dialogItem.currentIndex > dialogItem.previousIndex) { |
| 136 |
// we only go down if the new desktop is higher |
| 137 |
return false; |
| 138 |
} |
| 139 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 140 |
// don't show icons in same row as target desktop |
| 141 |
return false; |
| 142 |
} |
| 143 |
if (dialogItem.previousIndex % view.columns == index % view.columns) { |
| 144 |
// show arrows for icons in same column as the previous desktop |
| 145 |
return true; |
| 146 |
} |
| 147 |
return false; |
| 148 |
} |
| 149 |
} |
| 150 |
Kirigami.Icon { |
| 151 |
anchors.fill: parent |
| 152 |
source: "go-next" |
| 153 |
visible: { |
| 154 |
if (dialogItem.currentIndex <= index) { |
| 155 |
// we don't show for desktops not on the path |
| 156 |
return false; |
| 157 |
} |
| 158 |
if (index < dialogItem.previousIndex) { |
| 159 |
// we might have to show this icon in case we go up and to the right |
| 160 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 161 |
// can only happen in same row |
| 162 |
if (index % view.columns >= dialogItem.previousIndex % view.columns) { |
| 163 |
// but only for items in the same column or after of the previous desktop |
| 164 |
return true; |
| 165 |
} |
| 166 |
} |
| 167 |
return false; |
| 168 |
} |
| 169 |
if (dialogItem.currentIndex < dialogItem.previousIndex) { |
| 170 |
// we only go right if the new desktop is higher |
| 171 |
return false; |
| 172 |
} |
| 173 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 174 |
// show icons in same row as target desktop |
| 175 |
if (index % view.columns < dialogItem.previousIndex % view.columns) { |
| 176 |
// but only for items in the same column or after of the previous desktop |
| 177 |
return false; |
| 178 |
} |
| 179 |
return true; |
| 180 |
} |
| 181 |
return false; |
| 182 |
} |
| 183 |
} |
| 184 |
Kirigami.Icon { |
| 185 |
anchors.fill: parent |
| 186 |
source: "go-previous" |
| 187 |
visible: { |
| 188 |
if (dialogItem.currentIndex >= index) { |
| 189 |
// we don't show for desktops not on the path |
| 190 |
return false; |
| 191 |
} |
| 192 |
if (index > dialogItem.previousIndex) { |
| 193 |
// we might have to show this icon in case we go down and to the left |
| 194 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 195 |
// can only happen in same row |
| 196 |
if (index % view.columns <= dialogItem.previousIndex % view.columns) { |
| 197 |
// but only for items in the same column or before the previous desktop |
| 198 |
return true; |
| 199 |
} |
| 200 |
} |
| 201 |
return false; |
| 202 |
} |
| 203 |
if (dialogItem.currentIndex > dialogItem.previousIndex) { |
| 204 |
// we only go left if the new desktop is lower |
| 205 |
return false; |
| 206 |
} |
| 207 |
if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { |
| 208 |
// show icons in same row as target desktop |
| 209 |
if (index % view.columns > dialogItem.previousIndex % view.columns) { |
| 210 |
// but only for items in the same column or before of the previous desktop |
| 211 |
return false; |
| 212 |
} |
| 213 |
return true; |
| 214 |
} |
| 215 |
return false; |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
states: [ |
| 220 |
State { |
| 221 |
name: "NORMAL" |
| 222 |
when: index != dialogItem.currentIndex |
| 223 |
PropertyChanges { |
| 224 |
target: activeElement |
| 225 |
opacity: 0.0 |
| 226 |
} |
| 227 |
}, |
| 228 |
State { |
| 229 |
name: "SELECTED" |
| 230 |
when: index == dialogItem.currentIndex |
| 231 |
PropertyChanges { |
| 232 |
target: activeElement |
| 233 |
opacity: 1.0 |
| 234 |
} |
| 235 |
} |
| 236 |
] |
| 237 |
Component.onCompleted: { |
| 238 |
view.state = (index == dialogItem.currentIndex) ? "SELECTED" : "NORMAL" |
| 239 |
} |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
Timer { |
| 245 |
id: timer |
| 246 |
repeat: false |
| 247 |
interval: dialogItem.animationDuration |
| 248 |
onTriggered: dialog.visible = false |
| 249 |
} |
| 250 |
|
| 251 |
Connections { |
| 252 |
target: Options |
| 253 |
function onConfigChanged() { |
| 254 |
dialogItem.loadConfig() |
| 255 |
} |
| 256 |
} |
| 257 |
Component.onCompleted: { |
| 258 |
view.columns = Workspace.desktopGridWidth; |
| 259 |
view.rows = Workspace.desktopGridHeight; |
| 260 |
dialogItem.loadConfig(); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
function show(previous) { |
| 265 |
if (Workspace.isEffectActive("overview")) { |
| 266 |
return; |
| 267 |
} |
| 268 |
dialogItem.previousIndex = Workspace.desktops.indexOf(previous); |
| 269 |
dialogItem.currentIndex = Workspace.desktops.indexOf(Workspace.currentDesktop); |
| 270 |
// screen geometry might have changed |
| 271 |
var screen = Workspace.clientArea(KWin.FullScreenArea, Workspace.activeScreen, Workspace.currentDesktop); |
| 272 |
dialogItem.screenWidth = screen.width; |
| 273 |
dialogItem.screenHeight = screen.height; |
| 274 |
if (dialogItem.showGrid) { |
| 275 |
// non dependable properties might have changed |
| 276 |
view.columns = Workspace.desktopGridWidth; |
| 277 |
view.rows = Workspace.desktopGridHeight; |
| 278 |
} |
| 279 |
dialog.visible = true; |
| 280 |
// position might have changed |
| 281 |
dialog.x = screen.x + screen.width/2 - dialogItem.width/2; |
| 282 |
dialog.y = screen.y + screen.height/2 - dialogItem.height/2; |
| 283 |
// start the hide timer |
| 284 |
timer.restart(); |
| 285 |
} |
| 286 |
} |