From 8e0b58f90d5c1e325a7f3a1417ffdc2729bb29d5 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Wed, 26 Aug 2020 22:57:27 +0000 Subject: terminal: Set K_RAW and term raw mode on FreeBSD Taken from X11, weston and consolekit2 ports for FreeBSD. Setting just K_CODE as done before makes input seemingly have no ill effects, but it is still buffered and possibly send to the terminal after application exit if stdin is never drained. Setting raw mode appears to be needed to solve that issue. A K_OFF-like VT keyboard setting like Linux has would seem more appropriate, but that is not currently available to us on FreeBSD. --- common/terminal.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'common') diff --git a/common/terminal.c b/common/terminal.c index da66143..126641d 100644 --- a/common/terminal.c +++ b/common/terminal.c @@ -17,9 +17,10 @@ #elif defined(__FreeBSD__) #include #include +#include #define TTYF "/dev/ttyv%d" #define K_ENABLE K_XLATE -#define K_DISABLE K_CODE +#define K_DISABLE K_RAW #define FRSIG SIGIO #else #error Unsupported platform @@ -111,6 +112,22 @@ int terminal_set_keyboard(int fd, bool enable) { log_errorf("could not set KD keyboard mode: %s", strerror(errno)); return -1; } +#if defined(__FreeBSD__) + struct termios tios; + if (tcgetattr(fd, &tios) == -1) { + log_errorf("could not set get terminal mode: %s", strerror(errno)); + return -1; + } + if (enable) { + cfmakesane(&tios); + } else { + cfmakeraw(&tios); + } + if (tcsetattr(fd, TCSAFLUSH, &tios) == -1) { + log_errorf("could not set terminal mode: %s", strerror(errno)); + return -1; + } +#endif return 0; } -- cgit v1.2.3