aboutsummaryrefslogtreecommitdiff
path: root/src/ivypointer.c
diff options
context:
space:
mode:
authortissoire2007-12-20 17:39:01 +0000
committertissoire2007-12-20 17:39:01 +0000
commit7f03541f4c60c9ff3296ea0247778c7007c601b7 (patch)
tree6d42115b57207bab77bbfa19ced4634c9bbc0f20 /src/ivypointer.c
parent13059090d2cc7ebf6a68695e3401a643d0eb63bb (diff)
downloadivypointer-7f03541f4c60c9ff3296ea0247778c7007c601b7.zip
ivypointer-7f03541f4c60c9ff3296ea0247778c7007c601b7.tar.gz
ivypointer-7f03541f4c60c9ff3296ea0247778c7007c601b7.tar.bz2
ivypointer-7f03541f4c60c9ff3296ea0247778c7007c601b7.tar.xz
added the possibility to change the geometry of the input in live
Diffstat (limited to 'src/ivypointer.c')
-rw-r--r--src/ivypointer.c71
1 files changed, 64 insertions, 7 deletions
diff --git a/src/ivypointer.c b/src/ivypointer.c
index b6fbbd7..fc32379 100644
--- a/src/ivypointer.c
+++ b/src/ivypointer.c
@@ -52,6 +52,8 @@
#include "getopt.h"
+#define REGEXP_CHANGE_GEOMETRY_INPUT "^geometry_event device_id=(.*) x0=(.*) y0=(.*) x1=(.*) y1=(.*)"
+
#define REGEXP_MOVE "^TelepointerMotion Id=(.*) X=(.*) Y=(.*)"
#define REGEXP_DRAG "^TelepointerDrag Id=(.*) X=(.*) Y=(.*)"
#define REGEXP_REL_MOVE "^TelepointerRelativeMotion Id=(.*) X=(.*) Y=(.*)"
@@ -124,6 +126,34 @@ openDisplay(const char* displayName)
}
// --------------------------------------------------------------------------
+// tools
+// --------------------------------------------------------------------------
+
+void print_coords_input(void){
+ printf("coords of input : %.0f,%.0f %.0f,%.0f\n", coords_input[0], coords_input[1], coords_input[2], coords_input[3]);
+}
+
+int valid(float x, float y) {
+ if (x<coords_input[0]) {
+// printf("x < x0\n");
+ return 0;
+ }
+ if (x>coords_input[2]) {
+// printf("x > x1\n");
+ return 0;
+ }
+ if (y<coords_input[1]){
+// printf("y < y0\n");
+ return 0;
+ }
+ if (y>coords_input[3]){
+// printf("y < y1\n");
+ return 0;
+ }
+ return 1;
+}
+
+// --------------------------------------------------------------------------
// X11 functions
// --------------------------------------------------------------------------
@@ -152,6 +182,25 @@ fakeMouseRelativeMove(int dx, int dy)
XFlush(display);
}
+// --------------------------------------------------------------------------
+// Geometry callback
+// --------------------------------------------------------------------------
+void CallbackGeometry(IvyClientPtr app, void *user_data, int argc, char *argv[]) {
+// char *id = argv[0];
+ float x0 = atof(argv[1]);
+ float y0 = atof(argv[2]);
+ float x1 = atof(argv[3]);
+ float y1 = atof(argv[4]);
+ if (x1 > x0 && y1 > y0 ){
+ coords_input[0] = x0;
+ coords_input[1] = y0;
+ coords_input[2] = x1;
+ coords_input[3] = y1;
+ print_coords_input();
+ } else {
+ printf("bad coords received : %.0f,%.0f %.0f,%.0f\n",x0,y0,x1,y1);
+ }
+}
// --------------------------------------------------------------------------
// Telepointer callbacks
@@ -172,7 +221,8 @@ void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
x = x*width/100.0;
y = y*height/100.0;
// printf("x = %f,y = %f\n",x,y);
- fakeMouseMove((int)x,(int)y);
+ if (valid(x,y))
+ fakeMouseMove((int)x,(int)y);
// IvyUnbindMsg(*ptr);
}
@@ -188,7 +238,8 @@ void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
x *= width/100.0;
y *= height/100.0;
// printf("x = %f,y = %f\n",x,y);
- fakeMouseMove((int)x,(int)y);
+ if (valid(x,y))
+ fakeMouseMove((int)x,(int)y);
}
void CallbackRelMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
@@ -227,10 +278,14 @@ void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[])
dragged = 1;
}
// printf("x = %f,y = %f; ",x,y);
- x = (x-coords_input[0])*width/width_input;
- y = (y-coords_input[1])*height/height_input;
-// printf("x = %f,y = %f\n",x,y);
- fakeMouseMove((int)x,(int)y);
+ if (valid(x,y)){
+ x = (x-coords_input[0])*width/width_input;
+ y = (y-coords_input[1])*height/height_input;
+// printf("x = %f,y = %f\n",x,y);
+ fakeMouseMove((int)x,(int)y);
+// } else {
+// printf("bad event\n");
+ }
}
void CallbackPad (IvyClientPtr app, void *user_data, int argc, char *argv[]) {
@@ -332,7 +387,7 @@ int main(int argc, char *argv[]) {
coords_input[2] = WIDTH_WACOM;
coords_input[3] = HEIGHT_WACOM;
}
- printf("coords of input : %.0f,%.0f %.0f,%.0f\n", coords_input[0], coords_input[1], coords_input[2], coords_input[3]);
+ print_coords_input();
width_input = coords_input[2]-coords_input[0];
height_input = coords_input[3]-coords_input[1];
}
@@ -356,6 +411,8 @@ int main(int argc, char *argv[]) {
printf("bound to %s\n",REGEXP_BUTTON);
} else {
//wacom callbacks
+ ptrMove=IvyBindMsg(CallbackGeometry,&ptrMove,REGEXP_CHANGE_GEOMETRY_INPUT);
+ printf("bound to %s\n",REGEXP_CHANGE_GEOMETRY_INPUT);
ptrMove=IvyBindMsg(CallbackPointer,&ptrMove,REGEXP_POINTER);
printf("bound to %s\n",REGEXP_POINTER);
// ptrMove=IvyBindMsg(CallbackSlider,&ptrMove,REGEXP_SLIDER);