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