diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-03-26 09:05:24 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-03-26 09:05:24 +1000 |
commit | dfc101e4c6cdac4ff9a51732b2754287fbdc8582 (patch) | |
tree | 7eaaa6d7f32a53a8dd495b9f1b3663e01248dd8f /src | |
parent | 8436c920953f288aea2d6d5f370f8eaaaef82d97 (diff) |
Move version comparison into a helper function.
No functional changes, this simply introduces a version helper function that
returns -1, 0 or 1 depending on the version comparison result. To be used
internally only.
Needed for fix to #34240
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/XExtInt.c | 51 | ||||
-rw-r--r-- | src/XIint.h | 1 |
2 files changed, 42 insertions, 10 deletions
diff --git a/src/XExtInt.c b/src/XExtInt.c index 0c64f9a..4f85667 100644 --- a/src/XExtInt.c +++ b/src/XExtInt.c @@ -344,6 +344,43 @@ static int XInputCheckExtension(Display *dpy, XExtDisplayInfo *info) return 1; } +/***************************************************************** + * Compare version numbers between info and the built-in version table. + * Returns + * -1 if info's version is less than version_index's version, + * 0 if equal (or DontCheck), + * 1 if info's version is greater than version_index's version. + * Returns -2 on initialization errors which shouldn't happen if you call it + * correctly. + */ +_X_HIDDEN int +_XiCheckVersion(XExtDisplayInfo *info, + int version_index) +{ + XExtensionVersion *ext; + + if (versions[version_index].major_version == Dont_Check) + return 0; + + if (!info->data) + return -2; + + ext = ((XInputData *) info->data)->vers; + if (!ext) + return -2; + + if (ext->major_version == versions[version_index].major_version && + ext->minor_version == versions[version_index].minor_version) + return 0; + + if (ext->major_version < versions[version_index].major_version || + (ext->major_version == versions[version_index].major_version && + ext->minor_version < versions[version_index].minor_version)) + return -1; + else + return 1; +} + /*********************************************************************** * * Check to see if the input extension is installed in the server. @@ -357,8 +394,6 @@ _XiCheckExtInit( register int version_index, XExtDisplayInfo *info) { - XExtensionVersion *ext; - if (!XInputCheckExtension(dpy, info)) { UnlockDisplay(dpy); return (-1); @@ -374,15 +409,11 @@ _XiCheckExtInit( _XiGetExtensionVersion(dpy, "XInputExtension", info); } - if (versions[version_index].major_version > Dont_Check) { - ext = ((XInputData *) info->data)->vers; - if ((ext->major_version < versions[version_index].major_version) || - ((ext->major_version == versions[version_index].major_version) && - (ext->minor_version < versions[version_index].minor_version))) { - UnlockDisplay(dpy); - return (-1); - } + if (_XiCheckVersion(info, version_index) < 0) { + UnlockDisplay(dpy); + return -1; } + return (0); } diff --git a/src/XIint.h b/src/XIint.h index cc46754..be4eafb 100644 --- a/src/XIint.h +++ b/src/XIint.h @@ -26,6 +26,7 @@ extern XExtDisplayInfo *XInput_find_display(Display *); extern int _XiCheckExtInit(Display *, int, XExtDisplayInfo *); +extern int _XiCheckVersion(XExtDisplayInfo *info, int version_index); extern XExtensionVersion *_XiGetExtensionVersion(Display *, _Xconst char *, XExtDisplayInfo *); extern XExtensionVersion* _XiGetExtensionVersionRequest(Display *dpy, _Xconst char *name, int xi_opcode); |