aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKenny Levinsen <kl@kl.wtf>2020-08-26 22:57:27 +0000
committerKenny Levinsen <kl@kl.wtf>2020-08-28 02:54:14 +0200
commit8e0b58f90d5c1e325a7f3a1417ffdc2729bb29d5 (patch)
tree1bd028a7ed04a679c763b9af16f8bbe3780e6a4a /common
parent4ae4793b25c9b1292e76e1a938326c50c6793cfa (diff)
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.
Diffstat (limited to 'common')
-rw-r--r--common/terminal.c19
1 files changed, 18 insertions, 1 deletions
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 <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;
}