Ported GNOME Mahjongg to Gtk4 - my journey

Everything started with a tweet by Alexander Mikhaylenko about the state of the "Dark Style Preference" Initiative. As i play Mahjongg from time to time i wanted to help with the Initiative and postulated the goal "Lets make GNOME Mahjongg dark stylable". After digging a little bit in the code i tried to directly port to Gtk4. I mean, how hard can it be. Its just a small game with a GtkDrawingArea. (spoiler it was harder then i thought)

mahjongg-gtk3.png

Deprecations

Some rendering code for the tiles was using deprecated methods. These are gone in Gtk4 therefore i first had to fix this. Additionally i had to change:

Little refactorings

As the code was really cluttered with many GUI related construction code i decided to introduce composite templates into the project as this will significantly reduce the code and makes it more maintainable in the future. Lesson i learned doing this was, that its perfectly doable to port dialogs to composite templates but its important to stick to the default layout. Adding widgetry as child without the type internal-child="content_area" will damage the function of a typical dialog and you won't get action widgets correctly.

gnome-mahjongg-gtk4.png

Bringing in libadwaita

As the dark style preference (my initial goal) will be automatically used when i use libadwaita i decided to use this from now on. Libadwaita has some niceties which made the work really a pleasure:

gnome-mahjongg-gtk3-pref.png gnome-mahjongg-gtk4-pref.png

Closing

Overall i like where Gtk4 and libadwaita is heading to. Functionality is improved on several things and the API is now better then before. GNOME 42 will be an awesome release! Stay tuned