Gestures like these is now how almost all input is handled in Nautilus. The exception is the stuff that has no event controller counterpart in GTK+ 3.
This summer I’m working on porting Nautilus to GTK+ 4 as part of Google Summer of Code, and I’ve spent the entirety of the time on getting rid of deprecated 3.x API and obsolete ways of handling events. Despite slightly hack-ish ways of working around deprecations, it’s been smooth sailing so far – No Regressions™! Almost ready to switch†!
™ - one reported and fixed † - “switch” here means staring at an endless stream of compiler errors
The hacks mostly pertain to replacing gtk_style_context_get_background_color():
- using gtk_style_context_get_color() instead for the usage pie chart (using CSS instead of Cairo might be possible, but would look differently),
- rendering the background to an intermediate Cairo surface and multiplying the pixel values afterwards (https://gitlab.gnome.org/GNOME/nautilus/commit/487213ad9b7b1f216ce9f9e9d6aecf5b51a6ea19).
Going back to event handling, the next immediate goal is to dismantle the old icon view we use, since it holds non-widget objects, which largely requires emulating GTK+ for event handling. The reason for that is simply that Nautilus predates GtkIconView and was never ported to using that (possibly for performance reasons). I’ve got code that uses gestures for button presses locally already, but will look for something better than adding a small GdkEvent clone that allows setting fields, which is required mostly for synthesizing “enter” and “leave” events for the children.
It’s a bit unfortunate that there only exists a subset of event controllers in GTK+ 3, but at the same time it’s a great opportunity to make the code GTK+ 4-compliant (still hoping to see the key event controllers soon). Where impossible to use one, I switched to handling ::event (bar some instances of ::key-press-event, where that prevented accelerator handlers from being run).
All in all, the pain has been minimal and I’m looking forward to getting back with a fresh perspective on things after the university exam period ends.
Edit: clarified the bit about the canvas view not holding widgets.