-I$(builddir)/lib -I$(srcdir)/lib
AM_CFLAGS = $(MOTIF_CFLAGS)
+if HAVE_MOTIF
bin_PROGRAMS = rrace-motif
+endif
rrace_motif_SOURCES = src/game.c src/x11.c src/game.h src/motif.h \
- src/ewmhicon.c
+ src/ewmhicon.c src/ewmhicon.h
rrace_motif_LDADD = $(libmotifmain_a_OBJECTS) $(libmotifui_a_OBJECTS) \
$(libglohelp_a_OBJECTS) libgnu.a $(MOTIF_LIBS)
$(rrace_motif_OBJECTS): $(gnulib_headers)
check_PROGRAMS = t/boardmove t/ewmhicon t/rng-test
EXTRA_DIST += t/xos256ss.c
-t_boardmove_LDADD = src/game.$(OBJEXT) libgnu.a
+t_boardmove_SOURCES = t/boardmove.c src/game.c
+t_boardmove_LDADD = libgnu.a
$(t_boardmove_OBJECTS): $(gnulib_headers)
-t_ewmhicon_LDADD = src/ewmhicon.$(OBJEXT) libgnu.a $(MOTIF_LIBS)
+t_ewmhicon_SOURCES = t/ewmhicon.c src/ewmhicon.c
+t_ewmhicon_LDADD = libgnu.a $(MOTIF_LIBS)
$(t_ewmhicon_OBJECTS): $(gnulib_headers)
t_rng_test_LDADD = libgnu.a
AC_SUBST([MOTIF_CFLAGS], [@&t@])
AC_SUBST([MOTIF_LIBS], [@&t@])
AS_IF([test x"$dx_cv_have_motif" = x"yes"],
- [MOTIF_CFLAGS=$dx_cv_motif_cflags MOTIF_LIBS=$dx_cv_motif_libs])
+ [MOTIF_CFLAGS=$dx_cv_motif_cflags MOTIF_LIBS=$dx_cv_motif_libs],
+ [AC_DEFINE([X_DISPLAY_MISSING])])
+AM_CONDITIONAL([HAVE_MOTIF], [test x"$dx_cv_have_motif" = x"yes"])
AC_CONFIG_TESTDIR([.], [t:.])
DX_PROG_AUTOTEST
#include <stdlib.h>
#include <string.h>
-#include <X11/Intrinsic.h>
-#include <X11/Xatom.h>
-#include "motif.h"
+#if !X_DISPLAY_MISSING
+# include <X11/Intrinsic.h>
+# include <X11/Xatom.h>
+#endif
+#include "ewmhicon.h"
static unsigned long scale16to8(unsigned x)
{
}
}
+void *ewmh_icon_alloc(unsigned long **sizes)
+{
+ unsigned long *buf;
+
+ buf = calloc(sizeof *buf, EWMH_ICON_NELEM);
+ if (buf) {
+ sizes[ICON_16x16] = buf;
+ *sizes[ICON_16x16]++ = 16;
+ *sizes[ICON_16x16]++ = 16;
+
+ sizes[ICON_24x24] = sizes[ICON_16x16] + 16*16;
+ *sizes[ICON_24x24]++ = 24;
+ *sizes[ICON_24x24]++ = 24;
+
+ sizes[ICON_32x32] = sizes[ICON_24x24] + 24*24;
+ *sizes[ICON_32x32]++ = 32;
+ *sizes[ICON_32x32]++ = 32;
+
+ sizes[ICON_48x48] = sizes[ICON_32x32] + 32*32;
+ *sizes[ICON_48x48]++ = 48;
+ *sizes[ICON_48x48]++ = 48;
+ }
+
+ return buf;
+}
+
+#if !X_DISPLAY_MISSING
+
+/*
+ * EWMH-supporting window managers that handle _NET_WM_ICON add this atom to
+ * the _NET_SUPPORTED list on the root window. Look for that and return 1
+ * if it is found, or 0 otherwise.
+ */
int ewmh_probe_wm_icon(Widget shell)
{
Display *display = XtDisplay(shell);
unsigned char *prop_return;
int format;
- net_wm_icon = XInternAtom(display, "_NET_WM_ICON", FALSE);
- net_supported = XInternAtom(display, "_NET_SUPPORTED", FALSE);
+ net_wm_icon = XInternAtom(display, "_NET_WM_ICON", 0);
+ net_supported = XInternAtom(display, "_NET_SUPPORTED", 0);
do {
XGetWindowProperty(display, root, net_supported, offset, 10,
- FALSE, XA_ATOM, &type,
- &format, &nitems, &bytes_after,
+ 0, XA_ATOM, &type, &format,
+ &nitems, &bytes_after,
&prop_return);
if (format != 32 || type != XA_ATOM)
return 0;
}
-void *ewmh_icon_alloc(unsigned long **sizes)
-{
- unsigned long *buf;
-
- buf = calloc(sizeof *buf, EWMH_ICON_NELEM);
- if (buf) {
- sizes[ICON_16x16] = buf;
- *sizes[ICON_16x16]++ = 16;
- *sizes[ICON_16x16]++ = 16;
-
- sizes[ICON_24x24] = sizes[ICON_16x16] + 16*16;
- *sizes[ICON_24x24]++ = 24;
- *sizes[ICON_24x24]++ = 24;
-
- sizes[ICON_32x32] = sizes[ICON_24x24] + 24*24;
- *sizes[ICON_32x32]++ = 32;
- *sizes[ICON_32x32]++ = 32;
-
- sizes[ICON_48x48] = sizes[ICON_32x32] + 32*32;
- *sizes[ICON_48x48]++ = 48;
- *sizes[ICON_48x48]++ = 48;
- }
-
- return buf;
-}
+#endif
--- /dev/null
+/*
+ * _NET_WM_ICON helpers for slide puzzle game
+ * Copyright © 2022 Nick Bowler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef EWMHICON_H_
+#define EWMHICON_H_
+
+/*
+ * Define X_DISPLAY_MISSING to allow building without X11 (for test purposes)
+ */
+#if !X_DISPLAY_MISSING
+# include <X11/Intrinsic.h>
+#else
+
+/* Stub types to allow compilation */
+typedef struct {
+ unsigned short red, green, blue;
+} XColor;
+
+typedef struct stub_widget *Widget;
+
+#endif
+
+enum { COLOUR_PRIMARY, COLOUR_DARK, COLOUR_LIGHT, COLOUR_MAX };
+
+/*
+ * Helpers for drawing window icons in various sizes. The tileXX functions
+ * draw one (out of 9) tiles at a particular size using a particular colour
+ * set. Call for each tile position to draw a complete icon.
+ */
+enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX };
+#define EWMH_ICON_NELEM (2+16*16 + 2+24*24 + 2+32*32 + 2+48*48)
+
+void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
+void ewmh_tile24(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
+void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
+void ewmh_tile48(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
+
+/*
+ * Allocate storage for the EWMH _NET_WM_ICON array. The sizes array is
+ * populated with pointers to the beginning of each icon's pixel data. For
+ * example, sizes[ICON_24x24] points to the first pixel of the 24x24 image.
+ *
+ * The returned value can then be passed to XChangeProperty to set the icon,
+ * (use EWMH_ICON_NELEM for the number of elements) and must be freed by the
+ * caller.
+ */
+void *ewmh_icon_alloc(unsigned long **sizes);
+
+/*
+ * Check if the root window indicates support for EWMH icons. Returns 1 if
+ * supported, or 0 otherwise.
+ */
+int ewmh_probe_wm_icon(Widget shell);
+
+#endif
#define RRACE_MOTIF_H_
#include <inttypes.h>
+#include "ewmhicon.h"
#include "game.h"
-enum { COLOUR_PRIMARY, COLOUR_DARK, COLOUR_LIGHT, COLOUR_MAX };
-
struct app_state {
struct board board;
void x11_redraw_goal(struct app_state *state);
void x11_redraw_game(struct app_state *state);
-/*
- * Helpers for drawing window icons in various sizes. The tileXX functions
- * draw one (out of 9) tiles at a particular size using a particular colour
- * set. Call for each tile position to draw a complete icon.
- */
-
-enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX };
-#define EWMH_ICON_NELEM (2+16*16 + 2+24*24 + 2+32*32 + 2+48*48)
-
-void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
-void ewmh_tile24(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
-void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
-void ewmh_tile48(unsigned long *icon, const XColor *c, int tile_x, int tile_y);
-
-/*
- * Allocate storage for the EWMH _NET_WM_ICON array. The sizes array is
- * populated with pointers to the beginning of each icon's pixel data. For
- * example, sizes[ICON_24x24] points to the first pixel of the 24x24 image.
- *
- * The returned value can then be passed to XChangeProperty to set the icon,
- * (use EWMH_ICON_NELEM for the number of elements) and must be freed by the
- * caller.
- */
-void *ewmh_icon_alloc(unsigned long **sizes);
-
-/*
- * Check if the root window indicates support for EWMH icons. Returns 1 if
- * supported, or 0 otherwise.
- */
-int ewmh_probe_wm_icon(Widget shell);
-
#endif
#include <stdlib.h>
#include <string.h>
#include <assert.h>
-#include <X11/Intrinsic.h>
-#include "motif.h"
+
+#include "ewmhicon.h"
static const char *progname = "ewmhicon";