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