Search code examples
cgtkgtk4

libadwaita: erratic behaviour from AdwComboRow -- my fault or bug?


I'm trying to create an AdwComboRow in libadwaita, but after I change the selected entry a few times, it will suddenly pick a different entry from the one I clicked. This typically takes a while to start happening (20 or so changes), but seems to get more common the more I play around with the selected entry.

#include <gtk/gtk.h>
#include <adwaita.h>

GtkApplication *app;
GtkWidget *window;
GtkWidget *listbox;
GtkWidget *combo;
GtkStringList *slist;

const char *entries[] = {
    "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten"
};

const size_t n_entries = 10;

void app_startup(void)
{
    adw_init();
}

void app_activate(void)
{
    window = adw_application_window_new(app);
    listbox = gtk_list_box_new();
    combo = adw_combo_row_new();
    adw_preferences_row_set_title(ADW_PREFERENCES_ROW(combo), "Test");
    slist = gtk_string_list_new(NULL);

    for (size_t i = 0; i < n_entries; i++)
        gtk_string_list_append(slist, entries[i]);

    adw_combo_row_set_model(ADW_COMBO_ROW(combo), G_LIST_MODEL(slist));
    gtk_list_box_append(GTK_LIST_BOX(listbox), combo);

    adw_application_window_set_content(ADW_APPLICATION_WINDOW(window),
        listbox);

    gtk_widget_show(window);
}

int main(int argc, char **argv)
{
    app = gtk_application_new("org.null.null", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
    g_signal_connect(app, "activate", G_CALLBACK(app_activate), NULL);

    g_application_run(G_APPLICATION(app), argc, argv);

    g_object_unref(app);

    return 0;
}

This behaviour is reproducible on Gentoo amd64 (gui-libs/gtk-4.6.0 and gui-libs/libadwaita-1.0.1, as well as gui-libs/gtk-4.6.1 and gui-libs/libadwaita-1.0.2), a Debian Bookworm chroot on that same system (libgtk-4-dev/testing,now 4.6.1+ds-1 amd64 and libadwaita-1-dev/testing,now 1.1~rc-1 amd64), and Mobian Bookworm on PinePhone (same package versions as the chroot, but arm64 builds), which leads me to fear it may be my error rather than a bug in libadwaita. Is there something I'm missing here?


Solution

  • Did some more digging, and found that I could reproduce it with a simple GtkDropDown created with gtk_drop_down_new_from_strings; no libadwaita necessary at all! From there, it didn't take very long to find out that this is in fact GTK bug #2877. Unfortunately that bug appears to be very stale at this point, but at least I know it's not my fault after all.