2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2013-03-21 11:09:08 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2012, 2013 Martin Gräßlin <mgraesslin@kde.org>
|
2013-03-21 11:09:08 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2013-11-07 09:35:26 +00:00
|
|
|
import QtQuick 2.0;
|
2014-09-03 07:47:21 +00:00
|
|
|
import QtQuick.Window 2.0;
|
2013-11-07 09:35:26 +00:00
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore;
|
2018-10-28 16:46:15 +00:00
|
|
|
import org.kde.plasma.extras 2.0 as PlasmaExtras
|
2013-11-07 09:35:26 +00:00
|
|
|
import org.kde.plasma.components 2.0 as Plasma;
|
2014-03-25 16:13:43 +00:00
|
|
|
import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons;
|
2013-11-07 09:35:26 +00:00
|
|
|
import org.kde.kwin 2.0;
|
2013-03-21 11:09:08 +00:00
|
|
|
|
|
|
|
PlasmaCore.Dialog {
|
|
|
|
id: dialog
|
2013-11-07 13:29:44 +00:00
|
|
|
location: PlasmaCore.Types.Floating
|
2013-03-21 11:09:08 +00:00
|
|
|
visible: false
|
2016-08-11 06:45:41 +00:00
|
|
|
flags: Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint
|
2014-01-21 08:01:11 +00:00
|
|
|
outputOnly: true
|
2013-03-21 11:09:08 +00:00
|
|
|
|
|
|
|
mainItem: Item {
|
|
|
|
function loadConfig() {
|
2013-11-07 09:35:26 +00:00
|
|
|
dialogItem.animationDuration = KWin.readConfig("PopupHideDelay", 1000);
|
|
|
|
if (KWin.readConfig("TextOnly", "false") == "true") {
|
2013-03-21 11:09:08 +00:00
|
|
|
dialogItem.showGrid = false;
|
|
|
|
} else {
|
|
|
|
dialogItem.showGrid = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function show() {
|
|
|
|
if (dialogItem.currentDesktop == workspace.currentDesktop - 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dialogItem.previousDesktop = dialogItem.currentDesktop;
|
|
|
|
timer.stop();
|
|
|
|
dialogItem.currentDesktop = workspace.currentDesktop - 1;
|
|
|
|
textElement.text = workspace.desktopName(workspace.currentDesktop);
|
|
|
|
// screen geometry might have changed
|
|
|
|
var screen = workspace.clientArea(KWin.FullScreenArea, workspace.activeScreen, workspace.currentDesktop);
|
|
|
|
dialogItem.screenWidth = screen.width;
|
|
|
|
dialogItem.screenHeight = screen.height;
|
|
|
|
if (dialogItem.showGrid) {
|
|
|
|
// non dependable properties might have changed
|
|
|
|
view.columns = workspace.desktopGridWidth;
|
|
|
|
view.rows = workspace.desktopGridHeight;
|
|
|
|
}
|
2013-11-07 09:35:26 +00:00
|
|
|
dialog.visible = true;
|
2013-03-21 11:09:08 +00:00
|
|
|
// position might have changed
|
|
|
|
dialog.x = screen.x + screen.width/2 - dialogItem.width/2;
|
|
|
|
dialog.y = screen.y + screen.height/2 - dialogItem.height/2;
|
|
|
|
// start the hide timer
|
|
|
|
timer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
id: dialogItem
|
|
|
|
property int screenWidth: 0
|
|
|
|
property int screenHeight: 0
|
|
|
|
// we count desktops starting from 0 to have it better match the layout in the Grid
|
|
|
|
property int currentDesktop: 0
|
|
|
|
property int previousDesktop: 0
|
|
|
|
property int animationDuration: 1000
|
|
|
|
property bool showGrid: true
|
|
|
|
|
2018-10-28 16:46:15 +00:00
|
|
|
width: dialogItem.showGrid ? view.itemWidth * view.columns : Math.ceil(textElement.implicitWidth)
|
2013-03-21 11:09:08 +00:00
|
|
|
height: dialogItem.showGrid ? view.itemHeight * view.rows + textElement.height : textElement.height
|
|
|
|
|
2018-10-28 16:46:15 +00:00
|
|
|
PlasmaExtras.Heading {
|
2013-03-21 11:09:08 +00:00
|
|
|
id: textElement
|
|
|
|
anchors.top: dialogItem.showGrid ? parent.top : undefined
|
2018-10-28 16:46:15 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.right: parent.right
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
elide: Text.ElideRight
|
2013-03-21 11:09:08 +00:00
|
|
|
text: workspace.desktopName(workspace.currentDesktop)
|
|
|
|
}
|
2018-10-28 16:46:15 +00:00
|
|
|
|
2013-03-21 11:09:08 +00:00
|
|
|
Grid {
|
|
|
|
id: view
|
|
|
|
columns: 1
|
|
|
|
rows: 1
|
|
|
|
property int itemWidth: dialogItem.screenWidth * Math.min(0.8/columns, 0.1)
|
|
|
|
property int itemHeight: Math.min(itemWidth * (dialogItem.screenHeight / dialogItem.screenWidth), dialogItem.screenHeight * Math.min(0.8/rows, 0.1))
|
|
|
|
anchors {
|
|
|
|
top: textElement.bottom
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
|
|
|
bottom: parent.bottom
|
|
|
|
}
|
|
|
|
visible: dialogItem.showGrid
|
|
|
|
Repeater {
|
|
|
|
id: repeater
|
|
|
|
model: workspace.desktops
|
|
|
|
Item {
|
|
|
|
width: view.itemWidth
|
|
|
|
height: view.itemHeight
|
|
|
|
PlasmaCore.FrameSvgItem {
|
|
|
|
anchors.fill: parent
|
|
|
|
imagePath: "widgets/pager"
|
|
|
|
prefix: "normal"
|
|
|
|
}
|
|
|
|
PlasmaCore.FrameSvgItem {
|
|
|
|
id: activeElement
|
|
|
|
anchors.fill: parent
|
|
|
|
imagePath: "widgets/pager"
|
|
|
|
prefix: "active"
|
|
|
|
opacity: 0.0
|
|
|
|
Behavior on opacity {
|
|
|
|
NumberAnimation { duration: dialogItem.animationDuration/2 }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Item {
|
|
|
|
id: arrowsContainer
|
|
|
|
anchors.fill: parent
|
2014-03-25 16:13:43 +00:00
|
|
|
KQuickControlsAddons.QIconItem {
|
2013-03-21 11:09:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
icon: "go-up"
|
|
|
|
visible: false
|
|
|
|
}
|
2014-03-25 16:13:43 +00:00
|
|
|
KQuickControlsAddons.QIconItem {
|
2013-03-21 11:09:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
icon: "go-down"
|
|
|
|
visible: {
|
|
|
|
if (dialogItem.currentDesktop <= index) {
|
|
|
|
// don't show for target desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (index < dialogItem.previousDesktop) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.currentDesktop < dialogItem.previousDesktop) {
|
|
|
|
// we only go down if the new desktop is higher
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// don't show icons in same row as target desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.previousDesktop % view.columns == index % view.columns) {
|
|
|
|
// show arrows for icons in same column as the previous desktop
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 16:13:43 +00:00
|
|
|
KQuickControlsAddons.QIconItem {
|
2013-03-21 11:09:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
icon: "go-up"
|
|
|
|
visible: {
|
|
|
|
if (dialogItem.currentDesktop >= index) {
|
|
|
|
// don't show for target desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (index > dialogItem.previousDesktop) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.currentDesktop > dialogItem.previousDesktop) {
|
|
|
|
// we only go down if the new desktop is higher
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// don't show icons in same row as target desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.previousDesktop % view.columns == index % view.columns) {
|
|
|
|
// show arrows for icons in same column as the previous desktop
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 16:13:43 +00:00
|
|
|
KQuickControlsAddons.QIconItem {
|
2013-03-21 11:09:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
icon: "go-next"
|
|
|
|
visible: {
|
|
|
|
if (dialogItem.currentDesktop <= index) {
|
|
|
|
// we don't show for desktops not on the path
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (index < dialogItem.previousDesktop) {
|
|
|
|
// we might have to show this icon in case we go up and to the right
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// can only happen in same row
|
|
|
|
if (index % view.columns >= dialogItem.previousDesktop % view.columns) {
|
|
|
|
// but only for items in the same column or after of the previous desktop
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.currentDesktop < dialogItem.previousDesktop) {
|
|
|
|
// we only go right if the new desktop is higher
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// show icons in same row as target desktop
|
|
|
|
if (index % view.columns < dialogItem.previousDesktop % view.columns) {
|
|
|
|
// but only for items in the same column or after of the previous desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2014-03-25 16:13:43 +00:00
|
|
|
KQuickControlsAddons.QIconItem {
|
2013-03-21 11:09:08 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
icon: "go-previous"
|
|
|
|
visible: {
|
|
|
|
if (dialogItem.currentDesktop >= index) {
|
|
|
|
// we don't show for desktops not on the path
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (index > dialogItem.previousDesktop) {
|
|
|
|
// we might have to show this icon in case we go down and to the left
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// can only happen in same row
|
|
|
|
if (index % view.columns <= dialogItem.previousDesktop % view.columns) {
|
|
|
|
// but only for items in the same column or before the previous desktop
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (dialogItem.currentDesktop > dialogItem.previousDesktop) {
|
|
|
|
// we only go left if the new desktop is lower
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Math.floor(dialogItem.currentDesktop/view.columns) == Math.floor(index/view.columns)) {
|
|
|
|
// show icons in same row as target desktop
|
|
|
|
if (index % view.columns > dialogItem.previousDesktop % view.columns) {
|
|
|
|
// but only for items in the same column or before of the previous desktop
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: "NORMAL"
|
|
|
|
when: index != dialogItem.currentDesktop
|
|
|
|
PropertyChanges {
|
|
|
|
target: activeElement
|
|
|
|
opacity: 0.0
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: "SELECTED"
|
|
|
|
when: index == dialogItem.currentDesktop
|
|
|
|
PropertyChanges {
|
|
|
|
target: activeElement
|
|
|
|
opacity: 1.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
Component.onCompleted: {
|
|
|
|
view.state = (index == dialogItem.currentDesktop) ? "SELECTED" : "NORMAL"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
repeat: false
|
|
|
|
interval: dialogItem.animationDuration
|
|
|
|
onTriggered: dialog.visible = false
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
target: workspace
|
2021-01-10 10:32:17 +00:00
|
|
|
function onCurrentDesktopChanged() {
|
|
|
|
dialogItem.show()
|
|
|
|
}
|
2020-11-11 16:44:38 +00:00
|
|
|
function onNumberDesktopsChanged() {
|
2013-03-21 11:09:08 +00:00
|
|
|
repeater.model = workspace.desktops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connections {
|
|
|
|
target: options
|
2020-11-11 16:44:38 +00:00
|
|
|
function onConfigChanged() {
|
|
|
|
dialogItem.loadConfig()
|
|
|
|
}
|
2013-03-21 11:09:08 +00:00
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
2013-11-07 09:35:26 +00:00
|
|
|
view.columns = workspace.desktopGridWidth;
|
|
|
|
view.rows = workspace.desktopGridHeight;
|
2013-03-21 11:09:08 +00:00
|
|
|
dialogItem.loadConfig();
|
|
|
|
dialogItem.show();
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 13:10:35 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
KWin.registerWindow(dialog);
|
|
|
|
}
|
2013-03-21 11:09:08 +00:00
|
|
|
}
|