X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=screen.c;h=aabc6f0334b5b53e3a2fd46cef6730f832ec9e20;hb=589bbc3fa5acf9a1a4f402ecee097d9db9639291;hp=86269512527dc1ec8a5a37010e56e220d0917619;hpb=268b0823860274d6079c5dd307770a0769d404ef;p=ncmpc.git diff --git a/screen.c b/screen.c index 8626951..aabc6f0 100644 --- a/screen.c +++ b/screen.c @@ -68,8 +68,15 @@ static void paint_top_window(char *header, int volume, int clear) { static int prev_volume = -1; + static int prev_header_len = -1; WINDOW *w = screen->top_window.w; + if(prev_header_len!=strlen(header)) + { + prev_header_len = strlen(header); + clear = 1; + } + if(clear) { wclear(w); @@ -94,13 +101,11 @@ paint_top_window(char *header, int volume, int clear) if( options.enable_colors ) wattron(w, LINE_COLORS); - mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols); - if( options.enable_colors ) wattroff(w, LINE_COLORS); - wrefresh(w); + wnoutrefresh(w); } } @@ -114,7 +119,7 @@ paint_progress_window(mpd_client_t *c) { mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE, screen->progress_window.cols); - wrefresh(screen->progress_window.w); + wnoutrefresh(screen->progress_window.w); return; } @@ -127,7 +132,7 @@ paint_progress_window(mpd_client_t *c) screen->progress_window.cols); whline(screen->progress_window.w, '=', width-1); mvwaddch(screen->progress_window.w, 0, width-1, 'O'); - wrefresh(screen->progress_window.w); + wnoutrefresh(screen->progress_window.w); } static void @@ -171,7 +176,6 @@ paint_status_window(mpd_client_t *c) if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) && song ) { - // my_mvwaddstr(w, 0, x, mpc_get_song_name(song), COLOR_PAIR(2)); mvwaddstr(w, 0, x, mpc_get_song_name(song)); } @@ -185,11 +189,10 @@ paint_status_window(mpd_client_t *c) " [%i:%02i/%i:%02i] ", status->elapsedTime/60, status->elapsedTime%60, status->totalTime/60, status->totalTime%60 ); - //my_mvwaddstr(w, 0, x, screen->buf, COLOR_PAIR(1)); mvwaddstr(w, 0, x, screen->buf); } -#if 1 +#if 0 else if( c->status->state == MPD_STATUS_STATE_STOP ) { time_t timep; @@ -203,7 +206,7 @@ paint_status_window(mpd_client_t *c) #endif - wrefresh(w); + wnoutrefresh(w); } @@ -217,9 +220,9 @@ screen_exit(void) screen->playlist = list_window_free(screen->playlist); screen->filelist = list_window_free(screen->filelist); screen->helplist = list_window_free(screen->helplist); - free(screen->buf); - free(screen->findbuf); - free(screen); + g_free(screen->buf); + g_free(screen->findbuf); + g_free(screen); screen = NULL; } return 0; @@ -247,7 +250,7 @@ screen_status_message(char *msg) wattron(w, A_BOLD); my_waddstr(w, msg, ALERT_COLORS); wattroff(w, A_BOLD); - wrefresh(w); + wnoutrefresh(w); screen->status_timestamp = time(NULL); } @@ -267,19 +270,27 @@ int screen_init(void) { /* initialize the curses library */ - initscr(); - start_color(); - if( options.enable_colors ) + initscr(); + if( has_colors() ) { - init_pair(1, options.title_color, options.bg_color); - init_pair(2, options.line_color, options.bg_color); - init_pair(3, options.list_color, options.bg_color); - init_pair(4, options.progress_color, options.bg_color); - init_pair(5, options.status_color, options.bg_color); - init_pair(6, options.alert_color, options.bg_color); + start_color(); + if( options.enable_colors ) + { + init_pair(1, options.title_color, options.bg_color); + init_pair(2, options.line_color, options.bg_color); + init_pair(3, options.list_color, options.bg_color); + init_pair(4, options.progress_color, options.bg_color); + init_pair(5, options.status_color, options.bg_color); + init_pair(6, options.alert_color, options.bg_color); + } + else + use_default_colors(); + } + else if( options.enable_colors ) + { + fprintf(stderr, "Terminal lacks color capabilities.\n"); + options.enable_colors = 0; } - else - use_default_colors(); /* tell curses not to do NL->CR/NL on output */ nonl(); @@ -292,7 +303,7 @@ screen_init(void) /* return from getch() without blocking */ // nodelay(stdscr, TRUE); keypad(stdscr, TRUE); - timeout(100); /*void wtimeout(WINDOW *win, int delay);*/ + timeout(SCREEN_TIMEOUT); if( COLSmode = SCREEN_PLAY_WINDOW; screen->cols = COLS; screen->rows = LINES; - screen->buf = malloc(screen->cols); + screen->buf = g_malloc(screen->cols); screen->buf_size = screen->cols; screen->findbuf = NULL; screen->painted = 0; @@ -335,7 +346,8 @@ screen_init(void) screen->helplist = list_window_init( screen->main_window.w, screen->main_window.cols, screen->main_window.rows ); - leaveok(screen->main_window.w, TRUE); + + // leaveok(screen->main_window.w, TRUE); temporary disabled keypad(screen->main_window.w, TRUE); /* create progress window */ @@ -363,9 +375,6 @@ screen_init(void) /* set background attributes */ wbkgd(screen->main_window.w, LIST_COLORS); wbkgd(screen->top_window.w, TITLE_COLORS); - wbkgd(screen->playlist->w, LIST_COLORS); - wbkgd(screen->filelist->w, LIST_COLORS); - wbkgd(screen->helplist->w, LIST_COLORS); wbkgd(screen->progress_window.w, PROGRESS_COLORS); wbkgd(screen->status_window.w, STATUS_COLORS); } @@ -399,23 +408,46 @@ screen_paint(mpd_client_t *c) paint_progress_window(c); paint_status_window(c); screen->painted = 1; + wmove(screen->main_window.w, 0, 0); wnoutrefresh(screen->main_window.w); + doupdate(); } void screen_update(mpd_client_t *c) { + static int repeat = -1; + static int random = -1; + list_window_t *lw = NULL; + if( !screen->painted ) return screen_paint(c); + if( repeat<0 ) + { + repeat = c->status->repeat; + random = c->status->random; + } + if( repeat != c->status->repeat ) + screen_status_printf("Repeat is %s", + c->status->repeat ? "On" : "Off"); + if( random != c->status->random ) + screen_status_printf("Random is %s", + c->status->random ? "On" : "Off"); + + repeat = c->status->repeat; + random = c->status->random; + switch(screen->mode) { case SCREEN_PLAY_WINDOW: paint_top_window(TOP_HEADER_PLAY, c->status->volume, 0); play_update(screen, c); + lw = screen->playlist; break; case SCREEN_FILE_WINDOW: paint_top_window(file_get_header(c), c->status->volume, 0); file_update(screen, c); + lw = screen->filelist; break; case SCREEN_SEARCH_WINDOW: paint_top_window(TOP_HEADER_SEARCH, c->status->volume, 0); @@ -424,17 +456,20 @@ screen_update(mpd_client_t *c) case SCREEN_HELP_WINDOW: paint_top_window(TOP_HEADER_HELP, c->status->volume, 0); help_update(screen, c); + lw = screen->helplist; break; } paint_progress_window(c); paint_status_window(c); + wmove(screen->main_window.w, LW_ROW(lw), 0); + wnoutrefresh(screen->main_window.w); + doupdate(); } void screen_cmd(mpd_client_t *c, command_t cmd) { int n; - // char buf[256]; screen_mode_t new_mode = screen->mode; switch(screen->mode) @@ -500,13 +535,11 @@ screen_cmd(mpd_client_t *c, command_t cmd) n = !c->status->repeat; mpd_sendRepeatCommand(c->connection, n); mpd_finishCommand(c->connection); - screen_status_printf("Repeat is %s", n ? "On" : "Off"); break; case CMD_RANDOM: n = !c->status->random; mpd_sendRandomCommand(c->connection, n); mpd_finishCommand(c->connection); - screen_status_printf("Random is %s", n ? "On" : "Off"); break; case CMD_VOLUME_UP: if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 ) @@ -526,6 +559,11 @@ screen_cmd(mpd_client_t *c, command_t cmd) screen_status_printf("Volume %d%%", c->status->volume); } break; + case CMD_TOGGLE_FIND_WRAP: + options.find_wrap = !options.find_wrap; + screen_status_printf("Find mode: %s", + options.find_wrap ? "Wrapped" : "Normal"); + break; case CMD_SCREEN_PREVIOUS: if( screen->mode > SCREEN_PLAY_WINDOW ) new_mode = screen->mode - 1; @@ -553,21 +591,11 @@ screen_cmd(mpd_client_t *c, command_t cmd) break; case CMD_QUIT: exit(EXIT_SUCCESS); - case CMD_LIST_FIND: - case CMD_LIST_FIND_NEXT: - case CMD_NONE: - case CMD_DELETE: - case CMD_SELECT: - case CMD_LIST_PREVIOUS: - case CMD_LIST_NEXT: - case CMD_LIST_FIRST: - case CMD_LIST_LAST: - case CMD_LIST_NEXT_PAGE: - case CMD_LIST_PREVIOUS_PAGE: + default: break; } } -; +