Code

disable more features with --enable-mini
[ncmpc.git] / src / screen.c
index 3395255233ae9d4f3c7484448a18d8ab208f50ff..17641df997a2bfb5fc3efdebd16d431c30e8884c 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id$
- *
  * (c) 2004 by Kalle Wallin <kaw@linux.se>
  *
  * This program is free software; you can redistribute it and/or modify
  */
 
 #include "screen.h"
+#include "screen_list.h"
 #include "screen_utils.h"
 #include "config.h"
-#include "ncmpc.h"
+#include "i18n.h"
 #include "support.h"
+#include "charset.h"
 #include "mpdclient.h"
 #include "utils.h"
-#include "command.h"
 #include "options.h"
 #include "colors.h"
 #include "strfsong.h"
-#include "wreadln.h"
 
 #include <stdlib.h>
 #include <unistd.h>
 #include <time.h>
 #include <locale.h>
 
-#define SCREEN_PLAYLIST_ID     0
-#define SCREEN_BROWSE_ID       1
-#define SCREEN_ARTIST_ID       2
-#define SCREEN_HELP_ID         100
-#define SCREEN_KEYDEF_ID       101
-#define SCREEN_CLOCK_ID        102
-#define SCREEN_SEARCH_ID       103
-#define SCREEN_LYRICS_ID          104
+#ifndef NCMPC_MINI
+/** welcome message time [s] */
+static const GTime SCREEN_WELCOME_TIME = 10;
+#endif
 
+/** status message time [s] */
+static const GTime SCREEN_STATUS_MESSAGE_TIME = 3;
 
+/* minumum window size */
+static const int SCREEN_MIN_COLS = 14;
+static const int SCREEN_MIN_ROWS = 5;
 
 /* screens */
-extern const struct screen_functions screen_playlist;
-extern const struct screen_functions screen_browse;
-#ifdef ENABLE_ARTIST_SCREEN
-extern const struct screen_functions screen_artist;
-#endif
-extern const struct screen_functions screen_help;
-#ifdef ENABLE_SEARCH_SCREEN
-extern const struct screen_functions screen_search;
-#endif
-#ifdef ENABLE_KEYDEF_SCREEN
-extern const struct screen_functions screen_keydef;
-#endif
-#ifdef ENABLE_CLOCK_SCREEN
-extern const struct screen_functions screen_clock;
-#endif
-extern const struct screen_functions screen_lyrics;
-
-typedef struct screen_functions * (*screen_get_mode_functions_fn_t) (void);
 
-static const struct
-{
-       gint id;
-       const gchar *name;
-       const struct screen_functions *functions;
-} screens[] = {
-       { SCREEN_PLAYLIST_ID, "playlist", &screen_playlist },
-       { SCREEN_BROWSE_ID, "browse", &screen_browse },
-#ifdef ENABLE_ARTIST_SCREEN
-       { SCREEN_ARTIST_ID, "artist", &screen_artist },
-#endif
-       { SCREEN_HELP_ID, "help", &screen_help },
-#ifdef ENABLE_SEARCH_SCREEN
-       { SCREEN_SEARCH_ID, "search", &screen_search },
-#endif
-#ifdef ENABLE_KEYDEF_SCREEN
-       { SCREEN_KEYDEF_ID, "keydef", &screen_keydef },
-#endif
-#ifdef ENABLE_CLOCK_SCREEN
-       { SCREEN_CLOCK_ID, "clock", &screen_clock },
-#endif
-#ifdef ENABLE_LYRICS_SCREEN
-       { SCREEN_LYRICS_ID, "lyrics", &screen_lyrics },
+#ifndef NCMPC_MINI
+static gboolean welcome = TRUE;
 #endif
-       { G_MAXINT, NULL, NULL }
-};
 
-static gboolean welcome = TRUE;
-static struct screen screen;
+struct screen screen;
 static const struct screen_functions *mode_fn = &screen_playlist;
 static int seek_id = -1;
 static int seek_target_time = 0;
 
-gint
-screen_get_id(const char *name)
+gboolean
+screen_is_visible(const struct screen_functions *sf)
 {
-       gint i=0;
-
-       while (screens[i].name) {
-               if (strcmp(name, screens[i].name) == 0)
-                       return screens[i].id;
-               i++;
-       }
-       return -1;
+       return sf == mode_fn;
 }
 
