From: Kalle Wallin Date: Wed, 21 Apr 2004 19:06:18 +0000 (+0000) Subject: Fixed resize handling (SIGWINCH). X-Git-Tag: v0.12_alpha1~566 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b1f77e2684e85fac5ef5d50fc1342d7d53e5a492;p=ncmpc.git Fixed resize handling (SIGWINCH). git-svn-id: https://svn.musicpd.org/ncmpc/trunk@871 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- diff --git a/command.c b/command.c index 2ad85d0..2a426e3 100644 --- a/command.c +++ b/command.c @@ -328,6 +328,9 @@ get_keyboard_command(void) key = wgetch(stdscr); + if( key==KEY_RESIZE ) + screen_resize(); + if( key==ERR ) return CMD_NONE; diff --git a/main.c b/main.c index 21fd5ac..1d45884 100644 --- a/main.c +++ b/main.c @@ -102,15 +102,6 @@ main(int argc, const char *argv[]) perror("signal"); exit(EXIT_FAILURE); } - /* setup signal behavior - SIGWINCH */ - sigemptyset( &act.sa_mask ); - act.sa_flags = 0; - act.sa_handler = screen_resized; - if( sigaction( SIGWINCH, &act, NULL )<0 ) - { - perror("sigaction()"); - exit(EXIT_FAILURE); - } /* setup signal behavior - SIGTERM */ sigemptyset( &act.sa_mask ); act.sa_flags = 0; diff --git a/screen.c b/screen.c index ccf7c8c..5314621 100644 --- a/screen.c +++ b/screen.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -318,15 +319,64 @@ screen_exit(void) } void -screen_resized(int sig) +screen_resize(void) { - screen_exit(); + GList *list; + +#ifdef DEBUG + fprintf(stderr, "Resize rows %d->%d, cols %d->%d\n", + screen->rows, LINES, + screen->cols, COLS); +#endif + if( COLScols = COLS; + screen->rows = LINES; + + /* top window */ + screen->top_window.cols = screen->cols; + wresize(screen->top_window.w, 2, screen->cols); + + /* main window */ + screen->main_window.cols = screen->cols; + screen->main_window.rows = screen->rows-4; + wresize(screen->main_window.w, screen->main_window.rows, screen->cols); + wclear(screen->main_window.w); + + /* progress window */ + screen->progress_window.cols = screen->cols; + wresize(screen->progress_window.w, 1, screen->cols); + mvwin(screen->progress_window.w, screen->rows-2, 0); + + /* status window */ + screen->status_window.cols = screen->cols; + wresize(screen->status_window.w, 1, screen->cols); + mvwin(screen->status_window.w, screen->rows-1, 0); + + screen->buf_size = screen->cols; + g_free(screen->buf); + screen->buf = g_malloc(screen->cols); + + list = g_list_first(screen->screen_list); + while( list ) + { + screen_functions_t *mode_fn = list->data; + + if( mode_fn && mode_fn->resize ) + mode_fn->resize(screen->main_window.cols, screen->main_window.rows); + + list=list->next; + } + + screen->painted = 0; } void diff --git a/screen.h b/screen.h index d770aba..a952693 100644 --- a/screen.h +++ b/screen.h @@ -84,6 +84,7 @@ typedef void (*screen_init_fn_t) (WINDOW *w, int cols, int rows); typedef void (*screen_exit_fn_t) (void); typedef void (*screen_open_fn_t) (screen_t *screen, mpd_client_t *c); typedef void (*screen_close_fn_t) (void); +typedef void (*screen_resize_fn_t) (int cols, int rows); typedef void (*screen_paint_fn_t) (screen_t *screen, mpd_client_t *c); typedef void (*screen_update_fn_t) (screen_t *screen, mpd_client_t *c); typedef int (*screen_cmd_fn_t) (screen_t *scr, mpd_client_t *c, command_t cmd); @@ -96,6 +97,7 @@ typedef struct screen_exit_fn_t exit; screen_open_fn_t open; screen_close_fn_t close; + screen_resize_fn_t resize; screen_paint_fn_t paint; screen_update_fn_t update; screen_cmd_fn_t cmd; @@ -107,7 +109,7 @@ typedef struct int screen_init(void); int screen_exit(void); -void screen_resized(int sig); +void screen_resize(void); void screen_status_message(char *msg); void screen_status_printf(char *format, ...); char *screen_error(void); diff --git a/screen_file.c b/screen_file.c index a0b9ee3..e57fc31 100644 --- a/screen_file.c +++ b/screen_file.c @@ -178,6 +178,8 @@ handle_delete(screen_t *screen, mpd_client_t *c) snprintf(buf, BUFSIZE, "Delete playlist %s [y/n] ? ", str); g_free(str); key = tolower(screen_getch(screen->status_window.w, buf)); + if( key==KEY_RESIZE ) + screen_resize(); if( key!='y' ) { screen_status_printf("Aborted!"); @@ -330,6 +332,13 @@ file_init(WINDOW *w, int cols, int rows) lw = list_window_init(w, cols, rows); } +static void +file_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + static void file_exit(void) { @@ -484,6 +493,7 @@ get_screen_file(void) functions.exit = file_exit; functions.open = file_open; functions.close = file_close; + functions.resize = file_resize; functions.paint = file_paint; functions.update = file_update; functions.cmd = file_cmd; diff --git a/screen_help.c b/screen_help.c index 833342b..37bf9a3 100644 --- a/screen_help.c +++ b/screen_help.c @@ -171,6 +171,13 @@ help_init(WINDOW *w, int cols, int rows) lw = list_window_init(w, cols, rows); } +static void +help_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + static void help_exit(void) { @@ -234,6 +241,7 @@ get_screen_help(void) functions.exit = help_exit; functions.open = NULL; functions.close = NULL; + functions.resize = help_resize; functions.paint = help_paint; functions.update = help_update; functions.cmd = help_cmd; diff --git a/screen_keydef.c b/screen_keydef.c index 46510c0..4bda6ea 100644 --- a/screen_keydef.c +++ b/screen_keydef.c @@ -150,6 +150,8 @@ assign_new_key(WINDOW *w, int cmd_index, int key_index) snprintf(buf, BUFSIZE, "Enter new key for %s: ", cmds[cmd_index].name); key = screen_getch(w, buf); + if( key==KEY_RESIZE ) + screen_resize(); if( key==ERR ) { screen_status_printf("Aborted!"); @@ -214,6 +216,13 @@ keydef_init(WINDOW *w, int cols, int rows) lw = list_window_init(w, cols, rows); } +static void +keydef_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + static void keydef_exit(void) { @@ -370,6 +379,7 @@ get_screen_keydef(void) functions.exit = keydef_exit; functions.open = keydef_open; functions.close = keydef_close; + functions.resize = keydef_resize; functions.paint = keydef_paint; functions.update = keydef_update; functions.cmd = keydef_cmd; diff --git a/screen_play.c b/screen_play.c index 5669d36..eb10489 100644 --- a/screen_play.c +++ b/screen_play.c @@ -133,6 +133,14 @@ play_init(WINDOW *w, int cols, int rows) lw = list_window_init(w, cols, rows); } +static void +play_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + + static void play_exit(void) { @@ -251,6 +259,7 @@ get_screen_playlist(void) functions.exit = play_exit; functions.open = NULL; functions.close = NULL; + functions.resize = play_resize; functions.paint = play_paint; functions.update = play_update; functions.cmd = play_cmd; diff --git a/screen_utils.c b/screen_utils.c index c9fff74..1fb581a 100644 --- a/screen_utils.c +++ b/screen_utils.c @@ -50,6 +50,8 @@ screen_getch(WINDOW *w, char *prompt) timeout(-1); key = wgetch(w); + if( key==KEY_RESIZE ) + screen_resize(); noecho(); curs_set(0);