diff -Naur wmhdaps-0.04/wmhdaps/Makefile wmhdaps-0.04.netbsd/wmhdaps/Makefile --- wmhdaps-0.04/wmhdaps/Makefile 2006-05-01 11:42:20.000000000 +0200 +++ wmhdaps-0.04.netbsd/wmhdaps/Makefile 2007-08-27 23:20:46.000000000 +0200 @@ -1,15 +1,14 @@ CC = gcc -OS = -DLINUX +#OS = -DLINUX -LIBDIR = -L/usr/X11R6/lib -LIBDIR = -L/usr/X11R6/lib -INCDIR = -I/usr/X11R6/share/include +LIBDIR = -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib +INCDIR = -I/usr/pkg/include # Edit OSLIBS as appropriate to include OS specific libraries. OSLIBS = LIBS = -lXpm -lXext -lX11 -lm $(OSLIBS) -CFLAGS = -Wall -O2 $(OS) +CFLAGS = -Wall -O2 OBJS = wmhdaps.o \ ../wmgeneral/wmgeneral.o \ @@ -20,7 +19,7 @@ $(CC) $(CFLAGS) $(INCDIR) -c $< -o $*.o wmhdaps: $(OBJS) - $(CC) -o wmhdaps $^ -lXext $(LIBDIR) $(LIBS) + $(CC) -o wmhdaps $(OBJS) -lXext $(LIBDIR) $(LIBS) all:: wmhdaps diff -Naur wmhdaps-0.04/wmhdaps/wmhdaps.c wmhdaps-0.04.netbsd/wmhdaps/wmhdaps.c --- wmhdaps-0.04/wmhdaps/wmhdaps.c 2006-05-01 12:04:01.000000000 +0200 +++ wmhdaps-0.04.netbsd/wmhdaps/wmhdaps.c 2008-04-18 16:51:15.000000000 +0200 @@ -63,8 +63,11 @@ #include #include -#ifdef FREEBSD +#if defined(__FreeBSD__) #include +#elif defined(__NetBSD__) +#include +#include #endif #include "../wmgeneral/wmgeneral.h" @@ -150,14 +153,14 @@ float lum_vector[3] = { 0, 0, 100 }; // Lightsource vector -#ifdef FREEBSD +#if defined(__FreeBSD__) static kvm_t *kd; static struct nlist nlst[] = { {"_cp_time"}, {0} }; #endif #define UPDATE_THRESHOLD 4 -#if !defined(FREEBSD) +#if defined(__linux__) #define SYSFS_POSITION_FILE "/sys/devices/platform/hdaps/position" #define BUF_LEN 32 #else @@ -165,6 +168,10 @@ #define BUF_LEN (2*sizeof(int)) #endif /* !defined(FREEBSD) */ +#if defined(__NetBSD__) +static int read_data(int fd, int sensor, envsys_tre_data_t * data); +#endif + static int rest_x; static int rest_y; @@ -182,26 +189,32 @@ */ static int read_position (int *x, int *y) { -#if !defined(FREEBSD) - char buf[BUF_LEN]; -#else + int fd; +#if defined(__linux__) int buf[2]; -#endif /* !defined(FREEBSD) */ +#elif defined(__FreeBSD__) + char buf[BUF_LEN]; +#elif defined(__NetBSD__) + envsys_basic_info_t info; + envsys_tre_data_t data; + int i; +#endif - int fd, ret; + int ret; +#if defined(__linux__) || defined(__FreeBSD__) //read_again: memset(buf, 0, sizeof(buf)); fd = open (SYSFS_POSITION_FILE, O_RDONLY); if (fd < 0) { - perror ("open"); + perror (SYSFS_POSITION_FILE); return fd; } ret = read (fd, buf, BUF_LEN); if (ret < 0) { - perror ("read"); + perror (SYSFS_POSITION_FILE); goto out; } else if (ret == 0) { fprintf (stderr, "error: unexpectedly read zero!\n"); @@ -209,18 +222,55 @@ goto out; } ret = 0; +#elif defined(__NetBSD__) + fd = open (_PATH_SYSMON, O_RDONLY); + if (fd < 0) { + perror (_PATH_SYSMON); + return fd; + } + ret = 0; +#endif -#if !defined(FREEBSD) +#if defined(__linux__) if (sscanf (buf, "(%d,%d)\n", x, y) != 2) { - fprintf( stderr, "sscanf() error!\n" ); + fprintf (stderr, "sscanf() error!\n" ); ret = 1; } -#else +#elif defined(__FreeBSD__) *x = buf[0]; *y = buf[1]; -#endif /* !defined(FREEBSD) */ +#elif defined(__NetBSD__) + for(i = 0; i >= 0; i++) + { + memset(&info, 0, sizeof(info)); + info.sensor = i; + if (ioctl(fd, ENVSYS_GTREINFO, &info) == -1) { + fprintf (stderr, "ioctl() error!\n"); + ret = 1; + break; + } + if (!(info.validflags & ENVSYS_FVALID)) + break; + if (strcmp("Y_VAR", info.desc) == 0 + && read_data(fd, i, &data) == 0 + && data.validflags & ENVSYS_FCURVALID) + { + *x = -data.cur.data_us; + continue; + } + if (strcmp("X_VAR", info.desc) == 0 + && read_data(fd, i, &data) == 0 + && data.validflags & ENVSYS_FCURVALID) + { + *y = -data.cur.data_us; + continue; + } + } +#endif +#if defined(__linux__) || defined(__FreeBSD__) out: +#endif if (close (fd)) perror ("close"); @@ -229,6 +279,19 @@ return ret; } +#if defined(__NetBSD__) +static int read_data(int fd, int sensor, envsys_tre_data_t * data) +{ + memset (data, 0, sizeof(*data)); + data->sensor = sensor; + if (ioctl(fd, ENVSYS_GTREDATA, data) == -1) { + fprintf (stderr, "ioctl() error!\n"); + return 1; + } + return !(data->validflags & ENVSYS_FVALID); +} +#endif + static int check_for_update (int *val_x, int *val_y) { int ret, x, y, do_update = 0; @@ -431,11 +494,13 @@ int cube_color = 1; int c = 0; double treshold = 15.0; -#if !defined(FREEBSD) +#if defined(__linux__) char device[256] = "hda"; -#else +#elif defined(__FreeBSD__) char device[256] = "ad0"; -#endif /* !defined(FREEBSD) */ +#elif defined(__NetBSD__) + char device[256] = "wd0"; +#endif pname = strrchr(argv[0], '/'); if (pname == NULL) pname = argv[0];