From f50c1541a120319f2c6481b8923b32657eb35554 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 8 Jun 2016 08:20:21 -0400 Subject: [PATCH] gui/view: Scrolling improvements This patch fixes two issues. First, I disable scrolling when the user has manually selected a track. I've found that extra scrolling in this case can be disorienting, and frequently ends up with the wrong track selected due to how queue iterators are set so it's probably best just to disable scrolling in this case. This patch also changes the order of calls to set_cursor() and scroll_to_cell(). I've found that scrolling before setting the cursor causes the GtkTreeView to ignore alignment settings unless the row is already on the screen. Switching the order makes everything work properly. Fixes #57: Wrong track is sometimes scrolled to Signed-off-by: Anna Schumaker --- CHANGELOG | 1 + gui/view.c | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 8187e0c5..9184939f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,7 @@ - Enable GtkTreeView fixed-height mode - Fix bug where temporary queues don't save - Fix bug where a queue is not selected on startup +- Fix bugs related to scrolling on track change 6.4.13-rc: - Rewrite GtkTreeView code diff --git a/gui/view.c b/gui/view.c index 947465e5..64364ed0 100644 --- a/gui/view.c +++ b/gui/view.c @@ -41,6 +41,7 @@ static const enum compare_t QUEUE_SORT[Q_MODEL_N_COLUMNS] = { static GtkTreeView *view_treeview = NULL; static GtkTreeModelFilter *view_filter = NULL; static unsigned int view_sort_count = 0; +static bool view_no_scroll = false; static inline GuiQueueModel *__view_filter_get_model() { @@ -147,9 +148,11 @@ static void __view_set_sort_indicators() void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) { + view_no_scroll = true; audio_load(__view_filter_get_track(path)); queue_selected(__view_filter_get_model()->gqm_queue, gtk_tree_path_get_indices(path)[0]); + view_no_scroll = false; } void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec, @@ -351,18 +354,17 @@ void gui_view_scroll() struct queue *queue = __view_filter_get_queue(); GtkTreePath *real, *path; - if (!queue || (int)queue->q_cur.it_pos < 0) + if (!queue || (int)queue->q_cur.it_pos < 0 || view_no_scroll) return; real = gtk_tree_path_new_from_indices(queue->q_cur.it_pos, -1); path = gtk_tree_model_filter_convert_child_path_to_path(view_filter, real); + if (!path) + goto out; - if (path) { - gtk_tree_view_scroll_to_cell(view_treeview, path, - NULL, TRUE, 0.5, 0.5); - gtk_tree_view_set_cursor(view_treeview, path, NULL, false); - gtk_tree_path_free(path); - } - + gtk_tree_view_set_cursor(view_treeview, path, NULL, false); + gtk_tree_view_scroll_to_cell(view_treeview, path, NULL, TRUE, 0.5, 0.5); + gtk_tree_path_free(path); +out: gtk_tree_path_free(real); }