diff options
author | Maksim Yevmenkin <emax@FreeBSD.org> | 2005-07-14 22:43:20 +0000 |
---|---|---|
committer | Maksim Yevmenkin <emax@FreeBSD.org> | 2005-07-14 22:43:20 +0000 |
commit | 4673ea01e3d85d63317d3c7322b2fed979efa114 (patch) | |
tree | af08529cd4d19775f2d0bfdaea819dcfeb31f2c0 /usr.sbin/kbdcontrol | |
parent | 2e37c5a333bd995157935bdd3160558ca01c1959 (diff) | |
download | src-4673ea01e3d85d63317d3c7322b2fed979efa114.tar.gz src-4673ea01e3d85d63317d3c7322b2fed979efa114.zip |
kbdmux(4) keyboard multiplexer integration
o Slightly change KBADDKBD and KBRELKBD ioctl() interface. Instead of passing
keyboard index pass keyboard_info_t structure with populated 'kb_unit' and
'kb_name' fields. Keyboard index is not very user-friendly and is not very
easy to obtain. Keyboard driver name and unit, on the other hand, is much
more user friendly and known almost all the time;
o Move definition of keyboard_info_t structure up;
o Teach kbdcontrol(1) how to attach/detach keyboards to/from the keyboard
multiplexor;
o Update kbdcontrol(1) man page and document new functionality.
To attach/detach keyboard to/from keyboard multiplexor one needs to use
keyboard device name (i.e. ukbd0).
MFC after: 1 week
Notes
Notes:
svn path=/head/; revision=148017
Diffstat (limited to 'usr.sbin/kbdcontrol')
-rw-r--r-- | usr.sbin/kbdcontrol/kbdcontrol.1 | 22 | ||||
-rw-r--r-- | usr.sbin/kbdcontrol/kbdcontrol.c | 72 |
2 files changed, 92 insertions, 2 deletions
diff --git a/usr.sbin/kbdcontrol/kbdcontrol.1 b/usr.sbin/kbdcontrol/kbdcontrol.1 index 99ef3be91f3b..bae118d8dfed 100644 --- a/usr.sbin/kbdcontrol/kbdcontrol.1 +++ b/usr.sbin/kbdcontrol/kbdcontrol.1 @@ -22,6 +22,8 @@ .Sh SYNOPSIS .Nm .Op Fl dFKix +.Op Fl A Ar name +.Op Fl a Ar name .Oo .Fl b .Ar duration . Ns Ar pitch | Ar belltype @@ -52,6 +54,26 @@ below. .Pp The following command line options are supported: .Bl -tag -width indent +.It Fl A Ar name +Detach the keyboard, specified by the keyboard device name, from the keyboard +multiplexer. +When using this option, the standard input of the +.Nm +process should be redirected from the keyboard multilpexor keyboard device +(if keyboard multiplexor is not active keyboard) or +.Pa /dev/console +(if keyboard multiplexor is active keyboard and +you are not working on the system console). +.It Fl a Ar name +Attach the keyboard, specified by the keyboard device name, to the keyboard +multiplexer. +When using this option, the standard input of the +.Nm +process should be redirected from the keyboard multilpexor keyboard device +(if keyboard multiplexor is not active keyboard) or +.Pa /dev/console +(if keyboard multiplexor is active keyboard and +you are not working on the system console). .It Fl b Xo .Ar duration . Ns Ar pitch | Ar belltype .Xc diff --git a/usr.sbin/kbdcontrol/kbdcontrol.c b/usr.sbin/kbdcontrol/kbdcontrol.c index eb72b825b835..7607ff472d77 100644 --- a/usr.sbin/kbdcontrol/kbdcontrol.c +++ b/usr.sbin/kbdcontrol/kbdcontrol.c @@ -130,6 +130,7 @@ void print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key); void print_keymap(void); void release_keyboard(void); +void mux_keyboard(int op, char *kbd); void set_bell_values(char *opt); void set_functionkey(char *keynumstr, char *string); void set_keyboard(char *device); @@ -1080,12 +1081,75 @@ release_keyboard(void) warn("unable to release the keyboard"); } +void +mux_keyboard(int op, char *kbd) +{ + keyboard_info_t info; + char *unit, *ep; + + /* + * If stdin is not associated with a keyboard, the following ioctl + * will fail. + */ + if (ioctl(0, KDGKBINFO, &info) == -1) { + warn("unable to obtain keyboard information"); + return; + } +#if 1 + printf("kbd%d\n", info.kb_index); + printf(" %.*s%d, type:%s (%d)\n", + (int)sizeof(info.kb_name), info.kb_name, info.kb_unit, + get_kbd_type_name(info.kb_type), info.kb_type); +#endif + /* + * split kbd into name and unit. find the right most part of the + * kbd string that consist of only digits. + */ + + memset(&info, 0, sizeof(info)); + + info.kb_unit = -1; + ep = kbd - 1; + + do { + unit = strpbrk(ep + 1, "0123456789"); + if (unit != NULL) { + info.kb_unit = strtol(unit, &ep, 10); + if (*ep != '\0') + info.kb_unit = -1; + } + } while (unit != NULL && info.kb_unit == -1); + + if (info.kb_unit == -1) { + warnx("unable to find keyboard driver unit in '%s'", kbd); + return; + } + + if (unit == kbd) { + warnx("unable to find keyboard driver name in '%s'", kbd); + return; + } + if (unit - kbd >= (int) sizeof(info.kb_name)) { + warnx("keyboard name '%s' is too long", kbd); + return; + } + + strncpy(info.kb_name, kbd, unit - kbd); + + /* + * If stdin is not associated with a kbdmux(4) keyboard, the following + * ioctl will fail. + */ + + if (ioctl(0, op, &info) == -1) + warn("unable to (un)mux the keyboard"); +} void usage() { fprintf(stderr, "%s\n%s\n%s\n", -"usage: kbdcontrol [-dFKix] [-b duration.pitch | [quiet.]belltype]", +"usage: kbdcontrol [-dFKix] [-A name] [-a name] [-b duration.pitch | [quiet.]belltype]", " [-r delay.repeat | speed] [-l mapfile] [-f # string]", " [-k device] [-L mapfile]"); exit(1); @@ -1097,8 +1161,12 @@ main(int argc, char **argv) { int opt; - while((opt = getopt(argc, argv, "b:df:iKk:Fl:L:r:x")) != -1) + while((opt = getopt(argc, argv, "A:a:b:df:iKk:Fl:L:r:x")) != -1) switch(opt) { + case 'A': + case 'a': + mux_keyboard((opt == 'A')? KBRELKBD : KBADDKBD, optarg); + break; case 'b': set_bell_values(optarg); break; |