Search code examples
pythontouchgtk3

GTK+3 combobox on touchscreen workaround


I'm working on GTK+3 python app, which is running on embedded system on touch screen. I need to use combobox, but it is not compatible with touch input. If I click on it, it shows dropdown menu, which closes as soon as I lift finger up. It also selects option on coordinates, where I first touched the display. If I drag my finger somewhere else to select other option, It doesn't select nothing. If first click coordinates are outside of rendered dropdown, it doesn't close on finger lift and behaves correctly.

I have found this bug mentioned more than 10 years ago, but I wasn't able to find any workaround for this. I have tried recompiled GTK with some patches I made, but it's quite complex project and I'm wasn't successful. I'm not sure, how to debug my patches, I'm not even sure, if my patches were propagated successfully to gtk and pygobject library.

Is here some existing workaround or patch to use comboboxes on touch screen?


Solution

  • Ok, I have found this workaround. I have created yocto patch for Gtk+3_3.24.36. I have simply overrided piece of code responsible for setting vertical position of popup widget. In default, popup widget is positioned so selected option is aligned with combobox. In my workaround, popup widget is positioned below combobox, away from user finger. It works good for me.

    diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
    index ef4996c..727085e 100644
    --- a/gtk/gtkcombobox.c
    +++ b/gtk/gtkcombobox.c
    @@ -2209,7 +2219,7 @@ gtk_combo_box_menu_popup (GtkComboBox    
    *combo_box,
           g_object_set (priv->popup_widget,
                         "anchor-hints", (GDK_ANCHOR_SLIDE |
                                          GDK_ANCHOR_RESIZE),
    -                    "rect-anchor-dy", rect_anchor_dy,
    +                    "rect-anchor-dy", 30,
                         NULL);
    
           g_signal_connect (priv->popup_widget,