* particularly good reason not to.
*/
struct frontend {
+ bool headless; /* true if we're running without GTK, for --screenshot */
+
GtkWidget *window;
GtkAccelGroup *dummy_accelgroup;
GtkWidget *area;
{
frontend *fe = (frontend *)handle;
+ if (fe->headless)
+ return;
+
assert(fe->statusbar);
gtk_statusbar_pop(GTK_STATUSBAR(fe->statusbar), fe->statusctx);
fe->cr = NULL;
#ifndef USE_CAIRO_WITHOUT_PIXMAP
- {
+ if (!fe->headless) {
cairo_t *cr = gdk_cairo_create(fe->pixmap);
cairo_set_source_surface(cr, fe->image, 0, 0);
cairo_rectangle(cr,
static void setup_backing_store(frontend *fe)
{
#ifndef USE_CAIRO_WITHOUT_PIXMAP
+ if (fe->headless) {
+ fprintf(stderr, "headless mode does not work with GDK pixmaps\n");
+ exit(1);
+ }
+
fe->pixmap = gdk_pixmap_new(gtk_widget_get_window(fe->area),
fe->pw, fe->ph, -1);
#endif
wipe_and_maybe_destroy_cairo(fe, gdk_cairo_create(fe->pixmap), true);
#endif
#if GTK_CHECK_VERSION(3,22,0)
- {
+ if (!fe->headless) {
GdkWindow *gdkwin;
cairo_region_t *region;
GdkDrawingContext *drawctx;
{
GdkGC *gc;
+ if (fe->headless) {
+ fprintf(stderr, "headless mode does not work with GDK drawing\n");
+ exit(1);
+ }
+
fe->pixmap = gdk_pixmap_new(fe->area->window, fe->pw, fe->ph, -1);
gc = gdk_gc_new(fe->area->window);
teardown_drawing(fe);
- if (fe->bbox_l < fe->bbox_r && fe->bbox_u < fe->bbox_d) {
+ if (fe->bbox_l < fe->bbox_r && fe->bbox_u < fe->bbox_d && !fe->headless) {
#ifdef USE_CAIRO_WITHOUT_PIXMAP
gtk_widget_queue_draw_area(fe->area,
fe->bbox_l - 1 + fe->ox,
enum { ARG_EITHER, ARG_SAVE, ARG_ID }; /* for argtype */
-static frontend *new_window(char *arg, int argtype, char **error)
+static frontend *new_window(
+ char *arg, int argtype, char **error, bool headless)
{
frontend *fe;
GtkBox *vbox, *hbox;
struct preset_menu *preset_menu;
fe = snew(frontend);
-#if GTK_CHECK_VERSION(3,20,0)
- fe->css_provider = NULL;
+ memset(fe, 0, sizeof(frontend));
+
+#if !GTK_CHECK_VERSION(3,0,0)
+ if (headless) {
+ fprintf(stderr, "headless mode not supported below GTK 3\n");
+ exit(1);
+ }
+#else
+ fe->headless = headless;
#endif
fe->timer_active = false;
midend_new_game(fe->me);
}
+ snaffle_colours(fe);
+
+ if (headless) {
+ get_size(fe, &fe->pw, &fe->ph);
+ setup_backing_store(fe);
+ return fe;
+ }
+
#if !GTK_CHECK_VERSION(3,0,0)
{
/*
changed_preset(fe);
- snaffle_colours(fe);
-
if (midend_wants_statusbar(fe->me)) {
GtkWidget *viewport;
GtkRequisition req;
return 0;
} else {
frontend *fe;
+ bool headless = screenshot_file != NULL;
- gtk_init(&argc, &argv);
+ if (!headless)
+ gtk_init(&argc, &argv);
- fe = new_window(arg, argtype, &error);
+ fe = new_window(arg, argtype, &error, headless);
if (!fe) {
fprintf(stderr, "%s: %s\n", pname, error);