Apply clang-format to source files

This commit is contained in:
Rico Tiongson 2020-04-18 14:41:22 +08:00
parent fb92169a16
commit 7d897ac09e
9 changed files with 127 additions and 149 deletions

View File

@ -16,10 +16,10 @@ 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 "src/comfortable_swipe.cpp"
#include <ios> // std::ios #include <ios> // std::ios
#include <iostream> // std::cin, std::cout, std::cerr #include <iostream> // std::cin, std::cout, std::cerr
#include <string> // std::string #include <string> // std::string
#include "src/comfortable_swipe.cpp"
/* Command-line function. */ /* Command-line function. */

View File

@ -39,9 +39,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "service/start.cpp" #include "service/start.cpp"
#include "service/status.cpp" #include "service/status.cpp"
#include "service/stop.cpp" #include "service/stop.cpp"
#include "start.cpp"
#include "util/autostart_filename.cpp" #include "util/autostart_filename.cpp"
#include "util/conf_filename.cpp" #include "util/conf_filename.cpp"
#include "util/read_config_file.cpp" #include "util/read_config_file.cpp"
#include "start.cpp"
#endif /* __COMFORTABLE_SWIPE__ */ #endif /* __COMFORTABLE_SWIPE__ */

View File

@ -32,7 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif /* COMFORTABLE_SWIPE_PROGRAM */ #endif /* COMFORTABLE_SWIPE_PROGRAM */
#ifndef COMFORTABLE_SWIPE_CONFIG #ifndef COMFORTABLE_SWIPE_CONFIG
#define COMFORTABLE_SWIPE_CONFIG \ #define COMFORTABLE_SWIPE_CONFIG \
"/usr/local/share/comfortable-swipe/comfortable-swipe.conf" "/usr/local/share/comfortable-swipe/comfortable-swipe.conf"
#endif /* COMFORTABLE_SWIPE_CONFIG */ #endif /* COMFORTABLE_SWIPE_CONFIG */

View File

