tools - tweak-device: add a --resolution command

So far, 100% of the usages for tweak-tool was to set the x/y resolution of a
device. Make --resolution a shortcut for this.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Peter Hutterer 2015-06-29 12:13:40 +10:00
parent 4d058bc2b0
commit 8b9c47a7cb
2 changed files with 105 additions and 2 deletions

View file

@ -5,6 +5,8 @@ libevdev-tweak-device \- modify an evdev kernel device
.B libevdev-tweak-device
--abs ABS_X [--min a] [--max b] [--res c] [--fuzz d] [--flat e]
/dev/input/eventX
.B libevdev-tweak-device
--resolution res[,yres] /dev/input/eventX
.PP
.B libevdev-tweak-device
--led LED_NUML --on|--off /dev/input/eventX
@ -41,6 +43,14 @@ Set the absinfo fuzz to the value v
.B --flat v
Set the absinfo flat to the value v
.PP
.SS Changing the x/y resolution
.TP 8
.B --resolution res[,yres]
Changes the resolution of the ABS_X, ABS_MT_POSITION_X, ABS_Y, and
ABS_MT_POSITION_Y axis to the given resolution. If only one resolution value
is provided, both x and y axis are set to the same resolution, otherwise the
first resolution value is applied to the x axes and the second value to the
y axes.
.SS Toggling LEDs
.TP 8
.B --led led

View file

@ -24,6 +24,7 @@
#include <config.h>
#include <getopt.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -42,15 +43,20 @@ usage(void)
{
printf("%s --abs <axis> [--min min] [--max max] [--res res] [--fuzz fuzz] [--flat flat] /dev/input/eventXYZ\n"
"\tChange the absinfo struct for the named axis\n"
"%s --resolution res[,yres] /dev/input/eventXYZ\n"
"\tChange the x/y resolution on the given device\n"
"%s --led <led> --on|--off /dev/input/eventXYZ\n"
"\tEnable or disable the named LED\n",
program_invocation_short_name, program_invocation_short_name);
program_invocation_short_name,
program_invocation_short_name,
program_invocation_short_name);
}
enum mode {
MODE_NONE = 0,
MODE_ABS,
MODE_LED,
MODE_RESOLUTION,
MODE_HELP,
};
@ -64,9 +70,30 @@ enum opts {
OPT_LED = 1 << 6,
OPT_ON = 1 << 7,
OPT_OFF = 1 << 8,
OPT_HELP = 1 << 9,
OPT_RESOLUTION = 1 << 9,
OPT_HELP = 1 << 10,
};
static bool
parse_resolution_argument(const char *arg, int *xres, int *yres)
{
int matched;
matched = sscanf(arg, "%d,%d", xres, yres);
switch(matched) {
case 2:
break;
case 1:
*yres = *xres;
break;
default:
return false;
}
return true;
}
static int
parse_options_abs(int argc, char **argv, unsigned int *changes,
int *axis, struct input_absinfo *absinfo)
@ -174,6 +201,42 @@ error:
return rc;
}
static int
parse_options_resolution(int argc, char **argv, int *xres, int *yres)
{
int rc = 1;
int c;
int option_index = 0;
static struct option opts[] = {
{ "resolution", 1, 0, OPT_RESOLUTION },
{ NULL, 0, 0, 0 },
};
if (argc < 2)
goto error;
optind = 1;
while (1) {
c = getopt_long(argc, argv, "h", opts, &option_index);
if (c == -1)
break;
switch (c) {
case OPT_RESOLUTION:
if (!parse_resolution_argument(optarg,
xres, yres))
goto error;
break;
default:
goto error;
}
}
rc = 0;
error:
return rc;
}
static enum mode
parse_options_mode(int argc, char **argv, const char **path)
{
@ -182,6 +245,7 @@ parse_options_mode(int argc, char **argv, const char **path)
static const struct option opts[] = {
{ "abs", 1, 0, OPT_ABS },
{ "led", 1, 0, OPT_LED },
{ "resolution", 1, 0, OPT_RESOLUTION },
{ "help", 0, 0, OPT_HELP },
{ NULL, 0, 0, 0 },
};
@ -206,6 +270,9 @@ parse_options_mode(int argc, char **argv, const char **path)
case OPT_LED:
mode = MODE_LED;
break;
case OPT_RESOLUTION:
mode = MODE_RESOLUTION;
break;
default:
break;
}
@ -278,6 +345,24 @@ set_led(struct libevdev *dev, unsigned int led, int led_state)
strerror(-rc));
}
static void
set_resolution(struct libevdev *dev, int xres, int yres)
{
struct input_absinfo abs;
abs.resolution = xres;
if (libevdev_has_event_code(dev, EV_ABS, ABS_X))
set_abs(dev, OPT_RES, ABS_X, &abs);
if (libevdev_has_event_code(dev, EV_ABS, ABS_MT_POSITION_X))
set_abs(dev, OPT_RES, ABS_MT_POSITION_X, &abs);
abs.resolution = yres;
if (libevdev_has_event_code(dev, EV_ABS, ABS_Y))
set_abs(dev, OPT_RES, ABS_Y, &abs);
if (libevdev_has_event_code(dev, EV_ABS, ABS_MT_POSITION_Y))
set_abs(dev, OPT_RES, ABS_MT_POSITION_Y, &abs);
}
int
main(int argc, char **argv)
{
@ -291,6 +376,7 @@ main(int argc, char **argv)
int led;
int led_state = -1;
unsigned int changes; /* bitmask of changes */
int xres, yres;
mode = parse_options_mode(argc, argv, &path);
switch (mode) {
@ -307,6 +393,10 @@ main(int argc, char **argv)
case MODE_LED:
rc = parse_options_led(argc, argv, &led, &led_state);
break;
case MODE_RESOLUTION:
rc = parse_options_resolution(argc, argv, &xres,
&yres);
break;
default:
fprintf(stderr,
"++?????++ Out of Cheese Error. Redo From Start.\n");
@ -335,6 +425,9 @@ main(int argc, char **argv)
case MODE_LED:
set_led(dev, led, led_state);
break;
case MODE_RESOLUTION:
set_resolution(dev, xres, yres);
break;
default:
break;
}