Quick Guide to Create a GTK4 app with Rust and Flatpak

Quick Guide to Create a GTK4 app with Rust and Flatpak

Quick Guide to Create a GTK4 app with Rust and Flatpak


December 1, 2020

Quick Guide to Create a GTK4 app with Rust and Flatpak Quick Guide to Create a GTK4 app with Rust and Flatpak Okay! I will go super fast with that because I’m very busy with it? hmm? I don’t know yet, but I will find something to do! Anyway, just try to follow along! It is super easy and super fun! And so, we are on the GTK Rust Template project, which is a boilerplate script to initiate a new Flatpak Rust app. And we want to go to Merge Requests, and to

GTK 4 Port. Remember that’s number 11, although don’tworry about it that much! In the next couple of days it should be mergedon master! Anyway! Next we need to clone this, so we open a terminal! And do a git clone, and the repository I copiedbefore with my pure

Gitlab skills, without you even noticed when and how 🙂 Speaking of my amazing Gitlab skills, checkout how I’m merging a pull request from a different remote! Cool, huh? Okay, now we have this Python script we wantto run, and it will go through some questions. Application Name I’ll say The App. Project name, obviously the same but withhyphens. Application ID is the reversed domain, whichis World.babyWogue :p Which reminds me I should upload the siteat some point!

The Author details gets them from Git GlobalConfig! And so all done! What all this did was to create the app directory,so lets get inside it! And by the way we should move it somewhereoutside, but it doesn’t matter for now! Meanwhile let me show you another cool trick! So I open the project with Visual Studio Code,and it will immediately autodetect the Flatpak Manifest, and it will ask if we want to initiate a

build! But I’ll close that for now! And if we go to Visual Studio Marketplace,we will find a Flatpak extension that basically adds some quick scripts and shortcuts! So basically we can fully work our projecton Microsoft Code, and we don’t need to change code editors, which is a thing everyone hatesI believe! So I will initiate the build from CommandPalette, and if we’re missing some

runtimes it will say on terminal. Basically apart GNOME SDK from Nightly, youalso need Rust SDK 20.08 Okay, now the initialization was successful,we can proceed with the build and run! Only there is a tiny issue which is actuallya bug on the VSCode extension, rather on the project build template. Long story short, the build will fail, andso we’re going to use GNOME Builder after all! At least till this

bug gets fixed! So, select a folder.. Find our project in this terrible file picker.. And finally open it! And then just hit the play button, and leaveBuilder to do all the rest! But Flatpak Rust builds are huge and lastlong the first time, so till finishes it’s a great opportunity to go out of video context! But for a good reason I believe! So this is an article by Chris Davis, whichis a very active GNOME contributor, so I guess you know him already. And basically he says don’t use Glade, andbelow he explains the reasons and the issues with it. One thing you should know is that Builder’sDesigner is pretty much an integrated Glade,

so the shortcomings apply there too, moreor less. But it was on the comments section that somethingreally attracted all my attention, and my arguments too! So Chris responding to someone, he says thatGTK developers are focused to make GTK better, and they aren’t the developers of Glade. But if GTK developers aren’t responsible forthe building tools, and specially for the designer of the toolkit,then who is it? Chino? Definitely not my fault! But Cocoa?

Patches are welcome! Pouf! Too cute for writing code! So basically apart that we can’t easily prototypewithout a designer, and it is nearly impossible to write XML files manually, a bigger problemand specially for new GTK app developers, is that is very hard to learn the availablewidgets and how to compose them. And to be honest, I’m not very optimisticwe’ll get a new designer on Builder for GTK4 anytime soon. And the reason I’m saying all those, is becauseI don’t want to over-excite you that you can actually build a GTK 4 app inside a week! It is certainly easy to getting started, butscaling it is a new whole different universe! Anyway! Right on time that compile finished, and we’re having our

first Rust app \o/ It may cannot do a lot at the moment, butit is using the official development theme, and it has an under-construction icon too! And that’s something! Also we have headerbars and a main menu, pluskeyboard shortcuts and an About dialogue too! But the most impressive of everything, isthat we can get this Flatpak manifest, and literary open a pull request to Flathub andshare it with everyone! At least when GTK 4 will be available on thestable SDK! And that’s the

part that GNOME has done afantastic job! And make no mistake! All those started by GNOME and for GNOME,and later it just spread! So, beyond that point you want to continueby reading the GTK 4 examples! Then you also need to read the API, and I’mnot sure how complete and stable that is, but Bilal told me that most of the stuff youneed to start is there already! Speaking of which, I strongly suggest to lookat Authenticator source code, that has been already ported to GTK 4.

And because Bilal contributes big on Rustbindings, you will certainly find the best practices there! Ouch! That should hurt! And I wish you to start fresh and you won’t need to port anything! But there is also a migration guide from GTK3, which can be proved a bit useful even if that’s your first try! So that was everything for now! And so, good luck! You will need it!

Quick Guide to Create a GTK4 app with Rust and Flatpak

Leave a Reply

Your email address will not be published. Required fields are marked *