[PATCH app/xinput] Clean up --version, don't require a DISPLAY and display the server version too.
Peter Hutterer
peter.hutterer at who-t.net
Thu Oct 8 22:52:51 PDT 2009
version.c was removed, seemed a bit excessive for the 20 lines of code.
--version is integrated separate from the other commands now, checked before
opening the display. xinput now prints its own version in all cases, even if
the display is unavailable. If the display is available, it prints the
server version too. Example output:
$> xinput --version
xinput version 1.4.99.3
XI version on server: 2.0
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
man/xinput.man | 3 ++-
src/Makefile.am | 1 -
src/version.c | 43 -------------------------------------------
src/xinput.c | 45 ++++++++++++++++++++++++++++++++++++++-------
4 files changed, 40 insertions(+), 52 deletions(-)
delete mode 100644 src/version.c
diff --git a/man/xinput.man b/man/xinput.man
index 174df27..fbf445e 100644
--- a/man/xinput.man
+++ b/man/xinput.man
@@ -13,7 +13,8 @@ a device and change input device settings.
.TP 8
.B --version
Test if the X Input extension is available and return the version number
-of the program. This option does not require a device name.
+of the program and the version supported by the server. This option does not
+require a device name.
.PP
.TP 8
.B --list [--short || --long] [\fIdevice\fP]
diff --git a/src/Makefile.am b/src/Makefile.am
index a6dedb7..ba0d325 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -39,7 +39,6 @@ xinput_SOURCES = \
state.c \
property.c \
test.c \
- version.c \
xinput.c \
xinput.h \
$(xinput2_files)
diff --git a/src/version.c b/src/version.c
deleted file mode 100644
index 93a50d8..0000000
--- a/src/version.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 1996-1997 by Frederic Lepied, France. <Frederic.Lepied at sugix.frmug.org>
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of the authors not be used in
- * advertising or publicity pertaining to distribution of the software without
- * specific, written prior permission. The authors make no
- * representations about the suitability of this software for any purpose. It
- * is provided "as is" without express or implied warranty.
- *
- * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- */
-
-#include "xinput.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-static const char version_id[] = VERSION;
-
-int
-version(Display *display,
- int argc,
- char *argv[],
- char *name,
- char *desc)
-{
- printf("%s %s\n", name, version_id);
- return EXIT_SUCCESS;
-}
-
-/* end of version.c */
diff --git a/src/xinput.c b/src/xinput.c
index 3c8b23c..149662d 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -79,10 +79,6 @@ static entry drivers[] =
"[-proximity] <device name>",
test
},
- {"version",
- "",
- version
- },
#if HAVE_XI2
{ "create-master",
"<id> [<sendCore (dflt:1)>] [<enable (dflt:1)>]",
@@ -141,6 +137,37 @@ static entry drivers[] =
}
};
+static const char version_id[] = VERSION;
+
+int
+print_version()
+{
+ XExtensionVersion *version;
+ Display *display;
+
+ printf("xinput version %s\n", version_id);
+
+ display = XOpenDisplay(NULL);
+
+ printf("XI version on server: ");
+
+ if (display == NULL)
+ printf("Failed to open display.\n");
+ else {
+ version = XGetExtensionVersion(display, INAME);
+ if (!version || (version == (XExtensionVersion*) NoSuchExtension))
+ printf(" Extension not supported.\n");
+ else {
+ printf("%d.%d\n", version->major_version,
+ version->minor_version);
+ XFree(version);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
int
xinput_version(Display *display)
{
@@ -266,6 +293,13 @@ main(int argc, char * argv[])
return EXIT_FAILURE;
}
+ func = argv[1];
+ while((*func) == '-') func++;
+
+ if (strcmp("version", func) == 0) {
+ return print_version(argv[0]);
+ }
+
display = XOpenDisplay(NULL);
if (display == NULL) {
@@ -278,9 +312,6 @@ main(int argc, char * argv[])
return EXIT_FAILURE;
}
- func = argv[1];
- while((*func) == '-') func++;
-
if (!xinput_version(display)) {
fprintf(stderr, "%s extension not available\n", INAME);
return EXIT_FAILURE;
--
1.6.3.rc1.2.g0164.dirty
More information about the xorg-devel
mailing list