effects/{private,desktopgrid,overview}: Clean up QML/JS code and bump imports

This commit is contained in:
ivan tkachenko 2022-08-04 19:39:11 +03:00
parent f892c9510e
commit 8feaa8922a
No known key found for this signature in database
GPG key ID: AF72731B7C654CB3
8 changed files with 94 additions and 93 deletions

View file

@ -46,7 +46,7 @@ FocusScope {
Connections {
target: effect
function onItemDroppedOutOfScreen(globalPos, item, screen) {
if (screen != targetScreen) {
if (screen !== targetScreen) {
return;
}
const pos = screen.mapFromGlobal(globalPos);
@ -91,7 +91,7 @@ FocusScope {
WindowHeap {
id: heap
function resetPosition () {
function resetPosition() {
x = 0;
y = 0;
}
@ -113,8 +113,8 @@ FocusScope {
screenName: targetScreen.name
clientModel: desktopView.clientModel
windowType: ~KWinComponents.ClientFilterModel.Dock &
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification;
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification
}
delegate: WindowHeapDelegate {
windowHeap: heap

View file

@ -5,10 +5,10 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
import QtGraphicalEffects 1.15
import org.kde.kwin 3.0 as KWinComponents
import org.kde.kwin.private.effects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
@ -26,17 +26,17 @@ Rectangle {
color: "black"
function start() {
container.animationEnabled = true;
container.organized = true;
animationEnabled = true;
organized = true;
}
function stop() {
container.organized = false;
organized = false;
}
function switchTo(desktopId) {
KWinComponents.Workspace.currentDesktop = desktopId;
container.effect.deactivate(container.effect.animationDuration);
effect.deactivate(effect.animationDuration);
}
function selectNext(direction) {
@ -87,19 +87,19 @@ Rectangle {
}
Keys.onPressed: {
if (event.key == Qt.Key_Escape) {
if (event.key === Qt.Key_Escape) {
effect.deactivate(effect.animationDuration);
} else if (event.key == Qt.Key_Plus || event.key == Qt.Key_Equal) {
} else if (event.key === Qt.Key_Plus || event.key === Qt.Key_Equal) {
addButton.clicked();
} else if (event.key == Qt.Key_Minus) {
} else if (event.key === Qt.Key_Minus) {
removeButton.clicked();
} else if (event.key >= Qt.Key_F1 && event.key <= Qt.Key_F12) {
const desktopId = (event.key - Qt.Key_F1) + 1;
switchTo(desktopId);
} else if (event.key >= Qt.Key_0 && event.key <= Qt.Key_9) {
const desktopId = event.key == Qt.Key_0 ? 10 : (event.key - Qt.Key_0);
const desktopId = event.key === Qt.Key_0 ? 10 : (event.key - Qt.Key_0);
switchTo(desktopId);
} else if (event.key == Qt.Key_Up) {
} else if (event.key === Qt.Key_Up) {
event.accepted = selectNext(WindowHeap.Direction.Up);
if (!event.accepted) {
let view = effect.getView(Qt.TopEdge)
@ -107,7 +107,7 @@ Rectangle {
effect.activateView(view)
}
}
} else if (event.key == Qt.Key_Down) {
} else if (event.key === Qt.Key_Down) {
event.accepted = selectNext(WindowHeap.Direction.Down);
if (!event.accepted) {
let view = effect.getView(Qt.BottomEdge)
@ -115,7 +115,7 @@ Rectangle {
effect.activateView(view)
}
}
} else if (event.key == Qt.Key_Left) {
} else if (event.key === Qt.Key_Left) {
event.accepted = selectNext(WindowHeap.Direction.Left);
if (!event.accepted) {
let view = effect.getView(Qt.LeftEdge)
@ -123,7 +123,7 @@ Rectangle {
effect.activateView(view)
}
}
} else if (event.key == Qt.Key_Right) {
} else if (event.key === Qt.Key_Right) {
event.accepted = selectNext(WindowHeap.Direction.Right);
if (!event.accepted) {
let view = effect.getView(Qt.RightEdge)
@ -131,7 +131,7 @@ Rectangle {
effect.activateView(view)
}
}
} else if (event.key == Qt.Key_Return || event.key == Qt.Key_Space) {
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Space) {
for (let i = 0; i < gridRepeater.count; i++) {
if (gridRepeater.itemAt(i).focus) {
switchTo(gridRepeater.itemAt(i).desktop.x11DesktopNumber)
@ -154,7 +154,7 @@ Rectangle {
id: grid
property Item currentItem
readonly property real targetScale : 1 / Math.max(rows, columns)
readonly property real targetScale: 1 / Math.max(rows, columns)
property real panelOpacity: 1
Behavior on x {
@ -199,8 +199,8 @@ Rectangle {
when: container.effect.gestureInProgress
PropertyChanges {
target: grid
x: Math.max(0, container.width / 2 - (width * targetScale) / 2) * container.effect.partialActivationFactor - grid.currentItem.x * (1 - container.effect.partialActivationFactor)
y: Math.max(0, container.height / 2 - (height * targetScale) / 2) * container.effect.partialActivationFactor - grid.currentItem.y * (1 - container.effect.partialActivationFactor)
x: Math.max(0, container.width / 2 - (grid.width * grid.targetScale) / 2) * container.effect.partialActivationFactor - grid.currentItem.x * (1 - container.effect.partialActivationFactor)
y: Math.max(0, container.height / 2 - (grid.height * grid.targetScale) / 2) * container.effect.partialActivationFactor - grid.currentItem.y * (1 - container.effect.partialActivationFactor)
scale: 1 - (1 - grid.targetScale) * container.effect.partialActivationFactor
panelOpacity: 1 - container.effect.partialActivationFactor
}
@ -213,8 +213,8 @@ Rectangle {
when: container.organized
PropertyChanges {
target: grid
x: Math.max(0, container.width / 2 - (width * targetScale) / 2)
y: Math.max(0, container.height / 2 - (height * targetScale) / 2)
x: Math.max(0, container.width / 2 - (grid.width * grid.targetScale) / 2)
y: Math.max(0, container.height / 2 - (grid.height * grid.targetScale) / 2)
scale: grid.targetScale
panelOpacity: 0
}

View file

@ -4,11 +4,11 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
import org.kde.kirigami 2.12 as Kirigami
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kwin 3.0 as KWinComponents
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.core 2.0 as PlasmaCore

View file

@ -4,7 +4,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick 2.15
import org.kde.kwin 3.0 as KWinComponents
Item {

View file

@ -4,15 +4,15 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtGraphicalEffects 1.12
import QtQuick 2.15
import QtGraphicalEffects 1.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kwin 3.0 as KWinComponents
import org.kde.kwin.private.effects 1.0
import org.kde.milou 0.3 as Milou
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kirigami 2.12 as Kirigami
FocusScope {
id: container
@ -257,8 +257,8 @@ FocusScope {
filter: searchField.text
minimizedWindows: !effect.ignoreMinimized
windowType: ~KWinComponents.ClientFilterModel.Dock &
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification
}
onActivated: effect.deactivate();
delegate: WindowHeapDelegate {
@ -269,11 +269,11 @@ FocusScope {
return targetScale; // leave it alone, so it won't affect transitions before they start
}
var localPressPosition = activeDragHandler.centroid.scenePressPosition.y - heap.layout.Kirigami.ScenePosition.y;
if (localPressPosition == 0) {
return 0.1
if (localPressPosition === 0) {
return 0.1;
} else {
var localPosition = activeDragHandler.centroid.scenePosition.y - heap.layout.Kirigami.ScenePosition.y;
return Math.max(0.1, Math.min(localPosition / localPressPosition, 1))
return Math.max(0.1, Math.min(localPosition / localPressPosition, 1));
}
}

View file

@ -4,9 +4,9 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Window 2.12
import org.kde.kirigami 2.12 as Kirigami
import QtQuick 2.15
import QtQuick.Window 2.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kwin 3.0 as KWinComponents
import org.kde.kwin.private.effects 1.0
import org.kde.plasma.components 3.0 as PC3
@ -32,6 +32,7 @@ FocusScope {
property bool animationEnabled: false
property bool absolutePositioning: true
property real padding: 0
// Either a string "activeClass" or a list internalIds of clients
property var showOnly: []
property string activeClass
@ -125,7 +126,7 @@ FocusScope {
}
function findNextItem(selectedIndex, direction) {
if (selectedIndex == -1) {
if (selectedIndex === -1) {
return findFirstItem();
}
@ -147,7 +148,7 @@ FocusScope {
}
if (candidateItem.x + candidateItem.width < selectedItem.x + selectedItem.width) {
if (nextIndex == -1) {
if (nextIndex === -1) {
nextIndex = candidateIndex;
} else {
const nextItem = windowsRepeater.itemAt(nextIndex);
@ -172,11 +173,11 @@ FocusScope {
}
if (selectedItem.x < candidateItem.x) {
if (nextIndex == -1) {
if (nextIndex === -1) {
nextIndex = candidateIndex;
} else {
const nextItem = windowsRepeater.itemAt(nextIndex);
if (nextIndex == -1 || candidateItem.x < nextItem.x) {
if (nextIndex === -1 || candidateItem.x < nextItem.x) {
nextIndex = candidateIndex;
}
}
@ -197,7 +198,7 @@ FocusScope {
}
if (candidateItem.y + candidateItem.height < selectedItem.y + selectedItem.height) {
if (nextIndex == -1) {
if (nextIndex === -1) {
nextIndex = candidateIndex;
} else {
const nextItem = windowsRepeater.itemAt(nextIndex);
@ -222,7 +223,7 @@ FocusScope {
}
if (selectedItem.y < candidateItem.y) {
if (nextIndex == -1) {
if (nextIndex === -1) {
nextIndex = candidateIndex;
} else {
const nextItem = windowsRepeater.itemAt(nextIndex);
@ -239,30 +240,30 @@ FocusScope {
}
function resetSelected() {
heap.selectedIndex = -1;
selectedIndex = -1;
}
function selectNextItem(direction) {
const nextIndex = findNextItem(heap.selectedIndex, direction);
if (nextIndex != -1) {
heap.selectedIndex = nextIndex;
const nextIndex = findNextItem(selectedIndex, direction);
if (nextIndex !== -1) {
selectedIndex = nextIndex;
return true;
}
return false;
}
function selectLastItem(direction) {
let last = heap.selectedIndex;
let last = selectedIndex;
while (true) {
const next = findNextItem(last, direction);
if (next == -1) {
if (next === -1) {
break;
} else {
last = next;
}
}
if (last != -1) {
heap.selectedIndex = last;
if (last !== -1) {
selectedIndex = last;
return true;
}
return false;
@ -301,8 +302,8 @@ FocusScope {
case Qt.Key_Space:
handled = true;
let selectedItem = null;
if (heap.selectedIndex != -1) {
selectedItem = windowsRepeater.itemAt(heap.selectedIndex);
if (selectedIndex !== -1) {
selectedItem = windowsRepeater.itemAt(selectedIndex);
} else {
// If the window heap has only one visible window, activate it.
for (let i = 0; i < windowsRepeater.count; ++i) {
@ -319,7 +320,7 @@ FocusScope {
if (selectedItem) {
handled = true;
KWinComponents.Workspace.activeClient = selectedItem.client;
heap.activated();
activated();
}
break;
default:

View file

@ -4,15 +4,14 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Window 2.12
import org.kde.kirigami 2.12 as Kirigami
import QtQuick 2.15
import QtQuick.Window 2.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.kwin 3.0 as KWinComponents
import org.kde.kwin.private.effects 1.0
import org.kde.plasma.components 3.0 as PC3
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: thumb
@ -20,13 +19,15 @@ Item {
required property int index
required property Item windowHeap
readonly property bool selected: thumb.windowHeap.selectedIndex == index
readonly property bool selected: windowHeap.selectedIndex === index
//TODO: move?
readonly property bool hidden: {
if (thumb.windowHeap.showOnly === "activeClass") {
return thumb.windowHeap.activeClass !== String(thumb.client.resourceName); // thumb.client.resourceName is not an actual String as comes from a QByteArray so === would fail
if (windowHeap.showOnly === "activeClass") {
// client.resourceName is not an actual String as comes from a QByteArray so === would fail
return windowHeap.activeClass !== String(client.resourceName);
} else {
return thumb.windowHeap.showOnly.length && thumb.windowHeap.showOnly.indexOf(client.internalId) == -1;
return windowHeap.showOnly.length !== 0
&& windowHeap.showOnly.indexOf(client.internalId) === -1;
}
}
@ -38,15 +39,15 @@ Item {
//scale up and down the whole thumbnail without affecting layouting
property real targetScale: 1.0
property DragManager activeDragHandler: dragHandler
// Swipe down gesture by touch, in some effects will close the window
readonly property alias downGestureProgress: touchDragHandler.downGestureProgress
signal downGestureTriggered()
Component.onCompleted: {
if (thumb.client.active) {
thumb.windowHeap.activeClass = thumb.client.resourceName;
if (client.active) {
windowHeap.activeClass = client.resourceName;
}
}
Connections {
@ -62,15 +63,15 @@ Item {
if (effect.gestureInProgress) {
return "partial";
}
if (thumb.windowHeap.effectiveOrganized) {
if (windowHeap.effectiveOrganized) {
return hidden ? "active-hidden" : "active";
}
return client.minimized ? "initial-minimized" : "initial";
}
visible: opacity > 0
z: thumb.activeDragHandler.active ? 1000
: client.stackingOrder + (thumb.client.desktop == KWinComponents.Workspace.currentDesktop ? 100 : 0)
z: activeDragHandler.active ? 1000
: client.stackingOrder + (client.desktop === KWinComponents.Workspace.currentDesktop ? 100 : 0)
component TweenBehavior : Behavior {
enabled: thumb.state !== "partial" && thumb.windowHeap.animationEnabled && !thumb.activeDragHandler.active
@ -160,7 +161,6 @@ Item {
anchors.bottomMargin: -height / 4
visible: !thumb.hidden && !activeDragHandler.active
PC3.Label {
id: caption
visible: thumb.windowTitleVisible
@ -213,7 +213,7 @@ Item {
y: (thumb.client.y - targetScreen.geometry.y - (thumb.windowHeap.absolutePositioning ? windowHeap.layout.Kirigami.ScenePosition.y : 0)) * (1 - effect.partialActivationFactor) + cell.y * effect.partialActivationFactor
width: thumb.client.width * (1 - effect.partialActivationFactor) + cell.width * effect.partialActivationFactor
height: thumb.client.height * (1 - effect.partialActivationFactor) + cell.height * effect.partialActivationFactor
opacity: thumb.client.minimized || thumb.client.desktop != KWinComponents.Workspace.currentDesktop ? effect.partialActivationFactor : 1
opacity: thumb.client.minimized || thumb.client.desktop !== KWinComponents.Workspace.currentDesktop ? effect.partialActivationFactor : 1
}
PropertyChanges {
target: icon
@ -278,7 +278,6 @@ Item {
}
}
PlasmaCore.FrameSvgItem {
anchors {
fill: parent
@ -295,7 +294,7 @@ Item {
HoverHandler {
id: hoverHandler
onHoveredChanged: if (hovered != selected) {
onHoveredChanged: if (hovered !== selected) {
thumb.windowHeap.resetSelected();
}
}
@ -331,11 +330,12 @@ Item {
}
}
}
property DragManager activeDragHandler: dragHandler
DragManager {
id: dragHandler
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad | PointerDevice.Stylus
}
DragManager {
id: touchDragHandler
acceptedDevices: PointerDevice.TouchScreen
@ -384,7 +384,7 @@ Item {
Component.onDestruction: {
if (selected) {
thumb.windowHeap.resetSelected();
windowHeap.resetSelected();
}
}
}

View file

@ -4,9 +4,9 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
import QtQuick 2.12
import QtQuick.Layouts 1.4
import QtGraphicalEffects 1.12
import QtQuick 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.15
import org.kde.kwin 3.0 as KWinComponents
import org.kde.kwin.private.effects 1.0
import org.kde.plasma.core 2.0 as PlasmaCore
@ -26,12 +26,12 @@ Item {
readonly property int animationDuration: PlasmaCore.Units.longDuration
function start() {
container.animationEnabled = true;
container.organized = true;
animationEnabled = true;
organized = true;
}
function stop() {
container.organized = false;
organized = false;
}
Keys.onEscapePressed: effect.deactivate(animationDuration);
@ -150,9 +150,9 @@ Item {
switch (container.effect.mode) {
case WindowView.ModeWindowClass:
case WindowView.ModeWindowClassCurrentDesktop:
return "activeClass"
return "activeClass";
default:
return selectedIds
return selectedIds;
}
}
layout.mode: effect.layout
@ -168,9 +168,9 @@ Item {
switch (container.effect.mode) {
case WindowView.ModeCurrentDesktop:
case WindowView.ModeWindowClassCurrentDesktop:
return KWinComponents.Workspace.currentVirtualDesktop
return KWinComponents.Workspace.currentVirtualDesktop;
default:
return undefined
return undefined;
}
}
screenName: targetScreen.name
@ -178,8 +178,8 @@ Item {
filter: effect.searchText
minimizedWindows: !effect.ignoreMinimized
windowType: ~KWinComponents.ClientFilterModel.Dock &
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification;
~KWinComponents.ClientFilterModel.Desktop &
~KWinComponents.ClientFilterModel.Notification
}
delegate: WindowHeapDelegate {
windowHeap: heap