Code

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