From 65bc2cee989ecfc722cf4419f6aa52965011e305 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 18 Oct 2009 00:17:50 +0000 Subject: [PATCH] Handle screen size changes. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@471 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- dgamelaunch.c | 28 ++++++++++++++++++---------- dgamelaunch.h | 6 ++++++ dgl-common.c | 23 +++++++++++++++++++++++ mygetnstr.c | 2 +- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/dgamelaunch.c b/dgamelaunch.c index 2cb8b34..b5c443b 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -379,6 +379,7 @@ inprogressmenu (int gameid) int is_nhext[14]; sigset_t oldmask, toblock; int idx = -1; + int max_height = -1; if (sortmode == NUM_SORTMODES) sortmode = globalconfig.sortmode; @@ -388,12 +389,16 @@ inprogressmenu (int gameid) while (1) { + term_resize_check(); + max_height = local_LINES - 10; + if (max_height < 2) return; + if (len == 0) offset = 0; else { - while (offset >= len && offset >= 14) - offset -= 14; + while (offset >= len && offset >= max_height) + offset -= max_height; } erase (); @@ -408,7 +413,7 @@ inprogressmenu (int gameid) /* clean old games and list good ones */ i = 0; - for (i = 0; i < 14; i++) + for (i = 0; i < max_height; i++) { if (i + offset >= len) break; @@ -428,12 +433,13 @@ inprogressmenu (int gameid) (time (&ctime) - games[i + offset]->idle_time) % 60); } - mvprintw (22, 1, "'s' and 'S' change sort mode (current: %s)", SORTMODE_NAME[sortmode]); + mvprintw ((local_LINES-2), 1, "'s' and 'S' change sort mode (current: %s)", SORTMODE_NAME[sortmode]); if (len > 0) - mvprintw (21, 1, "(%d-%d of %d)", offset + 1, offset + i, len); - mvaddstr (23, 1, + mvprintw ((local_LINES-3), 1, "(%d-%d of %d)", offset + 1, offset + i, len); + mvaddstr ((local_LINES-1), 1, "Watch which game? (any key refreshes, 'q' quits, '>'/'<' for more/less) => "); + refresh (); switch ((menuchoice = getch ())) @@ -458,17 +464,17 @@ inprogressmenu (int gameid) } break; case '>': - if ((offset + 14) >= len) + if ((offset + max_height) >= len) break; else - offset += 14; + offset += max_height; break; case '<': - if ((offset - 14) < 0) + if ((offset - max_height) < 0) break; else - offset -= 14; + offset -= max_height; break; case ERR: @@ -1968,6 +1974,7 @@ main (int argc, char** argv) /* signal handlers */ signal (SIGHUP, catch_sighup); + signal(SIGWINCH, sigwinch_func); (void) tcgetattr (0, &tt); if (-1 == ioctl (0, TIOCGWINSZ, (char *) &win) || win.ws_row < 4 || @@ -2081,6 +2088,7 @@ main (int argc, char** argv) } initcurses (); + term_resize_check(); while (1) { if (runmenuloop(dgl_find_menu(loggedin ? "mainmenu_user" : "mainmenu_anon"))) diff --git a/dgamelaunch.h b/dgamelaunch.h index 7872fc9..290634c 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -174,6 +174,9 @@ extern int num_games; extern mode_t default_fmode; +extern int local_COLS; +extern int local_LINES; + /* dgamelaunch.c */ extern void create_config(void); extern void ttyrec_getmaster(void); @@ -185,6 +188,9 @@ extern void drawbanner(struct dg_banner *ban, unsigned int start_line, unsigned extern int check_retard(int reset); extern char *dgl_format_str(int game, struct dg_user *me, char *str, char *plrname); +extern void term_resize_check(); +extern void sigwinch_func(int sig); + extern struct dg_menu *dgl_find_menu(char *menuname); extern int dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me); diff --git a/dgl-common.c b/dgl-common.c index b4aca6d..85614a6 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -54,6 +54,9 @@ int loggedin = 0; char *chosen_name; int num_games = 0; +int local_COLS = -1, local_LINES = -1; +int curses_resize = 0; + int selected_game = 0; int return_from_submenu = 0; @@ -61,6 +64,26 @@ mode_t default_fmode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH struct dg_globalconfig globalconfig; +void +sigwinch_func(int sig) +{ + signal(SIGWINCH, sigwinch_func); + curses_resize = 1; + term_resize_check(); +} + +void +term_resize_check() +{ + if ((COLS == local_COLS) && (LINES == local_LINES) && !curses_resize) return; + + endwin(); + initcurses(); + refresh(); + local_COLS = COLS; + local_LINES = LINES; + curses_resize = 0; +} int check_retard(int reset) diff --git a/mygetnstr.c b/mygetnstr.c index 61b820a..38e479a 100644 --- a/mygetnstr.c +++ b/mygetnstr.c @@ -93,7 +93,7 @@ mygetnstr(char *buf, int maxlen, int doecho) else beep(); } - else if (c == 10 || c == 13 || c == KEY_ENTER) + else if (c == 10 || c == 13 || c == KEY_ENTER || c == KEY_RESIZE) break; else if (c == ERR) {