My GTemplate is simple but feature rich GUI Application template written in C using GTK3/GTK4. Several features are included along with a script to bootstrap your own project.
The project is released into public domain (CC0). Feel free to use it the way you wish. If you wish to support me, consider donating me via librepay.
Figure 1: Obligatory screenshot
Figure 2: The same on Windows 8
- Written in C programming language
- [G]Object Oriented Design
- Supports GTK3 and GTK4
- Meson build system with fallback configure script
- Flatpak support included
- GitLab CI configuration included
- Microsoft Windows support with MinGW and msitools
- GtkBuilder .ui templates for UI
- UI based on GNOME HIG
- GNOME shell menu not included as it’s deprecated
- Application specific CSS
- Keyboard shortcuts window
- Handles commandline arguments
- Tab completion for commandline
- Internationalisation using gettext
- Documentations for code using gtk-doc
- Mallard based help for GNOME Help
- Manpage in docbook XML format
- GSettings integration
- Symbolic and non-symbolic icons
- Script to generate non-symbolic icons from symbolic ones
- Uncrustify configuration and script
- Meson based unit tests
- And many more…
Follow the instructions below to compile the project from source:
To build the project you require a recent version of some GNU/Linux. Feel free to use the OS of your choice. Though it’s recommended to use the latest version Ubuntu, Fedora or Debian testing.
To bootstrap a new project, a few packages are required:
# On Debian, Ubuntu and derivatives sudo apt install -y git meson flatpak flatpak-builder \ uncrustify build-essential libgtk-3-dev appstream-util \ xsltproc docbook-xsl gedit gnome-builder # On Fedora and derivatives sudo dnf install -y @c-development @development-tools \ gettext-devel gtk3-devel uncrustify gettext-devel meson \ flatpak flatpak-builder desktop-file-utils git gedit \ docbook-style-xsl gnome-builder
Many developers use GNU Emacs or vim as Editor. If you don’t have such an editor of choice, it’s recommended to use GNOME Builder. You may also find Flatpak helpful when developing with GNOME Builder. To configure Flatpak, see Flatpak setup guide.
If you are planning to build for Microsoft Windows, Fedora may be the only OS choice as it includes many MinGW packages required for building GTK3 applications.
Creating a new project from template
To create a new project from the template, clone the
script and replace the default values with your project
# Clone the repository ~$ git clone https://gitlab.com/sadiq/my-gtemplate.git ~$ cd my-gtemplate # Edit the file 'new-project.sh' ~/my-gtemplate$ gedit new-project.sh
Let’s say we are creating a GTK3 project for managing notes.
Let’s choose some (in)sane names for our project and change
# Make necessary changes to the variables. # Only some of them are listed here. GTK_VERSION="gtk3" APP_NAME="gee-note" APP_LAST_NAME="note" APP_REAL_NAME="Gee Note" # Assuming your repo is https://gitlab.com/username/gee-note APP_ID="com.gitlab.username.gee-note" APP_SHRT="gnt" APP_SHRT_CAP="GNt"
Now let’s try to build a template for our project:
# Make necessary changes to new-project.sh and run ~/my-gtemplate$ ./new-project.sh # APP_NAME will be used as directory name, so for us # it will be gee-note. Move it ~/my-gtemplate$ mv gee-note ~/ ~/my-gtemplate$ cd ~/gee-note # Now compile using meson ~/gee-note$ meson _build && cd _build ~/gee-note/_build$ ninja && sudo ninja install # Or alternatively, use the configure script. # All it does is to run meson. ~/gee-note$ ./configure && make && sudo make install # Let’s now run it ~/gee-note$ gee-note
A build script to compile and build
.msi installer is
included in the repository. The build script make use of
MinGW packages to compile the source, and msitools to create
.msi installer out of it. You don’t require to have
access to any Windows machine to compile or build the installer.
All the process can be done on a Fedora GNU/Linux.
The script has been tested only with Fedora 28. And only GTK3 is supported.
First, install the required packages:
# Instal mingw64-gtk3 for 64 bit build sudo dnf install -y mingw32-gtk3 meson gcc gtk3-devel msitools
To build, Update the file
build-aux/w32/defaults.sh.in and adapt
the variables as per your needs and do:
# Compile ~/gee-note$ ./build-aux/w32/make-w32.sh # Alternately, give arguments to specify details # First argument: Whether the build has to be optimized # Posible values (arg1): yes no # Second argument: Architecture the program should run # Possible values (arg2): i686 x86_64 ~/gee-note$ ./build-aux/w32/make-w32.sh yes i686 # And then follow the instructions printed by the # script to create an msi installer.
The generated .msi installer has a size of about 26 MiB. Around 18 MiB of that is Adwaita icon theme. You may be able to optimize the size if you include a custom version of Adwaita with only the required icons. You can also strip the binaries which can further save around 1-2 MiB.
You may use wine to test the installer and the executable:
# Install the .msi file. Use the # right .msi path shown in previous step ~/$ wine msiexec /i /path/to/installer.msi /l*v log.txt # Run the executable. Adjust the path if needed ~$ cd "$HOME/.wine/drive_c/Program Files/My GTemplate" .../$ XDG_DATA_DIRS="./share" wine bin/my-gtemplate.exe
And on Windows, as usual, you can simply double click
.msi file to install.
Required changes for new projects
The project created by running
new-project.sh shall still
have stale data. So, those files should be updated to match
your project. At the minimum, the following list of files are
thus supposed to be changed (The items in paren suggests the
alternate name you might have set in
- dummy examples and descriptions
- At least the
- At least the
- Image in
- And then run
- And then run
data/appdata/(All files, except
Of course, that’s just the minimum change. When you develop,
you’ll have to change everything in
src/ directory, and
probably other directories too.
Written in 2017, 2018 by Mohammed Sadiq <firstname.lastname@example.org>
To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see the license online.