December through February - Gtk4 Migration (Tavmjong)
11 марта 2024 г. 16:59
Another three months have passed. My contract hours have been used up. The Gtk4 version of Inkscape runs and can be used for work but we've encountered more problems than we anticipated. As a result, we decided during our weekly developer's meetings to base our next Inkscape release on the Gtk3 version. This will give us more time to iron out the remaining problems with the Gtk4 version. We expected all along that we would have to have a long "alpha" and "beta" periods with the Gtk4 branch so this isn't entirely unexpected.
Cross Platform Support
One thing that concerns us is that the cross-platform support in Gtk4 is missing some key features. For example, it is not currently possible to set custom cursors on MacOS with Gtk4. The Gtk4 team struggles with cross-platform support as it's a rare developer who both knows the MacOS GUI code base and the Gtk code base well enough to contribute patches and has time to do so. The Gnome Foundation has indicated that cross-platform support is important and is willing to invest resources if a developer who can do the work can be found.
Gtk4 Maturity
Inkscape is one of the most demanding users of the Gtk toolkit. This means that we often find bugs or deficiencies that others miss. Sometimes crucial documentation is missing and working examples are scarce. In order to build Inkscape with Gtk4, we need to use the latest Gtk code which means compiling the Gtk4 libraries ourselves. This will be all worked out, it just takes time.
Summary of Work
At the beginning of this work period, Inkscape was runnable with the Gtk4 toolkit but it wasn't a pleasant experience. I've focused on the remaining "big" issues, the most important was getting keyboard shortcuts working. Event handling in Gtk4 is fundamentally different from that in Gtk3. It relies now on "Event Controllers" that can be attached to any widget. This is actually a good change, but as with all changes, it requires updating the code. The new Shortcut controller took quite a bit of effort get working correctly as our shortcut handling is quite complex.
I fixed a variety of smaller problems such as with localized formats. Gtk4 enforces that the "C" local and the "C++" local be the same. In Gtk3 the "C++" local defaulted to the "Classic C" local while the "C" local came from the users system. Depending on your local, numerical strings were being written different ways. For example, if your system is using the French local "FR_fr", the decimal separator is a comma, while with the "Classic C" local it is a period. This is fine for GUI purposes, but for internal purposes, having a comma rather than a period leads to incorrect numerical values.
Other smaller projects included fixing the Dash-pattern widget and fixing the Color-Wheel widget.
My biggest effort during this period focused on the "Layers and Objects dialog" and the "XML dialog". These dialogs both show "trees" of objects (e.g. rectangles, paths, text). One can drag and and drop objects to rearrange them which can change the order in which they are drawn or put them in different groups. This is done in Gtk3 by using a TreeView widget which has built-in drag and drop capabilities. The TreeView widget is deprecated in Gtk4 and some of its functionality has been removed as a result of the change in event handling.
It wasn't clear how to adapt to these changes. One fundamentally has three choices:
1. Use the TreeView widget with its existing drag and drop capabilities but with reduced functionality,
2. Use the TreeView widget with the new drag and drop controllers, or
3. Convert the code to using the new ListView widget which would promises great speed improvements for large lists.
I spent a lot of time writing toy programs, trying to get the new ListView widget to handle drag and drop (it has no internal support). I finally succeeded but due to problems on MacOS, I decided to keep the existing TreeView widget but to implement drag and drop with the new controllers. When the MacOS problems are solved, it should be straight forward to convert to the new ListView widget as the drag and drop mechanism is the same for both.
Future
We are still working on the Gtk4 Inkscape version. After we "branch" the code for Inkscape 1.4 (based on Gtk3), we will merge the new code. This will allow more developers to test and work on the code.