Code

removed the debugging function D()
[ncmpc.git] / src / screen.c
1 /*
2  * $Id$
3  *
4  * (c) 2004 by Kalle Wallin <kaw@linux.se>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
21 #include "screen.h"
22 #include "screen_list.h"
23 #include "screen_utils.h"
24 #include "config.h"
25 #include "ncmpc.h"
26 #include "support.h"
27 #include "mpdclient.h"
28 #include "utils.h"
29 #include "command.h"
30 #include "options.h"
31 #include "colors.h"
32 #include "strfsong.h"
33 #include "wreadln.h"
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <stdarg.h>
38 #include <string.h>
39 #include <time.h>
40 #include <locale.h>
42 /* screens */
44 static gboolean welcome = TRUE;
45 static struct screen screen;
46 static const struct screen_functions *mode_fn = &screen_playlist;
47 static int seek_id = -1;
48 static int seek_target_time = 0;
50 gboolean
51 screen_is_visible(const struct screen_functions *sf)
52 {
53         return sf == mode_fn;
54 }
56 void
57 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
58 {
59         assert(sf != NULL);
61         if (sf == mode_fn)
62                 return;
64         /* close the old mode */
65         if (mode_fn->close != NULL)
66                 mode_fn->close();
68         /* get functions for the new mode */
69         mode_fn = sf;
70         screen.painted = 0;
72         /* open the new mode */
73         if (mode_fn->open != NULL)
74                 mode_fn->open(&screen, c);
75 }
77 static int
78 find_configured_screen(const char *name)
79 {
80         unsigned i;
82         for (i = 0; options.screen_list[i] != NULL; ++i)
83                 if (strcmp(options.screen_list[i], name) == 0)
84                         return i;
86         return -1;
87 }
89 static void
90 screen_next_mode(mpdclient_t *c, int offset)
91 {
92         int max = g_strv_length(options.screen_list);
93         int current, next;
94         const struct screen_functions *sf;
96         /* find current screen */
97         current = find_configured_screen(screen_get_name(mode_fn));
98         next = current + offset;
99         if (next<0)
100                 next = max-1;
101         else if (next>=max)
102                 next = 0;
104         sf = screen_lookup_name(options.screen_list[next]);
105         if (sf != NULL)
106                 screen_switch(sf, c);
109 static void
110 paint_top_window2(const char *header, mpdclient_t *c)
112         char flags[5];
113         WINDOW *w = screen.top_window.w;
114         char buf[32];
116         if (header[0]) {
117                 colors_use(w, COLOR_TITLE_BOLD);
118                 mvwaddstr(w, 0, 0, header);
119         } else {
120                 colors_use(w, COLOR_TITLE_BOLD);
121                 waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
122                 colors_use(w, COLOR_TITLE);
123                 waddstr(w, _(":Help  "));
124                 colors_use(w, COLOR_TITLE_BOLD);
125                 waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
126                 colors_use(w, COLOR_TITLE);
127                 waddstr(w, _(":Playlist  "));
128                 colors_use(w, COLOR_TITLE_BOLD);
129                 waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
130                 colors_use(w, COLOR_TITLE);
131                 waddstr(w, _(":Browse  "));
132 #ifdef ENABLE_ARTIST_SCREEN
133                 colors_use(w, COLOR_TITLE_BOLD);
134                 waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
135                 colors_use(w, COLOR_TITLE);
136                 waddstr(w, _(":Artist  "));
137 #endif
138 #ifdef ENABLE_SEARCH_SCREEN
139                 colors_use(w, COLOR_TITLE_BOLD);
140                 waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
141                 colors_use(w, COLOR_TITLE);
142                 waddstr(w, _(":Search  "));
143 #endif
144 #ifdef ENABLE_LYRICS_SCREEN
145                 colors_use(w, COLOR_TITLE_BOLD);
146                 waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
147                 colors_use(w, COLOR_TITLE);
148                 waddstr(w, _(":Lyrics  "));
149 #endif
150         }
151         if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
152                 g_snprintf(buf, 32, _("Volume n/a "));
153         } else {
154                 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
155         }
156         colors_use(w, COLOR_TITLE);
157         mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
159         flags[0] = 0;
160         if (c->status != NULL) {
161                 if (c->status->repeat)
162                         g_strlcat(flags, "r", sizeof(flags));
163                 if (c->status->random)
164                         g_strlcat(flags, "z", sizeof(flags));;
165                 if (c->status->crossfade)
166                         g_strlcat(flags, "x", sizeof(flags));
167                 if (c->status->updatingDb)
168                         g_strlcat(flags, "U", sizeof(flags));
169         }
171         colors_use(w, COLOR_LINE);
172         mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
173         if (flags[0]) {
174                 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
175                 waddch(w, '[');
176                 colors_use(w, COLOR_LINE_BOLD);
177                 waddstr(w, flags);
178                 colors_use(w, COLOR_LINE);
179                 waddch(w, ']');
180         }
181         wnoutrefresh(w);
184 static void
185 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
187         static int prev_volume = -1;
188         static size_t prev_header_len = -1;
189         WINDOW *w = screen.top_window.w;
191         if (prev_header_len!=my_strlen(header)) {
192                 prev_header_len = my_strlen(header);
193                 full_repaint = 1;
194         }
196         if (full_repaint) {
197                 wmove(w, 0, 0);
198                 wclrtoeol(w);
199         }
201         if ((c->status != NULL && prev_volume != c->status->volume) ||
202             full_repaint)
203                 paint_top_window2(header, c);
206 static void
207 paint_progress_window(mpdclient_t *c)
209         double p;
210         int width;
211         int elapsedTime;
213         if (c->status==NULL || IS_STOPPED(c->status->state)) {
214                 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
215                          screen.progress_window.cols);
216                 wnoutrefresh(screen.progress_window.w);
217                 return;
218         }
220         if (c->song && seek_id == c->song->id)
221                 elapsedTime = seek_target_time;
222         else
223                 elapsedTime = c->status->elapsedTime;
225         p = ((double) elapsedTime) / ((double) c->status->totalTime);
227         width = (int) (p * (double) screen.progress_window.cols);
228         mvwhline(screen.progress_window.w,
229                  0, 0,
230                  ACS_HLINE,
231                  screen.progress_window.cols);
232         whline(screen.progress_window.w, '=', width-1);
233         mvwaddch(screen.progress_window.w, 0, width-1, 'O');
234         wnoutrefresh(screen.progress_window.w);
237 static void
238 paint_status_window(mpdclient_t *c)
240         WINDOW *w = screen.status_window.w;
241         mpd_Status *status = c->status;
242         mpd_Song *song = c->song;
243         int elapsedTime = 0;
244         char bitrate[16];
245         const char *str = NULL;
246         int x = 0;
248         if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
249                 return;
251         wmove(w, 0, 0);
252         wclrtoeol(w);
253         colors_use(w, COLOR_STATUS_BOLD);
255         switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
256         case MPD_STATUS_STATE_PLAY:
257                 str = _("Playing:");
258                 break;
259         case MPD_STATUS_STATE_PAUSE:
260                 str = _("[Paused]");
261                 break;
262         case MPD_STATUS_STATE_STOP:
263         default:
264                 break;
265         }
267         if (str) {
268                 waddstr(w, str);
269                 x += my_strlen(str)+1;
270         }
272         /* create time string */
273         memset(screen.buf, 0, screen.buf_size);
274         if (status != NULL && (IS_PLAYING(status->state) ||
275                                IS_PAUSED(status->state))) {
276                 if (status->totalTime > 0) {
277                         /*checks the conf to see whether to display elapsed or remaining time */
278                         if(!strcmp(options.timedisplay_type,"elapsed"))
279                                 elapsedTime = c->status->elapsedTime;
280                         else if(!strcmp(options.timedisplay_type,"remaining"))
281                                 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
283                         if( c->song && seek_id == c->song->id )
284                                 elapsedTime = seek_target_time;
286                         /* display bitrate if visible-bitrate is true */
287                         if (options.visible_bitrate) {
288                                 g_snprintf(bitrate, 16,
289                                            " [%d kbps]", status->bitRate);
290                         } else {
291                                 bitrate[0] = '\0';
292                         }
294                         /*write out the time, using hours if time over 60 minutes*/
295                         if (c->status->totalTime > 3600) {
296                                 g_snprintf(screen.buf, screen.buf_size,
297                                            "%s [%i:%02i:%02i/%i:%02i:%02i]",
298                                            bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
299                                            status->totalTime/3600, (status->totalTime%3600)/60,  status->totalTime%60);
300                         } else {
301                                 g_snprintf(screen.buf, screen.buf_size,
302                                            "%s [%i:%02i/%i:%02i]",
303                                            bitrate, elapsedTime/60, elapsedTime%60,
304                                            status->totalTime/60,   status->totalTime%60 );
305                         }
306                 } else {
307                         g_snprintf(screen.buf, screen.buf_size,
308                                    " [%d kbps]", status->bitRate );
309                 }
310         } else {
311                 time_t timep;
313                 time(&timep);
314                 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
315         }
317         /* display song */
318         if (status != NULL && (IS_PLAYING(status->state) ||
319                                IS_PAUSED(status->state))) {
320                 char songname[MAX_SONGNAME_LENGTH];
321                 int width = COLS-x-my_strlen(screen.buf);
323                 if (song)
324                         strfsong(songname, MAX_SONGNAME_LENGTH, STATUS_FORMAT, song);
325                 else
326                         songname[0] = '\0';
328                 colors_use(w, COLOR_STATUS);
329                 /* scroll if the song name is to long */
330                 if (options.scroll && my_strlen(songname) > (size_t)width) {
331                         static  scroll_state_t st = { 0, 0 };
332                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
334                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
335                         g_free(tmp);
336                 }
337                 //mvwaddnstr(w, 0, x, songname, width);
338                 mvwaddstr(w, 0, x, songname);
339         }
341         /* display time string */
342         if (screen.buf[0]) {
343                 x = screen.status_window.cols - strlen(screen.buf);
344                 colors_use(w, COLOR_STATUS_TIME);
345                 mvwaddstr(w, 0, x, screen.buf);
346         }
348         wnoutrefresh(w);
351 void
352 screen_exit(void)
354         if (mode_fn->close != NULL)
355                 mode_fn->close();
357         screen_list_exit();
359         string_list_free(screen.find_history);
360         g_free(screen.buf);
361         g_free(screen.findbuf);
364 void
365 screen_resize(void)
367         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
368                 screen_exit();
369                 fprintf(stderr, _("Error: Screen to small!\n"));
370                 exit(EXIT_FAILURE);
371         }
373         resizeterm(LINES, COLS);
375         screen.cols = COLS;
376         screen.rows = LINES;
378         /* top window */
379         screen.top_window.cols = screen.cols;
380         wresize(screen.top_window.w, 2, screen.cols);
382         /* main window */
383         screen.main_window.cols = screen.cols;
384         screen.main_window.rows = screen.rows-4;
385         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
386         wclear(screen.main_window.w);
388         /* progress window */
389         screen.progress_window.cols = screen.cols;
390         wresize(screen.progress_window.w, 1, screen.cols);
391         mvwin(screen.progress_window.w, screen.rows-2, 0);
393         /* status window */
394         screen.status_window.cols = screen.cols;
395         wresize(screen.status_window.w, 1, screen.cols);
396         mvwin(screen.status_window.w, screen.rows-1, 0);
398         screen.buf_size = screen.cols;
399         g_free(screen.buf);
400         screen.buf = g_malloc(screen.cols);
402         /* resize all screens */
403         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
405         /* ? - without this the cursor becomes visible with aterm & Eterm */
406         curs_set(1);
407         curs_set(0);
409         screen.painted = 0;
412 void
413 screen_status_message(const char *msg)
415         WINDOW *w = screen.status_window.w;
417         wmove(w, 0, 0);
418         wclrtoeol(w);
419         colors_use(w, COLOR_STATUS_ALERT);
420         waddstr(w, msg);
421         wnoutrefresh(w);
422         screen.status_timestamp = time(NULL);
425 void
426 screen_status_printf(const char *format, ...)
428         char *msg;
429         va_list ap;
431         va_start(ap,format);
432         msg = g_strdup_vprintf(format,ap);
433         va_end(ap);
434         screen_status_message(msg);
435         g_free(msg);
438 void
439 screen_init(mpdclient_t *c)
441         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
442                 fprintf(stderr, _("Error: Screen to small!\n"));
443                 exit(EXIT_FAILURE);
444         }
446         screen.cols = COLS;
447         screen.rows = LINES;
449         screen.buf  = g_malloc(screen.cols);
450         screen.buf_size = screen.cols;
451         screen.findbuf = NULL;
452         screen.painted = 0;
453         screen.start_timestamp = time(NULL);
454         screen.last_cmd = CMD_NONE;
456         /* create top window */
457         screen.top_window.rows = 2;
458         screen.top_window.cols = screen.cols;
459         screen.top_window.w = newwin(screen.top_window.rows,
460                                       screen.top_window.cols,
461                                       0, 0);
462         leaveok(screen.top_window.w, TRUE);
463         keypad(screen.top_window.w, TRUE);
465         /* create main window */
466         screen.main_window.rows = screen.rows-4;
467         screen.main_window.cols = screen.cols;
468         screen.main_window.w = newwin(screen.main_window.rows,
469                                        screen.main_window.cols,
470                                        2,
471                                        0);
473         //  leaveok(screen.main_window.w, TRUE); temporary disabled
474         keypad(screen.main_window.w, TRUE);
476         /* create progress window */
477         screen.progress_window.rows = 1;
478         screen.progress_window.cols = screen.cols;
479         screen.progress_window.w = newwin(screen.progress_window.rows,
480                                            screen.progress_window.cols,
481                                            screen.rows-2,
482                                            0);
483         leaveok(screen.progress_window.w, TRUE);
485         /* create status window */
486         screen.status_window.rows = 1;
487         screen.status_window.cols = screen.cols;
488         screen.status_window.w = newwin(screen.status_window.rows,
489                                          screen.status_window.cols,
490                                          screen.rows-1,
491                                          0);
493         leaveok(screen.status_window.w, FALSE);
494         keypad(screen.status_window.w, TRUE);
496         if (options.enable_colors) {
497                 /* set background attributes */
498                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
499                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
500                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
501                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
502                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
503                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
504         }
506         refresh();
508         /* initialize screens */
509         screen_list_init(screen.main_window.w,
510                          screen.main_window.cols, screen.main_window.rows);
512         if (mode_fn->open != NULL)
513                 mode_fn->open(&screen, c);
515         /* initialize wreadln */
516         wrln_wgetch = my_wgetch;
517         wrln_max_history_length = 16;
520 void
521 screen_paint(mpdclient_t *c)
523         const char *title = NULL;
525         if (mode_fn->get_title != NULL)
526                 title = mode_fn->get_title(screen.buf, screen.buf_size);
528         /* paint the title/header window */
529         if( title )
530                 paint_top_window(title, c, 1);
531         else
532                 paint_top_window("", c, 1);
534         /* paint the main window */
535         wclear(screen.main_window.w);
536         if (mode_fn->paint != NULL)
537                 mode_fn->paint(c);
539         paint_progress_window(c);
540         paint_status_window(c);
541         screen.painted = 1;
542         wmove(screen.main_window.w, 0, 0);
543         wnoutrefresh(screen.main_window.w);
545         /* tell curses to update */
546         doupdate();
549 void
550 screen_update(mpdclient_t *c)
552         static int repeat = -1;
553         static int random_enabled = -1;
554         static int crossfade = -1;
555         static int dbupdate = -1;
557         if( !screen.painted )
558                 screen_paint(c);
560         /* print a message if mpd status has changed */
561         if (c->status != NULL) {
562                 if (repeat < 0) {
563                         repeat = c->status->repeat;
564                         random_enabled = c->status->random;
565                         crossfade = c->status->crossfade;
566                         dbupdate = c->status->updatingDb;
567                 }
569                 if (repeat != c->status->repeat)
570                         screen_status_printf(c->status->repeat ?
571                                              _("Repeat is on") :
572                                              _("Repeat is off"));
574                 if (random_enabled != c->status->random)
575                         screen_status_printf(c->status->random ?
576                                              _("Random is on") :
577                                              _("Random is off"));
579                 if (crossfade != c->status->crossfade)
580                         screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
582                 if (dbupdate && dbupdate != c->status->updatingDb) {
583                         screen_status_printf(_("Database updated!"));
584                         mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
585                 }
587                 repeat = c->status->repeat;
588                 random_enabled = c->status->random;
589                 crossfade = c->status->crossfade;
590                 dbupdate = c->status->updatingDb;
591         }
593         /* update title/header window */
594         if (welcome && options.welcome_screen_list &&
595             screen.last_cmd==CMD_NONE &&
596             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
597                 paint_top_window("", c, 0);
598         else if (mode_fn->get_title != NULL) {
599                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
600                 welcome = FALSE;
601         } else
602                 paint_top_window("", c, 0);
604         /* update the main window */
605         if (mode_fn->update != NULL)
606                 mode_fn->update(c);
608         /* update progress window */
609         paint_progress_window(c);
611         /* update status window */
612         paint_status_window(c);
614         /* move the cursor to the origin */
615         wmove(screen.main_window.w, 0, 0);
616         wnoutrefresh(screen.main_window.w);
618         /* tell curses to update */
619         doupdate();
622 void
623 screen_idle(mpdclient_t *c)
625         if (c->song && seek_id == c->song->id &&
626             (screen.last_cmd == CMD_SEEK_FORWARD ||
627              screen.last_cmd == CMD_SEEK_BACKWARD))
628                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
630         screen.last_cmd = CMD_NONE;
631         seek_id = -1;
634 #ifdef HAVE_GETMOUSE
635 int
636 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
638         MEVENT event;
640         /* retreive the mouse event from ncurses */
641         getmouse(&event);
642         /* calculate the selected row in the list window */
643         *row = event.y - screen.top_window.rows;
644         /* copy button state bits */
645         *bstate = event.bstate;
646         /* if button 2 was pressed switch screen */
647         if (event.bstate & BUTTON2_CLICKED) {
648                 screen_cmd(c, CMD_SCREEN_NEXT);
649                 return 1;
650         }
652         return 0;
654 #endif
656 static int
657 screen_client_cmd(mpdclient_t *c, command_t cmd)
659         if (c->connection == NULL || c->status == NULL)
660                 return 0;
662         switch(cmd) {
663                 /*
664         case CMD_PLAY:
665                 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
666                 break;
667                 */
668         case CMD_PAUSE:
669                 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
670                 break;
671         case CMD_STOP:
672                 mpdclient_cmd_stop(c);
673                 break;
674         case CMD_CROP:
675                 mpdclient_cmd_crop(c);
676                 break;
677         case CMD_SEEK_FORWARD:
678                 if (!IS_STOPPED(c->status->state)) {
679                         if (c->song && seek_id != c->song->id) {
680                                 seek_id = c->song->id;
681                                 seek_target_time = c->status->elapsedTime;
682                         }
683                         seek_target_time+=options.seek_time;
684                         if (seek_target_time < c->status->totalTime)
685                                 break;
686                         seek_target_time = c->status->totalTime;
687                         /* seek_target_time=0; */
688                 }
689                 break;
690                 /* fall through... */
691         case CMD_TRACK_NEXT:
692                 if (!IS_STOPPED(c->status->state))
693                         mpdclient_cmd_next(c);
694                 break;
695         case CMD_SEEK_BACKWARD:
696                 if (!IS_STOPPED(c->status->state)) {
697                         if (seek_id != c->song->id) {
698                                 seek_id = c->song->id;
699                                 seek_target_time = c->status->elapsedTime;
700                         }
701                         seek_target_time-=options.seek_time;
702                         if (seek_target_time < 0)
703                                 seek_target_time=0;
704                 }
705                 break;
706         case CMD_TRACK_PREVIOUS:
707                 if (!IS_STOPPED(c->status->state))
708                         mpdclient_cmd_prev(c);
709                 break;
710         case CMD_SHUFFLE:
711                 if (mpdclient_cmd_shuffle(c) == 0)
712                         screen_status_message(_("Shuffled playlist!"));
713                 break;
714         case CMD_CLEAR:
715                 if (mpdclient_cmd_clear(c) == 0)
716                         screen_status_message(_("Cleared playlist!"));
717                 break;
718         case CMD_REPEAT:
719                 mpdclient_cmd_repeat(c, !c->status->repeat);
720                 break;
721         case CMD_RANDOM:
722                 mpdclient_cmd_random(c, !c->status->random);
723                 break;
724         case CMD_CROSSFADE:
725                 if (c->status->crossfade)
726                         mpdclient_cmd_crossfade(c, 0);
727                 else
728                         mpdclient_cmd_crossfade(c, options.crossfade_time);
729                 break;
730         case CMD_DB_UPDATE:
731                 if (!c->status->updatingDb) {
732                         if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
733                                 screen_status_printf(_("Database update started!"));
734                 } else
735                         screen_status_printf(_("Database update running..."));
736                 break;
737         case CMD_VOLUME_UP:
738                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
739                         mpdclient_cmd_volume(c, ++c->status->volume);
740                 break;
741         case CMD_VOLUME_DOWN:
742                 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
743                         mpdclient_cmd_volume(c, --c->status->volume);
744                 break;
746         default:
747                 return 0;
748         }
750         return 1;
753 void
754 screen_cmd(mpdclient_t *c, command_t cmd)
756         screen.last_cmd = cmd;
757         welcome = FALSE;
759         if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
760                 return;
762         if (screen_client_cmd(c, cmd))
763                 return;
765         switch(cmd) {
766         case CMD_TOGGLE_FIND_WRAP:
767                 options.find_wrap = !options.find_wrap;
768                 screen_status_printf(options.find_wrap ?
769                                      _("Find mode: Wrapped") :
770                                      _("Find mode: Normal"));
771                 break;
772         case CMD_TOGGLE_AUTOCENTER:
773                 options.auto_center = !options.auto_center;
774                 screen_status_printf(options.auto_center ?
775                                      _("Auto center mode: On") :
776                                      _("Auto center mode: Off"));
777                 break;
778         case CMD_SCREEN_UPDATE:
779                 screen.painted = 0;
780                 break;
781         case CMD_SCREEN_PREVIOUS:
782                 screen_next_mode(c, -1);
783                 break;
784         case CMD_SCREEN_NEXT:
785                 screen_next_mode(c, 1);
786                 break;
787         case CMD_SCREEN_PLAY:
788                 screen_switch(&screen_playlist, c);
789                 break;
790         case CMD_SCREEN_FILE:
791                 screen_switch(&screen_browse, c);
792                 break;
793         case CMD_SCREEN_HELP:
794                 screen_switch(&screen_help, c);
795                 break;
796 #ifdef ENABLE_SEARCH_SCREEN
797         case CMD_SCREEN_SEARCH:
798                 screen_switch(&screen_search, c);
799                 break;
800 #endif
801 #ifdef ENABLE_ARTIST_SCREEN
802         case CMD_SCREEN_ARTIST:
803                 screen_switch(&screen_artist, c);
804                 break;
805 #endif
806 #ifdef ENABLE_KEYDEF_SCREEN
807         case CMD_SCREEN_KEYDEF:
808                 screen_switch(&screen_keydef, c);
809                 break;
810 #endif
811 #ifdef ENABLE_LYRICS_SCREEN
812         case CMD_SCREEN_LYRICS:
813                 screen_switch(&screen_lyrics, c);
814                 break;
815 #endif
816         default:
817                 break;
818         }