Creating a binary bundle for your GTK3 theme can be useful. It will reduce the I/O error and file system checks as the the resources will already be in the memory. This means loading the resources will be more efficient. I really cannot say the impact on performance, but it is easy to do and makes no harm if you do.
Building the binarySo let's start. Now that your GTK3 theme is ready, we will create a binary for it. Backup the theme folder somewhere else before starting though, as we will delete and modify files.
- First, we shall rename the
gtk-dark.cssfile (if exists) to
- Then create a XML file named
gtk-3.0folder which will contain the list of all resources, i.e. all CSS files and images. An example would be,
<?xml version="1.0" encoding="UTF-8"?> <gresources> <gresource prefix="/org/gnome/name"> <file preprocess="to-pixdata">assets/slider.png</file> <file>apps/nautilus.css</file> <file>gtk-main.css</file> <file>gtk-main-dark.css</file> <file>gtk-widgets.css</file> </gresource> </gresources>
I think you will be able to understand the syntax from the above file. The part
prefix="/org/gnome/name"is important and you should use the name of your theme in place of
name. It will be the path which we will use to access the resources after we made the binary. After you are done, proceed to next step.
- To build the binary, we will need some packages installed. The packages may vary depending on the contents of the file. But for our example, we would need following packages,
libgtk-3-dev (>= 3.3.14), libglib2.0-dev, libgdk-pixbuf2.0-dev, libxml2-utils
The names above refer to the packages in Ubuntu, but you should install corresponding packages for your distro.
- After installing the required packages, navigate to the
gtk-3.0folder and run the following command,
If everything goes well, you will now have a shiny new file named
- Now make a file named
gtk-dark.css(only if you had a
gtk-main-dark.cssfile). The contents of the file
The name would be the one which used earlier in the
gtk.gresource.xmlfile. Here we are using the
@importrule to include
gtk-main.cssfile, which will in turn import all other files listed inside it.
For the file
gtk-dark.css, the contents should be,
- Now it is time to test the theme. Delete all other files except
settings.ini(you have a backup as I mentioned previously, don't you?). Then test the theme as you normally would. If everything was as expected, then you've successfully built the binary.
Writing a MakefileYou can package the theme for a specific distro and distribute via repositories. The advantage here would be that the user can get automatic updates and they won't face any problems installing the theme.
We will write a simple
Makefilein case you want to build packages for distros. Note that the
Makefileis not needed if you didn't compile the theme into binary.
Create a file
Makefileoutside your theme folder. We should have the following in our
source_dir=Name/gtk-3.0 gtk.gresource: glib-compile-resources --sourcedir=$(source_dir) $(source_dir)/gtk.gresource.xml clean: rm -f $(source_dir)/gtk.gresource
Notice that here the indention before the lines must be tabs, not spaces. Don't just copy/paste from here. It will not work.
Namehere should be the name of the directory inside which your theme is present. Now the
Makefileis ready, you can package the theme easily. Note that we didn't add an
installoption in the
Makefilebecause we will do that with whatever package we build, just to keep things simple.
I'm really a noob regarding
Makefiles and if you have any suggestions or corrections, please comment.