aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/Makefile.in2
-rw-r--r--src/ivypointer.c202
3 files changed, 132 insertions, 74 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4af348e..7c46171 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,3 +1,3 @@
bin_PROGRAMS = ivypointer
ivypointer_SOURCES = ivypointer.c getopt.c
-ivypointer_LDADD = -livy -lX11 -lXtst
+ivypointer_LDADD = -livy -lX11 -lXtst -lpcre -lXi
diff --git a/src/Makefile.in b/src/Makefile.in
index 1247e33..c683a27 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -144,7 +144,7 @@ target_alias = @target_alias@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
ivypointer_SOURCES = ivypointer.c getopt.c
-ivypointer_LDADD = -livy -lX11 -lXtst
+ivypointer_LDADD = -livy -lX11 -lXtst -lpcre -lXi
all: all-am
.SUFFIXES:
diff --git a/src/ivypointer.c b/src/ivypointer.c
index 95ade81..55b9343 100644
--- a/src/ivypointer.c
+++ b/src/ivypointer.c
@@ -26,9 +26,17 @@
# include <X11/Xlib.h>
# include <X11/X.h>
# include <X11/Xutil.h>
+//# include<X11/extensions/XInput.h>
+//# include<X11/extensions/shape.h>
# define XK_MISCELLANY
# define XK_XKB_KEYS
# include <X11/keysymdef.h>
+# ifndef IsXExtensionKeyboard
+# define IsXExtensionKeyboard 3
+# endif
+# ifndef IsXExtensionPointer
+# define IsXExtensionPointer 4
+# endif
# if HAVE_X11_EXTENSIONS_XTEST_H
# include <X11/extensions/XTest.h>
# else
@@ -70,6 +78,7 @@
#define TIME_BETWEEN_CLICK 200
Display* display = NULL;
+XDevice* device = NULL;
int width,height;
float coords_input[4] = {0.0,0.0,100.0,100.0};
int width_input,height_input, offsetx, offsety;
@@ -77,6 +86,9 @@ int width_input,height_input, offsetx, offsety;
int dragged = 0;
int relative = 0;
+int champX = 1;
+int champY = 2;
+
Display*
openDisplay(const char* displayName)
{
@@ -125,6 +137,41 @@ openDisplay(const char* displayName)
}
#endif
+// XDeviceInfo* devices;
+// int devicecount;
+//
+// devices = XListInputDevices(display, &devicecount);
+//// printf("there are %d available devices :\n",devicecount);
+// while(devicecount)
+// {
+// XDeviceInfo* currDevice;
+//
+// currDevice = &devices[--devicecount];
+// switch(currDevice->use){
+// case IsXPointer:
+// printf("xpointer id=%d\n",(int)currDevice->id);
+// device = XOpenDevice(display, currDevice->id);
+// if (device == NULL) {
+// printf("EE : can't open device \"%d\"\n", (int)currDevice->id);
+// return NULL;
+// // throw XScreenUnavailable(60.0);
+// }
+// break;
+// case IsXKeyboard:
+// printf("xkeyboard id=%d\n",(int)currDevice->id);
+// break;
+// case IsXExtensionDevice:
+// printf("xextensiondevice id=%d\n",(int)currDevice->id);
+// break;
+// case IsXExtensionKeyboard:
+// printf("XExtensionKeyboard id=%d\n",(int)currDevice->id);
+// break;
+// case IsXExtensionPointer:
+// printf("XExtensionPointer id=%d\n",(int)currDevice->id);
+// break;
+// }
+// }
+
return display;
}
@@ -287,82 +334,86 @@ void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *argv[])
// --------------------------------------------------------------------------
void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
-// char *id = argv[0];
- float x = atof(argv[1]);
- float y = atof(argv[2]);
- int time = atoi(argv[11]);
- int presure = atoi(argv[3]);
- static float old_x = 0;
- static float old_y = 0;
- static int old_time = 0;
- static int should_click = 0;
- static int clicked = 0;
- if (dragged && presure==0){
- fakeMouseButton(1,0);
- dragged = 0;
- }
- if (!relative) {
- if (!dragged && presure>0){
- fakeMouseButton(1,1);
- dragged = 1;
- }
- }
-// printf("x = %f,y = %f; ",x,y);
- if (valid(x,y)){
- x = offsetx + (x-coords_input[0])*width/width_input;
- y = offsety + (y-coords_input[1])*height/height_input;
-// printf("x = %f,y = %f\n",x,y);
- if (!relative) {
- fakeMouseMove((int)x,(int)y);
- } else {
- int dx = (int)(x-old_x);
- int dy = (int)(y-old_y);
- int dt = time-old_time;
+ // char *id = argv[0];
+ float x = atof(argv[champX]); // predicted position
+ float y = atof(argv[champY]); // predicted position
+ int time = atoi(argv[11]);
+ int presure = atoi(argv[3]);
+ static float old_x = 0;
+ static float old_y = 0;
+ static int old_time = 0;
+ static int should_click = 0;
+ static int clicked = 0;
+ if (!valid(x,y)){
+ // ignore outside events
+ return;
+ }
+ // printf("x = %f,y = %f; ",x,y);
+ x = offsetx + (x-coords_input[0])*width/width_input;
+ y = offsety + (y-coords_input[1])*height/height_input;
+
+
+ if (!relative) {
+ //absolute mode
+ fakeMouseMove((int)x,(int)y);
+ if (!dragged && presure>0){
+ fakeMouseButton(1,1);
+ dragged = 1;
+ }
+ } else {
+ //relative mode
+ int dx = (int)(x-old_x);
+ int dy = (int)(y-old_y);
+ int dt = time-old_time;
// if (old_time)
// printf("time=%d, old_time=%d, dt=%d\n",time, old_time, dt);
- if (presure > 0) {
- if (!should_click){
- old_time = time;
- dt = 0;
- should_click = 1;
-// printf("armement du timeout\n");
+ if (presure > 0) {
+ if (!should_click){
+ old_time = time;
+ dt = 0;
+ should_click = 1;
+// printf("armement du timeout\n");
+ } else {
+ if (should_click ==1 && dt > TIME_CLICK){
+ should_click = 2;
+// printf("timeout\n");
+ }
+ }
+ fakeMouseRelativeMove(dx,dy);
} else {
- if (should_click ==1 && dt > TIME_CLICK){
- should_click = 2;
-// printf("timeout\n");
- }
- }
- fakeMouseRelativeMove(dx,dy);
- } else {
- if (should_click == 1) {
-// printf("dt = %d\n",dt);
- if (clicked) {
- //double click
-// printf("ck\n");
- fakeMouseButton(1,0);
- }
-// printf("cli\n");
- clicked = 1;
- old_time = time;
- fakeMouseButton(1,1);
- }
- should_click = 0;
- if (clicked) {
- if (dt > TIME_BETWEEN_CLICK){
-// printf("ck\n");
- fakeMouseButton(1,0);
- clicked = 0;
+ if (should_click == 1) {
+// printf("dt = %d\n",dt);
+ if (clicked) {
+ //double click
+// printf("ck\n");
+ fakeMouseButton(1,0);
+ }
+// printf("cli\n");
+ clicked = 1;
+ old_time = time;
+ fakeMouseButton(1,1);
+ }
+ should_click = 0;
+ if (clicked) {
+ if (dt > TIME_BETWEEN_CLICK){
+// printf("ck\n");
+ fakeMouseButton(1,0);
+ clicked = 0;
+ }
+ } else {
+ old_time = 0;
}
- } else {
- old_time = 0;
}
- }
}
- old_x = x;
- old_y = y;
-// } else {
-// printf("bad event\n");
- }
+
+ // release (common of both modes)
+ if (dragged && presure==0){
+ fakeMouseButton(1,0);
+ dragged = 0;
+ }
+
+ old_x = x;
+ old_y = y;
}
void CallbackPad (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
@@ -400,6 +451,7 @@ void printHelpMsg(const char *name){
"\t-c x0,y0,x1,y1\tspecify the coords of the input used (only used with wacom)\n"
"\t-C x0,y0,x1,y1\tspecify the coords of the screen used\n"
"\t-r\tuse relative mode by default\n"
+ "\t-p\tuse predictive mode\n"
"\t-v\t\tprints the ivy relase number\n\n"
;
printf("usage: %s %s",name,helpmsg);
@@ -451,7 +503,7 @@ int main(int argc, char *argv[]) {
int coordsI[4] = {0,0,0,0};
int coordsO[4] = {0,0,0,0};
int c;
- while ((c = getopt(argc, argv, "vb:wc:C:r")) != EOF)
+ while ((c = getopt(argc, argv, "vb:wc:C:rp")) != EOF)
switch (c) {
case 'b':
strcpy (busbuf, optarg);
@@ -466,6 +518,10 @@ int main(int argc, char *argv[]) {
case 'w':
wacom = 1;
break;
+ case 'p':
+ champX = 7;
+ champY = 8;
+ break;
case 'c':
user_coordsI = extractValues(optarg, coordsI, argv[0]);
break;
@@ -511,7 +567,9 @@ int main(int argc, char *argv[]) {
printf("screen : %d+%d x %d+%d\n",offsetx,width,offsety,height);
// verifications
- if (width < 2 || height < 2 || width_input < 2 || height_input < 2){
+ if (width < 2 || height < 2 || (wacom && (width_input < 2 || height_input < 2))){
+ print_coords_input();
+ printf("%d %d %d %d\n",width,height,width_input,height_input);
printHelpMsg(argv[0]);
exit(1);
}