Code

b8102d670916608c410f373805cf345f3928bae0
[ncmpc.git] / src / screen.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "screen.h"
21 #include "screen_list.h"
22 #include "screen_utils.h"
23 #include "config.h"
24 #include "i18n.h"
25 #include "charset.h"
26 #include "mpdclient.h"
27 #include "utils.h"
28 #include "options.h"
29 #include "colors.h"
30 #include "strfsong.h"
32 #ifndef NCMPC_MINI
33 #include "hscroll.h"
34 #endif
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <time.h>
41 #include <locale.h>
43 #ifndef NCMPC_MINI
44 /** welcome message time [s] */
45 static const GTime SCREEN_WELCOME_TIME = 10;
46 #endif
48 /* minimum window size */
49 static const int SCREEN_MIN_COLS = 14;
50 static const int SCREEN_MIN_ROWS = 5;
52 /* screens */
54 #ifndef NCMPC_MINI
55 static gboolean welcome = TRUE;
56 #endif
58 struct screen screen;
59 static const struct screen_functions *mode_fn = &screen_playlist;
60 static const struct screen_functions *mode_fn_prev = &screen_playlist;
61 static int seek_id = -1;
62 static int seek_target_time = 0;
64 gboolean
65 screen_is_visible(const struct screen_functions *sf)
66 {
67         return sf == mode_fn;
68 }
70 void
71 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
72 {
73         assert(sf != NULL);
75         if (sf == mode_fn)
76                 return;
78         mode_fn_prev = mode_fn;
80         /* close the old mode */
81         if (mode_fn->close != NULL)
82                 mode_fn->close();
84         /* get functions for the new mode */
85         mode_fn = sf;
87         /* open the new mode */
88         if (mode_fn->open != NULL)
89                 mode_fn->open(c);
91         screen_paint(c);
92 }
94 void
95 screen_swap(struct mpdclient *c, const struct mpd_song *song)
96 {
97         if (song != NULL)
98         {
99                 if (false)
100                         { /* just a hack to make the ifdefs less ugly */ }
101 #ifdef ENABLE_SONG_SCREEN
102                 if (mode_fn_prev == &screen_song)
103                         screen_song_switch(c, song);
104 #endif
105 #ifdef ENABLE_LYRICS_SCREEN
106                 else if (mode_fn_prev == &screen_lyrics)
107                         screen_lyrics_switch(c, song);
108 #endif
109                 else
110                         screen_switch(mode_fn_prev, c);
111         }
112         else
113                 screen_switch(mode_fn_prev, c);
116 static int
117 find_configured_screen(const char *name)
119         unsigned i;
121         for (i = 0; options.screen_list[i] != NULL; ++i)
122                 if (strcmp(options.screen_list[i], name) == 0)
123                         return i;
125         return -1;
128 static void
129 screen_next_mode(mpdclient_t *c, int offset)
131         int max = g_strv_length(options.screen_list);
132         int current, next;
133         const struct screen_functions *sf;
135         /* find current screen */
136         current = find_configured_screen(screen_get_name(mode_fn));
137         next = current + offset;
138         if (next<0)
139                 next = max-1;
140         else if (next>=max)
141                 next = 0;
143         sf = screen_lookup_name(options.screen_list[next]);
144         if (sf != NULL)
145                 screen_switch(sf, c);
148 #ifndef NCMPC_MINI
149 static void
150 print_hotkey(WINDOW *w, command_t cmd, const char *label)
152         colors_use(w, COLOR_TITLE_BOLD);
153         waddstr(w, get_key_names(cmd, FALSE));
154         colors_use(w, COLOR_TITLE);
155         waddch(w, ':');
156         waddstr(w, label);
157         waddch(w, ' ');
158         waddch(w, ' ');
160 #endif
162 static inline int
163 get_volume(const struct mpd_Status *status)
165         return status != NULL
166                 ? status->volume
167                 : MPD_STATUS_NO_VOLUME;
170 static void
171 paint_top_window2(const char *header, mpdclient_t *c)
173         int volume;
174         char flags[5];
175         WINDOW *w = screen.top_window.w;
176         char buf[32];
178         if (header[0]) {
179                 colors_use(w, COLOR_TITLE_BOLD);
180                 mvwaddstr(w, 0, 0, header);
181 #ifndef NCMPC_MINI
182         } else {
183 #ifdef ENABLE_HELP_SCREEN
184                 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
185 #endif
186                 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
187                 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
188 #ifdef ENABLE_ARTIST_SCREEN
189                 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
190 #endif
191 #ifdef ENABLE_SEARCH_SCREEN
192                 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
193 #endif
194 #ifdef ENABLE_LYRICS_SCREEN
195                 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
196 #endif
197 #ifdef ENABLE_OUTPUTS_SCREEN
198                 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
199 #endif
200 #endif
201         }
203         volume = get_volume(c->status);
204         if (volume == MPD_STATUS_NO_VOLUME)
205                 g_snprintf(buf, 32, _("Volume n/a"));
206         else
207                 g_snprintf(buf, 32, _("Volume %d%%"), volume);
209         colors_use(w, COLOR_TITLE);
210         mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
212         flags[0] = 0;
213         if (c->status != NULL) {
214                 if (c->status->repeat)
215                         g_strlcat(flags, "r", sizeof(flags));
216                 if (c->status->random)
217                         g_strlcat(flags, "z", sizeof(flags));
218                 if (c->status->single)
219                         g_strlcat(flags, "s", sizeof(flags));
220                 if (c->status->consume)
221                         g_strlcat(flags, "c", sizeof(flags));
222                 if (c->status->crossfade)
223                         g_strlcat(flags, "x", sizeof(flags));
224                 if (c->status->updatingDb)
225                         g_strlcat(flags, "U", sizeof(flags));
226         }
228         colors_use(w, COLOR_LINE);
229         mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
230         if (flags[0]) {
231                 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
232                 waddch(w, '[');
233                 colors_use(w, COLOR_LINE_BOLD);
234                 waddstr(w, flags);
235                 colors_use(w, COLOR_LINE);
236                 waddch(w, ']');
237         }
238         wnoutrefresh(w);
241 static void
242 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
244         static int prev_volume = -1;
245         static unsigned prev_header_len = -1;
246         WINDOW *w = screen.top_window.w;
248         if (prev_header_len != utf8_width(header)) {
249                 prev_header_len = utf8_width(header);
250                 full_repaint = 1;
251         }
253         if (full_repaint) {
254                 wmove(w, 0, 0);
255                 wclrtoeol(w);
256         }
258         if ((c->status != NULL && prev_volume != c->status->volume) ||
259             full_repaint)
260                 paint_top_window2(header, c);
263 static void
264 paint_progress_window(mpdclient_t *c)
266         double p;
267         int width;
268         int elapsedTime;
270         if (c->status==NULL || IS_STOPPED(c->status->state)) {
271                 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
272                          screen.progress_window.cols);
273                 wnoutrefresh(screen.progress_window.w);
274                 return;
275         }
277         if (c->song && seek_id == c->song->id)
278                 elapsedTime = seek_target_time;
279         else
280                 elapsedTime = c->status->elapsedTime;
282         p = ((double) elapsedTime) / ((double) c->status->totalTime);
284         width = (int) (p * (double) screen.progress_window.cols);
285         mvwhline(screen.progress_window.w,
286                  0, 0,
287                  ACS_HLINE,
288                  screen.progress_window.cols);
289         whline(screen.progress_window.w, '=', width-1);
290         mvwaddch(screen.progress_window.w, 0, width-1, 'O');
291         wnoutrefresh(screen.progress_window.w);
294 static void
295 paint_status_window(mpdclient_t *c)
297         WINDOW *w = screen.status_window.w;
298         mpd_Status *status = c->status;
299         mpd_Song *song = c->song;
300         int elapsedTime = 0;
301 #ifdef NCMPC_MINI
302         static char bitrate[1];
303 #else
304         char bitrate[16];
305 #endif
306         const char *str = NULL;
307         int x = 0;
309         if( time(NULL) - screen.status_timestamp <= options.status_message_time )
310                 return;
312         wmove(w, 0, 0);
313         wclrtoeol(w);
314         colors_use(w, COLOR_STATUS_BOLD);
316         switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
317         case MPD_STATUS_STATE_PLAY:
318                 str = _("Playing:");
319                 break;
320         case MPD_STATUS_STATE_PAUSE:
321                 str = _("[Paused]");
322                 break;
323         case MPD_STATUS_STATE_STOP:
324         default:
325                 break;
326         }
328         if (str) {
329                 waddstr(w, str);
330                 x += utf8_width(str) + 1;
331         }
333         /* create time string */
334         memset(screen.buf, 0, screen.buf_size);
335         if (status != NULL && (IS_PLAYING(status->state) ||
336                                IS_PAUSED(status->state))) {
337                 if (status->totalTime > 0) {
338                         /*checks the conf to see whether to display elapsed or remaining time */
339                         if(!strcmp(options.timedisplay_type,"elapsed"))
340                                 elapsedTime = c->status->elapsedTime;
341                         else if(!strcmp(options.timedisplay_type,"remaining"))
342                                 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
344                         if( c->song && seek_id == c->song->id )
345                                 elapsedTime = seek_target_time;
347                         /* display bitrate if visible-bitrate is true */
348 #ifndef NCMPC_MINI
349                         if (options.visible_bitrate) {
350                                 g_snprintf(bitrate, 16,
351                                            " [%d kbps]", status->bitRate);
352                         } else {
353                                 bitrate[0] = '\0';
354                         }
355 #endif
357                         /*write out the time, using hours if time over 60 minutes*/
358                         if (c->status->totalTime > 3600) {
359                                 g_snprintf(screen.buf, screen.buf_size,
360                                            "%s [%i:%02i:%02i/%i:%02i:%02i]",
361                                            bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
362                                            status->totalTime/3600, (status->totalTime%3600)/60,  status->totalTime%60);
363                         } else {
364                                 g_snprintf(screen.buf, screen.buf_size,
365                                            "%s [%i:%02i/%i:%02i]",
366                                            bitrate, elapsedTime/60, elapsedTime%60,
367                                            status->totalTime/60,   status->totalTime%60 );
368                         }
369 #ifndef NCMPC_MINI
370                 } else {
371                         g_snprintf(screen.buf, screen.buf_size,
372                                    " [%d kbps]", status->bitRate );
373 #endif
374                 }
375 #ifndef NCMPC_MINI
376         } else {
377                 if (options.display_time) {
378                         time_t timep;
380                         time(&timep);
381                         strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
382                 }
383 #endif
384         }
386         /* display song */
387         if (status != NULL && (IS_PLAYING(status->state) ||
388                                IS_PAUSED(status->state))) {
389                 char songname[MAX_SONGNAME_LENGTH];
390 #ifndef NCMPC_MINI
391                 int width = COLS - x - utf8_width(screen.buf);
392 #endif
394                 if (song)
395                         strfsong(songname, MAX_SONGNAME_LENGTH,
396                                  options.status_format, song);
397                 else
398                         songname[0] = '\0';
400                 colors_use(w, COLOR_STATUS);
401                 /* scroll if the song name is to long */
402 #ifndef NCMPC_MINI
403                 if (options.scroll && utf8_width(songname) > (unsigned)width) {
404                         static  scroll_state_t st = { 0, 0 };
405                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
407                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
408                         g_free(tmp);
409                 }
410 #endif
411                 //mvwaddnstr(w, 0, x, songname, width);
412                 mvwaddstr(w, 0, x, songname);
413         }
415         /* display time string */
416         if (screen.buf[0]) {
417                 x = screen.status_window.cols - strlen(screen.buf);
418                 colors_use(w, COLOR_STATUS_TIME);
419                 mvwaddstr(w, 0, x, screen.buf);
420         }
422         wnoutrefresh(w);
425 void
426 screen_exit(void)
428         if (mode_fn->close != NULL)
429                 mode_fn->close();
431         screen_list_exit();
433         string_list_free(screen.find_history);
434         g_free(screen.buf);
435         g_free(screen.findbuf);
438 void
439 screen_resize(struct mpdclient *c)
441         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
442                 screen_exit();
443                 fprintf(stderr, "%s", _("Error: Screen too small"));
444                 exit(EXIT_FAILURE);
445         }
447         resizeterm(LINES, COLS);
449         screen.cols = COLS;
450         screen.rows = LINES;
452         /* top window */
453         screen.top_window.cols = screen.cols;
454         wresize(screen.top_window.w, 2, screen.cols);
456         /* main window */
457         screen.main_window.cols = screen.cols;
458         screen.main_window.rows = screen.rows-4;
459         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
460         wclear(screen.main_window.w);
462         /* progress window */
463         screen.progress_window.cols = screen.cols;
464         wresize(screen.progress_window.w, 1, screen.cols);
465         mvwin(screen.progress_window.w, screen.rows-2, 0);
467         /* status window */
468         screen.status_window.cols = screen.cols;
469         wresize(screen.status_window.w, 1, screen.cols);
470         mvwin(screen.status_window.w, screen.rows-1, 0);
472         screen.buf_size = screen.cols;
473         g_free(screen.buf);
474         screen.buf = g_malloc(screen.cols);
476         /* resize all screens */
477         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
479         /* ? - without this the cursor becomes visible with aterm & Eterm */
480         curs_set(1);
481         curs_set(0);
483         screen_paint(c);
486 void
487 screen_status_message(const char *msg)
489         WINDOW *w = screen.status_window.w;
491         wmove(w, 0, 0);
492         wclrtoeol(w);
493         colors_use(w, COLOR_STATUS_ALERT);
494         waddstr(w, msg);
495         wnoutrefresh(w);
496         screen.status_timestamp = time(NULL);
499 void
500 screen_status_printf(const char *format, ...)
502         char *msg;
503         va_list ap;
505         va_start(ap,format);
506         msg = g_strdup_vprintf(format,ap);
507         va_end(ap);
508         screen_status_message(msg);
509         g_free(msg);
512 void
513 screen_init(mpdclient_t *c)
515         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
516                 fprintf(stderr, "%s\n", _("Error: Screen too small"));
517                 exit(EXIT_FAILURE);
518         }
520         screen.cols = COLS;
521         screen.rows = LINES;
523         screen.buf  = g_malloc(screen.cols);
524         screen.buf_size = screen.cols;
525         screen.findbuf = NULL;
526         screen.start_timestamp = time(NULL);
527         screen.last_cmd = CMD_NONE;
529         /* create top window */
530         screen.top_window.rows = 2;
531         screen.top_window.cols = screen.cols;
532         screen.top_window.w = newwin(screen.top_window.rows,
533                                       screen.top_window.cols,
534                                       0, 0);
535         leaveok(screen.top_window.w, TRUE);
536         keypad(screen.top_window.w, TRUE);
538         /* create main window */
539         screen.main_window.rows = screen.rows-4;
540         screen.main_window.cols = screen.cols;
541         screen.main_window.w = newwin(screen.main_window.rows,
542                                        screen.main_window.cols,
543                                        2,
544                                        0);
546         //  leaveok(screen.main_window.w, TRUE); temporary disabled
547         keypad(screen.main_window.w, TRUE);
549         /* create progress window */
550         screen.progress_window.rows = 1;
551         screen.progress_window.cols = screen.cols;
552         screen.progress_window.w = newwin(screen.progress_window.rows,
553                                            screen.progress_window.cols,
554                                            screen.rows-2,
555                                            0);
556         leaveok(screen.progress_window.w, TRUE);
558         /* create status window */
559         screen.status_window.rows = 1;
560         screen.status_window.cols = screen.cols;
561         screen.status_window.w = newwin(screen.status_window.rows,
562                                          screen.status_window.cols,
563                                          screen.rows-1,
564                                          0);
566         leaveok(screen.status_window.w, FALSE);
567         keypad(screen.status_window.w, TRUE);
569 #ifdef ENABLE_COLORS
570         if (options.enable_colors) {
571                 /* set background attributes */
572                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
573                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
574                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
575                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
576                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
577                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
578         }
579 #endif
581         refresh();
583         /* initialize screens */
584         screen_list_init(screen.main_window.w,
585                          screen.main_window.cols, screen.main_window.rows);
587         if (mode_fn->open != NULL)
588                 mode_fn->open(c);
591 void
592 screen_paint(mpdclient_t *c)
594         const char *title = NULL;
596         if (mode_fn->get_title != NULL)
597                 title = mode_fn->get_title(screen.buf, screen.buf_size);
599         /* paint the title/header window */
600         if( title )
601                 paint_top_window(title, c, 1);
602         else
603                 paint_top_window("", c, 1);
605         /* paint the main window */
606         wclear(screen.main_window.w);
607         if (mode_fn->paint != NULL)
608                 mode_fn->paint();
610         paint_progress_window(c);
611         paint_status_window(c);
612         wmove(screen.main_window.w, 0, 0);
613         wnoutrefresh(screen.main_window.w);
615         /* tell curses to update */
616         doupdate();
619 void
620 screen_update(mpdclient_t *c)
622 #ifndef NCMPC_MINI
623         static int repeat = -1;
624         static int random_enabled = -1;
625         static int single = -1;
626         static int consume = -1;
627         static int crossfade = -1;
628         static int dbupdate = -1;
630         /* print a message if mpd status has changed */
631         if (c->status != NULL) {
632                 if (repeat < 0) {
633                         repeat = c->status->repeat;
634                         random_enabled = c->status->random;
635                         single = c->status->single;
636                         consume = c->status->consume;
637                         crossfade = c->status->crossfade;
638                         dbupdate = c->status->updatingDb;
639                 }
641                 if (repeat != c->status->repeat)
642                         screen_status_printf(c->status->repeat ?
643                                              _("Repeat mode is on") :
644                                              _("Repeat mode is off"));
646                 if (random_enabled != c->status->random)
647                         screen_status_printf(c->status->random ?
648                                              _("Random mode is on") :
649                                              _("Random mode is off"));
651                 if (single != c->status->single)
652                         screen_status_printf(c->status->single ?
653                                              /* "single" mode means
654                                                 that MPD will
655                                                 automatically stop
656                                                 after playing one
657                                                 single song */
658                                              _("Single mode is on") :
659                                              _("Single mode is off"));
661                 if (consume != c->status->consume)
662                         screen_status_printf(c->status->consume ?
663                                              /* "consume" mode means
664                                                 that MPD removes each
665                                                 song which has
666                                                 finished playing */
667                                              _("Consume mode is on") :
668                                              _("Consume mode is off"));
670                 if (crossfade != c->status->crossfade)
671                         screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
673                 if (dbupdate && dbupdate != c->status->updatingDb) {
674                         screen_status_printf(_("Database updated"));
675                         mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
676                 }
678                 repeat = c->status->repeat;
679                 single = c->status->single;
680                 consume = c->status->consume;
681                 random_enabled = c->status->random;
682                 crossfade = c->status->crossfade;
683                 dbupdate = c->status->updatingDb;
684         }
686         /* update title/header window */
687         if (welcome && options.welcome_screen_list &&
688             screen.last_cmd==CMD_NONE &&
689             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
690                 paint_top_window("", c, 0);
691         else
692 #endif
693         if (mode_fn->get_title != NULL) {
694                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
695 #ifndef NCMPC_MINI
696                 welcome = FALSE;
697 #endif
698         } else
699                 paint_top_window("", c, 0);
701         /* update the main window */
702         if (mode_fn->update != NULL)
703                 mode_fn->update(c);
705         /* update progress window */
706         paint_progress_window(c);
708         /* update status window */
709         paint_status_window(c);
711         /* move the cursor to the origin */
712         wmove(screen.main_window.w, 0, 0);
713         wnoutrefresh(screen.main_window.w);
715         /* tell curses to update */
716         doupdate();
719 void
720 screen_idle(mpdclient_t *c)
722         if (c->song && seek_id == c->song->id &&
723             (screen.last_cmd == CMD_SEEK_FORWARD ||
724              screen.last_cmd == CMD_SEEK_BACKWARD))
725                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
727         screen.last_cmd = CMD_NONE;
728         seek_id = -1;
731 #ifdef HAVE_GETMOUSE
732 int
733 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
735         MEVENT event;
737         /* retrieve the mouse event from ncurses */
738         getmouse(&event);
739         /* calculate the selected row in the list window */
740         *row = event.y - screen.top_window.rows;
741         /* copy button state bits */
742         *bstate = event.bstate;
743         /* if button 2 was pressed switch screen */
744         if (event.bstate & BUTTON2_CLICKED) {
745                 screen_cmd(c, CMD_SCREEN_NEXT);
746                 return 1;
747         }
749         return 0;
751 #endif
753 static int
754 screen_client_cmd(mpdclient_t *c, command_t cmd)
756         if (c->connection == NULL || c->status == NULL)
757                 return 0;
759         switch(cmd) {
760                 /*
761         case CMD_PLAY:
762                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
763                 break;
764                 */
765         case CMD_PAUSE:
766                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
767                 break;
768         case CMD_STOP:
769                 mpdclient_cmd_stop(c);
770                 break;
771         case CMD_CROP:
772                 mpdclient_cmd_crop(c);
773                 break;
774         case CMD_SEEK_FORWARD:
775                 if (!IS_STOPPED(c->status->state)) {
776                         if (c->song && seek_id != c->song->id) {
777                                 seek_id = c->song->id;
778                                 seek_target_time = c->status->elapsedTime;
779                         }
780                         seek_target_time+=options.seek_time;
781                         if (seek_target_time < c->status->totalTime)
782                                 break;
783                         seek_target_time = c->status->totalTime;
784                         /* seek_target_time=0; */
785                 }
786                 break;
787                 /* fall through... */
788         case CMD_TRACK_NEXT:
789                 if (!IS_STOPPED(c->status->state))
790                         mpdclient_cmd_next(c);
791                 break;
792         case CMD_SEEK_BACKWARD:
793                 if (!IS_STOPPED(c->status->state)) {
794                         if (seek_id != c->song->id) {
795                                 seek_id = c->song->id;
796                                 seek_target_time = c->status->elapsedTime;
797                         }
798                         seek_target_time-=options.seek_time;
799                         if (seek_target_time < 0)
800                                 seek_target_time=0;
801                 }
802                 break;
803         case CMD_TRACK_PREVIOUS:
804                 if (!IS_STOPPED(c->status->state))
805                         mpdclient_cmd_prev(c);
806                 break;
807         case CMD_SHUFFLE:
808                 if (mpdclient_cmd_shuffle(c) == 0)
809                         screen_status_message(_("Shuffled playlist"));
810                 break;
811         case CMD_CLEAR:
812                 if (mpdclient_cmd_clear(c) == 0)
813                         screen_status_message(_("Cleared playlist"));
814                 break;
815         case CMD_REPEAT:
816                 mpdclient_cmd_repeat(c, !c->status->repeat);
817                 break;
818         case CMD_RANDOM:
819                 mpdclient_cmd_random(c, !c->status->random);
820                 break;
821         case CMD_SINGLE:
822                 mpdclient_cmd_single(c, !c->status->single);
823                 break;
824         case CMD_CONSUME:
825                 mpdclient_cmd_consume(c, !c->status->consume);
826                 break;
827         case CMD_CROSSFADE:
828                 if (c->status->crossfade)
829                         mpdclient_cmd_crossfade(c, 0);
830                 else
831                         mpdclient_cmd_crossfade(c, options.crossfade_time);
832                 break;
833         case CMD_DB_UPDATE:
834                 if (!c->status->updatingDb) {
835                         if( mpdclient_cmd_db_update(c,NULL)==0 )
836                                 screen_status_printf(_("Database update started"));
837                 } else
838                         screen_status_printf(_("Database update running..."));
839                 break;
840         case CMD_VOLUME_UP:
841                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
842                         mpdclient_cmd_volume(c, ++c->status->volume);
843                 break;
844         case CMD_VOLUME_DOWN:
845                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
846                         mpdclient_cmd_volume(c, --c->status->volume);
847                 break;
849         default:
850                 return 0;
851         }
853         return 1;
856 void
857 screen_cmd(mpdclient_t *c, command_t cmd)
859         screen.last_cmd = cmd;
860 #ifndef NCMPC_MINI
861         welcome = FALSE;
862 #endif
864         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
865                 return;
867         if (screen_client_cmd(c, cmd))
868                 return;
870         switch(cmd) {
871         case CMD_TOGGLE_FIND_WRAP:
872                 options.find_wrap = !options.find_wrap;
873                 screen_status_printf(options.find_wrap ?
874                                      _("Find mode: Wrapped") :
875                                      _("Find mode: Normal"));
876                 break;
877         case CMD_TOGGLE_AUTOCENTER:
878                 options.auto_center = !options.auto_center;
879                 screen_status_printf(options.auto_center ?
880                                      _("Auto center mode: On") :
881                                      _("Auto center mode: Off"));
882                 break;
883         case CMD_SCREEN_UPDATE:
884                 screen_paint(c);
885                 break;
886         case CMD_SCREEN_PREVIOUS:
887                 screen_next_mode(c, -1);
888                 break;
889         case CMD_SCREEN_NEXT:
890                 screen_next_mode(c, 1);
891                 break;
892         case CMD_SCREEN_PLAY:
893                 screen_switch(&screen_playlist, c);
894                 break;
895         case CMD_SCREEN_FILE:
896                 screen_switch(&screen_browse, c);
897                 break;
898 #ifdef ENABLE_HELP_SCREEN
899         case CMD_SCREEN_HELP:
900                 screen_switch(&screen_help, c);
901                 break;
902 #endif
903 #ifdef ENABLE_SEARCH_SCREEN
904         case CMD_SCREEN_SEARCH:
905                 screen_switch(&screen_search, c);
906                 break;
907 #endif
908 #ifdef ENABLE_ARTIST_SCREEN
909         case CMD_SCREEN_ARTIST:
910                 screen_switch(&screen_artist, c);
911                 break;
912 #endif
913 #ifdef ENABLE_SONG_SCREEN
914         case CMD_SCREEN_SONG:
915                 screen_switch(&screen_song, c);
916                 break;
917 #endif
918 #ifdef ENABLE_KEYDEF_SCREEN
919         case CMD_SCREEN_KEYDEF:
920                 screen_switch(&screen_keydef, c);
921                 break;
922 #endif
923 #ifdef ENABLE_LYRICS_SCREEN
924         case CMD_SCREEN_LYRICS:
925                 screen_switch(&screen_lyrics, c);
926                 break;
927 #endif
928 #ifdef ENABLE_OUTPUTS_SCREEN
929         case CMD_SCREEN_OUTPUTS:
930                 screen_switch(&screen_outputs, c);
931                 break;
932         case CMD_SCREEN_SWAP:
933                 screen_swap(c, NULL);
934                 break;
935 #endif
937         default:
938                 break;
939         }