-static gint
-lookup_mode(gint id)
-{
-       gint i=0;
-
-       while (screens[i].name) {
-               if (screens[i].id == id)
-                       return i;
-               i++;
-       }
-       return -1;
-}
-
-gint get_cur_mode_id(void)
-{
-       return screens[screen.mode].id;
-}
-
-static void
-switch_screen_mode(gint id, mpdclient_t *c)
+void
+screen_switch(const struct screen_functions *sf, struct mpdclient *c)
 {
-       gint new_mode;
+       assert(sf != NULL);
 
-       if( id == screens[screen.mode].id )
+       if (sf == mode_fn)
                return;
 
        /* close the old mode */
@@ -146,18 +78,13 @@ switch_screen_mode(gint id, mpdclient_t *c)
                mode_fn->close();
 
        /* get functions for the new mode */
-       new_mode = lookup_mode(id);
-       if (new_mode >= 0 && screens[new_mode].functions) {
-               D("switch_screen(%s)\n", screens[new_mode].name );
-               mode_fn = screens[new_mode].functions;
-               screen.mode = new_mode;
-       }
-
-       screen.painted = 0;
+       mode_fn = sf;
 
        /* open the new mode */
        if (mode_fn->open != NULL)
-               mode_fn->open(&screen, c);
+               mode_fn->open(c);
+
+       screen_paint(c);
 }
 
 static int
@@ -177,17 +104,19 @@ screen_next_mode(mpdclient_t *c, int offset)
 {
        int max = g_strv_length(options.screen_list);
        int current, next;
+       const struct screen_functions *sf;
 
        /* find current screen */
-       current = find_configured_screen(screens[screen.mode].name);
+       current = find_configured_screen(screen_get_name(mode_fn));
        next = current + offset;
        if (next<0)
                next = max-1;
        else if (next>=max)
                next = 0;
 
-       D("current mode: %d:%d    next:%d\n", current, max, next);
-       switch_screen_mode(screen_get_id(options.screen_list[next]), c);
+       sf = screen_lookup_name(options.screen_list[next]);
+       if (sf != NULL)
+               screen_switch(sf, c);
 }
 
 static void
@@ -200,6 +129,7 @@ paint_top_window2(const char *header, mpdclient_t *c)
        if (header[0]) {
                colors_use(w, COLOR_TITLE_BOLD);
                mvwaddstr(w, 0, 0, header);
+#ifndef NCMPC_MINI
        } else {
                colors_use(w, COLOR_TITLE_BOLD);
                waddstr(w, get_key_names(CMD_SCREEN_HELP, FALSE));
@@ -230,25 +160,30 @@ paint_top_window2(const char *header, mpdclient_t *c)
                waddstr(w, get_key_names(CMD_SCREEN_LYRICS, FALSE));
                colors_use(w, COLOR_TITLE);
                waddstr(w, _(":Lyrics  "));
+#endif
 #endif
        }
