mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
Fix current index calculation, and refactor
This commit is contained in:
parent
bb3b6959ac
commit
89c0477b8d
2 changed files with 38 additions and 93 deletions
|
|
@ -21,6 +21,7 @@ Item {
|
||||||
|
|
||||||
readonly property point taskScreenPoint: Qt.point(model.ScreenGeometry.x, model.ScreenGeometry.y)
|
readonly property point taskScreenPoint: Qt.point(model.ScreenGeometry.x, model.ScreenGeometry.y)
|
||||||
readonly property real dragOffset: -control.y
|
readonly property real dragOffset: -control.y
|
||||||
|
|
||||||
readonly property real headerHeight: appHeader.height + PlasmaCore.Units.smallSpacing
|
readonly property real headerHeight: appHeader.height + PlasmaCore.Units.smallSpacing
|
||||||
|
|
||||||
property bool active: model.IsActive
|
property bool active: model.IsActive
|
||||||
|
|
@ -31,13 +32,25 @@ Item {
|
||||||
|
|
||||||
opacity: 1 - dragOffset / window.height
|
opacity: 1 - dragOffset / window.height
|
||||||
|
|
||||||
Component.onCompleted: syncDelegateGeometry();
|
//BEGIN functions
|
||||||
function syncDelegateGeometry() {
|
function syncDelegateGeometry() {
|
||||||
let pos = pipeWireLoader.mapToItem(tasksView, 0, 0);
|
let pos = pipeWireLoader.mapToItem(tasksView, 0, 0);
|
||||||
if (window.visible) {
|
if (window.visible) {
|
||||||
tasksModel.requestPublishDelegateGeometry(tasksModel.index(model.index, 0), Qt.rect(pos.x, pos.y, pipeWireLoader.width, pipeWireLoader.height), pipeWireLoader);
|
tasksModel.requestPublishDelegateGeometry(tasksModel.index(model.index, 0), Qt.rect(pos.x, pos.y, pipeWireLoader.width, pipeWireLoader.height), pipeWireLoader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeApp() {
|
||||||
|
tasksModel.requestClose(tasksModel.index(model.index, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
function activateApp() {
|
||||||
|
window.activateWindow(model.index);
|
||||||
|
}
|
||||||
|
//END functions
|
||||||
|
|
||||||
|
Component.onCompleted: syncDelegateGeometry();
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: window
|
target: window
|
||||||
function onVisibleChanged() {
|
function onVisibleChanged() {
|
||||||
|
|
@ -45,10 +58,6 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeApp() {
|
|
||||||
tasksModel.requestClose(tasksModel.index(model.index, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
QQC2.Control {
|
QQC2.Control {
|
||||||
id: control
|
id: control
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
@ -94,6 +103,7 @@ Item {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: appHeader
|
id: appHeader
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
spacing: PlasmaCore.Units.smallSpacing * 2
|
||||||
|
|
||||||
PlasmaCore.IconItem {
|
PlasmaCore.IconItem {
|
||||||
Layout.preferredHeight: PlasmaCore.Units.iconSizes.smallMedium
|
Layout.preferredHeight: PlasmaCore.Units.iconSizes.smallMedium
|
||||||
|
|
@ -171,9 +181,7 @@ Item {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TapHandler {
|
TapHandler {
|
||||||
onTapped: {
|
onTapped: delegate.activateApp()
|
||||||
window.activateWindow(model.index);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,12 @@ NanoShell.FullScreenOverlay {
|
||||||
|
|
||||||
required property real taskPanelHeight // height of task panel, provided by main.qml
|
required property real taskPanelHeight // height of task panel, provided by main.qml
|
||||||
|
|
||||||
|
// dimensions of a window on the screen
|
||||||
|
readonly property real windowHeight: window.height - (navPanel.isPortrait ? window.taskPanelHeight : 0) - MobileShell.TopPanelControls.panelHeight
|
||||||
|
readonly property real windowWidth: window.width - (navPanel.isPortrait ? 0 : window.taskPanelHeight)
|
||||||
|
|
||||||
property int tasksCount: window.model.count
|
property int tasksCount: window.model.count
|
||||||
property int currentTaskIndex: Math.round(tasksView.contentX / (tasksView.width + tasksView.spacing))
|
property int currentTaskIndex: tasksView.currentIndex
|
||||||
property TaskManager.TasksModel model
|
property TaskManager.TasksModel model
|
||||||
|
|
||||||
// properties controlled from main.qml MouseArea (swipe to open gesture)
|
// properties controlled from main.qml MouseArea (swipe to open gesture)
|
||||||
|
|
@ -35,7 +39,7 @@ NanoShell.FullScreenOverlay {
|
||||||
readonly property real targetYOffsetDist: window.height - tasksView.height // offset distance to perfect opening
|
readonly property real targetYOffsetDist: window.height - tasksView.height // offset distance to perfect opening
|
||||||
readonly property real dismissYOffsetDist: window.height
|
readonly property real dismissYOffsetDist: window.height
|
||||||
|
|
||||||
// set from main.qml
|
// set from NavigationPanel in main.qml
|
||||||
property bool wasInActiveTask: false // whether we were in an app before opening the task switcher
|
property bool wasInActiveTask: false // whether we were in an app before opening the task switcher
|
||||||
property bool currentlyDragging: false // whether we are in a swipe up gesture
|
property bool currentlyDragging: false // whether we are in a swipe up gesture
|
||||||
|
|
||||||
|
|
@ -86,6 +90,7 @@ NanoShell.FullScreenOverlay {
|
||||||
|
|
||||||
// skip to first active task
|
// skip to first active task
|
||||||
if (window.wasInActiveTask) {
|
if (window.wasInActiveTask) {
|
||||||
|
tasksView.currentIndex = window.model.activeTask.row;
|
||||||
tasksView.contentX = Math.max(0, Math.min(tasksView.contentWidth, window.model.activeTask.row * (tasksView.width + tasksView.spacing)));
|
tasksView.contentX = Math.max(0, Math.min(tasksView.contentWidth, window.model.activeTask.row * (tasksView.width + tasksView.spacing)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,24 +189,14 @@ NanoShell.FullScreenOverlay {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
||||||
width: window.width - horizontalMargin * 2
|
width: window.width - horizontalMargin * 2
|
||||||
height: window.height - (MobileShell.TopPanelControls.panelHeight + window.taskPanelHeight + PlasmaCore.Units.gridUnit * 2 + PlasmaCore.Units.largeSpacing * 2)
|
height: window.windowHeight - (PlasmaCore.Units.gridUnit * 2 + PlasmaCore.Units.largeSpacing * 2)
|
||||||
|
|
||||||
// ensure that window previews are exactly to the scale of the device screen
|
|
||||||
property real windowHeight: window.height - window.taskPanelHeight - MobileShell.TopPanelControls.panelHeight
|
|
||||||
property real scalingFactor: {
|
|
||||||
let candidateWidth = tasksView.width;
|
|
||||||
let candidateHeight = (tasksView.width / window.width) * windowHeight;
|
|
||||||
|
|
||||||
if (candidateHeight > tasksView.height) {
|
|
||||||
return tasksView.height / windowHeight;
|
|
||||||
} else {
|
|
||||||
return tasksView.width / window.width;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
model: window.model
|
model: window.model
|
||||||
snapMode: ListView.SnapToItem
|
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
|
|
||||||
|
highlightRangeMode: ListView.StrictlyEnforceRange // ensures currentIndex is updated
|
||||||
|
snapMode: ListView.SnapToItem
|
||||||
|
|
||||||
spacing: PlasmaCore.Units.largeSpacing
|
spacing: PlasmaCore.Units.largeSpacing
|
||||||
displayMarginBeginning: 2 * (width + spacing)
|
displayMarginBeginning: 2 * (width + spacing)
|
||||||
displayMarginEnd: 2 * (width + spacing)
|
displayMarginEnd: 2 * (width + spacing)
|
||||||
|
|
@ -210,21 +205,14 @@ NanoShell.FullScreenOverlay {
|
||||||
NumberAnimation { properties: "x,y"; duration: PlasmaCore.Units.longDuration; easing.type: Easing.InOutQuad }
|
NumberAnimation { properties: "x,y"; duration: PlasmaCore.Units.longDuration; easing.type: Easing.InOutQuad }
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
// ensure that window previews are exactly to the scale of the device screen
|
||||||
z: -1
|
property real scalingFactor: {
|
||||||
anchors.fill: parent
|
let candidateHeight = (tasksView.width / window.width) * window.windowHeight;
|
||||||
visible: tasksView.count === 0
|
|
||||||
enabled: visible
|
|
||||||
onClicked: { // close window on tap if there are no delegates
|
|
||||||
if (tasksView.count === 0) {
|
|
||||||
window.hide()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PlasmaComponents.Label {
|
if (candidateHeight > tasksView.height) {
|
||||||
anchors.centerIn: parent
|
return tasksView.height / window.windowHeight;
|
||||||
text: i18n("No applications are open")
|
} else {
|
||||||
color: "white"
|
return tasksView.width / window.windowWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,33 +227,20 @@ NanoShell.FullScreenOverlay {
|
||||||
y: task.headerHeight / 2
|
y: task.headerHeight / 2
|
||||||
|
|
||||||
// scale gesture
|
// scale gesture
|
||||||
property bool preventOverJump: false
|
|
||||||
scale: {
|
scale: {
|
||||||
let maxScale = 1 / tasksView.scalingFactor;
|
let maxScale = 1 / tasksView.scalingFactor;
|
||||||
let subtract = (maxScale - 1) * (window.yOffset / window.targetYOffsetDist);
|
let subtract = (maxScale - 1) * (window.yOffset / window.targetYOffsetDist);
|
||||||
let finalScale = Math.max(0, Math.min(maxScale, maxScale - subtract));
|
let finalScale = Math.max(0, Math.min(maxScale, maxScale - subtract));
|
||||||
|
|
||||||
// prevent y "jump" when letting go of gesture from homescreen
|
if ((window.wasInActiveTask || !taskSwitcher.currentlyDragging) && window.currentTaskIndex === task.curIndex) {
|
||||||
if (window.wasInActiveTask) {
|
|
||||||
preventOverJump = false;
|
|
||||||
} else {
|
|
||||||
if (!taskSwitcher.currentlyDragging && finalScale === 1) {
|
|
||||||
preventOverJump = false;
|
|
||||||
}
|
|
||||||
if (window.wasInActiveTask && taskSwitcher.currentlyDragging) {
|
|
||||||
preventOverJump = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((window.wasInActiveTask || !taskSwitcher.currentlyDragging) && !preventOverJump && window.currentTaskIndex === task.curIndex) {
|
|
||||||
return finalScale;
|
return finalScale;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure that window previews are exactly to the scale of the device screen
|
// ensure that window previews are exactly to the scale of the device screen
|
||||||
previewWidth: tasksView.scalingFactor * window.width
|
previewWidth: tasksView.scalingFactor * window.windowWidth
|
||||||
previewHeight: tasksView.scalingFactor * tasksView.windowHeight
|
previewHeight: tasksView.scalingFactor * window.windowHeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,42 +315,4 @@ NanoShell.FullScreenOverlay {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RowLayout {
|
|
||||||
// id: footerButtons
|
|
||||||
// anchors.left: parent.left
|
|
||||||
// anchors.right: parent.right
|
|
||||||
// anchors.bottom: parent.bottom
|
|
||||||
// anchors.bottomMargin: PlasmaCore.Units.largeSpacing + window.taskPanelHeight
|
|
||||||
// anchors.topMargin: PlasmaCore.Units.largeSpacing
|
|
||||||
//
|
|
||||||
// spacing: PlasmaCore.Units.largeSpacing
|
|
||||||
//
|
|
||||||
// PlasmaComponents.ToolButton {
|
|
||||||
// Layout.alignment: Qt.AlignRight
|
|
||||||
// icon.width: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.height: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.name: "view-list-symbolic" // "view-grid-symbolic"
|
|
||||||
// text: i18n("Switch to list view")
|
|
||||||
// display: PlasmaComponents.ToolButton.IconOnly
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// PlasmaComponents.ToolButton {
|
|
||||||
// Layout.alignment: Qt.AlignHCenter
|
|
||||||
// icon.width: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.height: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.name: "trash-empty"
|
|
||||||
// text: i18n("Clear All")
|
|
||||||
// display: PlasmaComponents.ToolButton.IconOnly
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// PlasmaComponents.ToolButton {
|
|
||||||
// Layout.alignment: Qt.AlignLeft
|
|
||||||
// icon.width: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.height: PlasmaCore.Units.iconSizes.medium
|
|
||||||
// icon.name: "system-search"
|
|
||||||
// text: i18n("Search")
|
|
||||||
// display: PlasmaComponents.ToolButton.IconOnly
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue