Bootstrap pinch_gestures class
This commit is contained in:
parent
3a0e1361c9
commit
e7573938b4
106
src/lib/gesture/pinch_gesture.cpp
Normal file
106
src/lib/gesture/pinch_gesture.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
/* WARNING: pinch gestures are experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a new pinch gesture, given configurations for certain pinch events.
|
||||||
|
*/
|
||||||
|
pinch_gesture::pinch_gesture
|
||||||
|
(
|
||||||
|
const float threshold,
|
||||||
|
const char* pinch_in3,
|
||||||
|
const char* pinch_in4,
|
||||||
|
const char* pinch_out3,
|
||||||
|
const char* pinch_out4
|
||||||
|
):
|
||||||
|
comfortable_swipe::gesture::xdo_gesture(),
|
||||||
|
threshold_squared(threshold),
|
||||||
|
commands(new const char*[4]{pinch_in3, pinch_in4, pinch_out3, pinch_out4})
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this pinch gesture.
|
||||||
|
*/
|
||||||
|
pinch_gesture::~pinch_gesture()
|
||||||
|
{
|
||||||
|
delete[] commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of pinch gesture.
|
||||||
|
*/
|
||||||
|
void pinch_gesture::begin()
|
||||||
|
{
|
||||||
|
this->previous_gesture = swipe_gesture::FRESH;
|
||||||
|
this->previous_radius = this->radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on update of swipe gesture.
|
||||||
|
*/
|
||||||
|
void swipe_gesture::update()
|
||||||
|
{
|
||||||
|
float delta_radius = this->radius - this->previous_radius;
|
||||||
|
this->previous_radius = this->radius;
|
||||||
|
if (this->delta_radius > EPSILON)
|
||||||
|
{
|
||||||
|
// TODO: pinch out
|
||||||
|
}
|
||||||
|
else if (this->delta_radius < -EPSILON)
|
||||||
|
{
|
||||||
|
// TODO: pinch in
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void pinch_gesture::end()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/* STATICS DEFINITIONS */
|
||||||
|
const int pinch_gesture::MSK_THREE_FINGERS = 0;
|
||||||
|
const int pinch_gesture::MSK_FOUR_FINGERS = 1;
|
||||||
|
const int pinch_gesture::MSK_NEGATIVE = 0;
|
||||||
|
const int pinch_gesture::MSK_POSITIVE = 2;
|
||||||
|
const int pinch_gesture::FRESH = -1;
|
||||||
|
const char * const pinch_gesture::command_map[4] = {
|
||||||
|
"pinch_in 3",
|
||||||
|
"pinch_in 4",
|
||||||
|
"pinch_out 3",
|
||||||
|
"pinch_out 4"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture__ */
|
||||||
77
src/lib/gesture/pinch_gesture.h
Normal file
77
src/lib/gesture/pinch_gesture.h
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/* WARNING: experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xdo_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class pinch_gesture : protected xdo_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
pinch_gesture(
|
||||||
|
const float threshold,
|
||||||
|
const char* pinch_in3,
|
||||||
|
const char* pinch_in4,
|
||||||
|
const char* pinch_out3,
|
||||||
|
const char* pinch_out4
|
||||||
|
);
|
||||||
|
|
||||||
|
~pinch_gesture();
|
||||||
|
float radius, omega;
|
||||||
|
|
||||||
|
void begin() override;
|
||||||
|
void update() override;
|
||||||
|
void end() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// current location
|
||||||
|
float previous_radius;
|
||||||
|
float threshold_squared;
|
||||||
|
int previous_gesture;
|
||||||
|
const char ** commands;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// static constants
|
||||||
|
static const int MSK_THREE_FINGERS;
|
||||||
|
static const int MSK_FOUR_FINGERS;
|
||||||
|
static const int MSK_NEGATIVE;
|
||||||
|
static const int MSK_POSITIVE;
|
||||||
|
static const int FRESH;
|
||||||
|
static const char * const command_map[4];
|
||||||
|
// regex patterns
|
||||||
|
static const char* GESTURE_BEGIN_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_UPDATE_REGEX_PATTERN;
|
||||||
|
static const char* GESTURE_END_REGEX_PATTERN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture_h__ */
|
||||||
94
src/lib/gesture/pinch_gesture.regex.cpp
Normal file
94
src/lib/gesture/pinch_gesture.regex.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/* WARNING: pinch gestures are experimental */
|
||||||
|
|
||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__
|
||||||
|
|
||||||
|
/*
|
||||||
|
Comfortable Swipe
|
||||||
|
by Rico Tiongson
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for start of pinch.
|
||||||
|
* Extracts one match for the number of fingers used during the pionch.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_PINCH_BEGIN +34.33s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_BEGIN_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_BEGIN" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for the end of swipe.
|
||||||
|
* Extracts one match for the number of fingers used during the swipe.
|
||||||
|
*
|
||||||
|
* eg. event15 GESTURE_PINCH_END +35.03s 3
|
||||||
|
* ^
|
||||||
|
* fingers
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_END_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_END" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// matches signed decimal numbers (eg. "6.02" "-1.1")
|
||||||
|
#define CF_NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
|
||||||
|
|
||||||
|
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
|
||||||
|
#define CF_NUMBER_DIVISION "\\s*(" CF_NUMBER_REGEX ")/\\s*(" CF_NUMBER_REGEX ")"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regex pattern for the libinput entry for during a pinch.
|
||||||
|
* Extracts number of fingers used and the speed (normal and accelerated) of the pinch.
|
||||||
|
* Extracts radius and rotational velocity of the pinch motion as well.
|
||||||
|
*
|
||||||
|
* eg. event8 GESTURE_PINCH_UPDATE +128.15s 3 -1.64/ 2.08 (-4.43/ 5.62 unaccelerated) 1.40 @ -0.14
|
||||||
|
* ^ ^ ^ ^ ^ ^ ^
|
||||||
|
* fingers dx dy udx udy radius omega
|
||||||
|
*/
|
||||||
|
const char* pinch_gesture::GESTURE_UPDATE_REGEX_PATTERN =
|
||||||
|
"^" // start of string
|
||||||
|
"[ -]event\\d+" // event
|
||||||
|
"\\s+GESTURE_PINCH_UPDATE" // gesture
|
||||||
|
"\\s+\\S+" // timestamp
|
||||||
|
"\\s+(\\d+)" // fingers
|
||||||
|
"\\s+" CF_NUMBER_DIVISION // speed (dx/dy)
|
||||||
|
"\\s+\\(" CF_NUMBER_DIVISION "\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
|
||||||
|
"\\s+(" CF_NUMBER_REGEX ")" // radius
|
||||||
|
" @\\s+(" CF_NUMBER_REGEX ")" // angular velocity (omega)
|
||||||
|
"\\s*$" // end of string
|
||||||
|
;
|
||||||
|
|
||||||
|
// delete macros
|
||||||
|
#undef CF_NUMBER_DIVISION
|
||||||
|
#undef CF_NUMBER_EXTRACT
|
||||||
|
#undef CF_NUMBER_REGEX
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_pinch_gesture_regex__ */
|
||||||
Loading…
Reference in New Issue
Block a user