]> git.draconx.ca Git - rrace.git/commitdiff
Allow compilation without X11.
authorNick Bowler <nbowler@draconx.ca>
Tue, 8 Mar 2022 04:35:22 +0000 (23:35 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 9 Mar 2022 02:10:39 +0000 (21:10 -0500)
At the moment this means nothing useful gets installed, but "make check"
is possible.  The icon functions being tested don't _really_ depend on
X11, just the XColor structure for which we can supply a suitable
definition.

Makefile.am
configure.ac
src/ewmhicon.c
src/ewmhicon.h [new file with mode: 0644]
src/motif.h
t/ewmhicon.c

index e9dd395ed358245c8afa1d8f4abd7b3270cb2b27..9c76dd469e42878c5ed8d5cd90ccd476f9065789 100644 (file)
@@ -17,10 +17,12 @@ AM_CPPFLAGS = -I$(builddir)/src -I$(srcdir)/src -I$(DX_BASEDIR)/src \
               -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)
@@ -68,10 +70,12 @@ EXTRA_DIST += $(DX_BASEDIR)/scripts/gen-tree.awk $(GUIFILES)
 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
index 88c9db9a2a11f83fada79fce250dcca40e6528e4..946fb53f639daea7b5211585f147b61d2f6a2d5a 100644 (file)
@@ -41,7 +41,9 @@ AS_IF([test x"$with_x" = x"yes" && test "$dx_cv_have_motif" != x"yes"],
 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
index e071ceceb9a3b24f54fc953b414e4fc227b34cb6..32392a802df6af414a2bafbae25b937d7ef7f30f 100644 (file)
 #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)
 {
@@ -143,6 +145,39 @@ void ewmh_tile48(unsigned long *icon, const XColor *c, int tile_x, int tile_y)
        }
 }
 
+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);
@@ -154,12 +189,12 @@ int ewmh_probe_wm_icon(Widget 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)
@@ -177,28 +212,4 @@ int ewmh_probe_wm_icon(Widget shell)
        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
diff --git a/src/ewmhicon.h b/src/ewmhicon.h
new file mode 100644 (file)
index 0000000..cd006c3
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * _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
index 74893d15a2f2b4b07dc81d11ffb0260368968dac..5c4d05fdf69d0326f4f0c29df2d71eb1e7546f97 100644 (file)
 #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;
 
@@ -43,35 +42,4 @@ void x11_redraw_icon(struct app_state *state, Widget shell);
 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
index e088d4104f1203958e26afc1978500929cc711f5..88ecfed436efd136a992e03c3f5eb4ab8ca78a18 100644 (file)
@@ -24,8 +24,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
-#include <X11/Intrinsic.h>
-#include "motif.h"
+
+#include "ewmhicon.h"
 
 static const char *progname = "ewmhicon";