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 "i18n.h"
27 #include "support.h"
28 #include "mpdclient.h"
29 #include "utils.h"
30 #include "command.h"
31 #include "options.h"
32 #include "colors.h"
33 #include "strfsong.h"
34 #include "wreadln.h"
36 #include <stdlib.h>
37 #include <unistd.h>
38 #include <stdarg.h>
39 #include <string.h>
40 #include <time.h>
41 #include <locale.h>
43 /* screens */
45 static gboolean welcome = TRUE;
46 static struct screen screen;
47 static const struct screen_functions *mode_fn = &screen_playlist;
48 static int seek_id = -1;
49 static int seek_target_time = 0;
51 gboolean
52 screen_is_visible(const struct screen_functions *sf)
53 {
54 return sf == mode_fn;
55 }
57 void
58 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
59 {
60 assert(sf != NULL);
62 if (sf == mode_fn)
63 return;
65 /* close the old mode */
66 if (mode_fn->close != NULL)
67 mode_fn->close();
69 /* get functions for the new mode */
70 mode_fn = sf;
71 screen.painted = 0;
73 /* open the new mode */
74 if (mode_fn->open != NULL)
75 mode_fn->open(&screen, c);
76 }
78 static int
79 find_configured_screen(const char *name)
80 {
81 unsigned i;
83 for (i = 0; options.screen_list[i] != NULL; ++i)
84 if (strcmp(options.screen_list[i], name) == 0)
85 return i;
87 return -1;
88 }
90 static void
91 screen_next_mode(mpdclient_t *c, int offset)
92 {
93 int max = g_strv_length(options.screen_list);
94 int current, next;
95 const struct screen_functions *sf;
97 /* find current screen */
98 current = find_configured_screen(screen_get_name(mode_fn));
99 next = current + offset;
100 if (next<0)
101 next = max-1;
102 else if (next>=max)
103 next = 0;
105 sf = screen_lookup_name(options.screen_list[next]);
106 if (sf != NULL)
107 screen_switch(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 if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
369 screen_exit();
370 fprintf(stderr, _("Error: Screen to small!\n"));
371 exit(EXIT_FAILURE);
372 }
374 resizeterm(LINES, COLS);
376 screen.cols = COLS;
377 screen.rows = LINES;
379 /* top window */
380 screen.top_window.cols = screen.cols;
381 wresize(screen.top_window.w, 2, screen.cols);
383 /* main window */
384 screen.main_window.cols = screen.cols;
385 screen.main_window.rows = screen.rows-4;
386 wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
387 wclear(screen.main_window.w);
389 /* progress window */
390 screen.progress_window.cols = screen.cols;
391 wresize(screen.progress_window.w, 1, screen.cols);
392 mvwin(screen.progress_window.w, screen.rows-2, 0);
394 /* status window */
395 screen.status_window.cols = screen.cols;
396 wresize(screen.status_window.w, 1, screen.cols);
397 mvwin(screen.status_window.w, screen.rows-1, 0);
399 screen.buf_size = screen.cols;
400 g_free(screen.buf);
401 screen.buf = g_malloc(screen.cols);
403 /* resize all screens */
404 screen_list_resize(screen.main_window.cols, screen.main_window.rows);
406 /* ? - without this the cursor becomes visible with aterm & Eterm */
407 curs_set(1);
408 curs_set(0);
410 screen.painted = 0;
411 }
413 void
414 screen_status_message(const char *msg)
415 {
416 WINDOW *w = screen.status_window.w;
418 wmove(w, 0, 0);
419 wclrtoeol(w);
420 colors_use(w, COLOR_STATUS_ALERT);
421 waddstr(w, msg);
422 wnoutrefresh(w);
423 screen.status_timestamp = time(NULL);
424 }
426 void
427 screen_status_printf(const char *format, ...)
428 {
429 char *msg;
430 va_list ap;
432 va_start(ap,format);
433 msg = g_strdup_vprintf(format,ap);
434 va_end(ap);
435 screen_status_message(msg);
436 g_free(msg);
437 }
439 void
440 screen_init(mpdclient_t *c)
441 {
442 if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
443 fprintf(stderr, _("Error: Screen to small!\n"));
444 exit(EXIT_FAILURE);
445 }
447 screen.cols = COLS;
448 screen.rows = LINES;
450 screen.buf = g_malloc(screen.cols);
451 screen.buf_size = screen.cols;
452 screen.findbuf = NULL;
453 screen.painted = 0;
454 screen.start_timestamp = time(NULL);
455 screen.last_cmd = CMD_NONE;
457 /* create top window */
458 screen.top_window.rows = 2;
459 screen.top_window.cols = screen.cols;
460 screen.top_window.w = newwin(screen.top_window.rows,
461 screen.top_window.cols,
462 0, 0);
463 leaveok(screen.top_window.w, TRUE);
464 keypad(screen.top_window.w, TRUE);
466 /* create main window */
467 screen.main_window.rows = screen.rows-4;
468 screen.main_window.cols = screen.cols;
469 screen.main_window.w = newwin(screen.main_window.rows,
470 screen.main_window.cols,
471 2,
472 0);
474 // leaveok(screen.main_window.w, TRUE); temporary disabled
475 keypad(screen.main_window.w, TRUE);
477 /* create progress window */
478 screen.progress_window.rows = 1;
479 screen.progress_window.cols = screen.cols;
480 screen.progress_window.w = newwin(screen.progress_window.rows,
481 screen.progress_window.cols,
482 screen.rows-2,
483 0);
484 leaveok(screen.progress_window.w, TRUE);
486 /* create status window */
487 screen.status_window.rows = 1;
488 screen.status_window.cols = screen.cols;
489 screen.status_window.w = newwin(screen.status_window.rows,
490 screen.status_window.cols,
491 screen.rows-1,
492 0);
494 leaveok(screen.status_window.w, FALSE);
495 keypad(screen.status_window.w, TRUE);
497 if (options.enable_colors) {
498 /* set background attributes */
499 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
500 wbkgd(screen.main_window.w, COLOR_PAIR(COLOR_LIST));
501 wbkgd(screen.top_window.w, COLOR_PAIR(COLOR_TITLE));
502 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
503 wbkgd(screen.status_window.w, COLOR_PAIR(COLOR_STATUS));
504 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
505 }
507 refresh();
509 /* initialize screens */
510 screen_list_init(screen.main_window.w,
511 screen.main_window.cols, screen.main_window.rows);
513 if (mode_fn->open != NULL)
514 mode_fn->open(&screen, c);
516 /* initialize wreadln */
517 wrln_wgetch = my_wgetch;
518 wrln_max_history_length = 16;
519 }
521 void
522 screen_paint(mpdclient_t *c)
523 {
524 const char *title = NULL;
526 if (mode_fn->get_title != NULL)
527 title = mode_fn->get_title(screen.buf, screen.buf_size);
529 /* paint the title/header window */
530 if( title )
531 paint_top_window(title, c, 1);
532 else
533 paint_top_window("", c, 1);
535 /* paint the main window */
536 wclear(screen.main_window.w);
537 if (mode_fn->paint != NULL)
538 mode_fn->paint(c);
540 paint_progress_window(c);
541 paint_status_window(c);
542 screen.painted = 1;
543 wmove(screen.main_window.w, 0, 0);
544 wnoutrefresh(screen.main_window.w);
546 /* tell curses to update */
547 doupdate();
548 }
550 void
551 screen_update(mpdclient_t *c)
552 {
553 static int repeat = -1;
554 static int random_enabled = -1;
555 static int crossfade = -1;
556 static int dbupdate = -1;
558 if( !screen.painted )
559 screen_paint(c);
561 /* print a message if mpd status has changed */
562 if (c->status != NULL) {
563 if (repeat < 0) {
564 repeat = c->status->repeat;
565 random_enabled = c->status->random;
566 crossfade = c->status->crossfade;
567 dbupdate = c->status->updatingDb;
568 }
570 if (repeat != c->status->repeat)
571 screen_status_printf(c->status->repeat ?
572 _("Repeat is on") :
573 _("Repeat is off"));
575 if (random_enabled != c->status->random)
576 screen_status_printf(c->status->random ?
577 _("Random is on") :
578 _("Random is off"));
580 if (crossfade != c->status->crossfade)
581 screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
583 if (dbupdate && dbupdate != c->status->updatingDb) {
584 screen_status_printf(_("Database updated!"));
585 mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
586 }
588 repeat = c->status->repeat;
589 random_enabled = c->status->random;
590 crossfade = c->status->crossfade;
591 dbupdate = c->status->updatingDb;
592 }
594 /* update title/header window */
595 if (welcome && options.welcome_screen_list &&
596 screen.last_cmd==CMD_NONE &&
597 time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
598 paint_top_window("", c, 0);
599 else if (mode_fn->get_title != NULL) {
600 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
601 welcome = FALSE;
602 } else
603 paint_top_window("", c, 0);
605 /* update the main window */
606 if (mode_fn->update != NULL)
607 mode_fn->update(c);
609 /* update progress window */
610 paint_progress_window(c);
612 /* update status window */
613 paint_status_window(c);
615 /* move the cursor to the origin */
616 wmove(screen.main_window.w, 0, 0);
617 wnoutrefresh(screen.main_window.w);
619 /* tell curses to update */
620 doupdate();
621 }
623 void
624 screen_idle(mpdclient_t *c)
625 {
626 if (c->song && seek_id == c->song->id &&
627 (screen.last_cmd == CMD_SEEK_FORWARD ||
628 screen.last_cmd == CMD_SEEK_BACKWARD))
629 mpdclient_cmd_seek(c, seek_id, seek_target_time);
631 screen.last_cmd = CMD_NONE;
632 seek_id = -1;
633 }
635 #ifdef HAVE_GETMOUSE
636 int
637 screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
638 {
639 MEVENT event;
641 /* retreive the mouse event from ncurses */
642 getmouse(&event);
643 /* calculate the selected row in the list window */
644 *row = event.y - screen.top_window.rows;
645 /* copy button state bits */
646 *bstate = event.bstate;
647 /* if button 2 was pressed switch screen */
648 if (event.bstate & BUTTON2_CLICKED) {
649 screen_cmd(c, CMD_SCREEN_NEXT);
650 return 1;
651 }
653 return 0;
654 }
655 #endif
657 static int
658 screen_client_cmd(mpdclient_t *c, command_t cmd)
659 {
660 if (c->connection == NULL || c->status == NULL)
661 return 0;
663 switch(cmd) {
664 /*
665 case CMD_PLAY:
666 mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
667 break;
668 */
669 case CMD_PAUSE:
670 mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
671 break;
672 case CMD_STOP:
673 mpdclient_cmd_stop(c);
674 break;
675 case CMD_CROP:
676 mpdclient_cmd_crop(c);
677 break;
678 case CMD_SEEK_FORWARD:
679 if (!IS_STOPPED(c->status->state)) {
680 if (c->song && seek_id != c->song->id) {
681 seek_id = c->song->id;
682 seek_target_time = c->status->elapsedTime;
683 }
684 seek_target_time+=options.seek_time;
685 if (seek_target_time < c->status->totalTime)
686 break;
687 seek_target_time = c->status->totalTime;
688 /* seek_target_time=0; */
689 }
690 break;
691 /* fall through... */
692 case CMD_TRACK_NEXT:
693 if (!IS_STOPPED(c->status->state))
694 mpdclient_cmd_next(c);
695 break;
696 case CMD_SEEK_BACKWARD:
697 if (!IS_STOPPED(c->status->state)) {
698 if (seek_id != c->song->id) {
699 seek_id = c->song->id;
700 seek_target_time = c->status->elapsedTime;
701 }
702 seek_target_time-=options.seek_time;
703 if (seek_target_time < 0)
704 seek_target_time=0;
705 }
706 break;
707 case CMD_TRACK_PREVIOUS:
708 if (!IS_STOPPED(c->status->state))
709 mpdclient_cmd_prev(c);
710 break;
711 case CMD_SHUFFLE:
712 if (mpdclient_cmd_shuffle(c) == 0)
713 screen_status_message(_("Shuffled playlist!"));
714 break;
715 case CMD_CLEAR:
716 if (mpdclient_cmd_clear(c) == 0)
717 screen_status_message(_("Cleared playlist!"));
718 break;
719 case CMD_REPEAT:
720 mpdclient_cmd_repeat(c, !c->status->repeat);
721 break;
722 case CMD_RANDOM:
723 mpdclient_cmd_random(c, !c->status->random);
724 break;
725 case CMD_CROSSFADE:
726 if (c->status->crossfade)
727 mpdclient_cmd_crossfade(c, 0);
728 else
729 mpdclient_cmd_crossfade(c, options.crossfade_time);
730 break;
731 case CMD_DB_UPDATE:
732 if (!c->status->updatingDb) {
733 if( mpdclient_cmd_db_update_utf8(c,NULL)==0 )
734 screen_status_printf(_("Database update started!"));
735 } else
736 screen_status_printf(_("Database update running..."));
737 break;
738 case CMD_VOLUME_UP:
739 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume<100 )
740 mpdclient_cmd_volume(c, ++c->status->volume);
741 break;
742 case CMD_VOLUME_DOWN:
743 if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
744 mpdclient_cmd_volume(c, --c->status->volume);
745 break;
747 default:
748 return 0;
749 }
751 return 1;
752 }
754 void
755 screen_cmd(mpdclient_t *c, command_t cmd)
756 {
757 screen.last_cmd = cmd;
758 welcome = FALSE;
760 if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
761 return;
763 if (screen_client_cmd(c, cmd))
764 return;
766 switch(cmd) {
767 case CMD_TOGGLE_FIND_WRAP:
768 options.find_wrap = !options.find_wrap;
769 screen_status_printf(options.find_wrap ?
770 _("Find mode: Wrapped") :
771 _("Find mode: Normal"));
772 break;
773 case CMD_TOGGLE_AUTOCENTER:
774 options.auto_center = !options.auto_center;
775 screen_status_printf(options.auto_center ?
776 _("Auto center mode: On") :
777 _("Auto center mode: Off"));
778 break;
779 case CMD_SCREEN_UPDATE:
780 screen.painted = 0;
781 break;
782 case CMD_SCREEN_PREVIOUS:
783 screen_next_mode(c, -1);
784 break;
785 case CMD_SCREEN_NEXT:
786 screen_next_mode(c, 1);
787 break;
788 case CMD_SCREEN_PLAY:
789 screen_switch(&screen_playlist, c);
790 break;
791 case CMD_SCREEN_FILE:
792 screen_switch(&screen_browse, c);
793 break;
794 case CMD_SCREEN_HELP:
795 screen_switch(&screen_help, c);
796 break;
797 #ifdef ENABLE_SEARCH_SCREEN
798 case CMD_SCREEN_SEARCH:
799 screen_switch(&screen_search, c);
800 break;
801 #endif
802 #ifdef ENABLE_ARTIST_SCREEN
803 case CMD_SCREEN_ARTIST:
804 screen_switch(&screen_artist, c);
805 break;
806 #endif
807 #ifdef ENABLE_KEYDEF_SCREEN
808 case CMD_SCREEN_KEYDEF:
809 screen_switch(&screen_keydef, c);
810 break;
811 #endif
812 #ifdef ENABLE_LYRICS_SCREEN
813 case CMD_SCREEN_LYRICS:
814 screen_switch(&screen_lyrics, c);
815 break;
816 #endif
817 default:
818 break;
819 }
820 }