Skip to content

Commit

Permalink
refactor: switch to enum class for TouchGestureType
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Nov 24, 2023
1 parent b8ac92d commit f22dda3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/GestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void GestureManager::emulateSwipeUpdate(uint32_t time) {
}

bool GestureManager::handleGesture(const CompletedGesture& gev) {
if (gev.type == GESTURE_TYPE_SWIPE_HOLD) {
if (gev.type == TouchGestureType::SWIPE_HOLD) {
return this->handleWorkspaceSwipe(gev);
}
if (gev.type == GESTURE_TYPE_SWIPE && this->dragGestureIsActive()) {
if (gev.type == TouchGestureType::SWIPE && this->dragGestureIsActive()) {
this->emulateSwipeEnd(0, false);
return true;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ bool GestureManager::handleWorkspaceSwipe(const CompletedGesture& gev) {
->m_vRenderOffset.getConfig()
->pValues->internalStyle == "slidevert";

if (gev.type == GESTURE_TYPE_SWIPE_HOLD && gev.finger_count == *PWORKSPACEFINGERS) {
if (gev.type == TouchGestureType::SWIPE_HOLD && gev.finger_count == *PWORKSPACEFINGERS) {
const auto horizontal = GESTURE_DIRECTION_LEFT | GESTURE_DIRECTION_RIGHT;
const auto vertical = GESTURE_DIRECTION_UP | GESTURE_DIRECTION_DOWN;
const auto workspace_directions = VERTANIMS ? vertical : horizontal;
Expand Down
18 changes: 9 additions & 9 deletions src/gestures/Gestures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ std::string stringifyDirection(gestureDirection direction) {
std::string CompletedGesture::to_string() const {
std::string bind = "";
switch (type) {
case GESTURE_TYPE_EDGE_SWIPE:
case TouchGestureType::EDGE_SWIPE:
bind += "edge";
break;
case GESTURE_TYPE_SWIPE:
case TouchGestureType::SWIPE:
bind += "swipe";
break;
case GESTURE_TYPE_SWIPE_HOLD:
case TouchGestureType::SWIPE_HOLD:
// this gesture is only used internally for workspace swipe
return "workspace_swipe";
}

bind += ":";

if (type == GESTURE_TYPE_EDGE_SWIPE) {
if (type == TouchGestureType::EDGE_SWIPE) {
bind += stringifyDirection(this->edge_origin);
} else {
bind += std::to_string(finger_count);
Expand Down Expand Up @@ -215,9 +215,9 @@ void IGestureManager::addTouchGesture(std::unique_ptr<wf::touch::gesture_t> gest
// Adds a Multi-fingered swipe:
// * inhibits events to client windows/surfaces when enough fingers touch
// down within a short duration.
// * emits a GESTURE_TYPE_SWIPE_HOLD event once fingers moved over the
// * emits a TouchGestureType::SWIPE_HOLD event once fingers moved over the
// threshold.
// * further emits a GESTURE_TYPE_SWIPE event if the SWIPE_HOLD event was
// * further emits a TouchGestureType::SWIPE event if the SWIPE_HOLD event was
// emitted and once a finger is lifted
void IGestureManager::addMultiFingerGesture(const float* sensitivity) {
auto multi_down = std::make_unique<MultiFingerDownAction>([this]() { this->cancelTouchEventsOnAllWindows(); });
Expand All @@ -233,7 +233,7 @@ void IGestureManager::addMultiFingerGesture(const float* sensitivity) {
if (this->dragGestureActive) {
return;
}
const auto gesture = CompletedGesture{GESTURE_TYPE_SWIPE_HOLD, swipe_ptr->target_direction,
const auto gesture = CompletedGesture{TouchGestureType::SWIPE_HOLD, swipe_ptr->target_direction,
static_cast<int>(this->m_sGestureState.fingers.size())};

this->dragGestureActive = this->handleGesture(gesture);
Expand All @@ -250,7 +250,7 @@ void IGestureManager::addMultiFingerGesture(const float* sensitivity) {
swipe_actions.emplace_back(std::move(swipe_liftoff));

auto ack = [swipe_ptr, this]() {
const auto gesture = CompletedGesture{GESTURE_TYPE_SWIPE, swipe_ptr->target_direction,
const auto gesture = CompletedGesture{TouchGestureType::SWIPE, swipe_ptr->target_direction,
static_cast<int>(this->m_sGestureState.fingers.size())};
this->handleGesture(gesture);
};
Expand Down Expand Up @@ -289,7 +289,7 @@ void IGestureManager::addEdgeSwipeGesture(const float* sensitivity) {
return;
}
auto direction = edge_ptr->target_direction;
auto gesture = CompletedGesture{GESTURE_TYPE_EDGE_SWIPE, direction, edge_ptr->finger_count, origin_edges};
auto gesture = CompletedGesture{TouchGestureType::EDGE_SWIPE, direction, edge_ptr->finger_count, origin_edges};
this->handleGesture(gesture);
};
auto cancel = [this]() { this->handleCancelledGesture(); };
Expand Down
16 changes: 7 additions & 9 deletions src/gestures/Gestures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,15 @@ constexpr static uint32_t GESTURE_BASE_DURATION = 400;

constexpr static uint32_t SEND_CANCEL_EVENT_FINGER_COUNT = 3;

enum eTouchGestureType
{
enum class TouchGestureType {
// Invalid Gesture
GESTURE_TYPE_SWIPE,
GESTURE_TYPE_SWIPE_HOLD, // same as SWIPE but fingers were not lifted
GESTURE_TYPE_EDGE_SWIPE,
// GESTURE_TYPE_PINCH,
SWIPE,
SWIPE_HOLD, // same as SWIPE but fingers were not lifted
EDGE_SWIPE,
// PINCH,
};

enum eTouchGestureDirection
{
enum TouchGestureDirection {
/* Swipe-specific */
GESTURE_DIRECTION_LEFT = (1 << 0),
GESTURE_DIRECTION_RIGHT = (1 << 1),
Expand All @@ -54,7 +52,7 @@ using gestureDirection = uint32_t;
* Finger count can be arbitrary (might be a good idea to limit to >3)
*/
struct CompletedGesture {
eTouchGestureType type;
TouchGestureType type;
gestureDirection direction;
int finger_count;

Expand Down
2 changes: 1 addition & 1 deletion src/gestures/test/MockGestureManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CMockGestureManager::CMockGestureManager() {}

bool CMockGestureManager::handleGesture(const CompletedGesture& gev) {
std::cout << "gesture triggered: " << gev.to_string() << "\n";
this->triggered = this->triggered || gev.type != GESTURE_TYPE_SWIPE_HOLD;
this->triggered = this->triggered || gev.type != TouchGestureType::SWIPE_HOLD;
return true;
}

Expand Down

0 comments on commit f22dda3

Please sign in to comment.