From 54131b174b5d490024e39b464b0e0769d322ce7f Mon Sep 17 00:00:00 2001 From: tissoire Date: Tue, 15 May 2012 08:50:50 +0000 Subject: change 4 spaces to tabs and remove empty lines full of blanks --- src/ivypointer.c | 368 +++++++++++++++++++++++++++---------------------------- 1 file changed, 184 insertions(+), 184 deletions(-) diff --git a/src/ivypointer.c b/src/ivypointer.c index 0eb55c8..ec5919b 100644 --- a/src/ivypointer.c +++ b/src/ivypointer.c @@ -141,18 +141,18 @@ openDisplay(const char* displayName) printf("XOpenDisplay(\"%s\")\n", displayName); display = XOpenDisplay(displayName); if (display == NULL) { - printf("EE : can't open display \"%s\"\n", displayName); - return NULL; + printf("EE : can't open display \"%s\"\n", displayName); + return NULL; // throw XScreenUnavailable(60.0); } // verify the availability of the XTest extension - int majorOpcode, firstEvent, firstError; + int majorOpcode, firstEvent, firstError; if (!XQueryExtension(display, XTestExtensionName, &majorOpcode, &firstEvent, &firstError)) { printf("XTEST extension not available"); XCloseDisplay(display); - return NULL; + return NULL; } XTestGrabControl(display, True); #if HAVE_XKB_EXTENSION @@ -214,10 +214,10 @@ fakeMouseMove(int x, int y) { // printf("x = %d,y = %d;\n ",x,y); #ifndef _MPX_ - XTestFakeMotionEvent(display, DefaultScreen(display), x, y, CurrentTime); + XTestFakeMotionEvent(display, DefaultScreen(display), x, y, CurrentTime); #else - int axes[2] = {x,y}; - XTestFakeDeviceMotionEvent(display, dev, False, 0, axes, 2, CurrentTime); + int axes[2] = {x,y}; + XTestFakeDeviceMotionEvent(display, dev, False, 0, axes, 2, CurrentTime); #endif //XWarpPointer(display, None, RootWindow(display, 0), 0, 0, 0, 0, x, y); XFlush(display); @@ -227,10 +227,10 @@ static void fakeMouseRelativeMove(int dx, int dy) { #ifndef _MPX_ - XTestFakeRelativeMotionEvent(display, dx, dy, CurrentTime); + XTestFakeRelativeMotionEvent(display, dx, dy, CurrentTime); #else - int axes[2] = {dx,dy}; - XTestFakeDeviceMotionEvent(display, dev, True, 0, axes, 2, CurrentTime); + int axes[2] = {dx,dy}; + XTestFakeDeviceMotionEvent(display, dev, True, 0, axes, 2, CurrentTime); #endif //XWarpPointer(display, None, None, 0, 0, 0, 0, dx, dy); XFlush(display); @@ -241,22 +241,22 @@ fakeMouseRelativeMove(int dx, int dy) // -------------------------------------------------------------------------- static void CallbackScreen(IvyClientPtr app, void *user_data, int argc, char *argv[]) { -// char *id = argv[0]; - 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; - width = x1-x0; - height = y1-y0; +// char *id = argv[0]; + 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; + width = x1-x0; + height = y1-y0; horiz_ratio = width / width_input; vert_ratio = height / height_input; - printf("screen : %f+%f x %f+%f\n",offsetx,width,offsety,height); - } else { - printf("bad coords received : %.2f,%.2f %.2f,%.2f\n",x0,y0,x1,y1); - } + printf("screen : %f+%f x %f+%f\n",offsetx,width,offsety,height); + } else { + printf("bad coords received : %.2f,%.2f %.2f,%.2f\n",x0,y0,x1,y1); + } } // -------------------------------------------------------------------------- @@ -264,7 +264,7 @@ static void CallbackScreen(IvyClientPtr app, void *user_data, int argc, char *ar // -------------------------------------------------------------------------- static void CallbackLockUnlock(IvyClientPtr app, void *user_data, int argc, char *argv[]) { - locked = strcmp(argv[1-device_input_id_given],"unlock"); + locked = strcmp(argv[1-device_input_id_given],"unlock"); } // -------------------------------------------------------------------------- @@ -272,18 +272,18 @@ static void CallbackLockUnlock(IvyClientPtr app, void *user_data, int argc, char // -------------------------------------------------------------------------- static 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 sent (size : %d)",IvyGetApplicationName(app),argc); +// for (i = 0; i < argc; i++) // printf(" '%s'",argv[i]); - float x = atof(argv[champX]); - float y = atof(argv[champY]); - if (!valid(x,y)){ + float x = atof(argv[champX]); + float y = atof(argv[champY]); + if (!valid(x,y)){ // ignore outside events return; } - x = offsetx + x * horiz_ratio; - y = offsety + y * vert_ratio; -// printf("x = %f,y = %f\n",x,y); + x = offsetx + x * horiz_ratio; + y = offsety + y * vert_ratio; +// printf("x = %f,y = %f\n",x,y); old_x = x; old_y = y; fakeMouseMove((int)x,(int)y); @@ -295,16 +295,16 @@ static void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *arg static void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *argv[]) { -// char *id = argv[0]; - float x = atof(argv[champX]); - float y = atof(argv[champY]); +// char *id = argv[0]; + float x = atof(argv[champX]); + float y = atof(argv[champY]); if (!valid(x,y)){ // ignore outside events return; } - x = offsetx + x * horiz_ratio; - y = offsety + y * vert_ratio; -// printf("x = %f,y = %f\n",x,y); + x = offsetx + x * horiz_ratio; + y = offsety + y * vert_ratio; +// printf("x = %f,y = %f\n",x,y); old_x = x; old_y = y; fakeMouseMove((int)x,(int)y); @@ -315,21 +315,21 @@ static void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *arg } static void CallbackRelMove (IvyClientPtr app, void *user_data, int argc, char *argv[]) { -// char *id = argv[0]; - float dx = atof(argv[1-device_input_id_given]); - float dy = atof(argv[2-device_input_id_given]); - fakeMouseRelativeMove((int)dx,(int)dy); +// char *id = argv[0]; + float dx = atof(argv[1-device_input_id_given]); + float dy = atof(argv[2-device_input_id_given]); + fakeMouseRelativeMove((int)dx,(int)dy); } static void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *argv[]) { -// char *id = argv[0]; - int b = atoi(argv[1-device_input_id_given]); - int press = atoi(argv[2-device_input_id_given]); +// char *id = argv[0]; + int b = atoi(argv[1-device_input_id_given]); + int press = atoi(argv[2-device_input_id_given]); if (!valid(old_x,old_y)){ // ignore outside events return; } - fakeMouseButton(b,press,0,0); + fakeMouseButton(b,press,0,0); } // -------------------------------------------------------------------------- @@ -337,7 +337,7 @@ static void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *a // -------------------------------------------------------------------------- static void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[]) { - // char *id = argv[0]; + // char *id = argv[0]; float x = atof(argv[champX]); // predicted position float y = atof(argv[champY]); // predicted position int time = atoi(argv[11-device_input_id_given]); @@ -355,7 +355,7 @@ static void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char * x = offsetx + x * horiz_ratio; y = offsety + y * vert_ratio; } - + if (!relative) { //absolute mode fakeMouseMove((int)x,(int)y); @@ -364,14 +364,14 @@ static void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char * 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 (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"); +// printf("armement du timeout\n"); } else { if (should_click ==1 && dt > TIME_CLICK){ should_click = 2; @@ -420,46 +420,46 @@ static void CallbackPad (IvyClientPtr app, void *user_data, int argc, char *argv // ignore outside events return; } - int b = atoi(argv[1-device_input_id_given]); - int press = 0; -// if (!b) -// return - if (strcmp(argv[2-device_input_id_given],"up")){ - press = 1; - } -// printf("Pad button=%d pressed%d event received\n",b, press); - if (switch_mode && (b==11 || b==15 || (press && (b==12 || b==16)))){ - //inversion du mode - relative = !relative; - } else { - fakeMouseButton(b,press,0,0); - } + int b = atoi(argv[1-device_input_id_given]); + int press = 0; +// if (!b) +// return + if (strcmp(argv[2-device_input_id_given],"up")){ + press = 1; + } +// printf("Pad button=%d pressed%d event received\n",b, press); + if (switch_mode && (b==11 || b==15 || (press && (b==12 || b==16)))){ + //inversion du mode + relative = !relative; + } else { + fakeMouseButton(b,press,0,0); + } } static 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); + //TODO +// char *id = argv[0]; +// int b = atoi(argv[1]); +// int press = atoi(argv[2]); +// if (!b) +// return +// fakeMouseButton(b,press); } static void CallbackButtonWacom (IvyClientPtr app, void *user_data, int argc, char *argv[]) { -// char *id = argv[0]; - int b = atoi(argv[1-device_input_id_given]); - if (b == 1 && relative) // gestion propre du bouton 1 - return; - int press = strcmp(argv[2-device_input_id_given],"up"); +// char *id = argv[0]; + int b = atoi(argv[1-device_input_id_given]); + if (b == 1 && relative) // gestion propre du bouton 1 + return; + int press = strcmp(argv[2-device_input_id_given],"up"); float x = atof(argv[champXButton]); float y = atof(argv[champYButton]); if (!valid(x,y)){ // ignore outside events return; } - - fakeMouseButton(b,press,0,0); + + fakeMouseButton(b,press,0,0); } static int extractValues(char optarg[], float* output, const char name[]){ @@ -482,16 +482,16 @@ static int extractValues(char optarg[], float* output, const char name[]){ 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]; - } - output[i] = atof(buf); - last = coupures[i]+1; - } + 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]; + } + output[i] = atof(buf); + last = coupures[i]+1; + } return 1; } @@ -505,7 +505,7 @@ static void printHelpMsg(const char *name){ "\t-s\tenable the ability to dynamically switch between relative and absolute\n" "\t-p\tuse predictive mode (disable geometry)\n" "\t-v\t\tprints the ivy relase number\n\n" - ; + ; printf("usage: %s %s",name,helpmsg); } @@ -516,11 +516,11 @@ static void printHelpMsg(const char *name){ int main(int argc, char *argv[]) { const char* bus = 0; char busbuf [1024] = ""; - char device_input_id [1024] = "(.*)"; - char ivyName [1024] = "IvyPointer"; - int wacom = 1; - float user_coordsO = 0; - float coordsO[4] = {0,0,0,0}; + char device_input_id [1024] = "(.*)"; + char ivyName [1024] = "IvyPointer"; + int wacom = 1; + float user_coordsO = 0; + float coordsO[4] = {0,0,0,0}; int c; int id = -1; while ((c = getopt(argc, argv, "vb:td:C:rpi:sc:")) != EOF) @@ -536,8 +536,8 @@ int main(int argc, char *argv[]) { relative = 1; break; case 'd': - strcpy (device_input_id, optarg); - device_input_id_given = 1; + strcpy (device_input_id, optarg); + device_input_id_given = 1; break; case 't': wacom = 0; @@ -562,42 +562,42 @@ int main(int argc, char *argv[]) { printHelpMsg(argv[0]); exit(1); } - Display* d = openDisplay(NULL); - if (!d){ - return 1; - } + Display* d = openDisplay(NULL); + if (!d){ + return 1; + } #ifdef _MPX_ - if (id >=0){ - printf("opening device id=%d\n",id); - dev = openDevice(d,id); + if (id >=0){ + printf("opening device id=%d\n",id); + dev = openDevice(d,id); if (!dev) { printf("unable to open device id=%d\n",id); } - } + } #endif - - if (!predictive_mode && user_coordsO){ - offsetx = coordsO[0]; - offsety = coordsO[1]; - width = coordsO[2]-coordsO[0]; - height = coordsO[3]-coordsO[1]; - } else { - offsetx = 0; - offsety = 0; - width = DisplayWidth(d, DefaultScreen(d)); - height = DisplayHeight(d, DefaultScreen(d)); - } - - printf("screen : %.2f+%.2f x %.2f+%.2f\n",offsetx,width,offsety,height); - - // verifications - if (width < 2 || height < 2 ){ - printf("screen geometry : %.2f %.2f\n",width,height); - printHelpMsg(argv[0]); - exit(1); - } - - if (wacom) { + + if (!predictive_mode && user_coordsO){ + offsetx = coordsO[0]; + offsety = coordsO[1]; + width = coordsO[2]-coordsO[0]; + height = coordsO[3]-coordsO[1]; + } else { + offsetx = 0; + offsety = 0; + width = DisplayWidth(d, DefaultScreen(d)); + height = DisplayHeight(d, DefaultScreen(d)); + } + + printf("screen : %.2f+%.2f x %.2f+%.2f\n",offsetx,width,offsety,height); + + // verifications + if (width < 2 || height < 2 ){ + printf("screen geometry : %.2f %.2f\n",width,height); + printHelpMsg(argv[0]); + exit(1); + } + + if (wacom) { if (predictive_mode){ coords_input[2] = width; coords_input[3] = height; @@ -605,7 +605,7 @@ int main(int argc, char *argv[]) { coords_input[2] = 1.0; coords_input[3] = 1.0; } - //~ print_coords_input(); + //~ print_coords_input(); if (!predictive_mode) { champX = CHAMP_X_WACOM; champY = CHAMP_Y_WACOM; @@ -617,66 +617,66 @@ int main(int argc, char *argv[]) { champXButton = CHAMP_X_WACOM_PREDICTIVE_BUTTON; champYButton = CHAMP_Y_WACOM_PREDICTIVE_BUTTON; } - } else { + } else { champX = CHAMP_X_TELEPOINTEUR; champY = CHAMP_Y_TELEPOINTEUR; } - + champX -= device_input_id_given; champY -= device_input_id_given; champXButton -= device_input_id_given; champYButton -= device_input_id_given; - - width_input = coords_input[2]-coords_input[0]; - height_input = coords_input[3]-coords_input[1]; + + width_input = coords_input[2]-coords_input[0]; + height_input = coords_input[3]-coords_input[1]; horiz_ratio = width / width_input; vert_ratio = height / height_input; - - MsgRcvPtr ptrMove,ptrRelMove,ptrButton,ptrGeometry,ptrLockUnlock; - - if (device_input_id_given) { - sprintf(ivyName, "IvyPointer:%s", device_input_id); - } - - IvyInit(ivyName,"IvyPointer Ready",NULL,NULL,NULL,NULL); - - char regexp[2048] = ""; - if (!wacom) { - // telepointer callbacks - - 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 - 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); - - 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); - } + + MsgRcvPtr ptrMove,ptrRelMove,ptrButton,ptrGeometry,ptrLockUnlock; + + if (device_input_id_given) { + sprintf(ivyName, "IvyPointer:%s", device_input_id); + } + + IvyInit(ivyName,"IvyPointer Ready",NULL,NULL,NULL,NULL); + + char regexp[2048] = ""; + if (!wacom) { + // telepointer callbacks + + 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 + 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); + + 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); + } if (!predictive_mode) { sprintf(regexp, REGEXP_CHANGE_GEOMETRY_SCREEN, device_input_id); @@ -687,12 +687,12 @@ int main(int argc, char *argv[]) { sprintf(regexp, REGEXP_LOCK_UNLOCK, device_input_id); ptrLockUnlock=IvyBindMsg(CallbackLockUnlock,&ptrLockUnlock, REGEXP_LOCK_UNLOCK, device_input_id); printf("bound to %s\n",regexp); - - IvyStart(bus); + + IvyStart(bus); #if (IVYMAJOR_VERSION == 3) && (IVYMINOR_VERSION < 9) - IvyMainLoop(NULL, NULL); + IvyMainLoop(NULL, NULL); #else - IvyMainLoop(); + IvyMainLoop(); #endif return 0; } -- cgit v1.1