From: Erik van der Kouwe Date: Thu, 15 Apr 2010 06:55:42 +0000 (+0000) Subject: Add scancode reading capability to TTY X-Git-Tag: v3.1.7~140 X-Git-Url: http://zhaoyanbai.com/repos/dnssec-signzone.html?a=commitdiff_plain;h=7de730afe4104cbd9f55127f6f98a50cbfc9d75e;p=minix.git Add scancode reading capability to TTY --- diff --git a/drivers/tty/keyboard.c b/drivers/tty/keyboard.c index 9b9e77f90..cf58c628c 100644 --- a/drivers/tty/keyboard.c +++ b/drivers/tty/keyboard.c @@ -591,14 +591,14 @@ int try; if (ch <= 0xFF) { /* A normal character. */ buf[0] = ch; - (void) in_process(tp, buf, 1); + (void) in_process(tp, buf, 1, scode); } else if (HOME <= ch && ch <= INSRT) { /* An ASCII escape sequence generated by the numeric pad. */ buf[0] = ESC; buf[1] = '['; buf[2] = numpad_map[ch - HOME]; - (void) in_process(tp, buf, 3); + (void) in_process(tp, buf, 3, scode); } else if ((F1 <= ch && ch <= F12) || (SF1 <= ch && ch <= SF12) || (CF1 <= ch && ch <= CF12 && !debug_fkeys)) { @@ -626,7 +626,7 @@ int try; *p++ = suffix; } *p++ = '~'; - (void) in_process(tp, buf, p - buf); + (void) in_process(tp, buf, p - buf, scode); } else if (ch == ALEFT) { /* Choose lower numbered console as current console. */ @@ -651,6 +651,9 @@ int try; case CF8: sigchar(&tty_table[CONSOLE], SIGINT, 1); break; case CF9: sigchar(&tty_table[CONSOLE], SIGKILL, 1); break; } + } else { + /* pass on scancode even though there is no character code */ + (void) in_process(tp, NULL, 0, scode); } } diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 025c27245..ee162f122 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -417,7 +417,7 @@ PRIVATE int pty_read(tty_t *tp, int try) } /* Input processing. */ - if (in_process(tp, &c, 1) == 0) break; + if (in_process(tp, &c, 1, -1) == 0) break; /* PTY writer bookkeeping. */ pp->wrcum++; diff --git a/drivers/tty/rs232.c b/drivers/tty/rs232.c index f6fc7332e..482024296 100644 --- a/drivers/tty/rs232.c +++ b/drivers/tty/rs232.c @@ -619,7 +619,7 @@ PRIVATE int rs_read(tty_t *tp, int try) if (count > icount) count = icount; /* Perform input processing on (part of) the input buffer. */ - if ((count = in_process(tp, rs->itail, count)) == 0) break; + if ((count = in_process(tp, rs->itail, count, -1)) == 0) break; lock(); /* protect interrupt sensitive variables */ rs->icount -= count; diff --git a/drivers/tty/tty.c b/drivers/tty/tty.c index 826803b48..78e595b51 100644 --- a/drivers/tty/tty.c +++ b/drivers/tty/tty.c @@ -1036,10 +1036,26 @@ register tty_t *tp; /* pointer to terminal to read from */ /*===========================================================================* * in_process * *===========================================================================*/ -PUBLIC int in_process(tp, buf, count) +PRIVATE void in_process_send_byte(tp, ch) +tty_t *tp; /* terminal on which character has arrived */ +int ch; /* input character */ +{ + /* Save the character in the input queue. */ + *tp->tty_inhead++ = ch; + if (tp->tty_inhead == bufend(tp->tty_inbuf)) + tp->tty_inhead = tp->tty_inbuf; + tp->tty_incount++; + if (ch & IN_EOT) tp->tty_eotct++; + + /* Try to finish input if the queue threatens to overflow. */ + if (tp->tty_incount == buflen(tp->tty_inbuf)) in_transfer(tp); +} + +PUBLIC int in_process(tp, buf, count, scode) register tty_t *tp; /* terminal on which character has arrived */ char *buf; /* buffer with input characters */ int count; /* number of input characters */ +int scode; /* scan code */ { /* Characters have just been typed in. Process, save, and echo them. Return * the number of characters processed. @@ -1048,6 +1064,11 @@ int count; /* number of input characters */ int ch, sig, ct; int timeset = FALSE; + /* Send scancode if requested */ + if (tp->tty_termios.c_iflag & SCANCODES) { + in_process_send_byte(tp, (scode & BYTE) | IN_EOT); + } + for (ct = 0; ct < count; ct++) { /* Take one character. */ ch = *buf++ & BYTE; @@ -1180,15 +1201,10 @@ int count; /* number of input characters */ /* Perform the intricate function of echoing. */ if (tp->tty_termios.c_lflag & (ECHO|ECHONL)) ch = tty_echo(tp, ch); - /* Save the character in the input queue. */ - *tp->tty_inhead++ = ch; - if (tp->tty_inhead == bufend(tp->tty_inbuf)) - tp->tty_inhead = tp->tty_inbuf; - tp->tty_incount++; - if (ch & IN_EOT) tp->tty_eotct++; - - /* Try to finish input if the queue threatens to overflow. */ - if (tp->tty_incount == buflen(tp->tty_inbuf)) in_transfer(tp); + /* Send processed byte of input unless scancodes sent instead */ + if (!(tp->tty_termios.c_iflag & SCANCODES)) { + in_process_send_byte(tp, ch); + } } return ct; } @@ -1502,6 +1518,9 @@ tty_t *tp; /* Setting the output speed to zero hangs up the phone. */ if (tp->tty_termios.c_ospeed == B0) sigchar(tp, SIGHUP, 1); + /* SCANCODES is supported only for the console */ + if (!isconsole(tp)) tp->tty_termios.c_iflag &= ~SCANCODES; + /* Set new line speed, character size, etc at the device level. */ (*tp->tty_ioctl)(tp, 0); } diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h index 71d0bd410..c77d03a09 100644 --- a/drivers/tty/tty.h +++ b/drivers/tty/tty.h @@ -147,7 +147,8 @@ extern struct kmessages kmess; _PROTOTYPE( void handle_events, (struct tty *tp) ); _PROTOTYPE( void sigchar, (struct tty *tp, int sig, int mayflush) ); _PROTOTYPE( void tty_task, (void) ); -_PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count) ); +_PROTOTYPE( int in_process, (struct tty *tp, char *buf, int count, + int scode) ); _PROTOTYPE( void out_process, (struct tty *tp, char *bstart, char *bpos, char *bend, int *icount, int *ocount) ); _PROTOTYPE( void tty_wakeup, (clock_t now) ); diff --git a/include/termios.h b/include/termios.h index ee9b7b8ed..5bd1da0c5 100644 --- a/include/termios.h +++ b/include/termios.h @@ -146,6 +146,7 @@ _PROTOTYPE( int tcsetattr, \ /* Extensions to the termios c_iflag bit map. */ #define IXANY 0x0800 /* allow any key to continue ouptut */ +#define SCANCODES 0x1000 /* send scancodes */ /* Extensions to the termios c_oflag bit map. They are only active iff * OPOST is enabled. */ diff --git a/man/man4/tty.4 b/man/man4/tty.4 index e7bc28767..6eb77001f 100644 --- a/man/man4/tty.4 +++ b/man/man4/tty.4 @@ -315,6 +315,30 @@ is set a break is input as a single '\e0', or if .B PARMRK is set as '\e377', '\e0', '\e0'. (Breaks are always ignored.) +.TP +.B SCANCODES +Send input as keyboard scancodes rather than processed ASCII characters. This +flag only applies to consoles; to check whether the flag is supported use the +.B tcgetattr +function after setting it and test whether +.B c_iflag +still contains the +.B SCANCODES +flag. Scancodes are provided directly and without any processing. As a +consequence, the +.B ISTRIP +, +.B IGNCR +, +.B ICRNL +, +.B INLCR +, +.B ICANON +and +.B IEXTEN +flags no longer influence input if this flag is specified. However, they may +still influence echoing if enabled. (MINIX 3 specific.) .SS "Output Modes" The .B c_oflag