[PATCH:xf86-input-keyboard 18/21] Fix wskbd handling when VT switching.

walter harms wharms at bfs.de
Sat Jul 27 02:55:27 PDT 2013



Am 26.07.2013 23:24, schrieb Thomas Klausner:
> When using /dev/wskbd* we need to close the device when VT switching
> out of X, and open it again when switching back.
> 
> From Michael Lorenz <macallan at NetBSD.org>
> Signed-off-by: Thomas Klausner <wiz at NetBSD.org>
> ---
>  src/bsd_kbd.c   | 35 ++++++++++++++++++++++++++++++++++-
>  src/xf86OSKbd.h |  1 +
>  2 files changed, 35 insertions(+), 1 deletion(-)
> 
> diff --git a/src/bsd_kbd.c b/src/bsd_kbd.c
> index 70a3ff1..0615cf2 100644
> --- a/src/bsd_kbd.c
> +++ b/src/bsd_kbd.c
> @@ -204,6 +204,24 @@ KbdOn(InputInfoPtr pInfo, int what)
>  		 break;
>  #endif
>          }
> +    } else {
> +        switch (pKbd->consType) {
> +#ifdef WSCONS_SUPPORT
> +            case WSCONS:
> +            	 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);
> +				return FALSE;
> +			}
> +#endif

I remember this from a patch before.
IMHO you can impove readablity be using a function to set version.
like:

int set_version(pinfo,int version) {
if (ioctl(pInfo->fd, WSKBDIO_SETVERSION, &version) == -1) {
	xf86Msg(X_WARNING, "%s: cannot set version\n", pInfo->name);
	return -1; /* do we need to know ??? */
}
	return 0;
}


#ifdef WSKBDIO_SETVERSION
	if ( set_version(pinfo, WSKBDIO_EVENT_VERSION ) <0 ) return FALSE;
#endif

when  WSKBDIO_EVENT_VERSION is defined unconditionaly you let set_version() return 0,
and has reduced the #ifdef level by 1.

I would also think again about the open(). In case open fails
the user get an error like "cannot set version", sending him on the wrong path.
adding an xopen() like:

int xopen(char *name, int mode) {
int fd=open (name,mode);
if ( fd < 0 ) 	error("failed to open %s\n",name);	
return fd;
}
In this case you could even ignore the error from ioctl() because it is clear what the acutal
problem is.

just my 2 cents,
re,
 wh

> +		}
> +		break;
> +#endif
> +	}
>      }
>      return Success;
>  }
> @@ -238,7 +256,20 @@ KbdOff(InputInfoPtr pInfo, int what)
>  	         break;
>  #endif
>          }
> -    }
> +    } else {
> +         switch (pKbd->consType) {
> +#ifdef WSCONS_SUPPORT
> +            case WSCONS:
> +                 if ((pKbd->wsKbdDev[0] != 0) && (pInfo->fd != -1)) {
> +                 	xf86Msg(X_INFO, "closing %s\n", pKbd->wsKbdDev);
> +                 	/* need to close the fd while we're gone */
> +                 	close(pInfo->fd);
> +                 	pInfo->fd = -1;
> +                 }
> +	         break;
> +#endif
> +        }
> +    }   	
>      return Success;
>  }
>  
> @@ -368,6 +399,7 @@ OpenKeyboard(InputInfoPtr pInfo)
>  	pInfo->fd = xf86Info.consoleFd;
>  	pKbd->isConsole = TRUE;
>  	pKbd->consType = xf86Info.consType;
> +	pKbd->wsKbdDev[0] = 0;
>      } else {
>  	pInfo->fd = open(s, O_RDONLY | O_NONBLOCK | O_EXCL);
>  	if (pInfo->fd == -1) {
> @@ -376,6 +408,7 @@ OpenKeyboard(InputInfoPtr pInfo)
>             return FALSE;
>         }
>         pKbd->isConsole = FALSE;
> +       strncpy(pKbd->wsKbdDev, s, 256);
>         pKbd->consType = xf86Info.consType;
>         free(s);
>      }
> diff --git a/src/xf86OSKbd.h b/src/xf86OSKbd.h
> index 0d8792d..86df0f5 100644
> --- a/src/xf86OSKbd.h
> +++ b/src/xf86OSKbd.h
> @@ -82,6 +82,7 @@ typedef struct {
>      pointer		private;
>      int			consType;
>      int			wsKbdType;
> +    char		wsKbdDev[256];
>  
>  } KbdDevRec, *KbdDevPtr;
>  


More information about the xorg-devel mailing list