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.
This commit is contained in:
Kenny Levinsen 2020-08-26 22:57:27 +00:00
parent 4ae4793b25
commit 8e0b58f90d

View file

@ -17,9 +17,10 @@
#elif defined(__FreeBSD__)
#include <sys/consio.h>
#include <sys/kbio.h>
#include <termios.h>
#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;
}