Improve semantics (#42)
* Keep consistency in buffer method * Revert default threshold to 0.0
This commit is contained in:
parent
b171fb2cdf
commit
f40145b6fa
@ -51,7 +51,7 @@ Comfortable swipe makes use of keyboard shortcuts for configurations. The config
|
|||||||
|
|
||||||
Property | Description | Default Value | Default Behavior
|
Property | Description | Default Value | Default Behavior
|
||||||
--------- | ----------- | -------------- | -----
|
--------- | ----------- | -------------- | -----
|
||||||
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point (Note: Sky is the limit! Can be as large as 1000.0) | 20.0
|
threshold | mouse pixels to activate swipe; higher = less sensitive; floating-point (Note: Sky is the limit! Can be as large as 1000.0) | 0.0
|
||||||
left3 | 3-finger swipe left | ctrl+shift+Right | switch to right workspace
|
left3 | 3-finger swipe left | ctrl+shift+Right | switch to right workspace
|
||||||
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
left4 | 4-finger swipe left | ctrl+alt+shift+Right | move window to right workspace
|
||||||
right3 | 3-finger swipe right | ctrl+shift+Left | switch to left workspace
|
right3 | 3-finger swipe right | ctrl+shift+Left | switch to left workspace
|
||||||
|
|||||||
@ -16,8 +16,8 @@
|
|||||||
#
|
#
|
||||||
# (Note: Sky is the limit! Can be as large as 1000.0)
|
# (Note: Sky is the limit! Can be as large as 1000.0)
|
||||||
#
|
#
|
||||||
# Default: threshold = 20.0
|
# Default: threshold = 0.0
|
||||||
threshold = 20.0
|
threshold = 0.0
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
# THREE / FOUR FINGER SWIPE #
|
# THREE / FOUR FINGER SWIPE #
|
||||||
|
|||||||
@ -37,23 +37,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "gesture/swipe_gesture.h"
|
#include "gesture/swipe_gesture.h"
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
namespace comfortable_swipe::util
|
namespace comfortable_swipe
|
||||||
{
|
{
|
||||||
extern const char* GESTURE_SWIPE_BEGIN_REGEX_PATTERN;
|
namespace util
|
||||||
extern const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN;
|
{
|
||||||
extern const char* GESTURE_SWIPE_END_REGEX_PATTERN;
|
extern const char* GESTURE_SWIPE_BEGIN_REGEX_PATTERN;
|
||||||
const char* autostart_filename();
|
extern const char* GESTURE_SWIPE_UPDATE_REGEX_PATTERN;
|
||||||
constexpr const char* conf_filename();
|
extern const char* GESTURE_SWIPE_END_REGEX_PATTERN;
|
||||||
std::map<std::string, std::string> read_config_file(const char*);
|
const char* autostart_filename();
|
||||||
}
|
constexpr const char* conf_filename();
|
||||||
namespace comfortable_swipe::service
|
std::map<std::string, std::string> read_config_file(const char*);
|
||||||
{
|
}
|
||||||
void autostart();
|
namespace service
|
||||||
void buffer();
|
{
|
||||||
void help();
|
void autostart();
|
||||||
void restart();
|
void buffer();
|
||||||
void start();
|
void help();
|
||||||
void stop();
|
void restart();
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,78 +27,76 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
/**
|
/**
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
*/
|
*/
|
||||||
void comfortable_swipe::service::buffer()
|
namespace comfortable_swipe::service
|
||||||
{
|
{
|
||||||
|
void buffer()
|
||||||
// import utility methods
|
|
||||||
using comfortable_swipe::util::read_config_file;
|
|
||||||
using comfortable_swipe::util::conf_filename;
|
|
||||||
using comfortable_swipe::gesture::swipe_gesture;
|
|
||||||
|
|
||||||
// import regex patterns
|
|
||||||
using comfortable_swipe::util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN;
|
|
||||||
using comfortable_swipe::util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN;
|
|
||||||
using comfortable_swipe::util::GESTURE_SWIPE_END_REGEX_PATTERN;
|
|
||||||
|
|
||||||
// pre-compile regex patterns
|
|
||||||
static const std::regex gesture_begin(GESTURE_SWIPE_BEGIN_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_update(GESTURE_SWIPE_UPDATE_REGEX_PATTERN);
|
|
||||||
static const std::regex gesture_end(GESTURE_SWIPE_END_REGEX_PATTERN);
|
|
||||||
|
|
||||||
// read config file
|
|
||||||
auto config = read_config_file(conf_filename());
|
|
||||||
|
|
||||||
// initialize swipegesture handler
|
|
||||||
swipe_gesture swipe
|
|
||||||
(
|
|
||||||
config.count("threshold") ? std::atof(config["threshold"].data()) : 0.0,
|
|
||||||
config["left3"].c_str(),
|
|
||||||
config["left4"].c_str(),
|
|
||||||
config["right3"].c_str(),
|
|
||||||
config["right4"].c_str(),
|
|
||||||
config["up3"].c_str(),
|
|
||||||
config["up4"].c_str(),
|
|
||||||
config["down3"].c_str(),
|
|
||||||
config["down4"].c_str()
|
|
||||||
);
|
|
||||||
|
|
||||||
// prepare data containers
|
|
||||||
static const int MAX_LINE_LENGTH = 256;
|
|
||||||
static char data[MAX_LINE_LENGTH];
|
|
||||||
static std::cmatch matches;
|
|
||||||
|
|
||||||
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
|
||||||
bool flag_begin = false;
|
|
||||||
|
|
||||||
// start reading lines from input one by one
|
|
||||||
while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL)
|
|
||||||
{
|
{
|
||||||
if (!flag_begin)
|
// read config file
|
||||||
|
auto config = comfortable_swipe::util::read_config_file(comfortable_swipe::util::conf_filename());
|
||||||
|
|
||||||
|
// pre-compile regex patterns
|
||||||
|
static const std::regex gesture_swipe_begin(comfortable_swipe::util::GESTURE_SWIPE_BEGIN_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_update(comfortable_swipe::util::GESTURE_SWIPE_UPDATE_REGEX_PATTERN);
|
||||||
|
static const std::regex gesture_swipe_end(comfortable_swipe::util::GESTURE_SWIPE_END_REGEX_PATTERN);
|
||||||
|
|
||||||
|
// initialize swipe gesture handler
|
||||||
|
comfortable_swipe::gesture::swipe_gesture swipe
|
||||||
|
(
|
||||||
|
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
||||||
|
config["left3"].c_str(),
|
||||||
|
config["left4"].c_str(),
|
||||||
|
config["right3"].c_str(),
|
||||||
|
config["right4"].c_str(),
|
||||||
|
config["up3"].c_str(),
|
||||||
|
config["up4"].c_str(),
|
||||||
|
config["down3"].c_str(),
|
||||||
|
config["down4"].c_str()
|
||||||
|
);
|
||||||
|
|
||||||
|
// prepare data containers
|
||||||
|
static const int MAX_LINE_LENGTH = 256;
|
||||||
|
static char data[MAX_LINE_LENGTH];
|
||||||
|
static std::cmatch matches;
|
||||||
|
|
||||||
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
|
bool flag_swiping = false;
|
||||||
|
|
||||||
|
// start reading lines from input one by one
|
||||||
|
while (fgets_unlocked(data, MAX_LINE_LENGTH, stdin) != NULL)
|
||||||
{
|
{
|
||||||
if (std::regex_match(data, matches, gesture_begin) != 0)
|
if (flag_swiping)
|
||||||
{
|
{
|
||||||
swipe.fingers = std::stoi(matches[1]);
|
// currently swiping
|
||||||
swipe.begin();
|
if (std::regex_match(data, matches, gesture_swipe_update) != 0)
|
||||||
flag_begin = true;
|
{
|
||||||
|
// update swipe
|
||||||
|
swipe.fingers = std::stoi(matches[1]);
|
||||||
|
swipe.dx = std::stof(matches[2]);
|
||||||
|
swipe.dy = std::stof(matches[3]);
|
||||||
|
swipe.udx = std::stof(matches[4]);
|
||||||
|
swipe.udy = std::stof(matches[5]);
|
||||||
|
swipe.update();
|
||||||
|
}
|
||||||
|
else if (std::regex_match(data, matches, gesture_swipe_end) != 0)
|
||||||
|
{
|
||||||
|
// end swipe
|
||||||
|
flag_swiping = false;
|
||||||
|
swipe.fingers = std::stoi(matches[1]);
|
||||||
|
swipe.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
else /* !flag_swiping */
|
||||||
else /* flag_begin == true */
|
|
||||||
{
|
|
||||||
if (std::regex_match(data, matches, gesture_update) != 0)
|
|
||||||
{
|
{
|
||||||
swipe.fingers = std::stoi(matches[1]);
|
// not swiping, check if swipe will begin
|
||||||
swipe.dx = std::stof(matches[2]);
|
if (std::regex_match(data, matches, gesture_swipe_begin) != 0)
|
||||||
swipe.dy = std::stof(matches[3]);
|
{
|
||||||
swipe.udx = std::stof(matches[4]);
|
// begin swipe
|
||||||
swipe.udy = std::stof(matches[5]);
|
flag_swiping = true;
|
||||||
swipe.update();
|
swipe.fingers = std::stoi(matches[1]);
|
||||||
}
|
swipe.begin();
|
||||||
else if (std::regex_match(data, matches, gesture_end) != 0)
|
}
|
||||||
{
|
|
||||||
swipe.fingers = std::stoi(matches[1]);
|
|
||||||
swipe.end();
|
|
||||||
flag_begin = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,8 @@ namespace comfortable_swipe::service
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
* Starts the comfortable-swipe service by buffering libinput debug-events.
|
||||||
|
* This method is deferred. Please refer to comfortable_swipe::service::buffer()
|
||||||
|
* for the technical implementation.
|
||||||
*/
|
*/
|
||||||
void start()
|
void start()
|
||||||
{
|
{
|
||||||
|
|||||||
29
src/main.cpp
29
src/main.cpp
@ -25,22 +25,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
int main(int argc, char** args)
|
int main(int argc, char** args)
|
||||||
{
|
{
|
||||||
using namespace comfortable_swipe::service;
|
|
||||||
|
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
std::string arg = args[1];
|
std::string arg = args[1];
|
||||||
|
|
||||||
// select based on argument
|
// select based on argument
|
||||||
if (arg == "start") start();
|
if (arg == "start")
|
||||||
else if (arg == "stop") stop();
|
comfortable_swipe::service::start();
|
||||||
else if (arg == "restart") restart();
|
|
||||||
else if (arg == "buffer") buffer();
|
|
||||||
else if (arg == "autostart") autostart();
|
|
||||||
else help();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
else if (arg == "stop")
|
||||||
|
comfortable_swipe::service::stop();
|
||||||
|
|
||||||
|
else if (arg == "restart")
|
||||||
|
comfortable_swipe::service::restart();
|
||||||
|
|
||||||
|
else if (arg == "buffer")
|
||||||
|
comfortable_swipe::service::buffer();
|
||||||
|
|
||||||
|
else if (arg == "autostart")
|
||||||
|
comfortable_swipe::service::autostart();
|
||||||
|
|
||||||
|
else /* if (arg == "help") */
|
||||||
|
comfortable_swipe::service::help();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
help();
|
comfortable_swipe::service::help();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user