From 2679d213fe4eae9f00a496c9b5fa2a67c85e78e1 Mon Sep 17 00:00:00 2001 From: Hamish Moffatt Date: Sun, 6 Jan 2002 13:02:15 +0100 Subject: Import libstroke_0.5.1.orig.tar.gz [dgit import orig libstroke_0.5.1.orig.tar.gz] --- tests/Makefile.am | 29 ++++ tests/Makefile.in | 361 ++++++++++++++++++++++++++++++++++++++++++ tests/gnome_stroke_test.c | 117 ++++++++++++++ tests/stroke_test.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++ tests/stroke_test.tcl | 11 ++ 5 files changed, 914 insertions(+) create mode 100644 tests/Makefile.am create mode 100644 tests/Makefile.in create mode 100644 tests/gnome_stroke_test.c create mode 100644 tests/stroke_test.c create mode 100755 tests/stroke_test.tcl (limited to 'tests') diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..0e402f5 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,29 @@ +## Process this file with automake to produce Makefile.in + +if HAVE_LIBGTK +GSTROKETEST = gnome_stroke_test +else +GSTROKETEST = +endif + + +noinst_PROGRAMS = stroke_test $(GSTROKETEST) #gstroke_conf + +# don't forget all *.h files */ +stroke_test_SOURCES = stroke_test.c #gstroke_conf.c +gnome_stroke_test_SOURCES = gnome_stroke_test.c + +INCLUDES = -I$(top_srcdir)/libstroke -I$(top_srcdir)/libgstroke \ + @X_CFLAGS@ @GTK_CFLAGS@ + +stroke_test_LDADD = ../libstroke/libstroke.la @X_LDFLAGS@ +gnome_stroke_test_LDADD = ../libgstroke/libgstroke.la @GTK_LIBS@ +#gstroke_conf_LDADD = ../libstroke/libgstroke.la @X_LDFLAGS@ + +EXTRA_DIST = stroke_test.tcl + +MOSTLYCLEANFILES = core *~ +CLEANFILES = core *~ +DISTCLEANFILES = core *~ +MAINTAINERCLEANFILES = core *~ + diff --git a/tests/Makefile.in b/tests/Makefile.in new file mode 100644 index 0000000..0888fc6 --- /dev/null +++ b/tests/Makefile.in @@ -0,0 +1,361 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +DLLTOOL = @DLLTOOL@ +GTK_CFLAGS = @GTK_CFLAGS@ +GTK_CONFIG = @GTK_CONFIG@ +GTK_LIBS = @GTK_LIBS@ +LD = @LD@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NM = @NM@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +USE_SYMBOL_UNDERSCORE = @USE_SYMBOL_UNDERSCORE@ +VERSION = @VERSION@ +X_CFLAGS = @X_CFLAGS@ +X_LDFLAGS = @X_LDFLAGS@ +@HAVE_LIBGTK_TRUE@GSTROKETEST = gnome_stroke_test +@HAVE_LIBGTK_FALSE@GSTROKETEST = + +noinst_PROGRAMS = stroke_test $(GSTROKETEST) #gstroke_conf + +# don't forget all *.h files */ +stroke_test_SOURCES = stroke_test.c #gstroke_conf.c +gnome_stroke_test_SOURCES = gnome_stroke_test.c + +INCLUDES = -I$(top_srcdir)/libstroke -I$(top_srcdir)/libgstroke @X_CFLAGS@ @GTK_CFLAGS@ + + +stroke_test_LDADD = ../libstroke/libstroke.la @X_LDFLAGS@ +gnome_stroke_test_LDADD = ../libgstroke/libgstroke.la @GTK_LIBS@ +#gstroke_conf_LDADD = ../libstroke/libgstroke.la @X_LDFLAGS@ + +EXTRA_DIST = stroke_test.tcl + +MOSTLYCLEANFILES = core *~ +CLEANFILES = core *~ +DISTCLEANFILES = core *~ +MAINTAINERCLEANFILES = core *~ +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../config.h +CONFIG_CLEAN_FILES = +PROGRAMS = $(noinst_PROGRAMS) + + +DEFS = @DEFS@ -I. -I$(srcdir) -I.. +CPPFLAGS = @CPPFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBS = @LIBS@ +X_LIBS = @X_LIBS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_PRE_LIBS = @X_PRE_LIBS@ +stroke_test_OBJECTS = stroke_test.o +stroke_test_DEPENDENCIES = ../libstroke/libstroke.la +stroke_test_LDFLAGS = +gnome_stroke_test_OBJECTS = gnome_stroke_test.o +gnome_stroke_test_DEPENDENCIES = ../libgstroke/libgstroke.la +gnome_stroke_test_LDFLAGS = +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +DEP_FILES = .deps/gnome_stroke_test.P .deps/stroke_test.P +SOURCES = $(stroke_test_SOURCES) $(gnome_stroke_test_SOURCES) +OBJECTS = $(stroke_test_OBJECTS) $(gnome_stroke_test_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .lo .o .s +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu tests/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-noinstPROGRAMS: + +clean-noinstPROGRAMS: + -test -z "$(noinst_PROGRAMS)" || rm -f $(noinst_PROGRAMS) + +distclean-noinstPROGRAMS: + +maintainer-clean-noinstPROGRAMS: + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +stroke_test: $(stroke_test_OBJECTS) $(stroke_test_DEPENDENCIES) + @rm -f stroke_test + $(LINK) $(stroke_test_LDFLAGS) $(stroke_test_OBJECTS) $(stroke_test_LDADD) $(LIBS) + +gnome_stroke_test: $(gnome_stroke_test_OBJECTS) $(gnome_stroke_test_DEPENDENCIES) + @rm -f gnome_stroke_test + $(LINK) $(gnome_stroke_test_LDFLAGS) $(gnome_stroke_test_OBJECTS) $(gnome_stroke_test_LDADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = tests + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu tests/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done + +DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :) + +-include $(DEP_FILES) + +mostlyclean-depend: + +clean-depend: + +distclean-depend: + -rm -rf .deps + +maintainer-clean-depend: + +%.o: %.c + @echo '$(COMPILE) -c $<'; \ + $(COMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-cp .deps/$(*F).pp .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm .deps/$(*F).pp + +%.lo: %.c + @echo '$(LTCOMPILE) -c $<'; \ + $(LTCOMPILE) -Wp,-MD,.deps/$(*F).pp -c $< + @-sed -e 's/^\([^:]*\)\.o[ ]*:/\1.lo \1.o :/' \ + < .deps/$(*F).pp > .deps/$(*F).P; \ + tr ' ' '\012' < .deps/$(*F).pp \ + | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \ + >> .deps/$(*F).P; \ + rm -f .deps/$(*F).pp +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: +uninstall: uninstall-am +all-am: Makefile $(PROGRAMS) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + + +mostlyclean-generic: + -test -z "$(MOSTLYCLEANFILES)" || rm -f $(MOSTLYCLEANFILES) + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + -test -z "$(DISTCLEANFILES)" || rm -f $(DISTCLEANFILES) + +maintainer-clean-generic: + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +mostlyclean-am: mostlyclean-noinstPROGRAMS mostlyclean-compile \ + mostlyclean-libtool mostlyclean-tags mostlyclean-depend \ + mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-noinstPROGRAMS clean-compile clean-libtool clean-tags \ + clean-depend clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-noinstPROGRAMS distclean-compile \ + distclean-libtool distclean-tags distclean-depend \ + distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-noinstPROGRAMS \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-tags maintainer-clean-depend \ + maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-noinstPROGRAMS distclean-noinstPROGRAMS \ +clean-noinstPROGRAMS maintainer-clean-noinstPROGRAMS \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile mostlyclean-libtool distclean-libtool \ +clean-libtool maintainer-clean-libtool tags mostlyclean-tags \ +distclean-tags clean-tags maintainer-clean-tags distdir \ +mostlyclean-depend distclean-depend clean-depend \ +maintainer-clean-depend info-am info dvi-am dvi check check-am \ +installcheck-am installcheck install-exec-am install-exec \ +install-data-am install-data install-am install uninstall-am uninstall \ +all-redirect all-am all installdirs mostlyclean-generic \ +distclean-generic clean-generic maintainer-clean-generic clean \ +mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/tests/gnome_stroke_test.c b/tests/gnome_stroke_test.c new file mode 100644 index 0000000..a44b012 --- /dev/null +++ b/tests/gnome_stroke_test.c @@ -0,0 +1,117 @@ +/* GTK+ stroke test program + Copyright (c) 2000, 2001 Dan Nicolaescu + See the file COPYING for distribution information. +*/ + +#include "config.h" + +#include +#include +#include +#include "gstroke.h" + +static gint +delete_event (GtkWidget *widget, GdkEvent *event G_GNUC_UNUSED, gpointer data G_GNUC_UNUSED) +{ + gtk_widget_destroy (widget); + gtk_main_quit (); + return TRUE; +} + +static void +clear_clicked (GtkWidget *widget G_GNUC_UNUSED, gpointer data) +{ + gdk_window_clear (GTK_WIDGET (data)->window); +} + +static void +exit_clicked (GtkWidget *widget G_GNUC_UNUSED, gpointer data) +{ + gtk_widget_destroy (GTK_WIDGET (data)); + gtk_main_quit (); +} + +static void +gstroke_exit (GtkWidget *widget G_GNUC_UNUSED) +{ + gtk_main_quit (); +} + +static void +gstroke_clear (GtkWidget *widget) +{ + gdk_window_clear (widget->window); +} + +static void +gstroke_help (GtkWidget *widget G_GNUC_UNUSED) +{ + printf ("-----\nStroke 456 clears the screen\n"); + printf ("Stroke 654 exits the program\n"); + printf ("Stroke 4123658 displays the help message\n------\n"); +} + + +int +main (int argc, char **argv) +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *da; + GtkWidget *hbox; + GtkWidget *button; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "GNOME-stroke test program"); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + (GtkSignalFunc) delete_event, + NULL); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show (vbox); + + da = gtk_drawing_area_new (); + gtk_widget_set_events (GTK_WIDGET (da), GDK_BUTTON_PRESS_MASK + | GDK_BUTTON_RELEASE_MASK); + gtk_drawing_area_size (GTK_DRAWING_AREA (da), 600, 600); + + + /* The sequence below shows how to use libgstroke */ + gstroke_enable (da); + gstroke_signal_connect (da, "654", (GtkSignalFunc)gstroke_exit, NULL); + gstroke_signal_connect (da, "456", (GtkSignalFunc)gstroke_clear, NULL); + gstroke_signal_connect (da, "4123658", (GtkSignalFunc)gstroke_help, NULL); + + gtk_box_pack_start (GTK_BOX (vbox), da, TRUE, TRUE, 0); + gtk_widget_show (da); + + hbox = gtk_hbox_new (TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + button = gtk_button_new_with_label ("Clear stroke test area"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + (GtkSignalFunc) clear_clicked, + da); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + button = gtk_button_new_with_label ("Exit"); + gtk_signal_connect (GTK_OBJECT (button), "clicked", + (GtkSignalFunc) exit_clicked, + window); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + gtk_widget_show (window); + + /*hack: call the help function to display the help message*/ + + gstroke_help (window); + + gtk_main (); + return 0; +} diff --git a/tests/stroke_test.c b/tests/stroke_test.c new file mode 100644 index 0000000..d716257 --- /dev/null +++ b/tests/stroke_test.c @@ -0,0 +1,396 @@ +/* + libstroke - an X11 stroke interface library + Copyright (c) 1996,1997,1998,1999,2001 Mark F. Willey, ETLA Technical + + See the files COPYRIGHT and LICENSE for distribution information. + +*/ + +/* + This test program was modified from the xev program. + The following is a copy of the copyright for the xev program: +*/ + +/* + +Copyright (c) 1988 X Consortium + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the X Consortium shall +not be used in advertising or otherwise to promote the sale, use or +other dealings in this Software without prior written authorization +from the X Consortium. + +* xev author: Jim Fulton, MIT X Consortium +*/ + +#include "config.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "stroke.h" + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +void set_sizehints (XSizeHints *hintp, + int min_width, int min_height, int defwidth, + int defheight, int defx, int defy, char *geom); +void do_ButtonPress (XEvent *eventp); +void do_ButtonPress (XEvent *eventp); +void do_ButtonRelease (XEvent *eventp); +void do_MotionNotify (XEvent *eventp); + + + +// send motion events to the stroek_record function? +int send_motion; + +#define WINDOW_MIN_WIDTH 500 +#define WINDOW_MIN_HEIGHT 500 +#define WINDOW_DEF_WIDTH (WINDOW_MIN_WIDTH + 100) +#define WINDOW_DEF_HEIGHT (WINDOW_MIN_HEIGHT + 100) +#define WINDOW_DEF_X 100 +#define WINDOW_DEF_Y 100 + + +typedef unsigned long Pixel; + +char *Yes = "YES"; +char *No = "NO"; +char *Unknown = "unknown"; + +char *ProgramName; +Display *dpy; +int screen; + +int +usage (void) +{ + static char *msg[] = { +" -display displayname X server to contact", +" -geometry geom size and location of window", +" -bw pixels border width in pixels", +" -bs {NotUseful,WhenMapped,Always} backingstore attribute", +" -id windowid use existing window", +" -s set save-unders attribute", +" -name string window name", +" -rv reverse video", +"", +NULL}; + char **cpp; + + fprintf (stderr, "usage: %s [-options ...]\n", ProgramName); + fprintf (stderr, "where options include:\n"); + + for (cpp = msg; *cpp; cpp++) { + fprintf (stderr, "%s\n", *cpp); + } + + exit (1); +} + +static int +parse_backing_store (char *s) +{ + int len = strlen (s); + char *cp; + + for (cp = s; *cp; cp++) { + if (isascii (*cp) && isupper (*cp)) *cp = tolower (*cp); + } + + if (strncmp (s, "notuseful", len) == 0) return (NotUseful); + if (strncmp (s, "whenmapped", len) == 0) return (WhenMapped); + if (strncmp (s, "always", len) == 0) return (Always); + + return usage (); +} + +char sequence[STROKE_MAX_SEQUENCE+1]; + +int +main (int argc, char **argv) +{ + char *displayname = NULL; + char *geom = NULL; + int i; + XSizeHints hints; + int borderwidth = 2; + Window w; + XSetWindowAttributes attr; + XWindowAttributes wattr; + unsigned long mask = 0L; + int done; + char *name = "Stroke Tester"; + Bool reverse = False; + unsigned long back, fore; + send_motion = FALSE; + w = 0; + ProgramName = argv[0]; + for (i = 1; i < argc; i++) { + char *arg = argv[i]; + + if (arg[0] == '-') { + switch (arg[1]) { + case 'd': /* -display host:dpy */ + if (++i >= argc) usage (); + displayname = argv[i]; + continue; + case 'g': /* -geometry geom */ + if (++i >= argc) usage (); + geom = argv[i]; + continue; + case 'b': + switch (arg[2]) { + case 'w': /* -bw pixels */ + if (++i >= argc) usage (); + borderwidth = atoi (argv[i]); + continue; + case 's': /* -bs type */ + if (++i >= argc) usage (); + attr.backing_store = parse_backing_store (argv[i]); + mask |= CWBackingStore; + continue; + default: + usage (); + } + case 'i': /* -id */ + if (++i >= argc) usage (); + sscanf(argv[i], "0x%lx", &w); + if (!w) + sscanf(argv[i], "%ld", &w); + if (!w) + usage (); + continue; + case 'n': /* -name */ + if (++i >= argc) usage (); + name = argv[i]; + continue; + case 'r': /* -rv */ + reverse = True; + continue; + case 's': /* -s */ + attr.save_under = True; + mask |= CWSaveUnder; + continue; + default: + usage (); + } /* end switch on - */ + } else + usage (); + } /* end for over argc */ + + dpy = XOpenDisplay (displayname); + if (!dpy) { + fprintf (stderr, "%s: unable to open display '%s'\n", + ProgramName, XDisplayName (displayname)); + exit (1); + } + + screen = DefaultScreen (dpy); + + /* select for all events */ + attr.event_mask = ButtonPressMask | + ButtonReleaseMask | + PointerMotionMask | + Button1MotionMask | + Button2MotionMask | + Button3MotionMask | + Button4MotionMask | + Button5MotionMask | + ButtonMotionMask | + OwnerGrabButtonMask; + + if (w) { + XGetWindowAttributes(dpy, w, &wattr); + if (wattr.all_event_masks & ButtonPressMask) + attr.event_mask &= ~ButtonPressMask; + attr.event_mask &= ~SubstructureRedirectMask; + XSelectInput(dpy, w, attr.event_mask); + } else { + set_sizehints (&hints, WINDOW_MIN_WIDTH, WINDOW_MIN_HEIGHT, + WINDOW_DEF_WIDTH, WINDOW_DEF_HEIGHT, + WINDOW_DEF_X, WINDOW_DEF_Y, geom); + + if (reverse) { + back = BlackPixel(dpy,screen); + fore = WhitePixel(dpy,screen); + } else { + back = WhitePixel(dpy,screen); + fore = BlackPixel(dpy,screen); + } + + attr.background_pixel = back; + attr.border_pixel = fore; + mask |= (CWBackPixel | CWBorderPixel | CWEventMask); + + w = XCreateWindow (dpy, RootWindow (dpy, screen), hints.x, hints.y, + hints.width, hints.height, borderwidth, 0, + InputOutput, (Visual *)CopyFromParent, + mask, &attr); + + XSetStandardProperties (dpy, w, name, NULL, (Pixmap) 0, + argv, argc, &hints); + + XMapWindow (dpy, w); + + // initialize stroke library routines +#ifdef STROKE_MOUSE_FOOTPRINTS + stroke_init_with_mouse_footprints (dpy, w); +#else + stroke_init (); +#endif + + } + + for (done = 0; !done; ) { + XEvent event; + + XNextEvent (dpy, &event); + + switch (event.type) { + case ButtonPress: + do_ButtonPress (&event); + break; + case ButtonRelease: + do_ButtonRelease (&event); + break; + case MotionNotify: + do_MotionNotify (&event); + break; + default: + printf ("Unknown event type %d\n", event.type); + break; + } + } + + XCloseDisplay (dpy); + exit (0); +} + +void +do_ButtonPress (eventp) + XEvent *eventp; +{ + XButtonEvent *e = (XButtonEvent *) eventp; + + // begin recording points in stroke + if (e->button == 2) + send_motion = TRUE; + + return; +} + +void +do_ButtonRelease (eventp) + XEvent *eventp; +{ + XButtonEvent *e = (XButtonEvent *) eventp; + + // if it's button 2, translate the stroke + if (e->button == 2) { + send_motion = FALSE; + + if (stroke_trans (sequence) == TRUE) + printf ("Translation succeeded: "); + else + printf ("Translation failed: "); + printf ("Sequence=\"%s\"\n",sequence); + } + + return; +} + +void +do_MotionNotify (eventp) + XEvent *eventp; +{ + XMotionEvent *e = (XMotionEvent *) eventp; + + // if button 2 is down, record the point in the stroke + if (send_motion == TRUE) { + stroke_record (e->x,e->y); + } + + return; +} + +void +set_sizehints (hintp, min_width, min_height, + defwidth, defheight, defx, defy, geom) + XSizeHints *hintp; + int min_width, min_height, defwidth, defheight, defx, defy; + char *geom; +{ + int geom_result; + + /* set the size hints, algorithm from xlib xbiff */ + + hintp->width = hintp->min_width = min_width; + hintp->height = hintp->min_height = min_height; + hintp->flags = PMinSize; + hintp->x = hintp->y = 0; + geom_result = NoValue; + if (geom != NULL) { + geom_result = XParseGeometry (geom, &hintp->x, &hintp->y, + (unsigned int *)&hintp->width, + (unsigned int *)&hintp->height); + if ((geom_result & WidthValue) && (geom_result & HeightValue)) { +#define max(a,b) ((a) > (b) ? (a) : (b)) + hintp->width = max (hintp->width, hintp->min_width); + hintp->height = max (hintp->height, hintp->min_height); + hintp->flags |= USSize; + } + if ((geom_result & XValue) && (geom_result & YValue)) { + hintp->flags += USPosition; + } + } + if (!(hintp->flags & USSize)) { + hintp->width = defwidth; + hintp->height = defheight; + hintp->flags |= PSize; + } +/* + if (!(hintp->flags & USPosition)) { + hintp->x = defx; + hintp->y = defy; + hintp->flags |= PPosition; + } + */ + if (geom_result & XNegative) { + hintp->x = DisplayWidth (dpy, DefaultScreen (dpy)) + hintp->x - + hintp->width; + } + if (geom_result & YNegative) { + hintp->y = DisplayHeight (dpy, DefaultScreen (dpy)) + hintp->y - + hintp->height; + } + return; +} diff --git a/tests/stroke_test.tcl b/tests/stroke_test.tcl new file mode 100755 index 0000000..4da736d --- /dev/null +++ b/tests/stroke_test.tcl @@ -0,0 +1,11 @@ +#!/usr/bin/wish +# stroke_test.tcl +# A clone of stroke_test using Tcl/Tk, which is far shorter than the +# plain C version. Long live Tcl/Tk! +# By Chris Laas, chrisl@cybercom.net. +# This file falls under the copyright of libstroke. + +load ../libstroke/.libs/libstroke_tcl.so.0.2 +bind . <2> { stroke record %x %y } +bind . { stroke record %x %y } +bind . { puts [stroke translate] } -- cgit v1.2.3