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 "i18n.h"
26 #include "support.h"
27 #include "charset.h"
28 #include "mpdclient.h"
29 #include "utils.h"
30 #include "command.h"
31 #include "options.h"
32 #include "colors.h"
33 #include "strfsong.h"
34 #include "wreadln.h"
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <time.h>
41 #include <locale.h>
43 /** welcome message time [s] */
44 static const unsigned SCREEN_WELCOME_TIME = 10;
46 /** status message time [s] */
47 static const unsigned SCREEN_STATUS_MESSAGE_TIME = 3;
49 /* minumum window size */
50 static const int SCREEN_MIN_COLS = 14;
51 static const int SCREEN_MIN_ROWS = 5;
53 /* screens */
55 static gboolean welcome = TRUE;
56 static struct screen screen;
57 static const struct screen_functions *mode_fn = &screen_playlist;
58 static int seek_id = -1;
59 static int seek_target_time = 0;
61 gboolean
62 screen_is_visible(const struct screen_functions *sf)
63 {
64 return sf == mode_fn;
65 }
67 void
68 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
69 {
70 assert(sf != NULL);
72 if (sf == mode_fn)
73 return;
75 /* close the old mode */
76 if (mode_fn->close != NULL)
77 mode_fn->close();
79 /* get functions for the new mode */
80 mode_fn = sf;
81 screen.painted = 0;
83 /* open the new mode */
84 if (mode_fn->open != NULL)
85 mode_fn->open(&screen, c);
86 }
88 static int
89 find_configured_screen(const char *name)
90 {
91 unsigned i;
93 for (i = 0; options.screen_list[i] != NULL; ++i)
94 if (strcmp(options.screen_list[i], name) == 0)
95 return i;
97 return -1;
98 }
100 static void
101 screen_next_mode(mpdclient_t *c, int offset)
102 {
103 int max = g_strv_length(options.screen_list);
104 int current, next;
105 const struct screen_functions *sf;
107 /* find current screen */
108 current = find_configured_screen(screen_get_name(mode_fn));
109 next = current + offset;
110 if (next<0)
111 next = max-1;
112 else if (next>=max)
113 next = 0;
115 sf = screen_lookup_name(options.screen_list[next]);
116 if (sf != NULL)
117 screen_switch(sf, c);
118 }
120 static void
121 paint_top_window2(const char *header, mpdclient_t *c)
122 {
123 char flags[5];
124 WINDOW *w = screen.top_window.w;
125 char buf[32];
127 if (header[0]) {
128 colors_use(w, COLOR_TITLE_BOLD);
129 mvwaddstr(w, 0, 0, header);
130 } else {
131 colors_use(w, COLOR_TITLE_BOLD);
132 waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
133 colors_use(w, COLOR_TITLE);
134 waddstr(w, _(":Help "));
135 colors_use(w, COLOR_TITLE_BOLD);
136 waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
137 colors_use(w, COLOR_TITLE);
138 waddstr(w, _(":Playlist "));
139 colors_use(w, COLOR_TITLE_BOLD);
140 waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
141 colors_use(w, COLOR_TITLE);
142 waddstr(w, _(":Browse "));
143 #ifdef ENABLE_ARTIST_SCREEN
144 colors_use(w, COLOR_TITLE_BOLD);
145 waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
146 colors_use(w, COLOR_TITLE);
147 waddstr(w, _(":Artist "));
148 #endif
149 #ifdef ENABLE_SEARCH_SCREEN
150 colors_use(w, COLOR_TITLE_BOLD);
151 waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
152 colors_use(w, COLOR_TITLE);
153 waddstr(w, _(":Search "));
154 #endif
155 #ifdef ENABLE_LYRICS_SCREEN
156 colors_use(w, COLOR_TITLE_BOLD);
157 waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
158 colors_use(w, COLOR_TITLE);
159 waddstr(w, _(":Lyrics "));
160 #endif
161 }
162 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
163 g_snprintf(buf, 32, _("Volume n/a "));
164 } else {
165 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
166 }
167 colors_use(w, COLOR_TITLE);
168 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
170 flags[0] = 0;
171 if (c->status != NULL) {
172 if (c->status->repeat)
173 g_strlcat(flags, "r", sizeof(flags));
174 if (c->status->random)
175 g_strlcat(flags, "z", sizeof(flags));;
176 if (c->status->crossfade)
177 g_strlcat(flags, "x", sizeof(flags));
178 if (c->status->updatingDb)
179 g_strlcat(flags, "U", sizeof(flags));
180 }
182 colors_use(w, COLOR_LINE);
183 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
184 if (flags[0]) {
185 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
186 waddch(w, '[');
187 colors_use(w, COLOR_LINE_BOLD);
188 waddstr(w, flags);
189 colors_use(w, COLOR_LINE);
190 waddch(w, ']');
191 }
192 wnoutrefresh(w);
193 }
195 static void
196 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
197 {
198 static int prev_volume = -1;
199 static unsigned prev_header_len = -1;
200 WINDOW *w = screen.top_window.w;
202 if (prev_header_len != utf8_width(header)) {
203 prev_header_len = utf8_width(header);
204 full_repaint = 1;
205 }
207 if (full_repaint) {
208 wmove(w, 0, 0);
209 wclrtoeol(w);
210 }
212 if ((c->status != NULL && prev_volume != c->status->volume) ||
213 full_repaint)
214 paint_top_window2(header, c);
215 }
217 static void
218 paint_progress_window(mpdclient_t *c)
219 {
220 double p;
221 int width;
222 int elapsedTime;
224 if (c->status==NULL || IS_STOPPED(c->status->state)) {
225 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
226 screen.progress_window.cols);
227 wnoutrefresh(screen.progress_window.w);
228 return;
229 }
231 if (c->song && seek_id == c->song->id)
232 elapsedTime = seek_target_time;
233 else
234 elapsedTime = c->status->elapsedTime;
236 p = ((double) elapsedTime) / ((double) c->status->totalTime);
238 width = (int) (p * (double) screen.progress_window.cols);
239 mvwhline(screen.progress_window.w,
240 0, 0,
241 ACS_HLINE,
242 screen.progress_window.cols);
243 whline(screen.progress_window.w, '=', width-1);
244 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
245 wnoutrefresh(screen.progress_window.w);
246 }
248 static void
249 paint_status_window(mpdclient_t *c)
250 {
251 WINDOW *w = screen.status_window.w;
252 mpd_Status *status = c->status;
253 mpd_Song *song = c->song;
254 int elapsedTime = 0;
255 char bitrate[16];
256 const char *str = NULL;
257 int x = 0;
259 if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
260 return;
262 wmove(w, 0, 0);
263 wclrtoeol(w);
264 colors_use(w, COLOR_STATUS_BOLD);
266 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
267 case MPD_STATUS_STATE_PLAY:
268 str = _("Playing:");
269 break;
270 case MPD_STATUS_STATE_PAUSE:
271 str = _("[Paused]");
272 break;
273 case MPD_STATUS_STATE_STOP:
274 default:
275 break;
276 }
278 if (str) {
279 waddstr(w, str);
280 x += utf8_width(str) + 1;
281 }
283 /* create time string */
284 memset(screen.buf, 0, screen.buf_size);
285 if (status != NULL && (IS_PLAYING(status->state) ||
286 IS_PAUSED(status->state))) {
287 if (status->totalTime > 0) {
288 /*checks the conf to see whether to display elapsed or remaining time */
289 if(!strcmp(options.timedisplay_type,"elapsed"))
290 elapsedTime = c->status->elapsedTime;
291 else if(!strcmp(options.timedisplay_type,"remaining"))
292 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
294 if( c->song && seek_id == c->song->id )
295 elapsedTime = seek_target_time;
297 /* display bitrate if visible-bitrate is true */
298 if (options.visible_bitrate) {
299 g_snprintf(bitrate, 16,
300 " [%d kbps]", status->bitRate);
301 } else {
302 bitrate[0] = '\0';
303 }
305 /*write out the time, using hours if time over 60 minutes*/
306 if (c->status->totalTime > 3600) {
307 g_snprintf(screen.buf, screen.buf_size,
308 "%s [%i:%02i:%02i/%i:%02i:%02i]",
309 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
310 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
311 } else {
312 g_snprintf(screen.buf, screen.buf_size,
313 "%s [%i:%02i/%i:%02i]",
314 bitrate, elapsedTime/60, elapsedTime%60,
315 status->totalTime/60, status->totalTime%60 );
316 }
317 } else {
318 g_snprintf(screen.buf, screen.buf_size,
319 " [%d kbps]", status->bitRate );
320 }
321 } else {
322 time_t timep;
324 time(&timep);
325 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
326 }
328 /* display song */
329 if (status != NULL && (IS_PLAYING(status->state) ||
330 IS_PAUSED(status->state))) {
331 char songname[MAX_SONGNAME_LENGTH];
332 int width = COLS - x - utf8_width(screen.buf);
334 if (song)
335 strfsong(songname, MAX_SONGNAME_LENGTH,
336 options.status_format, song);
337 else
338 songname[0] = '\0';
340 colors_use(w, COLOR_STATUS);
341 /* scroll if the song name is to long */
342 if (options.scroll && utf8_width(songname) > (unsigned)width) {
343 static scroll_state_t st = { 0, 0 };
344 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
346 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
347 g_free(tmp);
348 }
349 //mvwaddnstr(w, 0, x, songname, width);
350 mvwaddstr(w, 0, x, songname);
351 }
353 /* display time string */
354 if (screen.buf[0]) {
355 x = screen.status_window.cols - strlen(screen.buf);
356 colors_use(w, COLOR_STATUS_TIME);
357 mvwaddstr(w, 0, x, screen.buf);
358 }
360 wnoutrefresh(w);
361 }
363 void
364 screen_exit(void)
365 {
366 if (mode_fn->close != NULL)
367 mode_fn->close();
369 screen_list_exit();
371 string_list_free(screen.find_history);
372 g_free(screen.buf);
373 g_free(screen.findbuf);
374 }
376 void
377 screen_resize(void)
378 {
379 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
380 screen_exit();
381 fprintf(stderr, _("Error: Screen to small!\n"));
382 exit(EXIT_FAILURE);
383 }
385 resizeterm(LINES, COLS);
387 screen.cols = COLS;
388 screen.rows = LINES;
390 /* top window */
391 screen.top_window.cols = screen.cols;
392 wresize(screen.top_window.w, 2, screen.cols);
394 /* main window */
395 screen.main_window.cols = screen.cols;
396 screen.main_window.rows = screen.rows-4;
397 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
398 wclear(screen.main_window.w);
400 /* progress window */
401 screen.progress_window.cols = screen.cols;
402 wresize(screen.progress_window.w, 1, screen.cols);
403 mvwin(screen.progress_window.w, screen.rows-2, 0);
405 /* status window */
406 screen.status_window.cols = screen.cols;
407 wresize(screen.status_window.w, 1, screen.cols);
408 mvwin(screen.status_window.w, screen.rows-1, 0);
410 screen.buf_size = screen.cols;
411 g_free(screen.buf);
412 screen.buf = g_malloc(screen.cols);
414 /* resize all screens */
415 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
417 /* ? - without this the cursor becomes visible with aterm & Eterm */
418 curs_set(1);
419 curs_set(0);
421 screen.painted = 0;
422 }
424 void
425 screen_status_message(const char *msg)
426 {
427 WINDOW *w = screen.status_window.w;
429 wmove(w, 0, 0);
430 wclrtoeol(w);
431 colors_use(w, COLOR_STATUS_ALERT);
432 waddstr(w, msg);
433 wnoutrefresh(w);
434 screen.status_timestamp = time(NULL);
435 }
437 void
438 screen_status_printf(const char *format, ...)
439 {
440 char *msg;
441 va_list ap;
443 va_start(ap,format);
444 msg = g_strdup_vprintf(format,ap);
445 va_end(ap);
446 screen_status_message(msg);
447 g_free(msg);
448 }
450 void
451 screen_init(mpdclient_t *c)
452 {
453 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
454 fprintf(stderr, _("Error: Screen to small!\n"));
455 exit(EXIT_FAILURE);
456 }
458 screen.cols = COLS;
459 screen.rows = LINES;
461 screen.buf = g_malloc(screen.cols);
462 screen.buf_size = screen.cols;
463 screen.findbuf = NULL;
464 screen.painted = 0;
465 screen.start_timestamp = time(NULL);
466 screen.last_cmd = CMD_NONE;
468 /* create top window */
469 screen.top_window.rows = 2;
470 screen.top_window.cols = screen.cols;
471 screen.top_window.w = newwin(screen.top_window.rows,
472 screen.top_window.cols,
473 0, 0);
474 leaveok(screen.top_window.w, TRUE);
475 keypad(screen.top_window.w, TRUE);
477 /* create main window */
478 screen.main_window.rows = screen.rows-4;
479 screen.main_window.cols = screen.cols;
480 screen.main_window.w = newwin(screen.main_window.rows,
481 screen.main_window.cols,
482 2,
483 0);
485 // leaveok(screen.main_window.w, TRUE); temporary disabled
486 keypad(screen.main_window.w, TRUE);
488 /* create progress window */
489 screen.progress_window.rows = 1;
490 screen.progress_window.cols = screen.cols;
491 screen.progress_window.w = newwin(screen.progress_window.rows,
492 screen.progress_window.cols,
493 screen.rows-2,
494 0);
495 leaveok(screen.progress_window.w, TRUE);
497 /* create status window */
498 screen.status_window.rows = 1;
499 screen.status_window.cols = screen.cols;
500 screen.status_window.w = newwin(screen.status_window.rows,
501 screen.status_window.cols,
502 screen.rows-1,
503 0);
505 leaveok(screen.status_window.w, FALSE);
506 keypad(screen.status_window.w, TRUE);
508 if (options.enable_colors) {
509 /* set background attributes */
510 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
511 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
512 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
513 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
514 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
515 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
516 }
518 refresh();
520 /* initialize screens */
521 screen_list_init(screen.main_window.w,
522 screen.main_window.cols, screen.main_window.rows);
524 if (mode_fn->open != NULL)
525 mode_fn->open(&screen, c);
527 /* initialize wreadln */
528 wrln_wgetch = my_wgetch;
529 wrln_max_history_length = 16;
530 }
532 void
533 screen_paint(mpdclient_t *c)
534 {
535 const char *title = NULL;
537 if (mode_fn->get_title != NULL)
538 title = mode_fn->get_title(screen.buf, screen.buf_size);
540 /* paint the title/header window */
541 if( title )
542 paint_top_window(title, c, 1);
543 else
544 paint_top_window("", c, 1);
546 /* paint the main window */
547 wclear(screen.main_window.w);
548 if (mode_fn->paint != NULL)
549 mode_fn->paint(c);
551 paint_progress_window(c);
552 paint_status_window(c);
553 screen.painted = 1;
554 wmove(screen.main_window.w, 0, 0);
555 wnoutrefresh(screen.main_window.w);
557 /* tell curses to update */
558 doupdate();
559 }
561 void
562 screen_update(mpdclient_t *c)
563 {
564 static int repeat = -1;
565 static int random_enabled = -1;
566 static int crossfade = -1;
567 static int dbupdate = -1;
569 if( !screen.painted )
570 screen_paint(c);
572 /* print a message if mpd status has changed */
573 if (c->status != NULL) {
574 if (repeat < 0) {
575 repeat = c->status->repeat;
576 random_enabled = c->status->random;
577 crossfade = c->status->crossfade;
578 dbupdate = c->status->updatingDb;
579 }
581 if (repeat != c->status->repeat)
582 screen_status_printf(c->status->repeat ?
583 _("Repeat is on") :
584 _("Repeat is off"));
586 if (random_enabled != c->status->random)
587 screen_status_printf(c->status->random ?
588 _("Random is on") :
589 _("Random is off"));
591 if (crossfade != c->status->crossfade)
592 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
594 if (dbupdate && dbupdate != c->status->updatingDb) {
595 screen_status_printf(_("Database updated!"));
596 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
597 }
599 repeat = c->status->repeat;
600 random_enabled = c->status->random;
601 crossfade = c->status->crossfade;
602 dbupdate = c->status->updatingDb;
603 }
605 /* update title/header window */
606 if (welcome && options.welcome_screen_list &&
607 screen.last_cmd==CMD_NONE &&
608 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
609 paint_top_window("", c, 0);
610 else if (mode_fn->get_title != NULL) {
611 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
612 welcome = FALSE;
613 } else
614 paint_top_window("", c, 0);
616 /* update the main window */
617 if (mode_fn->update != NULL)
618 mode_fn->update(c);
620 /* update progress window */
621 paint_progress_window(c);
623 /* update status window */
624 paint_status_window(c);
626 /* move the cursor to the origin */
627 wmove(screen.main_window.w, 0, 0);
628 wnoutrefresh(screen.main_window.w);
630 /* tell curses to update */
631 doupdate();
632 }
634 void
635 screen_idle(mpdclient_t *c)
636 {
637 if (c->song && seek_id == c->song->id &&
638 (screen.last_cmd == CMD_SEEK_FORWARD ||
639 screen.last_cmd == CMD_SEEK_BACKWARD))
640 mpdclient_cmd_seek(c, seek_id, seek_target_time);
642 screen.last_cmd = CMD_NONE;
643 seek_id = -1;
644 }
646 #ifdef HAVE_GETMOUSE
647 int
648 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
649 {
650 MEVENT event;
652 /* retreive the mouse event from ncurses */
653 getmouse(&event);
654 /* calculate the selected row in the list window */
655 *row = event.y - screen.top_window.rows;
656 /* copy button state bits */
657 *bstate = event.bstate;
658 /* if button 2 was pressed switch screen */
659 if (event.bstate & BUTTON2_CLICKED) {
660 screen_cmd(c, CMD_SCREEN_NEXT);
661 return 1;
662 }
664 return 0;
665 }
666 #endif
668 static int
669 screen_client_cmd(mpdclient_t *c, command_t cmd)
670 {
671 if (c->connection == NULL || c->status == NULL)
672 return 0;
674 switch(cmd) {
675 /*
676 case CMD_PLAY:
677 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
678 break;
679 */
680 case CMD_PAUSE:
681 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
682 break;
683 case CMD_STOP:
684 mpdclient_cmd_stop(c);
685 break;
686 case CMD_CROP:
687 mpdclient_cmd_crop(c);
688 break;
689 case CMD_SEEK_FORWARD:
690 if (!IS_STOPPED(c->status->state)) {
691 if (c->song && seek_id != c->song->id) {
692 seek_id = c->song->id;
693 seek_target_time = c->status->elapsedTime;
694 }
695 seek_target_time+=options.seek_time;
696 if (seek_target_time < c->status->totalTime)
697 break;
698 seek_target_time = c->status->totalTime;
699 /* seek_target_time=0; */
700 }
701 break;
702 /* fall through... */
703 case CMD_TRACK_NEXT:
704 if (!IS_STOPPED(c->status->state))
705 mpdclient_cmd_next(c);
706 break;
707 case CMD_SEEK_BACKWARD:
708 if (!IS_STOPPED(c->status->state)) {
709 if (seek_id != c->song->id) {
710 seek_id = c->song->id;
711 seek_target_time = c->status->elapsedTime;
712 }
713 seek_target_time-=options.seek_time;
714 if (seek_target_time < 0)
715 seek_target_time=0;
716 }
717 break;
718 case CMD_TRACK_PREVIOUS:
719 if (!IS_STOPPED(c->status->state))
720 mpdclient_cmd_prev(c);
721 break;
722 case CMD_SHUFFLE:
723 if (mpdclient_cmd_shuffle(c) == 0)
724 screen_status_message(_("Shuffled playlist!"));
725 break;
726 case CMD_CLEAR:
727 if (mpdclient_cmd_clear(c) == 0)
728 screen_status_message(_("Cleared playlist!"));
729 break;
730 case CMD_REPEAT:
731 mpdclient_cmd_repeat(c, !c->status->repeat);
732 break;
733 case CMD_RANDOM:
734 mpdclient_cmd_random(c, !c->status->random);
735 break;
736 case CMD_CROSSFADE:
737 if (c->status->crossfade)
738 mpdclient_cmd_crossfade(c, 0);
739 else
740 mpdclient_cmd_crossfade(c, options.crossfade_time);
741 break;
742 case CMD_DB_UPDATE:
743 if (!c->status->updatingDb) {
744 if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
745 screen_status_printf(_("Database update started!"));
746 } else
747 screen_status_printf(_("Database update running..."));
748 break;
749 case CMD_VOLUME_UP:
750 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
751 mpdclient_cmd_volume(c, ++c->status->volume);
752 break;
753 case CMD_VOLUME_DOWN:
754 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
755 mpdclient_cmd_volume(c, --c->status->volume);
756 break;
758 default:
759 return 0;
760 }
762 return 1;
763 }
765 void
766 screen_cmd(mpdclient_t *c, command_t cmd)
767 {
768 screen.last_cmd = cmd;
769 welcome = FALSE;
771 if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
772 return;
774 if (screen_client_cmd(c, cmd))
775 return;
777 switch(cmd) {
778 case CMD_TOGGLE_FIND_WRAP:
779 options.find_wrap = !options.find_wrap;
780 screen_status_printf(options.find_wrap ?
781 _("Find mode: Wrapped") :
782 _("Find mode: Normal"));
783 break;
784 case CMD_TOGGLE_AUTOCENTER:
785 options.auto_center = !options.auto_center;
786 screen_status_printf(options.auto_center ?
787 _("Auto center mode: On") :
788 _("Auto center mode: Off"));
789 break;
790 case CMD_SCREEN_UPDATE:
791 screen.painted = 0;
792 break;
793 case CMD_SCREEN_PREVIOUS:
794 screen_next_mode(c, -1);
795 break;
796 case CMD_SCREEN_NEXT:
797 screen_next_mode(c, 1);
798 break;
799 case CMD_SCREEN_PLAY:
800 screen_switch(&screen_playlist, c);
801 break;
802 case CMD_SCREEN_FILE:
803 screen_switch(&screen_browse, c);
804 break;
805 case CMD_SCREEN_HELP:
806 screen_switch(&screen_help, c);
807 break;
808 #ifdef ENABLE_SEARCH_SCREEN
809 case CMD_SCREEN_SEARCH:
810 screen_switch(&screen_search, c);
811 break;
812 #endif
813 #ifdef ENABLE_ARTIST_SCREEN
814 case CMD_SCREEN_ARTIST:
815 screen_switch(&screen_artist, c);
816 break;
817 #endif
818 #ifdef ENABLE_KEYDEF_SCREEN
819 case CMD_SCREEN_KEYDEF:
820 screen_switch(&screen_keydef, c);
821 break;
822 #endif
823 #ifdef ENABLE_LYRICS_SCREEN
824 case CMD_SCREEN_LYRICS:
825 screen_switch(&screen_lyrics, c);
826 break;
827 #endif
828 default:
829 break;
830 }
831 }