Optimize swipe function

This commit is contained in:
Rico Tiongson 2019-03-03 21:58:23 +08:00
parent 0f7a222d86
commit 186fcbab7c
2 changed files with 9 additions and 3 deletions

View File

@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream> // std::cout, std::endl #include <iostream> // std::cout, std::endl
#include <string> // std::stoi, std::stof #include <string> // std::stoi, std::stof
#include <regex> // std::regex, std::regex_match, std::cmatch #include <regex> // std::regex, std::regex_match, std::cmatch
#include <ctime>
#include "swipe_gesture.h" #include "swipe_gesture.h"
extern "C" extern "C"
@ -50,7 +51,8 @@ namespace comfortable_swipe::gesture
): ):
comfortable_swipe::gesture::xdo_gesture(), comfortable_swipe::gesture::xdo_gesture(),
threshold_squared(threshold*threshold), threshold_squared(threshold*threshold),
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}) commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}),
flag_swiping(false)
{ {
// improve responsiveness of first gesture by pre-empting xdotool runtime // improve responsiveness of first gesture by pre-empting xdotool runtime
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num); xdo_get_mouse_location(this->xdo, &this->ix, &this->iy, &this->screen_num);
@ -139,8 +141,6 @@ namespace comfortable_swipe::gesture
*/ */
bool swipe_gesture::parse_line(const char * line) bool swipe_gesture::parse_line(const char * line)
{ {
// prepare regex matchers (will only load at most once)
static const std::regex gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN); static const std::regex gesture_swipe_begin(swipe_gesture::GESTURE_BEGIN_REGEX_PATTERN);
static const std::regex gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN); static const std::regex gesture_swipe_update(swipe_gesture::GESTURE_UPDATE_REGEX_PATTERN);
static const std::regex gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN); static const std::regex gesture_swipe_end(swipe_gesture::GESTURE_END_REGEX_PATTERN);

View File

@ -20,6 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "_index.hpp" #include "_index.hpp"
#include <iostream> // std::cin, std::cout, std::ios
#include <cstdlib> // std::system #include <cstdlib> // std::system
#include <unistd.h> // pipe, fork, perror, exit #include <unistd.h> // pipe, fork, perror, exit
@ -32,6 +33,11 @@ namespace comfortable_swipe::service
*/ */
void start() void start()
{ {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
std::cout.flush();
// redirect stdout to stdin // redirect stdout to stdin
int fd[2]; int fd[2];
pipe(fd); // create the pipes pipe(fd); // create the pipes