Code

mpdclient: added mpdclient_cmd_volume_up(), mpdclient_cmd_volume_down()
[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                 }
679                 repeat = c->status->repeat;
680                 single = c->status->single;
681                 consume = c->status->consume;
682                 random_enabled = c->status->random;
683                 crossfade = c->status->crossfade;
684                 dbupdate = c->status->updatingDb;
685         }
687         /* update title/header window */
688         if (welcome && options.welcome_screen_list &&
689             screen.last_cmd==CMD_NONE &&
690             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
691                 paint_top_window("", c, 0);
692         else
693 #endif
694         if (mode_fn->get_title != NULL) {
695                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
696 #ifndef NCMPC_MINI
697                 welcome = FALSE;
698 #endif
699         } else
700                 paint_top_window("", c, 0);
702         /* update the main window */
703         if (mode_fn->update != NULL)
704                 mode_fn->update(c);
706         /* update progress window */
707         paint_progress_window(c);
709         /* update status window */
710         paint_status_window(c);
712         /* move the cursor to the origin */
713         wmove(screen.main_window.w, 0, 0);
714         wnoutrefresh(screen.main_window.w);
716         /* tell curses to update */
717         doupdate();
720 void
721 screen_idle(mpdclient_t *c)
723         if (c->song && seek_id == c->song->id &&
724             (screen.last_cmd == CMD_SEEK_FORWARD ||
725              screen.last_cmd == CMD_SEEK_BACKWARD))
726                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
728         screen.last_cmd = CMD_NONE;
729         seek_id = -1;
732 #ifdef HAVE_GETMOUSE
733 int
734 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
736         MEVENT event;
738         /* retrieve the mouse event from ncurses */
739         getmouse(&event);
740         /* calculate the selected row in the list window */
741         *row = event.y - screen.top_window.rows;
742         /* copy button state bits */
743         *bstate = event.bstate;
744         /* if button 2 was pressed switch screen */
745         if (event.bstate & BUTTON2_CLICKED) {
746                 screen_cmd(c, CMD_SCREEN_NEXT);
747                 return 1;
748         }
750         return 0;
752 #endif
754 static int
755 screen_client_cmd(mpdclient_t *c, command_t cmd)
757         if (c->connection == NULL || c->status == NULL)
758                 return 0;
760         switch(cmd) {
761                 /*
762         case CMD_PLAY:
763                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
764                 break;
765                 */
766         case CMD_PAUSE:
767                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
768                 break;
769         case CMD_STOP:
770                 mpdclient_cmd_stop(c);
771                 break;
772         case CMD_CROP:
773                 mpdclient_cmd_crop(c);
774                 break;
775         case CMD_SEEK_FORWARD:
776                 if (!IS_STOPPED(c->status->state)) {
777                         if (c->song && seek_id != c->song->id) {
778                                 seek_id = c->song->id;
779                                 seek_target_time = c->status->elapsedTime;
780                         }
781                         seek_target_time+=options.seek_time;
782                         if (seek_target_time < c->status->totalTime)
783                                 break;
784                         seek_target_time = c->status->totalTime;
785                         /* seek_target_time=0; */
786                 }
787                 break;
788                 /* fall through... */
789         case CMD_TRACK_NEXT:
790                 if (!IS_STOPPED(c->status->state))
791                         mpdclient_cmd_next(c);
792                 break;
793         case CMD_SEEK_BACKWARD:
794                 if (!IS_STOPPED(c->status->state)) {
795                         if (seek_id != c->song->id) {
796                                 seek_id = c->song->id;
797                                 seek_target_time = c->status->elapsedTime;
798                         }
799                         seek_target_time-=options.seek_time;
800                         if (seek_target_time < 0)
801                                 seek_target_time=0;
802                 }
803                 break;
804         case CMD_TRACK_PREVIOUS:
805                 if (!IS_STOPPED(c->status->state))
806                         mpdclient_cmd_prev(c);
807                 break;
808         case CMD_SHUFFLE:
809                 if (mpdclient_cmd_shuffle(c) == 0)
810                         screen_status_message(_("Shuffled playlist"));
811                 break;
812         case CMD_CLEAR:
813                 if (mpdclient_cmd_clear(c) == 0)
814                         screen_status_message(_("Cleared playlist"));
815                 break;
816         case CMD_REPEAT:
817                 mpdclient_cmd_repeat(c, !c->status->repeat);
818                 break;
819         case CMD_RANDOM:
820                 mpdclient_cmd_random(c, !c->status->random);
821                 break;
822         case CMD_SINGLE:
823                 mpdclient_cmd_single(c, !c->status->single);
824                 break;
825         case CMD_CONSUME:
826                 mpdclient_cmd_consume(c, !c->status->consume);
827                 break;
828         case CMD_CROSSFADE:
829                 if (c->status->crossfade)
830                         mpdclient_cmd_crossfade(c, 0);
831                 else
832                         mpdclient_cmd_crossfade(c, options.crossfade_time);
833                 break;
834         case CMD_DB_UPDATE:
835                 if (!c->status->updatingDb) {
836                         if( mpdclient_cmd_db_update(c,NULL)==0 )
837                                 screen_status_printf(_("Database update started"));
838                 } else
839                         screen_status_printf(_("Database update running..."));
840                 break;
841         case CMD_VOLUME_UP:
842                 mpdclient_cmd_volume_up(c);
843                 break;
844         case CMD_VOLUME_DOWN:
845                 mpdclient_cmd_volume_down(c);
846                 break;
848         default:
849                 return 0;
850         }
852         return 1;
855 void
856 screen_cmd(mpdclient_t *c, command_t cmd)
858         screen.last_cmd = cmd;
859 #ifndef NCMPC_MINI
860         welcome = FALSE;
861 #endif
863         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
864                 return;
866         if (screen_client_cmd(c, cmd))
867                 return;
869         switch(cmd) {
870         case CMD_TOGGLE_FIND_WRAP:
871                 options.find_wrap = !options.find_wrap;
872                 screen_status_printf(options.find_wrap ?
873                                      _("Find mode: Wrapped") :
874                                      _("Find mode: Normal"));
875                 break;
876         case CMD_TOGGLE_AUTOCENTER:
877                 options.auto_center = !options.auto_center;
878                 screen_status_printf(options.auto_center ?
879                                      _("Auto center mode: On") :
880                                      _("Auto center mode: Off"));
881                 break;
882         case CMD_SCREEN_UPDATE:
883                 screen_paint(c);
884                 break;
885         case CMD_SCREEN_PREVIOUS:
886                 screen_next_mode(c, -1);
887                 break;
888         case CMD_SCREEN_NEXT:
889                 screen_next_mode(c, 1);
890                 break;
891         case CMD_SCREEN_PLAY:
892                 screen_switch(&screen_playlist, c);
893                 break;
894         case CMD_SCREEN_FILE:
895                 screen_switch(&screen_browse, c);
896                 break;
897 #ifdef ENABLE_HELP_SCREEN
898         case CMD_SCREEN_HELP:
899                 screen_switch(&screen_help, c);
900                 break;
901 #endif
902 #ifdef ENABLE_SEARCH_SCREEN
903         case CMD_SCREEN_SEARCH:
904                 screen_switch(&screen_search, c);
905                 break;
906 #endif
907 #ifdef ENABLE_ARTIST_SCREEN
908         case CMD_SCREEN_ARTIST:
909                 screen_switch(&screen_artist, c);
910                 break;
911 #endif
912 #ifdef ENABLE_SONG_SCREEN
913         case CMD_SCREEN_SONG:
914                 screen_switch(&screen_song, c);
915                 break;
916 #endif
917 #ifdef ENABLE_KEYDEF_SCREEN
918         case CMD_SCREEN_KEYDEF:
919                 screen_switch(&screen_keydef, c);
920                 break;
921 #endif
922 #ifdef ENABLE_LYRICS_SCREEN
923         case CMD_SCREEN_LYRICS:
924                 screen_switch(&screen_lyrics, c);
925                 break;
926 #endif
927 #ifdef ENABLE_OUTPUTS_SCREEN
928         case CMD_SCREEN_OUTPUTS:
929                 screen_switch(&screen_outputs, c);
930                 break;
931         case CMD_SCREEN_SWAP:
932                 screen_swap(c, NULL);
933                 break;
934 #endif
936         default:
937                 break;
938         }