diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ivypointer.c | 138 |
1 files changed, 83 insertions, 55 deletions
diff --git a/src/ivypointer.c b/src/ivypointer.c index 6f72a60..e536888 100644 --- a/src/ivypointer.c +++ b/src/ivypointer.c @@ -62,18 +62,18 @@ #include "getopt.h" -#define REGEXP_CHANGE_GEOMETRY_INPUT "^geometry_event device_id=(.*) x0=(.*) y0=(.*) x1=(.*) y1=(.*)" -#define REGEXP_CHANGE_GEOMETRY_SCREEN "^screen_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=(.*)" -#define REGEXP_BUTTON "^TelepointerButton Id=(.*) Button=(.*) status=(.*)" - -#define REGEXP_POINTER "^pointer_event device_id=(.*) x=(.*) y=(.*) presure=(.*) tilt_x=(.*) tilt_y=(.*) wheel=(.*) predicted_x=(.*) predicted_y=(.*) type=(.*) serial_number=(.*) time=(.*) hires_x=(.*) hires_y=(.*) proximity=(.*)" -#define REGEXP_PAD "^pad_event device_id=(.*) button=(.*) status=(.*) time=(.*)" -#define REGEXP_SLIDER "^slider_event device_id=(.*) value=(.*) side=(.*) time=(.*)" -#define REGEXP_BUTTON_WACOM "^button_event device_id=(.*) button=(.*) status=(.*) x=(.*) y=(.*) presure=(.*) tilt_x=(.*) tilt_y=(.*) wheel=(.*) predicted_x=(.*) predicted_y=(.*) type=(.*) serial_number=(.*) time=(.*) hires_x=(.*) hires_y=(.*) proximity=(.*)" +#define REGEXP_CHANGE_GEOMETRY_INPUT "^geometry_event device_id=%s x0=(.*) y0=(.*) x1=(.*) y1=(.*)" +#define REGEXP_CHANGE_GEOMETRY_SCREEN "^screen_geometry_event device_id=%s x0=(.*) y0=(.*) x1=(.*) y1=(.*)" + +#define REGEXP_MOVE "^TelepointerMotion Id=%s X=(.*) Y=(.*)" +#define REGEXP_DRAG "^TelepointerDrag Id=%s X=(.*) Y=(.*)" +#define REGEXP_REL_MOVE "^TelepointerRelativeMotion Id=%s X=(.*) Y=(.*)" +#define REGEXP_BUTTON "^TelepointerButton Id=%s Button=(.*) status=(.*)" + +#define REGEXP_POINTER "^pointer_event device_id=%s x=(.*) y=(.*) presure=(.*) tilt_x=(.*) tilt_y=(.*) wheel=(.*) predicted_x=(.*) predicted_y=(.*) type=(.*) serial_number=(.*) time=(.*) hires_x=(.*) hires_y=(.*) proximity=(.*)" +#define REGEXP_PAD "^pad_event device_id=%s button=(.*) status=(.*) time=(.*)" +#define REGEXP_SLIDER "^slider_event device_id=%s value=(.*) side=(.*) time=(.*)" +#define REGEXP_BUTTON_WACOM "^button_event device_id=%s button=(.*) status=(.*) x=(.*) y=(.*) presure=(.*) tilt_x=(.*) tilt_y=(.*) wheel=(.*) predicted_x=(.*) predicted_y=(.*) type=(.*) serial_number=(.*) time=(.*) hires_x=(.*) hires_y=(.*) proximity=(.*)" #define WIDTH_WACOM 1600.0 @@ -101,6 +101,8 @@ int relative = 0; int champX = 12; int champY = 13; +int device_input_id_given = 0; + Display* openDisplay(const char* displayName) { @@ -234,10 +236,10 @@ fakeMouseRelativeMove(int dx, int dy) // -------------------------------------------------------------------------- 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]); + float x0 = atof(argv[1-device_input_id_given]); + float y0 = atof(argv[2-device_input_id_given]); + float x1 = atof(argv[3-device_input_id_given]); + float y1 = atof(argv[4-device_input_id_given]); if (x1 > x0 && y1 > y0 ){ coords_input[0] = x0; coords_input[1] = y0; @@ -253,10 +255,10 @@ void CallbackGeometry(IvyClientPtr app, void *user_data, int argc, char *argv[]) void CallbackScreen(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]); + float x0 = atof(argv[1-device_input_id_given]); + float y0 = atof(argv[2-device_input_id_given]); + float x1 = atof(argv[3-device_input_id_given]); + float y1 = atof(argv[4-device_input_id_given]); if (x1 > x0 && y1 > y0 ){ offsetx = x0; offsety = y0; @@ -276,8 +278,8 @@ void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // printf ("%s sent (size : %d)",IvyGetApplicationName(app),argc); // for (i = 0; i < argc; i++) // printf(" '%s'",argv[i]); - float x = atof(argv[1]); - float y = atof(argv[2]); + float x = atof(argv[1-device_input_id_given]); + float y = atof(argv[2-device_input_id_given]); x = x*width/100.0; y = y*height/100.0; // char *id = argv[0]; @@ -295,8 +297,8 @@ void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // char *id = argv[0]; - float x = atof(argv[1]); - float y = atof(argv[2]); + float x = atof(argv[1-device_input_id_given]); + float y = atof(argv[2-device_input_id_given]); x *= width/100.0; y *= height/100.0; // printf("x = %f,y = %f\n",x,y); @@ -311,8 +313,8 @@ void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *argv[]) { void CallbackRelMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // char *id = argv[0]; - float x = atof(argv[1]); - float y = atof(argv[2]); + float x = atof(argv[1-device_input_id_given]); + float y = atof(argv[2-device_input_id_given]); x *= width/100.0; y *= height/100.0; fakeMouseRelativeMove((int)x,(int)y); @@ -320,8 +322,8 @@ void CallbackRelMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // char *id = argv[0]; - int b = atoi(argv[1]); - int press = atoi(argv[2]); + int b = atoi(argv[1-device_input_id_given]); + int press = atoi(argv[2-device_input_id_given]); // if (!b) // return fakeMouseButton(b,press,0,0); @@ -335,8 +337,8 @@ void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[]) // 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]); + int time = atoi(argv[11-device_input_id_given]); + int presure = atoi(argv[3-device_input_id_given]); static float old_x = 0; static float old_y = 0; static int old_time = 0; @@ -416,11 +418,11 @@ void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[]) void CallbackPad (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // char *id = argv[0]; - int b = atoi(argv[1]); + int b = atoi(argv[1-device_input_id_given]); int press = 0; // if (!b) // return - if (strcmp(argv[2],"up")){ + if (strcmp(argv[2-device_input_id_given],"up")){ press = 1; } // printf("Pad button=%d pressed%d event received\n",b, press); @@ -444,10 +446,10 @@ void CallbackSlider (IvyClientPtr app, void *user_data, int argc, char *argv[]) void CallbackButtonWacom (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // char *id = argv[0]; - int b = atoi(argv[1]); + int b = atoi(argv[1-device_input_id_given]); if (b == 1) // gestion propre du bouton 1 return; - int press = strcmp(argv[2],"up"); + int press = strcmp(argv[2-device_input_id_given],"up"); fakeMouseButton(b,press,0,0); } @@ -458,6 +460,7 @@ void printHelpMsg(const char *name){ "\t-t\t\tuse data from ModeManager instead of xinput_wacom\n" "\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-d device\tuse \"device\" as the source of the events\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" @@ -505,6 +508,7 @@ int extractValues(char optarg[], float* output, const char name[]){ int main(int argc, char *argv[]) { const char* bus = 0; char busbuf [1024] = ""; + char device_input_id [1024] = "(.*)"; int wacom = 1; int predictive_mode = 0; float user_coordsI = 0; @@ -513,7 +517,7 @@ int main(int argc, char *argv[]) { float coordsO[4] = {0,0,0,0}; int c; int id = -1; - while ((c = getopt(argc, argv, "vb:twc:C:rpd:")) != EOF) + while ((c = getopt(argc, argv, "vb:td:c:C:rpi:")) != EOF) switch (c) { case 'b': strcpy (busbuf, optarg); @@ -525,7 +529,9 @@ int main(int argc, char *argv[]) { case 'r': relative = 1; break; - case 'w': + case 'd': + strcpy (device_input_id, optarg); + device_input_id_given = 1; break; case 't': wacom = 0; @@ -541,7 +547,7 @@ int main(int argc, char *argv[]) { case 'C': user_coordsO = extractValues(optarg, coordsO, argv[0]); break; - case 'd': + case 'i': id = atoi(optarg); break; default: @@ -581,6 +587,8 @@ int main(int argc, char *argv[]) { print_coords_input(); width_input = coords_input[2]-coords_input[0]; height_input = coords_input[3]-coords_input[1]; + champX -= device_input_id_given; + champY -= device_input_id_given; } if (user_coordsO){ @@ -608,31 +616,51 @@ int main(int argc, char *argv[]) { MsgRcvPtr ptrMove,ptrRelMove,ptrButton; IvyInit("IvyPointer","IvyPointer Ready",NULL,NULL,NULL,NULL); + char regexp[2048] = ""; if (!wacom) { // telepointer callbacks - ptrMove=IvyBindMsg(CallbackMove,&ptrMove,REGEXP_MOVE); - printf("bound to %s\n",REGEXP_MOVE); - ptrMove=IvyBindMsg(CallbackDrag,&ptrMove,REGEXP_DRAG); - printf("bound to %s\n",REGEXP_DRAG); - ptrMove=IvyBindMsg(CallbackRelMove,&ptrRelMove,REGEXP_REL_MOVE); - printf("bound to %s\n",REGEXP_REL_MOVE); - ptrMove=IvyBindMsg(CallbackButton,&ptrButton,REGEXP_BUTTON); - printf("bound to %s\n",REGEXP_BUTTON); + + sprintf(regexp, REGEXP_MOVE, device_input_id); + ptrMove=IvyBindMsg(CallbackMove,&ptrMove,REGEXP_MOVE, device_input_id); + printf("bound to %s\n",regexp); + + sprintf(regexp, REGEXP_DRAG, device_input_id); + ptrMove=IvyBindMsg(CallbackDrag,&ptrMove, REGEXP_DRAG, device_input_id); + printf("bound to %s\n",regexp); + + sprintf(regexp, REGEXP_REL_MOVE, device_input_id); + ptrMove=IvyBindMsg(CallbackRelMove,&ptrRelMove, REGEXP_REL_MOVE, device_input_id); + printf("bound to %s\n",regexp); + + sprintf(regexp, REGEXP_BUTTON, device_input_id); + ptrMove=IvyBindMsg(CallbackButton,&ptrButton, REGEXP_BUTTON, device_input_id); + printf("bound to %s\n",regexp); } 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); + sprintf(regexp, REGEXP_CHANGE_GEOMETRY_INPUT, device_input_id); + ptrMove=IvyBindMsg(CallbackGeometry,&ptrMove,REGEXP_CHANGE_GEOMETRY_INPUT, device_input_id); + printf("bound to %s\n",regexp); + + sprintf(regexp, REGEXP_POINTER, device_input_id); + ptrMove=IvyBindMsg(CallbackPointer,&ptrMove, REGEXP_POINTER, device_input_id); + printf("bound to %s\n",regexp); + // ptrMove=IvyBindMsg(CallbackSlider,&ptrMove,REGEXP_SLIDER); // printf("bound to %s\n",REGEXP_SLIDER); - ptrMove=IvyBindMsg(CallbackPad,&ptrButton,REGEXP_PAD); - printf("bound to %s\n",REGEXP_PAD); - ptrMove=IvyBindMsg(CallbackButtonWacom,&ptrButton,REGEXP_BUTTON_WACOM); - printf("bound to %s\n",REGEXP_BUTTON_WACOM); + + sprintf(regexp, REGEXP_PAD, device_input_id); + ptrMove=IvyBindMsg(CallbackPad,&ptrButton, REGEXP_PAD, device_input_id); + printf("bound to %s\n",regexp); + + sprintf(regexp, REGEXP_BUTTON_WACOM, device_input_id); + ptrMove=IvyBindMsg(CallbackButtonWacom,&ptrButton, REGEXP_BUTTON_WACOM, device_input_id); + printf("bound to %s\n",regexp); } - ptrMove=IvyBindMsg(CallbackScreen,&ptrMove,REGEXP_CHANGE_GEOMETRY_SCREEN); - printf("bound to %s\n",REGEXP_CHANGE_GEOMETRY_SCREEN); + + sprintf(regexp, REGEXP_CHANGE_GEOMETRY_SCREEN, device_input_id); + ptrMove=IvyBindMsg(CallbackScreen,&ptrMove, REGEXP_CHANGE_GEOMETRY_SCREEN, device_input_id); + printf("bound to %s\n",regexp); + IvyStart(bus); #if (IVYMAJOR_VERSION == 3) && (IVYMINOR_VERSION < 9) IvyMainLoop(NULL, NULL); |