From 7255a84c9c8f4d46b47d490331100a11179180a1 Mon Sep 17 00:00:00 2001 From: Jesse Barnes Date: Wed, 26 Mar 2014 11:02:48 -0700 Subject: testdisplay: make termio unbuffered So hotkeys take effect immediately. --- tests/testdisplay.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'tests/testdisplay.c') diff --git a/tests/testdisplay.c b/tests/testdisplay.c index 2b0233ea..d807f905 100644 --- a/tests/testdisplay.c +++ b/tests/testdisplay.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -70,6 +71,8 @@ #include #include +struct termios saved_tio; + drmModeRes *resources; int drm_fd, modes; int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane, @@ -720,6 +723,15 @@ static void __attribute__((noreturn)) usage(char *name) #define dump_resource(res) if (res) dump_##res() +static void cleanup_and_exit(int ret) +{ + close(drm_fd); + + tcsetattr(STDIN_FILENO, TCSANOW, &saved_tio); + + exit(ret); +} + static gboolean input_event(GIOChannel *source, GIOCondition condition, gpointer data) { @@ -728,7 +740,7 @@ static gboolean input_event(GIOChannel *source, GIOCondition condition, count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf)); if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) { - exit(0); + cleanup_and_exit(0); } return TRUE; @@ -754,6 +766,21 @@ static void enter_exec_path( char **argv ) free(exec_path); } +static void set_termio_mode(void) +{ + struct termios tio; + + tcgetattr(STDIN_FILENO, &saved_tio); + + tio = saved_tio; + + tio.c_lflag &= ~(ICANON | ECHO); + + tcsetattr(STDIN_FILENO, TCSANOW, &tio); + + return; +} + int main(int argc, char **argv) { int c; @@ -826,6 +853,8 @@ int main(int argc, char **argv) } } + set_termio_mode(); + if (depth <= 8) bpp = 8; else if (depth <= 16) @@ -898,5 +927,7 @@ out_mainloop: out_close: close(drm_fd); + tcsetattr(STDIN_FILENO, TCSANOW, &saved_tio); + return ret; } -- cgit v1.2.3