-       if (c->status->volume==MPD_STATUS_NO_VOLUME) {
+
+       if (c->status == NULL || c->status->volume == MPD_STATUS_NO_VOLUME) {
                g_snprintf(buf, 32, _("Volume n/a "));
        } else {
                g_snprintf(buf, 32, _(" Volume %d%%"), c->status->volume);
        }
        colors_use(w, COLOR_TITLE);
-       mvwaddstr(w, 0, screen.top_window.cols-my_strlen(buf), buf);
+       mvwaddstr(w, 0, screen.top_window.cols - utf8_width(buf), buf);
 
        flags[0] = 0;
-       if( c->status->repeat )
-               g_strlcat(flags, "r", sizeof(flags));
-       if( c->status->random )
-               g_strlcat(flags, "z", sizeof(flags));;
-       if( c->status->crossfade )
-               g_strlcat(flags, "x", sizeof(flags));
-       if( c->status->updatingDb )
-               g_strlcat(flags, "U", sizeof(flags));
+       if (c->status != NULL) {
+               if (c->status->repeat)
+                       g_strlcat(flags, "r", sizeof(flags));
+               if (c->status->random)
+                       g_strlcat(flags, "z", sizeof(flags));;
+               if (c->status->crossfade)
+                       g_strlcat(flags, "x", sizeof(flags));
+               if (c->status->updatingDb)
+                       g_strlcat(flags, "U", sizeof(flags));
+       }
+
        colors_use(w, COLOR_LINE);
        mvwhline(w, 1, 0, ACS_HLINE, screen.top_window.cols);
        if (flags[0]) {
@@ -266,11 +201,11 @@ static void
 paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
 {
        static int prev_volume = -1;
-       static size_t prev_header_len = -1;
+       static unsigned prev_header_len = -1;
        WINDOW *w = screen.top_window.w;
 
-       if (prev_header_len!=my_strlen(header)) {
-               prev_header_len = my_strlen(header);
+       if (prev_header_len != utf8_width(header)) {
+               prev_header_len = utf8_width(header);
                full_repaint = 1;
        }
 
@@ -279,7 +214,8 @@ paint_top_window(const char *header, mpdclient_t *c, int full_repaint)
                wclrtoeol(w);
        }
 
-       if (prev_volume!=c->status->volume || full_repaint)
+       if ((c->status != NULL && prev_volume != c->status->volume) ||
+           full_repaint)
                paint_top_window2(header, c);
 }
 
@@ -288,7 +224,7 @@ paint_progress_window(mpdclient_t *c)
 {
        double p;
        int width;
-       int elapsedTime = c->status->elapsedTime;
+       int elapsedTime;
 
        if (c->status==NULL || IS_STOPPED(c->status->state)) {
                mvwhline(screen.progress_window.w, 0, 0, ACS_HLINE,
@@ -299,6 +235,8 @@ paint_progress_window(mpdclient_t *c)
 
        if (c->song && seek_id == c->song->id)
                elapsedTime = seek_target_time;
+       else
+               elapsedTime = c->status->elapsedTime;
 
        p = ((double) elapsedTime) / ((double) c->status->totalTime);
 
@@ -319,6 +257,11 @@ paint_status_window(mpdclient_t *c)
        mpd_Status *status = c->status;
        mpd_Song *song = c->song;
        int elapsedTime = 0;
+#ifdef NCMPC_MINI
+       static char bitrate[1];
+#else
+       char bitrate[16];
+#endif
        const char *str = NULL;
        int x = 0;
 
@@ -329,7 +272,7 @@ paint_status_window(mpdclient_t *c)
        wclrtoeol(w);
        colors_use(w, COLOR_STATUS_BOLD);
 
-       switch(status->state) {
+       switch (status == NULL ? MPD_STATUS_STATE_STOP : status->state) {
        case MPD_STATUS_STATE_PLAY:
                str = _("Playing:");
                break;
@@ -343,12 +286,13 @@ paint_status_window(mpdclient_t *c)
 
        if (str) {
                waddstr(w, str);
-               x += my_strlen(str)+1;
+               x += utf8_width(str) + 1;
        }
 
        /* create time string */
        memset(screen.buf, 0, screen.buf_size);
-       if (IS_PLAYING(status->state) || IS_PAUSED(status->state)) {
+       if (status != NULL && (IS_PLAYING(status->state) ||
+                              IS_PAUSED(status->state))) {
                if (status->totalTime > 0) {
                        /*checks the conf to see whether to display elapsed or remaining time */
                        if(!strcmp(options.timedisplay_type,"elapsed"))
@@ -358,48 +302,69 @@ paint_status_window(mpdclient_t *c)
 
                        if( c->song && seek_id == c->song->id )
                                elapsedTime = seek_target_time;
+
+                       /* display bitrate if visible-bitrate is true */
+#ifndef NCMPC_MINI
+                       if (options.visible_bitrate) {
+                               g_snprintf(bitrate, 16,
+                                          " [%d kbps]", status->bitRate);
+                       } else {
+                               bitrate[0] = '\0';
+                       }
+#endif
+
                        /*write out the time, using hours if time over 60 minutes*/
                        if (c->status->totalTime > 3600) {
                                g_snprintf(screen.buf, screen.buf_size,
-                                          " [%i:%02i:%02i/%i:%02i:%02i]",
-                                          elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
+                                          "%s [%i:%02i:%02i/%i:%02i:%02i]",
+                                          bitrate, elapsedTime/3600, (elapsedTime%3600)/60, elapsedTime%60,
                                           status->totalTime/3600, (status->totalTime%3600)/60,  status->totalTime%60);
                        } else {
                                g_snprintf(screen.buf, screen.buf_size,
-                                          " [%i:%02i/%i:%02i]",
-                                          elapsedTime/60, elapsedTime%60,
+                                          "%s [%i:%02i/%i:%02i]",
+                                          bitrate, elapsedTime/60, elapsedTime%60,
                                           status->totalTime/60,   status->totalTime%60 );
                        }
+#ifndef NCMPC_MINI
                } else {
                        g_snprintf(screen.buf, screen.buf_size,
                                   " [%d kbps]", status->bitRate );
+#endif
                }
+#ifndef NCMPC_MINI
        } else {
                time_t timep;
 
                time(&timep);
                strftime(screen.buf, screen.buf_size, "%X ",localtime(&timep));
+#endif
        }
 
        /* display song */
-       if (IS_PLAYING(status->state) || IS_PAUSED(status->state)) {
+       if (status != NULL && (IS_PLAYING(status->state) ||
+                              IS_PAUSED(status->state))) {
                char songname[MAX_SONGNAME_LENGTH];
-               int width = COLS-x-my_strlen(screen.buf);
+#ifndef NCMPC_MINI
+               int width = COLS - x - utf8_width(screen.buf);
+#endif
 
                if (song)
-                       strfsong(songname, MAX_SONGNAME_LENGTH, STATUS_FORMAT, song);
+                       strfsong(songname, MAX_SONGNAME_LENGTH,
+                                options.status_format, song);
                else
                        songname[0] = '\0';
 
                colors_use(w, COLOR_STATUS);
                /* scroll if the song name is to long */
-               if (options.scroll && my_strlen(songname) > (size_t)width) {
+#ifndef NCMPC_MINI
+               if (options.scroll && utf8_width(songname) > (unsigned)width) {
                        static  scroll_state_t st = { 0, 0 };
                        char *tmp = strscroll(songname, options.scroll_sep, width, &st);
 
                        g_strlcpy(songname, tmp, MAX_SONGNAME_LENGTH);
                        g_free(tmp);
                }
+#endif
                //mvwaddnstr(w, 0, x, songname, width);
                mvwaddstr(w, 0, x, songname);
        }
@@ -414,40 +379,22 @@ paint_status_window(mpdclient_t *c)
        wnoutrefresh(w);
 }
 
-int
+void
 screen_exit(void)
 {
-       gint i;
-
-       endwin();
-
        if (mode_fn->close != NULL)
                mode_fn->close();
 
-       /* close and exit all screens (playlist,browse,help...) */
-       i=0;
-       while (screens[i].functions) {
-               const struct screen_functions *sf = screens[i].functions;
-
-               if (sf->exit)
-                       sf->exit();
-
-               i++;
-       }
+       screen_list_exit();
 
        string_list_free(screen.find_history);
        g_free(screen.buf);
        g_free(screen.findbuf);
-
-       return 0;
 }
 
 void
-screen_resize(void)
+screen_resize(struct mpdclient *c)
 {
-       gint i;
-
-       D("Resize rows %d->%d, cols %d->%d\n",screen.rows,LINES,screen.cols,COLS);
        if (COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS) {
                screen_exit();
                fprintf(stderr, _("Error: Screen to small!\n"));
@@ -483,22 +430,14 @@ screen_resize(void)
        g_free(screen.buf);
        screen.buf = g_malloc(screen.cols);
 
-       /* close and exit all screens (playlist,browse,help...) */
-       i=0;
-       while (screens[i].functions) {
-               const struct screen_functions *sf = screens[i].functions;
-
-               if (sf->resize)
-                       sf->resize(screen.main_window.cols, screen.main_window.rows);
-
-               i++;
-       }
+       /* resize all screens */
+       screen_list_resize(screen.main_window.cols, screen.main_window.rows);
 
        /* ? - without this the cursor becomes visible with aterm & Eterm */
        curs_set(1);
        curs_set(0);
 
-       screen.painted = 0;
+       screen_paint(c);
 }
 
 void
@@ -528,48 +467,20 @@ screen_status_printf(const char *format, ...)
 }
 
 void
-ncurses_init(void)
+screen_init(mpdclient_t *c)
 {
+       if (COLS < SCREEN_MIN_COLS || LINES < SCREEN_MIN_ROWS) {
+               fprintf(stderr, _("Error: Screen to small!\n"));
+               exit(EXIT_FAILURE);
+       }
 
-       /* initialize the curses library */
-       initscr();
-       /* initialize color support */
-       colors_start();
-       /* tell curses not to do NL->CR/NL on output */
-       nonl();
-       /*  use raw mode (ignore interrupt,quit,suspend, and flow control ) */
-#ifdef ENABLE_RAW_MODE
-       //  raw();
-#endif
-       /* don't echo input */
-       noecho();
-       /* set cursor invisible */
-       curs_set(0);
-       /* enable extra keys */
-       keypad(stdscr, TRUE);
-       /* return from getch() without blocking */
-       timeout(SCREEN_TIMEOUT);
-       /* initialize mouse support */
-#ifdef HAVE_GETMOUSE
-       if( options.enable_mouse )
-               mousemask(ALL_MOUSE_EVENTS, NULL);
-#endif
-
-       if( COLS<SCREEN_MIN_COLS || LINES<SCREEN_MIN_ROWS )
-               {
-                       fprintf(stderr, _("Error: Screen to small!\n"));
-                       exit(EXIT_FAILURE);
-               }
-       screen.mode = 0;
        screen.cols = COLS;
        screen.rows = LINES;
 
        screen.buf  = g_malloc(screen.cols);
        screen.buf_size = screen.cols;
        screen.findbuf = NULL;
-       screen.painted = 0;
        screen.start_timestamp = time(NULL);
-       screen.input_timestamp = time(NULL);
        screen.last_cmd = CMD_NONE;
 
        /* create top window */
@@ -612,46 +523,26 @@ ncurses_init(void)
        leaveok(screen.status_window.w, FALSE);
        keypad(screen.status_window.w, TRUE);
 
-       if( options.enable_colors )
-               {
-                       /* set background attributes */
-                       wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
-                       wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
-                       wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
-                       wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
-                       wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
-                       colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
-               }
+#ifdef ENABLE_COLORS
+       if (options.enable_colors) {
+               /* set background attributes */
+               wbkgd(stdscr, COLOR_PAIR(COLOR_LIST));
+               wbkgd(screen.main_window.w,     COLOR_PAIR(COLOR_LIST));
+               wbkgd(screen.top_window.w,      COLOR_PAIR(COLOR_TITLE));
+               wbkgd(screen.progress_window.w, COLOR_PAIR(COLOR_PROGRESSBAR));
+               wbkgd(screen.status_window.w,   COLOR_PAIR(COLOR_STATUS));
+               colors_use(screen.progress_window.w, COLOR_PROGRESSBAR);
+       }
+#endif
 
        refresh();
-}
-
-int
-screen_init(mpdclient_t *c)
-{
-       gint i;
 
        /* initialize screens */
-       i=0;
-       while (screens[i].functions) {
-               const struct screen_functions *fn = screens[i].functions;
-
-               if (fn->init)
-                       fn->init(screen.main_window.w,
-                                screen.main_window.cols,
-                                screen.main_window.rows);
-
-               i++;
-       }
+       screen_list_init(screen.main_window.w,
+                        screen.main_window.cols, screen.main_window.rows);
 
        if (mode_fn->open != NULL)
-               mode_fn->open(&screen, c);
-
-       /* initialize wreadln */
-       wrln_wgetch = my_wgetch;
-       wrln_max_history_length = 16;
-
-       return 0;
+               mode_fn->open(c);
 }
 
 void
@@ -662,7 +553,6 @@ screen_paint(mpdclient_t *c)
        if (mode_fn->get_title != NULL)
                title = mode_fn->get_title(screen.buf, screen.buf_size);
 
-       D("screen_paint(%s)\n", title);
        /* paint the title/header window */
        if( title )
                paint_top_window(title, c, 1);
@@ -672,11 +562,10 @@ screen_paint(mpdclient_t *c)
        /* paint the main window */
        wclear(screen.main_window.w);
        if (mode_fn->paint != NULL)
-               mode_fn->paint(&screen, c);
+               mode_fn->paint();
 
        paint_progress_window(c);
        paint_status_window(c);
-       screen.painted = 1;
        wmove(screen.main_window.w, 0, 0);
        wnoutrefresh(screen.main_window.w);
 
@@ -687,58 +576,63 @@ screen_paint(mpdclient_t *c)
 void
 screen_update(mpdclient_t *c)
 {
+#ifndef NCMPC_MINI
        static int repeat = -1;
        static int random_enabled = -1;
        static int crossfade = -1;
        static int dbupdate = -1;
 
-       if( !screen.painted )
-               return screen_paint(c);
-
        /* print a message if mpd status has changed */
-       if (repeat < 0) {
-               repeat = c->status->repeat;
-               random_enabled = c->status->random;
-               crossfade = c->status->crossfade;
-               dbupdate = c->status->updatingDb;
-       }
+       if (c->status != NULL) {
+               if (repeat < 0) {
+                       repeat = c->status->repeat;
+                       random_enabled = c->status->random;
+                       crossfade = c->status->crossfade;
+                       dbupdate = c->status->updatingDb;
+               }
 
-       if (repeat != c->status->repeat)
-               screen_status_printf(c->status->repeat ?
-                                    _("Repeat is on") :
-                                    _("Repeat is off"));
+               if (repeat != c->status->repeat)
+                       screen_status_printf(c->status->repeat ?
+                                            _("Repeat is on") :
+                                            _("Repeat is off"));
 
-       if (random_enabled != c->status->random)
-               screen_status_printf(c->status->random ?
-                                    _("Random is on") :
-                                    _("Random is off"));
+               if (random_enabled != c->status->random)
+                       screen_status_printf(c->status->random ?
+                                            _("Random is on") :
+                                            _("Random is off"));
 
-       if (crossfade != c->status->crossfade)
-               screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
+               if (crossfade != c->status->crossfade)
+                       screen_status_printf(_("Crossfade %d seconds"), c->status->crossfade);
 
-       if (dbupdate && dbupdate != c->status->updatingDb) {
-               screen_status_printf(_("Database updated!"));
-               mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
-       }
+               if (dbupdate && dbupdate != c->status->updatingDb) {
+                       screen_status_printf(_("Database updated!"));
+                       mpdclient_browse_callback(c, BROWSE_DB_UPDATED, NULL);
+               }
 
-       repeat = c->status->repeat;
-       random_enabled = c->status->random;
-       crossfade = c->status->crossfade;
-       dbupdate = c->status->updatingDb;
+               repeat = c->status->repeat;
+               random_enabled = c->status->random;
+               crossfade = c->status->crossfade;
+               dbupdate = c->status->updatingDb;
+       }
 
        /* update title/header window */
-       if (welcome && screen.last_cmd==CMD_NONE &&
+       if (welcome && options.welcome_screen_list &&
+           screen.last_cmd==CMD_NONE &&
            time(NULL)-screen.start_timestamp <= SCREEN_WELCOME_TIME)
                paint_top_window("", c, 0);
-       else if (mode_fn->get_title != NULL) {
+       else
+#endif
+       if (mode_fn->get_title != NULL) {
                paint_top_window(mode_fn->get_title(screen.buf,screen.buf_size), c, 0);
+#ifndef NCMPC_MINI
                welcome = FALSE;
+#endif
        } else
                paint_top_window("", c, 0);
 
        /* update the main window */
        if (mode_fn->update != NULL)
-               mode_fn->update(&screen, c);
+               mode_fn->update(c);
 
        /* update progress window */
        paint_progress_window(c);
@@ -768,15 +662,12 @@ screen_idle(mpdclient_t *c)
 
 #ifdef HAVE_GETMOUSE
 int
-screen_get_mouse_event(mpdclient_t *c,
-                      list_window_t *lw, int lw_length,
-                      unsigned long *bstate, int *row)
+screen_get_mouse_event(mpdclient_t *c, unsigned long *bstate, int *row)
 {
        MEVENT event;
 
        /* retreive the mouse event from ncurses */
        getmouse(&event);
-       D("mouse: id=%d  y=%d,x=%d,z=%d\n",event.id,event.y,event.x,event.z);
        /* calculate the selected row in the list window */
        *row = event.y - screen.top_window.rows;
        /* copy button state bits */
@@ -787,48 +678,31 @@ screen_get_mouse_event(mpdclient_t *c,
                return 1;
        }
 
-       /* if the even occured above the list window move up */
-       if (*row < 0 && lw) {
-               if (event.bstate & BUTTON3_CLICKED)
-                       list_window_first(lw);
-               else
-                       list_window_previous_page(lw);
-               return 1;
-       }
-
-       /* if the even occured below the list window move down */
-       if ((unsigned)*row >= lw->rows && lw) {
-               if (event.bstate & BUTTON3_CLICKED)
-                       list_window_last(lw, lw_length);
-               else
-                       list_window_next_page(lw, lw_length);
-               return 1;
-       }
-
        return 0;
 }
 #endif
 
-void
-screen_cmd(mpdclient_t *c, command_t cmd)
+static int
+screen_client_cmd(mpdclient_t *c, command_t cmd)
 {
-       screen.input_timestamp = time(NULL);
-       screen.last_cmd = cmd;
-       welcome = FALSE;
-
-       if (mode_fn->cmd != NULL && mode_fn->cmd(&screen, c, cmd))
-               return;
+       if (c->connection == NULL || c->status == NULL)
+               return 0;
 
        switch(cmd) {
+               /*
        case CMD_PLAY:
                mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
                break;
+               */
        case CMD_PAUSE:
                mpdclient_cmd_pause(c, !IS_PAUSED(c->status->state));
                break;
        case CMD_STOP:
                mpdclient_cmd_stop(c);
                break;
+       case CMD_CROP:
+               mpdclient_cmd_crop(c);
+               break;
        case CMD_SEEK_FORWARD:
                if (!IS_STOPPED(c->status->state)) {
                        if (c->song && seek_id != c->song->id) {
@@ -897,6 +771,29 @@ screen_cmd(mpdclient_t *c, command_t cmd)
                if( c->status->volume!=MPD_STATUS_NO_VOLUME && c->status->volume>0 )
                        mpdclient_cmd_volume(c, --c->status->volume);
                break;
+
+       default:
+               return 0;
+       }
+
+       return 1;
+}
+
+void
+screen_cmd(mpdclient_t *c, command_t cmd)
+{
+       screen.last_cmd = cmd;
+#ifndef NCMPC_MINI
+       welcome = FALSE;
+#endif
+
+       if (mode_fn->cmd != NULL && mode_fn->cmd(c, cmd))
+               return;
+
+       if (screen_client_cmd(c, cmd))
+               return;
+
+       switch(cmd) {
        case CMD_TOGGLE_FIND_WRAP:
                options.find_wrap = !options.find_wrap;
                screen_status_printf(options.find_wrap ?
@@ -910,7 +807,7 @@ screen_cmd(mpdclient_t *c, command_t cmd)
                                     _("Auto center mode: Off"));
                break;
        case CMD_SCREEN_UPDATE:
-               screen.painted = 0;
+               screen_paint(c);
                break;
        case CMD_SCREEN_PREVIOUS:
                screen_next_mode(c, -1);
@@ -919,31 +816,36 @@ screen_cmd(mpdclient_t *c, command_t cmd)
                screen_next_mode(c, 1);
                break;
        case CMD_SCREEN_PLAY:
-               switch_screen_mode(SCREEN_PLAYLIST_ID, c);
+               screen_switch(&screen_playlist, c);
                break;
        case CMD_SCREEN_FILE:
-               switch_screen_mode(SCREEN_BROWSE_ID, c);
+               screen_switch(&screen_browse, c);
                break;
+#ifdef ENABLE_HELP_SCREEN
        case CMD_SCREEN_HELP:
-               switch_screen_mode(SCREEN_HELP_ID, c);
+               screen_switch(&screen_help, c);
                break;
+#endif
+#ifdef ENABLE_SEARCH_SCREEN
        case CMD_SCREEN_SEARCH:
-               switch_screen_mode(SCREEN_SEARCH_ID, c);
+               screen_switch(&screen_search, c);
                break;
+#endif
+#ifdef ENABLE_ARTIST_SCREEN
        case CMD_SCREEN_ARTIST:
-               switch_screen_mode(SCREEN_ARTIST_ID, c);
+               screen_switch(&screen_artist, c);
                break;
+#endif
+#ifdef ENABLE_KEYDEF_SCREEN
        case CMD_SCREEN_KEYDEF:
-               switch_screen_mode(SCREEN_KEYDEF_ID, c);
-               break;
-       case CMD_SCREEN_CLOCK:
-               switch_screen_mode(SCREEN_CLOCK_ID, c);
+               screen_switch(&screen_keydef, c);
                break;
+#endif
+#ifdef ENABLE_LYRICS_SCREEN
        case CMD_SCREEN_LYRICS:
-               switch_screen_mode(SCREEN_LYRICS_ID, c);
+               screen_switch(&screen_lyrics, c);
                break;
-       case CMD_QUIT:
-               exit(EXIT_SUCCESS);
+#endif
        default:
                break;
        }