2020-12-07 22:12:27 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
term: use no-op SIGWINCH handler to trigger redraw
diff --git a/seqt.c b/seqt.c index 8b4da05..9a75de7 100644 --- a/seqt.c +++ b/seqt.c @@ -6,7 +6,6 @@ int ntracks; char map[MAPSIZE][RECSIZE]; unsigned char matrix[MAXINDEX][MAXTRACK][MAXVOICE]; -struct winsize term_size; void print_blank() @@ -102,6 +101,7 @@ main(int argc, char *argv[]) FILE *fin; char *fname; struct termios term_prev; + struct winsize term_size; int running; char key; if (argc < 2) { @@ -115,11 +115,12 @@ main(int argc, char *argv[]) return 1; } fclose(fin); - setup_terminal(&term_prev, &term_size); - /* printf("%hux%hu\n", term_size.ws_col, term_size.ws_row); */ + setup_terminal(&term_prev); print_tracks(0, 10, 0, 3); running = 1; while (running) { + get_terminal_size(&term_size); + printf("%hux%hu \r", term_size.ws_col, term_size.ws_row); key = getchar(); switch (key) { case 'q': diff --git a/seqt.h b/seqt.h index 81a5f21..21d21e8 100644 --- a/seqt.h +++ b/seqt.h @@ -58,8 +58,8 @@ int save_txt(FILE *fp); /* ============================ terminal =======]==================== */ -extern struct winsize term_size; -void setup_terminal(struct termios *term_prev, struct winsize *term_size); +#define get_terminal_size(WS) ioctl(0, TIOCGWINSZ, (WS)) +void setup_terminal(struct termios *term_prev); void restore_terminal(struct termios *term_prev); /* ====================[=====+===== =====+=====]==================== */ diff --git a/term.c b/term.c index f3281c0..ab01eee 100644 --- a/term.c +++ b/term.c @@ -3,23 +3,18 @@ #include <string.h> #include <signal.h> -#define get_terminal_size(TS) ioctl(0, TIOCGWINSZ, (TS)) - #ifndef SIGWINCH #define SIGWINCH 28 #endif -volatile sig_atomic_t pending_winch; - -void -handle_winch(int sig) -{ - (void) sig; - pending_winch = 1; -} +/* When a UNIX terminal is resized, it sends a SIGWINCH signal to clients. + * Normally, seqt's mainloop remains blocked on user input upon SIGWINCH. + * Setting up any signal handler seems to send EOF to stdin upon SIGWINCH. + * This allows seqt to redraw the screen immediately. */ +void handle_winch(int sig) { (void) sig; } void -setup_terminal(struct termios *term_prev, struct winsize *term_size) +setup_terminal(struct termios *term_prev) { struct termios term_raw; struct sigaction sa; @@ -38,8 +33,6 @@ setup_terminal(struct termios *term_prev, struct winsize *term_size) term_raw.c_cc[VMIN] = 1; term_raw.c_cc[VTIME] = 0; tcsetattr(0, TCSAFLUSH, &term_raw); - /* get terminal size */ - get_terminal_size(term_size); } void