summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Cristau <jcristau@debian.org>2009-09-15 17:55:35 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2009-09-17 11:02:27 +1000
commit79800e1e0fa3b45b6ed37453851df24c98da4435 (patch)
treeb89769dff88f6ed5ce99d1e32dffe98c32a68507
parent1665fa4e24930f7e3f1cfbc8bf50119ab7d6ca04 (diff)
set-prop: add --type={atom,float,int} and --format={8,16,32} options
Allows creating new properties or modifying the type and format of existing ones. Signed-off-by: Julien Cristau <jcristau@debian.org> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--man/xinput.man8
-rw-r--r--src/property.c44
-rw-r--r--src/xinput.c2
3 files changed, 47 insertions, 7 deletions
diff --git a/man/xinput.man b/man/xinput.man
index 104cafb..660cc0c 100644
--- a/man/xinput.man
+++ b/man/xinput.man
@@ -69,10 +69,10 @@ are 8, 16, or 32, depending on the property.
Sets a float property for the device.
.PP
.TP 8
-.B xinput set-prop \fIdevice_name\fP \fIproperty\fP \fIvalue\fP
-Set the property to the given value(s). The format and type of the property
-are left as-is and the arguments are interpreted according to the property
-type. This argument can only be used to modify existing properties.
+.B xinput set\-prop [\-\-type=\fIatom|float|int\fP] [\-\-format=\fI8|16|32\fP] \fIdevice_name\fP \fIproperty\fP \fIvalue\fP [...]
+Set the property to the given value(s). If not specified, the format and type
+of the property are left as-is. The arguments are interpreted according to the
+property type.
.PP
.TP 8
.B xinput watch-props \fIdevice_name\fP
diff --git a/src/property.c b/src/property.c
index a41446b..1ab7e4a 100644
--- a/src/property.c
+++ b/src/property.c
@@ -915,6 +915,46 @@ do_set_prop(Display *display, Atom type, int format, int argc, char *argv[], cha
int set_prop(Display *display, int argc, char *argv[], char *name,
char *desc)
{
- return do_set_prop(display, None, 0, argc, argv, name, desc);
-}
+ Atom type = None;
+ int format = 0;
+ int i = 0, j;
+
+ while (i < argc) {
+ char *option = strchr(argv[i], '=');
+ /* skip non-option arguments */
+ if (strncmp(argv[i], "--", 2) || !option) {
+ i++;
+ continue;
+ }
+
+ if (!strncmp(argv[i], "--type=", strlen("--type="))) {
+ if (!strcmp(option + 1, "int")) {
+ type = XA_INTEGER;
+ } else if (!strcmp(option + 1, "float")) {
+ type = XInternAtom(display, "FLOAT", False);
+ format = 32;
+ } else if (!strcmp(option + 1, "atom")) {
+ type = XA_ATOM;
+ format = 32;
+ } else {
+ fprintf(stderr, "unknown property type %s\n", option + 1);
+ return EXIT_FAILURE;
+ }
+ } else if (!strncmp(argv[i], "--format=", strlen("--format="))) {
+ format = atoi(option + 1);
+ if (format != 8 && format != 16 && format != 32) {
+ fprintf(stderr, "invalid property format %s\n", option + 1);
+ return EXIT_FAILURE;
+ }
+ } else {
+ fprintf(stderr, "invalid option %s\n", argv[i]);
+ return EXIT_FAILURE;
+ }
+ for (j = i; j + 1 < argc; j++)
+ argv[j] = argv[j + 1];
+ argc--;
+ }
+
+ return do_set_prop(display, type, format, argc, argv, name, desc);
+}
diff --git a/src/xinput.c b/src/xinput.c
index 8340211..1a1e7ce 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -134,7 +134,7 @@ static entry drivers[] =
delete_prop
},
{ "set-prop",
- "<device> <property> <val> [<val> ...]",
+ "<device> [--type=atom|float|int] [--format=8|16|32] <property> <val> [<val> ...]",
set_prop
},
{NULL, NULL, NULL