aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.c3
-rw-r--r--command.h1
-rw-r--r--conf.c27
-rw-r--r--doc/ncmpcrc.sample40
-rw-r--r--screen.c25
-rw-r--r--screen_help.c2
-rw-r--r--screen_play.c42
7 files changed, 100 insertions, 40 deletions
diff --git a/command.c b/command.c
index e165aa466..f3e129f04 100644
--- a/command.c
+++ b/command.c
@@ -51,7 +51,8 @@ static command_definition_t cmds[] =
{ { '+', RGHT, 0 }, CMD_VOLUME_UP, "Increase volume" },
{ { '-', LEFT, 0 }, CMD_VOLUME_DOWN, "Decrease volume" },
- { { 'w', 0, 0 }, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" },
+ { { 'w', 0, 0 }, CMD_TOGGLE_FIND_WRAP, "Toggle find mode" },
+ { { 'U', 0, 0 }, CMD_TOGGLE_AUTOCENTER, "Toggle auto center mode" },
{ { ' ', 0, 0 }, CMD_SELECT, "Select/deselect song in playlist" },
{ { DEL, 'd', 0 }, CMD_DELETE, "Delete song from playlist" },
diff --git a/command.h b/command.h
index a7e08555b..ba8de80c9 100644
--- a/command.h
+++ b/command.h
@@ -17,6 +17,7 @@ typedef enum
CMD_VOLUME_DOWN,
CMD_SAVE_PLAYLIST,
CMD_TOGGLE_FIND_WRAP,
+ CMD_TOGGLE_AUTOCENTER,
CMD_LIST_PREVIOUS,
CMD_LIST_NEXT,
CMD_LIST_FIRST,
diff --git a/conf.c b/conf.c
index 5969c85ba..6def7b638 100644
--- a/conf.c
+++ b/conf.c
@@ -28,6 +28,9 @@
/* configuration field names */
#define CONF_ENABLE_COLORS "enable_colors"
+#define CONF_AUTO_CENTER "auto_center"
+
+/* configuration field names - colors */
#define CONF_COLOR_BACKGROUND "background_color"
#define CONF_COLOR_TITLE "title_color"
#define CONF_COLOR_LINE "line_color"
@@ -65,24 +68,6 @@ str2color(char *str)
return COLOR_CYAN;
else if( !strcasecmp(str,"white") )
return COLOR_WHITE;
-#if 0
- else if( !strcasecmp(str,"grey") )
- return COLOR_BLACK | A_BOLD;
- else if( !strcasecmp(str,"brightred") )
- return COLOR_RED | A_BOLD;
- else if( !strcasecmp(str,"brightgreen") )
- return COLOR_GREEN | A_BOLD;
- else if( !strcasecmp(str,"brightyellow") )
- return COLOR_YELLOW | A_BOLD;
- else if( !strcasecmp(str,"brightblue") )
- return COLOR_BLUE | A_BOLD;
- else if( !strcasecmp(str,"brightmagenta") )
- return COLOR_MAGENTA | A_BOLD;
- else if( !strcasecmp(str,"brightcyan") )
- return COLOR_CYAN | A_BOLD;
- else if( !strcasecmp(str,"brightwhite") )
- return COLOR_WHITE | A_BOLD;
-#endif
fprintf(stderr,"Warning: unknown color %s\n", str);
return -1;
}
@@ -181,6 +166,12 @@ read_rc_file(char *filename, options_t *options)
options->enable_colors = str2bool(value);
match_found = 1;
}
+ /* auto center */
+ else if( !strcasecmp(CONF_AUTO_CENTER, name) )
+ {
+ options->auto_center = str2bool(value);
+ match_found = 1;
+ }
/* background color */
else if( !strcasecmp(CONF_COLOR_BACKGROUND, name) )
{
diff --git a/doc/ncmpcrc.sample b/doc/ncmpcrc.sample
index 98d34c699..bebae0817 100644
--- a/doc/ncmpcrc.sample
+++ b/doc/ncmpcrc.sample
@@ -1,21 +1,23 @@
-#
-# Configuration file for ncmpc (~/.ncmpcrc)
-#
+##
+## Configuration file for ncmpc (~/.ncmpcrc)
+##
+## auto center (center the playing track in the playlist)
+#auto_center = no
-#
-# Color configuration
-#
-# colors: black,red,green,yellow,blue,magenta,cyan,white
-#
+##
+## Color configuration
+##
+## colors: black,red,green,yellow,blue,magenta,cyan,white
+##
-# enable/disable colors
-enable_colors = yes
+## enable/disable colors
+#enable_colors = yes
-# background color
+## background color
#background_color = blue
-# text colors
+## text colors
#title_color = white
#line_color = green
#list_color = yellow
@@ -24,16 +26,16 @@ enable_colors = yes
#alert_color = yellow
-#
-# Key bindings - NOT IMPLEMENTED
-#
+##
+## Key bindings - NOT IMPLEMENTED
+##
# key_up = 13
-#
-# Key names - NOT IMPLEMENTED
-#
+##
+## Key names - NOT IMPLEMENTED
+##
#key_name 13 Enter
-#
+
diff --git a/screen.c b/screen.c
index aabc6f033..efd93d1fe 100644
--- a/screen.c
+++ b/screen.c
@@ -79,7 +79,8 @@ paint_top_window(char *header, int volume, int clear)
if(clear)
{
- wclear(w);
+ wmove(w, 0, 0);
+ wclrtoeol(w);
}
if(prev_volume!=volume || clear)
@@ -99,11 +100,24 @@ paint_top_window(char *header, int volume, int clear)
}
mvwaddstr(w, 0, screen->top_window.cols-12, buf);
+#if 1
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);
+#else
+ if( options.enable_colors )
+ wattron(w, LINE_COLORS);
+
+ mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
+ wmove(w,1,screen->top_window.cols-6);
+ waddstr(w, "[rzx]");
+
+ if( options.enable_colors )
+ wattroff(w, LINE_COLORS);
+
+#endif
wnoutrefresh(w);
}
@@ -115,7 +129,7 @@ paint_progress_window(mpd_client_t *c)
double p;
int width;
- if( c->status==NULL || !IS_PLAYING(c->status->state) )
+ if( c->status==NULL || IS_STOPPED(c->status->state) )
{
mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE,
screen->progress_window.cols);
@@ -320,6 +334,7 @@ screen_init(void)
screen->buf_size = screen->cols;
screen->findbuf = NULL;
screen->painted = 0;
+ screen->input_timestamp = time(NULL);
/* create top window */
screen->top_window.rows = 2;
@@ -472,6 +487,7 @@ screen_cmd(mpd_client_t *c, command_t cmd)
int n;
screen_mode_t new_mode = screen->mode;
+ screen->input_timestamp = time(NULL);
switch(screen->mode)
{
case SCREEN_PLAY_WINDOW:
@@ -564,6 +580,11 @@ screen_cmd(mpd_client_t *c, command_t cmd)
screen_status_printf("Find mode: %s",
options.find_wrap ? "Wrapped" : "Normal");
break;
+ case CMD_TOGGLE_AUTOCENTER:
+ options.auto_center = !options.auto_center;
+ screen_status_printf("Auto center mode: %s",
+ options.auto_center ? "On" : "Off");
+ break;
case CMD_SCREEN_PREVIOUS:
if( screen->mode > SCREEN_PLAY_WINDOW )
new_mode = screen->mode - 1;
diff --git a/screen_help.c b/screen_help.c
index 09349a361..d2e8086af 100644
--- a/screen_help.c
+++ b/screen_help.c
@@ -53,6 +53,8 @@ static help_text_row_t help_text[] =
{ 0, CMD_SAVE_PLAYLIST, "Save playlist" },
{ 0, CMD_REPEAT, "Toggle repeat mode" },
{ 0, CMD_RANDOM, "Toggle random mode" },
+ { 0, CMD_SCREEN_UPDATE, "Center playing track" },
+ { 0, CMD_TOGGLE_AUTOCENTER, "Toggle auto center" },
{ 0, CMD_NONE, " " },
{ 0, CMD_NONE, " " },
{ 1, CMD_NONE, " Keys - Browse screen " },
diff --git a/screen_play.c b/screen_play.c
index 151402def..c9fd248eb 100644
--- a/screen_play.c
+++ b/screen_play.c
@@ -4,6 +4,7 @@
#include <ncurses.h>
#include "config.h"
+#include "options.h"
#include "support.h"
#include "libmpdclient.h"
#include "mpc.h"
@@ -37,6 +38,33 @@ list_callback(int index, int *highlight, void *data)
}
static int
+center_playing_item(screen_t *screen, mpd_client_t *c)
+{
+ list_window_t *lw = screen->playlist;
+ int length = c->playlist_length;
+ int offset = lw->selected-lw->start;
+
+ if( !lw || length<lw->rows || !IS_PLAYING(c->status->state) )
+ return 0;
+
+ /* try to center the song that are playing */
+ lw->start = c->song_id-(lw->rows/2);
+ if( lw->start+lw->rows > length )
+ lw->start = length-lw->rows;
+ if( lw->start<0 )
+ lw->start=0;
+
+ /* make sure the cursor is in the window */
+ lw->selected = lw->start+offset;
+ list_window_check_selected(lw, length);
+
+ lw->clear = 1;
+ lw->repaint = 1;
+
+ return 0;
+}
+
+static int
handle_save_playlist(screen_t *screen, mpd_client_t *c)
{
char *filename, *filename_utf8;
@@ -103,6 +131,17 @@ play_paint(screen_t *screen, mpd_client_t *c)
void
play_update(screen_t *screen, mpd_client_t *c)
{
+ if( options.auto_center )
+ {
+ static int prev_song_id = 0;
+
+ if( prev_song_id != c->song_id )
+ {
+ center_playing_item(screen, c);
+ prev_song_id = c->song_id;
+ }
+ }
+
if( c->playlist_updated )
{
if( screen->playlist->selected >= c->playlist_length )
@@ -142,6 +181,9 @@ play_cmd(screen_t *screen, mpd_client_t *c, command_t cmd)
case CMD_SAVE_PLAYLIST:
handle_save_playlist(screen, c);
return 1;
+ case CMD_SCREEN_UPDATE:
+ center_playing_item(screen, c);
+ return 1;
case CMD_LIST_FIND:
case CMD_LIST_RFIND:
case CMD_LIST_FIND_NEXT: