aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--drmtest.c46
-rw-r--r--meson.build2
-rw-r--r--ttytools.c53
-rw-r--r--ttytools.h3
5 files changed, 59 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index e92df18..c1b7ca6 100644
--- a/Makefile
+++ b/Makefile
@@ -44,7 +44,7 @@ clean:
rm -f *~ *.o
drminfo: drminfo.o drmtools.o
-drmtest: drmtest.o drmtools.o render.o image.o
+drmtest: drmtest.o drmtools.o ttytools.o render.o image.o
gtktest: gtktest.o render.o image.o
endif
diff --git a/drmtest.c b/drmtest.c
index 762ea52..5efb796 100644
--- a/drmtest.c
+++ b/drmtest.c
@@ -2,17 +2,13 @@
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
-#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <inttypes.h>
#include <getopt.h>
-#include <time.h>
-#include <termios.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
-#include <sys/time.h>
#include <libdrm/drm_fourcc.h>
#include <xf86drm.h>
@@ -25,6 +21,7 @@
#include <cairo.h>
#include <pixman.h>
+#include "ttytools.h"
#include "drmtools.h"
#include "render.h"
#include "image.h"
@@ -149,47 +146,6 @@ static void drm_draw_dumb_fb(void)
/* ------------------------------------------------------------------ */
-struct termios saved_attributes;
-int saved_fl;
-
-void tty_raw(void)
-{
- struct termios tattr;
-
- fcntl(STDIN_FILENO, F_GETFL, &saved_fl);
- tcgetattr (0, &saved_attributes);
-
- fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
- memcpy(&tattr,&saved_attributes,sizeof(struct termios));
- tattr.c_lflag &= ~(ICANON|ECHO);
- tattr.c_cc[VMIN] = 1;
- tattr.c_cc[VTIME] = 0;
- tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr);
-}
-
-void tty_restore(void)
-{
- fcntl(STDIN_FILENO, F_SETFL, saved_fl);
- tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
-}
-
-int kbd_wait(int timeout)
-{
- struct timeval limit;
- fd_set set;
- int rc;
-
- FD_ZERO(&set);
- FD_SET(STDIN_FILENO, &set);
- limit.tv_sec = timeout;
- limit.tv_usec = 0;
- rc = select(STDIN_FILENO + 1, &set, NULL, NULL,
- timeout ? &limit : NULL);
- return rc;
-}
-
-/* ------------------------------------------------------------------ */
-
static void usage(FILE *fp)
{
fprintf(fp,
diff --git a/meson.build b/meson.build
index cd7e728..6d6b208 100644
--- a/meson.build
+++ b/meson.build
@@ -12,7 +12,7 @@ gtk3_dep = dependency('gtk+-3.0')
jpeg_dep = declare_dependency(link_args : '-ljpeg')
drminfo_srcs = [ 'drminfo.c', 'drmtools.c' ]
-drmtest_srcs = [ 'drmtest.c', 'drmtools.c', 'render.c', 'image.c' ]
+drmtest_srcs = [ 'drmtest.c', 'drmtools.c', 'ttytools.c', 'render.c', 'image.c' ]
gtktest_srcs = [ 'gtktest.c', 'render.c', 'image.c' ]
drminfo_deps = [ libdrm_dep, cairo_dep, pixman_dep ]
diff --git a/ttytools.c b/ttytools.c
new file mode 100644
index 0000000..95289a2
--- /dev/null
+++ b/ttytools.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <inttypes.h>
+#include <fcntl.h>
+#include <time.h>
+#include <termios.h>
+
+#include <sys/time.h>
+
+#include "ttytools.h"
+
+static struct termios saved_attributes;
+static int saved_fl;
+
+void tty_raw(void)
+{
+ struct termios tattr;
+
+ fcntl(STDIN_FILENO, F_GETFL, &saved_fl);
+ tcgetattr (0, &saved_attributes);
+
+ fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
+ memcpy(&tattr,&saved_attributes,sizeof(struct termios));
+ tattr.c_lflag &= ~(ICANON|ECHO);
+ tattr.c_cc[VMIN] = 1;
+ tattr.c_cc[VTIME] = 0;
+ tcsetattr(STDIN_FILENO, TCSAFLUSH, &tattr);
+}
+
+void tty_restore(void)
+{
+ fcntl(STDIN_FILENO, F_SETFL, saved_fl);
+ tcsetattr(STDIN_FILENO, TCSANOW, &saved_attributes);
+}
+
+int kbd_wait(int timeout)
+{
+ struct timeval limit;
+ fd_set set;
+ int rc;
+
+ FD_ZERO(&set);
+ FD_SET(STDIN_FILENO, &set);
+ limit.tv_sec = timeout;
+ limit.tv_usec = 0;
+ rc = select(STDIN_FILENO + 1, &set, NULL, NULL,
+ timeout ? &limit : NULL);
+ return rc;
+}
diff --git a/ttytools.h b/ttytools.h
new file mode 100644
index 0000000..391fa08
--- /dev/null
+++ b/ttytools.h
@@ -0,0 +1,3 @@
+void tty_raw(void);
+void tty_restore(void);
+int kbd_wait(int timeout);