diff --git a/screen.c b/screen.c
index 2d61122fd91cfe08d988bab76080f93a0124a0c6..aabc6f0334b5b53e3a2fd46cef6730f832ec9e20 100644 (file)
--- a/screen.c
+++ b/screen.c
-/*
- * $Id: screen.c,v 1.10 2004/03/17 14:50:12 kalle Exp $
- *
- */
-
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include "libmpdclient.h"
#include "mpc.h"
#include "command.h"
+#include "options.h"
#include "screen.h"
#include "screen_play.h"
#include "screen_file.h"
#include "screen_help.h"
#include "screen_search.h"
+#include "screen_utils.h"
#define STATUS_MESSAGE_TIMEOUT 3
#define STATUS_LINE_MAX_SIZE 512
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);
char buf[12];
wattron(w, A_BOLD);
- mvwaddstr(w, 0, 0, header );
+ mvwaddstr(w, 0, 0, header);
wattroff(w, A_BOLD);
if( volume==MPD_STATUS_NO_VOLUME )
{
}
mvwaddstr(w, 0, screen->top_window.cols-12, buf);
+ 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);
}
}
{
mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE,
screen->progress_window.cols);
- wrefresh(screen->progress_window.w);
+ wnoutrefresh(screen->progress_window.w);
return;
}
p = ((double) c->status->elapsedTime) / ((double) c->status->totalTime);
width = (int) (p * (double) screen->progress_window.cols);
-
mvwhline(screen->progress_window.w,
0, 0,
ACS_HLINE,
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
wattroff(w, A_BOLD);
break;
case MPD_STATUS_STATE_PLAY:
+ wattron(w, A_BOLD);
waddstr(w, "Playing:");
+ wattroff(w, A_BOLD);
break;
case MPD_STATUS_STATE_PAUSE:
wattron(w, A_BOLD);
- waddstr(w, "Paused:");
+ waddstr(w, "[Paused]");
wattroff(w, A_BOLD);
break;
default:
- waddstr(w, "Warning: Music Player Daemon in unknown state!");
+ my_waddstr(w,
+ "Warning: Music Player Daemon in unknown state!",
+ ALERT_COLORS);
break;
}
x += 10;
- if( IS_PLAYING(status->state) && song )
+ if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) && song )
{
mvwaddstr(w, 0, x, mpc_get_song_name(song));
}
/* time */
- if( IS_PLAYING(status->state) )
+ if( IS_PLAYING(status->state) || IS_PAUSED(status->state) )
{
x = screen->status_window.cols - strlen(screen->buf);
- if( c->status->repeat )
- mvwaddstr(w, 0, x-3, "<R>");
- else
- mvwaddstr(w, 0, x-3, " ");
-
snprintf(screen->buf, screen->buf_size,
" [%i:%02i/%i:%02i] ",
status->elapsedTime/60, status->elapsedTime%60,
mvwaddstr(w, 0, x, screen->buf);
}
+#if 0
+ else if( c->status->state == MPD_STATUS_STATE_STOP )
+ {
+ time_t timep;
+ x = screen->status_window.cols - strlen(screen->buf);
+
+ time(&timep);
+ //strftime(screen->buf, screen->buf_size, "%X ", localtime(&timep));
+ strftime(screen->buf, screen->buf_size, "%R ", localtime(&timep));
+ mvwaddstr(w, 0, x, screen->buf);
+ }
+#endif
- wrefresh(w);
+ wnoutrefresh(w);
}
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;
}
void
-screen_status_message(mpd_client_t *c, char *msg)
+screen_status_message(char *msg)
{
WINDOW *w = screen->status_window.w;
wmove(w, 0, 0);
wclrtoeol(w);
wattron(w, A_BOLD);
- waddstr(w, msg);
+ my_waddstr(w, msg, ALERT_COLORS);
wattroff(w, A_BOLD);
- wrefresh(w);
+ wnoutrefresh(w);
screen->status_timestamp = time(NULL);
}
void
-screen_status_printf(mpd_client_t *c, char *format, ...)
+screen_status_printf(char *format, ...)
{
char buffer[STATUS_LINE_MAX_SIZE];
va_list ap;
va_start(ap,format);
vsnprintf(buffer,sizeof(buffer),format,ap);
va_end(ap);
- screen_status_message(c, buffer);
+ screen_status_message(buffer);
}
int
screen_init(void)
{
/* initialize the curses library */
- initscr();
- start_color();
- use_default_colors();
+ initscr();
+ if( has_colors() )
+ {
+ 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;
+ }
+
/* tell curses not to do NL->CR/NL on output */
nonl();
/* take input chars one at a time, no wait for \n */
/* return from getch() without blocking */
// nodelay(stdscr, TRUE);
keypad(stdscr, TRUE);
- timeout(100); /*void wtimeout(WINDOW *win, int delay);*/
-
+ timeout(SCREEN_TIMEOUT);
if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
{
exit(EXIT_FAILURE);
}
- screen = malloc(sizeof(screen_t));
+ screen = g_malloc(sizeof(screen_t));
memset(screen, 0, sizeof(screen_t));
screen->mode = 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;
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 */
screen->status_window.cols,
screen->rows-1,
0);
+
leaveok(screen->status_window.w, FALSE);
keypad(screen->status_window.w, TRUE);
+ if( options.enable_colors )
+ {
+ /* set background attributes */
+ wbkgd(screen->main_window.w, LIST_COLORS);
+ wbkgd(screen->top_window.w, TITLE_COLORS);
+ wbkgd(screen->progress_window.w, PROGRESS_COLORS);
+ wbkgd(screen->status_window.w, STATUS_COLORS);
+ }
+
return 0;
}
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);
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)
case CMD_SHUFFLE:
mpd_sendShuffleCommand(c->connection);
mpd_finishCommand(c->connection);
- screen_status_message(c, "Shuffled playlist!");
+ screen_status_message("Shuffled playlist!");
break;
case CMD_CLEAR:
mpd_sendClearCommand(c->connection);
mpd_finishCommand(c->connection);
file_clear_highlights(c);
- screen_status_message(c, "Cleared playlist!");
+ screen_status_message("Cleared playlist!");
break;
case CMD_REPEAT:
n = !c->status->repeat;
mpd_sendRepeatCommand(c->connection, n);
mpd_finishCommand(c->connection);
- snprintf(buf, 256, "Repeat is %s", n ? "On" : "Off");
- screen_status_message(c, buf);
break;
case CMD_RANDOM:
n = !c->status->random;
mpd_sendRandomCommand(c->connection, n);
mpd_finishCommand(c->connection);
- snprintf(buf, 256, "Random is %s", n ? "On" : "Off");
- screen_status_message(c, buf);
break;
case CMD_VOLUME_UP:
- mpd_sendSetvolCommand(c->connection, 1);
- mpd_finishCommand(c->connection);
- if( c->status->volume!=MPD_STATUS_NO_VOLUME )
+ if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
{
- snprintf(buf, 256, "Volume %d%%", c->status->volume+1);
- screen_status_message(c, buf);
+ c->status->volume=c->status->volume+1;
+ mpd_sendSetvolCommand(c->connection, c->status->volume );
+ mpd_finishCommand(c->connection);
+ screen_status_printf("Volume %d%%", c->status->volume);
}
break;
case CMD_VOLUME_DOWN:
- mpd_sendSetvolCommand(c->connection, -1);
- mpd_finishCommand(c->connection);
- if( c->status->volume!=MPD_STATUS_NO_VOLUME )
+ if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
{
- snprintf(buf, 256, "Volume %d%%", c->status->volume-1);
- screen_status_message(c, buf);
+ c->status->volume=c->status->volume-1;
+ mpd_sendSetvolCommand(c->connection, c->status->volume );
+ mpd_finishCommand(c->connection);
+ 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;
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;
}
}
+