@ -25,57 +25,52 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe::gesture namespace comfortable_swipe::gesture {
{ class keyboard_swipe_gesture : public swipe_gesture {
class keyboard_swipe_gesture : public swipe_gesture public:
{ // constructor
public: keyboard_swipe_gesture(const float threshold, const char *left3 /* 000 */,
// constructor const char *left4 /* 001 */,
keyboard_swipe_gesture( const char *right3 /* 010 */,
const float threshold, const char *right4 /* 011 */,
const char* left3 /* 000 */, const char *up3 /* 100 */, const char *up4 /* 101 */,
const char* left4 /* 001 */, const char *down3 /* 110 */,
const char* right3 /* 010 */, const char *down4 /* 111 */
const char* right4 /* 011 */, );
const char* up3 /* 100 */,
const char* up4 /* 101 */,
const char* down3 /* 110 */,
const char* down4 /* 111 */
);
// destructor // destructor
virtual ~keyboard_swipe_gesture(); virtual ~keyboard_swipe_gesture();
// hooks that we override // hooks that we override
virtual void begin() override; virtual void begin() override;
virtual void update() override; 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;
// stores all command strings for xdo to execute // stores all command strings for xdo to execute
const char ** commands; const char **commands;
public: public:
// static enums we will use for gesture matching // static enums we will use for gesture matching
static const int FRESH; static const int FRESH;
static const int MSK_THREE_FINGERS; static const int MSK_THREE_FINGERS;
static const int MSK_FOUR_FINGERS; static const int MSK_FOUR_FINGERS;
static const int MSK_NEGATIVE; static const int MSK_NEGATIVE;
static const int MSK_POSITIVE; static const int MSK_POSITIVE;
static const int MSK_HORIZONTAL; static const int MSK_HORIZONTAL;
static const int MSK_VERTICAL; static const int MSK_VERTICAL;
static const char * const command_map[8]; static const char *const command_map[8];
}; };
} } // namespace comfortable_swipe::gesture
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,44 +25,41 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe::gesture namespace comfortable_swipe::gesture {
{ class mouse_hold_gesture : public swipe_gesture {
class mouse_hold_gesture : public swipe_gesture public:
{ // constructor
public: mouse_hold_gesture(const char *hold3, // 3 finger mouse down
// constructor const char *hold4 // 4 finger mouse down
mouse_hold_gesture( );
const char* hold3, // 3 finger mouse down
const char* hold4 // 4 finger mouse down
);
// the button being clicked // the button being clicked
int button; int button;
virtual ~mouse_hold_gesture(); virtual ~mouse_hold_gesture();
// override begin and end for mousedown // override begin and end for mousedown
virtual void begin() override; virtual void begin() override;
virtual void update() override; virtual void update() override;
virtual void end() override; virtual void end() override;
// provide our own mouse functions // provide our own mouse functions
virtual void do_mousedown(const char*); virtual void do_mousedown(const char *);
virtual void do_mouseup(const char*); virtual void do_mouseup(const char *);
virtual bool is_mousedown() const; virtual bool is_mousedown() 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;
// flag we can use to check if mouse is down // flag we can use to check if mouse is down
bool flag_mousedown; bool flag_mousedown;
}; };
} } // namespace comfortable_swipe::gesture
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -25,46 +25,44 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe::gesture namespace comfortable_swipe::gesture {
{ class swipe_gesture : public xdo_gesture {
class swipe_gesture : public xdo_gesture public:
{ // constructor
public: swipe_gesture();
// constructor
swipe_gesture();
// destructor // destructor
virtual ~swipe_gesture(); virtual ~swipe_gesture();
// fields for xdo // fields for xdo
int fingers; int fingers;
// normal values (for touchpad mapping) // normal values (for touchpad mapping)
float x, y, dx, dy; float x, y, dx, dy;
// unaccelerated values (for screen mapping) // unaccelerated values (for screen mapping)
float ux, uy, udx, udy; float ux, uy, udx, udy;
// hooks that we can override (mark as virtual) // hooks that we can override (mark as virtual)
virtual void begin(); virtual void begin();
virtual void update(); virtual void update();
virtual void end(); virtual void end();
virtual bool parse_line(const char *); virtual bool parse_line(const char *);
protected: protected:
// location of mouse // location of mouse
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:
// regex patterns // regex patterns
static const char* GESTURE_BEGIN_REGEX_PATTERN; static const char *GESTURE_BEGIN_REGEX_PATTERN;
static const char* GESTURE_UPDATE_REGEX_PATTERN; static const char *GESTURE_UPDATE_REGEX_PATTERN;
static const char* GESTURE_END_REGEX_PATTERN; static const char *GESTURE_END_REGEX_PATTERN;
}; };
} } // namespace comfortable_swipe::gesture
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -19,30 +19,26 @@ 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/>.
*/ */
extern "C" extern "C" {
{ #include <xdo.h> // xdo_t
#include <xdo.h> // xdo_t
} }
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe namespace comfortable_swipe {
{ namespace gesture {
namespace gesture class xdo_gesture {
{ protected:
class xdo_gesture xdo_t *xdo;
{
protected:
xdo_t * xdo;
public: public:
xdo_gesture(); xdo_gesture();
virtual ~xdo_gesture(); virtual ~xdo_gesture();
}; };
} } // namespace gesture
} } // namespace comfortable_swipe
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -45,31 +45,23 @@ void start() {
// 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>
const char * const hold3 = config["hold3"].c_str(); const char *const hold3 = config["hold3"].c_str();
const char * const hold4 = config["hold4"].c_str(); const char *const hold4 = config["hold4"].c_str();
comfortable_swipe::gesture::mouse_hold_gesture mouse_hold(hold3, hold4); comfortable_swipe::gesture::mouse_hold_gesture mouse_hold(hold3, hold4);
// initialize keyboard swipe gesture handler // initialize keyboard swipe gesture handler
const float threshold = config.count("threshold") ? std::stof(config["threshold"]) : 0.0; const float threshold =
const char * const left3 = config["left3"].c_str(); config.count("threshold") ? std::stof(config["threshold"]) : 0.0;
const char * const left4 = config["left4"].c_str(); const char *const left3 = config["left3"].c_str();
const char * const right3 = config["right3"].c_str(); const char *const left4 = config["left4"].c_str();
const char * const right4 = config["right4"].c_str(); const char *const right3 = config["right3"].c_str();
const char * const up3 = config["up3"].c_str(); const char *const right4 = config["right4"].c_str();
const char * const up4 = config["up4"].c_str(); const char *const up3 = config["up3"].c_str();
const char * const down3 = config["down3"].c_str(); const char *const up4 = config["up4"].c_str();
const char * const down4 = config["down4"].c_str(); const char *const down3 = config["down3"].c_str();
const char *const down4 = config["down4"].c_str();
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe( comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe(
threshold, threshold, left3, left4, right3, right4, up3, up4, down3, down4);
left3,
left4,
right3,
right4,
up3,
up4,
down3,
down4
);
// prepare data containers // prepare data containers
std::array<char, 256> line; std::array<char, 256> line;

View File

@ -2,7 +2,7 @@
#define __COMFORTABLE_SWIPE__start_h__ #define __COMFORTABLE_SWIPE__start_h__
namespace comfortable_swipe { namespace comfortable_swipe {
void start(); void start();
} }
#endif /* __COMFORTABLE_SWIPE__start_h__ */ #endif /* __COMFORTABLE_SWIPE__start_h__ */