mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
add haptic feedback to task switcher gestures
haptics are triggered when conditions are met to open task switcher or task scrub mode is engaged. fixes related bug in task switcher gesture logic when invoked from homescreen fixes https://invent.kde.org/plasma/plasma-mobile/-/issues/366
This commit is contained in:
parent
642392366b
commit
617ba59de7
2 changed files with 36 additions and 1 deletions
|
|
@ -39,6 +39,10 @@ FocusScope {
|
||||||
stateClass: TaskSwitcherData.TaskSwitcherState
|
stateClass: TaskSwitcherData.TaskSwitcherState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MobileShell.HapticsEffect {
|
||||||
|
id: haptics
|
||||||
|
}
|
||||||
|
|
||||||
property var tasksModel: TaskSwitcherData.TaskFilterModel {
|
property var tasksModel: TaskSwitcherData.TaskFilterModel {
|
||||||
screenName: root.targetScreen.name
|
screenName: root.targetScreen.name
|
||||||
windowModel: TaskSwitcherData.TaskModel
|
windowModel: TaskSwitcherData.TaskModel
|
||||||
|
|
@ -102,6 +106,12 @@ FocusScope {
|
||||||
taskSwitcherHelpers.isInTaskScrubMode = true;
|
taskSwitcherHelpers.isInTaskScrubMode = true;
|
||||||
taskSwitcherHelpers.cancelAnimations();
|
taskSwitcherHelpers.cancelAnimations();
|
||||||
taskSwitcherHelpers.open();
|
taskSwitcherHelpers.open();
|
||||||
|
if (!taskSwitcherHelpers.hasVibrated) {
|
||||||
|
// Haptic feedback when the task scrub mode engages
|
||||||
|
haptics.buttonVibrate();
|
||||||
|
taskSwitcherHelpers.hasVibrated = true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
let newTaskIndex = Math.max(0, Math.min(tasksCount - 1, Math.floor(state.touchXPosition / taskSwitcherHelpers.taskScrubDistance) + state.initialTaskIndex));
|
let newTaskIndex = Math.max(0, Math.min(tasksCount - 1, Math.floor(state.touchXPosition / taskSwitcherHelpers.taskScrubDistance) + state.initialTaskIndex));
|
||||||
if (newTaskIndex != state.currentTaskIndex) {
|
if (newTaskIndex != state.currentTaskIndex) {
|
||||||
|
|
@ -217,12 +227,33 @@ FocusScope {
|
||||||
taskSwitcherHelpers.open();
|
taskSwitcherHelpers.open();
|
||||||
} else {
|
} else {
|
||||||
// no flick and not enough activation to go to task switcher
|
// no flick and not enough activation to go to task switcher
|
||||||
|
if (state.wasInActiveTask) {
|
||||||
returnToApp();
|
returnToApp();
|
||||||
|
} else {
|
||||||
|
// do open switcher in case we were on homescreen before
|
||||||
|
taskSwitcherHelpers.animateGoToTaskIndex(state.currentTaskIndex);
|
||||||
|
taskSwitcherHelpers.open();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onVelocityChanged() {
|
||||||
|
if (!taskSwitcherHelpers.hasVibrated) {
|
||||||
|
if (!state.wasInActiveTask ||
|
||||||
|
(state.wasInActiveTask &&
|
||||||
|
state.yPosition > taskSwitcherHelpers.undoYThreshold &&
|
||||||
|
state.totalSquaredVelocity < state.flickVelocityThreshold)) {
|
||||||
|
// Haptic feedback when conditions are met for the task switcher to open
|
||||||
|
haptics.buttonVibrate();
|
||||||
|
taskSwitcherHelpers.hasVibrated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onXPositionChanged() {
|
function onXPositionChanged() {
|
||||||
taskSwitcherHelpers.updateTaskIndex();
|
taskSwitcherHelpers.updateTaskIndex();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ QtObject {
|
||||||
// yPosition threshold below which opening the task switcher should be undone and returned to the previously active task
|
// yPosition threshold below which opening the task switcher should be undone and returned to the previously active task
|
||||||
readonly property real undoYThreshold: openedYPosition / 2
|
readonly property real undoYThreshold: openedYPosition / 2
|
||||||
|
|
||||||
|
// whether the switcher has already triggered haptic feedback or not
|
||||||
|
// we don't want to continuously send haptics, just once is enough
|
||||||
|
property bool hasVibrated: false
|
||||||
|
|
||||||
// ~~ measurement constants ~~
|
// ~~ measurement constants ~~
|
||||||
|
|
||||||
// dimensions of a real window on the screen
|
// dimensions of a real window on the screen
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue