Prepare mouse swipe gesture skeleton
This commit is contained in:
parent
9143c715c6
commit
d03e6cc081
@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "gesture/swipe_gesture.cpp"
|
#include "gesture/swipe_gesture.cpp"
|
||||||
#include "gesture/swipe_gesture.regex.cpp"
|
#include "gesture/swipe_gesture.regex.cpp"
|
||||||
#include "gesture/keyboard_swipe_gesture.cpp"
|
#include "gesture/keyboard_swipe_gesture.cpp"
|
||||||
|
#include "gesture/mouse_swipe_gesture.cpp"
|
||||||
#include "service/autostart.cpp"
|
#include "service/autostart.cpp"
|
||||||
#include "service/buffer.cpp"
|
#include "service/buffer.cpp"
|
||||||
#include "service/config.cpp"
|
#include "service/config.cpp"
|
||||||
|
|||||||
@ -20,8 +20,6 @@ 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 <string> // std::stoi, std::stof
|
|
||||||
#include <regex> // std::regex, std::regex_match, std::cmatch
|
|
||||||
#include "keyboard_swipe_gesture.h"
|
#include "keyboard_swipe_gesture.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
|
|||||||
159
lib/gesture/mouse_swipe_gesture.cpp
Normal file
159
lib/gesture/mouse_swipe_gesture.cpp
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_swipe_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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream> // std::cout, std::endl
|
||||||
|
#include <cstdio> // std::sscanf
|
||||||
|
#include "mouse_swipe_gesture.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#include <xdo.h> // xdo, xdo_new, xdo_free,
|
||||||
|
// xdo_get_mouse_location
|
||||||
|
// CURRENT_WINDOW
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
|
||||||
|
*/
|
||||||
|
mouse_swipe_gesture::mouse_swipe_gesture
|
||||||
|
(
|
||||||
|
const char* hold3,
|
||||||
|
const char* hold4
|
||||||
|
):
|
||||||
|
comfortable_swipe::gesture::swipe_gesture(),
|
||||||
|
hold3(hold3),
|
||||||
|
hold4(hold4),
|
||||||
|
flag_mousedown(false)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Destructs this mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
mouse_swipe_gesture::~mouse_swipe_gesture()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run mousedown command on hold input.
|
||||||
|
*/
|
||||||
|
void mouse_swipe_gesture::do_mousedown(const char * mouseinput)
|
||||||
|
{
|
||||||
|
int mouse = this->parse_mouse_input(mouseinput);
|
||||||
|
if (mouse != -1)
|
||||||
|
{
|
||||||
|
std::cout << "MOUSE DOWN " << mouse << std::endl;
|
||||||
|
this->flag_mousedown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void mouse_swipe_gesture::do_mouseup(const char * mouseinput)
|
||||||
|
{
|
||||||
|
int mouse = this->parse_mouse_input(mouseinput);
|
||||||
|
if (mouse != -1)
|
||||||
|
{
|
||||||
|
std::cout << "MOUSE UP " << mouse << std::endl;
|
||||||
|
this->flag_mousedown = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to parse mouse number from input.
|
||||||
|
* Returns -1 on failure.
|
||||||
|
*/
|
||||||
|
int mouse_swipe_gesture::parse_mouse_input(const char *input)
|
||||||
|
{
|
||||||
|
// parse mouse number
|
||||||
|
int mouseno;
|
||||||
|
if (std::sscanf(input, "mouse%d", &mouseno) == 1)
|
||||||
|
{
|
||||||
|
return mouseno;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on begin of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_swipe_gesture::begin()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::begin();
|
||||||
|
// dispatch mouse down event
|
||||||
|
if (this->fingers == 3)
|
||||||
|
{
|
||||||
|
this->do_mousedown(this->hold3);
|
||||||
|
}
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
{
|
||||||
|
this->do_mousedown(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of mouse swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_swipe_gesture::update()
|
||||||
|
{
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::update();
|
||||||
|
if (this->is_mousedown())
|
||||||
|
{
|
||||||
|
// TODO: drag mouse while it's updating
|
||||||
|
std::cout << this->dx << " " << this->dy << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hook on end of swipe gesture.
|
||||||
|
*/
|
||||||
|
void mouse_swipe_gesture::end()
|
||||||
|
{
|
||||||
|
if (this->is_mousedown())
|
||||||
|
{
|
||||||
|
if (this->fingers == 3)
|
||||||
|
{
|
||||||
|
this->do_mouseup(this->hold3);
|
||||||
|
}
|
||||||
|
else if (this->fingers == 4)
|
||||||
|
{
|
||||||
|
this->do_mouseup(this->hold4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// call superclass method
|
||||||
|
swipe_gesture::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to check if mouse is current held.
|
||||||
|
*/
|
||||||
|
bool mouse_swipe_gesture::is_mousedown()
|
||||||
|
{
|
||||||
|
return this->flag_mousedown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture__ */
|
||||||
69
lib/gesture/mouse_swipe_gesture.h
Normal file
69
lib/gesture/mouse_swipe_gesture.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#ifndef __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture_h__
|
||||||
|
#define __COMFORTABLE_SWIPE__gesture_mouse_swipe_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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "swipe_gesture.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace comfortable_swipe::gesture
|
||||||
|
{
|
||||||
|
class mouse_swipe_gesture : public swipe_gesture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructor
|
||||||
|
mouse_swipe_gesture(
|
||||||
|
const char* hold3, // 3 finger mouse down
|
||||||
|
const char* hold4 // 4 finger mouse down
|
||||||
|
);
|
||||||
|
|
||||||
|
virtual ~mouse_swipe_gesture();
|
||||||
|
|
||||||
|
// override begin and end for mousedown
|
||||||
|
virtual void begin() override;
|
||||||
|
virtual void update() override;
|
||||||
|
virtual void end() override;
|
||||||
|
|
||||||
|
// provide our own mouse functions
|
||||||
|
virtual void do_mousedown(const char*);
|
||||||
|
virtual void do_mouseup(const char*);
|
||||||
|
virtual bool is_mousedown();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// command holders
|
||||||
|
const char * hold3;
|
||||||
|
const char * hold4;
|
||||||
|
|
||||||
|
// flag we can use to check if mouse is down
|
||||||
|
bool flag_mousedown;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// utility method to parse mouse input given config characters
|
||||||
|
int parse_mouse_input(const char*);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture_h__ */
|
||||||
@ -40,7 +40,7 @@ namespace comfortable_swipe::service
|
|||||||
comfortable_swipe::util::conf_filename()
|
comfortable_swipe::util::conf_filename()
|
||||||
);
|
);
|
||||||
|
|
||||||
// initialize swipe gesture handler
|
// initialize keyboard swipe gesture handler
|
||||||
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe
|
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe
|
||||||
(
|
(
|
||||||
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
|
||||||
@ -54,14 +54,28 @@ namespace comfortable_swipe::service
|
|||||||
config["down4"].c_str()
|
config["down4"].c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// initialize mouse swipe gesture handler
|
||||||
|
comfortable_swipe::gesture::mouse_swipe_gesture mouse_hold
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
"mouse1"
|
||||||
|
);
|
||||||
|
|
||||||
// prepare data containers
|
// prepare data containers
|
||||||
std::array<char, 256> line;
|
std::array<char, 256> line;
|
||||||
|
|
||||||
// start reading lines from input one by one
|
// start reading lines from input one by one
|
||||||
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
|
||||||
{
|
{
|
||||||
// attempt to parse swipe gestures
|
// prioritize mouse hold gesture first
|
||||||
keyboard_swipe.parse_line(line.data());
|
mouse_hold.parse_line(line.data());
|
||||||
|
|
||||||
|
// if mouse hold fails, try keyboard hold
|
||||||
|
if (!mouse_hold.is_mousedown())
|
||||||
|
{
|
||||||
|
// attempt to parse keyboard gestures
|
||||||
|
keyboard_swipe.parse_line(line.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user