Update pinch gesture logic
This commit is contained in:
parent
48a79607dc
commit
7b0502c0b7
@ -45,7 +45,7 @@ namespace comfortable_swipe::gesture
|
|||||||
const char* pinch_out4
|
const char* pinch_out4
|
||||||
):
|
):
|
||||||
comfortable_swipe::gesture::xdo_gesture(),
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
threshold_squared(threshold),
|
threshold(threshold),
|
||||||
commands(new const char*[4]{pinch_in3, pinch_in4, pinch_out3, pinch_out4})
|
commands(new const char*[4]{pinch_in3, pinch_in4, pinch_out3, pinch_out4})
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on begin of pinch gesture.
|
* Hook on begin of pinch gesture.
|
||||||
*/
|
*/
|
||||||
void pinch_gesture::begin()
|
inline void pinch_gesture::begin()
|
||||||
{
|
{
|
||||||
this->previous_gesture = swipe_gesture::FRESH;
|
this->previous_gesture = swipe_gesture::FRESH;
|
||||||
this->previous_radius = this->radius;
|
this->previous_radius = this->radius;
|
||||||
@ -69,10 +69,13 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on update of swipe gesture.
|
* Hook on update of swipe gesture.
|
||||||
*/
|
*/
|
||||||
void swipe_gesture::update()
|
inline void pinch_gesture::update()
|
||||||
{
|
{
|
||||||
float delta_radius = this->radius - this->previous_radius;
|
float delta_radius = this->radius - this->previous_radius;
|
||||||
this->previous_radius = this->radius;
|
this->previous_radius = this->radius;
|
||||||
|
|
||||||
|
// TODO: use a different epsilon threshold
|
||||||
|
const float EPSILON = this->threshold;
|
||||||
if (this->delta_radius > EPSILON)
|
if (this->delta_radius > EPSILON)
|
||||||
{
|
{
|
||||||
// TODO: pinch out
|
// TODO: pinch out
|
||||||
@ -86,9 +89,60 @@ namespace comfortable_swipe::gesture
|
|||||||
/**
|
/**
|
||||||
* Hook on end of swipe gesture.
|
* Hook on end of swipe gesture.
|
||||||
*/
|
*/
|
||||||
void pinch_gesture::end()
|
inline void pinch_gesture::end()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an output line and dispatches pinch begin/update/end upon match.
|
||||||
|
* Uses GESTURE_BEGIN_REGEX_PATTERN for begin,
|
||||||
|
* GESTURE_UPDATE_REGEX_PATTERN for update,
|
||||||
|
* GESTURE_END_REGEX_PATTERN for end.
|
||||||
|
*
|
||||||
|
* @param line the output line from libinput debug-events
|
||||||
|
* @return true if line matches this gesture
|
||||||
|
*/
|
||||||
|
inline bool pinch_gesture::parse_line(const char * line)
|
||||||
|
{
|
||||||
|
// pre-compile regex patterns
|
||||||
|
static const std::regex gesture_swipe_begin(pinch_gesture::GESTURE_BEGIN_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_update(pinch_gesture::GESTURE_UPDATE_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_end(pinch_gesture::GESTURE_END_REGEX_PATTERN);
|
||||||
|
std::cmatch matches;
|
||||||
|
if (this->flag_pinching)
|
||||||
|
{
|
||||||
|
// currently pinching
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_update) != 0)
|
||||||
|
{
|
||||||
|
// update pinch
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->radius = std::stof(matches[2]);
|
||||||
|
this->update();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else if (std::regex_match(line, matches, gesture_swipe_end) != 0)
|
||||||
|
{
|
||||||
|
// end pinch
|
||||||
|
this->flag_pinching = false;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->end();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* !flag_swiping */
|
||||||
|
{
|
||||||
|
// not swiping, check if swipe will begin
|
||||||
|
if (std::regex_match(line, matches, gesture_swipe_begin) != 0)
|
||||||
|
{
|
||||||
|
// begin swipe
|
||||||
|
this->flag_pinching = true;
|
||||||
|
this->fingers = std::stoi(matches[1]);
|
||||||
|
this->begin();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* STATICS DEFINITIONS */
|
/* STATICS DEFINITIONS */
|
||||||
const int pinch_gesture::MSK_THREE_FINGERS = 0;
|
const int pinch_gesture::MSK_THREE_FINGERS = 0;
|
||||||
const int pinch_gesture::MSK_FOUR_FINGERS = 1;
|
const int pinch_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
|
|||||||
@ -42,7 +42,7 @@ namespace comfortable_swipe::gesture
|
|||||||
);
|
);
|
||||||
|
|
||||||
~pinch_gesture();
|
~pinch_gesture();
|
||||||
float radius, omega;
|
float radius;
|
||||||
|
|
||||||
inline void begin() override;
|
inline void begin() override;
|
||||||
inline void update() override;
|
inline void update() override;
|
||||||
@ -52,8 +52,9 @@ namespace comfortable_swipe::gesture
|
|||||||
protected:
|
protected:
|
||||||
// current location
|
// current location
|
||||||
float previous_radius;
|
float previous_radius;
|
||||||
float threshold_squared;
|
float threshold;
|
||||||
int previous_gesture;
|
int previous_gesture;
|
||||||
|
bool flag_pinching;
|
||||||
const char ** commands;
|
const char ** commands;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -60,8 +60,8 @@ namespace comfortable_swipe::gesture
|
|||||||
// matches signed decimal numbers (eg. "6.02" "-1.1")
|
// matches signed decimal numbers (eg. "6.02" "-1.1")
|
||||||
#define CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
#define CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
||||||
|
|
||||||
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
// matches a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
||||||
#define CF_NUMBER_DIVISION "\\s*(" CF_NUMBER_REGEX ")/\\s*(" CF_NUMBER_REGEX ")"
|
#define CF_NUMBER_DIVISION "\\s*" CF_NUMBER_REGEX "/\\s*" CF_NUMBER_REGEX
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regex pattern for the libinput entry for during a pinch.
|
* Regex pattern for the libinput entry for during a pinch.
|
||||||
@ -81,7 +81,7 @@ namespace comfortable_swipe::gesture
|
|||||||
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
||||||
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
||||||
"\\s+(" CF_NUMBER_REGEX ")" // radius
|
"\\s+(" CF_NUMBER_REGEX ")" // radius
|
||||||
" @\\s+(" CF_NUMBER_REGEX ")" // angular velocity (omega)
|
" @\\s+" CF_NUMBER_REGEX "" // angular velocity (omega)
|
||||||
"\\s*$" // end of string
|
"\\s*$" // end of string
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user