From 0abad1f1c80945ca9301cf721a19ad9c6a80099d Mon Sep 17 00:00:00 2001 From: Scoopta Date: Thu, 6 Feb 2020 21:47:59 -0800 Subject: [PATCH] Fixed ordering when no search is input --- src/wofi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wofi.c b/src/wofi.c index 79399aa..70e1138 100644 --- a/src/wofi.c +++ b/src/wofi.c @@ -65,6 +65,7 @@ static enum locations location; static bool no_actions; static uint64_t columns; static bool is_first = true; +static uint64_t widget_count = 0; struct mode { void (*mode_exec)(const gchar* cmd); @@ -298,6 +299,10 @@ static GtkWidget* create_label(char* mode, char* text, char* search_text, char* gtk_style_context_add_class(style, "entry"); wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "mode", mode); wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "action", action); + char index[6]; + snprintf(index, sizeof(index), "%lu", ++widget_count); + wofi_property_box_add_property(WOFI_PROPERTY_BOX(box), "index", index); + if(allow_images) { parse_images(WOFI_PROPERTY_BOX(box), text, true); } else { @@ -835,11 +840,13 @@ static gint do_sort(GtkFlowBoxChild* child1, GtkFlowBoxChild* child2, gpointer d const gchar* text1 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "filter"); const gchar* text2 = wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "filter"); + uint64_t index1 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box1), "index"), NULL, 10); + uint64_t index2 = strtol(wofi_property_box_get_property(WOFI_PROPERTY_BOX(box2), "index"), NULL, 10); if(filter == NULL || strcmp(filter, "") == 0) { - return 0; + return index1 - index2; } if(text1 == NULL || text2 == NULL) { - return 0; + return index1 - index2; } switch(matching) {