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 #ifdef ENABLE_HELP_SCREEN
149 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
150 #endif
151 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
152 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
153 #ifdef ENABLE_ARTIST_SCREEN
154 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
155 #endif
156 #ifdef ENABLE_SEARCH_SCREEN
157 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
158 #endif
159 #ifdef ENABLE_LYRICS_SCREEN
160 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
161 #endif
162 #endif
163 }
165 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
166 g_snprintf(buf, 32, _("Volume n/a "));
167 } else {
168 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
169 }
170 colors_use(w, COLOR_TITLE);
171 mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
173 flags[0] = 0;
174 if (c->status != NULL) {
175 if (c->status->repeat)
176 g_strlcat(flags, "r", sizeof(flags));
177 if (c->status->random)
178 g_strlcat(flags, "z", sizeof(flags));;
179 if (c->status->crossfade)
180 g_strlcat(flags, "x", sizeof(flags));
181 if (c->status->updatingDb)
182 g_strlcat(flags, "U", sizeof(flags));
183 }
185 colors_use(w, COLOR_LINE);
186 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
187 if (flags[0]) {
188 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
189 waddch(w, '[');
190 colors_use(w, COLOR_LINE_BOLD);
191 waddstr(w, flags);
192 colors_use(w, COLOR_LINE);
193 waddch(w, ']');
194 }
195 wnoutrefresh(w);
196 }
198 static void
199 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
200 {
201 static int prev_volume = -1;
202 static unsigned prev_header_len = -1;
203 WINDOW *w = screen.top_window.w;
205 if (prev_header_len != utf8_width(header)) {
206 prev_header_len = utf8_width(header);
207 full_repaint = 1;
208 }
210 if (full_repaint) {
211 wmove(w, 0, 0);
212 wclrtoeol(w);
213 }
215 if ((c->status != NULL && prev_volume != c->status->volume) ||
216 full_repaint)
217 paint_top_window2(header, c);
218 }
220 static void
221 paint_progress_window(mpdclient_t *c)
222 {
223 double p;
224 int width;
225 int elapsedTime;
227 if (c->status==NULL || IS_STOPPED(c->status->state)) {
228 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
229 screen.progress_window.cols);
230 wnoutrefresh(screen.progress_window.w);
231 return;
232 }
234 if (c->song && seek_id == c->song->id)
235 elapsedTime = seek_target_time;
236 else
237 elapsedTime = c->status->elapsedTime;
239 p = ((double) elapsedTime) / ((double) c->status->totalTime);
241 width = (int) (p * (double) screen.progress_window.cols);
242 mvwhline(screen.progress_window.w,
243 0, 0,
244 ACS_HLINE,
245 screen.progress_window.cols);
246 whline(screen.progress_window.w, '=', width-1);
247 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
248 wnoutrefresh(screen.progress_window.w);
249 }
251 static void
252 paint_status_window(mpdclient_t *c)
253 {
254 WINDOW *w = screen.status_window.w;
255 mpd_Status *status = c->status;
256 mpd_Song *song = c->song;
257 int elapsedTime = 0;
258 #ifdef NCMPC_MINI
259 static char bitrate[1];
260 #else
261 char bitrate[16];
262 #endif
263 const char *str = NULL;
264 int x = 0;
266 if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
267 return;
269 wmove(w, 0, 0);
270 wclrtoeol(w);
271 colors_use(w, COLOR_STATUS_BOLD);
273 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
274 case MPD_STATUS_STATE_PLAY:
275 str = _("Playing:");
276 break;
277 case MPD_STATUS_STATE_PAUSE:
278 str = _("[Paused]");
279 break;
280 case MPD_STATUS_STATE_STOP:
281 default:
282 break;
283 }
285 if (str) {
286 waddstr(w, str);
287 x += utf8_width(str) + 1;
288 }
290 /* create time string */
291 memset(screen.buf, 0, screen.buf_size);
292 if (status != NULL && (IS_PLAYING(status->state) ||
293 IS_PAUSED(status->state))) {
294 if (status->totalTime > 0) {
295 /*checks the conf to see whether to display elapsed or remaining time */
296 if(!strcmp(options.timedisplay_type,"elapsed"))
297 elapsedTime = c->status->elapsedTime;
298 else if(!strcmp(options.timedisplay_type,"remaining"))
299 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
301 if( c->song && seek_id == c->song->id )
302 elapsedTime = seek_target_time;
304 /* display bitrate if visible-bitrate is true */
305 #ifndef NCMPC_MINI
306 if (options.visible_bitrate) {
307 g_snprintf(bitrate, 16,
308 " [%d kbps]", status->bitRate);
309 } else {
310 bitrate[0] = '\0';
311 }
312 #endif
314 /*write out the time, using hours if time over 60 minutes*/
315 if (c->status->totalTime > 3600) {
316 g_snprintf(screen.buf, screen.buf_size,
317 "%s [%i:%02i:%02i/%i:%02i:%02i]",
318 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
319 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
320 } else {
321 g_snprintf(screen.buf, screen.buf_size,
322 "%s [%i:%02i/%i:%02i]",
323 bitrate, elapsedTime/60, elapsedTime%60,
324 status->totalTime/60, status->totalTime%60 );
325 }
326 #ifndef NCMPC_MINI
327 } else {
328 g_snprintf(screen.buf, screen.buf_size,
329 " [%d kbps]", status->bitRate );
330 #endif
331 }
332 #ifndef NCMPC_MINI
333 } else {
334 time_t timep;
336 time(&timep);
337 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
338 #endif
339 }
341 /* display song */
342 if (status != NULL && (IS_PLAYING(status->state) ||
343 IS_PAUSED(status->state))) {
344 char songname[MAX_SONGNAME_LENGTH];
345 #ifndef NCMPC_MINI
346 int width = COLS - x - utf8_width(screen.buf);
347 #endif
349 if (song)
350 strfsong(songname, MAX_SONGNAME_LENGTH,
351 options.status_format, song);
352 else
353 songname[0] = '\0';
355 colors_use(w, COLOR_STATUS);
356 /* scroll if the song name is to long */
357 #ifndef NCMPC_MINI
358 if (options.scroll && utf8_width(songname) > (unsigned)width) {
359 static scroll_state_t st = { 0, 0 };
360 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
362 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
363 g_free(tmp);
364 }
365 #endif
366 //mvwaddnstr(w, 0, x, songname, width);
367 mvwaddstr(w, 0, x, songname);
368 }
370 /* display time string */
371 if (screen.buf[0]) {
372 x = screen.status_window.cols - strlen(screen.buf);
373 colors_use(w, COLOR_STATUS_TIME);
374 mvwaddstr(w, 0, x, screen.buf);
375 }
377 wnoutrefresh(w);
378 }
380 void
381 screen_exit(void)
382 {
383 if (mode_fn->close != NULL)
384 mode_fn->close();
386 screen_list_exit();
388 string_list_free(screen.find_history);
389 g_free(screen.buf);
390 g_free(screen.findbuf);
391 }
393 void
394 screen_resize(struct mpdclient *c)
395 {
396 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
397 screen_exit();
398 fprintf(stderr, "%s", _("Error: Screen too small"));
399 exit(EXIT_FAILURE);
400 }
402 resizeterm(LINES, COLS);
404 screen.cols = COLS;
405 screen.rows = LINES;
407 /* top window */
408 screen.top_window.cols = screen.cols;
409 wresize(screen.top_window.w, 2, screen.cols);
411 /* main window */
412 screen.main_window.cols = screen.cols;
413 screen.main_window.rows = screen.rows-4;
414 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
415 wclear(screen.main_window.w);
417 /* progress window */
418 screen.progress_window.cols = screen.cols;
419 wresize(screen.progress_window.w, 1, screen.cols);
420 mvwin(screen.progress_window.w, screen.rows-2, 0);
422 /* status window */
423 screen.status_window.cols = screen.cols;
424 wresize(screen.status_window.w, 1, screen.cols);
425 mvwin(screen.status_window.w, screen.rows-1, 0);
427 screen.buf_size = screen.cols;
428 g_free(screen.buf);
429 screen.buf = g_malloc(screen.cols);
431 /* resize all screens */
432 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
434 /* ? - without this the cursor becomes visible with aterm & Eterm */
435 curs_set(1);
436 curs_set(0);
438 screen_paint(c);
439 }
441 void
442 screen_status_message(const char *msg)
443 {
444 WINDOW *w = screen.status_window.w;
446 wmove(w, 0, 0);
447 wclrtoeol(w);
448 colors_use(w, COLOR_STATUS_ALERT);
449 waddstr(w, msg);
450 wnoutrefresh(w);
451 screen.status_timestamp = time(NULL);
452 }
454 void
455 screen_status_printf(const char *format, ...)
456 {
457 char *msg;
458 va_list ap;
460 va_start(ap,format);
461 msg = g_strdup_vprintf(format,ap);
462 va_end(ap);
463 screen_status_message(msg);
464 g_free(msg);
465 }
467 void
468 screen_init(mpdclient_t *c)
469 {
470 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
471 fprintf(stderr, "%s\n", _("Error: Screen too small"));
472 exit(EXIT_FAILURE);
473 }
475 screen.cols = COLS;
476 screen.rows = LINES;
478 screen.buf = g_malloc(screen.cols);
479 screen.buf_size = screen.cols;
480 screen.findbuf = NULL;
481 screen.start_timestamp = time(NULL);
482 screen.last_cmd = CMD_NONE;
484 /* create top window */
485 screen.top_window.rows = 2;
486 screen.top_window.cols = screen.cols;
487 screen.top_window.w = newwin(screen.top_window.rows,
488 screen.top_window.cols,
489 0, 0);
490 leaveok(screen.top_window.w, TRUE);
491 keypad(screen.top_window.w, TRUE);
493 /* create main window */
494 screen.main_window.rows = screen.rows-4;
495 screen.main_window.cols = screen.cols;
496 screen.main_window.w = newwin(screen.main_window.rows,
497 screen.main_window.cols,
498 2,
499 0);
501 // leaveok(screen.main_window.w, TRUE); temporary disabled
502 keypad(screen.main_window.w, TRUE);
504 /* create progress window */
505 screen.progress_window.rows = 1;
506 screen.progress_window.cols = screen.cols;
507 screen.progress_window.w = newwin(screen.progress_window.rows,
508 screen.progress_window.cols,
509 screen.rows-2,
510 0);
511 leaveok(screen.progress_window.w, TRUE);
513 /* create status window */
514 screen.status_window.rows = 1;
515 screen.status_window.cols = screen.cols;
516 screen.status_window.w = newwin(screen.status_window.rows,
517 screen.status_window.cols,
518 screen.rows-1,
519 0);
521 leaveok(screen.status_window.w, FALSE);
522 keypad(screen.status_window.w, TRUE);
524 #ifdef ENABLE_COLORS
525 if (options.enable_colors) {
526 /* set background attributes */
527 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
528 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
529 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
530 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
531 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
532 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
533 }
534 #endif
536 refresh();
538 /* initialize screens */
539 screen_list_init(screen.main_window.w,
540 screen.main_window.cols, screen.main_window.rows);
542 if (mode_fn->open != NULL)
543 mode_fn->open(c);
544 }
546 void
547 screen_paint(mpdclient_t *c)
548 {
549 const char *title = NULL;
551 if (mode_fn->get_title != NULL)
552 title = mode_fn->get_title(screen.buf, screen.buf_size);
554 /* paint the title/header window */
555 if( title )
556 paint_top_window(title, c, 1);
557 else
558 paint_top_window("", c, 1);
560 /* paint the main window */
561 wclear(screen.main_window.w);
562 if (mode_fn->paint != NULL)
563 mode_fn->paint();
565 paint_progress_window(c);
566 paint_status_window(c);
567 wmove(screen.main_window.w, 0, 0);
568 wnoutrefresh(screen.main_window.w);
570 /* tell curses to update */
571 doupdate();
572 }
574 void
575 screen_update(mpdclient_t *c)
576 {
577 #ifndef NCMPC_MINI
578 static int repeat = -1;
579 static int random_enabled = -1;
580 static int crossfade = -1;
581 static int dbupdate = -1;
583 /* print a message if mpd status has changed */
584 if (c->status != NULL) {
585 if (repeat < 0) {
586 repeat = c->status->repeat;
587 random_enabled = c->status->random;
588 crossfade = c->status->crossfade;
589 dbupdate = c->status->updatingDb;
590 }
592 if (repeat != c->status->repeat)
593 screen_status_printf(c->status->repeat ?
594 _("Repeat is on") :
595 _("Repeat is off"));
597 if (random_enabled != c->status->random)
598 screen_status_printf(c->status->random ?
599 _("Random is on") :
600 _("Random is off"));
602 if (crossfade != c->status->crossfade)
603 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
605 if (dbupdate && dbupdate != c->status->updatingDb) {
606 screen_status_printf(_("Database updated"));
607 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
608 }
610 repeat = c->status->repeat;
611 random_enabled = c->status->random;
612 crossfade = c->status->crossfade;
613 dbupdate = c->status->updatingDb;
614 }
616 /* update title/header window */
617 if (welcome && options.welcome_screen_list &&
618 screen.last_cmd==CMD_NONE &&
619 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
620 paint_top_window("", c, 0);
621 else
622 #endif
623 if (mode_fn->get_title != NULL) {
624 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
625 #ifndef NCMPC_MINI
626 welcome = FALSE;
627 #endif
628 } else
629 paint_top_window("", c, 0);
631 /* update the main window */
632 if (mode_fn->update != NULL)
633 mode_fn->update(c);
635 /* update progress window */
636 paint_progress_window(c);
638 /* update status window */
639 paint_status_window(c);
641 /* move the cursor to the origin */
642 wmove(screen.main_window.w, 0, 0);
643 wnoutrefresh(screen.main_window.w);
645 /* tell curses to update */
646 doupdate();
647 }
649 void
650 screen_idle(mpdclient_t *c)
651 {
652 if (c->song && seek_id == c->song->id &&
653 (screen.last_cmd == CMD_SEEK_FORWARD ||
654 screen.last_cmd == CMD_SEEK_BACKWARD))
655 mpdclient_cmd_seek(c, seek_id, seek_target_time);
657 screen.last_cmd = CMD_NONE;
658 seek_id = -1;
659 }
661 #ifdef HAVE_GETMOUSE
662 int
663 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
664 {
665 MEVENT event;
667 /* retreive the mouse event from ncurses */
668 getmouse(&event);
669 /* calculate the selected row in the list window */
670 *row = event.y - screen.top_window.rows;
671 /* copy button state bits */
672 *bstate = event.bstate;
673 /* if button 2 was pressed switch screen */
674 if (event.bstate & BUTTON2_CLICKED) {
675 screen_cmd(c, CMD_SCREEN_NEXT);
676 return 1;
677 }
679 return 0;
680 }
681 #endif
683 static int
684 screen_client_cmd(mpdclient_t *c, command_t cmd)
685 {
686 if (c->connection == NULL || c->status == NULL)
687 return 0;
689 switch(cmd) {
690 /*
691 case CMD_PLAY:
692 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
693 break;
694 */
695 case CMD_PAUSE:
696 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
697 break;
698 case CMD_STOP:
699 mpdclient_cmd_stop(c);
700 break;
701 case CMD_CROP:
702 mpdclient_cmd_crop(c);
703 break;
704 case CMD_SEEK_FORWARD:
705 if (!IS_STOPPED(c->status->state)) {
706 if (c->song && seek_id != c->song->id) {
707 seek_id = c->song->id;
708 seek_target_time = c->status->elapsedTime;
709 }
710 seek_target_time+=options.seek_time;
711 if (seek_target_time < c->status->totalTime)
712 break;
713 seek_target_time = c->status->totalTime;
714 /* seek_target_time=0; */
715 }
716 break;
717 /* fall through... */
718 case CMD_TRACK_NEXT:
719 if (!IS_STOPPED(c->status->state))
720 mpdclient_cmd_next(c);
721 break;
722 case CMD_SEEK_BACKWARD:
723 if (!IS_STOPPED(c->status->state)) {
724 if (seek_id != c->song->id) {
725 seek_id = c->song->id;
726 seek_target_time = c->status->elapsedTime;
727 }
728 seek_target_time-=options.seek_time;
729 if (seek_target_time < 0)
730 seek_target_time=0;
731 }
732 break;
733 case CMD_TRACK_PREVIOUS:
734 if (!IS_STOPPED(c->status->state))
735 mpdclient_cmd_prev(c);
736 break;
737 case CMD_SHUFFLE:
738 if (mpdclient_cmd_shuffle(c) == 0)
739 screen_status_message(_("Shuffled playlist"));
740 break;
741 case CMD_CLEAR:
742 if (mpdclient_cmd_clear(c) == 0)
743 screen_status_message(_("Cleared playlist"));
744 break;
745 case CMD_REPEAT:
746 mpdclient_cmd_repeat(c, !c->status->repeat);
747 break;
748 case CMD_RANDOM:
749 mpdclient_cmd_random(c, !c->status->random);
750 break;
751 case CMD_CROSSFADE:
752 if (c->status->crossfade)
753 mpdclient_cmd_crossfade(c, 0);
754 else
755 mpdclient_cmd_crossfade(c, options.crossfade_time);
756 break;
757 case CMD_DB_UPDATE:
758 if (!c->status->updatingDb) {
759 if( mpdclient_cmd_db_update(c,NULL)==0 )
760 screen_status_printf(_("Database update started"));
761 } else
762 screen_status_printf(_("Database update running..."));
763 break;
764 case CMD_VOLUME_UP:
765 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
766 mpdclient_cmd_volume(c, ++c->status->volume);
767 break;
768 case CMD_VOLUME_DOWN:
769 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
770 mpdclient_cmd_volume(c, --c->status->volume);
771 break;
773 default:
774 return 0;
775 }
777 return 1;
778 }
780 void
781 screen_cmd(mpdclient_t *c, command_t cmd)
782 {
783 screen.last_cmd = cmd;
784 #ifndef NCMPC_MINI
785 welcome = FALSE;
786 #endif
788 if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
789 return;
791 if (screen_client_cmd(c, cmd))
792 return;
794 switch(cmd) {
795 case CMD_TOGGLE_FIND_WRAP:
796 options.find_wrap = !options.find_wrap;
797 screen_status_printf(options.find_wrap ?
798 _("Find mode: Wrapped") :
799 _("Find mode: Normal"));
800 break;
801 case CMD_TOGGLE_AUTOCENTER:
802 options.auto_center = !options.auto_center;
803 screen_status_printf(options.auto_center ?
804 _("Auto center mode: On") :
805 _("Auto center mode: Off"));
806 break;
807 case CMD_SCREEN_UPDATE:
808 screen_paint(c);
809 break;
810 case CMD_SCREEN_PREVIOUS:
811 screen_next_mode(c, -1);
812 break;
813 case CMD_SCREEN_NEXT:
814 screen_next_mode(c, 1);
815 break;
816 case CMD_SCREEN_PLAY:
817 screen_switch(&screen_playlist, c);
818 break;
819 case CMD_SCREEN_FILE:
820 screen_switch(&screen_browse, c);
821 break;
822 #ifdef ENABLE_HELP_SCREEN
823 case CMD_SCREEN_HELP:
824 screen_switch(&screen_help, c);
825 break;
826 #endif
827 #ifdef ENABLE_SEARCH_SCREEN
828 case CMD_SCREEN_SEARCH:
829 screen_switch(&screen_search, c);
830 break;
831 #endif
832 #ifdef ENABLE_ARTIST_SCREEN
833 case CMD_SCREEN_ARTIST:
834 screen_switch(&screen_artist, c);
835 break;
836 #endif
837 #ifdef ENABLE_KEYDEF_SCREEN
838 case CMD_SCREEN_KEYDEF:
839 screen_switch(&screen_keydef, c);
840 break;
841 #endif
842 #ifdef ENABLE_LYRICS_SCREEN
843 case CMD_SCREEN_LYRICS:
844 screen_switch(&screen_lyrics, c);
845 break;
846 #endif
847 default:
848 break;
849 }
850 }