Code

929766b998a8593306af867207f026285a133451
[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         int state;
300         mpd_Song *song = c->song;
301         int elapsedTime = 0;
302 #ifdef NCMPC_MINI
303         static char bitrate[1];
304 #else
305         char bitrate[16];
306 #endif
307         const char *str = NULL;
308         int x = 0;
310         if( time(NULL) - screen.status_timestamp <= options.status_message_time )
311                 return;
313         wmove(w, 0, 0);
314         wclrtoeol(w);
315         colors_use(w, COLOR_STATUS_BOLD);
317         state = status == NULL ? MPD_STATUS_STATE_UNKNOWN : status->state;
319         switch (state) {
320         case MPD_STATUS_STATE_PLAY:
321                 str = _("Playing:");
322                 break;
323         case MPD_STATUS_STATE_PAUSE:
324                 str = _("[Paused]");
325                 break;
326         case MPD_STATUS_STATE_STOP:
327         default:
328                 break;
329         }
331         if (str) {
332                 waddstr(w, str);
333                 x += utf8_width(str) + 1;
334         }
336         /* create time string */
337         memset(screen.buf, 0, screen.buf_size);
338         if (IS_PLAYING(state) || IS_PAUSED(state)) {
339                 if (status->totalTime > 0) {
340                         /*checks the conf to see whether to display elapsed or remaining time */
341                         if(!strcmp(options.timedisplay_type,"elapsed"))
342                                 elapsedTime = c->status->elapsedTime;
343                         else if(!strcmp(options.timedisplay_type,"remaining"))
344                                 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
346                         if( c->song && seek_id == c->song->id )
347                                 elapsedTime = seek_target_time;
349                         /* display bitrate if visible-bitrate is true */
350 #ifndef NCMPC_MINI
351                         if (options.visible_bitrate) {
352                                 g_snprintf(bitrate, 16,
353                                            " [%d kbps]", status->bitRate);
354                         } else {
355                                 bitrate[0] = '\0';
356                         }
357 #endif
359                         /*write out the time, using hours if time over 60 minutes*/
360                         if (c->status->totalTime > 3600) {
361                                 g_snprintf(screen.buf, screen.buf_size,
362                                            "%s [%i:%02i:%02i/%i:%02i:%02i]",
363                                            bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
364                                            status->totalTime/3600, (status->totalTime%3600)/60,  status->totalTime%60);
365                         } else {
366                                 g_snprintf(screen.buf, screen.buf_size,
367                                            "%s [%i:%02i/%i:%02i]",
368                                            bitrate, elapsedTime/60, elapsedTime%60,
369                                            status->totalTime/60,   status->totalTime%60 );
370                         }
371 #ifndef NCMPC_MINI
372                 } else {
373                         g_snprintf(screen.buf, screen.buf_size,
374                                    " [%d kbps]", status->bitRate );
375 #endif
376                 }
377 #ifndef NCMPC_MINI
378         } else {
379                 if (options.display_time) {
380                         time_t timep;
382                         time(&timep);
383                         strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
384                 }
385 #endif
386         }
388         /* display song */
389         if (status != NULL && (IS_PLAYING(status->state) ||
390                                IS_PAUSED(status->state))) {
391                 char songname[MAX_SONGNAME_LENGTH];
392 #ifndef NCMPC_MINI
393                 int width = COLS - x - utf8_width(screen.buf);
394 #endif
396                 if (song)
397                         strfsong(songname, MAX_SONGNAME_LENGTH,
398                                  options.status_format, song);
399                 else
400                         songname[0] = '\0';
402                 colors_use(w, COLOR_STATUS);
403                 /* scroll if the song name is to long */
404 #ifndef NCMPC_MINI
405                 if (options.scroll && utf8_width(songname) > (unsigned)width) {
406                         static  scroll_state_t st = { 0, 0 };
407                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
409                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
410                         g_free(tmp);
411                 }
412 #endif
413                 //mvwaddnstr(w, 0, x, songname, width);
414                 mvwaddstr(w, 0, x, songname);
415         }
417         /* display time string */
418         if (screen.buf[0]) {
419                 x = screen.status_window.cols - strlen(screen.buf);
420                 colors_use(w, COLOR_STATUS_TIME);
421                 mvwaddstr(w, 0, x, screen.buf);
422         }
424         wnoutrefresh(w);
427 void
428 screen_exit(void)
430         if (mode_fn->close != NULL)
431                 mode_fn->close();
433         screen_list_exit();
435         string_list_free(screen.find_history);
436         g_free(screen.buf);
437         g_free(screen.findbuf);
440 void
441 screen_resize(struct mpdclient *c)
443         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
444                 screen_exit();
445                 fprintf(stderr, "%s", _("Error: Screen too small"));
446                 exit(EXIT_FAILURE);
447         }
449         resizeterm(LINES, COLS);
451         screen.cols = COLS;
452         screen.rows = LINES;
454         /* top window */
455         screen.top_window.cols = screen.cols;
456         wresize(screen.top_window.w, 2, screen.cols);
458         /* main window */
459         screen.main_window.cols = screen.cols;
460         screen.main_window.rows = screen.rows-4;
461         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
462         wclear(screen.main_window.w);
464         /* progress window */
465         screen.progress_window.cols = screen.cols;
466         wresize(screen.progress_window.w, 1, screen.cols);
467         mvwin(screen.progress_window.w, screen.rows-2, 0);
469         /* status window */
470         screen.status_window.cols = screen.cols;
471         wresize(screen.status_window.w, 1, screen.cols);
472         mvwin(screen.status_window.w, screen.rows-1, 0);
474         screen.buf_size = screen.cols;
475         g_free(screen.buf);
476         screen.buf = g_malloc(screen.cols);
478         /* resize all screens */
479         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
481         /* ? - without this the cursor becomes visible with aterm & Eterm */
482         curs_set(1);
483         curs_set(0);
485         screen_paint(c);
488 void
489 screen_status_message(const char *msg)
491         WINDOW *w = screen.status_window.w;
493         wmove(w, 0, 0);
494         wclrtoeol(w);
495         colors_use(w, COLOR_STATUS_ALERT);
496         waddstr(w, msg);
497         wnoutrefresh(w);
498         screen.status_timestamp = time(NULL);
501 void
502 screen_status_printf(const char *format, ...)
504         char *msg;
505         va_list ap;
507         va_start(ap,format);
508         msg = g_strdup_vprintf(format,ap);
509         va_end(ap);
510         screen_status_message(msg);
511         g_free(msg);
514 void
515 screen_init(mpdclient_t *c)
517         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
518                 fprintf(stderr, "%s\n", _("Error: Screen too small"));
519                 exit(EXIT_FAILURE);
520         }
522         screen.cols = COLS;
523         screen.rows = LINES;
525         screen.buf  = g_malloc(screen.cols);
526         screen.buf_size = screen.cols;
527         screen.findbuf = NULL;
528         screen.start_timestamp = time(NULL);
529         screen.last_cmd = CMD_NONE;
531         /* create top window */
532         screen.top_window.rows = 2;
533         screen.top_window.cols = screen.cols;
534         screen.top_window.w = newwin(screen.top_window.rows,
535                                       screen.top_window.cols,
536                                       0, 0);
537         leaveok(screen.top_window.w, TRUE);
538         keypad(screen.top_window.w, TRUE);
540         /* create main window */
541         screen.main_window.rows = screen.rows-4;
542         screen.main_window.cols = screen.cols;
543         screen.main_window.w = newwin(screen.main_window.rows,
544                                        screen.main_window.cols,
545                                        2,
546                                        0);
548         //  leaveok(screen.main_window.w, TRUE); temporary disabled
549         keypad(screen.main_window.w, TRUE);
551         /* create progress window */
552         screen.progress_window.rows = 1;
553         screen.progress_window.cols = screen.cols;
554         screen.progress_window.w = newwin(screen.progress_window.rows,
555                                            screen.progress_window.cols,
556                                            screen.rows-2,
557                                            0);
558         leaveok(screen.progress_window.w, TRUE);
560         /* create status window */
561         screen.status_window.rows = 1;
562         screen.status_window.cols = screen.cols;
563         screen.status_window.w = newwin(screen.status_window.rows,
564                                          screen.status_window.cols,
565                                          screen.rows-1,
566                                          0);
568         leaveok(screen.status_window.w, FALSE);
569         keypad(screen.status_window.w, TRUE);
571 #ifdef ENABLE_COLORS
572         if (options.enable_colors) {
573                 /* set background attributes */
574                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
575                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
576                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
577                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
578                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
579                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
580         }
581 #endif
583         refresh();
585         /* initialize screens */
586         screen_list_init(screen.main_window.w,
587                          screen.main_window.cols, screen.main_window.rows);
589         if (mode_fn->open != NULL)
590                 mode_fn->open(c);
593 void
594 screen_paint(mpdclient_t *c)
596         const char *title = NULL;
598         if (mode_fn->get_title != NULL)
599                 title = mode_fn->get_title(screen.buf, screen.buf_size);
601         /* paint the title/header window */
602         if( title )
603                 paint_top_window(title, c, 1);
604         else
605                 paint_top_window("", c, 1);
607         /* paint the main window */
608         wclear(screen.main_window.w);
609         if (mode_fn->paint != NULL)
610                 mode_fn->paint();
612         paint_progress_window(c);
613         paint_status_window(c);
614         wmove(screen.main_window.w, 0, 0);
615         wnoutrefresh(screen.main_window.w);
617         /* tell curses to update */
618         doupdate();
621 void
622 screen_update(mpdclient_t *c)
624 #ifndef NCMPC_MINI
625         static int repeat = -1;
626         static int random_enabled = -1;
627         static int single = -1;
628         static int consume = -1;
629         static int crossfade = -1;
630         static int dbupdate = -1;
632         /* print a message if mpd status has changed */
633         if (c->status != NULL) {
634                 if (repeat < 0) {
635                         repeat = c->status->repeat;
636                         random_enabled = c->status->random;
637                         single = c->status->single;
638                         consume = c->status->consume;
639                         crossfade = c->status->crossfade;
640                         dbupdate = c->status->updatingDb;
641                 }
643                 if (repeat != c->status->repeat)
644                         screen_status_printf(c->status->repeat ?
645                                              _("Repeat mode is on") :
646                                              _("Repeat mode is off"));
648                 if (random_enabled != c->status->random)
649                         screen_status_printf(c->status->random ?
650                                              _("Random mode is on") :
651                                              _("Random mode is off"));
653                 if (single != c->status->single)
654                         screen_status_printf(c->status->single ?
655                                              /* "single" mode means
656                                                 that MPD will
657                                                 automatically stop
658                                                 after playing one
659                                                 single song */
660                                              _("Single mode is on") :
661                                              _("Single mode is off"));
663                 if (consume != c->status->consume)
664                         screen_status_printf(c->status->consume ?
665                                              /* "consume" mode means
666                                                 that MPD removes each
667                                                 song which has
668                                                 finished playing */
669                                              _("Consume mode is on") :
670                                              _("Consume mode is off"));
672                 if (crossfade != c->status->crossfade)
673                         screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
675                 if (dbupdate && dbupdate != c->status->updatingDb) {
676                         screen_status_printf(_("Database updated"));
677                         mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
678                 }
680                 repeat = c->status->repeat;
681                 single = c->status->single;
682                 consume = c->status->consume;
683                 random_enabled = c->status->random;
684                 crossfade = c->status->crossfade;
685                 dbupdate = c->status->updatingDb;
686         }
688         /* update title/header window */
689         if (welcome && options.welcome_screen_list &&
690             screen.last_cmd==CMD_NONE &&
691             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
692                 paint_top_window("", c, 0);
693         else
694 #endif
695         if (mode_fn->get_title != NULL) {
696                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
697 #ifndef NCMPC_MINI
698                 welcome = FALSE;
699 #endif
700         } else
701                 paint_top_window("", c, 0);
703         /* update the main window */
704         if (mode_fn->update != NULL)
705                 mode_fn->update(c);
707         /* update progress window */
708         paint_progress_window(c);
710         /* update status window */
711         paint_status_window(c);
713         /* move the cursor to the origin */
714         wmove(screen.main_window.w, 0, 0);
715         wnoutrefresh(screen.main_window.w);
717         /* tell curses to update */
718         doupdate();
721 void
722 screen_idle(mpdclient_t *c)
724         if (c->song && seek_id == c->song->id &&
725             (screen.last_cmd == CMD_SEEK_FORWARD ||
726              screen.last_cmd == CMD_SEEK_BACKWARD))
727                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
729         screen.last_cmd = CMD_NONE;
730         seek_id = -1;
733 #ifdef HAVE_GETMOUSE
734 int
735 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
737         MEVENT event;
739         /* retrieve the mouse event from ncurses */
740         getmouse(&event);
741         /* calculate the selected row in the list window */
742         *row = event.y - screen.top_window.rows;
743         /* copy button state bits */
744         *bstate = event.bstate;
745         /* if button 2 was pressed switch screen */
746         if (event.bstate & BUTTON2_CLICKED) {
747                 screen_cmd(c, CMD_SCREEN_NEXT);
748                 return 1;
749         }
751         return 0;
753 #endif
755 static int
756 screen_client_cmd(mpdclient_t *c, command_t cmd)
758         if (c->connection == NULL || c->status == NULL)
759                 return 0;
761         switch(cmd) {
762                 /*
763         case CMD_PLAY:
764                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
765                 break;
766                 */
767         case CMD_PAUSE:
768                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
769                 break;
770         case CMD_STOP:
771                 mpdclient_cmd_stop(c);
772                 break;
773         case CMD_CROP:
774                 mpdclient_cmd_crop(c);
775                 break;
776         case CMD_SEEK_FORWARD:
777                 if (!IS_STOPPED(c->status->state)) {
778                         if (c->song && seek_id != c->song->id) {
779                                 seek_id = c->song->id;
780                                 seek_target_time = c->status->elapsedTime;
781                         }
782                         seek_target_time+=options.seek_time;
783                         if (seek_target_time < c->status->totalTime)
784                                 break;
785                         seek_target_time = c->status->totalTime;
786                         /* seek_target_time=0; */
787                 }
788                 break;
789                 /* fall through... */
790         case CMD_TRACK_NEXT:
791                 if (!IS_STOPPED(c->status->state))
792                         mpdclient_cmd_next(c);
793                 break;
794         case CMD_SEEK_BACKWARD:
795                 if (!IS_STOPPED(c->status->state)) {
796                         if (seek_id != c->song->id) {
797                                 seek_id = c->song->id;
798                                 seek_target_time = c->status->elapsedTime;
799                         }
800                         seek_target_time-=options.seek_time;
801                         if (seek_target_time < 0)
802                                 seek_target_time=0;
803                 }
804                 break;
805         case CMD_TRACK_PREVIOUS:
806                 if (!IS_STOPPED(c->status->state))
807                         mpdclient_cmd_prev(c);
808                 break;
809         case CMD_SHUFFLE:
810                 if (mpdclient_cmd_shuffle(c) == 0)
811                         screen_status_message(_("Shuffled playlist"));
812                 break;
813         case CMD_CLEAR:
814                 if (mpdclient_cmd_clear(c) == 0)
815                         screen_status_message(_("Cleared playlist"));
816                 break;
817         case CMD_REPEAT:
818                 mpdclient_cmd_repeat(c, !c->status->repeat);
819                 break;
820         case CMD_RANDOM:
821                 mpdclient_cmd_random(c, !c->status->random);
822                 break;
823         case CMD_SINGLE:
824                 mpdclient_cmd_single(c, !c->status->single);
825                 break;
826         case CMD_CONSUME:
827                 mpdclient_cmd_consume(c, !c->status->consume);
828                 break;
829         case CMD_CROSSFADE:
830                 if (c->status->crossfade)
831                         mpdclient_cmd_crossfade(c, 0);
832                 else
833                         mpdclient_cmd_crossfade(c, options.crossfade_time);
834                 break;
835         case CMD_DB_UPDATE:
836                 if (!c->status->updatingDb) {
837                         if( mpdclient_cmd_db_update(c,NULL)==0 )
838                                 screen_status_printf(_("Database update started"));
839                 } else
840                         screen_status_printf(_("Database update running..."));
841                 break;
842         case CMD_VOLUME_UP:
843                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
844                         mpdclient_cmd_volume(c, ++c->status->volume);
845                 break;
846         case CMD_VOLUME_DOWN:
847                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
848                         mpdclient_cmd_volume(c, --c->status->volume);
849                 break;
851         default:
852                 return 0;
853         }
855         return 1;
858 void
859 screen_cmd(mpdclient_t *c, command_t cmd)
861         screen.last_cmd = cmd;
862 #ifndef NCMPC_MINI
863         welcome = FALSE;
864 #endif
866         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
867                 return;
869         if (screen_client_cmd(c, cmd))
870                 return;
872         switch(cmd) {
873         case CMD_TOGGLE_FIND_WRAP:
874                 options.find_wrap = !options.find_wrap;
875                 screen_status_printf(options.find_wrap ?
876                                      _("Find mode: Wrapped") :
877                                      _("Find mode: Normal"));
878                 break;
879         case CMD_TOGGLE_AUTOCENTER:
880                 options.auto_center = !options.auto_center;
881                 screen_status_printf(options.auto_center ?
882                                      _("Auto center mode: On") :
883                                      _("Auto center mode: Off"));
884                 break;
885         case CMD_SCREEN_UPDATE:
886                 screen_paint(c);
887                 break;
888         case CMD_SCREEN_PREVIOUS:
889                 screen_next_mode(c, -1);
890                 break;
891         case CMD_SCREEN_NEXT:
892                 screen_next_mode(c, 1);
893                 break;
894         case CMD_SCREEN_PLAY:
895                 screen_switch(&screen_playlist, c);
896                 break;
897         case CMD_SCREEN_FILE:
898                 screen_switch(&screen_browse, c);
899                 break;
900 #ifdef ENABLE_HELP_SCREEN
901         case CMD_SCREEN_HELP:
902                 screen_switch(&screen_help, c);
903                 break;
904 #endif
905 #ifdef ENABLE_SEARCH_SCREEN
906         case CMD_SCREEN_SEARCH:
907                 screen_switch(&screen_search, c);
908                 break;
909 #endif
910 #ifdef ENABLE_ARTIST_SCREEN
911         case CMD_SCREEN_ARTIST:
912                 screen_switch(&screen_artist, c);
913                 break;
914 #endif
915 #ifdef ENABLE_SONG_SCREEN
916         case CMD_SCREEN_SONG:
917                 screen_switch(&screen_song, c);
918                 break;
919 #endif
920 #ifdef ENABLE_KEYDEF_SCREEN
921         case CMD_SCREEN_KEYDEF:
922                 screen_switch(&screen_keydef, c);
923                 break;
924 #endif
925 #ifdef ENABLE_LYRICS_SCREEN
926         case CMD_SCREEN_LYRICS:
927                 screen_switch(&screen_lyrics, c);
928                 break;
929 #endif
930 #ifdef ENABLE_OUTPUTS_SCREEN
931         case CMD_SCREEN_OUTPUTS:
932                 screen_switch(&screen_outputs, c);
933                 break;
934         case CMD_SCREEN_SWAP:
935                 screen_swap(c, NULL);
936                 break;
937 #endif
939         default:
940                 break;
941         }