summaryrefslogtreecommitdiffstats
path: root/usr.sbin/kbdcontrol/kbdcontrol.c
diff options
context:
space:
mode:
authoremax <emax@FreeBSD.org>2005-07-14 22:43:20 +0000
committeremax <emax@FreeBSD.org>2005-07-14 22:43:20 +0000
commitd2de93780cda13f880d4a89bafd3fb9440420da5 (patch)
treeaf08529cd4d19775f2d0bfdaea819dcfeb31f2c0 /usr.sbin/kbdcontrol/kbdcontrol.c
parentc224d596cf8de5c957244e362536d42d21579fa4 (diff)
downloadFreeBSD-src-d2de93780cda13f880d4a89bafd3fb9440420da5.zip
FreeBSD-src-d2de93780cda13f880d4a89bafd3fb9440420da5.tar.gz
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
Diffstat (limited to 'usr.sbin/kbdcontrol/kbdcontrol.c')
-rw-r--r--usr.sbin/kbdcontrol/kbdcontrol.c72
1 files changed, 70 insertions, 2 deletions
diff --git a/usr.sbin/kbdcontrol/kbdcontrol.c b/usr.sbin/kbdcontrol/kbdcontrol.c
index eb72b82..7607ff4 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;
OpenPOWER on IntegriCloud