From a9970c455f528b67d82b652d5af836f01537159d Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 20 Apr 2018 09:08:26 -0400 Subject: [PATCH] gui/sidebar: Add a function for getting an iter from x, y coordinates This will be used for drag and drop, so that we can figure out what playlist tracks are being added to. Signed-off-by: Anna Schumaker --- gui/sidebar.c | 16 ++++++++++++++++ include/gui/sidebar.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/gui/sidebar.c b/gui/sidebar.c index 3256c0e0..8aa8add8 100644 --- a/gui/sidebar.c +++ b/gui/sidebar.c @@ -486,3 +486,19 @@ gboolean gui_sidebar_iter_from_string(const gchar *path, GtkTreeIter *child) __gui_sidebar_filter_iter_convert(&iter, child); return TRUE; } + +gboolean gui_sidebar_iter_from_xy(gint x, gint y, GtkTreeIter *child) +{ + GtkTreeModel *model = GTK_TREE_MODEL(gui_sidebar_filter()); + GtkTreePath *path; + GtkTreeIter iter; + + if (!gtk_tree_view_get_path_at_pos(gui_sidebar_treeview(), x, y, + &path, NULL, NULL, NULL)) + return false; + + gtk_tree_model_get_iter(model, &iter, path); + __gui_sidebar_filter_iter_convert(&iter, child); + gtk_tree_path_free(path); + return true; +} diff --git a/include/gui/sidebar.h b/include/gui/sidebar.h index a5732161..2dcfa3e5 100644 --- a/include/gui/sidebar.h +++ b/include/gui/sidebar.h @@ -76,6 +76,9 @@ gboolean gui_sidebar_iter_find(GtkTreeIter *, const gchar *, /* Called to set the a GtkTreeIter to the row at path string */ gboolean gui_sidebar_iter_from_string(const gchar *, GtkTreeIter *); +/* Called to set the GtkTreeIter to the row at (x, y) */ +gboolean gui_sidebar_iter_from_xy(gint, gint, GtkTreeIter *); + /* Called to get the sidebar widget. */ static inline GtkPaned *gui_sidebar() {