Hello there,
I’m trying to setup a multi-selection using a GtkListView in a GtkScrolledWindow and a GListModel via GtkStringList. Everything works fine, with keyboard and mouse using CTRL/SHIFT+LMB,
but things break down, when trying to select multiple entries on a touch device.
This can be reproduced with the colors example of the GTK4 demo.
How is this supposed to work on a device without a keyboard?
Greetings.
Okay, I’ve inquired ChatGPT about this problem, and came up with the following solution, that seems to be working. However I don’t think it’s really clean, to me it smells more like a workaround. ChatGPT insists that’s how it’s done, so it must have found discussions and other sources that most likely back this.
Nonetheless, I thought I’d present it to help someone else stumbling across the same problem and to allow for discussion:
- Use the signal list item factory to create entries
- On the “setup” signal of the factory, create the widgets
- While creating the widgets, add a KV set to the widget, tracking the GtkListItem (using g_object_set_data)
- Install a new “released” handler on the new widget
- In the handler: Listen to the primary button and claim the event sequence,
get the GtkListItem from the KV set of the widget. Activate the action “list.select-item” on the widget. Apparently it will bubble up.
Why I don’t like this approach:
This works only if the widget inside the GtkListItemWidget is filling it completely.
Otherwise, the default behavior, of unselecting the old item will occur.
Furthermore, it requires the application to be touch-aware, something that should be handled in GTK in my opinion. For example, long-pressing the item, somehow freezes the list, as if some special mode has been entered. It can’t be scrolled, but multiple selection still doesn’t work as one would expect.
EDIT:
Also apparently you can’t ever get the child widget of the GtkListItemWidget to completely fill, because the widget will try to keep it from filling into the space, where the selection highlight curves.
EDIT2:
How I would have expected things to work:
I expected, that the GtkListFactoryWidget installs a signal, that not only checks if CTRL or SHIFT are pressed, but also checks that if the event source is from a touch device, it behaves as if CTRL is pressed. Are the any concerns about doing it like this?