mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-27 06:33:08 +00:00
rework tasks switcher
This commit is contained in:
parent
bdac73fdab
commit
d4e443104a
2 changed files with 120 additions and 89 deletions
|
|
@ -17,7 +17,7 @@
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import QtQuick 2.0
|
import QtQuick 2.12
|
||||||
import QtQuick.Layouts 1.1
|
import QtQuick.Layouts 1.1
|
||||||
import QtQuick.Window 2.2
|
import QtQuick.Window 2.2
|
||||||
import org.kde.taskmanager 0.1 as TaskManager
|
import org.kde.taskmanager 0.1 as TaskManager
|
||||||
|
|
@ -33,53 +33,62 @@ NanoShell.FullScreenOverlay {
|
||||||
height: Screen.height
|
height: Screen.height
|
||||||
property int offset: 0
|
property int offset: 0
|
||||||
property int overShoot: units.gridUnit * 2
|
property int overShoot: units.gridUnit * 2
|
||||||
property int tasksCount: tasksModel.count
|
property int tasksCount: window.model.count
|
||||||
property int currentTaskIndex: -1
|
property int currentTaskIndex: -1
|
||||||
property alias model: tasksModel
|
property TaskManager.TasksModel model
|
||||||
|
|
||||||
Component.onCompleted: plasmoid.nativeInterface.panel = window;
|
Component.onCompleted: plasmoid.nativeInterface.panel = window;
|
||||||
|
|
||||||
|
enum MovementDirection {
|
||||||
|
None = 0,
|
||||||
|
Up,
|
||||||
|
Down
|
||||||
|
}
|
||||||
|
|
||||||
onTasksCountChanged: {
|
onTasksCountChanged: {
|
||||||
if (tasksCount == 0) {
|
if (tasksCount == 0) {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
color: Qt.rgba(0, 0, 0, 0.8 * Math.min(
|
color: Qt.rgba(0, 0, 0, 0.6 * Math.min(
|
||||||
(Math.min(tasksView.contentY + tasksView.height, tasksView.height) / tasksView.height),
|
(Math.min(tasksView.contentY, tasksView.height) / tasksView.height),
|
||||||
((tasksView.contentHeight - tasksView.contentY - tasksView.headerItem.height - tasksView.footerItem.height)/tasksView.height)))
|
((tasksView.contentHeight - tasksView.contentY - window.height) / tasksView.height)))
|
||||||
|
|
||||||
function show() {
|
function show() {
|
||||||
if (tasksModel.count == 0) {
|
if (window.model.count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!visible) {
|
|
||||||
tasksView.contentY = -tasksView.headerItem.height;
|
|
||||||
}
|
|
||||||
visible = true;
|
visible = true;
|
||||||
scrollAnim.from = tasksView.contentY;
|
scrollAnim.from = tasksView.contentY;
|
||||||
scrollAnim.to = 0;
|
scrollAnim.to = window.height;
|
||||||
scrollAnim.running = true;
|
scrollAnim.restart();
|
||||||
}
|
}
|
||||||
function hide() {
|
function hide() {
|
||||||
if (!window.visible) {
|
if (!window.visible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
scrollAnim.from = tasksView.contentY;
|
scrollAnim.from = tasksView.contentY;
|
||||||
if (tasksView.contentY + tasksView.headerItem.height < tasksView.contentHeight/2) {
|
if (tasksView.contentY + window.height < tasksView.contentHeight/2) {
|
||||||
scrollAnim.to = -tasksView.headerItem.height;
|
scrollAnim.to = 0;
|
||||||
} else {
|
} else {
|
||||||
scrollAnim.to = tasksView.contentHeight - tasksView.headerItem.height;
|
scrollAnim.to = tasksView.contentHeight - window.height;
|
||||||
}
|
}
|
||||||
scrollAnim.running = true;
|
scrollAnim.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setSingleActiveWindow(id) {
|
function setSingleActiveWindow(id) {
|
||||||
if (id >= 0) {
|
if (id >= 0) {
|
||||||
tasksModel.requestActivate(tasksModel.index(id, 0));
|
window.model.requestActivate(window.model.index(id, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onOffsetChanged: tasksView.contentY = offset
|
onOffsetChanged: tasksView.contentY = offset
|
||||||
|
onVisibleChanged: {
|
||||||
|
if (!visible) {
|
||||||
|
tasksView.contentY = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SequentialAnimation {
|
SequentialAnimation {
|
||||||
id: scrollAnim
|
id: scrollAnim
|
||||||
|
|
@ -97,7 +106,7 @@ NanoShell.FullScreenOverlay {
|
||||||
}
|
}
|
||||||
ScriptAction {
|
ScriptAction {
|
||||||
script: {
|
script: {
|
||||||
if (tasksView.contentY <= -tasksView.headerItem.height || tasksView.contentY >= tasksView.contentHeight - tasksView.headerItem.height) {
|
if (tasksView.contentY <= 0 || tasksView.contentY >= tasksView.contentHeight - window.height) {
|
||||||
window.visible = false;
|
window.visible = false;
|
||||||
setSingleActiveWindow(currentTaskIndex);
|
setSingleActiveWindow(currentTaskIndex);
|
||||||
}
|
}
|
||||||
|
|
@ -105,96 +114,117 @@ NanoShell.FullScreenOverlay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GridView {
|
Flickable {
|
||||||
id: tasksView
|
id: tasksView
|
||||||
width: window.width
|
width: window.width
|
||||||
height: window.height
|
height: window.height
|
||||||
cellWidth: window.width/2
|
contentWidth: width
|
||||||
cellHeight: window.height/2
|
contentHeight: mainArea.implicitHeight
|
||||||
onFlickingChanged: {
|
property int flickState: TaskSwitcher.MovementDirection.None
|
||||||
if (!draggingVertically && contentY < -headerItem.height + window.height ||
|
|
||||||
(contentY + footerItem.height) > (contentHeight - footerItem.height - window.height/6*5)) {
|
readonly property int movementDirection: {
|
||||||
window.hide();
|
if (flickState != TaskSwitcher.MovementDirection.None) {
|
||||||
|
return flickState;
|
||||||
|
} else if (verticalVelocity < 0) {
|
||||||
|
return TaskSwitcher.MovementDirection.Up;
|
||||||
|
} else if (verticalVelocity > 0) {
|
||||||
|
return TaskSwitcher.MovementDirection.Down;
|
||||||
|
} else {
|
||||||
|
return TaskSwitcher.MovementDirection.None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onFlickingVerticallyChanged: {
|
||||||
|
if (flickingVertically) {
|
||||||
|
flickState = verticalVelocity < 0 ? TaskSwitcher.MovementDirection.Up : TaskSwitcher.MovementDirection.Down;
|
||||||
|
} else if (/*!draggingVertically &&*/ !flickingVertically) {
|
||||||
|
draggingVerticallyChanged();
|
||||||
|
flickState = TaskSwitcher.MovementDirection.None
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
onDraggingVerticallyChanged: {
|
onDraggingVerticallyChanged: {
|
||||||
if (draggingVertically) {
|
if (draggingVertically) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//manage separately the first page, the lockscreen
|
let beforeBeginning = contentY < window.height;
|
||||||
//scrolling down
|
let afterEnd = contentY > contentHeight - window.height * 2;
|
||||||
if (verticalVelocity > 0 && contentY < -headerItem.height + window.height &&
|
|
||||||
contentY > (-headerItem.height + window.height/6)) {
|
|
||||||
show();
|
|
||||||
return;
|
|
||||||
|
|
||||||
//scrolling up
|
let topCloseCondition = contentY < window.height / 10 * 9;
|
||||||
} else if (verticalVelocity < 0 && contentY < -headerItem.height + window.height &&
|
let bottomClosecondition = contentY > contentHeight - window.height * 2 - window.height / 10;
|
||||||
contentY < (-headerItem.height + window.height/6*5)) {
|
|
||||||
hide();
|
|
||||||
return;
|
|
||||||
|
|
||||||
//hide by scrolling down
|
switch (movementDirection) {
|
||||||
} else if ((contentY + footerItem.height) > (contentHeight - footerItem.height - window.height/6*5)) {
|
case TaskSwitcher.MovementDirection.Up: {
|
||||||
hide();
|
if (topCloseCondition) {
|
||||||
return;
|
hide();
|
||||||
//show
|
} else if (beforeBeginning) {
|
||||||
} else if ((contentY + tasksView.height) > (contentHeight - headerItem.height - footerItem.height) &&
|
show();
|
||||||
(contentY + tasksView.height) < (contentHeight - headerItem.height - footerItem.height + window.height/6*5)) {
|
} else if (afterEnd) {
|
||||||
scrollAnim.from = tasksView.contentY;
|
scrollAnim.from = tasksView.contentY;
|
||||||
visible = true;
|
scrollAnim.to = tasksView.contentHeight - window.height * 2;
|
||||||
|
scrollAnim.restart();
|
||||||
scrollAnim.to = contentHeight - footerItem.height - tasksView.height*2;
|
}
|
||||||
scrollAnim.running = true;
|
break;
|
||||||
return;
|
}
|
||||||
} else if (contentY < 0) {
|
case TaskSwitcher.MovementDirection.Down: {
|
||||||
show();
|
if (bottomClosecondition) {
|
||||||
|
hide();
|
||||||
|
} else if (beforeBeginning) {
|
||||||
|
show();
|
||||||
|
} else if (afterEnd) {
|
||||||
|
scrollAnim.from = tasksView.contentY;
|
||||||
|
scrollAnim.to = tasksView.contentHeight - window.height * 2;
|
||||||
|
scrollAnim.restart();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TaskSwitcher.MovementDirection.None:
|
||||||
|
default:
|
||||||
|
if (beforeBeginning) {
|
||||||
|
show();
|
||||||
|
} else if (afterEnd) {
|
||||||
|
scrollAnim.from = tasksView.contentY;
|
||||||
|
scrollAnim.to = tasksView.contentHeight - window.height * 2;
|
||||||
|
scrollAnim.restart();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskManager.TasksModel {
|
MouseArea {
|
||||||
id: tasksModel
|
id: mainArea
|
||||||
sortMode: TaskManager.TasksModel.SortVirtualDesktop
|
parent: tasksView.contentItem
|
||||||
groupMode: TaskManager.TasksModel.GroupDisabled
|
width: tasksView.width
|
||||||
|
implicitHeight: window.height * 2 + Math.max(window.height, grid.implicitHeight)
|
||||||
|
onClicked: window.hide()
|
||||||
|
|
||||||
screenGeometry: plasmoid.screenGeometry
|
Grid {
|
||||||
filterByScreen: plasmoid.configuration.showForCurrentScreenOnly
|
id: grid
|
||||||
}
|
anchors {
|
||||||
//This proxy is only used for "get"
|
left: parent.left
|
||||||
PlasmaCore.SortFilterModel {
|
right: parent.right
|
||||||
id: filterModel
|
bottom: parent.bottom
|
||||||
sourceModel: TaskManager.TasksModel {}
|
bottomMargin: window.height
|
||||||
onCountChanged: {
|
}
|
||||||
if (count == 0) {
|
columns: 2
|
||||||
window.hide();
|
|
||||||
|
Repeater {
|
||||||
|
model: window.model
|
||||||
|
delegate: Task {}
|
||||||
|
}
|
||||||
|
|
||||||
|
move: Transition {
|
||||||
|
NumberAnimation {
|
||||||
|
properties: "x,y"
|
||||||
|
duration: units.longDuration
|
||||||
|
easing.type: Easing.InOutQuad
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
model: tasksModel
|
|
||||||
header: Item {
|
|
||||||
width: window.width
|
|
||||||
height: window.height
|
|
||||||
}
|
|
||||||
footer: Item {
|
|
||||||
width: window.width
|
|
||||||
height: window.height
|
|
||||||
}
|
|
||||||
delegate: Task {}
|
|
||||||
displaced: Transition {
|
|
||||||
NumberAnimation {
|
|
||||||
properties: "x,y"
|
|
||||||
duration: units.longDuration
|
|
||||||
easing.type: Easing.InOutQuad
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MouseArea {
|
|
||||||
parent: tasksView.contentItem
|
|
||||||
anchors.fill:parent
|
|
||||||
onClicked: window.hide()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlasmaComponents.RoundButton {
|
PlasmaComponents.RoundButton {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,9 @@ PlasmaCore.ColorScope {
|
||||||
Timer {
|
Timer {
|
||||||
running: true
|
running: true
|
||||||
interval: 200
|
interval: 200
|
||||||
onTriggered: taskSwitcherLoader.source = Qt.resolvedUrl("TaskSwitcher.qml")
|
onTriggered: {
|
||||||
|
taskSwitcherLoader.setSource(Qt.resolvedUrl("TaskSwitcher.qml"), {"model": tasksModel});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TaskManager.TasksModel {
|
TaskManager.TasksModel {
|
||||||
|
|
@ -57,7 +59,6 @@ PlasmaCore.ColorScope {
|
||||||
groupMode: TaskManager.TasksModel.GroupDisabled
|
groupMode: TaskManager.TasksModel.GroupDisabled
|
||||||
|
|
||||||
screenGeometry: plasmoid.screenGeometry
|
screenGeometry: plasmoid.screenGeometry
|
||||||
filterByScreen: plasmoid.configuration.showForCurrentScreenOnly
|
|
||||||
sortMode: TaskManager.TasksModel.SortAlpha
|
sortMode: TaskManager.TasksModel.SortAlpha
|
||||||
|
|
||||||
virtualDesktop: virtualDesktopInfo.currentDesktop
|
virtualDesktop: virtualDesktopInfo.currentDesktop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue