Apply clang format
This commit is contained in:
parent
45ab9f9c16
commit
ffe664c7d8
@ -22,7 +22,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
* COMFORTABLE_SWIPE_CONFIG
|
* COMFORTABLE_SWIPE_CONFIG
|
||||||
*
|
*
|
||||||
* This definition points to the location of the configuration file.
|
* 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
|
#ifndef COMFORTABLE_SWIPE_CONFIG
|
||||||
#pragma message "Please define COMFORTABLE_SWIPE_CONFIG during compilation!"
|
#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
|
* COMFORTABLE_SWIPE_AUTOSTART
|
||||||
*
|
*
|
||||||
* This definition points to the location of the autostart (.desktop) file.
|
* 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
|
#ifndef COMFORTABLE_SWIPE_AUTOSTART
|
||||||
#pragma message "Please define COMFORTABLE_SWIPE_AUTOSTART during compilation!"
|
#pragma message "Please define COMFORTABLE_SWIPE_AUTOSTART during compilation!"
|
||||||
|
|||||||
@ -19,8 +19,8 @@ You should have received a copy of the GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream> // std::cout, std::endl
|
|
||||||
#include <array> // std::array
|
#include <array> // std::array
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -40,8 +40,7 @@ namespace comfortable_swipe {
|
|||||||
* When constructing, please mind the order in the
|
* When constructing, please mind the order in the
|
||||||
* `gesture_swipe_xdokey::command_name[]` static array.
|
* `gesture_swipe_xdokey::command_name[]` static array.
|
||||||
*/
|
*/
|
||||||
class gesture_swipe_xdokey : public gesture_swipe
|
class gesture_swipe_xdokey : public gesture_swipe {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
// stores the 8 command strings for xdo to execute
|
// stores the 8 command strings for xdo to execute
|
||||||
std::array<std::string, 8> commands;
|
std::array<std::string, 8> commands;
|
||||||
@ -55,11 +54,13 @@ virtual void update() override;
|
|||||||
virtual void end() override;
|
virtual void end() override;
|
||||||
// override this when keyboard gesture is to be performed
|
// override this when keyboard gesture is to be performed
|
||||||
virtual void do_keyboard_gesture(int mask);
|
virtual void do_keyboard_gesture(int mask);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// stores square of threshold so we can compute faster
|
// stores square of threshold so we can compute faster
|
||||||
float threshold_squared;
|
float threshold_squared;
|
||||||
// stores previous gesture so we don't repeat action
|
// stores previous gesture so we don't repeat action
|
||||||
int previous_gesture;
|
int previous_gesture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// static enums we will use for gesture matching
|
// static enums we will use for gesture matching
|
||||||
static const int FRESH = -1;
|
static const int FRESH = -1;
|
||||||
@ -81,8 +82,8 @@ static const std::string command_name[];
|
|||||||
* Refer to the order of this array for the "commands"
|
* Refer to the order of this array for the "commands"
|
||||||
* paramter in the constructor.
|
* paramter in the constructor.
|
||||||
*/
|
*/
|
||||||
decltype(gesture_swipe_xdokey::command_name)
|
decltype(
|
||||||
gesture_swipe_xdokey::command_name = {
|
gesture_swipe_xdokey::command_name) gesture_swipe_xdokey::command_name = {
|
||||||
// the order of variables is based on bitmasking
|
// the order of variables is based on bitmasking
|
||||||
// <VERTICAL?> | <POSITIVE?> | <FOUR FINGERS?>
|
// <VERTICAL?> | <POSITIVE?> | <FOUR FINGERS?>
|
||||||
"left3", // 000
|
"left3", // 000
|
||||||
@ -102,9 +103,9 @@ gesture_swipe_xdokey::command_name = {
|
|||||||
* scrolling direction (ie. left3 is natural movement of 3 fingers left).
|
* scrolling direction (ie. left3 is natural movement of 3 fingers left).
|
||||||
*/
|
*/
|
||||||
gesture_swipe_xdokey::gesture_swipe_xdokey(
|
gesture_swipe_xdokey::gesture_swipe_xdokey(
|
||||||
const decltype(gesture_swipe_xdokey::commands)& commands,
|
const decltype(gesture_swipe_xdokey::commands) &commands, float threshold)
|
||||||
float threshold
|
: gesture_swipe(), commands(commands),
|
||||||
): gesture_swipe(), commands(commands), threshold_squared(threshold * threshold) {}
|
threshold_squared(threshold * threshold) {}
|
||||||
/**
|
/**
|
||||||
* Destructs this keyboard swipe gesture.
|
* Destructs this keyboard swipe gesture.
|
||||||
*/
|
*/
|
||||||
@ -150,8 +151,7 @@ void gesture_swipe_xdokey::update() {
|
|||||||
mask |= gesture_swipe_xdokey::MSK_NEGATIVE;
|
mask |= gesture_swipe_xdokey::MSK_NEGATIVE;
|
||||||
else
|
else
|
||||||
mask |= gesture_swipe_xdokey::MSK_POSITIVE;
|
mask |= gesture_swipe_xdokey::MSK_POSITIVE;
|
||||||
}
|
} else /* std::abs(x) <= std::abs(y) */
|
||||||
else /* std::abs(x) <= std::abs(y) */
|
|
||||||
{
|
{
|
||||||
// gesture is vertical
|
// gesture is vertical
|
||||||
mask |= gesture_swipe_xdokey::MSK_VERTICAL;
|
mask |= gesture_swipe_xdokey::MSK_VERTICAL;
|
||||||
@ -162,8 +162,7 @@ void gesture_swipe_xdokey::update() {
|
|||||||
}
|
}
|
||||||
// send command on fresh OR opposite gesture
|
// send command on fresh OR opposite gesture
|
||||||
if (this->previous_gesture == gesture_swipe_xdokey::FRESH ||
|
if (this->previous_gesture == gesture_swipe_xdokey::FRESH ||
|
||||||
this->previous_gesture ==
|
this->previous_gesture == (mask ^ gesture_swipe_xdokey::MSK_POSITIVE)) {
|
||||||
(mask ^ gesture_swipe_xdokey::MSK_POSITIVE)) {
|
|
||||||
// finally, perform keyboard gesture
|
// finally, perform keyboard gesture
|
||||||
this->do_keyboard_gesture(mask);
|
this->do_keyboard_gesture(mask);
|
||||||
}
|
}
|
||||||
@ -174,7 +173,8 @@ void gesture_swipe_xdokey::update() {
|
|||||||
*/
|
*/
|
||||||
void gesture_swipe_xdokey::do_keyboard_gesture(int mask) {
|
void gesture_swipe_xdokey::do_keyboard_gesture(int mask) {
|
||||||
// perform our keyboard command with xdo_send_keysequence
|
// 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;
|
std::cout << "SWIPE " << command_name[mask] << std::endl;
|
||||||
// reset our location variables
|
// reset our location variables
|
||||||
this->x = this->y = 0;
|
this->x = this->y = 0;
|
||||||
@ -187,5 +187,5 @@ void gesture_swipe_xdokey::end() {
|
|||||||
// just call superclass method
|
// just call superclass method
|
||||||
gesture_swipe::end();
|
gesture_swipe::end();
|
||||||
}
|
}
|
||||||
}
|
} // namespace comfortable_swipe
|
||||||
#endif /* __comfortable_swipe_gesture_swipe_xdokey__ */
|
#endif /* __comfortable_swipe_gesture_swipe_xdokey__ */
|
||||||
|
|||||||
@ -83,10 +83,12 @@ public:
|
|||||||
virtual bool is_holding() const;
|
virtual bool is_holding() const;
|
||||||
// utility method to parse mouse input given config characters
|
// utility method to parse mouse input given config characters
|
||||||
static int parse_mouse_button(const char *);
|
static int parse_mouse_button(const char *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// command holders
|
// command holders
|
||||||
const char *hold3;
|
const char *hold3;
|
||||||
const char *hold4;
|
const char *hold4;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// flag we can use to check if mouse is down
|
// flag we can use to check if mouse is down
|
||||||
bool flag_is_holding;
|
bool flag_is_holding;
|
||||||
@ -94,7 +96,8 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
|
* 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),
|
: gesture_swipe(), button(MOUSE_NONE), hold3(hold3), hold4(hold4),
|
||||||
flag_is_holding(false) {}
|
flag_is_holding(false) {}
|
||||||
/**
|
/**
|
||||||
@ -214,6 +217,6 @@ void gesture_swipe_xdomouse::end() {
|
|||||||
// call superclass method
|
// call superclass method
|
||||||
gesture_swipe::end();
|
gesture_swipe::end();
|
||||||
}
|
}
|
||||||
}
|
} // namespace comfortable_swipe
|
||||||
|
|
||||||
#endif /* __comfortable_swipe_gesture_swipe_xdomouse__ */
|
#endif /* __comfortable_swipe_gesture_swipe_xdomouse__ */
|
||||||
|
|||||||
@ -70,6 +70,7 @@ public:
|
|||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void end();
|
virtual void end();
|
||||||
virtual bool run(const char *);
|
virtual bool run(const char *);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// xdo container
|
// xdo container
|
||||||
xdo_t *xdo;
|
xdo_t *xdo;
|
||||||
@ -77,6 +78,7 @@ protected:
|
|||||||
int screen_num, ix, iy;
|
int screen_num, ix, iy;
|
||||||
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
// optimization flag for checking if GESTURE_SWIPE_BEGIN was dispatched
|
||||||
bool flag_swiping;
|
bool flag_swiping;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// defined in: comfortable-swipe-gesture-swipe.regex.cpp
|
// defined in: comfortable-swipe-gesture-swipe.regex.cpp
|
||||||
static const std::regex GESTURE_SWIPE_BEGIN;
|
static const std::regex GESTURE_SWIPE_BEGIN;
|
||||||
@ -140,8 +142,7 @@ bool gesture_swipe::run(const char *line) {
|
|||||||
this->begin();
|
this->begin();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// currently swiping
|
// currently swiping
|
||||||
if (std::regex_match(line, matches, GESTURE_SWIPE_UPDATE) != 0) {
|
if (std::regex_match(line, matches, GESTURE_SWIPE_UPDATE) != 0) {
|
||||||
// assign necessary variables for swipe update
|
// assign necessary variables for swipe update
|
||||||
@ -172,8 +173,8 @@ bool gesture_swipe::run(const char *line) {
|
|||||||
* ^
|
* ^
|
||||||
* fingers
|
* fingers
|
||||||
*/
|
*/
|
||||||
const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
|
const std::regex
|
||||||
"^" // start of string
|
gesture_swipe::GESTURE_SWIPE_BEGIN("^" // start of string
|
||||||
"[ -]event\\d+" // event
|
"[ -]event\\d+" // event
|
||||||
"\\s+GESTURE_SWIPE_BEGIN" // gesture
|
"\\s+GESTURE_SWIPE_BEGIN" // gesture
|
||||||
"\\s+\\S+" // timestamp
|
"\\s+\\S+" // timestamp
|
||||||
@ -188,8 +189,8 @@ const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
|
|||||||
* ^
|
* ^
|
||||||
* fingers
|
* fingers
|
||||||
*/
|
*/
|
||||||
const std::regex gesture_swipe::GESTURE_SWIPE_END(
|
const std::regex
|
||||||
"^" // start of string
|
gesture_swipe::GESTURE_SWIPE_END("^" // start of string
|
||||||
"[ -]event\\d+" // event
|
"[ -]event\\d+" // event
|
||||||
"\\s+GESTURE_SWIPE_END" // gesture
|
"\\s+GESTURE_SWIPE_END" // gesture
|
||||||
"\\s+\\S+" // timestamp
|
"\\s+\\S+" // timestamp
|
||||||
|
|||||||
@ -28,13 +28,13 @@ GNU General Public License for more details.
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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-defines.cpp"
|
||||||
#include "comfortable-swipe-gesture-swipe.cpp"
|
|
||||||
#include "comfortable-swipe-gesture-swipe-xdokey.cpp"
|
#include "comfortable-swipe-gesture-swipe-xdokey.cpp"
|
||||||
#include "comfortable-swipe-gesture-swipe-xdomouse.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" {
|
extern "C" {
|
||||||
#include <ini.h> // ini_parse
|
#include <ini.h> // ini_parse
|
||||||
@ -43,8 +43,8 @@ extern "C" {
|
|||||||
/**
|
/**
|
||||||
* Registers keys and values from the config file to a map.
|
* 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[])
|
int parse_config(void *config, const char section[], const char name[],
|
||||||
{
|
const char value[]) {
|
||||||
auto &configmap = *(std::map<std::string, std::string> *)config;
|
auto &configmap = *(std::map<std::string, std::string> *)config;
|
||||||
configmap[name] = value;
|
configmap[name] = value;
|
||||||
return 0;
|
return 0;
|
||||||
@ -76,8 +76,7 @@ int main() {
|
|||||||
// up3=super+Up maximize
|
// up3=super+Up maximize
|
||||||
// down3=super+Down minimize
|
// down3=super+Down minimize
|
||||||
decltype(gesture_swipe_xdokey::commands) commands;
|
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]];
|
commands[i] = config[gesture_swipe_xdokey::command_name[i]];
|
||||||
}
|
}
|
||||||
gesture_swipe_xdokey keyswipe(commands, stof(config["threshold"]));
|
gesture_swipe_xdokey keyswipe(commands, stof(config["threshold"]));
|
||||||
@ -88,7 +87,8 @@ int main() {
|
|||||||
// hold3=button1 hold button 1 on 3 fingers
|
// hold3=button1 hold button 1 on 3 fingers
|
||||||
// hold4=button3 hold button 3 (right click) on 3 fingers
|
// hold4=button3 hold button 3 (right click) on 3 fingers
|
||||||
// hold3=ignore <do nothing>
|
// 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
|
// start reading lines from input one by one
|
||||||
for (string line; getline(cin, line);) {
|
for (string line; getline(cin, line);) {
|
||||||
// prioritize mouse hold gesture first before keyboard gesture
|
// prioritize mouse hold gesture first before keyboard gesture
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user