Code

Clear the main window on CMD_SCREEN_UPDATE
[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   D("screen_paint()\n");
594   /* paint the title/header window */
595   if( mode_fn && mode_fn->get_title )
596     paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 1);
597   else
598     paint_top_window("", c, 1);
600   /* paint the main window */
601   wclear(screen->main_window.w);
602   if( mode_fn && mode_fn->paint )
603     mode_fn->paint(screen, c);
604   
605   paint_progress_window(c);
606   paint_status_window(c);
607   screen->painted = 1;
608   wmove(screen->main_window.w, 0, 0);  
609   wnoutrefresh(screen->main_window.w);
611   /* tell curses to update */
612   doupdate();
615 void 
616 screen_update(mpdclient_t *c)
618   static int repeat = -1;
619   static int random = -1;
620   static int crossfade = -1;
621   static int dbupdate = -1;
622   list_window_t *lw = NULL;
624   if( !screen->painted )
625     return screen_paint(c);
627   /* print a message if mpd status has changed */
628   if( repeat<0 )
629     {
630       repeat = c->status->repeat;
631       random = c->status->random;
632       crossfade = c->status->crossfade;
633       dbupdate = c->status->updatingDb;
634     }
635   if( repeat != c->status->repeat )
636     screen_status_printf(c->status->repeat ? 
637                          _("Repeat is on") :
638                          _("Repeat is off"));
639   if( random != c->status->random )
640     screen_status_printf(c->status->random ?
641                          _("Random is on") :
642                          _("Random is off"));
643                          
644   if( crossfade != c->status->crossfade )
645     screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
646   if( dbupdate && dbupdate != c->status->updatingDb )
647     {
648       screen_status_printf(_("Database updated!"));
649       mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
650     }
652   repeat = c->status->repeat;
653   random = c->status->random;
654   crossfade = c->status->crossfade;
655   dbupdate = c->status->updatingDb;
657   /* update title/header window */
658   if( welcome && screen->last_cmd==CMD_NONE &&
659       time(NULL)-screen->start_timestamp <= SCREEN_WELCOME_TIME)
660     paint_top_window("", c, 0);
661   else if( mode_fn && mode_fn->get_title )
662     {
663       paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 0);
664       welcome = FALSE;
665     }
666   else
667     paint_top_window("", c, 0);
669   /* update the main window */
670   if( mode_fn && mode_fn->paint )
671     mode_fn->update(screen, c);
673   if( mode_fn && mode_fn->get_lw )
674     lw = mode_fn->get_lw();
676   /* update progress window */
677   paint_progress_window(c);
679   /* update status window */
680   paint_status_window(c);
682   /* move the cursor to the selected row in the main window */
683   if( lw )
684     wmove(screen->main_window.w, LW_ROW(lw), 0);   
685   else
686     wmove(screen->main_window.w, 0, 0);   
687   wnoutrefresh(screen->main_window.w);
689   /* tell curses to update */
690   doupdate();
693 void
694 screen_idle(mpdclient_t *c)
696   if( c->song && seek_id ==  c->song->id &&
697       (screen->last_cmd == CMD_SEEK_FORWARD || 
698        screen->last_cmd == CMD_SEEK_BACKWARD) )
699     {
700       mpdclient_cmd_seek(c, seek_id, seek_target_time);
701     }
703   screen->last_cmd = CMD_NONE;
704   seek_id = -1;
707 void 
708 screen_cmd(mpdclient_t *c, command_t cmd)
710   screen_mode_t new_mode = screen->mode;
712   screen->input_timestamp = time(NULL);
713   screen->last_cmd = cmd;
714   welcome = FALSE;
716   if( mode_fn && mode_fn->cmd && mode_fn->cmd(screen, c, cmd) )
717     return;
719   switch(cmd)
720     {
721     case CMD_PLAY:
722       mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
723       break;
724     case CMD_PAUSE:
725       mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
726       break;
727     case CMD_STOP:
728       mpdclient_cmd_stop(c);
729       break;
730     case CMD_SEEK_FORWARD:
731       if( !IS_STOPPED(c->status->state) )
732         {
733           if( c->song && seek_id != c->song->id )
734             {
735               seek_id = c->song->id;
736               seek_target_time = c->status->elapsedTime;
737             }
738           seek_target_time++;
739           if( seek_target_time < c->status->totalTime )
740             break;
741           seek_target_time = c->status->totalTime;
742           /* seek_target_time=0; */
743         }
744       break;
745       /* fall through... */
746     case CMD_TRACK_NEXT:
747       if( !IS_STOPPED(c->status->state) )
748         mpdclient_cmd_next(c);
749       break;
750     case CMD_SEEK_BACKWARD:
751       if( !IS_STOPPED(c->status->state) )
752         {
753           if( seek_id != c->song->id )
754             {
755               seek_id = c->song->id;
756               seek_target_time = c->status->elapsedTime;
757             }
758           seek_target_time--;
759           if( seek_target_time < 0 )
760             seek_target_time=0;
761         }
762       break;
763     case CMD_TRACK_PREVIOUS:
764       if( !IS_STOPPED(c->status->state) )
765         mpdclient_cmd_prev(c);
766       break;   
767     case CMD_SHUFFLE:
768       if( mpdclient_cmd_shuffle(c) == 0 )
769         screen_status_message(_("Shuffled playlist!"));
770       break;
771     case CMD_CLEAR:
772       if( mpdclient_cmd_clear(c) == 0 )
773         screen_status_message(_("Cleared playlist!"));
774       break;
775     case CMD_REPEAT:
776       mpdclient_cmd_repeat(c, !c->status->repeat);
777       break;
778     case CMD_RANDOM:
779       mpdclient_cmd_random(c, !c->status->random);
780       break;
781     case CMD_CROSSFADE:
782       mpdclient_cmd_crossfade(c, c->status->crossfade ? 0 : CROSSFADE_TIME);
783       break;
784     case CMD_DB_UPDATE:
785       if( !c->status->updatingDb )
786         {
787           if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
788             screen_status_printf(_("Database update started!"));
789         }
790       else
791         screen_status_printf(_("Database update running..."));
792       break;
793     case CMD_VOLUME_UP:
794       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
795         mpdclient_cmd_volume(c, ++c->status->volume);
796       break;
797     case CMD_VOLUME_DOWN:
798       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
799         mpdclient_cmd_volume(c, --c->status->volume);
800       break;
801     case CMD_TOGGLE_FIND_WRAP:
802       options.find_wrap = !options.find_wrap;
803       screen_status_printf(options.find_wrap ? 
804                            _("Find mode: Wrapped") :
805                            _("Find mode: Normal"));
806       break;
807     case CMD_TOGGLE_AUTOCENTER:
808       options.auto_center = !options.auto_center;
809       screen_status_printf(options.auto_center ?
810                            _("Auto center mode: On") :
811                            _("Auto center mode: Off"));
812       break;
813     case CMD_SCREEN_UPDATE:
814       screen->painted = 0;
815       break;
816     case CMD_SCREEN_PREVIOUS:
817       if( screen->mode > SCREEN_PLAY_WINDOW )
818         new_mode = screen->mode - 1;
819       else
820         new_mode = SCREEN_HELP_WINDOW-1;
821       switch_screen_mode(new_mode, c);
822       break;
823     case CMD_SCREEN_NEXT:
824       new_mode = screen->mode + 1;
825       if( new_mode >= SCREEN_HELP_WINDOW )
826         new_mode = SCREEN_PLAY_WINDOW;
827       switch_screen_mode(new_mode, c);
828       break;
829     case CMD_SCREEN_PLAY:
830       switch_screen_mode(SCREEN_PLAY_WINDOW, c);
831       break;
832     case CMD_SCREEN_FILE:
833       switch_screen_mode(SCREEN_FILE_WINDOW, c);
834       break;
835     case CMD_SCREEN_SEARCH:
836       switch_screen_mode(SCREEN_SEARCH_WINDOW, c);
837       break;
838     case CMD_SCREEN_HELP:
839       switch_screen_mode(SCREEN_HELP_WINDOW, c);
840       break;
841 #ifdef ENABLE_KEYDEF_SCREEN 
842     case CMD_SCREEN_KEYDEF:
843       switch_screen_mode(SCREEN_KEYDEF_WINDOW, c);
844       break;
845 #endif
846 #ifdef ENABLE_CLOCK_SCREEN 
847     case CMD_SCREEN_CLOCK:
848       switch_screen_mode(SCREEN_CLOCK_WINDOW, c);
849       break;
850 #endif
851     case CMD_QUIT:
852       exit(EXIT_SUCCESS);
853     default:
854       break;
855     }