Merge pull request #43 from Hikari9/xdo-gesture

Derive gestures from xdo_gesture interface
This commit is contained in:
Rico Tiongson 2019-02-07 21:32:10 +08:00 committed by GitHub
commit f3909f85f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 249 additions and 149 deletions

View File

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
* Make sure to include all implementation (.cpp) files below to be ready for export. * Make sure to include all implementation (.cpp) files below to be ready for export.
*/ */
#include "gesture/xdo_gesture.cpp"
#include "gesture/swipe_gesture.cpp" #include "gesture/swipe_gesture.cpp"
#include "service/autostart.cpp" #include "service/autostart.cpp"
#include "service/buffer.cpp" #include "service/buffer.cpp"

View File

@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream> // std::cout, std::endl #include <iostream> // std::cout, std::endl
#include "../index.hpp" #include "../index.hpp"
#include "xdo_gesture.h"
extern "C" extern "C"
{ {
@ -29,12 +30,10 @@ extern "C"
// CURRENT_WINDOW // CURRENT_WINDOW
} }
namespace comfortable_swipe namespace comfortable_swipe::gesture
{
namespace gesture
{ {
/** /**
* Constructs a new swipe gesture with xdo. * Constructs a new swipe gesture, given configurations for certain swipe events.
*/ */
swipe_gesture::swipe_gesture swipe_gesture::swipe_gesture
( (
@ -48,16 +47,15 @@ namespace comfortable_swipe
const char* down3 /* 110 */, const char* down3 /* 110 */,
const char* down4 /* 111 */ const char* down4 /* 111 */
): ):
xdo(xdo_new(NULL)), comfortable_swipe::gesture::xdo_gesture(),
commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4}) commands(new const char*[8]{left3, left4, right3, right4, up3, up4, down3, down4})
{ } { }
/** /**
* Constructs a new swipe gesture with xdo. * Destructs this swipe gesture.
*/ */
swipe_gesture::~swipe_gesture() swipe_gesture::~swipe_gesture()
{ {
xdo_free(this->xdo);
delete[] commands; delete[] commands;
} }
@ -145,6 +143,5 @@ namespace comfortable_swipe
"down 4" "down 4"
}; };
} }
}
#endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */ #endif /* __COMFORTABLE_SWIPE__gesture_swipe_gesture__ */

View File

@ -24,27 +24,28 @@ extern "C"
#include <xdo.h> // xdo_t #include <xdo.h> // xdo_t
} }
#include "xdo_gesture.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
namespace comfortable_swipe namespace comfortable_swipe::gesture
{ {
namespace gesture class swipe_gesture : protected xdo_gesture
{
struct swipe_gesture
{ {
public:
// constructor // constructor
swipe_gesture( swipe_gesture(
const float, const float threshold,
const char*, const char* left3 /* 000 */,
const char*, const char* left4 /* 001 */,
const char*, const char* right3 /* 010 */,
const char*, const char* right4 /* 011 */,
const char*, const char* up3 /* 100 */,
const char*, const char* up4 /* 101 */,
const char*, const char* down3 /* 110 */,
const char* const char* down4 /* 111 */
); );
~swipe_gesture(); ~swipe_gesture();
@ -52,8 +53,12 @@ namespace comfortable_swipe
// fields for xdo // fields for xdo
int fingers; int fingers;
float dx, dy, udx, udy; float dx, dy, udx, udy;
xdo_t * xdo;
void begin() override;
void update() override;
void end() override;
protected:
// location of mouse // location of mouse
int screen_num, ix, iy; int screen_num, ix, iy;
@ -62,12 +67,8 @@ namespace comfortable_swipe
int previous_gesture; int previous_gesture;
const char ** commands; const char ** commands;
// hooks public:
void update(); // static constants
void begin();
void end();
// statics
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;
@ -78,7 +79,6 @@ namespace comfortable_swipe
static const char * const command_map[8]; static const char * const command_map[8];
}; };
} }
}
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -0,0 +1,45 @@
#ifndef __COMFORTABLE_SWIPE__xdo_gesture__
#define __COMFORTABLE_SWIPE__xdo_gesture__
/*
Comfortable Swipe
by Rico Tiongson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
*/
extern "C"
{
#include <xdo.h> // xdo, xdo_new
}
namespace comfortable_swipe::gesture
{
/**
* Constructs a new gesture handler with xdo.
*/
xdo_gesture::xdo_gesture():
xdo(xdo_new(NULL))
{ }
/**
* Constructs a new swipe gesture with xdo.
*/
xdo_gesture::~xdo_gesture()
{
xdo_free(this->xdo);
}
}
#endif /* __COMFORTABLE_SWIPE__xdo_gesture__ */

View File

@ -0,0 +1,56 @@
#ifndef __COMFORTABLE_SWIPE__xdo_gesture_h__
#define __COMFORTABLE_SWIPE__xdo_gesture_h__
/*
Comfortable Swipe
by Rico Tiongson
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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/>.
*/
extern "C"
{
#include <xdo.h> // xdo_t
}
#ifdef __cplusplus
extern "C" {
#endif
namespace comfortable_swipe
{
namespace gesture
{
class xdo_gesture
{
protected:
xdo_t * xdo;
public:
xdo_gesture();
~xdo_gesture();
// hooks
virtual void begin() = 0;
virtual void update() = 0;
virtual void end() = 0;
};
}
}
#ifdef __cplusplus
}
#endif
#endif /* __COMFORTABLE_SWIPE__xdo_gesture_h__ */

View File

@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/** /**
* Make sure to include your header files here so that they can be imported by other modules. * Make sure to include your header files here so that they can be imported by other modules.
*/ */
#include "gesture/xdo_gesture.h"
#include "gesture/swipe_gesture.h" #include "gesture/swipe_gesture.h"
extern "C" extern "C"
{ {