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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-06-08 08:20:21 -04:00
parent dfb023a0fc
commit f50c1541a1
2 changed files with 11 additions and 8 deletions

View File

@ -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

View File

@ -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);
}