From: Nick Bowler Date: Tue, 8 Mar 2022 04:35:22 +0000 (-0500) Subject: Allow compilation without X11. X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/0a46ad3167e6f87e254288080e3ce89402089afb Allow compilation without X11. 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. --- diff --git a/Makefile.am b/Makefile.am index e9dd395..9c76dd4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/configure.ac b/configure.ac index 88c9db9..946fb53 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/src/ewmhicon.c b/src/ewmhicon.c index e071cec..32392a8 100644 --- a/src/ewmhicon.c +++ b/src/ewmhicon.c @@ -21,9 +21,11 @@ #include #include -#include -#include -#include "motif.h" +#if !X_DISPLAY_MISSING +# include +# include +#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 index 0000000..cd006c3 --- /dev/null +++ b/src/ewmhicon.h @@ -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 . + */ + +#ifndef EWMHICON_H_ +#define EWMHICON_H_ + +/* + * Define X_DISPLAY_MISSING to allow building without X11 (for test purposes) + */ +#if !X_DISPLAY_MISSING +# include +#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 diff --git a/src/motif.h b/src/motif.h index 74893d1..5c4d05f 100644 --- a/src/motif.h +++ b/src/motif.h @@ -20,10 +20,9 @@ #define RRACE_MOTIF_H_ #include +#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 diff --git a/t/ewmhicon.c b/t/ewmhicon.c index e088d41..88ecfed 100644 --- a/t/ewmhicon.c +++ b/t/ewmhicon.c @@ -24,8 +24,8 @@ #include #include #include -#include -#include "motif.h" + +#include "ewmhicon.h" static const char *progname = "ewmhicon";