June - GTK4 Migration

We're transitioning from Gtk3 to Gtk4. What is Gtk? It's a toolkit! Or more practically it's the buttons, menus, and other "widgets" used to create Inkscape's Graphical User Interface (GUI for short). It also handles mouse and keyboard events. It's an important part of Inkscape.

Why switch? Gtk4 is the future! It offers improved ways of doing common things. While Gtk3 is not abandoned, it is now in "maintenance" mode and won't be receiving much love.

Why switch now? The most compelling reason is that Gtk4 has the promise of being more performant, especially on MacOSX. There are other, "under-the-hood" benefits too.

Switching from Gtk3 to Gtk4 is a big thing, literally, thousands of lines of code will need to be changed. We expect it to take months to make the basic changes needed to just compile the code using the Gtk4 libraries. And then some time to fix the inevitable regressions.

I've been working the past month on the transition under a contract funded by your donations. We've also contracted Daniel Boles, a Gtk expert, to help. He'll be staring work this month.

So what have I been doing? The past month I've focused on things that can be done before we create a Gtk4 code branch, that is things that can be done while still using Gtk3. Here are a few of the things I worked on (most of the work is very technical, I'll list everything at the end):

Gtk::ButtonBox

Gtk::ButtonBox, like the name hints, is a container for buttons. It's basically a Gtk::Box that has the added feature that all the "buttons" it contains are constrained to have the same width. This widget has been removed from Gtk4. The recommended replacement is to just use a Gtk::Box.

This project got off to a fast start. A number of places where we used Gtk::ButtonBox didn't need its special properties. For example, if the buttons were created using icons, they were automatically the same width. Things got a little more complicated if the buttons contained text. The Gtk::Box widget has a property called "homogeneous", setting this true forces all the widgets contained by the box to have the same width. This handled most of the remaining cases. But there were a couple of "stubborn" cases. If the box had a button on the far left and a button on the far right, setting "homogeneous" to true caused each button to take up a third of the width of the box which was way too wide. Why? Because the Gtk3 box actually has three places you can attach widgets: at the start of the box (usually the left edge), at the end of the box (usually the right edge), and with one place for a widget in the center of the box). Even if there was not widget in the center position, the box calculates the widths as if there was one there. The solution is to not set the "homogeneous" property true but to use a Gtk::SizeGroup to explicitly tell Gtk that these widgets should be the same width. There was also the some monkeying around with properties to get everything to work as anyone who has worked with CSS should be familiar with.

Color Management for Monitors

Inkscape had code that tried to automatically apply monitor color corrections depending on which monitor an Inkscape window was being viewed on (in a multi-monitor setup). This code was very complicate and poorly documented. It relied on things removed from Gtk4 so a refactoring was necessary. It took quite a while and many tests to show that this code, which could have only worked under Linux with the X11 windowing system, didn't work and probably hadn't for some time. And even if it did work, getting it setup required setting an X11 "Atom" that after searching the Internet for hours, I still couldn't figure out how to do. (One program that might have been used didn't work with the latest ICC profile version.) Given that almost all modern windowing systems allow the user to set system wide monitor color corrections, it was time for this code to go. You can still manually specify a monitor color correction inside Inkscape if you need to.

Test Programs

I spent quite a bit of time writing short test programs to get to know how the things have changed between Gtk3 and Gtk4. The maintainers of Gtk have provided a migration guide but given the huge number of changes made, there is not a lot of detail for any particular change. By writing short programs, it is easier to figure out what one needs to do to adapt to Gtk4. I wrote programs that tested:

These programs are publicly available at my GitLab site: https://gitlab.com/Tavmjong/gtk_sandbox

Items Worked On:

Commits to Inkscape's Gitlab repository: