From 79800e1e0fa3b45b6ed37453851df24c98da4435 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Tue, 15 Sep 2009 17:55:35 +0200 Subject: 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 Signed-off-by: Peter Hutterer --- src/property.c | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/xinput.c | 2 +- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'src') 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", - " [ ...]", + " [--type=atom|float|int] [--format=8|16|32] [ ...]", set_prop }, {NULL, NULL, NULL -- cgit v1.2.3