Code

Mouse support is now optional (enable-mouse)
[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 #ifdef ENABLE_RAW_MODE
469   raw();
470 #endif
471   /* don't echo input */
472   noecho();    
473   /* set cursor invisible */     
474   curs_set(0);     
475   /* enable extra keys */
476   keypad(stdscr, TRUE);  
477   /* return from getch() without blocking */
478   timeout(SCREEN_TIMEOUT);
479   /* initialize mouse support */
480 #ifdef HAVE_GETMOUSE
481   if( options.enable_mouse_events )
482     mousemask(ALL_MOUSE_EVENTS, NULL);
483 #endif
485   if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
486     {
487       fprintf(stderr, _("Error: Screen to small!\n"));
488       exit(EXIT_FAILURE);
489     }
491   screen = g_malloc(sizeof(screen_t));
492   memset(screen, 0, sizeof(screen_t));
493   screen->mode = SCREEN_PLAY_WINDOW;
494   screen->cols = COLS;
495   screen->rows = LINES;
496   screen->buf  = g_malloc(screen->cols);
497   screen->buf_size = screen->cols;
498   screen->findbuf = NULL;
499   screen->painted = 0;
500   screen->start_timestamp = time(NULL);
501   screen->input_timestamp = time(NULL);
502   screen->last_cmd = CMD_NONE;
504   /* create top window */
505   screen->top_window.rows = 2;
506   screen->top_window.cols = screen->cols;
507   screen->top_window.w = newwin(screen->top_window.rows, 
508                                   screen->top_window.cols,
509                                   0, 0);
510   leaveok(screen->top_window.w, TRUE);
511   keypad(screen->top_window.w, TRUE);  
513   /* create main window */
514   screen->main_window.rows = screen->rows-4;
515   screen->main_window.cols = screen->cols;
516   screen->main_window.w = newwin(screen->main_window.rows, 
517                                  screen->main_window.cols,
518                                  2, 
519                                  0);
521   //  leaveok(screen->main_window.w, TRUE); temporary disabled
522   keypad(screen->main_window.w, TRUE);  
524   /* create progress window */
525   screen->progress_window.rows = 1;
526   screen->progress_window.cols = screen->cols;
527   screen->progress_window.w = newwin(screen->progress_window.rows, 
528                                      screen->progress_window.cols,
529                                      screen->rows-2, 
530                                      0);
531   leaveok(screen->progress_window.w, TRUE);
532   
533   /* create status window */
534   screen->status_window.rows = 1;
535   screen->status_window.cols = screen->cols;
536   screen->status_window.w = newwin(screen->status_window.rows, 
537                                    screen->status_window.cols,
538                                    screen->rows-1, 
539                                    0);
541   leaveok(screen->status_window.w, FALSE);
542   keypad(screen->status_window.w, TRUE);  
544   if( options.enable_colors )
545     {
546       /* set background attributes */
547       wbkgd(stdscr, COLOR_PAIR(COLOR_LIST)); 
548       wbkgd(screen->main_window.w,     COLOR_PAIR(COLOR_LIST));
549       wbkgd(screen->top_window.w,      COLOR_PAIR(COLOR_TITLE));
550       wbkgd(screen->progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
551       wbkgd(screen->status_window.w,   COLOR_PAIR(COLOR_STATUS));
552       colors_use(screen->progress_window.w, COLOR_PROGRESSBAR);
553     }
555   /* initialize screens */
556   screen->screen_list = NULL;
557   screen->screen_list = g_list_append(screen->screen_list, 
558                                       (gpointer) get_screen_playlist());
559   screen->screen_list = g_list_append(screen->screen_list, 
560                                       (gpointer) get_screen_browse());
561   screen->screen_list = g_list_append(screen->screen_list, 
562                                       (gpointer) get_screen_help());
563 #ifdef ENABLE_KEYDEF_SCREEN
564   screen->screen_list = g_list_append(screen->screen_list, 
565                                       (gpointer) get_screen_keydef());
566 #endif
567 #ifdef ENABLE_CLOCK_SCREEN
568   screen->screen_list = g_list_append(screen->screen_list, 
569                                       (gpointer) get_screen_clock());
570 #endif
572   list = screen->screen_list;
573   while( list )
574     {
575       screen_functions_t *fn = list->data;
576       
577       if( fn && fn->init )
578         fn->init(screen->main_window.w, 
579                  screen->main_window.cols,
580                  screen->main_window.rows);
581       
582       list = list->next;
583     }
585   mode_fn = get_screen_playlist();
586   if( mode_fn && mode_fn->open )
587     mode_fn->open(screen, c);
589   /* initialize wreadln */
590   wrln_resize_callback = screen_resize;
591   wrln_max_history_length = 16;
593   return 0;
596 void 
597 screen_paint(mpdclient_t *c)
599   D("screen_paint()\n");
600   /* paint the title/header window */
601   if( mode_fn && mode_fn->get_title )
602     paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 1);
603   else
604     paint_top_window("", c, 1);
606   /* paint the main window */
607   wclear(screen->main_window.w);
608   if( mode_fn && mode_fn->paint )
609     mode_fn->paint(screen, c);
610   
611   paint_progress_window(c);
612   paint_status_window(c);
613   screen->painted = 1;
614   wmove(screen->main_window.w, 0, 0);  
615   wnoutrefresh(screen->main_window.w);
617   /* tell curses to update */
618   doupdate();
621 void 
622 screen_update(mpdclient_t *c)
624   static int repeat = -1;
625   static int random = -1;
626   static int crossfade = -1;
627   static int dbupdate = -1;
628   list_window_t *lw = NULL;
630   if( !screen->painted )
631     return screen_paint(c);
633   /* print a message if mpd status has changed */
634   if( repeat<0 )
635     {
636       repeat = c->status->repeat;
637       random = c->status->random;
638       crossfade = c->status->crossfade;
639       dbupdate = c->status->updatingDb;
640     }
641   if( repeat != c->status->repeat )
642     screen_status_printf(c->status->repeat ? 
643                          _("Repeat is on") :
644                          _("Repeat is off"));
645   if( random != c->status->random )
646     screen_status_printf(c->status->random ?
647                          _("Random is on") :
648                          _("Random is off"));
649                          
650   if( crossfade != c->status->crossfade )
651     screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
652   if( dbupdate && dbupdate != c->status->updatingDb )
653     {
654       screen_status_printf(_("Database updated!"));
655       mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
656     }
658   repeat = c->status->repeat;
659   random = c->status->random;
660   crossfade = c->status->crossfade;
661   dbupdate = c->status->updatingDb;
663   /* update title/header window */
664   if( welcome && screen->last_cmd==CMD_NONE &&
665       time(NULL)-screen->start_timestamp <= SCREEN_WELCOME_TIME)
666     paint_top_window("", c, 0);
667   else if( mode_fn && mode_fn->get_title )
668     {
669       paint_top_window(mode_fn->get_title(screen->buf,screen->buf_size), c, 0);
670       welcome = FALSE;
671     }
672   else
673     paint_top_window("", c, 0);
675   /* update the main window */
676   if( mode_fn && mode_fn->paint )
677     mode_fn->update(screen, c);
679   if( mode_fn && mode_fn->get_lw )
680     lw = mode_fn->get_lw();
682   /* update progress window */
683   paint_progress_window(c);
685   /* update status window */
686   paint_status_window(c);
688   /* move the cursor to the selected row in the main window */
689   if( lw )
690     wmove(screen->main_window.w, LW_ROW(lw), 0);   
691   else
692     wmove(screen->main_window.w, 0, 0);   
693   wnoutrefresh(screen->main_window.w);
695   /* tell curses to update */
696   doupdate();
699 void
700 screen_idle(mpdclient_t *c)
702   if( c->song && seek_id ==  c->song->id &&
703       (screen->last_cmd == CMD_SEEK_FORWARD || 
704        screen->last_cmd == CMD_SEEK_BACKWARD) )
705     {
706       mpdclient_cmd_seek(c, seek_id, seek_target_time);
707     }
709   screen->last_cmd = CMD_NONE;
710   seek_id = -1;
713 #ifdef HAVE_GETMOUSE
714 int
715 screen_get_mouse_event(mpdclient_t *c,
716                        list_window_t *lw, int lw_length, 
717                        unsigned long *bstate, int *row)
719   MEVENT event;
721   /* retreive the mouse event from ncurses */
722   getmouse(&event);
723   D("mouse: id=%d  y=%d,x=%d,z=%d\n",event.id,event.y,event.x,event.z);
724   /* calculate the selected row in the list window */
725   *row = event.y - screen->top_window.rows;
726   /* copy button state bits */
727   *bstate = event.bstate;
728   /* if button 2 was pressed switch screen */
729   if( event.bstate & BUTTON2_CLICKED )
730     {
731       screen_cmd(c, CMD_SCREEN_NEXT);
732       return 1;
733     }
734   /* if the even occured above the list window move up */
735   if( *row<0 && lw )
736     {
737       if( event.bstate & BUTTON3_CLICKED )
738         list_window_first(lw);
739       else
740         list_window_previous_page(lw);
741       return 1;
742     }
743    /* if the even occured below the list window move down */
744   if( *row>=lw->rows && lw )
745     {
746       if( event.bstate & BUTTON3_CLICKED )
747         list_window_last(lw, lw_length);
748       else
749         list_window_next_page(lw, lw_length);
750       return 1;
751     } 
752   return 0;
754 #endif
756 void 
757 screen_cmd(mpdclient_t *c, command_t cmd)
759   screen_mode_t new_mode = screen->mode;
761   screen->input_timestamp = time(NULL);
762   screen->last_cmd = cmd;
763   welcome = FALSE;
765   if( mode_fn && mode_fn->cmd && mode_fn->cmd(screen, c, cmd) )
766     return;
768   switch(cmd)
769     {
770     case CMD_PLAY:
771       mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
772       break;
773     case CMD_PAUSE:
774       mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
775       break;
776     case CMD_STOP:
777       mpdclient_cmd_stop(c);
778       break;
779     case CMD_SEEK_FORWARD:
780       if( !IS_STOPPED(c->status->state) )
781         {
782           if( c->song && seek_id != c->song->id )
783             {
784               seek_id = c->song->id;
785               seek_target_time = c->status->elapsedTime;
786             }
787           seek_target_time++;
788           if( seek_target_time < c->status->totalTime )
789             break;
790           seek_target_time = c->status->totalTime;
791           /* seek_target_time=0; */
792         }
793       break;
794       /* fall through... */
795     case CMD_TRACK_NEXT:
796       if( !IS_STOPPED(c->status->state) )
797         mpdclient_cmd_next(c);
798       break;
799     case CMD_SEEK_BACKWARD:
800       if( !IS_STOPPED(c->status->state) )
801         {
802           if( seek_id != c->song->id )
803             {
804               seek_id = c->song->id;
805               seek_target_time = c->status->elapsedTime;
806             }
807           seek_target_time--;
808           if( seek_target_time < 0 )
809             seek_target_time=0;
810         }
811       break;
812     case CMD_TRACK_PREVIOUS:
813       if( !IS_STOPPED(c->status->state) )
814         mpdclient_cmd_prev(c);
815       break;   
816     case CMD_SHUFFLE:
817       if( mpdclient_cmd_shuffle(c) == 0 )
818         screen_status_message(_("Shuffled playlist!"));
819       break;
820     case CMD_CLEAR:
821       if( mpdclient_cmd_clear(c) == 0 )
822         screen_status_message(_("Cleared playlist!"));
823       break;
824     case CMD_REPEAT:
825       mpdclient_cmd_repeat(c, !c->status->repeat);
826       break;
827     case CMD_RANDOM:
828       mpdclient_cmd_random(c, !c->status->random);
829       break;
830     case CMD_CROSSFADE:
831       mpdclient_cmd_crossfade(c, c->status->crossfade ? 0 : CROSSFADE_TIME);
832       break;
833     case CMD_DB_UPDATE:
834       if( !c->status->updatingDb )
835         {
836           if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
837             screen_status_printf(_("Database update started!"));
838         }
839       else
840         screen_status_printf(_("Database update running..."));
841       break;
842     case CMD_VOLUME_UP:
843       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
844         mpdclient_cmd_volume(c, ++c->status->volume);
845       break;
846     case CMD_VOLUME_DOWN:
847       if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
848         mpdclient_cmd_volume(c, --c->status->volume);
849       break;
850     case CMD_TOGGLE_FIND_WRAP:
851       options.find_wrap = !options.find_wrap;
852       screen_status_printf(options.find_wrap ? 
853                            _("Find mode: Wrapped") :
854                            _("Find mode: Normal"));
855       break;
856     case CMD_TOGGLE_AUTOCENTER:
857       options.auto_center = !options.auto_center;
858       screen_status_printf(options.auto_center ?
859                            _("Auto center mode: On") :
860                            _("Auto center mode: Off"));
861       break;
862     case CMD_SCREEN_UPDATE:
863       screen->painted = 0;
864       break;
865     case CMD_SCREEN_PREVIOUS:
866       if( screen->mode > SCREEN_PLAY_WINDOW )
867         new_mode = screen->mode - 1;
868       else
869         new_mode = SCREEN_HELP_WINDOW-1;
870       switch_screen_mode(new_mode, c);
871       break;
872     case CMD_SCREEN_NEXT:
873       new_mode = screen->mode + 1;
874       if( new_mode >= SCREEN_HELP_WINDOW )
875         new_mode = SCREEN_PLAY_WINDOW;
876       switch_screen_mode(new_mode, c);
877       break;
878     case CMD_SCREEN_PLAY:
879       switch_screen_mode(SCREEN_PLAY_WINDOW, c);
880       break;
881     case CMD_SCREEN_FILE:
882       switch_screen_mode(SCREEN_FILE_WINDOW, c);
883       break;
884     case CMD_SCREEN_SEARCH:
885       switch_screen_mode(SCREEN_SEARCH_WINDOW, c);
886       break;
887     case CMD_SCREEN_HELP:
888       switch_screen_mode(SCREEN_HELP_WINDOW, c);
889       break;
890 #ifdef ENABLE_KEYDEF_SCREEN 
891     case CMD_SCREEN_KEYDEF:
892       switch_screen_mode(SCREEN_KEYDEF_WINDOW, c);
893       break;
894 #endif
895 #ifdef ENABLE_CLOCK_SCREEN 
896     case CMD_SCREEN_CLOCK:
897       switch_screen_mode(SCREEN_CLOCK_WINDOW, c);
898       break;
899 #endif
900     case CMD_QUIT:
901       exit(EXIT_SUCCESS);
902     default:
903       break;
904     }