diff options
author | tissoire | 2007-12-20 16:52:19 +0000 |
---|---|---|
committer | tissoire | 2007-12-20 16:52:19 +0000 |
commit | 13059090d2cc7ebf6a68695e3401a643d0eb63bb (patch) | |
tree | e92bc74ea9674e541812cac8536ecda09c7bb5b5 /src/ivypointer.c | |
parent | 98f62bc78586332320db02686c2453d3dd3a6f31 (diff) | |
download | ivypointer-13059090d2cc7ebf6a68695e3401a643d0eb63bb.zip ivypointer-13059090d2cc7ebf6a68695e3401a643d0eb63bb.tar.gz ivypointer-13059090d2cc7ebf6a68695e3401a643d0eb63bb.tar.bz2 ivypointer-13059090d2cc7ebf6a68695e3401a643d0eb63bb.tar.xz |
ajout du support de xinput_ivy
Diffstat (limited to 'src/ivypointer.c')
-rw-r--r-- | src/ivypointer.c | 165 |
1 files changed, 148 insertions, 17 deletions
diff --git a/src/ivypointer.c b/src/ivypointer.c index fe6e5a8..b6fbbd7 100644 --- a/src/ivypointer.c +++ b/src/ivypointer.c @@ -1,5 +1,5 @@ /* - * Ivy probe + * Ivypointer * * Copyright (C) 2007 * DGAC / DSNA / DTI / R&D @@ -54,13 +54,20 @@ #define REGEXP_MOVE "^TelepointerMotion Id=(.*) X=(.*) Y=(.*)" #define REGEXP_DRAG "^TelepointerDrag Id=(.*) X=(.*) Y=(.*)" -//#define REGEXP_MOVE "^IvyPointer Move=(.*),(.*)" #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=(.*)" +#define REGEXP_PAD "^pad_event device_id=(.*) button=(.*) status=(.*) time=(.*)" +#define REGEXP_SLIDER "^slider_event device_id=(.*) value=(.*) side=(.*) time=(.*)" + +#define WIDTH_WACOM 1600.0 +#define HEIGHT_WACOM 1200.0 Display* display = NULL; int width,height; +float coords_input[4] = {0.0,0.0,100.0,100.0}; +int width_input,height_input; int dragged = 0; @@ -116,6 +123,10 @@ openDisplay(const char* displayName) return display; } +// -------------------------------------------------------------------------- +// X11 functions +// -------------------------------------------------------------------------- + void fakeMouseButton(const unsigned int xButton, Bool press) { @@ -142,6 +153,10 @@ fakeMouseRelativeMove(int dx, int dy) } +// -------------------------------------------------------------------------- +// Telepointer callbacks +// -------------------------------------------------------------------------- + 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++) @@ -150,7 +165,7 @@ void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { fakeMouseButton(1,0); dragged = 0; } - char *id = argv[0]; +// char *id = argv[0]; float x = atof(argv[1]); float y = atof(argv[2]); // printf("x = %f,y = %f; ",x,y); @@ -161,12 +176,13 @@ void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { // IvyUnbindMsg(*ptr); } + void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *argv[]) { if (!dragged){ fakeMouseButton(1,1); dragged = 1; } - char *id = argv[0]; +// char *id = argv[0]; float x = atof(argv[1]); float y = atof(argv[2]); x *= width/100.0; @@ -176,7 +192,7 @@ 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]; +// char *id = argv[0]; float x = atof(argv[1]); float y = atof(argv[2]); x *= width/100.0; @@ -185,7 +201,7 @@ 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]; +// char *id = argv[0]; int b = atoi(argv[1]); int press = atoi(argv[2]); // if (!b) @@ -193,15 +209,71 @@ void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *argv[]) fakeMouseButton(b,press); } +// -------------------------------------------------------------------------- +// Wacom callbacks +// -------------------------------------------------------------------------- + +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 presure = atoi(argv[3]); + if (dragged && presure==0){ + fakeMouseButton(1,0); + dragged = 0; + } + if (!dragged && presure>0){ + fakeMouseButton(1,1); + 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); +} + +void CallbackPad (IvyClientPtr app, void *user_data, int argc, char *argv[]) { +// char *id = argv[0]; + int b = atoi(argv[1]); + int press = atoi(argv[2]); +// if (!b) +// return + fakeMouseButton(b,press); +} + +void CallbackSlider (IvyClientPtr app, void *user_data, int argc, char *argv[]) { + //TODO +// char *id = argv[0]; +// int b = atoi(argv[1]); +// int press = atoi(argv[2]); +// if (!b) +// return +// fakeMouseButton(b,press); +} + +// -------------------------------------------------------------------------- +// Main +// -------------------------------------------------------------------------- + int main(int argc, char *argv[]) { const char* bus = 0; char busbuf [1024] = ""; const char* helpmsg = - "[options] [regexps]\n\t-b bus\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n" - "\t-v\tprints the ivy relase number\n\n" + "[options] [regexps]\n\t-b bus\t\tdefines the Ivy bus to which to connect to, defaults to 127:2010\n" + "\t-w\t\tuse data from xinput_wacom instead of ModeManager\n" + "\t-c x0,y0,x1,y1\tspecify the coords of the window used (only used with wacom)\n" + "\t-v\t\tprints the ivy relase number\n\n" ; + int wacom = 0; + int user_coords = 0; + int coords[4] = {0,0,0,0}; int c; - while ((c = getopt(argc, argv, "vb:")) != EOF) + int i = 0; + int j = 0; + int coupures[4] = {0,0,0,0}; + int last = 0; + while ((c = getopt(argc, argv, "vb:wc:")) != EOF) switch (c) { case 'b': strcpy (busbuf, optarg); @@ -210,6 +282,37 @@ int main(int argc, char *argv[]) { case 'v': printf("ivy c library version %d.%d\n",IVYMAJOR_VERSION,IVYMINOR_VERSION); break; + case 'w': + wacom = 1; + break; + case 'c': + while(optarg[i]){ + if (optarg[i] == ','){ + coupures[j] = i; + j++; + } + i++; + } + if (j != 3) { + printf("usage: %s %s",argv[0],helpmsg); + exit(1); + } else { + coupures[j] = i; + } + j = 0; + last = 0; + for (i=0; i< 4; i++){ + int length = coupures[i]-last; + char buf [1024] = ""; + int k; + for (k = 0; k < length; k++) { + buf[k] = optarg[last+k]; + } + coords[i] = atoi(buf); + last = coupures[i]+1; + } + user_coords = 1; + break; default: printf("usage: %s %s",argv[0],helpmsg); exit(1); @@ -219,19 +322,47 @@ int main(int argc, char *argv[]) { return 1; } + if (wacom) { + if (user_coords){ + int i; + for (i=0;i<4;i++) { + coords_input[i] = coords[i]; + } + } else { + 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]); + width_input = coords_input[2]-coords_input[0]; + height_input = coords_input[3]-coords_input[1]; + } + width = DisplayWidth(d, DefaultScreen(d)); height = DisplayHeight(d, DefaultScreen(d)); printf("screen : %dx%d\n",width,height); + MsgRcvPtr ptrMove,ptrRelMove,ptrButton; IvyInit("IvyPointer","IvyPointer Ready",NULL,NULL,NULL,NULL); - 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); + + 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); + } else { + //wacom callbacks + ptrMove=IvyBindMsg(CallbackPointer,&ptrMove,REGEXP_POINTER); + printf("bound to %s\n",REGEXP_POINTER); +// 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); + } IvyStart(bus); #if (IVYMAJOR_VERSION == 3) && (IVYMINOR_VERSION < 9) IvyMainLoop(NULL, NULL); |