diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-12 17:36:01 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2017-04-12 17:36:01 +0200 |
commit | 6dc1ae8f9bee176d953274d7501eaf898746f6c0 (patch) | |
tree | b5d5a698ca99e8407b1ab8f880b74531b972e2d3 /drmtest.c | |
parent | 7d6d9ad36c811873c55e1d87c02f307ad63994e7 (diff) | |
download | drminfo-6dc1ae8f9bee176d953274d7501eaf898746f6c0.tar.gz |
exit on key press
Diffstat (limited to 'drmtest.c')
-rw-r--r-- | drmtest.c | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -7,9 +7,12 @@ #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 <xf86drm.h> #include <xf86drmMode.h> @@ -346,6 +349,47 @@ static void drm_make_egl_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, @@ -367,7 +411,7 @@ static void usage(FILE *fp) int main(int argc, char **argv) { int card = 0; - int secs = 3; + int secs = 60; bool gl = false; char *output = NULL; int c; @@ -415,7 +459,11 @@ int main(int argc, char **argv) drm_draw_dumb_fb(); } drm_show_fb(); - sleep(secs); + + tty_raw(); + kbd_wait(secs); + tty_restore(); + drm_fini_dev(); return 0; } |