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