Warning, /plasma/latte-dock/containment/package/contents/ui/layouts/EnvironmentActions.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: 2019 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 import QtQuick 2.7 0007 0008 import org.kde.plasma.core 2.0 as PlasmaCore 0009 import org.kde.plasma.plasmoid 2.0 0010 0011 import org.kde.latte.core 0.2 as LatteCore 0012 0013 import org.kde.latte.private.containment 0.1 as LatteContainment 0014 0015 import org.kde.latte.abilities.items 0.1 as AbilityItem 0016 0017 import "loaders" as Loaders 0018 0019 Loader { 0020 id: environmentLoader 0021 0022 width: root.isHorizontal ? length : localThickness 0023 height: root.isVertical ? length : localThickness 0024 0025 property int alignment: LatteCore.Types.BottomEdgeCenterAlign 0026 0027 readonly property bool useAllLayouts: root.myView.alignment === LatteCore.Types.Justify 0028 0029 readonly property int localThickness: active ? metrics.totals.thickness + metrics.margin.screenEdge : 0 0030 readonly property int length: { 0031 if (!active) { 0032 return 0; 0033 } 0034 0035 if (screenEdgeMarginEnabled && root.floatingInternalGapIsForced) { 0036 return root.isHorizontal ? root.width : root.height; 0037 } 0038 0039 return useAllLayouts ? root.maxLength : background.totals.visualLength; 0040 } 0041 0042 sourceComponent: MouseArea{ 0043 id: mainArea 0044 acceptedButtons: Qt.LeftButton | Qt.MidButton 0045 hoverEnabled: true 0046 0047 property bool wheelIsBlocked: false 0048 0049 property int lastPressX: -1 0050 property int lastPressY: -1 0051 0052 onClicked: { 0053 if (root.closeActiveWindowEnabled && mouse.button === Qt.MidButton) { 0054 selectedWindowsTracker.lastActiveWindow.requestClose(); 0055 } 0056 } 0057 0058 onPressed: { 0059 if (!root.dragActiveWindowEnabled) { 0060 return; 0061 } 0062 0063 if (mouse.button === Qt.LeftButton && selectedWindowsTracker.lastActiveWindow.canBeDragged()) { 0064 lastPressX = mouse.x; 0065 lastPressY = mouse.y; 0066 dragWindowTimer.start(); 0067 } 0068 } 0069 0070 onReleased: { 0071 lastPressX = -1; 0072 lastPressY = -1; 0073 } 0074 0075 onPositionChanged: { 0076 if (!root.dragActiveWindowEnabled || !(mainArea.pressedButtons & Qt.LeftButton)) { 0077 return; 0078 } 0079 0080 var stepX = Math.abs(lastPressX-mouse.x); 0081 var stepY = Math.abs(lastPressY-mouse.y); 0082 var threshold = 5; 0083 0084 var tryDrag = mainArea.pressed && (stepX>threshold || stepY>threshold); 0085 0086 if ( tryDrag && selectedWindowsTracker.lastActiveWindow.canBeDragged()) { 0087 dragWindowTimer.stop(); 0088 activateDragging(); 0089 } 0090 } 0091 0092 onDoubleClicked: { 0093 if (!root.dragActiveWindowEnabled) { 0094 return; 0095 } 0096 0097 dragWindowTimer.stop(); 0098 selectedWindowsTracker.lastActiveWindow.requestToggleMaximized(); 0099 } 0100 0101 onWheel: { 0102 if (wheelIsBlocked) { 0103 return; 0104 } 0105 0106 if (root.scrollAction === LatteContainment.Types.ScrollNone) { 0107 root.emptyAreasWheel(wheel); 0108 return; 0109 } 0110 0111 wheelIsBlocked = true; 0112 scrollDelayer.start(); 0113 0114 var delta = 0; 0115 0116 if (wheel.angleDelta.y>=0 && wheel.angleDelta.x>=0) { 0117 delta = Math.max(wheel.angleDelta.y, wheel.angleDelta.x); 0118 } else { 0119 delta = Math.min(wheel.angleDelta.y, wheel.angleDelta.x); 0120 } 0121 0122 var angle = delta / 8; 0123 0124 var ctrlPressed = (wheel.modifiers & Qt.ControlModifier); 0125 0126 if (angle>10) { 0127 //! upwards 0128 if (root.scrollAction === LatteContainment.Types.ScrollDesktops) { 0129 latteView.windowsTracker.switchToPreviousVirtualDesktop(); 0130 } else if (root.scrollAction === LatteContainment.Types.ScrollActivities) { 0131 latteView.windowsTracker.switchToPreviousActivity(); 0132 } else if (root.scrollAction === LatteContainment.Types.ScrollToggleMinimized) { 0133 if (!ctrlPressed) { 0134 tasksLoader.item.activateNextPrevTask(true); 0135 } else if (!selectedWindowsTracker.lastActiveWindow.isMaximized){ 0136 selectedWindowsTracker.lastActiveWindow.requestToggleMaximized(); 0137 } 0138 } else if (tasksLoader.active) { 0139 tasksLoader.item.activateNextPrevTask(true); 0140 } 0141 } else if (angle<-10) { 0142 //! downwards 0143 if (root.scrollAction === LatteContainment.Types.ScrollDesktops) { 0144 latteView.windowsTracker.switchToNextVirtualDesktop(); 0145 } else if (root.scrollAction === LatteContainment.Types.ScrollActivities) { 0146 latteView.windowsTracker.switchToNextActivity(); 0147 } else if (root.scrollAction === LatteContainment.Types.ScrollToggleMinimized) { 0148 if (!ctrlPressed) { 0149 if (selectedWindowsTracker.lastActiveWindow.isValid 0150 && !selectedWindowsTracker.lastActiveWindow.isMinimized 0151 && selectedWindowsTracker.lastActiveWindow.isMaximized){ 0152 //! maximized 0153 selectedWindowsTracker.lastActiveWindow.requestToggleMaximized(); 0154 } else if (selectedWindowsTracker.lastActiveWindow.isValid 0155 && !selectedWindowsTracker.lastActiveWindow.isMinimized 0156 && !selectedWindowsTracker.lastActiveWindow.isMaximized) { 0157 //! normal 0158 selectedWindowsTracker.lastActiveWindow.requestToggleMinimized(); 0159 } 0160 } else if (selectedWindowsTracker.lastActiveWindow.isMaximized) { 0161 selectedWindowsTracker.lastActiveWindow.requestToggleMaximized(); 0162 } 0163 } else if (tasksLoader.active) { 0164 tasksLoader.item.activateNextPrevTask(false); 0165 } 0166 } 0167 } 0168 0169 Loaders.Tasks{ 0170 id: tasksLoader 0171 } 0172 0173 function activateDragging(){ 0174 selectedWindowsTracker.requestMoveLastWindow(mainArea.mouseX, mainArea.mouseY); 0175 mainArea.lastPressX = -1; 0176 mainArea.lastPressY = -1; 0177 } 0178 0179 //! Timers 0180 Timer { 0181 id: dragWindowTimer 0182 interval: 500 0183 onTriggered: { 0184 if (mainArea.pressed && selectedWindowsTracker.lastActiveWindow.canBeDragged()) { 0185 mainArea.activateDragging(); 0186 } 0187 } 0188 } 0189 0190 //! A timer is needed in order to handle also touchpads that probably 0191 //! send too many signals very fast. This way the signals per sec are limited. 0192 //! The user needs to have a steady normal scroll in order to not 0193 //! notice a annoying delay 0194 Timer{ 0195 id: scrollDelayer 0196 0197 interval: 200 0198 onTriggered: mainArea.wheelIsBlocked = false; 0199 } 0200 0201 //! Background Indicator 0202 AbilityItem.IndicatorLevel { 0203 id: indicatorBackLayer 0204 anchors.fill: parent 0205 0206 level.isDrawn: root.indicators.isEnabled 0207 level.isBackground: true 0208 level.indicator: AbilityItem.IndicatorObject{ 0209 animations: root.animations 0210 metrics: root.metrics 0211 host: root.indicators 0212 0213 isEmptySpace: true 0214 isPressed: mainArea.pressed 0215 panelOpacity: root.background.currentOpacity 0216 shadowColor: root.myView.itemShadow.shadowSolidColor 0217 palette: colorizerManager.applyTheme 0218 0219 iconBackgroundColor: "brown" 0220 iconGlowColor: "pink" 0221 } 0222 0223 Connections { 0224 target: mainArea 0225 enabled: root.indicators.info.needsMouseEventCoordinates 0226 onPressed: indicatorBackLayer.level.mousePressed(mouse.x, mouse.y, mouse.button); 0227 onReleased: indicatorBackLayer.level.mouseReleased(mouse.x, mouse.y, mouse.button); 0228 } 0229 } 0230 } 0231 0232 states:[ 0233 State { 0234 name: "bottomCenter" 0235 when: (alignment === LatteCore.Types.BottomEdgeCenterAlign) 0236 0237 AnchorChanges { 0238 target: environmentLoader 0239 anchors{ top:undefined; bottom:_mainLayout.bottom; left:undefined; right:undefined; 0240 horizontalCenter: _mainLayout.horizontalCenter; verticalCenter:undefined} 0241 } 0242 }, 0243 State { 0244 name: "bottomLeft" 0245 when: (alignment === LatteCore.Types.BottomEdgeLeftAlign) 0246 0247 AnchorChanges { 0248 target: environmentLoader 0249 anchors{ top:undefined; bottom:_mainLayout.bottom; left:_mainLayout.left; right:undefined; 0250 horizontalCenter: undefined; verticalCenter:undefined} 0251 } 0252 }, 0253 State { 0254 name: "bottomRight" 0255 when: (alignment === LatteCore.Types.BottomEdgeRightAlign) 0256 0257 AnchorChanges { 0258 target: environmentLoader 0259 anchors{ top:undefined; bottom: _mainLayout.bottom; left:undefined; right:_mainLayout.right; 0260 horizontalCenter: undefined; verticalCenter:undefined} 0261 } 0262 }, 0263 State { 0264 name: "topCenter" 0265 when: (alignment === LatteCore.Types.TopEdgeCenterAlign) 0266 0267 AnchorChanges { 0268 target: environmentLoader 0269 anchors{ top: _mainLayout.top; bottom:undefined; left:undefined; right:undefined; 0270 horizontalCenter: _mainLayout.horizontalCenter; verticalCenter:undefined} 0271 } 0272 }, 0273 State { 0274 name: "topLeft" 0275 when: (alignment === LatteCore.Types.TopEdgeLeftAlign) 0276 0277 AnchorChanges { 0278 target: environmentLoader 0279 anchors{ top: _mainLayout.top; bottom:undefined; left: _mainLayout.left; right:undefined; 0280 horizontalCenter: undefined; verticalCenter:undefined} 0281 } 0282 }, 0283 State { 0284 name: "topRight" 0285 when: (alignment === LatteCore.Types.TopEdgeRightAlign) 0286 0287 AnchorChanges { 0288 target: environmentLoader 0289 anchors{ top: _mainLayout.top; bottom:undefined; left:undefined; right: _mainLayout.right; 0290 horizontalCenter: undefined; verticalCenter:undefined} 0291 } 0292 }, 0293 State { 0294 name: "leftCenter" 0295 when: (alignment === LatteCore.Types.LeftEdgeCenterAlign) 0296 0297 AnchorChanges { 0298 target: environmentLoader 0299 anchors{ top:undefined; bottom:undefined; left: _mainLayout.left; right:undefined; 0300 horizontalCenter:undefined; verticalCenter: _mainLayout.verticalCenter} 0301 } 0302 }, 0303 State { 0304 name: "leftTop" 0305 when: (alignment === LatteCore.Types.LeftEdgeTopAlign) 0306 0307 AnchorChanges { 0308 target: environmentLoader 0309 anchors{ top:mainLayout.top; bottom:undefined; left: _mainLayout.left; right:undefined; 0310 horizontalCenter:undefined; verticalCenter: undefined} 0311 } 0312 }, 0313 State { 0314 name: "leftBottom" 0315 when: (alignment === LatteCore.Types.LeftEdgeBottomAlign) 0316 0317 AnchorChanges { 0318 target: environmentLoader 0319 anchors{ top:undefined; bottom:_mainLayout.bottom; left: _mainLayout.left; right:undefined; 0320 horizontalCenter:undefined; verticalCenter: undefined} 0321 } 0322 }, 0323 State { 0324 name: "rightCenter" 0325 when: (alignment === LatteCore.Types.RightEdgeCenterAlign) 0326 0327 AnchorChanges { 0328 target: environmentLoader 0329 anchors{ top:undefined; bottom:undefined; left:undefined; right: _mainLayout.right; 0330 horizontalCenter:undefined; verticalCenter: _mainLayout.verticalCenter} 0331 } 0332 }, 0333 State { 0334 name: "rightTop" 0335 when: (alignment === LatteCore.Types.RightEdgeTopAlign) 0336 0337 AnchorChanges { 0338 target: environmentLoader 0339 anchors{ top:_mainLayout.top; bottom:undefined; left:undefined; right: _mainLayout.right; 0340 horizontalCenter:undefined; verticalCenter: undefined} 0341 } 0342 }, 0343 State { 0344 name: "rightBottom" 0345 when: (alignment === LatteCore.Types.RightEdgeBottomAlign) 0346 0347 AnchorChanges { 0348 target: environmentLoader 0349 anchors{ top:undefined; bottom:_mainLayout.bottom; left:undefined; right: _mainLayout.right; 0350 horizontalCenter:undefined; verticalCenter: undefined} 0351 } 0352 } 0353 ] 0354 }