Code

screen_play: repaint hscrolling only if selected item is wide
authorMax Kellermann <max@duempel.org>
Mon, 28 Sep 2009 16:21:54 +0000 (18:21 +0200)
committerMax Kellermann <max@duempel.org>
Mon, 28 Sep 2009 16:21:54 +0000 (18:21 +0200)
When the "scroll" option is active, ncmpc repainted the whole screen
with each tick, even if the selected item is not wider than the
screen.  This wasted a lot of CPU cycles.

src/screen_play.c

index fb5e82b1d3dddad4f48471dcc8e819a636bda7a9..ed17499164d0f5bca8a4636e5372129127ab4d8d 100644 (file)
@@ -52,6 +52,8 @@ typedef struct
        GList **dir_list;
        struct mpdclient *c;
 } completion_callback_data_t;
+
+static bool must_scroll;
 #endif
 
 static struct mpdclient_playlist *playlist;
@@ -141,6 +143,8 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
                        static unsigned current_song;
                        char *tmp;
 
+                       must_scroll = true;
+
                        if (current_song != lw->selected) {
                                st.offset = 0;
                                current_song = lw->selected;
@@ -537,6 +541,10 @@ play_title(char *str, size_t size)
 static void
 play_paint(void)
 {
+#ifndef NCMPC_MINI
+       must_scroll = false;
+#endif
+
        list_window_paint(lw, list_callback, NULL);
 }
 
@@ -558,7 +566,7 @@ play_update(struct mpdclient *c)
 
                playlist_repaint();
 #ifndef NCMPC_MINI
-       } else if (options.scroll) {
+       } else if (options.scroll && must_scroll) {
                /* always repaint if horizontal scrolling is
                   enabled */
                playlist_repaint();