Warning, /plasma/kwin/src/plugins/desktopchangeosd/package/contents/ui/osd.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 KWin - the KDE window manager 0003 This file is part of the KDE project. 0004 0005 SPDX-FileCopyrightText: 2012, 2013 Martin Gräßlin <mgraesslin@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 import QtQuick 0010 import QtQuick.Window 0011 import org.kde.plasma.core as PlasmaCore 0012 import org.kde.kirigami 2.20 as Kirigami 0013 import org.kde.ksvg 1.0 as KSvg 0014 import org.kde.kwin 0015 0016 PlasmaCore.Dialog { 0017 id: dialog 0018 location: PlasmaCore.Types.Floating 0019 visible: false 0020 flags: Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint 0021 outputOnly: true 0022 0023 mainItem: Item { 0024 function loadConfig() { 0025 dialogItem.animationDuration = KWin.readConfig("PopupHideDelay", 1000); 0026 if (KWin.readConfig("TextOnly", "false") == "true") { 0027 dialogItem.showGrid = false; 0028 } else { 0029 dialogItem.showGrid = true; 0030 } 0031 } 0032 0033 id: dialogItem 0034 property int screenWidth: 0 0035 property int screenHeight: 0 0036 property int currentIndex: 0 0037 property int previousIndex: 0 0038 property int animationDuration: 1000 0039 property bool showGrid: true 0040 0041 width: dialogItem.showGrid ? view.itemWidth * view.columns : Math.ceil(textElement.implicitWidth) 0042 height: dialogItem.showGrid ? view.itemHeight * view.rows + textElement.height : textElement.height 0043 0044 Kirigami.Heading { 0045 id: textElement 0046 anchors.top: dialogItem.showGrid ? parent.top : undefined 0047 anchors.left: parent.left 0048 anchors.right: parent.right 0049 horizontalAlignment: Text.AlignHCenter 0050 wrapMode: Text.NoWrap 0051 elide: Text.ElideRight 0052 text: Workspace.currentDesktop.name 0053 } 0054 0055 Grid { 0056 id: view 0057 columns: 1 0058 rows: 1 0059 property int itemWidth: dialogItem.screenWidth * Math.min(0.8/columns, 0.1) 0060 property int itemHeight: Math.min(itemWidth * (dialogItem.screenHeight / dialogItem.screenWidth), dialogItem.screenHeight * Math.min(0.8/rows, 0.1)) 0061 anchors { 0062 top: textElement.bottom 0063 left: parent.left 0064 right: parent.right 0065 bottom: parent.bottom 0066 } 0067 visible: dialogItem.showGrid 0068 Repeater { 0069 id: repeater 0070 model: Workspace.desktops 0071 Item { 0072 width: view.itemWidth 0073 height: view.itemHeight 0074 KSvg.FrameSvgItem { 0075 anchors.fill: parent 0076 imagePath: "widgets/pager" 0077 prefix: "normal" 0078 } 0079 KSvg.FrameSvgItem { 0080 id: activeElement 0081 anchors.fill: parent 0082 imagePath: "widgets/pager" 0083 prefix: "active" 0084 opacity: 0.0 0085 Behavior on opacity { 0086 NumberAnimation { duration: dialogItem.animationDuration/2 } 0087 } 0088 } 0089 Item { 0090 id: arrowsContainer 0091 anchors.fill: parent 0092 Kirigami.Icon { 0093 anchors.fill: parent 0094 source: "go-up" 0095 visible: false 0096 } 0097 Kirigami.Icon { 0098 anchors.fill: parent 0099 source: "go-down" 0100 visible: { 0101 if (dialogItem.currentIndex <= index) { 0102 // don't show for target desktop 0103 return false; 0104 } 0105 if (index < dialogItem.previousIndex) { 0106 return false; 0107 } 0108 if (dialogItem.currentIndex < dialogItem.previousIndex) { 0109 // we only go down if the new desktop is higher 0110 return false; 0111 } 0112 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0113 // don't show icons in same row as target desktop 0114 return false; 0115 } 0116 if (dialogItem.previousIndex % view.columns == index % view.columns) { 0117 // show arrows for icons in same column as the previous desktop 0118 return true; 0119 } 0120 return false; 0121 } 0122 } 0123 Kirigami.Icon { 0124 anchors.fill: parent 0125 source: "go-up" 0126 visible: { 0127 if (dialogItem.currentIndex >= index) { 0128 // don't show for target desktop 0129 return false; 0130 } 0131 if (index > dialogItem.previousIndex) { 0132 return false; 0133 } 0134 if (dialogItem.currentIndex > dialogItem.previousIndex) { 0135 // we only go down if the new desktop is higher 0136 return false; 0137 } 0138 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0139 // don't show icons in same row as target desktop 0140 return false; 0141 } 0142 if (dialogItem.previousIndex % view.columns == index % view.columns) { 0143 // show arrows for icons in same column as the previous desktop 0144 return true; 0145 } 0146 return false; 0147 } 0148 } 0149 Kirigami.Icon { 0150 anchors.fill: parent 0151 source: "go-next" 0152 visible: { 0153 if (dialogItem.currentIndex <= index) { 0154 // we don't show for desktops not on the path 0155 return false; 0156 } 0157 if (index < dialogItem.previousIndex) { 0158 // we might have to show this icon in case we go up and to the right 0159 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0160 // can only happen in same row 0161 if (index % view.columns >= dialogItem.previousIndex % view.columns) { 0162 // but only for items in the same column or after of the previous desktop 0163 return true; 0164 } 0165 } 0166 return false; 0167 } 0168 if (dialogItem.currentIndex < dialogItem.previousIndex) { 0169 // we only go right if the new desktop is higher 0170 return false; 0171 } 0172 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0173 // show icons in same row as target desktop 0174 if (index % view.columns < dialogItem.previousIndex % view.columns) { 0175 // but only for items in the same column or after of the previous desktop 0176 return false; 0177 } 0178 return true; 0179 } 0180 return false; 0181 } 0182 } 0183 Kirigami.Icon { 0184 anchors.fill: parent 0185 source: "go-previous" 0186 visible: { 0187 if (dialogItem.currentIndex >= index) { 0188 // we don't show for desktops not on the path 0189 return false; 0190 } 0191 if (index > dialogItem.previousIndex) { 0192 // we might have to show this icon in case we go down and to the left 0193 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0194 // can only happen in same row 0195 if (index % view.columns <= dialogItem.previousIndex % view.columns) { 0196 // but only for items in the same column or before the previous desktop 0197 return true; 0198 } 0199 } 0200 return false; 0201 } 0202 if (dialogItem.currentIndex > dialogItem.previousIndex) { 0203 // we only go left if the new desktop is lower 0204 return false; 0205 } 0206 if (Math.floor(dialogItem.currentIndex/view.columns) == Math.floor(index/view.columns)) { 0207 // show icons in same row as target desktop 0208 if (index % view.columns > dialogItem.previousIndex % view.columns) { 0209 // but only for items in the same column or before of the previous desktop 0210 return false; 0211 } 0212 return true; 0213 } 0214 return false; 0215 } 0216 } 0217 } 0218 states: [ 0219 State { 0220 name: "NORMAL" 0221 when: index != dialogItem.currentIndex 0222 PropertyChanges { 0223 target: activeElement 0224 opacity: 0.0 0225 } 0226 }, 0227 State { 0228 name: "SELECTED" 0229 when: index == dialogItem.currentIndex 0230 PropertyChanges { 0231 target: activeElement 0232 opacity: 1.0 0233 } 0234 } 0235 ] 0236 Component.onCompleted: { 0237 view.state = (index == dialogItem.currentIndex) ? "SELECTED" : "NORMAL" 0238 } 0239 } 0240 } 0241 } 0242 0243 Timer { 0244 id: timer 0245 repeat: false 0246 interval: dialogItem.animationDuration 0247 onTriggered: dialog.visible = false 0248 } 0249 0250 Connections { 0251 target: Options 0252 function onConfigChanged() { 0253 dialogItem.loadConfig() 0254 } 0255 } 0256 Component.onCompleted: { 0257 view.columns = Workspace.desktopGridWidth; 0258 view.rows = Workspace.desktopGridHeight; 0259 dialogItem.loadConfig(); 0260 } 0261 } 0262 0263 function show(previous) { 0264 if (Workspace.isEffectActive("overview")) { 0265 return; 0266 } 0267 dialogItem.previousIndex = Workspace.desktops.indexOf(previous); 0268 dialogItem.currentIndex = Workspace.desktops.indexOf(Workspace.currentDesktop); 0269 // screen geometry might have changed 0270 var screen = Workspace.clientArea(KWin.FullScreenArea, Workspace.activeScreen, Workspace.currentDesktop); 0271 dialogItem.screenWidth = screen.width; 0272 dialogItem.screenHeight = screen.height; 0273 if (dialogItem.showGrid) { 0274 // non dependable properties might have changed 0275 view.columns = Workspace.desktopGridWidth; 0276 view.rows = Workspace.desktopGridHeight; 0277 } 0278 dialog.visible = true; 0279 // position might have changed 0280 dialog.x = screen.x + screen.width/2 - dialogItem.width/2; 0281 dialog.y = screen.y + screen.height/2 - dialogItem.height/2; 0282 // start the hide timer 0283 timer.restart(); 0284 } 0285 }