Code

screen: moved screen_client_cmd() to player_command.c
[ncmpc.git] / src / screen.c
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #include "screen.h"
21 #include "screen_list.h"
22 #include "screen_utils.h"
23 #include "config.h"
24 #include "i18n.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"
31 #include "player_command.h"
33 #ifndef NCMPC_MINI
34 #include "hscroll.h"
35 #endif
37 #include <mpd/client.h>
39 #include <stdlib.h>
40 #include <unistd.h>
41 #include <stdarg.h>
42 #include <string.h>
43 #include <time.h>
44 #include <locale.h>
46 #ifndef NCMPC_MINI
47 /** welcome message time [s] */
48 static const GTime SCREEN_WELCOME_TIME = 10;
49 #endif
51 /* minimum window size */
52 static const int SCREEN_MIN_COLS = 14;
53 static const int SCREEN_MIN_ROWS = 5;
55 /* screens */
57 #ifndef NCMPC_MINI
58 static gboolean welcome = TRUE;
59 #endif
61 struct screen screen;
62 static const struct screen_functions *mode_fn = &screen_playlist;
63 static const struct screen_functions *mode_fn_prev = &screen_playlist;
65 gboolean
66 screen_is_visible(const struct screen_functions *sf)
67 {
68         return sf == mode_fn;
69 }
71 void
72 screen_switch(const struct screen_functions *sf, struct mpdclient *c)
73 {
74         assert(sf != NULL);
76         if (sf == mode_fn)
77                 return;
79         mode_fn_prev = mode_fn;
81         /* close the old mode */
82         if (mode_fn->close != NULL)
83                 mode_fn->close();
85         /* get functions for the new mode */
86         mode_fn = sf;
88         /* open the new mode */
89         if (mode_fn->open != NULL)
90                 mode_fn->open(c);
92         screen_paint(c);
93 }
95 void
96 screen_swap(struct mpdclient *c, const struct mpd_song *song)
97 {
98         if (song != NULL)
99         {
100                 if (false)
101                         { /* just a hack to make the ifdefs less ugly */ }
102 #ifdef ENABLE_SONG_SCREEN
103                 if (mode_fn_prev == &screen_song)
104                         screen_song_switch(c, song);
105 #endif
106 #ifdef ENABLE_LYRICS_SCREEN
107                 else if (mode_fn_prev == &screen_lyrics)
108                         screen_lyrics_switch(c, song, true);
109 #endif
110                 else
111                         screen_switch(mode_fn_prev, c);
112         }
113         else
114                 screen_switch(mode_fn_prev, c);
117 static int
118 find_configured_screen(const char *name)
120         unsigned i;
122         for (i = 0; options.screen_list[i] != NULL; ++i)
123                 if (strcmp(options.screen_list[i], name) == 0)
124                         return i;
126         return -1;
129 static void
130 screen_next_mode(struct mpdclient *c, int offset)
132         int max = g_strv_length(options.screen_list);
133         int current, next;
134         const struct screen_functions *sf;
136         /* find current screen */
137         current = find_configured_screen(screen_get_name(mode_fn));
138         next = current + offset;
139         if (next<0)
140                 next = max-1;
141         else if (next>=max)
142                 next = 0;
144         sf = screen_lookup_name(options.screen_list[next]);
145         if (sf != NULL)
146                 screen_switch(sf, c);
149 #ifndef NCMPC_MINI
150 static void
151 print_hotkey(WINDOW *w, command_t cmd, const char *label)
153         colors_use(w, COLOR_TITLE_BOLD);
154         waddstr(w, get_key_names(cmd, FALSE));
155         colors_use(w, COLOR_TITLE);
156         waddch(w, ':');
157         waddstr(w, label);
158         waddch(w, ' ');
159         waddch(w, ' ');
161 #endif
163 static inline int
164 get_volume(const struct mpd_status *status)
166         return status != NULL
167                 ? mpd_status_get_volume(status)
168                 : MPD_STATUS_NO_VOLUME;
171 static void
172 paint_top_window2(const char *header, struct mpdclient *c)
174         int volume;
175         char flags[5];
176         WINDOW *w = screen.top_window.w;
177         char buf[32];
179         if (header[0]) {
180                 colors_use(w, COLOR_TITLE_BOLD);
181                 mvwaddstr(w, 0, 0, header);
182 #ifndef NCMPC_MINI
183         } else {
184 #ifdef ENABLE_HELP_SCREEN
185                 print_hotkey(w, CMD_SCREEN_HELP, _("Help"));
186 #endif
187                 print_hotkey(w, CMD_SCREEN_PLAY, _("Playlist"));
188                 print_hotkey(w, CMD_SCREEN_FILE, _("Browse"));
189 #ifdef ENABLE_ARTIST_SCREEN
190                 print_hotkey(w, CMD_SCREEN_ARTIST, _("Artist"));
191 #endif
192 #ifdef ENABLE_SEARCH_SCREEN
193                 print_hotkey(w, CMD_SCREEN_SEARCH, _("Search"));
194 #endif
195 #ifdef ENABLE_LYRICS_SCREEN
196                 print_hotkey(w, CMD_SCREEN_LYRICS, _("Lyrics"));
197 #endif
198 #ifdef ENABLE_OUTPUTS_SCREEN
199                 print_hotkey(w, CMD_SCREEN_OUTPUTS, _("Outputs"));
200 #endif
201 #endif
202         }
204         volume = get_volume(c->status);
205         if (volume == MPD_STATUS_NO_VOLUME)
206                 g_snprintf(buf, 32, _("Volume n/a"));
207         else
208                 g_snprintf(buf, 32, _("Volume %d%%"), volume);
210         colors_use(w, COLOR_TITLE);
211         mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
213         flags[0] = 0;
214         if (c->status != NULL) {
215                 if (mpd_status_get_repeat(c->status))
216                         g_strlcat(flags, "r", sizeof(flags));
217                 if (mpd_status_get_random(c->status))
218                         g_strlcat(flags, "z", sizeof(flags));
219                 if (mpd_status_get_single(c->status))
220                         g_strlcat(flags, "s", sizeof(flags));
221                 if (mpd_status_get_consume(c->status))
222                         g_strlcat(flags, "c", sizeof(flags));
223                 if (mpd_status_get_crossfade(c->status))
224                         g_strlcat(flags, "x", sizeof(flags));
225                 if (mpd_status_get_update_id(c->status) != 0)
226                         g_strlcat(flags, "U", sizeof(flags));
227         }
229         colors_use(w, COLOR_LINE);
230         mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
231         if (flags[0]) {
232                 wmove(w,1,screen.top_window.cols-strlen(flags)-3);
233                 waddch(w, '[');
234                 colors_use(w, COLOR_LINE_BOLD);
235                 waddstr(w, flags);
236                 colors_use(w, COLOR_LINE);
237                 waddch(w, ']');
238         }
239         wnoutrefresh(w);
242 static inline int
243 volume_length(int volume)
245         if (volume == 100)
246                 return 3;
247         if (volume >= 10 && volume < 100)
248                 return 2;
249         if (volume >= 0 && volume < 10)
250                 return 1;
251         return -1;
254 static void
255 paint_top_window(const char *header, struct mpdclient *c, int full_repaint)
257         static int prev_volume = -1;
258         static unsigned prev_header_len = -1;
259         WINDOW *w = screen.top_window.w;
261         if (prev_header_len != utf8_width(header)) {
262                 prev_header_len = utf8_width(header);
263                 full_repaint = 1;
264         }
266         if (c->status &&
267             volume_length(prev_volume) !=
268             volume_length(mpd_status_get_volume(c->status)))
269                 full_repaint = 1;
271         if (full_repaint) {
272                 wmove(w, 0, 0);
273                 wclrtoeol(w);
274         }
276         if ((c->status != NULL &&
277              prev_volume != mpd_status_get_volume(c->status)) ||
278             full_repaint)
279                 paint_top_window2(header, c);
282 static void
283 paint_progress_window(struct mpdclient *c)
285         double p;
286         int width;
287         int elapsedTime;
289         if (c->status==NULL || IS_STOPPED(mpd_status_get_state(c->status))) {
290                 mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
291                          screen.progress_window.cols);
292                 wnoutrefresh(screen.progress_window.w);
293                 return;
294         }
296         if (c->song != NULL && seek_id == (int)mpd_song_get_id(c->song))
297                 elapsedTime = seek_target_time;
298         else
299                 elapsedTime = mpd_status_get_elapsed_time(c->status);
301         p = ((double) elapsedTime) / ((double) mpd_status_get_total_time(c->status));
303         width = (int) (p * (double) screen.progress_window.cols);
304         mvwhline(screen.progress_window.w,
305                  0, 0,
306                  ACS_HLINE,
307                  screen.progress_window.cols);
308         whline(screen.progress_window.w, '=', width-1);
309         mvwaddch(screen.progress_window.w, 0, width-1, 'O');
310         wnoutrefresh(screen.progress_window.w);
313 static void
314 paint_status_window(struct mpdclient *c)
316         WINDOW *w = screen.status_window.w;
317         const struct mpd_status *status = c->status;
318         enum mpd_state state;
319         const struct mpd_song *song = c->song;
320         int elapsedTime = 0;
321 #ifdef NCMPC_MINI
322         static char bitrate[1];
323 #else
324         char bitrate[16];
325 #endif
326         const char *str = NULL;
327         int x = 0;
329         if( time(NULL) - screen.status_timestamp <= options.status_message_time )
330                 return;
332         wmove(w, 0, 0);
333         wclrtoeol(w);
334         colors_use(w, COLOR_STATUS_BOLD);
336         state = status == NULL ? MPD_STATE_UNKNOWN
337                 : mpd_status_get_state(status);
339         switch (state) {
340         case MPD_STATE_PLAY:
341                 str = _("Playing:");
342                 break;
343         case MPD_STATE_PAUSE:
344                 str = _("[Paused]");
345                 break;
346         case MPD_STATE_STOP:
347         default:
348                 break;
349         }
351         if (str) {
352                 waddstr(w, str);
353                 x += utf8_width(str) + 1;
354         }
356         /* create time string */
357         memset(screen.buf, 0, screen.buf_size);
358         if (IS_PLAYING(state) || IS_PAUSED(state)) {
359                 int total_time = mpd_status_get_total_time(status);
360                 if (total_time > 0) {
361                         /*checks the conf to see whether to display elapsed or remaining time */
362                         if(!strcmp(options.timedisplay_type,"elapsed"))
363                                 elapsedTime = mpd_status_get_elapsed_time(c->status);
364                         else if(!strcmp(options.timedisplay_type,"remaining"))
365                                 elapsedTime = total_time -
366                                         mpd_status_get_elapsed_time(c->status);
368                         if (c->song != NULL &&
369                             seek_id == (int)mpd_song_get_id(c->song))
370                                 elapsedTime = seek_target_time;
372                         /* display bitrate if visible-bitrate is true */
373 #ifndef NCMPC_MINI
374                         if (options.visible_bitrate) {
375                                 g_snprintf(bitrate, 16,
376                                            " [%d kbps]",
377                                            mpd_status_get_kbit_rate(status));
378                         } else {
379                                 bitrate[0] = '\0';
380                         }
381 #endif
383                         /*write out the time, using hours if time over 60 minutes*/
384                         if (total_time > 3600) {
385                                 g_snprintf(screen.buf, screen.buf_size,
386                                            "%s [%i:%02i:%02i/%i:%02i:%02i]",
387                                            bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
388                                            total_time / 3600,
389                                            (total_time % 3600)/60,
390                                            total_time % 60);
391                         } else {
392                                 g_snprintf(screen.buf, screen.buf_size,
393                                            "%s [%i:%02i/%i:%02i]",
394                                            bitrate, elapsedTime/60, elapsedTime%60,
395                                            total_time / 60, total_time % 60);
396                         }
397 #ifndef NCMPC_MINI
398                 } else {
399                         g_snprintf(screen.buf, screen.buf_size,
400                                    " [%d kbps]",
401                                    mpd_status_get_kbit_rate(status));
402 #endif
403                 }
404 #ifndef NCMPC_MINI
405         } else {
406                 if (options.display_time) {
407                         time_t timep;
409                         time(&timep);
410                         strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
411                 }
412 #endif
413         }
415         /* display song */
416         if (IS_PLAYING(state) || IS_PAUSED(state)) {
417                 char songname[MAX_SONGNAME_LENGTH];
418 #ifndef NCMPC_MINI
419                 int width = COLS - x - utf8_width(screen.buf);
420 #endif
422                 if (song)
423                         strfsong(songname, MAX_SONGNAME_LENGTH,
424                                  options.status_format, song);
425                 else
426                         songname[0] = '\0';
428                 colors_use(w, COLOR_STATUS);
429                 /* scroll if the song name is to long */
430 #ifndef NCMPC_MINI
431                 if (options.scroll && utf8_width(songname) > (unsigned)width) {
432                         static  scroll_state_t st = { 0, 0 };
433                         char *tmp = strscroll(songname, options.scroll_sep, width, &st);
435                         g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
436                         g_free(tmp);
437                 }
438 #endif
439                 //mvwaddnstr(w, 0, x, songname, width);
440                 mvwaddstr(w, 0, x, songname);
441         }
443         /* display time string */
444         if (screen.buf[0]) {
445                 x = screen.status_window.cols - strlen(screen.buf);
446                 colors_use(w, COLOR_STATUS_TIME);
447                 mvwaddstr(w, 0, x, screen.buf);
448         }
450         wnoutrefresh(w);
453 void
454 screen_exit(void)
456         if (mode_fn->close != NULL)
457                 mode_fn->close();
459         screen_list_exit();
461         string_list_free(screen.find_history);
462         g_free(screen.buf);
463         g_free(screen.findbuf);
465         delwin(screen.top_window.w);
466         delwin(screen.main_window.w);
467         delwin(screen.progress_window.w);
468         delwin(screen.status_window.w);
471 void
472 screen_resize(struct mpdclient *c)
474         if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
475                 screen_exit();
476                 fprintf(stderr, "%s", _("Error: Screen too small"));
477                 exit(EXIT_FAILURE);
478         }
480         resizeterm(LINES, COLS);
482         screen.cols = COLS;
483         screen.rows = LINES;
485         /* top window */
486         screen.top_window.cols = screen.cols;
487         wresize(screen.top_window.w, 2, screen.cols);
489         /* main window */
490         screen.main_window.cols = screen.cols;
491         screen.main_window.rows = screen.rows-4;
492         wresize(screen.main_window.w, screen.main_window.rows, screen.cols);
493         wclear(screen.main_window.w);
495         /* progress window */
496         screen.progress_window.cols = screen.cols;
497         wresize(screen.progress_window.w, 1, screen.cols);
498         mvwin(screen.progress_window.w, screen.rows-2, 0);
500         /* status window */
501         screen.status_window.cols = screen.cols;
502         wresize(screen.status_window.w, 1, screen.cols);
503         mvwin(screen.status_window.w, screen.rows-1, 0);
505         screen.buf_size = screen.cols;
506         g_free(screen.buf);
507         screen.buf = g_malloc(screen.cols);
509         /* resize all screens */
510         screen_list_resize(screen.main_window.cols, screen.main_window.rows);
512         /* ? - without this the cursor becomes visible with aterm & Eterm */
513         curs_set(1);
514         curs_set(0);
516         screen_paint(c);
519 void
520 screen_status_message(const char *msg)
522         WINDOW *w = screen.status_window.w;
524         wmove(w, 0, 0);
525         wclrtoeol(w);
526         colors_use(w, COLOR_STATUS_ALERT);
527         waddstr(w, msg);
528         wnoutrefresh(w);
529         screen.status_timestamp = time(NULL);
532 void
533 screen_status_printf(const char *format, ...)
535         char *msg;
536         va_list ap;
538         va_start(ap,format);
539         msg = g_strdup_vprintf(format,ap);
540         va_end(ap);
541         screen_status_message(msg);
542         g_free(msg);
545 void
546 screen_init(struct mpdclient *c)
548         if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
549                 fprintf(stderr, "%s\n", _("Error: Screen too small"));
550                 exit(EXIT_FAILURE);
551         }
553         screen.cols = COLS;
554         screen.rows = LINES;
556         screen.buf  = g_malloc(screen.cols);
557         screen.buf_size = screen.cols;
558         screen.findbuf = NULL;
559         screen.start_timestamp = time(NULL);
560         screen.last_cmd = CMD_NONE;
562         /* create top window */
563         screen.top_window.rows = 2;
564         screen.top_window.cols = screen.cols;
565         screen.top_window.w = newwin(screen.top_window.rows,
566                                       screen.top_window.cols,
567                                       0, 0);
568         leaveok(screen.top_window.w, TRUE);
569         keypad(screen.top_window.w, TRUE);
571         /* create main window */
572         screen.main_window.rows = screen.rows-4;
573         screen.main_window.cols = screen.cols;
574         screen.main_window.w = newwin(screen.main_window.rows,
575                                        screen.main_window.cols,
576                                        2,
577                                        0);
579         //  leaveok(screen.main_window.w, TRUE); temporary disabled
580         keypad(screen.main_window.w, TRUE);
582         /* create progress window */
583         screen.progress_window.rows = 1;
584         screen.progress_window.cols = screen.cols;
585         screen.progress_window.w = newwin(screen.progress_window.rows,
586                                            screen.progress_window.cols,
587                                            screen.rows-2,
588                                            0);
589         leaveok(screen.progress_window.w, TRUE);
591         /* create status window */
592         screen.status_window.rows = 1;
593         screen.status_window.cols = screen.cols;
594         screen.status_window.w = newwin(screen.status_window.rows,
595                                          screen.status_window.cols,
596                                          screen.rows-1,
597                                          0);
599         leaveok(screen.status_window.w, FALSE);
600         keypad(screen.status_window.w, TRUE);
602 #ifdef ENABLE_COLORS
603         if (options.enable_colors) {
604                 /* set background attributes */
605                 wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
606                 wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
607                 wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
608                 wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
609                 wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
610                 colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
611         }
612 #endif
614         refresh();
616         /* initialize screens */
617         screen_list_init(screen.main_window.w,
618                          screen.main_window.cols, screen.main_window.rows);
620         if (mode_fn->open != NULL)
621                 mode_fn->open(c);
624 void
625 screen_paint(struct mpdclient *c)
627         const char *title = NULL;
629         if (mode_fn->get_title != NULL)
630                 title = mode_fn->get_title(screen.buf, screen.buf_size);
632         /* paint the title/header window */
633         if( title )
634                 paint_top_window(title, c, 1);
635         else
636                 paint_top_window("", c, 1);
638         /* paint the bottom window */
640         paint_progress_window(c);
641         paint_status_window(c);
643         /* paint the main window */
645         wclear(screen.main_window.w);
646         if (mode_fn->paint != NULL)
647                 mode_fn->paint();
649         /* move the cursor to the origin */
651         if (!options.hardware_cursor)
652                 wmove(screen.main_window.w, 0, 0);
654         wnoutrefresh(screen.main_window.w);
656         /* tell curses to update */
657         doupdate();
660 void
661 screen_update(struct mpdclient *c)
663 #ifndef NCMPC_MINI
664         static bool initialized = false;
665         static bool repeat;
666         static bool random_enabled;
667         static bool single;
668         static bool consume;
669         static unsigned crossfade;
670         static unsigned dbupdate;
672         /* print a message if mpd status has changed */
673         if (c->status != NULL) {
674                 if (!initialized) {
675                         repeat = mpd_status_get_repeat(c->status);
676                         random_enabled = mpd_status_get_random(c->status);
677                         single = mpd_status_get_single(c->status);
678                         consume = mpd_status_get_consume(c->status);
679                         crossfade = mpd_status_get_crossfade(c->status);
680                         dbupdate = mpd_status_get_update_id(c->status);
681                         initialized = true;
682                 }
684                 if (repeat != mpd_status_get_repeat(c->status))
685                         screen_status_printf(mpd_status_get_repeat(c->status) ?
686                                              _("Repeat mode is on") :
687                                              _("Repeat mode is off"));
689                 if (random_enabled != mpd_status_get_random(c->status))
690                         screen_status_printf(mpd_status_get_random(c->status) ?
691                                              _("Random mode is on") :
692                                              _("Random mode is off"));
694                 if (single != mpd_status_get_single(c->status))
695                         screen_status_printf(mpd_status_get_single(c->status) ?
696                                              /* "single" mode means
697                                                 that MPD will
698                                                 automatically stop
699                                                 after playing one
700                                                 single song */
701                                              _("Single mode is on") :
702                                              _("Single mode is off"));
704                 if (consume != mpd_status_get_consume(c->status))
705                         screen_status_printf(mpd_status_get_consume(c->status) ?
706                                              /* "consume" mode means
707                                                 that MPD removes each
708                                                 song which has
709                                                 finished playing */
710                                              _("Consume mode is on") :
711                                              _("Consume mode is off"));
713                 if (crossfade != mpd_status_get_crossfade(c->status))
714                         screen_status_printf(_("Crossfade %d seconds"),
715                                              mpd_status_get_crossfade(c->status));
717                 if (dbupdate != 0 &&
718                     dbupdate != mpd_status_get_update_id(c->status)) {
719                         screen_status_printf(_("Database updated"));
720                 }
722                 repeat = mpd_status_get_repeat(c->status);
723                 random_enabled = mpd_status_get_random(c->status);
724                 single = mpd_status_get_single(c->status);
725                 consume = mpd_status_get_consume(c->status);
726                 crossfade = mpd_status_get_crossfade(c->status);
727                 dbupdate = mpd_status_get_update_id(c->status);
728         }
730         /* update title/header window */
731         if (welcome && options.welcome_screen_list &&
732             screen.last_cmd==CMD_NONE &&
733             time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
734                 paint_top_window("", c, 0);
735         else
736 #endif
737         if (mode_fn->get_title != NULL) {
738                 paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
739 #ifndef NCMPC_MINI
740                 welcome = FALSE;
741 #endif
742         } else
743                 paint_top_window("", c, 0);
745         /* update progress window */
746         paint_progress_window(c);
748         /* update status window */
749         paint_status_window(c);
751         /* update the main window */
752         if (mode_fn->update != NULL)
753                 mode_fn->update(c);
755         /* move the cursor to the origin */
757         if (!options.hardware_cursor)
758                 wmove(screen.main_window.w, 0, 0);
760         wnoutrefresh(screen.main_window.w);
762         /* tell curses to update */
763         doupdate();
766 void
767 screen_idle(struct mpdclient *c)
769         if (c->song != NULL && seek_id == (int)mpd_song_get_id(c->song) &&
770             (screen.last_cmd == CMD_SEEK_FORWARD ||
771              screen.last_cmd == CMD_SEEK_BACKWARD))
772                 mpdclient_cmd_seek(c, seek_id, seek_target_time);
774         screen.last_cmd = CMD_NONE;
775         seek_id = -1;
778 #ifdef HAVE_GETMOUSE
779 int
780 screen_get_mouse_event(struct mpdclient *c, unsigned long *bstate, int *row)
782         MEVENT event;
784         /* retrieve the mouse event from ncurses */
785         getmouse(&event);
786         /* calculate the selected row in the list window */
787         *row = event.y - screen.top_window.rows;
788         /* copy button state bits */
789         *bstate = event.bstate;
790         /* if button 2 was pressed switch screen */
791         if (event.bstate & BUTTON2_CLICKED) {
792                 screen_cmd(c, CMD_SCREEN_NEXT);
793                 return 1;
794         }
796         return 0;
798 #endif
800 void
801 screen_cmd(struct mpdclient *c, command_t cmd)
803         screen.last_cmd = cmd;
804 #ifndef NCMPC_MINI
805         welcome = FALSE;
806 #endif
808         if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
809                 return;
811         if (handle_player_command(c, cmd))
812                 return;
814         switch(cmd) {
815         case CMD_TOGGLE_FIND_WRAP:
816                 options.find_wrap = !options.find_wrap;
817                 screen_status_printf(options.find_wrap ?
818                                      _("Find mode: Wrapped") :
819                                      _("Find mode: Normal"));
820                 break;
821         case CMD_TOGGLE_AUTOCENTER:
822                 options.auto_center = !options.auto_center;
823                 screen_status_printf(options.auto_center ?
824                                      _("Auto center mode: On") :
825                                      _("Auto center mode: Off"));
826                 break;
827         case CMD_SCREEN_UPDATE:
828                 screen_paint(c);
829                 break;
830         case CMD_SCREEN_PREVIOUS:
831                 screen_next_mode(c, -1);
832                 break;
833         case CMD_SCREEN_NEXT:
834                 screen_next_mode(c, 1);
835                 break;
836         case CMD_SCREEN_PLAY:
837                 screen_switch(&screen_playlist, c);
838                 break;
839         case CMD_SCREEN_FILE:
840                 screen_switch(&screen_browse, c);
841                 break;
842 #ifdef ENABLE_HELP_SCREEN
843         case CMD_SCREEN_HELP:
844                 screen_switch(&screen_help, c);
845                 break;
846 #endif
847 #ifdef ENABLE_SEARCH_SCREEN
848         case CMD_SCREEN_SEARCH:
849                 screen_switch(&screen_search, c);
850                 break;
851 #endif
852 #ifdef ENABLE_ARTIST_SCREEN
853         case CMD_SCREEN_ARTIST:
854                 screen_switch(&screen_artist, c);
855                 break;
856 #endif
857 #ifdef ENABLE_SONG_SCREEN
858         case CMD_SCREEN_SONG:
859                 screen_switch(&screen_song, c);
860                 break;
861 #endif
862 #ifdef ENABLE_KEYDEF_SCREEN
863         case CMD_SCREEN_KEYDEF:
864                 screen_switch(&screen_keydef, c);
865                 break;
866 #endif
867 #ifdef ENABLE_LYRICS_SCREEN
868         case CMD_SCREEN_LYRICS:
869                 screen_switch(&screen_lyrics, c);
870                 break;
871 #endif
872 #ifdef ENABLE_OUTPUTS_SCREEN
873         case CMD_SCREEN_OUTPUTS:
874                 screen_switch(&screen_outputs, c);
875                 break;
876         case CMD_SCREEN_SWAP:
877                 screen_swap(c, NULL);
878                 break;
879 #endif
881         default:
882                 break;
883         }