# On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # modified: src/feedback.c # modified: src/xinput.c # modified: src/xinput.h # diff --git a/src/feedback.c b/src/feedback.c index 7f4da57..e1e5045 100644 --- a/src/feedback.c +++ b/src/feedback.c @@ -183,4 +183,128 @@ get_feedbacks(Display *display, return EXIT_SUCCESS; } +/** cheat sheet from Xi.h + DevicePtrAccel_Scheme (DEVICE_PTRACCEL + 0) +#define DevicePtrAccel_Profile (DEVICE_PTRACCEL + 1) +#define DevicePtrAccel_Scale (DEVICE_PTRACCEL + 2) +#define DevicePtrAccel_Coeff (DEVICE_PTRACCEL + 3) +#define DevicePtrAccel_AvgDecay (DEVICE_PTRACCEL + 4) +#define DevicePtrAccel_MinAcc (DEVICE_PTRACCEL + 5) +#define DevicePtrAccel_ConstAcc (DEVICE_PTRACCEL + 6) +#define DevicePtrAccel_Soften (DEVICE_PTRACCEL + 7) +#define DevicePtrAccel_Coupling (DEVICE_PTRACCEL + 8) +#define DevicePtrAccel_LutSize (DEVICE_PTRACCEL + 9) +#define DevicePtrAccel_SampleCoupling (DEVICE_PTRACCEL + 10) +#define DevicePtrAccel_SampleVelocity (DEVICE_PTRACCEL + 11) +#define DevicePtrAccel_SampleAcceleration (DEVICE_PTRACCEL + 12) + */ + +/* + * This relates to bug#8583 + */ +int +set_ptr_feedback_advanced(Display *display, + int argc, + char *argv[], + char *name, + char *desc) +{ + XDeviceInfo *info; + XDevice *device; + XDeviceAccelerationControl ctrl; + int id; + int ppos = 2; + int controlcode = -1; + int nargc = 2; + Bool has_int, has_rat; + + if (argc < nargc) { + fprintf(stderr, "usage: xinput %s %s\n", name, desc); + return 1; + } + + info = find_device_info(display, argv[0], True); + + if (!info) { + fprintf(stderr, "unable to find extension device %s\n", argv[0]); + return 1; + } + + device = XOpenDevice(display, info->id); + + if (!device) { + fprintf(stderr, "unable to open device %s\n", argv[0]); + return 1; + } + + if(strcmp(argv[1], "profile") == 0){ + controlcode = DevicePtrAccel_Profile; + has_int = 1; + has_rat = 0; + } + if(strcmp(argv[1], "scheme") == 0){ + controlcode = DevicePtrAccel_Scheme; + has_int = 1; + has_rat = 0; + } + if(strcmp(argv[1], "scale") == 0){ + controlcode = DevicePtrAccel_Scale; + has_int = 0; + has_rat = 1; + } + if(strcmp(argv[1], "avg-decay") == 0){ + controlcode = DevicePtrAccel_AvgDecay; + has_int = 0; + has_rat = 1; + } + if(strcmp(argv[1], "const-dec") == 0){ + controlcode = DevicePtrAccel_ConstAcc; + has_int = 1; /* rat is unsuitable, see below */ + has_rat = 0; + } + + if(has_int) + nargc++; + if(has_rat) //a rational may need only one parameter, den = 1 then + nargc++; + + if (argc < nargc){ + fprintf(stderr, "not enough parameterrs for setting '%s'\n", argv[1]); + return 1; + } + + if(-1 == controlcode){ + fprintf(stderr, "unmatched parameter type %s\n", argv[1]); + return 1; + } + + ctrl.control = controlcode; + ctrl.length = sizeof(ctrl); + if(has_int){ + ctrl.integer = atoi(argv[ppos++]); + }else{ + ctrl.integer = 0; + } + if(has_rat){ + ctrl.rational_num = atoi(argv[ppos++]); + if(ppos < argc) + ctrl.rational_den = atoi(argv[ppos++]); + else + ctrl.rational_den = 1; + }else{ + ctrl.rational_num = 0; + ctrl.rational_den = 0; + } + + if(DevicePtrAccel_ConstAcc == controlcode){ + /* e.g. int 3 -> 1/3 */ + ctrl.rational_den = ctrl.integer; + ctrl.rational_num = 1; + ctrl.integer = 0; + } + + XChangeDeviceControl(display, device, controlcode, (XDeviceControl*)&ctrl); + return EXIT_SUCCESS; +} + /* end of ptrfdbk.c */ diff --git a/src/xinput.c b/src/xinput.c index f74dee5..21eb34a 100644 --- a/src/xinput.c +++ b/src/xinput.c @@ -49,6 +49,10 @@ static entry drivers[] = " ", set_ptr_feedback }, + {"set-ptr-accel", + " [] [ ]", + set_ptr_feedback_advanced + }, {"set-integer-feedback", " ", set_integer_feedback diff --git a/src/xinput.h b/src/xinput.h index a43ab73..e38d641 100644 --- a/src/xinput.h +++ b/src/xinput.h @@ -65,6 +65,17 @@ set_ptr_feedback( ); int +set_ptr_feedback_advanced( +#if NeedFunctionPrototypes + Display* display, + int argc, + char *argv[], + char *prog_name, + char *prog_desc +#endif +); + +int set_button_map( #if NeedFunctionPrototypes Display* display,