chiark / gitweb /
Don't initialise GTK in --screenshot mode.
authorSimon Tatham <anakin@pobox.com>
Fri, 23 Nov 2018 23:44:17 +0000 (23:44 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 23 Nov 2018 23:44:17 +0000 (23:44 +0000)
commitd9e03f50daffc37027a5c57c88c7fd4241a58782
tree5c82fb0f14e935349678be3c53cf7aff47670fdf
parentdb3b531e2cab765a00475054d2e9046c9d0437d3
Don't initialise GTK in --screenshot mode.

I had this idea today and immediately wondered why I'd never had it
before!

To generate the puzzle screenshots used on the website and as program
icons, we run the GTK front end with the --screenshot option, which
sets up GTK, insists on connecting to an X server (or other display),
draws the state of a puzzle on a Cairo surface, writes that surface
out to a .png file, and exits.

But there's no reason we actually need the GTK setup during that
process, especially because the surface we do the drawing on is our
_own_ surface, not even one provided to us by GTK. We could just set
up a Cairo surface by itself, draw on it, and save it to a file.
Calling gtk_init is not only pointless, but actively inconvenient,
because it means the build script depends on having an X server
available for the sole purpose of making gtk_init not complain.

So now I've simplified things, by adding a 'headless' flag in
new_window and the frontend structure, which suppresses all uses of
actual GTK, leaving only the Cairo surface setup and enough supporting
stuff (like colours) to generate the puzzle image. One awkward build
dependency removed.

This means that --screenshot no longer works in GTK 2, which I don't
care about, because it only needs to run on _one_ platform.
Buildscr
gtk.c