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