X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/769be9881aa8d7212c6372e2fb10075cad551578..18f94073fa55c7d32d0e84ee0d8d033a950a77b0:/disobedience/multidrag.c diff --git a/disobedience/multidrag.c b/disobedience/multidrag.c index 95dcbb2..f4a5a76 100644 --- a/disobedience/multidrag.c +++ b/disobedience/multidrag.c @@ -76,11 +76,11 @@ static void block_selection(GtkWidget *w, gboolean block, int *where = g_object_get_data(G_OBJECT(w), "multidrag-where"); if(!where) { where = g_malloc(2 * sizeof (int)); - g_object_set_data(G_OBJECT(w), "multidrag-where", where); + g_object_set_data_full(G_OBJECT(w), "multidrag-where", where, + g_free); } where[0] = x; where[1] = y; - // TODO release 'where' when object is destroyed } static gboolean multidrag_button_press_event(GtkWidget *w, @@ -92,25 +92,27 @@ static gboolean multidrag_button_press_event(GtkWidget *w, /* We are only interested in left-button behavior */ if(event->button != 1) return FALSE; - /* We are only interested in unmodified clicks (not SHIFT etc) */ - if(event->state & GDK_MODIFIER_MASK) + /* We are only uninterested in clicks without CTRL or SHIFT. GTK ignores the + * other possible modifiers, so we do too. */ + if(event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK)) return FALSE; /* We are only interested if a well-defined path is clicked */ - GtkTreePath *path; + GtkTreePath *path = NULL; if(!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w), event->x, event->y, &path, NULL, NULL, NULL)) return FALSE; - //gtk_widget_grab_focus(w); // TODO why?? /* We are only interested if a selected row is clicked */ GtkTreeSelection *s = gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); - if(!gtk_tree_selection_path_is_selected(s, path)) - return FALSE; - /* We block subsequent selection changes and remember where the - * click was */ - block_selection(w, FALSE, event->x, event->y); + if(gtk_tree_selection_path_is_selected(s, path)) { + /* We block subsequent selection changes and remember where the + * click was */ + block_selection(w, FALSE, event->x, event->y); + } + if(path) + gtk_tree_path_free(path); return FALSE; /* propagate */ } @@ -129,7 +131,7 @@ static gboolean multidrag_button_release_event(GtkWidget *w, if(x == event->x && y == event->y) { // If the up-click is at the same location as the down-click, // it's not a drag. - GtkTreePath *path; + GtkTreePath *path = NULL; GtkTreeViewColumn *col; if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w), event->x, event->y, @@ -138,6 +140,8 @@ static gboolean multidrag_button_release_event(GtkWidget *w, NULL, NULL)) { gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, col, FALSE); } + if(path) + gtk_tree_path_free(path); } } return FALSE; /* propagate */