[PATCH:xf86-input-keyboard 23/23] Factor out common code.

Thomas Klausner wiz at NetBSD.org
Mon Jul 29 14:23:49 PDT 2013


Suggested by Walter Harms <wharms at bfs.de>.

Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
Reviewed-by: Matthieu Herrb <matthieu.herrb at laas.fr>
---
 src/bsd_kbd.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/bsd_kbd.c b/src/bsd_kbd.c
index 1e0531e..175c544 100644
--- a/src/bsd_kbd.c
+++ b/src/bsd_kbd.c
@@ -39,6 +39,21 @@ typedef struct {
    struct termios kbdtty;
 } BsdKbdPrivRec, *BsdKbdPrivPtr;
 
+#ifdef WSCONS_SUPPORT
+static Bool
+WSSetVersion(int fd, const char *name)
+{
+#ifdef WSKBDIO_SETVERSION
+    int version = WSKBDIO_EVENT_VERSION;
+    if (ioctl(fd, WSKBDIO_SETVERSION, &version) == -1) {
+        xf86Msg(X_WARNING, "%s: cannot set version\n", name);
+        return FALSE;
+    }
+#endif
+    return TRUE;
+}
+#endif
+
 static
 int KbdInit(InputInfoPtr pInfo, int what)
 {
@@ -211,13 +226,8 @@ KbdOn(InputInfoPtr pInfo, int what)
             	 if ((pKbd->wsKbdDev[0] != 0) && (pInfo->fd == -1)) {
 			xf86Msg(X_INFO, "opening %s\n", pKbd->wsKbdDev);
 			pInfo->fd = open(pKbd->wsKbdDev, O_RDONLY | O_NONBLOCK | O_EXCL);
-#ifdef WSKBDIO_SETVERSION
-			int version = WSKBDIO_EVENT_VERSION;
-			if (ioctl(pInfo->fd, WSKBDIO_SETVERSION, &version) == -1) {
-				xf86Msg(X_WARNING, "%s: cannot set version\n", pInfo->name);
+			if (WSSetVersion(pInfo->fd, pInfo->name) == FALSE)
 				return FALSE;
-			}
-#endif
 		}
 		break;
 #endif
@@ -416,13 +426,8 @@ OpenKeyboard(InputInfoPtr pInfo)
 #ifdef WSCONS_SUPPORT
     if( prot == PROT_WSCONS) {
        pKbd->consType = WSCONS;
-#ifdef WSKBDIO_SETVERSION
-       int version = WSKBDIO_EVENT_VERSION;
-       if (ioctl(pInfo->fd, WSKBDIO_SETVERSION, &version) == -1) {
-           xf86Msg(X_WARNING, "%s: cannot set version\n", pInfo->name);
-           return FALSE;
-       }
-#endif
+       if (WSSetVersion(pInfo->fd, pInfo->name) == FALSE)
+	   return FALSE;
        /* Find out keyboard type */
        if (ioctl(pInfo->fd, WSKBDIO_GTYPE, &(pKbd->wsKbdType)) == -1) {
            xf86Msg(X_ERROR, "%s: cannot get keyboard type", pInfo->name);
-- 
1.8.3.3



More information about the xorg-devel mailing list