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
|
||||
*
|
||||
* 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!"
|
||||
|
||||
@ -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/>.
|
||||
*/
|
||||
|
||||
#include <iostream> // std::cout, std::endl
|
||||
#include <array> // std::array
|
||||
#include <iostream> // std::cout, std::endl
|
||||
#include <string> // std::string
|
||||
|
||||
extern "C" {
|
||||
@ -40,8 +40,7 @@ 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;
|
||||
@ -55,11 +54,13 @@ 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;
|
||||
|
||||
public:
|
||||
// static enums we will use for gesture matching
|
||||
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"
|
||||
* 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,9 +103,9 @@ 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.
|
||||
*/
|
||||
@ -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__ */
|
||||
|
||||
@ -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__ */
|
||||
|
||||
@ -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,8 +173,8 @@ bool gesture_swipe::run(const char *line) {
|
||||
* ^
|
||||
* fingers
|
||||
*/
|
||||
const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
|
||||
"^" // start of string
|
||||
const std::regex
|
||||
gesture_swipe::GESTURE_SWIPE_BEGIN("^" // start of string
|
||||
"[ -]event\\d+" // event
|
||||
"\\s+GESTURE_SWIPE_BEGIN" // gesture
|
||||
"\\s+\\S+" // timestamp
|
||||
@ -188,8 +189,8 @@ const std::regex gesture_swipe::GESTURE_SWIPE_BEGIN(
|
||||
* ^
|
||||
* fingers
|
||||
*/
|
||||
const std::regex gesture_swipe::GESTURE_SWIPE_END(
|
||||
"^" // start of string
|
||||
const std::regex
|
||||
gesture_swipe::GESTURE_SWIPE_END("^" // start of string
|
||||
"[ -]event\\d+" // event
|
||||
"\\s+GESTURE_SWIPE_END" // gesture
|
||||
"\\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
|
||||
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
|
||||
@ -43,8 +43,8 @@ extern "C" {
|
||||
/**
|
||||
* 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;
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user