summaryrefslogtreecommitdiff
path: root/src
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 /src
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>
Diffstat (limited to 'src')
-rw-r--r--src/property.c44
-rw-r--r--src/xinput.c2
2 files changed, 43 insertions, 3 deletions
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