diff --git a/.gitignore b/.gitignore index bc40ffa..1bb2f49 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ *.so.* spnav_config.h Makefile +examples/cube/cube +examples/simple/simple_af_unix +examples/simple/simple_x11 diff --git a/Makefile.in b/Makefile.in index 7914af3..e6933af 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,11 +1,11 @@ - -obj = spnav.o $(magellan_obj) -hdr = spnav.h spnav_magellan.h spnav_config.h +src = $(sort $(wildcard src/*.c)) +obj = $(src:.c=.o) +pubhdr = $(wildcard include/*.h) name = spnav lib_a = lib$(name).a -incpaths = -I. -I/usr/local/include -I/usr/X11R6/include +incpaths = -Iinclude -Isrc -I/usr/local/include -I/usr/X11R6/include libpaths = -L/usr/local/lib -L/usr/X11R6/lib CC = gcc @@ -48,7 +48,7 @@ distclean: rm -f $(obj) $(lib_a) $(lib_so) Makefile .PHONY: install -install: $(lib_a) $(lib_so) $(hdr) +install: $(lib_a) $(lib_so) $(pubhdr) mkdir -p $(DESTDIR)$(PREFIX)/$(libdir) $(DESTDIR)$(PREFIX)/include cp $(lib_a) $(DESTDIR)$(PREFIX)/$(libdir)/$(lib_a) cp $(lib_so) $(DESTDIR)$(PREFIX)/$(libdir)/$(lib_so) @@ -57,7 +57,7 @@ install: $(lib_a) $(lib_so) $(hdr) ln -s $(DESTDIR)$(PREFIX)/$(libdir)/$(lib_so) $(DESTDIR)$(PREFIX)/$(libdir)/$(soname) && \ ln -s $(DESTDIR)$(PREFIX)/$(libdir)/$(soname) $(DESTDIR)$(PREFIX)/$(libdir)/$(devlink) || \ true - for h in $(hdr); do cp -p $(srcdir)/$$h $(DESTDIR)$(PREFIX)/include/; done + for h in $(pubhdr); do cp -p $(srcdir)/$$h $(DESTDIR)$(PREFIX)/include/; done .PHONY: uninstall uninstall: @@ -66,5 +66,5 @@ uninstall: [ -n "$(soname)" ] && \ rm -f $(DESTDIR)$(PREFIX)/$(libdir)/$(soname) $(DESTDIR)$(PREFIX)/$(libdir)/$(devlink) || \ true - for i in $(hdr); do rm -f $(DESTDIR)$(PREFIX)/include/$$i; done + for i in $(pubhdr); do rm -f $(DESTDIR)$(PREFIX)/include/$$i; done diff --git a/configure b/configure index 6f85fec..974e7ae 100755 --- a/configure +++ b/configure @@ -91,22 +91,22 @@ if [ "$OPT" = 'yes' ]; then fi if [ "$X11" = 'yes' ]; then - echo 'magellan_obj = spnav_magellan.o' >>Makefile echo 'xlib = -lX11' >>Makefile fi cat "$srcdir/Makefile.in" >>Makefile # create spnav_config.h +cfghdr=include/spnav_config.h echo 'creating spnav_config.h ...' -echo '#ifndef SPNAV_CONFIG_H_' >spnav_config.h -echo '#define SPNAV_CONFIG_H_' >>spnav_config.h -echo '' >>spnav_config.h +echo '#ifndef SPNAV_CONFIG_H_' >$cfghdr +echo '#define SPNAV_CONFIG_H_' >>$cfghdr +echo '' >>$cfghdr if [ "$X11" = 'yes' ]; then - echo '#define USE_X11' >>spnav_config.h - echo '' >>spnav_config.h + echo '#define USE_X11' >>$cfghdr + echo '' >>$cfghdr fi -echo '#endif /* SPNAV_CONFIG_H_ */' >>spnav_config.h +echo '#endif /* SPNAV_CONFIG_H_ */' >>$cfghdr #done echo '' diff --git a/spnav.h b/include/spnav.h similarity index 99% rename from spnav.h rename to include/spnav.h index 28293b7..be6f322 100644 --- a/spnav.h +++ b/include/spnav.h @@ -148,7 +148,7 @@ enum { SPNAV_GET_HAVE_DISP, /* int: non-zero if the device has a display */ SPNAV_GET_DISP_XRES, /* int: display horizontal resolution */ SPNAV_GET_DISP_YRES, /* int: display vertical resolution */ - SPNAV_GET_DISP_COLORS, /* int: display number of colors */ + SPNAV_GET_DISP_COLORS /* int: display number of colors */ }; int spnav_get_int(int query, int *res); int spnav_get_str(int query, char *buf, int bufsz); diff --git a/spnav_magellan.h b/include/spnav_magellan.h similarity index 100% rename from spnav_magellan.h rename to include/spnav_magellan.h diff --git a/src/inpsrc.h b/src/inpsrc.h new file mode 100644 index 0000000..7cccdbb --- /dev/null +++ b/src/inpsrc.h @@ -0,0 +1,68 @@ +/* +This file is part of libspnav, part of the spacenav project (spacenav.sf.net) +Copyright (C) 2007-2018 John Tsiombikas + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. +3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT +OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY +OF SUCH DAMAGE. +*/ +/* input source abstraction */ +#ifndef INPSRC_H_ +#define INPSRC_H_ + +struct display; + +struct input_src { + const char *name; /* module name */ + int fd; /* file descriptor for select */ + void *data; /* extra data */ + + struct display *disp; /* display callbacks */ + + int (*open)(struct input_src*); + int (*close)(struct input_src*); + + int (*pending)(struct input_src*); + int (*process)(struct input_src*); + + int (*get_int)(struct input_src*, int*); + int (*get_str)(struct input_src*, char*, int); +}; + +struct display { + struct input_src *inp; + int width, height; + int num_colors; + + void *(*map)(struct display*); + int (*unmap)(struct display*); + + int (*color)(struct display*, unsigned int, unsigned int); + int (*cursor)(struct display*, int, int); + int (*print)(struct display*, const char*); + int (*clear)(struct display*); + int (*rect)(struct display*, int, int, int, int); + int (*fill)(struct display*, int, int, int, int); + int (*line)(struct display*, int, int, int, int); +}; + + +#endif /* INPSRC_H_ */ diff --git a/spnav.c b/src/spnav.c similarity index 99% rename from spnav.c rename to src/spnav.c index e9b2d96..7c08c71 100644 --- a/spnav.c +++ b/src/spnav.c @@ -105,7 +105,7 @@ int spnav_open(void) } proto = 0; - if(conn_unix(s, SPNAVEXT_SOCK_PATH) == -1) { + if(conn_unix(s, SPNAV1_SOCK_PATH) == -1) { proto = 1; if(conn_unix(s, SPNAV_SOCK_PATH) == -1) { perror("failed to connect"); diff --git a/spnav_magellan.c b/src/spnav_magellan.c similarity index 100% rename from spnav_magellan.c rename to src/spnav_magellan.c