From 8713f704d371029df3c7b99390a672546b6e6d7d Mon Sep 17 00:00:00 2001 From: tissoire Date: Tue, 15 May 2012 12:56:24 +0000 Subject: implement crop ivy command. Currently, the outside treatment is dummy, i.e. once outside, no events beside mouse up are transfered. --- src/ivypointer.c | 58 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/ivypointer.c b/src/ivypointer.c index c365042..6a38165 100644 --- a/src/ivypointer.c +++ b/src/ivypointer.c @@ -63,6 +63,7 @@ #include "getopt.h" #define REGEXP_CHANGE_GEOMETRY_SCREEN "^screen_geometry_event device_id=%s x0=(.*) y0=(.*) x1=(.*) y1=(.*)" +#define REGEXP_CHANGE_CROP "^crop_event device_id=%s x0=(.*) y0=(.*) x1=(.*) y1=(.*)" #define REGEXP_LOCK_UNLOCK "^lock_event device_id=%s status=(lock|unlock)" #define REGEXP_MOVE "^TelepointerMotion Id=%s X=(.*) Y=(.*)" @@ -100,8 +101,8 @@ #define CHAMP_TIME_XINPUT_2 4 #define CHAMP_PRESSURE_XINPUT_2 3 -#define CHAMP_X_WACOM_BUTTON_2 1 -#define CHAMP_Y_WACOM_BUTTON_2 2 +#define CHAMP_X_WACOM_BUTTON_2 3 +#define CHAMP_Y_WACOM_BUTTON_2 4 #define TIME_CLICK 200 #define TIME_BETWEEN_CLICK 200 @@ -280,6 +281,31 @@ static void CallbackScreen(IvyClientPtr app, void *user_data, int argc, char *ar } // -------------------------------------------------------------------------- +// Crop callback +// -------------------------------------------------------------------------- + +static void CallbackCrop(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 ){ + coords_input[0] = x0; + coords_input[1] = y0; + coords_input[2] = x1; + coords_input[3] = y1; + 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; + printf("crop : %f %f %f %f\n",x0, y0, x1, y1); + } else { + printf("bad coords received : %.2f,%.2f %.2f,%.2f\n",x0,y0,x1,y1); + } +} + +// -------------------------------------------------------------------------- // Lock/Unlock callback // -------------------------------------------------------------------------- @@ -301,8 +327,8 @@ static void CallbackMove (IvyClientPtr app, void *user_data, int argc, char *arg // ignore outside events return; } - x = offsetx + x * horiz_ratio; - y = offsety + y * vert_ratio; + x = offsetx + (x - coords_input[0]) * horiz_ratio; + y = offsety + (y - coords_input[1]) * vert_ratio; // printf("x = %f,y = %f\n",x,y); old_x = x; old_y = y; @@ -322,8 +348,8 @@ static void CallbackDrag (IvyClientPtr app, void *user_data, int argc, char *arg // ignore outside events return; } - x = offsetx + x * horiz_ratio; - y = offsety + y * vert_ratio; + x = offsetx + (x - coords_input[0]) * horiz_ratio; + y = offsety + (y - coords_input[1]) * vert_ratio; // printf("x = %f,y = %f\n",x,y); old_x = x; old_y = y; @@ -345,8 +371,8 @@ static void CallbackButton (IvyClientPtr app, void *user_data, int argc, char *a // 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 + if (press && !valid(old_x,old_y)){ + // ignore outside release events return; } fakeMouseButton(b,press,0,0); @@ -372,8 +398,8 @@ static void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char * if (!predictive_mode) { // in predictive mode, we don't allow the geometry to be changed - x = offsetx + x * horiz_ratio; - y = offsety + y * vert_ratio; + x = offsetx + (x - coords_input[0]) * horiz_ratio; + y = offsety + (y - coords_input[1]) * vert_ratio; } if (!relative) { @@ -474,8 +500,8 @@ static void CallbackButtonWacom (IvyClientPtr app, void *user_data, int argc, ch 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 + if (press && !valid(x,y)){ + // ignore outside release events return; } @@ -490,8 +516,8 @@ static void CallbackButtonXInput2 (IvyClientPtr app, void *user_data, int argc, int press = !!strcmp(argv[2-device_input_id_given],"released"); float x = atof(argv[champXButton]); float y = atof(argv[champYButton]); - if (!valid(x,y)){ - // ignore outside events + if (press && !valid(x,y)){ + // ignore outside release events return; } @@ -752,6 +778,10 @@ int main(int argc, char *argv[]) { printf("bound to %s\n",regexp); } + sprintf(regexp, REGEXP_CHANGE_CROP, device_input_id); + ptrGeometry=IvyBindMsg(CallbackCrop,&ptrGeometry, REGEXP_CHANGE_CROP, device_input_id); + printf("bound to %s\n",regexp); + sprintf(regexp, REGEXP_LOCK_UNLOCK, device_input_id); ptrLockUnlock=IvyBindMsg(CallbackLockUnlock,&ptrLockUnlock, REGEXP_LOCK_UNLOCK, device_input_id); printf("bound to %s\n",regexp); -- cgit v1.1