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 static 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;
79 screen.painted = 0;
81 /* open the new mode */
82 if (mode_fn->open != NULL)
83 mode_fn->open(&screen, 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(void)
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.painted = 0;
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.painted = 0;
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 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 }
516 refresh();
518 /* initialize screens */
519 screen_list_init(screen.main_window.w,
520 screen.main_window.cols, screen.main_window.rows);
522 if (mode_fn->open != NULL)
523 mode_fn->open(&screen, c);
525 /* initialize wreadln */
526 wrln_wgetch = my_wgetch;
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(c);
549 paint_progress_window(c);
550 paint_status_window(c);
551 screen.painted = 1;
552 wmove(screen.main_window.w, 0, 0);
553 wnoutrefresh(screen.main_window.w);
555 /* tell curses to update */
556 doupdate();
557 }
559 void
560 screen_update(mpdclient_t *c)
561 {
562 static int repeat = -1;
563 static int random_enabled = -1;
564 static int crossfade = -1;
565 static int dbupdate = -1;
567 if( !screen.painted )
568 screen_paint(c);
570 /* print a message if mpd status has changed */
571 if (c->status != NULL) {
572 if (repeat < 0) {
573 repeat = c->status->repeat;
574 random_enabled = c->status->random;
575 crossfade = c->status->crossfade;
576 dbupdate = c->status->updatingDb;
577 }
579 if (repeat != c->status->repeat)
580 screen_status_printf(c->status->repeat ?
581 _("Repeat is on") :
582 _("Repeat is off"));
584 if (random_enabled != c->status->random)
585 screen_status_printf(c->status->random ?
586 _("Random is on") :
587 _("Random is off"));
589 if (crossfade != c->status->crossfade)
590 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
592 if (dbupdate && dbupdate != c->status->updatingDb) {
593 screen_status_printf(_("Database updated!"));
594 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
595 }
597 repeat = c->status->repeat;
598 random_enabled = c->status->random;
599 crossfade = c->status->crossfade;
600 dbupdate = c->status->updatingDb;
601 }
603 /* update title/header window */
604 if (welcome && options.welcome_screen_list &&
605 screen.last_cmd==CMD_NONE &&
606 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
607 paint_top_window("", c, 0);
608 else if (mode_fn->get_title != NULL) {
609 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
610 welcome = FALSE;
611 } else
612 paint_top_window("", c, 0);
614 /* update the main window */
615 if (mode_fn->update != NULL)
616 mode_fn->update(c);
618 /* update progress window */
619 paint_progress_window(c);
621 /* update status window */
622 paint_status_window(c);
624 /* move the cursor to the origin */
625 wmove(screen.main_window.w, 0, 0);
626 wnoutrefresh(screen.main_window.w);
628 /* tell curses to update */
629 doupdate();
630 }
632 void
633 screen_idle(mpdclient_t *c)
634 {
635 if (c->song && seek_id == c->song->id &&
636 (screen.last_cmd == CMD_SEEK_FORWARD ||
637 screen.last_cmd == CMD_SEEK_BACKWARD))
638 mpdclient_cmd_seek(c, seek_id, seek_target_time);
640 screen.last_cmd = CMD_NONE;
641 seek_id = -1;
642 }
644 #ifdef HAVE_GETMOUSE
645 int
646 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
647 {
648 MEVENT event;
650 /* retreive the mouse event from ncurses */
651 getmouse(&event);
652 /* calculate the selected row in the list window */
653 *row = event.y - screen.top_window.rows;
654 /* copy button state bits */
655 *bstate = event.bstate;
656 /* if button 2 was pressed switch screen */
657 if (event.bstate & BUTTON2_CLICKED) {
658 screen_cmd(c, CMD_SCREEN_NEXT);
659 return 1;
660 }
662 return 0;
663 }
664 #endif
666 static int
667 screen_client_cmd(mpdclient_t *c, command_t cmd)
668 {
669 if (c->connection == NULL || c->status == NULL)
670 return 0;
672 switch(cmd) {
673 /*
674 case CMD_PLAY:
675 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
676 break;
677 */
678 case CMD_PAUSE:
679 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
680 break;
681 case CMD_STOP:
682 mpdclient_cmd_stop(c);
683 break;
684 case CMD_CROP:
685 mpdclient_cmd_crop(c);
686 break;
687 case CMD_SEEK_FORWARD:
688 if (!IS_STOPPED(c->status->state)) {
689 if (c->song && seek_id != c->song->id) {
690 seek_id = c->song->id;
691 seek_target_time = c->status->elapsedTime;
692 }
693 seek_target_time+=options.seek_time;
694 if (seek_target_time < c->status->totalTime)
695 break;
696 seek_target_time = c->status->totalTime;
697 /* seek_target_time=0; */
698 }
699 break;
700 /* fall through... */
701 case CMD_TRACK_NEXT:
702 if (!IS_STOPPED(c->status->state))
703 mpdclient_cmd_next(c);
704 break;
705 case CMD_SEEK_BACKWARD:
706 if (!IS_STOPPED(c->status->state)) {
707 if (seek_id != c->song->id) {
708 seek_id = c->song->id;
709 seek_target_time = c->status->elapsedTime;
710 }
711 seek_target_time-=options.seek_time;
712 if (seek_target_time < 0)
713 seek_target_time=0;
714 }
715 break;
716 case CMD_TRACK_PREVIOUS:
717 if (!IS_STOPPED(c->status->state))
718 mpdclient_cmd_prev(c);
719 break;
720 case CMD_SHUFFLE:
721 if (mpdclient_cmd_shuffle(c) == 0)
722 screen_status_message(_("Shuffled playlist!"));
723 break;
724 case CMD_CLEAR:
725 if (mpdclient_cmd_clear(c) == 0)
726 screen_status_message(_("Cleared playlist!"));
727 break;
728 case CMD_REPEAT:
729 mpdclient_cmd_repeat(c, !c->status->repeat);
730 break;
731 case CMD_RANDOM:
732 mpdclient_cmd_random(c, !c->status->random);
733 break;
734 case CMD_CROSSFADE:
735 if (c->status->crossfade)
736 mpdclient_cmd_crossfade(c, 0);
737 else
738 mpdclient_cmd_crossfade(c, options.crossfade_time);
739 break;
740 case CMD_DB_UPDATE:
741 if (!c->status->updatingDb) {
742 if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
743 screen_status_printf(_("Database update started!"));
744 } else
745 screen_status_printf(_("Database update running..."));
746 break;
747 case CMD_VOLUME_UP:
748 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
749 mpdclient_cmd_volume(c, ++c->status->volume);
750 break;
751 case CMD_VOLUME_DOWN:
752 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
753 mpdclient_cmd_volume(c, --c->status->volume);
754 break;
756 default:
757 return 0;
758 }
760 return 1;
761 }
763 void
764 screen_cmd(mpdclient_t *c, command_t cmd)
765 {
766 screen.last_cmd = cmd;
767 welcome = FALSE;
769 if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
770 return;
772 if (screen_client_cmd(c, cmd))
773 return;
775 switch(cmd) {
776 case CMD_TOGGLE_FIND_WRAP:
777 options.find_wrap = !options.find_wrap;
778 screen_status_printf(options.find_wrap ?
779 _("Find mode: Wrapped") :
780 _("Find mode: Normal"));
781 break;
782 case CMD_TOGGLE_AUTOCENTER:
783 options.auto_center = !options.auto_center;
784 screen_status_printf(options.auto_center ?
785 _("Auto center mode: On") :
786 _("Auto center mode: Off"));
787 break;
788 case CMD_SCREEN_UPDATE:
789 screen.painted = 0;
790 break;
791 case CMD_SCREEN_PREVIOUS:
792 screen_next_mode(c, -1);
793 break;
794 case CMD_SCREEN_NEXT:
795 screen_next_mode(c, 1);
796 break;
797 case CMD_SCREEN_PLAY:
798 screen_switch(&screen_playlist, c);
799 break;
800 case CMD_SCREEN_FILE:
801 screen_switch(&screen_browse, c);
802 break;
803 case CMD_SCREEN_HELP:
804 screen_switch(&screen_help, c);
805 break;
806 #ifdef ENABLE_SEARCH_SCREEN
807 case CMD_SCREEN_SEARCH:
808 screen_switch(&screen_search, c);
809 break;
810 #endif
811 #ifdef ENABLE_ARTIST_SCREEN
812 case CMD_SCREEN_ARTIST:
813 screen_switch(&screen_artist, c);
814 break;
815 #endif
816 #ifdef ENABLE_KEYDEF_SCREEN
817 case CMD_SCREEN_KEYDEF:
818 screen_switch(&screen_keydef, c);
819 break;
820 #endif
821 #ifdef ENABLE_LYRICS_SCREEN
822 case CMD_SCREEN_LYRICS:
823 screen_switch(&screen_lyrics, c);
824 break;
825 #endif
826 default:
827 break;
828 }
829 }