Code

display errors without exiting when key bindings are broken
[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 <stdlib.h>
22 #include <unistd.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <time.h>
26 #include <locale.h>
27 #include <glib.h>
28 #include <ncurses.h>
30 #include "config.h"
31 #include "ncmpc.h"
32 #include "support.h"
33 #include "mpdclient.h"
34 #include "command.h"
35 #include "options.h"
36 #include "colors.h"
37 #include "strfsong.h"
38 #include "wreadln.h"
39 #include "screen.h"
40 #include "screen_utils.h"
42 #define ENABLE_STATUS_LINE_CLOCK
43 #define ENABLE_SCROLLING
45 #define CROSSFADE_TIME 10
47 #define STATUS_MESSAGE_TIMEOUT 3
48 #define STATUS_LINE_MAX_SIZE   512
50 /* screens */
51 extern screen_functions_t *get_screen_playlist(void);
52 extern screen_functions_t *get_screen_browse(void);
53 extern screen_functions_t *get_screen_help(void);
55 #ifdef ENABLE_KEYDEF_SCREEN
56 extern screen_functions_t *get_screen_keydef(void);
57 #endif
58 #ifdef ENABLE_CLOCK_SCREEN
59 extern screen_functions_t *get_screen_clock(void);
60 #endif
62 static gboolean welcome = TRUE;
63 static screen_t *screen = NULL;
64 static screen_functions_t *mode_fn = NULL;
65 static int seek_id = -1;
66 static int seek_target_time = 0;
69 static void
70 switch_screen_mode(screen_mode_t new_mode, mpdclient_t *c)
71 {
72   if( new_mode == screen->mode )
73     return;
75   /* close the old mode */
76   if( mode_fn && mode_fn->close )
77     mode_fn->close();
79   /* get functions for the new mode */
80   switch(new_mode)
81     {
82     case SCREEN_PLAY_WINDOW:
83       mode_fn = get_screen_playlist();
84       break;
85     case SCREEN_FILE_WINDOW:
86       mode_fn = get_screen_browse();
87       break;
88     case SCREEN_HELP_WINDOW:
89       mode_fn = get_screen_help();
90       break;
91 #ifdef ENABLE_KEYDEF_SCREEN
92     case SCREEN_KEYDEF_WINDOW:
93       mode_fn = get_screen_keydef();
94       break;
95 #endif
96 #ifdef ENABLE_CLOCK_SCREEN
97     case SCREEN_CLOCK_WINDOW:
98       mode_fn = get_screen_clock();
99       break;
100 #endif
102     default:
103       break;
104     }
106  screen->mode = new_mode;
107  screen->painted = 0;
109  /* open the new mode */
110  if( mode_fn && mode_fn->open )
111    mode_fn->open(screen, c);
115 static void
116 paint_top_window(char *header, mpdclient_t *c, int clear)
118   char flags[4];
119   static int prev_volume = -1;
120   static int prev_header_len = -1;
121   WINDOW *w = screen->top_window.w;
123   if(prev_header_len!=strlen(header))
124     {
125       prev_header_len = strlen(header);
126       clear = 1;
127     }
129   if(clear)
130     {
131       wmove(w, 0, 0);
132       wclrtoeol(w);
133     }
135   if(prev_volume!=c->status->volume || clear)
136     {
137       char buf[32];
139       if( header[0] )
140         {
141           colors_use(w, COLOR_TITLE_BOLD);
142           mvwaddstr(w, 0, 0, header);
143         }
144       else
145         {
146           colors_use(w, COLOR_TITLE_BOLD);
147           waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
148           colors_use(w, COLOR_TITLE);
149           waddstr(w, _(":Help  "));
150           colors_use(w, COLOR_TITLE_BOLD);
151           waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
152           colors_use(w, COLOR_TITLE);
153           waddstr(w, _(":Playlist  "));
154           colors_use(w, COLOR_TITLE_BOLD);
155           waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
156           colors_use(w, COLOR_TITLE);
157           waddstr(w, _(":Browse"));
158         }
159       if( c->status->volume==MPD_STATUS_NO_VOLUME )
160         {
161           snprintf(buf, 32, _("Volume n/a "));
162         }
163       else
164         {
165           snprintf(buf, 32, _(" Volume %d%%"), c->status->volume); 
166         }
167       colors_use(w, COLOR_TITLE);
168       mvwaddstr(w, 0, screen->top_window.cols-strlen(buf), buf);
170       flags[0] = 0;
171       if( c->status->repeat )
172         strcat(flags, "r");
173       if( c->status->random )
174         strcat(flags, "z");
175       if( c->status->crossfade )
176         strcat(flags, "x");
177       if( c->status->updatingDb )
178         strcat(flags, "U");
179       colors_use(w, COLOR_LINE);
180       mvwhline(w, 1, 0, ACS_HLINE, screen->top_window.cols);
181       if( flags[0] )
182         {
183           wmove(w,1,screen->top_window.cols-strlen(flags)-3);
184           waddch(w, '[');
185           colors_use(w, COLOR_LINE_BOLD);
186           waddstr(w, flags);
187           colors_use(w, COLOR_LINE);
188           waddch(w, ']');
189         }
190       wnoutrefresh(w);
191     }
194 static void
195 paint_progress_window(mpdclient_t *c)
197   double p;
198   int width;
199   int elapsedTime = c->status->elapsedTime;
201   if( c->status==NULL || IS_STOPPED(c->status->state) )
202     {
203       mvwhline(screen->progress_window.w, 0, 0, ACS_HLINE, 
204                screen->progress_window.cols);
205       wnoutrefresh(screen->progress_window.w);
206       return;
207     }
209   if( c->song && seek_id == c->song->id )
210     elapsedTime = seek_target_time;
212   p = ((double) elapsedTime) / ((double) c->status->totalTime);
213   
214   width = (int) (p * (double) screen->progress_window.cols);
215   mvwhline(screen->progress_window.w, 
216            0, 0,
217            ACS_HLINE, 
218            screen->progress_window.cols);
219   whline(screen->progress_window.w, '=', width-1);
220   mvwaddch(screen->progress_window.w, 0, width-1, 'O');
221   wnoutrefresh(screen->progress_window.w);
224 static void 
225 paint_status_window(mpdclient_t *c)
227   WINDOW *w = screen->status_window.w;
228   mpd_Status *status = c->status;
229   mpd_Song *song   = c->song;
230   int elapsedTime = c->status->elapsedTime;
231   char *str = NULL;
232   int x = 0;
234   if( time(NULL) - screen->status_timestamp <= STATUS_MESSAGE_TIMEOUT )
235     return;
236   
237   
238   wmove(w, 0, 0);
239   wclrtoeol(w);
240   colors_use(w, COLOR_STATUS_BOLD);
241   
242   switch(status->state)
243     {
244     case MPD_STATUS_STATE_PLAY:
245       str = _("Playing:");
246       break;
247     case MPD_STATUS_STATE_PAUSE:
248       str = _("[Paused]");
249       break;
250     case MPD_STATUS_STATE_STOP:
251     default:
252       break;
253     }
255   if( str )
256     {
257       waddstr(w, str);
258       x += strlen(str)+1;
259     }
261   /* create time string */
262   memset(screen->buf, 0, screen->buf_size);
263   if( IS_PLAYING(status->state) || IS_PAUSED(status->state) )
264     {
265       if( status->totalTime > 0 )
266         {
267           if( c->song && seek_id == c->song->id )
268             elapsedTime = seek_target_time;
269           snprintf(screen->buf, screen->buf_size, 
270                    " [%i:%02i/%i:%02i]",
271                    elapsedTime/60, elapsedTime%60,
272                    status->totalTime/60,   status->totalTime%60 );
273         }
274       else
275         {
276           snprintf(screen->buf, screen->buf_size,  " [%d kbps]", status->bitRate );
277         }
278     }
279 #ifdef ENABLE_STATUS_LINE_CLOCK
280   else
281     {
282       time_t timep;
284       time(&timep);
285       strftime(screen->buf, screen->buf_size, "%X ",localtime(&timep));
286     }
287 #endif
289   /* display song */
290   if( (IS_PLAYING(status->state) || IS_PAUSED(status->state)) )
291     {
292       char songname[STATUS_LINE_MAX_SIZE];
293       int width = COLS-x-strlen(screen->buf);
295       if( song )
296         strfsong(songname, STATUS_LINE_MAX_SIZE, STATUS_FORMAT, song);
297       else
298         songname[0] = '\0';
300       colors_use(w, COLOR_STATUS);
301 #ifdef ENABLE_SCROLLING
302       if( strlen(songname) > width )
303         {
304           static  scroll_state_t st = { 0, 0 };
305           char *tmp = strscroll(songname, " *** ", width, &st);
307           strcpy(songname, tmp);
308           g_free(tmp);    
309         }
310 #endif
311       mvwaddnstr(w, 0, x, songname, width);
312     } 
314   /* distplay time string */
315   if( screen->buf[0] )
316     {
317       x = screen->status_window.cols - strlen(screen->buf);
318       colors_use(w, COLOR_STATUS_TIME);
319       mvwaddstr(w, 0, x, screen->buf);
320     }
322   wnoutrefresh(w);
325 GList *
326 screen_free_string_list(GList *list)
328   GList *l = g_list_first(list);
329   
330   while(l)
331     {
332       g_free(l->data);
333       l->data = NULL;
334       l=l->next;
335     }
336   g_list_free(list);
337   return NULL;
340 int
341 screen_exit(void)
343   endwin();
344   if( screen )
345     {
346       GList *list = g_list_first(screen->screen_list);
348       /* close and exit all screens (playlist,browse,help...) */
349       while( list )
350         {
351           screen_functions_t *mode_fn = list->data;
353           if( mode_fn && mode_fn->close )
354             mode_fn->close();
355           if( mode_fn && mode_fn->exit )
356             mode_fn->exit();
357           list->data = NULL;
358           list=list->next;
359         }
360       g_list_free(screen->screen_list);
361       screen_free_string_list(screen->find_history);
362       g_free(screen->buf);
363       g_free(screen->findbuf);
364       
365       g_free(screen);
366       screen = NULL;
367     }
368   return 0;
371 void
372 screen_resize(void)
374   GList *list;
376   D("Resize rows %d->%d, cols %d->%d\n",screen->rows,LINES,screen->cols,COLS);
377   if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
378     {
379       screen_exit();
380       fprintf(stderr, _("Error: Screen to small!\n"));
381       exit(EXIT_FAILURE);
382     }
384   resizeterm(LINES, COLS);
386   screen->cols = COLS;
387   screen->rows = LINES;
389   /* top window */
390   screen->top_window.cols = screen->cols;
391   wresize(screen->top_window.w, 2, screen->cols);
393   /* main window */
394   screen->main_window.cols = screen->cols;
395   screen->main_window.rows = screen->rows-4;
396   wresize(screen->main_window.w, screen->main_window.rows, screen->cols);
397   wclear(screen->main_window.w);
399   /* progress window */
400   screen->progress_window.cols = screen->cols;
401   wresize(screen->progress_window.w, 1, screen->cols);
402   mvwin(screen->progress_window.w, screen->rows-2, 0);
404   /* status window */
405   screen->status_window.cols = screen->cols;
406   wresize(screen->status_window.w, 1, screen->cols);
407   mvwin(screen->status_window.w, screen->rows-1, 0);
409   screen->buf_size = screen->cols;
410   g_free(screen->buf);
411   screen->buf = g_malloc(screen->cols);
413   list = g_list_first(screen->screen_list);
414   while( list )
415     {
416       screen_functions_t *mode_fn = list->data;
418       if( mode_fn && mode_fn->resize )
419         mode_fn->resize(screen->main_window.cols, screen->main_window.rows);
421       list=list->next;
422     }
424   /* ? - without this the cursor becomes visible with aterm & Eterm */
425   curs_set(1);
426   curs_set(0);     
428   screen->painted = 0;
431 void 
432 screen_status_message(char *msg)
434   WINDOW *w = screen->status_window.w;
436   wmove(w, 0, 0);
437   wclrtoeol(w);
438   colors_use(w, COLOR_STATUS_ALERT);
439   waddstr(w, msg);
440   wnoutrefresh(w);
441   screen->status_timestamp = time(NULL);
444 void 
445 screen_status_printf(char *format, ...)
447   char buffer[STATUS_LINE_MAX_SIZE];
448   va_list ap;
449   
450   va_start(ap,format);
451   vsnprintf(buffer,sizeof(buffer),format,ap);
452   va_end(ap);
453   screen_status_message(buffer);
456 int
457 screen_init(mpdclient_t *c)
459   GList *list;
461   /* initialize the curses library */
462   initscr();
463   /* initialize color support */
464   colors_start();
465   /* tell curses not to do NL->CR/NL on output */
466   nonl();          
467   /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
468   raw();
469   /* don't echo input */
470   noecho();    
471   /* set cursor invisible */     
472   curs_set(0);     
473   /* enable extra keys */
474   keypad(stdscr, TRUE);  
475   /* return from getch() without blocking */
476   timeout(SCREEN_TIMEOUT);
477   
479   if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
480     {
481       fprintf(stderr, _("Error: Screen to small!\n"));
482       exit(EXIT_FAILURE);
483     }
485   screen = g_malloc(sizeof(screen_t));
486   memset(screen, 0, sizeof(screen_t));
487   screen->mode = SCREEN_PLAY_WINDOW;
488   screen->cols = COLS;
489   screen->rows = LINES;
490   screen->buf  = g_malloc(screen->cols);
491   screen->buf_size = screen->cols;
492   screen->findbuf = NULL;
493   screen->painted = 0;
494   screen->start_timestamp = time(NULL);
495   screen->input_timestamp = time(NULL);
496   screen->last_cmd = CMD_NONE;
498   /* create top window */
499   screen->top_window.rows = 2;
500   screen->top_window.cols = screen->cols;
501   screen->top_window.w = newwin(screen->top_window.rows, 
502                                   screen->top_window.cols,
503                                   0, 0);
504   leaveok(screen->top_window.w, TRUE);
505   keypad(screen->top_window.w, TRUE);  
507   /* create main window */
508   screen->main_window.rows = screen->rows-4;
509   screen->main_window.cols = screen->cols;
510   screen->main_window.w = newwin(screen->main_window.rows, 
511                                  screen->main_window.cols,
512                                  2, 
513                                  0);
515   //  leaveok(screen->main_window.w, TRUE); temporary disabled
516   keypad(screen->main_window.w, TRUE);  
518   /* create progress window */
519   screen->progress_window.rows = 1;
520   screen->progress_window.cols = screen->cols;
521   screen->progress_window.w = newwin(screen->progress_window.rows, 
522                                      screen->progress_window.cols,
523                                      screen->rows-2, 
524                                      0);
525   leaveok(screen->progress_window.w, TRUE);
526   
527   /* create status window */
528   screen->status_window.rows = 1;
529   screen->status_window.cols = screen->cols;
530   screen->status_window.w = newwin(screen->status_window.rows, 
531                                    screen->status_window.cols,
532                                    screen->rows-1, 
533                                    0);
535   leaveok(screen->status_window.w, FALSE);
536   keypad(screen->status_window.w, TRUE);  
538   if( options.enable_colors )
539     {
540       /* set background attributes */
541       wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); 
542       wbkgd(screen->main_window.w,     COLOR_PAIR(COLOR_LIST));
543       wbkgd(screen->top_window.w,      COLOR_PAIR(COLOR_TITLE));
544       wbkgd(screen->progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
545       wbkgd(screen->status_window.w,   COLOR_PAIR(COLOR_STATUS));
546       colors_use(screen->progress_window.w, COLOR_PROGRESSBAR);
547     }
549   /* initialize screens */
550   screen->screen_list = NULL;
551   screen->screen_list = g_list_append(screen->screen_list, 
552                                       (gpointer) get_screen_playlist());
553   screen->screen_list = g_list_append(screen->screen_list, 
554                                       (gpointer) get_screen_browse());
555   screen->screen_list = g_list_append(screen->screen_list, 
556                                       (gpointer) get_screen_help());
557 #ifdef ENABLE_KEYDEF_SCREEN
558   screen->screen_list = g_list_append(screen->screen_list, 
559                                       (gpointer) get_screen_keydef());
560 #endif
561 #ifdef ENABLE_CLOCK_SCREEN
562   screen->screen_list = g_list_append(screen->screen_list, 
563                                       (gpointer) get_screen_clock());
564 #endif
566   list = screen->screen_list;
567   while( list )
568     {
569       screen_functions_t *fn = list->data;
570       
571       if( fn && fn->init )
572         fn->init(screen->main_window.w, 
573                  screen->main_window.cols,
574                  screen->main_window.rows);
575       
576       list = list->next;
577     }
579   mode_fn = get_screen_playlist();
580   if( mode_fn && mode_fn->open )
581     mode_fn->open(screen, c);
583   /* initialize wreadln */
584   wrln_resize_callback = screen_resize;
585   wrln_max_history_length = 16;
587   return 0;
590 void 
591 screen_paint(mpdclient_t *c)
593   /* paint the title/header window */
594   if( mode_fn && mode_fn->get_title )
595     paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 1);
596   else
597     paint_top_window("", c, 1);
599   /* paint the main window */
600   if( mode_fn && mode_fn->paint )
601     mode_fn->paint(screen, c);
602   
603   paint_progress_window(c);
604   paint_status_window(c);
605   screen->painted = 1;
606   wmove(screen->main_window.w, 0, 0);  
607   wnoutrefresh(screen->main_window.w);
609   /* tell curses to update */
610   doupdate();
613 void 
614 screen_update(mpdclient_t *c)
616   static int repeat = -1;
617   static int random = -1;
618   static int crossfade = -1;
619   static int dbupdate = -1;
620   list_window_t *lw = NULL;
622   if( !screen->painted )
623     return screen_paint(c);
625   /* print a message if mpd status has changed */
626   if( repeat<0 )
627     {
628       repeat = c->status->repeat;
629       random = c->status->random;
630       crossfade = c->status->crossfade;
631       dbupdate = c->status->updatingDb;
632     }
633   if( repeat != c->status->repeat )
634     screen_status_printf(c->status->repeat ? 
635                          _("Repeat is on") :
636                          _("Repeat is off"));
637   if( random != c->status->random )
638     screen_status_printf(c->status->random ?
639                          _("Random is on") :
640                          _("Random is off"));
641                          
642   if( crossfade != c->status->crossfade )
643     screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
644   if( dbupdate && dbupdate != c->status->updatingDb )
645     {
646       screen_status_printf(_("Database updated!"));
647       mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
648     }
650   repeat = c->status->repeat;
651   random = c->status->random;
652   crossfade = c->status->crossfade;
653   dbupdate = c->status->updatingDb;
655   /* update title/header window */
656   if( welcome && screen->last_cmd==CMD_NONE &&
657       time(NULL)-screen->start_timestamp <= SCREEN_WELCOME_TIME)
658     paint_top_window("", c, 0);
659   else if( mode_fn && mode_fn->get_title )
660     {
661       paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 0);
662       welcome = FALSE;
663     }
664   else
665     paint_top_window("", c, 0);
667   /* update the main window */
668   if( mode_fn && mode_fn->paint )
669     mode_fn->update(screen, c);
671   if( mode_fn && mode_fn->get_lw )
672     lw = mode_fn->get_lw();
674   /* update progress window */
675   paint_progress_window(c);
677   /* update status window */
678   paint_status_window(c);
680   /* move the cursor to the selected row in the main window */
681   if( lw )
682     wmove(screen->main_window.w, LW_ROW(lw), 0);   
683   else
684     wmove(screen->main_window.w, 0, 0);   
685   wnoutrefresh(screen->main_window.w);
687   /* tell curses to update */
688   doupdate();
691 void
692 screen_idle(mpdclient_t *c)
694   if( c->song && seek_id ==  c->song->id &&
695       (screen->last_cmd == CMD_SEEK_FORWARD || 
696        screen->last_cmd == CMD_SEEK_BACKWARD) )
697     {
698       mpdclient_cmd_seek(c, seek_id, seek_target_time);
699     }
701   screen->last_cmd = CMD_NONE;
702   seek_id = -1;
705 void 
706 screen_cmd(mpdclient_t *c, command_t cmd)
708   screen_mode_t new_mode = screen->mode;
710   screen->input_timestamp = time(NULL);
711   screen->last_cmd = cmd;
712   welcome = FALSE;
714   if( mode_fn && mode_fn->cmd && mode_fn->cmd(screen, c, cmd) )
715     return;
717   switch(cmd)
718     {
719     case CMD_PLAY:
720       mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
721       break;
722     case CMD_PAUSE:
723       mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
724       break;
725     case CMD_STOP:
726       mpdclient_cmd_stop(c);
727       break;
728     case CMD_SEEK_FORWARD:
729       if( !IS_STOPPED(c->status->state) )
730         {
731           if( c->song && seek_id != c->song->id )
732             {
733               seek_id = c->song->id;
734               seek_target_time = c->status->elapsedTime;
735             }
736           seek_target_time++;
737           if( seek_target_time < c->status->totalTime )
738             break;
739           seek_target_time = c->status->totalTime;
740           /* seek_target_time=0; */
741         }
742       break;
743       /* fall through... */
744     case CMD_TRACK_NEXT:
745       if( !IS_STOPPED(c->status->state) )
746         mpdclient_cmd_next(c);
747       break;
748     case CMD_SEEK_BACKWARD:
749       if( !IS_STOPPED(c->status->state) )
750         {
751           if( seek_id != c->song->id )
752             {
753               seek_id = c->song->id;
754               seek_target_time = c->status->elapsedTime;
755             }
756           seek_target_time--;
757           if( seek_target_time < 0 )
758             seek_target_time=0;
759         }
760       break;
761     case CMD_TRACK_PREVIOUS:
762       if( !IS_STOPPED(c->status->state) )
763         mpdclient_cmd_prev(c);
764       break;   
765     case CMD_SHUFFLE:
766       if( mpdclient_cmd_shuffle(c) == 0 )
767         screen_status_message(_("Shuffled playlist!"));
768       break;
769     case CMD_CLEAR:
770       if( mpdclient_cmd_clear(c) == 0 )
771         screen_status_message(_("Cleared playlist!"));
772       break;
773     case CMD_REPEAT:
774       mpdclient_cmd_repeat(c, !c->status->repeat);
775       break;
776     case CMD_RANDOM:
777       mpdclient_cmd_random(c, !c->status->random);
778       break;
779     case CMD_CROSSFADE:
780       mpdclient_cmd_crossfade(c, c->status->crossfade ? 0 : CROSSFADE_TIME);
781       break;
782     case CMD_DB_UPDATE:
783       if( !c->status->updatingDb )
784         {
785           if( mpdclient_cmd_db_update(c,NULL)==0 )
786             screen_status_printf(_("Database update started!"));
787         }
788       else
789         screen_status_printf(_("Database update running..."));
790       break;
791     case CMD_VOLUME_UP:
792       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
793         mpdclient_cmd_volume(c, ++c->status->volume);
794       break;
795     case CMD_VOLUME_DOWN:
796       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
797         mpdclient_cmd_volume(c, --c->status->volume);
798       break;
799     case CMD_TOGGLE_FIND_WRAP:
800       options.find_wrap = !options.find_wrap;
801       screen_status_printf(options.find_wrap ? 
802                            _("Find mode: Wrapped") :
803                            _("Find mode: Normal"));
804       break;
805     case CMD_TOGGLE_AUTOCENTER:
806       options.auto_center = !options.auto_center;
807       screen_status_printf(options.auto_center ?
808                            _("Auto center mode: On") :
809                            _("Auto center mode: Off"));
810       break;
811     case CMD_SCREEN_PREVIOUS:
812       if( screen->mode > SCREEN_PLAY_WINDOW )
813         new_mode = screen->mode - 1;
814       else
815         new_mode = SCREEN_HELP_WINDOW-1;
816       switch_screen_mode(new_mode, c);
817       break;
818     case CMD_SCREEN_NEXT:
819       new_mode = screen->mode + 1;
820       if( new_mode >= SCREEN_HELP_WINDOW )
821         new_mode = SCREEN_PLAY_WINDOW;
822       switch_screen_mode(new_mode, c);
823       break;
824     case CMD_SCREEN_PLAY:
825       switch_screen_mode(SCREEN_PLAY_WINDOW, c);
826       break;
827     case CMD_SCREEN_FILE:
828       switch_screen_mode(SCREEN_FILE_WINDOW, c);
829       break;
830     case CMD_SCREEN_SEARCH:
831       switch_screen_mode(SCREEN_SEARCH_WINDOW, c);
832       break;
833     case CMD_SCREEN_HELP:
834       switch_screen_mode(SCREEN_HELP_WINDOW, c);
835       break;
836 #ifdef ENABLE_KEYDEF_SCREEN 
837     case CMD_SCREEN_KEYDEF:
838       switch_screen_mode(SCREEN_KEYDEF_WINDOW, c);
839       break;
840 #endif
841 #ifdef ENABLE_CLOCK_SCREEN 
842     case CMD_SCREEN_CLOCK:
843       switch_screen_mode(SCREEN_CLOCK_WINDOW, c);
844       break;
845 #endif
846     case CMD_QUIT:
847       exit(EXIT_SUCCESS);
848     default:
849       break;
850     }