5239b82d8161bd7126cd94926fb31f6cd61c9af4
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 "i18n.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 /** welcome message time [s] */
43 static const unsigned SCREEN_WELCOME_TIME = 10;
45 /** status message time [s] */
46 static const unsigned SCREEN_STATUS_MESSAGE_TIME = 3;
48 /* minumum window size */
49 static const int SCREEN_MIN_COLS = 14;
50 static const int SCREEN_MIN_ROWS = 5;
52 /* screens */
54 static gboolean welcome = TRUE;
55 static struct screen screen;
56 static const struct screen_functions *mode_fn = &screen_playlist;
57 static int seek_id = -1;
58 static int seek_target_time = 0;
60 gboolean
61 screen_is_visible(const struct screen_functions *sf)
62 {
63 return sf == mode_fn;
64 }
66 void
67 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
68 {
69 assert(sf != NULL);
71 if (sf == mode_fn)
72 return;
74 /* close the old mode */
75 if (mode_fn->close != NULL)
76 mode_fn->close();
78 /* get functions for the new mode */
79 mode_fn = sf;
80 screen.painted = 0;
82 /* open the new mode */
83 if (mode_fn->open != NULL)
84 mode_fn->open(&screen, c);
85 }
87 static int
88 find_configured_screen(const char *name)
89 {
90 unsigned i;
92 for (i = 0; options.screen_list[i] != NULL; ++i)
93 if (strcmp(options.screen_list[i], name) == 0)
94 return i;
96 return -1;
97 }
99 static void
100 screen_next_mode(mpdclient_t *c, int offset)
101 {
102 int max = g_strv_length(options.screen_list);
103 int current, next;
104 const struct screen_functions *sf;
106 /* find current screen */
107 current = find_configured_screen(screen_get_name(mode_fn));
108 next = current + offset;
109 if (next<0)
110 next = max-1;
111 else if (next>=max)
112 next = 0;
114 sf = screen_lookup_name(options.screen_list[next]);
115 if (sf != NULL)
116 screen_switch(sf, c);
117 }
119 static void
120 paint_top_window2(const char *header, mpdclient_t *c)
121 {
122 char flags[5];
123 WINDOW *w = screen.top_window.w;
124 char buf[32];
126 if (header[0]) {
127 colors_use(w, COLOR_TITLE_BOLD);
128 mvwaddstr(w, 0, 0, header);
129 } else {
130 colors_use(w, COLOR_TITLE_BOLD);
131 waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
132 colors_use(w, COLOR_TITLE);
133 waddstr(w, _(":Help "));
134 colors_use(w, COLOR_TITLE_BOLD);
135 waddstr(w, get_key_names(CMD_SCREEN_PLAY, FALSE));
136 colors_use(w, COLOR_TITLE);
137 waddstr(w, _(":Playlist "));
138 colors_use(w, COLOR_TITLE_BOLD);
139 waddstr(w, get_key_names(CMD_SCREEN_FILE, FALSE));
140 colors_use(w, COLOR_TITLE);
141 waddstr(w, _(":Browse "));
142 #ifdef ENABLE_ARTIST_SCREEN
143 colors_use(w, COLOR_TITLE_BOLD);
144 waddstr(w, get_key_names(CMD_SCREEN_ARTIST, FALSE));
145 colors_use(w, COLOR_TITLE);
146 waddstr(w, _(":Artist "));
147 #endif
148 #ifdef ENABLE_SEARCH_SCREEN
149 colors_use(w, COLOR_TITLE_BOLD);
150 waddstr(w, get_key_names(CMD_SCREEN_SEARCH, FALSE));
151 colors_use(w, COLOR_TITLE);
152 waddstr(w, _(":Search "));
153 #endif
154 #ifdef ENABLE_LYRICS_SCREEN
155 colors_use(w, COLOR_TITLE_BOLD);
156 waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
157 colors_use(w, COLOR_TITLE);
158 waddstr(w, _(":Lyrics "));
159 #endif
160 }
161 if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
162 g_snprintf(buf, 32, _("Volume n/a "));
163 } else {
164 g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
165 }
166 colors_use(w, COLOR_TITLE);
167 mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
169 flags[0] = 0;
170 if (c->status != NULL) {
171 if (c->status->repeat)
172 g_strlcat(flags, "r", sizeof(flags));
173 if (c->status->random)
174 g_strlcat(flags, "z", sizeof(flags));;
175 if (c->status->crossfade)
176 g_strlcat(flags, "x", sizeof(flags));
177 if (c->status->updatingDb)
178 g_strlcat(flags, "U", sizeof(flags));
179 }
181 colors_use(w, COLOR_LINE);
182 mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
183 if (flags[0]) {
184 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
185 waddch(w, '[');
186 colors_use(w, COLOR_LINE_BOLD);
187 waddstr(w, flags);
188 colors_use(w, COLOR_LINE);
189 waddch(w, ']');
190 }
191 wnoutrefresh(w);
192 }
194 static void
195 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
196 {
197 static int prev_volume = -1;
198 static size_t prev_header_len = -1;
199 WINDOW *w = screen.top_window.w;
201 if (prev_header_len!=my_strlen(header)) {
202 prev_header_len = my_strlen(header);
203 full_repaint = 1;
204 }
206 if (full_repaint) {
207 wmove(w, 0, 0);
208 wclrtoeol(w);
209 }
211 if ((c->status != NULL && prev_volume != c->status->volume) ||
212 full_repaint)
213 paint_top_window2(header, c);
214 }
216 static void
217 paint_progress_window(mpdclient_t *c)
218 {
219 double p;
220 int width;
221 int elapsedTime;
223 if (c->status==NULL || IS_STOPPED(c->status->state)) {
224 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
225 screen.progress_window.cols);
226 wnoutrefresh(screen.progress_window.w);
227 return;
228 }
230 if (c->song && seek_id == c->song->id)
231 elapsedTime = seek_target_time;
232 else
233 elapsedTime = c->status->elapsedTime;
235 p = ((double) elapsedTime) / ((double) c->status->totalTime);
237 width = (int) (p * (double) screen.progress_window.cols);
238 mvwhline(screen.progress_window.w,
239 0, 0,
240 ACS_HLINE,
241 screen.progress_window.cols);
242 whline(screen.progress_window.w, '=', width-1);
243 mvwaddch(screen.progress_window.w, 0, width-1, 'O');
244 wnoutrefresh(screen.progress_window.w);
245 }
247 static void
248 paint_status_window(mpdclient_t *c)
249 {
250 WINDOW *w = screen.status_window.w;
251 mpd_Status *status = c->status;
252 mpd_Song *song = c->song;
253 int elapsedTime = 0;
254 char bitrate[16];
255 const char *str = NULL;
256 int x = 0;
258 if( time(NULL) - screen.status_timestamp <= SCREEN_STATUS_MESSAGE_TIME )
259 return;
261 wmove(w, 0, 0);
262 wclrtoeol(w);
263 colors_use(w, COLOR_STATUS_BOLD);
265 switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
266 case MPD_STATUS_STATE_PLAY:
267 str = _("Playing:");
268 break;
269 case MPD_STATUS_STATE_PAUSE:
270 str = _("[Paused]");
271 break;
272 case MPD_STATUS_STATE_STOP:
273 default:
274 break;
275 }
277 if (str) {
278 waddstr(w, str);
279 x += my_strlen(str)+1;
280 }
282 /* create time string */
283 memset(screen.buf, 0, screen.buf_size);
284 if (status != NULL && (IS_PLAYING(status->state) ||
285 IS_PAUSED(status->state))) {
286 if (status->totalTime > 0) {
287 /*checks the conf to see whether to display elapsed or remaining time */
288 if(!strcmp(options.timedisplay_type,"elapsed"))
289 elapsedTime = c->status->elapsedTime;
290 else if(!strcmp(options.timedisplay_type,"remaining"))
291 elapsedTime = (c->status->totalTime - c->status->elapsedTime);
293 if( c->song && seek_id == c->song->id )
294 elapsedTime = seek_target_time;
296 /* display bitrate if visible-bitrate is true */
297 if (options.visible_bitrate) {
298 g_snprintf(bitrate, 16,
299 " [%d kbps]", status->bitRate);
300 } else {
301 bitrate[0] = '\0';
302 }
304 /*write out the time, using hours if time over 60 minutes*/
305 if (c->status->totalTime > 3600) {
306 g_snprintf(screen.buf, screen.buf_size,
307 "%s [%i:%02i:%02i/%i:%02i:%02i]",
308 bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
309 status->totalTime/3600, (status->totalTime%3600)/60, status->totalTime%60);
310 } else {
311 g_snprintf(screen.buf, screen.buf_size,
312 "%s [%i:%02i/%i:%02i]",
313 bitrate, elapsedTime/60, elapsedTime%60,
314 status->totalTime/60, status->totalTime%60 );
315 }
316 } else {
317 g_snprintf(screen.buf, screen.buf_size,
318 " [%d kbps]", status->bitRate );
319 }
320 } else {
321 time_t timep;
323 time(&timep);
324 strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
325 }
327 /* display song */
328 if (status != NULL && (IS_PLAYING(status->state) ||
329 IS_PAUSED(status->state))) {
330 char songname[MAX_SONGNAME_LENGTH];
331 int width = COLS-x-my_strlen(screen.buf);
333 if (song)
334 strfsong(songname, MAX_SONGNAME_LENGTH,
335 options.status_format, song);
336 else
337 songname[0] = '\0';
339 colors_use(w, COLOR_STATUS);
340 /* scroll if the song name is to long */
341 if (options.scroll && my_strlen(songname) > (size_t)width) {
342 static scroll_state_t st = { 0, 0 };
343 char *tmp = strscroll(songname, options.scroll_sep, width, &st);
345 g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
346 g_free(tmp);
347 }
348 //mvwaddnstr(w, 0, x, songname, width);
349 mvwaddstr(w, 0, x, songname);
350 }
352 /* display time string */
353 if (screen.buf[0]) {
354 x = screen.status_window.cols - strlen(screen.buf);
355 colors_use(w, COLOR_STATUS_TIME);
356 mvwaddstr(w, 0, x, screen.buf);
357 }
359 wnoutrefresh(w);
360 }
362 void
363 screen_exit(void)
364 {
365 if (mode_fn->close != NULL)
366 mode_fn->close();
368 screen_list_exit();
370 string_list_free(screen.find_history);
371 g_free(screen.buf);
372 g_free(screen.findbuf);
373 }
375 void
376 screen_resize(void)
377 {
378 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
379 screen_exit();
380 fprintf(stderr, _("Error: Screen to small!\n"));
381 exit(EXIT_FAILURE);
382 }
384 resizeterm(LINES, COLS);
386 screen.cols = COLS;
387 screen.rows = LINES;
389 /* top window */
390 screen.top_window.cols = screen.cols;
391 wresize(screen.top_window.w, 2, screen.cols);
393 /* main window */
394 screen.main_window.cols = screen.cols;
395 screen.main_window.rows = screen.rows-4;
396 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
397 wclear(screen.main_window.w);
399 /* progress window */
400 screen.progress_window.cols = screen.cols;
401 wresize(screen.progress_window.w, 1, screen.cols);
402 mvwin(screen.progress_window.w, screen.rows-2, 0);
404 /* status window */
405 screen.status_window.cols = screen.cols;
406 wresize(screen.status_window.w, 1, screen.cols);
407 mvwin(screen.status_window.w, screen.rows-1, 0);
409 screen.buf_size = screen.cols;
410 g_free(screen.buf);
411 screen.buf = g_malloc(screen.cols);
413 /* resize all screens */
414 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
416 /* ? - without this the cursor becomes visible with aterm & Eterm */
417 curs_set(1);
418 curs_set(0);
420 screen.painted = 0;
421 }
423 void
424 screen_status_message(const char *msg)
425 {
426 WINDOW *w = screen.status_window.w;
428 wmove(w, 0, 0);
429 wclrtoeol(w);
430 colors_use(w, COLOR_STATUS_ALERT);
431 waddstr(w, msg);
432 wnoutrefresh(w);
433 screen.status_timestamp = time(NULL);
434 }
436 void
437 screen_status_printf(const char *format, ...)
438 {
439 char *msg;
440 va_list ap;
442 va_start(ap,format);
443 msg = g_strdup_vprintf(format,ap);
444 va_end(ap);
445 screen_status_message(msg);
446 g_free(msg);
447 }
449 void
450 screen_init(mpdclient_t *c)
451 {
452 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
453 fprintf(stderr, _("Error: Screen to small!\n"));
454 exit(EXIT_FAILURE);
455 }
457 screen.cols = COLS;
458 screen.rows = LINES;
460 screen.buf = g_malloc(screen.cols);
461 screen.buf_size = screen.cols;
462 screen.findbuf = NULL;
463 screen.painted = 0;
464 screen.start_timestamp = time(NULL);
465 screen.last_cmd = CMD_NONE;
467 /* create top window */
468 screen.top_window.rows = 2;
469 screen.top_window.cols = screen.cols;
470 screen.top_window.w = newwin(screen.top_window.rows,
471 screen.top_window.cols,
472 0, 0);
473 leaveok(screen.top_window.w, TRUE);
474 keypad(screen.top_window.w, TRUE);
476 /* create main window */
477 screen.main_window.rows = screen.rows-4;
478 screen.main_window.cols = screen.cols;
479 screen.main_window.w = newwin(screen.main_window.rows,
480 screen.main_window.cols,
481 2,
482 0);
484 // leaveok(screen.main_window.w, TRUE); temporary disabled
485 keypad(screen.main_window.w, TRUE);
487 /* create progress window */
488 screen.progress_window.rows = 1;
489 screen.progress_window.cols = screen.cols;
490 screen.progress_window.w = newwin(screen.progress_window.rows,
491 screen.progress_window.cols,
492 screen.rows-2,
493 0);
494 leaveok(screen.progress_window.w, TRUE);
496 /* create status window */
497 screen.status_window.rows = 1;
498 screen.status_window.cols = screen.cols;
499 screen.status_window.w = newwin(screen.status_window.rows,
500 screen.status_window.cols,
501 screen.rows-1,
502 0);
504 leaveok(screen.status_window.w, FALSE);
505 keypad(screen.status_window.w, TRUE);
507 if (options.enable_colors) {
508 /* set background attributes */
509 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
510 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
511 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
512 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
513 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
514 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
515 }
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(&screen, c);
526 /* initialize wreadln */
527 wrln_wgetch = my_wgetch;
528 wrln_max_history_length = 16;
529 }
531 void
532 screen_paint(mpdclient_t *c)
533 {
534 const char *title = NULL;
536 if (mode_fn->get_title != NULL)
537 title = mode_fn->get_title(screen.buf, screen.buf_size);
539 /* paint the title/header window */
540 if( title )
541 paint_top_window(title, c, 1);
542 else
543 paint_top_window("", c, 1);
545 /* paint the main window */
546 wclear(screen.main_window.w);
547 if (mode_fn->paint != NULL)
548 mode_fn->paint(c);
550 paint_progress_window(c);
551 paint_status_window(c);
552 screen.painted = 1;
553 wmove(screen.main_window.w, 0, 0);
554 wnoutrefresh(screen.main_window.w);
556 /* tell curses to update */
557 doupdate();
558 }
560 void
561 screen_update(mpdclient_t *c)
562 {
563 static int repeat = -1;
564 static int random_enabled = -1;
565 static int crossfade = -1;
566 static int dbupdate = -1;
568 if( !screen.painted )
569 screen_paint(c);
571 /* print a message if mpd status has changed */
572 if (c->status != NULL) {
573 if (repeat < 0) {
574 repeat = c->status->repeat;
575 random_enabled = c->status->random;
576 crossfade = c->status->crossfade;
577 dbupdate = c->status->updatingDb;
578 }
580 if (repeat != c->status->repeat)
581 screen_status_printf(c->status->repeat ?
582 _("Repeat is on") :
583 _("Repeat is off"));
585 if (random_enabled != c->status->random)
586 screen_status_printf(c->status->random ?
587 _("Random is on") :
588 _("Random is off"));
590 if (crossfade != c->status->crossfade)
591 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
593 if (dbupdate && dbupdate != c->status->updatingDb) {
594 screen_status_printf(_("Database updated!"));
595 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
596 }
598 repeat = c->status->repeat;
599 random_enabled = c->status->random;
600 crossfade = c->status->crossfade;
601 dbupdate = c->status->updatingDb;
602 }
604 /* update title/header window */
605 if (welcome && options.welcome_screen_list &&
606 screen.last_cmd==CMD_NONE &&
607 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
608 paint_top_window("", c, 0);
609 else if (mode_fn->get_title != NULL) {
610 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
611 welcome = FALSE;
612 } else
613 paint_top_window("", c, 0);
615 /* update the main window */
616 if (mode_fn->update != NULL)
617 mode_fn->update(c);
619 /* update progress window */
620 paint_progress_window(c);
622 /* update status window */
623 paint_status_window(c);
625 /* move the cursor to the origin */
626 wmove(screen.main_window.w, 0, 0);
627 wnoutrefresh(screen.main_window.w);
629 /* tell curses to update */
630 doupdate();
631 }
633 void
634 screen_idle(mpdclient_t *c)
635 {
636 if (c->song && seek_id == c->song->id &&
637 (screen.last_cmd == CMD_SEEK_FORWARD ||
638 screen.last_cmd == CMD_SEEK_BACKWARD))
639 mpdclient_cmd_seek(c, seek_id, seek_target_time);
641 screen.last_cmd = CMD_NONE;
642 seek_id = -1;
643 }
645 #ifdef HAVE_GETMOUSE
646 int
647 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
648 {
649 MEVENT event;
651 /* retreive the mouse event from ncurses */
652 getmouse(&event);
653 /* calculate the selected row in the list window */
654 *row = event.y - screen.top_window.rows;
655 /* copy button state bits */
656 *bstate = event.bstate;
657 /* if button 2 was pressed switch screen */
658 if (event.bstate & BUTTON2_CLICKED) {
659 screen_cmd(c, CMD_SCREEN_NEXT);
660 return 1;
661 }
663 return 0;
664 }
665 #endif
667 static int
668 screen_client_cmd(mpdclient_t *c, command_t cmd)
669 {
670 if (c->connection == NULL || c->status == NULL)
671 return 0;
673 switch(cmd) {
674 /*
675 case CMD_PLAY:
676 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
677 break;
678 */
679 case CMD_PAUSE:
680 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
681 break;
682 case CMD_STOP:
683 mpdclient_cmd_stop(c);
684 break;
685 case CMD_CROP:
686 mpdclient_cmd_crop(c);
687 break;
688 case CMD_SEEK_FORWARD:
689 if (!IS_STOPPED(c->status->state)) {
690 if (c->song && seek_id != c->song->id) {
691 seek_id = c->song->id;
692 seek_target_time = c->status->elapsedTime;
693 }
694 seek_target_time+=options.seek_time;
695 if (seek_target_time < c->status->totalTime)
696 break;
697 seek_target_time = c->status->totalTime;
698 /* seek_target_time=0; */
699 }
700 break;
701 /* fall through... */
702 case CMD_TRACK_NEXT:
703 if (!IS_STOPPED(c->status->state))
704 mpdclient_cmd_next(c);
705 break;
706 case CMD_SEEK_BACKWARD:
707 if (!IS_STOPPED(c->status->state)) {
708 if (seek_id != c->song->id) {
709 seek_id = c->song->id;
710 seek_target_time = c->status->elapsedTime;
711 }
712 seek_target_time-=options.seek_time;
713 if (seek_target_time < 0)
714 seek_target_time=0;
715 }
716 break;
717 case CMD_TRACK_PREVIOUS:
718 if (!IS_STOPPED(c->status->state))
719 mpdclient_cmd_prev(c);
720 break;
721 case CMD_SHUFFLE:
722 if (mpdclient_cmd_shuffle(c) == 0)
723 screen_status_message(_("Shuffled playlist!"));
724 break;
725 case CMD_CLEAR:
726 if (mpdclient_cmd_clear(c) == 0)
727 screen_status_message(_("Cleared playlist!"));
728 break;
729 case CMD_REPEAT:
730 mpdclient_cmd_repeat(c, !c->status->repeat);
731 break;
732 case CMD_RANDOM:
733 mpdclient_cmd_random(c, !c->status->random);
734 break;
735 case CMD_CROSSFADE:
736 if (c->status->crossfade)
737 mpdclient_cmd_crossfade(c, 0);
738 else
739 mpdclient_cmd_crossfade(c, options.crossfade_time);
740 break;
741 case CMD_DB_UPDATE:
742 if (!c->status->updatingDb) {
743 if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
744 screen_status_printf(_("Database update started!"));
745 } else
746 screen_status_printf(_("Database update running..."));
747 break;
748 case CMD_VOLUME_UP:
749 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
750 mpdclient_cmd_volume(c, ++c->status->volume);
751 break;
752 case CMD_VOLUME_DOWN:
753 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
754 mpdclient_cmd_volume(c, --c->status->volume);
755 break;
757 default:
758 return 0;
759 }
761 return 1;
762 }
764 void
765 screen_cmd(mpdclient_t *c, command_t cmd)
766 {
767 screen.last_cmd = cmd;
768 welcome = FALSE;
770 if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
771 return;
773 if (screen_client_cmd(c, cmd))
774 return;
776 switch(cmd) {
777 case CMD_TOGGLE_FIND_WRAP:
778 options.find_wrap = !options.find_wrap;
779 screen_status_printf(options.find_wrap ?
780 _("Find mode: Wrapped") :
781 _("Find mode: Normal"));
782 break;
783 case CMD_TOGGLE_AUTOCENTER:
784 options.auto_center = !options.auto_center;
785 screen_status_printf(options.auto_center ?
786 _("Auto center mode: On") :
787 _("Auto center mode: Off"));
788 break;
789 case CMD_SCREEN_UPDATE:
790 screen.painted = 0;
791 break;
792 case CMD_SCREEN_PREVIOUS:
793 screen_next_mode(c, -1);
794 break;
795 case CMD_SCREEN_NEXT:
796 screen_next_mode(c, 1);
797 break;
798 case CMD_SCREEN_PLAY:
799 screen_switch(&screen_playlist, c);
800 break;
801 case CMD_SCREEN_FILE:
802 screen_switch(&screen_browse, c);
803 break;
804 case CMD_SCREEN_HELP:
805 screen_switch(&screen_help, c);
806 break;
807 #ifdef ENABLE_SEARCH_SCREEN
808 case CMD_SCREEN_SEARCH:
809 screen_switch(&screen_search, c);
810 break;
811 #endif
812 #ifdef ENABLE_ARTIST_SCREEN
813 case CMD_SCREEN_ARTIST:
814 screen_switch(&screen_artist, c);
815 break;
816 #endif
817 #ifdef ENABLE_KEYDEF_SCREEN
818 case CMD_SCREEN_KEYDEF:
819 screen_switch(&screen_keydef, c);
820 break;
821 #endif
822 #ifdef ENABLE_LYRICS_SCREEN
823 case CMD_SCREEN_LYRICS:
824 screen_switch(&screen_lyrics, c);
825 break;
826 #endif
827 default:
828 break;
829 }
830 }