diff options
author | Kalle Wallin <kaw@linux.se> | 2004-04-21 19:06:18 +0000 |
---|---|---|
committer | Kalle Wallin <kaw@linux.se> | 2004-04-21 19:06:18 +0000 |
commit | b1f77e2684e85fac5ef5d50fc1342d7d53e5a492 (patch) | |
tree | 7727ec3010c4368f59b19a3e246f8d62cc8944d5 | |
parent | 41d5f057a8e0fa8ed4a0c8465ce8a1d0e7ab8e1a (diff) | |
download | mpd-b1f77e2684e85fac5ef5d50fc1342d7d53e5a492.tar.gz mpd-b1f77e2684e85fac5ef5d50fc1342d7d53e5a492.tar.xz mpd-b1f77e2684e85fac5ef5d50fc1342d7d53e5a492.zip |
Fixed resize handling (SIGWINCH).
git-svn-id: https://svn.musicpd.org/ncmpc/trunk@871 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r-- | command.c | 3 | ||||
-rw-r--r-- | main.c | 9 | ||||
-rw-r--r-- | screen.c | 56 | ||||
-rw-r--r-- | screen.h | 4 | ||||
-rw-r--r-- | screen_file.c | 10 | ||||
-rw-r--r-- | screen_help.c | 8 | ||||
-rw-r--r-- | screen_keydef.c | 10 | ||||
-rw-r--r-- | screen_play.c | 9 | ||||
-rw-r--r-- | screen_utils.c | 2 |
9 files changed, 98 insertions, 13 deletions
@@ -328,6 +328,9 @@ get_keyboard_command(void) key = wgetch(stdscr); + if( key==KEY_RESIZE ) + screen_resize(); + if( key==ERR ) return CMD_NONE; @@ -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; @@ -21,6 +21,7 @@ #include <stdarg.h> #include <string.h> #include <time.h> +#include <signal.h> #include <glib.h> #include <ncurses.h> @@ -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( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS ) { + screen_exit(); fprintf(stderr, "Error: Screen to small!\n"); exit(EXIT_FAILURE); } - screen_init(); + + resizeterm(LINES, COLS); + + screen->cols = 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 @@ -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 a0b9ee3f7..e57fc317f 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!"); @@ -331,6 +333,13 @@ file_init(WINDOW *w, int cols, int rows) } static void +file_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + +static void file_exit(void) { list_window_free(lw); @@ -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 833342b9d..37bf9a385 100644 --- a/screen_help.c +++ b/screen_help.c @@ -172,6 +172,13 @@ help_init(WINDOW *w, int cols, int rows) } static void +help_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + +static void help_exit(void) { list_window_free(lw); @@ -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 46510c06b..4bda6ea21 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 5669d3641..eb1048951 100644 --- a/screen_play.c +++ b/screen_play.c @@ -134,6 +134,14 @@ play_init(WINDOW *w, int cols, int rows) } static void +play_resize(int cols, int rows) +{ + lw->cols = cols; + lw->rows = rows; +} + + +static void play_exit(void) { list_window_free(lw); @@ -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 c9fff74c4..1fb581aaa 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); |