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 "options.h"
29 #include "colors.h"
30 #include "strfsong.h"
31 #include "wreadln.h"
33 #include <stdlib.h>
34 #include <unistd.h>
35 #include <stdarg.h>
36 #include <string.h>
37 #include <time.h>
38 #include <locale.h>
40 /** welcome message time [s] */
41 static const GTime SCREEN_WELCOME_TIME = 10;
43 /** status message time [s] */
44 static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
46 /* minumum window size */
47 static const int SCREEN_MIN_COLS = 14;
48 static const int SCREEN_MIN_ROWS = 5;
50 /* screens */
52 static gboolean welcome = TRUE;
53 struct screen screen;
54 static const struct screen_functions *mode_fn = &screen_playlist;
55 static int seek_id = -1;
56 static int seek_target_time = 0;
58 gboolean
59 screen_is_visible(const struct screen_functions *sf)
60 {
61 return sf == mode_fn;
62 }
64 void
65 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
66 {
67 assert(sf != NULL);
69 if (sf == mode_fn)
70 return;
72 /* close the old mode */
73 if (mode_fn->close != NULL)
74 mode_fn->close();
76 /* get functions for the new mode */
77 mode_fn = sf;
79 /* open the new mode */
80 if (mode_fn->open != NULL)
81 mode_fn->open(c);
83 screen_paint(c);
84 }
86 static int
87 find_configured_screen(const char *name)
88 {
89 unsigned i;
91 for (i = 0; options.screen_list[i] != NULL; ++i)
92 if (strcmp(options.screen_list[i], name) == 0)
93 return i;
95 return -1;
96 }
98 static void
99 screen_next_mode(mpdclient_t *c, int offset)
100 {
101 int max = g_strv_length(options.screen_list);
102 int current, next;
103 const struct screen_functions *sf;
105 /* find current screen */
106 current = find_configured_screen(screen_get_name(mode_fn));
107 next = current + offset;
108 if (next<0)
109 next = max-1;
110 else if (next>=max)
111 next = 0;
113 sf = screen_lookup_name(options.screen_list[next]);
114 if (sf != NULL)
115 screen_switch(sf, c);
116 }
118 static void
119 paint_top_window2(const char *header, mpdclient_t *c)
120 {
121 char flags[5];
122 WINDOW *w = screen.top_window.w;
123 char buf[32];
125 if (header[0]) {
126 colors_use(w, COLOR_TITLE_BOLD);
127 mvwaddstr(w, 0, 0, header);
128 } else {
129 colors_use(w, COLOR_TITLE_BOLD);
130 waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
131 colors_use(w, COLOR_TITLE);
132 waddstr(w, _(":Help "));
133 colors_use(w, COLOR_TITLE_BOLD);
134 waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
135 colors_use(w, COLOR_TITLE);
136 waddstr(w, _(":Playlist "));
137 colors_use(w, COLOR_TITLE_BOLD);
138 waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
139 colors_use(w, COLOR_TITLE);
140 waddstr(w, _(":Browse "));
141 #ifdef ENABLE_ARTIST_SCREEN
142 colors_use(w, COLOR_TITLE_BOLD);
143 waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
144 colors_use(w, COLOR_TITLE);
145 waddstr(w, _(":Artist "));
146 #endif
147 #ifdef ENABLE_SEARCH_SCREEN
148 colors_use(w, COLOR_TITLE_BOLD);
149 waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
150 colors_use(w, COLOR_TITLE);
151 waddstr(w, _(":Search "));
152 #endif
153 #ifdef ENABLE_LYRICS_SCREEN
154 colors_use(w, COLOR_TITLE_BOLD);
155 waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
156 colors_use(w, COLOR_TITLE);
157 waddstr(w, _(":Lyrics "));
158 #endif
159 }
160 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
161 g_snprintf(buf, 32, _("Volume n/a "));
162 } else {
163 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
164 }
165 colors_use(w, COLOR_TITLE);
166 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
168 flags[0] = 0;
169 if (c->status != NULL) {
170 if (c->status->repeat)
171 g_strlcat(flags, "r", sizeof(flags));
172 if (c->status->random)
173 g_strlcat(flags, "z", sizeof(flags));;
174 if (c->status->crossfade)
175 g_strlcat(flags, "x", sizeof(flags));
176 if (c->status->updatingDb)
177 g_strlcat(flags, "U", sizeof(flags));
178 }
180 colors_use(w, COLOR_LINE);
181 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
182 if (flags[0]) {
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 }
193 static void
194 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
195 {
196 static int prev_volume = -1;
197 static unsigned prev_header_len = -1;
198 WINDOW *w = screen.top_window.w;
200 if (prev_header_len != utf8_width(header)) {
201 prev_header_len = utf8_width(header);
202 full_repaint = 1;
203 }
205 if (full_repaint) {
206 wmove(w, 0, 0);
207 wclrtoeol(w);
208 }
210 if ((c->status != NULL && prev_volume != c->status->volume) ||
211 full_repaint)
212 paint_top_window2(header, c);
213 }
215 static void
216 paint_progress_window(mpdclient_t *c)
217 {
218 double p;
219 int width;
220 int elapsedTime;
222 if (c->status==NULL || IS_STOPPED(c->status->state)) {
223 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
224 screen.progress_window.cols);
225 wnoutrefresh(screen.progress_window.w);
226 return;
227 }
229 if (c->song && seek_id == c->song->id)
230 elapsedTime = seek_target_time;
231 else
232 elapsedTime = c->status->elapsedTime;
234 p = ((double) elapsedTime) / ((double) c->status->totalTime);
236 width = (int) (p * (double) screen.progress_window.cols);
237 mvwhline(screen.progress_window.w,
238 0, 0,
239 ACS_HLINE,
240 screen.progress_window.cols);
241 whline(screen.progress_window.w, '=', width-1);
242 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
243 wnoutrefresh(screen.progress_window.w);
244 }
246 static void
247 paint_status_window(mpdclient_t *c)
248 {
249 WINDOW *w = screen.status_window.w;
250 mpd_Status *status = c->status;
251 mpd_Song *song = c->song;
252 int elapsedTime = 0;
253 char bitrate[16];
254 const char *str = NULL;
255 int x = 0;
257 if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
258 return;
260 wmove(w, 0, 0);
261 wclrtoeol(w);
262 colors_use(w, COLOR_STATUS_BOLD);
264 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
265 case MPD_STATUS_STATE_PLAY:
266 str = _("Playing:");
267 break;
268 case MPD_STATUS_STATE_PAUSE:
269 str = _("[Paused]");
270 break;
271 case MPD_STATUS_STATE_STOP:
272 default:
273 break;
274 }
276 if (str) {
277 waddstr(w, str);
278 x += utf8_width(str) + 1;
279 }
281 /* create time string */
282 memset(screen.buf, 0, screen.buf_size);
283 if (status != NULL && (IS_PLAYING(status->state) ||
284 IS_PAUSED(status->state))) {
285 if (status->totalTime > 0) {
286 /*checks the conf to see whether to display elapsed or remaining time */
287 if(!strcmp(options.timedisplay_type,"elapsed"))
288 elapsedTime = c->status->elapsedTime;
289 else if(!strcmp(options.timedisplay_type,"remaining"))
290 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
292 if( c->song && seek_id == c->song->id )
293 elapsedTime = seek_target_time;
295 /* display bitrate if visible-bitrate is true */
296 if (options.visible_bitrate) {
297 g_snprintf(bitrate, 16,
298 " [%d kbps]", status->bitRate);
299 } else {
300 bitrate[0] = '\0';
301 }
303 /*write out the time, using hours if time over 60 minutes*/
304 if (c->status->totalTime > 3600) {
305 g_snprintf(screen.buf, screen.buf_size,
306 "%s [%i:%02i:%02i/%i:%02i:%02i]",
307 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
308 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
309 } else {
310 g_snprintf(screen.buf, screen.buf_size,
311 "%s [%i:%02i/%i:%02i]",
312 bitrate, elapsedTime/60, elapsedTime%60,
313 status->totalTime/60, status->totalTime%60 );
314 }
315 } else {
316 g_snprintf(screen.buf, screen.buf_size,
317 " [%d kbps]", status->bitRate );
318 }
319 } else {
320 time_t timep;
322 time(&timep);
323 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
324 }
326 /* display song */
327 if (status != NULL && (IS_PLAYING(status->state) ||
328 IS_PAUSED(status->state))) {
329 char songname[MAX_SONGNAME_LENGTH];
330 int width = COLS - x - utf8_width(screen.buf);
332 if (song)
333 strfsong(songname, MAX_SONGNAME_LENGTH,
334 options.status_format, song);
335 else
336 songname[0] = '\0';
338 colors_use(w, COLOR_STATUS);
339 /* scroll if the song name is to long */
340 if (options.scroll && utf8_width(songname) > (unsigned)width) {
341 static scroll_state_t st = { 0, 0 };
342 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
344 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
345 g_free(tmp);
346 }
347 //mvwaddnstr(w, 0, x, songname, width);
348 mvwaddstr(w, 0, x, songname);
349 }
351 /* display time string */
352 if (screen.buf[0]) {
353 x = screen.status_window.cols - strlen(screen.buf);
354 colors_use(w, COLOR_STATUS_TIME);
355 mvwaddstr(w, 0, x, screen.buf);
356 }
358 wnoutrefresh(w);
359 }
361 void
362 screen_exit(void)
363 {
364 if (mode_fn->close != NULL)
365 mode_fn->close();
367 screen_list_exit();
369 string_list_free(screen.find_history);
370 g_free(screen.buf);
371 g_free(screen.findbuf);
372 }
374 void
375 screen_resize(struct mpdclient *c)
376 {
377 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
378 screen_exit();
379 fprintf(stderr, _("Error: Screen to small!\n"));
380 exit(EXIT_FAILURE);
381 }
383 resizeterm(LINES, COLS);
385 screen.cols = COLS;
386 screen.rows = LINES;
388 /* top window */
389 screen.top_window.cols = screen.cols;
390 wresize(screen.top_window.w, 2, screen.cols);
392 /* main window */
393 screen.main_window.cols = screen.cols;
394 screen.main_window.rows = screen.rows-4;
395 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
396 wclear(screen.main_window.w);
398 /* progress window */
399 screen.progress_window.cols = screen.cols;
400 wresize(screen.progress_window.w, 1, screen.cols);
401 mvwin(screen.progress_window.w, screen.rows-2, 0);
403 /* status window */
404 screen.status_window.cols = screen.cols;
405 wresize(screen.status_window.w, 1, screen.cols);
406 mvwin(screen.status_window.w, screen.rows-1, 0);
408 screen.buf_size = screen.cols;
409 g_free(screen.buf);
410 screen.buf = g_malloc(screen.cols);
412 /* resize all screens */
413 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
415 /* ? - without this the cursor becomes visible with aterm & Eterm */
416 curs_set(1);
417 curs_set(0);
419 screen_paint(c);
420 }
422 void
423 screen_status_message(const char *msg)
424 {
425 WINDOW *w = screen.status_window.w;
427 wmove(w, 0, 0);
428 wclrtoeol(w);
429 colors_use(w, COLOR_STATUS_ALERT);
430 waddstr(w, msg);
431 wnoutrefresh(w);
432 screen.status_timestamp = time(NULL);
433 }
435 void
436 screen_status_printf(const char *format, ...)
437 {
438 char *msg;
439 va_list ap;
441 va_start(ap,format);
442 msg = g_strdup_vprintf(format,ap);
443 va_end(ap);
444 screen_status_message(msg);
445 g_free(msg);
446 }
448 void
449 screen_init(mpdclient_t *c)
450 {
451 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
452 fprintf(stderr, _("Error: Screen to small!\n"));
453 exit(EXIT_FAILURE);
454 }
456 screen.cols = COLS;
457 screen.rows = LINES;
459 screen.buf = g_malloc(screen.cols);
460 screen.buf_size = screen.cols;
461 screen.findbuf = NULL;
462 screen.start_timestamp = time(NULL);
463 screen.last_cmd = CMD_NONE;
465 /* create top window */
466 screen.top_window.rows = 2;
467 screen.top_window.cols = screen.cols;
468 screen.top_window.w = newwin(screen.top_window.rows,
469 screen.top_window.cols,
470 0, 0);
471 leaveok(screen.top_window.w, TRUE);
472 keypad(screen.top_window.w, TRUE);
474 /* create main window */
475 screen.main_window.rows = screen.rows-4;
476 screen.main_window.cols = screen.cols;
477 screen.main_window.w = newwin(screen.main_window.rows,
478 screen.main_window.cols,
479 2,
480 0);
482 // leaveok(screen.main_window.w, TRUE); temporary disabled
483 keypad(screen.main_window.w, TRUE);
485 /* create progress window */
486 screen.progress_window.rows = 1;
487 screen.progress_window.cols = screen.cols;
488 screen.progress_window.w = newwin(screen.progress_window.rows,
489 screen.progress_window.cols,
490 screen.rows-2,
491 0);
492 leaveok(screen.progress_window.w, TRUE);
494 /* create status window */
495 screen.status_window.rows = 1;
496 screen.status_window.cols = screen.cols;
497 screen.status_window.w = newwin(screen.status_window.rows,
498 screen.status_window.cols,
499 screen.rows-1,
500 0);
502 leaveok(screen.status_window.w, FALSE);
503 keypad(screen.status_window.w, TRUE);
505 #ifdef ENABLE_COLORS
506 if (options.enable_colors) {
507 /* set background attributes */
508 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
509 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
510 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
511 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
512 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
513 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
514 }
515 #endif
517 refresh();
519 /* initialize screens */
520 screen_list_init(screen.main_window.w,
521 screen.main_window.cols, screen.main_window.rows);
523 if (mode_fn->open != NULL)
524 mode_fn->open(c);
526 /* initialize wreadln */
527 wrln_max_history_length = 16;
528 }
530 void
531 screen_paint(mpdclient_t *c)
532 {
533 const char *title = NULL;
535 if (mode_fn->get_title != NULL)
536 title = mode_fn->get_title(screen.buf, screen.buf_size);
538 /* paint the title/header window */
539 if( title )
540 paint_top_window(title, c, 1);
541 else
542 paint_top_window("", c, 1);
544 /* paint the main window */
545 wclear(screen.main_window.w);
546 if (mode_fn->paint != NULL)
547 mode_fn->paint();
549 paint_progress_window(c);
550 paint_status_window(c);
551 wmove(screen.main_window.w, 0, 0);
552 wnoutrefresh(screen.main_window.w);
554 /* tell curses to update */
555 doupdate();
556 }
558 void
559 screen_update(mpdclient_t *c)
560 {
561 static int repeat = -1;
562 static int random_enabled = -1;
563 static int crossfade = -1;
564 static int dbupdate = -1;
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 /* calculate the selected row in the list window */
649 *row = event.y - screen.top_window.rows;
650 /* copy button state bits */
651 *bstate = event.bstate;
652 /* if button 2 was pressed switch screen */
653 if (event.bstate & BUTTON2_CLICKED) {
654 screen_cmd(c, CMD_SCREEN_NEXT);
655 return 1;
656 }
658 return 0;
659 }
660 #endif
662 static int
663 screen_client_cmd(mpdclient_t *c, command_t cmd)
664 {
665 if (c->connection == NULL || c->status == NULL)
666 return 0;
668 switch(cmd) {
669 /*
670 case CMD_PLAY:
671 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
672 break;
673 */
674 case CMD_PAUSE:
675 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
676 break;
677 case CMD_STOP:
678 mpdclient_cmd_stop(c);
679 break;
680 case CMD_CROP:
681 mpdclient_cmd_crop(c);
682 break;
683 case CMD_SEEK_FORWARD:
684 if (!IS_STOPPED(c->status->state)) {
685 if (c->song && seek_id != c->song->id) {
686 seek_id = c->song->id;
687 seek_target_time = c->status->elapsedTime;
688 }
689 seek_target_time+=options.seek_time;
690 if (seek_target_time < c->status->totalTime)
691 break;
692 seek_target_time = c->status->totalTime;
693 /* seek_target_time=0; */
694 }
695 break;
696 /* fall through... */
697 case CMD_TRACK_NEXT:
698 if (!IS_STOPPED(c->status->state))
699 mpdclient_cmd_next(c);
700 break;
701 case CMD_SEEK_BACKWARD:
702 if (!IS_STOPPED(c->status->state)) {
703 if (seek_id != c->song->id) {
704 seek_id = c->song->id;
705 seek_target_time = c->status->elapsedTime;
706 }
707 seek_target_time-=options.seek_time;
708 if (seek_target_time < 0)
709 seek_target_time=0;
710 }
711 break;
712 case CMD_TRACK_PREVIOUS:
713 if (!IS_STOPPED(c->status->state))
714 mpdclient_cmd_prev(c);
715 break;
716 case CMD_SHUFFLE:
717 if (mpdclient_cmd_shuffle(c) == 0)
718 screen_status_message(_("Shuffled playlist!"));
719 break;
720 case CMD_CLEAR:
721 if (mpdclient_cmd_clear(c) == 0)
722 screen_status_message(_("Cleared playlist!"));
723 break;
724 case CMD_REPEAT:
725 mpdclient_cmd_repeat(c, !c->status->repeat);
726 break;
727 case CMD_RANDOM:
728 mpdclient_cmd_random(c, !c->status->random);
729 break;
730 case CMD_CROSSFADE:
731 if (c->status->crossfade)
732 mpdclient_cmd_crossfade(c, 0);
733 else
734 mpdclient_cmd_crossfade(c, options.crossfade_time);
735 break;
736 case CMD_DB_UPDATE:
737 if (!c->status->updatingDb) {
738 if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
739 screen_status_printf(_("Database update started!"));
740 } else
741 screen_status_printf(_("Database update running..."));
742 break;
743 case CMD_VOLUME_UP:
744 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
745 mpdclient_cmd_volume(c, ++c->status->volume);
746 break;
747 case CMD_VOLUME_DOWN:
748 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
749 mpdclient_cmd_volume(c, --c->status->volume);
750 break;
752 default:
753 return 0;
754 }
756 return 1;
757 }
759 void
760 screen_cmd(mpdclient_t *c, command_t cmd)
761 {
762 screen.last_cmd = cmd;
763 welcome = FALSE;
765 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
766 return;
768 if (screen_client_cmd(c, cmd))
769 return;
771 switch(cmd) {
772 case CMD_TOGGLE_FIND_WRAP:
773 options.find_wrap = !options.find_wrap;
774 screen_status_printf(options.find_wrap ?
775 _("Find mode: Wrapped") :
776 _("Find mode: Normal"));
777 break;
778 case CMD_TOGGLE_AUTOCENTER:
779 options.auto_center = !options.auto_center;
780 screen_status_printf(options.auto_center ?
781 _("Auto center mode: On") :
782 _("Auto center mode: Off"));
783 break;
784 case CMD_SCREEN_UPDATE:
785 screen_paint(c);
786 break;
787 case CMD_SCREEN_PREVIOUS:
788 screen_next_mode(c, -1);
789 break;
790 case CMD_SCREEN_NEXT:
791 screen_next_mode(c, 1);
792 break;
793 case CMD_SCREEN_PLAY:
794 screen_switch(&screen_playlist, c);
795 break;
796 case CMD_SCREEN_FILE:
797 screen_switch(&screen_browse, c);
798 break;
799 case CMD_SCREEN_HELP:
800 screen_switch(&screen_help, c);
801 break;
802 #ifdef ENABLE_SEARCH_SCREEN
803 case CMD_SCREEN_SEARCH:
804 screen_switch(&screen_search, c);
805 break;
806 #endif
807 #ifdef ENABLE_ARTIST_SCREEN
808 case CMD_SCREEN_ARTIST:
809 screen_switch(&screen_artist, c);
810 break;
811 #endif
812 #ifdef ENABLE_KEYDEF_SCREEN
813 case CMD_SCREEN_KEYDEF:
814 screen_switch(&screen_keydef, c);
815 break;
816 #endif
817 #ifdef ENABLE_LYRICS_SCREEN
818 case CMD_SCREEN_LYRICS:
819 screen_switch(&screen_lyrics, c);
820 break;
821 #endif
822 default:
823 break;
824 }
825 }