Code

screen: Added screen swap command
[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
4  
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 /** status message time [s] */
49 static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
51 /* minumum window size */
52 static const int SCREEN_MIN_COLS = 14;
53 static const int SCREEN_MIN_ROWS = 5;
55 /* screens */
57 #ifndef NCMPC_MINI
58 static gboolean welcome = TRUE;
59 #endif
61 struct screen screen;
62 static const struct screen_functions *mode_fn = &screen_playlist;
63 static const struct screen_functions *mode_fn_prev = &screen_playlist;
64 static int seek_id = -1;
65 static int seek_target_time = 0;
67 gboolean
68 screen_is_visible(const struct screen_functions *sf)
69 {
70         return sf == mode_fn;
71 }
73 void
74 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
75 {
76         assert(sf != NULL);
78         if (sf == mode_fn)
79                 return;
81         mode_fn_prev = mode_fn;
83         /* close the old mode */
84         if (mode_fn->close != NULL)
85                 mode_fn->close();
87         /* get functions for the new mode */
88         mode_fn = sf;
90         /* open the new mode */
91         if (mode_fn->open != NULL)
92                 mode_fn->open(c);
94         screen_paint(c);
95 }
97 static int
98 find_configured_screen(const char *name)
99 {
100         unsigned i;
102         for (i = 0; options.screen_list[i] != NULL; ++i)
103                 if (strcmp(options.screen_list[i], name) == 0)
104                         return i;
106         return -1;
109 static void
110 screen_next_mode(mpdclient_t *c, int offset)
112         int max = g_strv_length(options.screen_list);
113         int current, next;
114         const struct screen_functions *sf;
116         /* find current screen */
117         current = find_configured_screen(screen_get_name(mode_fn));
118         next = current + offset;
119         if (next<0)
120                 next = max-1;
121         else if (next>=max)
122                 next = 0;
124         sf = screen_lookup_name(options.screen_list[next]);
125         if (sf != NULL)
126                 screen_switch(sf, c);
129 #ifndef NCMPC_MINI
130 static void
131 print_hotkey(WINDOW *w, command_t cmd, const char *label)
133         colors_use(w, COLOR_TITLE_BOLD);
134         waddstr(w, get_key_names(cmd, FALSE));
135         colors_use(w, COLOR_TITLE);
136         waddch(w, ':');
137         waddstr(w, label);
138         waddch(w, ' ');
139         waddch(w, ' ');
141 #endif
143 static void
144 paint_top_window2(const char *header, mpdclient_t *c)
146         char flags[5];
147         WINDOW *w = screen.top_window.w;
148         char buf[32];
150         if (header[0]) {
151                 colors_use(w, COLOR_TITLE_BOLD);
152                 mvwaddstr(w, 0, 0, header);
153 #ifndef NCMPC_MINI
154         } else {
155 #ifdef ENABLE_HELP_SCREEN
156                 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
157 #endif
158                 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
159                 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
160 #ifdef ENABLE_ARTIST_SCREEN
161                 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
162 #endif
163 #ifdef ENABLE_SEARCH_SCREEN
164                 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
165 #endif
166 #ifdef ENABLE_LYRICS_SCREEN
167                 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
168 #endif
169 #ifdef ENABLE_OUTPUTS_SCREEN
170                 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
171 #endif
172 #endif
173         }
175         if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
176                 g_snprintf(buf, 32, _("Volume n/a "));
177         } else {
178                 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
179         }
180         colors_use(w, COLOR_TITLE);
181         mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
183         flags[0] = 0;
184         if (c->status != NULL) {
185                 if (c->status->repeat)
186                         g_strlcat(flags, "r", sizeof(flags));
187                 if (c->status->random)
188                         g_strlcat(flags, "z", sizeof(flags));;
189                 if (c->status->crossfade)
190                         g_strlcat(flags, "x", sizeof(flags));
191                 if (c->status->updatingDb)
192                         g_strlcat(flags, "U", sizeof(flags));
193         }
195         colors_use(w, COLOR_LINE);
196         mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
197         if (flags[0]) {
198                 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
199                 waddch(w, '[');
200                 colors_use(w, COLOR_LINE_BOLD);
201                 waddstr(w, flags);
202                 colors_use(w, COLOR_LINE);
203                 waddch(w, ']');
204         }
205         wnoutrefresh(w);
208 static void
209 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
211         static int prev_volume = -1;
212         static unsigned prev_header_len = -1;
213         WINDOW *w = screen.top_window.w;
215         if (prev_header_len != utf8_width(header)) {
216                 prev_header_len = utf8_width(header);
217                 full_repaint = 1;
218         }
220         if (full_repaint) {
221                 wmove(w, 0, 0);
222                 wclrtoeol(w);
223         }
225         if ((c->status != NULL && prev_volume != c->status->volume) ||
226             full_repaint)
227                 paint_top_window2(header, c);
230 static void
231 paint_progress_window(mpdclient_t *c)
233         double p;
234         int width;
235         int elapsedTime;
237         if (c->status==NULL || IS_STOPPED(c->status->state)) {
238                 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
239                          screen.progress_window.cols);
240                 wnoutrefresh(screen.progress_window.w);
241                 return;
242         }
244         if (c->song && seek_id == c->song->id)
245                 elapsedTime = seek_target_time;
246         else
247                 elapsedTime = c->status->elapsedTime;
249         p = ((double) elapsedTime) / ((double) c->status->totalTime);
251         width = (int) (p * (double) screen.progress_window.cols);
252         mvwhline(screen.progress_window.w,
253                  0, 0,
254                  ACS_HLINE,
255                  screen.progress_window.cols);
256         whline(screen.progress_window.w, '=', width-1);
257         mvwaddch(screen.progress_window.w, 0, width-1, 'O');
258         wnoutrefresh(screen.progress_window.w);
261 static void
262 paint_status_window(mpdclient_t *c)
264         WINDOW *w = screen.status_window.w;
265         mpd_Status *status = c->status;
266         mpd_Song *song = c->song;
267         int elapsedTime = 0;
268 #ifdef NCMPC_MINI
269         static char bitrate[1];
270 #else
271         char bitrate[16];
272 #endif
273         const char *str = NULL;
274         int x = 0;
276         if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
277                 return;
279         wmove(w, 0, 0);
280         wclrtoeol(w);
281         colors_use(w, COLOR_STATUS_BOLD);
283         switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
284         case MPD_STATUS_STATE_PLAY:
285                 str = _("Playing:");
286                 break;
287         case MPD_STATUS_STATE_PAUSE:
288                 str = _("[Paused]");
289                 break;
290         case MPD_STATUS_STATE_STOP:
291         default:
292                 break;
293         }
295         if (str) {
296                 waddstr(w, str);
297                 x += utf8_width(str) + 1;
298         }
300         /* create time string */
301         memset(screen.buf, 0, screen.buf_size);
302         if (status != NULL && (IS_PLAYING(status->state) ||
303                                IS_PAUSED(status->state))) {
304                 if (status->totalTime > 0) {
305                         /*checks the conf to see whether to display elapsed or remaining time */
306                         if(!strcmp(options.timedisplay_type,"elapsed"))
307                                 elapsedTime = c->status->elapsedTime;
308                         else if(!strcmp(options.timedisplay_type,"remaining"))
309                                 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
311                         if( c->song && seek_id == c->song->id )
312                                 elapsedTime = seek_target_time;
314                         /* display bitrate if visible-bitrate is true */
315 #ifndef NCMPC_MINI
316                         if (options.visible_bitrate) {
317                                 g_snprintf(bitrate, 16,
318                                            " [%d kbps]", status->bitRate);
319                         } else {
320                                 bitrate[0] = '\0';
321                         }
322 #endif
324                         /*write out the time, using hours if time over 60 minutes*/
325                         if (c->status->totalTime > 3600) {
326                                 g_snprintf(screen.buf, screen.buf_size,
327                                            "%s [%i:%02i:%02i/%i:%02i:%02i]",
328                                            bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
329                                            status->totalTime/3600, (status->totalTime%3600)/60,  status->totalTime%60);
330                         } else {
331                                 g_snprintf(screen.buf, screen.buf_size,
332                                            "%s [%i:%02i/%i:%02i]",
333                                            bitrate, elapsedTime/60, elapsedTime%60,
334                                            status->totalTime/60,   status->totalTime%60 );
335                         }
336 #ifndef NCMPC_MINI
337                 } else {
338                         g_snprintf(screen.buf, screen.buf_size,
339                                    " [%d kbps]", status->bitRate );
340 #endif
341                 }
342 #ifndef NCMPC_MINI
343         } else {
344                 if (options.display_time) {
345                         time_t timep;
347                         time(&timep);
348                         strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
349                 }
350 #endif
351         }
353         /* display song */
354         if (status != NULL && (IS_PLAYING(status->state) ||
355                                IS_PAUSED(status->state))) {
356                 char songname[MAX_SONGNAME_LENGTH];
357 #ifndef NCMPC_MINI
358                 int width = COLS - x - utf8_width(screen.buf);
359 #endif
361                 if (song)
362                         strfsong(songname, MAX_SONGNAME_LENGTH,
363                                  options.status_format, song);
364                 else
365                         songname[0] = '\0';
367                 colors_use(w, COLOR_STATUS);
368                 /* scroll if the song name is to long */
369 #ifndef NCMPC_MINI
370                 if (options.scroll && utf8_width(songname) > (unsigned)width) {
371                         static  scroll_state_t st = { 0, 0 };
372                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
374                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
375                         g_free(tmp);
376                 }
377 #endif
378                 //mvwaddnstr(w, 0, x, songname, width);
379                 mvwaddstr(w, 0, x, songname);
380         }
382         /* display time string */
383         if (screen.buf[0]) {
384                 x = screen.status_window.cols - strlen(screen.buf);
385                 colors_use(w, COLOR_STATUS_TIME);
386                 mvwaddstr(w, 0, x, screen.buf);
387         }
389         wnoutrefresh(w);
392 void
393 screen_exit(void)
395         if (mode_fn->close != NULL)
396                 mode_fn->close();
398         screen_list_exit();
400         string_list_free(screen.find_history);
401         g_free(screen.buf);
402         g_free(screen.findbuf);
405 void
406 screen_resize(struct mpdclient *c)
408         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
409                 screen_exit();
410                 fprintf(stderr, "%s", _("Error: Screen too small"));
411                 exit(EXIT_FAILURE);
412         }
414         resizeterm(LINES, COLS);
416         screen.cols = COLS;
417         screen.rows = LINES;
419         /* top window */
420         screen.top_window.cols = screen.cols;
421         wresize(screen.top_window.w, 2, screen.cols);
423         /* main window */
424         screen.main_window.cols = screen.cols;
425         screen.main_window.rows = screen.rows-4;
426         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
427         wclear(screen.main_window.w);
429         /* progress window */
430         screen.progress_window.cols = screen.cols;
431         wresize(screen.progress_window.w, 1, screen.cols);
432         mvwin(screen.progress_window.w, screen.rows-2, 0);
434         /* status window */
435         screen.status_window.cols = screen.cols;
436         wresize(screen.status_window.w, 1, screen.cols);
437         mvwin(screen.status_window.w, screen.rows-1, 0);
439         screen.buf_size = screen.cols;
440         g_free(screen.buf);
441         screen.buf = g_malloc(screen.cols);
443         /* resize all screens */
444         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
446         /* ? - without this the cursor becomes visible with aterm & Eterm */
447         curs_set(1);
448         curs_set(0);
450         screen_paint(c);
453 void
454 screen_status_message(const char *msg)
456         WINDOW *w = screen.status_window.w;
458         wmove(w, 0, 0);
459         wclrtoeol(w);
460         colors_use(w, COLOR_STATUS_ALERT);
461         waddstr(w, msg);
462         wnoutrefresh(w);
463         screen.status_timestamp = time(NULL);
466 void
467 screen_status_printf(const char *format, ...)
469         char *msg;
470         va_list ap;
472         va_start(ap,format);
473         msg = g_strdup_vprintf(format,ap);
474         va_end(ap);
475         screen_status_message(msg);
476         g_free(msg);
479 void
480 screen_init(mpdclient_t *c)
482         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
483                 fprintf(stderr, "%s\n", _("Error: Screen too small"));
484                 exit(EXIT_FAILURE);
485         }
487         screen.cols = COLS;
488         screen.rows = LINES;
490         screen.buf  = g_malloc(screen.cols);
491         screen.buf_size = screen.cols;
492         screen.findbuf = NULL;
493         screen.start_timestamp = time(NULL);
494         screen.last_cmd = CMD_NONE;
496         /* create top window */
497         screen.top_window.rows = 2;
498         screen.top_window.cols = screen.cols;
499         screen.top_window.w = newwin(screen.top_window.rows,
500                                       screen.top_window.cols,
501                                       0, 0);
502         leaveok(screen.top_window.w, TRUE);
503         keypad(screen.top_window.w, TRUE);
505         /* create main window */
506         screen.main_window.rows = screen.rows-4;
507         screen.main_window.cols = screen.cols;
508         screen.main_window.w = newwin(screen.main_window.rows,
509                                        screen.main_window.cols,
510                                        2,
511                                        0);
513         //  leaveok(screen.main_window.w, TRUE); temporary disabled
514         keypad(screen.main_window.w, TRUE);
516         /* create progress window */
517         screen.progress_window.rows = 1;
518         screen.progress_window.cols = screen.cols;
519         screen.progress_window.w = newwin(screen.progress_window.rows,
520                                            screen.progress_window.cols,
521                                            screen.rows-2,
522                                            0);
523         leaveok(screen.progress_window.w, TRUE);
525         /* create status window */
526         screen.status_window.rows = 1;
527         screen.status_window.cols = screen.cols;
528         screen.status_window.w = newwin(screen.status_window.rows,
529                                          screen.status_window.cols,
530                                          screen.rows-1,
531                                          0);
533         leaveok(screen.status_window.w, FALSE);
534         keypad(screen.status_window.w, TRUE);
536 #ifdef ENABLE_COLORS
537         if (options.enable_colors) {
538                 /* set background attributes */
539                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
540                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
541                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
542                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
543                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
544                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
545         }
546 #endif
548         refresh();
550         /* initialize screens */
551         screen_list_init(screen.main_window.w,
552                          screen.main_window.cols, screen.main_window.rows);
554         if (mode_fn->open != NULL)
555                 mode_fn->open(c);
558 void
559 screen_paint(mpdclient_t *c)
561         const char *title = NULL;
563         if (mode_fn->get_title != NULL)
564                 title = mode_fn->get_title(screen.buf, screen.buf_size);
566         /* paint the title/header window */
567         if( title )
568                 paint_top_window(title, c, 1);
569         else
570                 paint_top_window("", c, 1);
572         /* paint the main window */
573         wclear(screen.main_window.w);
574         if (mode_fn->paint != NULL)
575                 mode_fn->paint();
577         paint_progress_window(c);
578         paint_status_window(c);
579         wmove(screen.main_window.w, 0, 0);
580         wnoutrefresh(screen.main_window.w);
582         /* tell curses to update */
583         doupdate();
586 void
587 screen_update(mpdclient_t *c)
589 #ifndef NCMPC_MINI
590         static int repeat = -1;
591         static int random_enabled = -1;
592         static int crossfade = -1;
593         static int dbupdate = -1;
595         /* print a message if mpd status has changed */
596         if (c->status != NULL) {
597                 if (repeat < 0) {
598                         repeat = c->status->repeat;
599                         random_enabled = c->status->random;
600                         crossfade = c->status->crossfade;
601                         dbupdate = c->status->updatingDb;
602                 }
604                 if (repeat != c->status->repeat)
605                         screen_status_printf(c->status->repeat ?
606                                              _("Repeat is on") :
607                                              _("Repeat is off"));
609                 if (random_enabled != c->status->random)
610                         screen_status_printf(c->status->random ?
611                                              _("Random is on") :
612                                              _("Random is off"));
614                 if (crossfade != c->status->crossfade)
615                         screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
617                 if (dbupdate && dbupdate != c->status->updatingDb) {
618                         screen_status_printf(_("Database updated"));
619                         mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
620                 }
622                 repeat = c->status->repeat;
623                 random_enabled = c->status->random;
624                 crossfade = c->status->crossfade;
625                 dbupdate = c->status->updatingDb;
626         }
628         /* update title/header window */
629         if (welcome && options.welcome_screen_list &&
630             screen.last_cmd==CMD_NONE &&
631             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
632                 paint_top_window("", c, 0);
633         else
634 #endif
635         if (mode_fn->get_title != NULL) {
636                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
637 #ifndef NCMPC_MINI
638                 welcome = FALSE;
639 #endif
640         } else
641                 paint_top_window("", c, 0);
643         /* update the main window */
644         if (mode_fn->update != NULL)
645                 mode_fn->update(c);
647         /* update progress window */
648         paint_progress_window(c);
650         /* update status window */
651         paint_status_window(c);
653         /* move the cursor to the origin */
654         wmove(screen.main_window.w, 0, 0);
655         wnoutrefresh(screen.main_window.w);
657         /* tell curses to update */
658         doupdate();
661 void
662 screen_idle(mpdclient_t *c)
664         if (c->song && seek_id == c->song->id &&
665             (screen.last_cmd == CMD_SEEK_FORWARD ||
666              screen.last_cmd == CMD_SEEK_BACKWARD))
667                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
669         screen.last_cmd = CMD_NONE;
670         seek_id = -1;
673 #ifdef HAVE_GETMOUSE
674 int
675 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
677         MEVENT event;
679         /* retreive the mouse event from ncurses */
680         getmouse(&event);
681         /* calculate the selected row in the list window */
682         *row = event.y - screen.top_window.rows;
683         /* copy button state bits */
684         *bstate = event.bstate;
685         /* if button 2 was pressed switch screen */
686         if (event.bstate & BUTTON2_CLICKED) {
687                 screen_cmd(c, CMD_SCREEN_NEXT);
688                 return 1;
689         }
691         return 0;
693 #endif
695 static int
696 screen_client_cmd(mpdclient_t *c, command_t cmd)
698         if (c->connection == NULL || c->status == NULL)
699                 return 0;
701         switch(cmd) {
702                 /*
703         case CMD_PLAY:
704                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
705                 break;
706                 */
707         case CMD_PAUSE:
708                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
709                 break;
710         case CMD_STOP:
711                 mpdclient_cmd_stop(c);
712                 break;
713         case CMD_CROP:
714                 mpdclient_cmd_crop(c);
715                 break;
716         case CMD_SEEK_FORWARD:
717                 if (!IS_STOPPED(c->status->state)) {
718                         if (c->song && seek_id != c->song->id) {
719                                 seek_id = c->song->id;
720                                 seek_target_time = c->status->elapsedTime;
721                         }
722                         seek_target_time+=options.seek_time;
723                         if (seek_target_time < c->status->totalTime)
724                                 break;
725                         seek_target_time = c->status->totalTime;
726                         /* seek_target_time=0; */
727                 }
728                 break;
729                 /* fall through... */
730         case CMD_TRACK_NEXT:
731                 if (!IS_STOPPED(c->status->state))
732                         mpdclient_cmd_next(c);
733                 break;
734         case CMD_SEEK_BACKWARD:
735                 if (!IS_STOPPED(c->status->state)) {
736                         if (seek_id != c->song->id) {
737                                 seek_id = c->song->id;
738                                 seek_target_time = c->status->elapsedTime;
739                         }
740                         seek_target_time-=options.seek_time;
741                         if (seek_target_time < 0)
742                                 seek_target_time=0;
743                 }
744                 break;
745         case CMD_TRACK_PREVIOUS:
746                 if (!IS_STOPPED(c->status->state))
747                         mpdclient_cmd_prev(c);
748                 break;
749         case CMD_SHUFFLE:
750                 if (mpdclient_cmd_shuffle(c) == 0)
751                         screen_status_message(_("Shuffled playlist"));
752                 break;
753         case CMD_CLEAR:
754                 if (mpdclient_cmd_clear(c) == 0)
755                         screen_status_message(_("Cleared playlist"));
756                 break;
757         case CMD_REPEAT:
758                 mpdclient_cmd_repeat(c, !c->status->repeat);
759                 break;
760         case CMD_RANDOM:
761                 mpdclient_cmd_random(c, !c->status->random);
762                 break;
763         case CMD_CROSSFADE:
764                 if (c->status->crossfade)
765                         mpdclient_cmd_crossfade(c, 0);
766                 else
767                         mpdclient_cmd_crossfade(c, options.crossfade_time);
768                 break;
769         case CMD_DB_UPDATE:
770                 if (!c->status->updatingDb) {
771                         if( mpdclient_cmd_db_update(c,NULL)==0 )
772                                 screen_status_printf(_("Database update started"));
773                 } else
774                         screen_status_printf(_("Database update running..."));
775                 break;
776         case CMD_VOLUME_UP:
777                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
778                         mpdclient_cmd_volume(c, ++c->status->volume);
779                 break;
780         case CMD_VOLUME_DOWN:
781                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
782                         mpdclient_cmd_volume(c, --c->status->volume);
783                 break;
785         default:
786                 return 0;
787         }
789         return 1;
792 void
793 screen_cmd(mpdclient_t *c, command_t cmd)
795         screen.last_cmd = cmd;
796 #ifndef NCMPC_MINI
797         welcome = FALSE;
798 #endif
800         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
801                 return;
803         if (screen_client_cmd(c, cmd))
804                 return;
806         switch(cmd) {
807         case CMD_TOGGLE_FIND_WRAP:
808                 options.find_wrap = !options.find_wrap;
809                 screen_status_printf(options.find_wrap ?
810                                      _("Find mode: Wrapped") :
811                                      _("Find mode: Normal"));
812                 break;
813         case CMD_TOGGLE_AUTOCENTER:
814                 options.auto_center = !options.auto_center;
815                 screen_status_printf(options.auto_center ?
816                                      _("Auto center mode: On") :
817                                      _("Auto center mode: Off"));
818                 break;
819         case CMD_SCREEN_UPDATE:
820                 screen_paint(c);
821                 break;
822         case CMD_SCREEN_PREVIOUS:
823                 screen_next_mode(c, -1);
824                 break;
825         case CMD_SCREEN_NEXT:
826                 screen_next_mode(c, 1);
827                 break;
828         case CMD_SCREEN_PLAY:
829                 screen_switch(&screen_playlist, c);
830                 break;
831         case CMD_SCREEN_FILE:
832                 screen_switch(&screen_browse, c);
833                 break;
834 #ifdef ENABLE_HELP_SCREEN
835         case CMD_SCREEN_HELP:
836                 screen_switch(&screen_help, c);
837                 break;
838 #endif
839 #ifdef ENABLE_SEARCH_SCREEN
840         case CMD_SCREEN_SEARCH:
841                 screen_switch(&screen_search, c);
842                 break;
843 #endif
844 #ifdef ENABLE_ARTIST_SCREEN
845         case CMD_SCREEN_ARTIST:
846                 screen_switch(&screen_artist, c);
847                 break;
848 #endif
849 #ifdef ENABLE_KEYDEF_SCREEN
850         case CMD_SCREEN_KEYDEF:
851                 screen_switch(&screen_keydef, c);
852                 break;
853 #endif
854 #ifdef ENABLE_LYRICS_SCREEN
855         case CMD_SCREEN_LYRICS:
856                 screen_switch(&screen_lyrics, c);
857                 break;
858 #endif
859 #ifdef ENABLE_OUTPUTS_SCREEN
860         case CMD_SCREEN_OUTPUTS:
861                 screen_switch(&screen_outputs, c);
862                 break;
863         case CMD_SCREEN_SWAP:
864                 screen_switch(mode_fn_prev, c);
865                 break;
866 #endif
868         default:
869                 break;
870         }