summaryrefslogtreecommitdiff
path: root/tests/testdisplay.c
diff options
context:
space:
mode:
authorJesse Barnes <jbarnes@virtuousgeek.org>2014-03-26 11:02:48 -0700
committerJesse Barnes <jbarnes@virtuousgeek.org>2014-03-26 11:13:23 -0700
commit7255a84c9c8f4d46b47d490331100a11179180a1 (patch)
treede245b37e1b77b7f9293bad8701c7f4e213d6068 /tests/testdisplay.c
parent3d9e63f2ad0c676b3efba4c854ef645ae60ee7e1 (diff)
testdisplay: make termio unbuffered
So hotkeys take effect immediately.
Diffstat (limited to 'tests/testdisplay.c')
-rw-r--r--tests/testdisplay.c33
1 files changed, 32 insertions, 1 deletions
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 <stdbool.h>
#include <strings.h>
#include <unistd.h>
+#include <termios.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <sys/ioctl.h>
@@ -70,6 +71,8 @@
#include <stdlib.h>
#include <signal.h>
+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;
}