Modify mouse move update
This commit is contained in:
parent
d03e6cc081
commit
eb69b2fce4
@ -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 <cstdio> // std::sscanf
|
#include <cstdio> // std::sscanf
|
||||||
|
#include <cstdlib> // strncmp
|
||||||
#include "mouse_swipe_gesture.h"
|
#include "mouse_swipe_gesture.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@ -60,7 +61,8 @@ namespace comfortable_swipe::gesture
|
|||||||
int mouse = this->parse_mouse_input(mouseinput);
|
int mouse = this->parse_mouse_input(mouseinput);
|
||||||
if (mouse != -1)
|
if (mouse != -1)
|
||||||
{
|
{
|
||||||
std::cout << "MOUSE DOWN " << mouse << std::endl;
|
// eg. MOUSE DOWN hold3 mouse1
|
||||||
|
std::printf("MOUSE DOWN hold%d %s\n", this->fingers, mouseinput);
|
||||||
this->flag_mousedown = true;
|
this->flag_mousedown = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ namespace comfortable_swipe::gesture
|
|||||||
int mouse = this->parse_mouse_input(mouseinput);
|
int mouse = this->parse_mouse_input(mouseinput);
|
||||||
if (mouse != -1)
|
if (mouse != -1)
|
||||||
{
|
{
|
||||||
std::cout << "MOUSE UP " << mouse << std::endl;
|
std::printf("MOUSE UP hold%d %s\n", this->fingers, mouseinput);
|
||||||
this->flag_mousedown = false;
|
this->flag_mousedown = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,12 +86,22 @@ namespace comfortable_swipe::gesture
|
|||||||
*/
|
*/
|
||||||
int mouse_swipe_gesture::parse_mouse_input(const char *input)
|
int mouse_swipe_gesture::parse_mouse_input(const char *input)
|
||||||
{
|
{
|
||||||
// parse mouse number
|
// check if "mouse" is prefix
|
||||||
int mouseno;
|
if (strncmp(input, "mouse", 5) == 0)
|
||||||
if (std::sscanf(input, "mouse%d", &mouseno) == 1)
|
|
||||||
{
|
{
|
||||||
return mouseno;
|
if (input[5] == '\0')
|
||||||
|
{
|
||||||
|
// just "mouse" without a number
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int mouseno;
|
||||||
|
if (std::sscanf(input + 5, "%d", &mouseno) == 1)
|
||||||
|
{
|
||||||
|
// parse the number after "mouse"
|
||||||
|
return mouseno;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,8 +132,14 @@ namespace comfortable_swipe::gesture
|
|||||||
swipe_gesture::update();
|
swipe_gesture::update();
|
||||||
if (this->is_mousedown())
|
if (this->is_mousedown())
|
||||||
{
|
{
|
||||||
// TODO: drag mouse while it's updating
|
// ix, iy: mouse location on begin
|
||||||
std::cout << this->dx << " " << this->dy << std::endl;
|
// ux, uy: integral of mouse accelerations
|
||||||
|
xdo_move_mouse(
|
||||||
|
this->xdo,
|
||||||
|
this->ix + this->ux,
|
||||||
|
this->iy + this->uy,
|
||||||
|
this->screen_num
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,9 @@ namespace comfortable_swipe::gesture
|
|||||||
virtual void do_mouseup(const char*);
|
virtual void do_mouseup(const char*);
|
||||||
virtual bool is_mousedown();
|
virtual bool is_mousedown();
|
||||||
|
|
||||||
|
// utility method to parse mouse input given config characters
|
||||||
|
virtual int parse_mouse_input(const char*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// command holders
|
// command holders
|
||||||
const char * hold3;
|
const char * hold3;
|
||||||
@ -55,10 +58,6 @@ namespace comfortable_swipe::gesture
|
|||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
private:
|
|
||||||
// utility method to parse mouse input given config characters
|
|
||||||
int parse_mouse_input(const char*);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -58,10 +58,13 @@ namespace comfortable_swipe::gesture
|
|||||||
*/
|
*/
|
||||||
void swipe_gesture::begin()
|
void swipe_gesture::begin()
|
||||||
{
|
{
|
||||||
|
// save current screen location for gestured mouse movement
|
||||||
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy,
|
xdo_get_mouse_location(this->xdo, &this->ix, &this->iy,
|
||||||
&this->screen_num);
|
&this->screen_num);
|
||||||
this->x = 0;
|
this->x = 0;
|
||||||
this->y = 0;
|
this->y = 0;
|
||||||
|
this->ux = 0;
|
||||||
|
this->uy = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,6 +74,8 @@ namespace comfortable_swipe::gesture
|
|||||||
{
|
{
|
||||||
this->x += this->dx;
|
this->x += this->dx;
|
||||||
this->y += this->dy;
|
this->y += this->dy;
|
||||||
|
this->ux += this->udx;
|
||||||
|
this->uy += this->udy;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -38,7 +38,12 @@ namespace comfortable_swipe::gesture
|
|||||||
|
|
||||||
// fields for xdo
|
// fields for xdo
|
||||||
int fingers;
|
int fingers;
|
||||||
float x, y, dx, dy, udx, udy;
|
|
||||||
|
// normal values (for touchpad mapping)
|
||||||
|
float x, y, dx, dy;
|
||||||
|
|
||||||
|
// unaccelerated values (for screen mapping)
|
||||||
|
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();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user