Code

screen_play: repaint after the "select-playing" command
[ncmpc.git] / src / screen_play.c
index 0abee2ee46f96b0be9c352bb43c9b2091e724f56..256ea36d2b9e5f03b5d593586cf4637c88e511a9 100644 (file)
@@ -56,16 +56,14 @@ typedef struct
        struct mpdclient *c;
 } completion_callback_data_t;
 
-#ifndef NCMPC_MINI
 static struct hscroll hscroll;
-#endif
-static bool must_scroll;
+static guint scroll_source_id;
 #endif
 
 static struct mpdclient_playlist *playlist;
 static int current_song_id = -1;
 static int selected_song_id = -1;
-static list_window_t *lw = NULL;
+static struct list_window *lw;
 static guint timer_hide_cursor_id;
 
 static void
@@ -119,6 +117,18 @@ playlist_restore_selection(void)
        playlist_save_selection();
 }
 
+#ifndef NCMPC_MINI
+static gboolean
+scroll_timer_callback(G_GNUC_UNUSED gpointer data)
+{
+       scroll_source_id = 0;
+
+       hscroll_step(&hscroll);
+       playlist_repaint();
+       return false;
+}
+#endif
+
 static const char *
 list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED void *data)
 {
@@ -152,8 +162,6 @@ 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) {
                                hscroll_reset(&hscroll);
                                current_song = lw->selected;
@@ -163,9 +171,20 @@ list_callback(unsigned idx, bool *highlight, char **second_column, G_GNUC_UNUSED
                                        MAX_SONG_LENGTH);
                        g_strlcpy(songname, tmp, MAX_SONG_LENGTH);
                        g_free(tmp);
-               }
-               else
+
+                       if (scroll_source_id == 0)
+                               scroll_source_id =
+                                       g_timeout_add(1000,
+                                                     scroll_timer_callback,
+                                                     NULL);
+               } else {
                        hscroll_reset(&hscroll);
+
+                       if (scroll_source_id != 0) {
+                               g_source_remove(scroll_source_id);
+                               scroll_source_id = 0;
+                       }
+               }
        }
 #else
        (void)second_column;
@@ -270,6 +289,7 @@ completion_strncmp(const gchar *s1, const gchar *s2, gsize n)
 int
 playlist_save(struct mpdclient *c, char *name, char *defaultname)
 {
+       struct mpd_connection *connection;
        gchar *filename, *filename_utf8;
 #ifndef NCMPC_MINI
        GCompletion *gcmp;
@@ -319,10 +339,11 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
 
        filename_utf8 = locale_to_utf8(filename);
 
-       if (!mpd_run_save(c->connection, filename_utf8)) {
-               if (mpd_connection_get_error(c->connection) == MPD_ERROR_SERVER &&
-                   mpd_connection_get_server_error(c->connection) == MPD_SERVER_ERROR_EXIST &&
-                   mpd_connection_clear_error(c->connection)) {
+       connection = mpdclient_get_connection(c);
+       if (!mpd_run_save(connection, filename_utf8)) {
+               if (mpd_connection_get_error(connection) == MPD_ERROR_SERVER &&
+                   mpd_connection_get_server_error(connection) == MPD_SERVER_ERROR_EXIST &&
+                   mpd_connection_clear_error(connection)) {
                        char *buf;
                        int key;
 
@@ -338,8 +359,8 @@ playlist_save(struct mpdclient *c, char *name, char *defaultname)
                                return -1;
                        }
 
-                       if (!mpd_run_rm(c->connection, filename_utf8) ||
-                           !mpd_run_save(c->connection, filename_utf8)) {
+                       if (!mpd_run_rm(connection, filename_utf8) ||
+                           !mpd_run_save(connection, filename_utf8)) {
                                mpdclient_handle_error(c);
                                g_free(filename_utf8);
                                g_free(filename);
@@ -544,10 +565,6 @@ screen_playlist_title(char *str, size_t size)
 static void
 screen_playlist_paint(void)
 {
-#ifndef NCMPC_MINI
-       must_scroll = false;
-#endif
-
        list_window_paint(lw, list_callback, NULL);
 }
 
@@ -572,12 +589,6 @@ screen_playlist_update(struct mpdclient *c)
                        center_playing_item(c, false);
 
                playlist_repaint();
-#ifndef NCMPC_MINI
-       } else if (options.scroll && must_scroll) {
-               /* always repaint if horizontal scrolling is
-                  enabled */
-               playlist_repaint();
-#endif
        } else if (c->events & MPD_IDLE_PLAYLIST) {
                /* the playlist has changed, we must paint the new
                   version */
@@ -629,6 +640,7 @@ handle_mouse_event(struct mpdclient *c)
 static bool
 screen_playlist_cmd(struct mpdclient *c, command_t cmd)
 {
+       struct mpd_connection *connection;
        static command_t cached_cmd = CMD_NONE;
        command_t prev_cmd = cached_cmd;
        cached_cmd = cmd;
@@ -657,6 +669,7 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
                list_window_set_selected(lw, playlist_get_index(&c->playlist,
                                                                c->song));
                playlist_save_selection();
+               playlist_repaint();
                return true;
 
        case CMD_LIST_FIND:
@@ -743,18 +756,17 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
                return true;
 
        case CMD_SHUFFLE:
-       {
                if(!lw->range_selection)
                        /* No range selection, shuffle all list. */
                        break;
 
-               if (mpd_run_shuffle_range(c->connection, lw->selected_start,
+               connection = mpdclient_get_connection(c);
+               if (mpd_run_shuffle_range(connection, lw->selected_start,
                                          lw->selected_end + 1))
                        screen_status_message(_("Shuffled playlist"));
                else
                        mpdclient_handle_error(c);
                return true;
-       }
 
        case CMD_LIST_MOVE_UP:
                if(lw->selected_start == 0)