aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ivypointer.c148
1 files changed, 99 insertions, 49 deletions
diff --git a/src/ivypointer.c b/src/ivypointer.c
index 7183f0d..95ade81 100644
--- a/src/ivypointer.c
+++ b/src/ivypointer.c
@@ -53,6 +53,7 @@
#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=(.*)"
@@ -71,7 +72,7 @@
Display* display = NULL;
int width,height;
float coords_input[4] = {0.0,0.0,100.0,100.0};
-int width_input,height_input;
+int width_input,height_input, offsetx, offsety;
int dragged = 0;
int relative = 0;
@@ -206,6 +207,23 @@ 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]);
+ if (x1 > x0 && y1 > y0 ){
+ offsetx = x0;
+ offsety = y0;
+ width = x1-x0;
+ height = y1-y0;
+ printf("screen : %d+%d x %d+%d\n",offsetx,width,offsety,height);
+ } else {
+ printf("bad coords received : %.0f,%.0f %.0f,%.0f\n",x0,y0,x1,y1);
+ }
+}
+
// --------------------------------------------------------------------------
// Telepointer callbacks
// --------------------------------------------------------------------------
@@ -291,8 +309,8 @@ void CallbackPointer (IvyClientPtr app, void *user_data, int argc, char *argv[])
}
// printf("x = %f,y = %f; ",x,y);
if (valid(x,y)){
- x = (x-coords_input[0])*width/width_input;
- y = (y-coords_input[1])*height/height_input;
+ x = offsetx + (x-coords_input[0])*width/width_input;
+ y = offsety + (y-coords_input[1])*height/height_input;
// printf("x = %f,y = %f\n",x,y);
if (!relative) {
fakeMouseMove((int)x,(int)y);
@@ -375,29 +393,65 @@ void CallbackSlider (IvyClientPtr app, void *user_data, int argc, char *argv[])
// fakeMouseButton(b,press);
}
-// --------------------------------------------------------------------------
-// Main
-// --------------------------------------------------------------------------
-
-int main(int argc, char *argv[]) {
- const char* bus = 0;
- char busbuf [1024] = "";
+void printHelpMsg(const char *name){
const char* helpmsg =
"[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-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-r\tuse relative mode by default\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;
+ printf("usage: %s %s",name,helpmsg);
+}
+
+int extractValues(char optarg[], int* output, const char name[]){
int i = 0;
int j = 0;
- int coupures[4] = {0,0,0,0};
int last = 0;
- while ((c = getopt(argc, argv, "vb:wc:r")) != EOF)
+ int coupures[4] = {0,0,0,0};
+
+ while(optarg[i]){
+ if (optarg[i] == ','){
+ coupures[j] = i;
+ j++;
+ if (j > 3) {
+ printHelpMsg(name);
+ exit(1);
+ }
+ }
+ i++;
+ }
+ 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] = atoi(buf);
+ last = coupures[i]+1;
+ }
+ return 1;
+}
+
+// --------------------------------------------------------------------------
+// Main
+// --------------------------------------------------------------------------
+
+int main(int argc, char *argv[]) {
+ const char* bus = 0;
+ char busbuf [1024] = "";
+ int wacom = 0;
+ int user_coordsI = 0;
+ int user_coordsO = 0;
+ int coordsI[4] = {0,0,0,0};
+ int coordsO[4] = {0,0,0,0};
+ int c;
+ while ((c = getopt(argc, argv, "vb:wc:C:r")) != EOF)
switch (c) {
case 'b':
strcpy (busbuf, optarg);
@@ -413,35 +467,13 @@ int main(int argc, char *argv[]) {
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;
+ user_coordsI = extractValues(optarg, coordsI, argv[0]);
+ break;
+ case 'C':
+ user_coordsO = extractValues(optarg, coordsO, argv[0]);
break;
default:
- printf("usage: %s %s",argv[0],helpmsg);
+ printHelpMsg(argv[0]);
exit(1);
}
Display* d = openDisplay(NULL);
@@ -450,10 +482,10 @@ int main(int argc, char *argv[]) {
}
if (wacom) {
- if (user_coords){
+ if (user_coordsI){
int i;
for (i=0;i<4;i++) {
- coords_input[i] = coords[i];
+ coords_input[i] = coordsI[i];
}
} else {
coords_input[2] = WIDTH_WACOM;
@@ -464,9 +496,25 @@ int main(int argc, char *argv[]) {
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);
+ if (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 : %d+%d x %d+%d\n",offsetx,width,offsety,height);
+
+ // verifications
+ if (width < 2 || height < 2 || width_input < 2 || height_input < 2){
+ printHelpMsg(argv[0]);
+ exit(1);
+ }
MsgRcvPtr ptrMove,ptrRelMove,ptrButton;
IvyInit("IvyPointer","IvyPointer Ready",NULL,NULL,NULL,NULL);
@@ -492,6 +540,8 @@ int main(int argc, char *argv[]) {
ptrMove=IvyBindMsg(CallbackPad,&ptrButton,REGEXP_PAD);
printf("bound to %s\n",REGEXP_PAD);
}
+ ptrMove=IvyBindMsg(CallbackScreen,&ptrMove,REGEXP_CHANGE_GEOMETRY_SCREEN);
+ printf("bound to %s\n",REGEXP_CHANGE_GEOMETRY_SCREEN);
IvyStart(bus);
#if (IVYMAJOR_VERSION == 3) && (IVYMINOR_VERSION < 9)
IvyMainLoop(NULL, NULL);