Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait for all fingers to be lifted before completing long press #157

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/gestures/Actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ wf::touch::action_status_t TouchUpOrDownAction::update_state(const wf::touch::ge
return wf::touch::ACTION_STATUS_RUNNING;
}

wf::touch::action_status_t LiftAll::update_state(const wf::touch::gesture_state_t& state,
const wf::touch::gesture_event_t& event) {
if (event.time - this->start_time > this->get_duration()) {
return wf::touch::ACTION_STATUS_CANCELLED;
}

if (event.type == wf::touch::EVENT_TYPE_TOUCH_UP && state.fingers.size() == 0) {
return wf::touch::ACTION_STATUS_COMPLETED;
}

return wf::touch::ACTION_STATUS_RUNNING;
}
wf::touch::action_status_t OnCompleteAction::update_state(const wf::touch::gesture_state_t& state,
const wf::touch::gesture_event_t& event) {
auto status = this->action->update_state(state, event);
Expand Down
6 changes: 6 additions & 0 deletions src/gestures/Actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class TouchUpOrDownAction : public wf::touch::gesture_action_t {
const wf::touch::gesture_event_t& event) override;
};

// Completes upon all touch points lifted.
class LiftAll : public wf::touch::gesture_action_t {
wf::touch::action_status_t update_state(const wf::touch::gesture_state_t& state,
const wf::touch::gesture_event_t& event) override;
};

// This action is used to call a function right after another action is completed
class OnCompleteAction : public wf::touch::gesture_action_t {
private:
Expand Down
4 changes: 2 additions & 2 deletions src/gestures/Gestures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ void IGestureManager::addLongPress(const float* sensitivity, const int64_t* dela
}
});

auto touch_up_or_down = std::make_unique<TouchUpOrDownAction>();
auto lift_all = std::make_unique<LiftAll>();

std::vector<std::unique_ptr<wf::touch::gesture_action_t>> long_press_actions;
long_press_actions.emplace_back(std::move(long_press_and_emit));
long_press_actions.emplace_back(std::move(touch_up_or_down));
long_press_actions.emplace_back(std::move(lift_all));

auto ack = [this]() {
const auto drag =
Expand Down
19 changes: 18 additions & 1 deletion src/gestures/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,28 @@ TEST_CASE("Long press and drag: full drag") {
{wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {450, 290}}, {wf::touch::EVENT_TYPE_TOUCH_DOWN, 105, 1, {500, 300}},
{wf::touch::EVENT_TYPE_TOUCH_DOWN, 110, 2, {550, 290}}, {wf::touch::EVENT_TYPE_MOTION, 200, 0, {460, 300}},
{wf::touch::EVENT_TYPE_MOTION, 300, 1, {510, 290}}, {wf::touch::EVENT_TYPE_MOTION, 511, 2, {560, 300}},
{wf::touch::EVENT_TYPE_MOTION, 530, 0, {470, 310}}, {wf::touch::EVENT_TYPE_TOUCH_UP, 550, 2, {560, 300}}};
{wf::touch::EVENT_TYPE_MOTION, 530, 0, {470, 310}}, {wf::touch::EVENT_TYPE_TOUCH_UP, 550, 2, {560, 300}},
{wf::touch::EVENT_TYPE_TOUCH_UP, 550, 0, {560, 300}}, {wf::touch::EVENT_TYPE_TOUCH_UP, 550, 1, {560, 300}},
};

ProcessEvents(gm, {.type = ExpectResultType::DRAG_ENDED}, events);
}

TEST_CASE("Long press and drag: touch down does nothing") {
std::cout << " ==== stdout:" << std::endl;
auto gm = CMockGestureManager::newDragHandler();
gm.addLongPress(&SENSITIVITY, &LONG_PRESS_DELAY);

const std::vector<TouchEvent> events{
{wf::touch::EVENT_TYPE_TOUCH_DOWN, 100, 0, {450, 290}}, {wf::touch::EVENT_TYPE_TOUCH_DOWN, 105, 1, {500, 300}},
{wf::touch::EVENT_TYPE_TOUCH_DOWN, 110, 2, {550, 290}}, {wf::touch::EVENT_TYPE_MOTION, 200, 0, {460, 300}},
{wf::touch::EVENT_TYPE_MOTION, 300, 1, {510, 290}}, {wf::touch::EVENT_TYPE_MOTION, 511, 2, {560, 300}},
{wf::touch::EVENT_TYPE_MOTION, 530, 0, {470, 310}}, {wf::touch::EVENT_TYPE_TOUCH_DOWN, 550, 3, {560, 300}},
};

ProcessEvents(gm, {.type = ExpectResultType::CHECK_PROGRESS, .progress = 0.5}, events);
}

TEST_CASE("Long press and drag: cancelled due to short hold duration") {
std::cout << " ==== stdout:" << std::endl;
auto gm = CMockGestureManager::newDragHandler();
Expand Down
Loading