Apply clang format

This commit is contained in:
Rico Tiongson 2020-04-20 19:36:26 +08:00
parent 45ab9f9c16
commit ffe664c7d8
5 changed files with 84 additions and 78 deletions

View File

@ -22,7 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* COMFORTABLE_SWIPE_CONFIG
*
* This definition points to the location of the configuration file.
* A warning will be issued to the compiler if you do not define this at compile time.
* A warning will be issued to the compiler if you do not define this at compile
* time.
*/
#ifndef COMFORTABLE_SWIPE_CONFIG
#pragma message "Please define COMFORTABLE_SWIPE_CONFIG during compilation!"
@ -33,7 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* COMFORTABLE_SWIPE_AUTOSTART
*
* This definition points to the location of the autostart (.desktop) file.
* A warning will be issued to the compiler if you do not define this at compile time.
* A warning will be issued to the compiler if you do not define this at compile
* time.
*/
#ifndef COMFORTABLE_SWIPE_AUTOSTART
#pragma message "Please define COMFORTABLE_SWIPE_AUTOSTART during compilation!"

View File

@ -19,9 +19,9 @@ 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 <array> // std::array
#include <iostream> // std::cout, std::endl
#include <array> // std::array
#include <string> // std::string
#include <string> // std::string
extern "C" {
#include <xdo.h> // xdo_send_keysequence_window
@ -40,37 +40,38 @@ namespace comfortable_swipe {
* When constructing, please mind the order in the
* `gesture_swipe_xdokey::command_name[]` static array.
*/
class gesture_swipe_xdokey : public gesture_swipe
{
class gesture_swipe_xdokey : public gesture_swipe {
public:
// stores the 8 command strings for xdo to execute
std::array<std::string, 8> commands;
// constructor
gesture_swipe_xdokey(const decltype(commands)& commands, float threshold=0);
// destructor
virtual ~gesture_swipe_xdokey();
// hooks that we override
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// override this when keyboard gesture is to be performed
virtual void do_keyboard_gesture(int mask);
// stores the 8 command strings for xdo to execute
std::array<std::string, 8> commands;
// constructor
gesture_swipe_xdokey(const decltype(commands) &commands, float threshold = 0);
// destructor
virtual ~gesture_swipe_xdokey();
// hooks that we override
virtual void begin() override;
virtual void update() override;
virtual void end() override;
// override this when keyboard gesture is to be performed
virtual void do_keyboard_gesture(int mask);
protected:
// stores square of threshold so we can compute faster
float threshold_squared;
// stores previous gesture so we don't repeat action
int previous_gesture;
// stores square of threshold so we can compute faster
float threshold_squared;
// stores previous gesture so we don't repeat action
int previous_gesture;
public:
// static enums we will use for gesture matching
static const int FRESH = -1;
static const int MSK_THREE_FINGERS = 0;
static const int MSK_FOUR_FINGERS = 1;
static const int MSK_NEGATIVE = 0;
static const int MSK_POSITIVE = 2;
static const int MSK_HORIZONTAL = 0;
static const int MSK_VERTICAL = 4;
// mappings to our command string names
static const std::string command_name[];
// static enums we will use for gesture matching
static const int FRESH = -1;
static const int MSK_THREE_FINGERS = 0;
static const int MSK_FOUR_FINGERS = 1;
static const int MSK_NEGATIVE = 0;
static const int MSK_POSITIVE = 2;
static const int MSK_HORIZONTAL = 0;
static const int MSK_VERTICAL = 4;
// mappings to our command string names
static const std::string command_name[];
};
/**
* Our mapped directional command names. These will be
@ -81,8 +82,8 @@ static const std::string command_name[];
* Refer to the order of this array for the "commands"
* paramter in the constructor.
*/
decltype(gesture_swipe_xdokey::command_name)
gesture_swipe_xdokey::command_name = {
decltype(
gesture_swipe_xdokey::command_name) gesture_swipe_xdokey::command_name = {
// the order of variables is based on bitmasking
// <VERTICAL?> | <POSITIVE?> | <FOUR FINGERS?>
"left3", // 000
@ -102,13 +103,13 @@ gesture_swipe_xdokey::command_name = {
* scrolling direction (ie. left3 is natural movement of 3 fingers left).
*/
gesture_swipe_xdokey::gesture_swipe_xdokey(
const decltype(gesture_swipe_xdokey::commands)& commands,
float threshold
): gesture_swipe(), commands(commands), threshold_squared(threshold * threshold) {}
const decltype(gesture_swipe_xdokey::commands) &commands, float threshold)
: gesture_swipe(), commands(commands),
threshold_squared(threshold * threshold) {}
/**
* Destructs this keyboard swipe gesture.
*/
gesture_swipe_xdokey::~gesture_swipe_xdokey() { }
gesture_swipe_xdokey::~gesture_swipe_xdokey() {}
/**
* Hook on begin of swipe gesture.
*/
@ -150,8 +151,7 @@ void gesture_swipe_xdokey::update() {
mask |= gesture_swipe_xdokey::MSK_NEGATIVE;
else
mask |= gesture_swipe_xdokey::MSK_POSITIVE;
}
else /* std::abs(x) <= std::abs(y) */
} else /* std::abs(x) <= std::abs(y) */
{
// gesture is vertical
mask |= gesture_swipe_xdokey::MSK_VERTICAL;
@ -162,8 +162,7 @@ void gesture_swipe_xdokey::update() {
}
// send command on fresh OR opposite gesture
if (this->previous_gesture == gesture_swipe_xdokey::FRESH ||
this->previous_gesture ==
(mask ^ gesture_swipe_xdokey::MSK_POSITIVE)) {
this->previous_gesture == (mask ^ gesture_swipe_xdokey::MSK_POSITIVE)) {
// finally, perform keyboard gesture
this->do_keyboard_gesture(mask);
}
@ -174,7 +173,8 @@ void gesture_swipe_xdokey::update() {
*/
void gesture_swipe_xdokey::do_keyboard_gesture(int mask) {
// perform our keyboard command with xdo_send_keysequence
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, commands[mask].data(), 0);
xdo_send_keysequence_window(this->xdo, CURRENTWINDOW, commands[mask].data(),
0);
std::cout << "SWIPE " << command_name[mask] << std::endl;
// reset our location variables
this->x = this->y = 0;
@ -187,5 +187,5 @@ void gesture_swipe_xdokey::end() {
// just call superclass method
gesture_swipe::end();
}
}
} // namespace comfortable_swipe
#endif /* __comfortable_swipe_gesture_swipe_xdokey__ */

View File

@ -68,7 +68,7 @@ public:
int button;
// constructor
gesture_swipe_xdomouse(const char *hold3, // 3 finger mouse down
const char *hold4 // 4 finger mouse down
const char *hold4 // 4 finger mouse down
);
// destructor
virtual ~gesture_swipe_xdomouse();
@ -83,10 +83,12 @@ public:
virtual bool is_holding() const;
// utility method to parse mouse input given config characters
static int parse_mouse_button(const char *);
protected:
// command holders
const char *hold3;
const char *hold4;
private:
// flag we can use to check if mouse is down
bool flag_is_holding;
@ -94,7 +96,8 @@ private:
/**
* Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
*/
gesture_swipe_xdomouse::gesture_swipe_xdomouse(const char *hold3, const char *hold4)
gesture_swipe_xdomouse::gesture_swipe_xdomouse(const char *hold3,
const char *hold4)
: gesture_swipe(), button(MOUSE_NONE), hold3(hold3), hold4(hold4),
flag_is_holding(false) {}
/**
@ -214,6 +217,6 @@ void gesture_swipe_xdomouse::end() {
// call superclass method
gesture_swipe::end();
}
}
} // namespace comfortable_swipe
#endif /* __comfortable_swipe_gesture_swipe_xdomouse__ */

View File

@ -70,6 +70,7 @@ public:
virtual void update();
virtual void end();
virtual bool run(const char *);
protected:
// xdo container
xdo_t *xdo;
@ -77,6 +78,7 @@ protected:
int screen_num, ix, iy;
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
bool flag_swiping;
public:
// defined in: comfortable-swipe-gesture-swipe.regex.cpp
static const std::regex GESTURE_SWIPE_BEGIN;
@ -140,8 +142,7 @@ bool gesture_swipe::run(const char *line) {
this->begin();
return true;
}
}
else {
} else {
// currently swiping
if (std::regex_match(line, matches, GESTURE_SWIPE_UPDATE) != 0) {
// assign necessary variables for swipe update
@ -172,14 +173,14 @@ bool gesture_swipe::run(const char *line) {
* ^
* fingers
*/
const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
"^" // start of string
"[ -]event\\d+" // event
"\\s+GESTURE_SWIPE_BEGIN" // gesture
"\\s+\\S+" // timestamp
"\\s+(\\d+)" // fingers
"\\s*$" // end of string
);
const std::regex
gesture_swipe::GESTURE_SWIPE_BEGIN("^" // start of string
"[ -]event\\d+" // event
"\\s+GESTURE_SWIPE_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.
@ -188,14 +189,14 @@ const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
* ^
* fingers
*/
const std::regex gesture_swipe::GESTURE_SWIPE_END(
"^" // start of string
"[ -]event\\d+" // event
"\\s+GESTURE_SWIPE_END" // gesture
"\\s+\\S+" // timestamp
"\\s+(\\d+)" // fingers
"\\s*$" // end of string
);
const std::regex
gesture_swipe::GESTURE_SWIPE_END("^" // start of string
"[ -]event\\d+" // event
"\\s+GESTURE_SWIPE_END" // gesture
"\\s+\\S+" // timestamp
"\\s+(\\d+)" // fingers
"\\s*$" // end of string
);
// matches signed decimal numbers (eg. "6.02" "-1.1")
#define _NUMBER_REGEX "-?\\d+(?:\\.\\d+)"
// matches and extracts a space-prefixed signed fraction (eg. "-3.00/ 5.12")
@ -218,8 +219,8 @@ const std::regex gesture_swipe::GESTURE_SWIPE_UPDATE(
"\\s+(\\d+)" // fingers
"\\s+" _NUMBER_DIVISION // speed (dx/dy)
"\\s+\\(" _NUMBER_DIVISION
"\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
"\\s*$" // end of string
"\\s+unaccelerated\\)" // unaccelerated speed (udx/udy)
"\\s*$" // end of string
);
// clean up temporary macros
#undef _NUMBER_DIVISION

View File

@ -28,24 +28,24 @@ 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::ios, std::cin, std::getline
#include <string> // std::string
#include <map> // std::map
#include "comfortable-swipe-defines.cpp"
#include "comfortable-swipe-gesture-swipe.cpp"
#include "comfortable-swipe-gesture-swipe-xdokey.cpp"
#include "comfortable-swipe-gesture-swipe-xdomouse.cpp"
#include "comfortable-swipe-gesture-swipe.cpp"
#include <iostream> // std::ios, std::cin, std::getline
#include <map> // std::map
#include <string> // std::string
extern "C" {
#include <ini.h> // ini_parse
#include <ini.h> // ini_parse
}
/**
* Registers keys and values from the config file to a map.
*/
int parse_config(void* config, const char section[], const char name[], const char value[])
{
auto& configmap = *(std::map<std::string, std::string>*) config;
int parse_config(void *config, const char section[], const char name[],
const char value[]) {
auto &configmap = *(std::map<std::string, std::string> *)config;
configmap[name] = value;
return 0;
}
@ -76,8 +76,7 @@ int main() {
// up3=super+Up maximize
// down3=super+Down minimize
decltype(gesture_swipe_xdokey::commands) commands;
for (size_t i = 0; i < commands.size(); ++i)
{
for (size_t i = 0; i < commands.size(); ++i) {
commands[i] = config[gesture_swipe_xdokey::command_name[i]];
}
gesture_swipe_xdokey keyswipe(commands, stof(config["threshold"]));
@ -88,7 +87,8 @@ int main() {
// hold3=button1 hold button 1 on 3 fingers
// hold4=button3 hold button 3 (right click) on 3 fingers
// hold3=ignore <do nothing>
gesture_swipe_xdomouse mousehold(config["hold3"].data(), config["hold4"].data());
gesture_swipe_xdomouse mousehold(config["hold3"].data(),
config["hold4"].data());
// start reading lines from input one by one
for (string line; getline(cin, line);) {
// prioritize mouse hold gesture first before keyboard gesture