summaryrefslogtreecommitdiff
path: root/reference/C/X_EXAMPLES
diff options
context:
space:
mode:
Diffstat (limited to 'reference/C/X_EXAMPLES')
-rw-r--r--reference/C/X_EXAMPLES/Makefile.am5
-rw-r--r--reference/C/X_EXAMPLES/Makefile.in410
-rw-r--r--reference/C/X_EXAMPLES/Xref.html55
-rw-r--r--reference/C/X_EXAMPLES/hardware.c63
-rw-r--r--reference/C/X_EXAMPLES/root_colour.c235
-rw-r--r--reference/C/X_EXAMPLES/xxterm.c615
6 files changed, 1383 insertions, 0 deletions
diff --git a/reference/C/X_EXAMPLES/Makefile.am b/reference/C/X_EXAMPLES/Makefile.am
new file mode 100644
index 0000000..142b747
--- /dev/null
+++ b/reference/C/X_EXAMPLES/Makefile.am
@@ -0,0 +1,5 @@
+EXTRA_DIST = $(wildcard *.html) $(wildcard *.c)
+docs_DATA = $(EXTRA_DIST)
+
+docsdir = $(kde_htmldir)/en/kdevelop/$(subdir)
+
diff --git a/reference/C/X_EXAMPLES/Makefile.in b/reference/C/X_EXAMPLES/Makefile.in
new file mode 100644
index 0000000..6c7c98b
--- /dev/null
+++ b/reference/C/X_EXAMPLES/Makefile.in
@@ -0,0 +1,410 @@
+# KDE tags expanded automatically by am_edit - $Revision: 1.2 $
+# Makefile.in generated automatically by automake 1.5 from Makefile.am.
+
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+# 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.
+
+@SET_MAKE@
+
+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
+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@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = @program_transform_name@
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_alias = @build_alias@
+build_triplet = @build@
+host_alias = @host_alias@
+host_triplet = @host@
+target_alias = @target_alias@
+target_triplet = @target@
+AMTAR = @AMTAR@
+ARTSCCONFIG = @ARTSCCONFIG@
+AS = @AS@
+AUTODIRS = @AUTODIRS@
+AWK = @AWK@
+CC = @CC@
+CONF_FILES = @CONF_FILES@
+CPP = @CPP@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+DCOPIDL = @DCOPIDL@
+DCOPIDL2CPP = @DCOPIDL2CPP@
+DCOP_DEPENDENCIES = @DCOP_DEPENDENCIES@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DPMSINC = @DPMSINC@
+DPMSLIB = @DPMSLIB@
+EXEEXT = @EXEEXT@
+GCJ = @GCJ@
+GCJFLAGS = @GCJFLAGS@
+GLINC = @GLINC@
+GLLIB = @GLLIB@
+GMSGFMT = @GMSGFMT@
+IDL = @IDL@
+IDL_DEPENDENCIES = @IDL_DEPENDENCIES@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+JAR = @JAR@
+JAVAC = @JAVAC@
+JAVAH = @JAVAH@
+JVMLIBS = @JVMLIBS@
+KDECONFIG = @KDECONFIG@
+KDE_CXXFLAGS = @KDE_CXXFLAGS@
+KDE_EXTRA_RPATH = @KDE_EXTRA_RPATH@
+KDE_INCLUDES = @KDE_INCLUDES@
+KDE_LDFLAGS = @KDE_LDFLAGS@
+KDE_PLUGIN = @KDE_PLUGIN@
+KDE_RPATH = @KDE_RPATH@
+KDE_USE_CLOSURE_FALSE = @KDE_USE_CLOSURE_FALSE@
+KDE_USE_CLOSURE_TRUE = @KDE_USE_CLOSURE_TRUE@
+KDE_USE_FINAL_FALSE = @KDE_USE_FINAL_FALSE@
+KDE_USE_FINAL_TRUE = @KDE_USE_FINAL_TRUE@
+KDE_XSL_STYLESHEET = @KDE_XSL_STYLESHEET@
+LIBCOMPAT = @LIBCOMPAT@
+LIBCRYPT = @LIBCRYPT@
+LIBDL = @LIBDL@
+LIBGEN = @LIBGEN@
+LIBJPEG = @LIBJPEG@
+LIBMICO = @LIBMICO@
+LIBOBJS = @LIBOBJS@
+LIBPNG = @LIBPNG@
+LIBPTHREAD = @LIBPTHREAD@
+LIBPYTHON = @LIBPYTHON@
+LIBQIMGIO = @LIBQIMGIO@
+LIBRESOLV = @LIBRESOLV@
+LIBSHADOW = @LIBSHADOW@
+LIBSM = @LIBSM@
+LIBSOCKET = @LIBSOCKET@
+LIBTIFF = @LIBTIFF@
+LIBTOOL = @LIBTOOL@
+LIBUCB = @LIBUCB@
+LIBUTIL = @LIBUTIL@
+LIBXINERAMA = @LIBXINERAMA@
+LIBZ = @LIBZ@
+LIB_KAB = @LIB_KAB@
+LIB_KDECORE = @LIB_KDECORE@
+LIB_KDEUI = @LIB_KDEUI@
+LIB_KFILE = @LIB_KFILE@
+LIB_KFM = @LIB_KFM@
+LIB_KFORMULA = @LIB_KFORMULA@
+LIB_KHTML = @LIB_KHTML@
+LIB_KIMGIO = @LIB_KIMGIO@
+LIB_KIO = @LIB_KIO@
+LIB_KPARTS = @LIB_KPARTS@
+LIB_KSPELL = @LIB_KSPELL@
+LIB_KSYCOCA = @LIB_KSYCOCA@
+LIB_KWRITE = @LIB_KWRITE@
+LIB_QT = @LIB_QT@
+LIB_SMB = @LIB_SMB@
+LIB_X11 = @LIB_X11@
+LN_S = @LN_S@
+MCOPIDL = @MCOPIDL@
+MEINPROC = @MEINPROC@
+MICO_INCLUDES = @MICO_INCLUDES@
+MICO_LDFLAGS = @MICO_LDFLAGS@
+MOC = @MOC@
+MSGFMT = @MSGFMT@
+NOOPT_CXXFLAGS = @NOOPT_CXXFLAGS@
+NOREPO = @NOREPO@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PAMLIBS = @PAMLIBS@
+PASSWDLIBS = @PASSWDLIBS@
+PYTHONINC = @PYTHONINC@
+PYTHONLIB = @PYTHONLIB@
+PYTHONMODDIR = @PYTHONMODDIR@
+QT_INCLUDES = @QT_INCLUDES@
+QT_LDFLAGS = @QT_LDFLAGS@
+RANLIB = @RANLIB@
+REPO = @REPO@
+SETUIDFLAGS = @SETUIDFLAGS@
+STRIP = @STRIP@
+TOPSUBDIRS = @TOPSUBDIRS@
+UIC = @UIC@
+UIC_TR = @UIC_TR@
+USER_INCLUDES = @USER_INCLUDES@
+USER_LDFLAGS = @USER_LDFLAGS@
+USE_EXCEPTIONS = @USE_EXCEPTIONS@
+USE_RTTI = @USE_RTTI@
+USE_THREADS = @USE_THREADS@
+VERSION = @VERSION@
+XGETTEXT = @XGETTEXT@
+XPMINC = @XPMINC@
+XPMLIB = @XPMLIB@
+X_EXTRA_LIBS = @X_EXTRA_LIBS@
+X_INCLUDES = @X_INCLUDES@
+X_LDFLAGS = @X_LDFLAGS@
+X_PRE_LIBS = @X_PRE_LIBS@
+all_includes = @all_includes@
+all_libraries = @all_libraries@
+am__include = @am__include@
+am__quote = @am__quote@
+idldir = @idldir@
+install_sh = @install_sh@
+jni_includes = @jni_includes@
+kde_appsdir = @kde_appsdir@
+kde_bindir = @kde_bindir@
+kde_confdir = @kde_confdir@
+kde_datadir = @kde_datadir@
+kde_htmldir = @kde_htmldir@
+kde_icondir = @kde_icondir@
+kde_includes = @kde_includes@
+kde_libraries = @kde_libraries@
+kde_libs_htmldir = @kde_libs_htmldir@
+kde_libs_prefix = @kde_libs_prefix@
+kde_locale = @kde_locale@
+kde_mimedir = @kde_mimedir@
+kde_moduledir = @kde_moduledir@
+kde_qtver = @kde_qtver@
+kde_servicesdir = @kde_servicesdir@
+kde_servicetypesdir = @kde_servicetypesdir@
+kde_sounddir = @kde_sounddir@
+kde_templatesdir = @kde_templatesdir@
+kde_wallpaperdir = @kde_wallpaperdir@
+micodir = @micodir@
+qt_includes = @qt_includes@
+qt_libraries = @qt_libraries@
+x_includes = @x_includes@
+x_libraries = @x_libraries@
+
+EXTRA_DIST = $(wildcard *.html) $(wildcard *.c)
+docs_DATA = $(EXTRA_DIST)
+
+docsdir = $(kde_htmldir)/en/kdevelop/$(subdir)
+subdir = reference/C/X_EXAMPLES
+mkinstalldirs = $(SHELL) $(top_srcdir)/admin/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+DIST_SOURCES =
+DATA = $(docs_DATA)
+
+DIST_COMMON = Makefile.am Makefile.in
+#>- all: all-am
+#>+ 1
+all: docs-am all-am
+
+.SUFFIXES:
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+#>- cd $(top_srcdir) && \
+#>- $(AUTOMAKE) --gnu reference/C/X_EXAMPLES/Makefile
+#>+ 3
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu reference/C/X_EXAMPLES/Makefile
+ cd $(top_srcdir) && perl admin/am_edit reference/C/X_EXAMPLES/Makefile.in
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) && \
+ CONFIG_HEADERS= CONFIG_LINKS= \
+ CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status
+uninstall-info-am:
+install-docsDATA: $(docs_DATA)
+ @$(NORMAL_INSTALL)
+ $(mkinstalldirs) $(DESTDIR)$(docsdir)
+ @list='$(docs_DATA)'; for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ f="`echo $$p | sed -e 's|^.*/||'`"; \
+ echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(docsdir)/$$f"; \
+ $(INSTALL_DATA) $$d$$p $(DESTDIR)$(docsdir)/$$f; \
+ done
+
+uninstall-docsDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(docs_DATA)'; for p in $$list; do \
+ f="`echo $$p | sed -e 's|^.*/||'`"; \
+ echo " rm -f $(DESTDIR)$(docsdir)/$$f"; \
+ rm -f $(DESTDIR)$(docsdir)/$$f; \
+ done
+tags: TAGS
+TAGS:
+
+
+#>- DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+#>+ 4
+KDE_DIST=root_colour.c xxterm.c hardware.c Xref.html
+
+DISTFILES= $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) $(KDE_DIST)
+
+
+top_distdir = ../../..
+distdir = $(top_distdir)/$(PACKAGE)-$(VERSION)
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ if test -f $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ $(mkinstalldirs) "$(distdir)/$$dir"; \
+ fi; \
+ if test -d $$d/$$file; then \
+ cp -pR $$d/$$file $(distdir) \
+ || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(DATA)
+
+installdirs:
+ $(mkinstalldirs) $(DESTDIR)$(docsdir)
+
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+#>- clean: clean-am
+#>+ 1
+clean: kde-rpo-clean clean-am
+
+clean-am: clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+
+distclean-am: clean-am distclean-generic distclean-libtool
+
+dvi: dvi-am
+
+dvi-am:
+
+info: info-am
+
+info-am:
+
+install-data-am: install-docsDATA
+
+install-exec-am:
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-generic mostlyclean-libtool
+
+uninstall-am: uninstall-docsDATA uninstall-info-am
+
+.PHONY: all all-am check check-am clean clean-generic clean-libtool \
+ distclean distclean-generic distclean-libtool distdir dvi \
+ dvi-am info info-am install install-am install-data \
+ install-data-am install-docsDATA install-exec install-exec-am \
+ install-info install-info-am install-man install-strip \
+ installcheck installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-generic \
+ mostlyclean-libtool uninstall uninstall-am uninstall-docsDATA \
+ uninstall-info-am
+
+# 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:
+
+#>+ 2
+docs-am:
+
+#>+ 6
+force-reedit:
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu reference/C/X_EXAMPLES/Makefile
+ cd $(top_srcdir) && perl admin/am_edit reference/C/X_EXAMPLES/Makefile.in
+
+
+#>+ 2
+final:
+ $(MAKE) all-am
+#>+ 2
+final-install:
+ $(MAKE) install-am
+#>+ 2
+no-final:
+ $(MAKE) all-am
+#>+ 2
+no-final-install:
+ $(MAKE) install-am
+#>+ 3
+cvs-clean:
+ $(MAKE) -f $(top_srcdir)/admin/Makefile.common cvs-clean
+
+#>+ 3
+kde-rpo-clean:
+ -rm -f *.rpo
diff --git a/reference/C/X_EXAMPLES/Xref.html b/reference/C/X_EXAMPLES/Xref.html
new file mode 100644
index 0000000..ee40749
--- /dev/null
+++ b/reference/C/X_EXAMPLES/Xref.html
@@ -0,0 +1,55 @@
+<title>X Examples</title>
+<body bgcolor=#f5deb3>
+<hr>
+<center>
+<h1>X Examples</h1>
+</center>
+<hr>
+<p>
+
+The following programs will only run under the 'X Windows' environment,
+they have been tested on Linux running X11R6 and SunOS running X11R5.
+If you are a DOS/Windows user these programs will not compile until
+you junk 'Windows' and install Linux.
+
+<dl compact>
+
+<dt><img src=../../GRAPHICS/computer.gif>
+<a href=hardware.c>A few statistics about your X environment</a>
+
+<dt><img src=../../GRAPHICS/computer.gif>
+<a href=root_colour.c>randomly change the colour of the root window.</a>
+
+<dt><img src=../../GRAPHICS/computer.gif>
+<a href=xxterm.c> A tool for issuing an rlogin to anothe machine. It basicaly
+saves a bit of typing.
+</dl>
+<hr>
+<p>
+<center>
+<table border=2 width=80% bgcolor=ivory>
+<tr align=center>
+<td width=25%>
+<a href="../cref.html" target="_top">Top</a>
+</td><td width=25%>
+<a href="../master_index.html" target="_top">Master Index</a>
+</td><td width=25%>
+<a href="../SYNTAX/keywords.html" target="_top">C Keywords</a>
+</td><td width=25%>
+<a href="../FUNCTIONS/funcref.htm" target="_top">Functions</a>
+</td>
+</tr>
+</table>
+</center>
+<p>
+
+<hr>
+<address>Martin Leslie
+<script language="JavaScript">
+<!-- //
+document.write(document.lastModified);
+// -->
+</script>
+</address>
+
+
diff --git a/reference/C/X_EXAMPLES/hardware.c b/reference/C/X_EXAMPLES/hardware.c
new file mode 100644
index 0000000..bca5b3e
--- /dev/null
+++ b/reference/C/X_EXAMPLES/hardware.c
@@ -0,0 +1,63 @@
+/************************************************************************
+ *
+ * Purpose: Program extracts information from the X server and displays
+ * it on the screen.
+ *
+ * Notes: Use the following command to compile.
+ *
+ * gcc hardware.c -lX11
+ *
+ * Author: M.J. Leslie
+ *
+ * Date: 26-Mar-95
+ *
+ ************************************************************************/
+
+/****************** Includes ********************************************/
+ /* These are in /usr/X386 */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+
+#include <stdio.h>
+
+main()
+{
+ Display * display;
+ int screen;
+ char * display_name=NULL;
+ Window root;
+ Visual* visual;
+
+ /* Connect to X display server. */
+ display=XOpenDisplay(display_name);
+
+ /* Get screen ID */
+ screen=DefaultScreen(display);
+
+
+ printf("\n\tInformation extracted from the X server\n");
+ printf("\t---------------------------------------\n\n");
+
+ printf(" X server by \'%s\'\n", ServerVendor(display));
+
+ printf(" X Server protocol %d\n", ProtocolVersion(display));
+
+ printf(" X server Release %d\n", VendorRelease(display));
+
+ printf(" Screen is %dmm high.\n", DisplayHeightMM(display, screen));
+
+ printf(" Screen is %dmm wide.\n", DisplayWidthMM(display, screen));
+
+ printf(" Screen is %d pixels high.\n", DisplayHeight(display, screen));
+
+ printf(" Screen is %d pixels wide.\n", DisplayWidth(display, screen));
+
+ visual = DefaultVisual(display,screen);
+ printf(" %3d Colour map entries", visual->map_entries);
+ printf(" (Number of colours on the screen at one time).\n");
+
+ printf(" %3d Display planes (bits per screen pixel).\n", DisplayPlanes(display, screen));
+
+ printf(" There is %d screen(s).\n", ScreenCount (display));
+} \ No newline at end of file
diff --git a/reference/C/X_EXAMPLES/root_colour.c b/reference/C/X_EXAMPLES/root_colour.c
new file mode 100644
index 0000000..430baa8
--- /dev/null
+++ b/reference/C/X_EXAMPLES/root_colour.c
@@ -0,0 +1,235 @@
+/************************************************************************
+ *
+ * Purpose: Program to randomly change the root window colour on X Displays.
+ *
+ * Description.
+ * The program randomly selects a target colour and then
+ * performs a basic interpolation to move from the current
+ * colour to the target colour. When the target has been
+ * reached, a new target is selected and the process is
+ * repeated.
+ *
+ * Notes: 1) No attempt is made to see if the client supports colour.
+ * 2) Other applications may cause problems if they have allocated
+ * all the available colour cells in the colour map.
+ * 3) Use the following command to compile.
+ *
+ * gcc root_col.c -lX11
+ * 4) Tested on Linux running XFree386 and FVWM
+ * and SunOS 4.1.3 running X11R5 and Motif.
+ *
+ * Author: M.J. Leslie
+ *
+ * Date: 26-Mar-95
+ *
+ ************************************************************************/
+/****************** Includes ********************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+/************************************************************************/
+
+#define INC 512 /* Increments between colours. */
+#define MAX_COL 65536 /* Max number of colours. */
+#define SECONDS 2 /* # of seconds between updates */
+
+/****************** Functions *******************************************/
+
+void help(char * proganme); /* Give some help on syntax. */
+
+ /* Used to see if a colour gun has
+ * reached its required intensity
+ */
+int reached_target( unsigned short colour, unsigned short target_colour);
+
+void root_colour(int seconds); /* Where the real work starts. */
+
+ /* Change the colour of the
+ * root window */
+void change_colour(Display * display,
+ Window root,
+ Colormap colormap,
+ XColor colour);
+
+/************************************************************************/
+
+main(int argc, char * argv[])
+ {
+ int seconds=SECONDS;
+ /* Have we got cmd line parms? */
+ if (argc > 1 )
+ {
+ /* Yes. Is Help Required? */
+ if ( !strcmp(argv[1], "-h"))
+ {
+ help(argv[0]); /* Yes. */
+ exit(0);
+ }
+ /* Do we have an integer. */
+ if (!sscanf(argv[1], "%u", &seconds))
+ {
+ help(argv[0]); /* No. */
+ exit(0);
+ }
+
+ }
+
+ root_colour(seconds); /* Start colouring the
+ * root window.
+ * 'seconds' is the # of seconds
+ * between updates. */
+ }
+
+/************************************************************************/
+
+void root_colour(int seconds)
+ {
+ Display * display;
+ int screen;
+ char * display_name=NULL;
+ Window root;
+ Colormap colormap;
+ XColor colour, target_colour;
+
+ /****************************************
+ *
+ * Initalise the X environment.
+ *
+ ****************************************/
+
+ /* Connect to X display server. */
+ display=XOpenDisplay(display_name);
+
+ /* Get screen ID */
+ screen=DefaultScreen(display);
+
+ root=RootWindow(display, screen);
+
+ /* Load the default colour map */
+ colormap = DefaultColormap(display, screen);
+
+ /* Starting colour - Grey */
+ colour.red=MAX_COL/2; colour.green=MAX_COL/2; colour.blue=MAX_COL/2;
+
+ colour.flags = DoRed|DoGreen|DoBlue;
+
+ /****************************************
+ *
+ * Loop forever.
+ *
+ ****************************************/
+
+ while(1)
+ {
+ /* Increments used to go from the current
+ * colour to the target colour. */
+
+ int red_inc, green_inc, blue_inc;
+
+ /* Flags used to show when the target
+ * colour has been reached.
+ *
+ * 0 = Arrived at the target colour.
+ * 1 = Not arrived at the target colour.
+ * */
+ int red=1, green=1, blue=1;
+
+ /* Random selection of a new target
+ * colour */
+
+ target_colour.red=rand()%MAX_COL;
+ target_colour.green=rand()%MAX_COL;
+ target_colour.blue=rand()%MAX_COL;
+
+ /* Calculate the direction to go in
+ * to reach the new target colour. */
+
+ red_inc = ( target_colour.red > colour.red ) ? INC : INC * -1;
+ green_inc = ( target_colour.green > colour.green) ? INC : INC * -1;
+ blue_inc = ( target_colour.blue > colour.blue ) ? INC : INC * -1;
+
+
+ /* Loop until all three colours have
+ * reached their required value. */
+
+ while(red || green || blue)
+ {
+ /* Change the colour of the root window */
+
+ change_colour(display, root, colormap, colour);
+
+ /* Increment onto the next colour. */
+
+ if ( red=reached_target(colour.red, target_colour.red))
+ colour.red += red_inc;
+ if (green=reached_target(colour.green, target_colour.green))
+ colour.green += green_inc;
+ if ( blue=reached_target(colour.blue, target_colour.blue))
+ colour.blue += blue_inc;
+
+ sleep(seconds); /* Pause...... */
+
+ }
+
+ }
+
+ XCloseDisplay(display);
+ }
+
+/************************************************************************/
+
+int reached_target( unsigned short colour, unsigned short target_colour)
+ {
+ return (( colour >= target_colour-INC && colour <= target_colour+INC) ?0:1);
+ }
+
+/************************************************************************/
+
+void change_colour(Display * display,
+ Window root,
+ Colormap colormap,
+ XColor colour)
+ {
+ /* Reserve a cell in the colour map */
+
+ XAllocColorCells(display, colormap, False, NULL, 0, &colour.pixel, 1);
+
+ /* Place the required colour in the map.*/
+
+ XStoreColor(display, colormap, &colour);
+
+ /* Free the cell so it can be reused. */
+
+ XFreeColors(display, colormap, &colour.pixel, 1, 0);
+
+ /* Set the root window colour. */
+
+ XSetWindowBackground(display, root, colour.pixel);
+
+ /* Refresh the root window (with the new
+ * colour). */
+
+ XClearWindow(display, root);
+
+ }
+
+/************************************************************************/
+
+void help(char * progname)
+ {
+
+ printf("\n%s information\n\n", progname);
+
+ puts(" This program randomly changes the color of the screen background.");
+ puts("\n Syntax:\n");
+
+ printf("\t%s \tRun the program with with a default update time\n", progname);
+ printf("\t\t \tof %d seconds.\n", SECONDS);
+ printf("\t%s 3\tRun the program specifing the delay between updates.\n", progname);
+ printf("\t%s -h\tHelp. you are reading it.\n\n", progname);
+ }
diff --git a/reference/C/X_EXAMPLES/xxterm.c b/reference/C/X_EXAMPLES/xxterm.c
new file mode 100644
index 0000000..366337c
--- /dev/null
+++ b/reference/C/X_EXAMPLES/xxterm.c
@@ -0,0 +1,615 @@
+/***********************************************************************
+ * Purpose: To provide a tool that allows people to login to machines.
+ *
+ * Compile: Edit BUTTONS - Number of machines.
+ * Edit XTERM - Location of the xterm command.
+ * Edit 'machines' - Names of the machines.
+ *
+ * Compile command for Linux and Sun
+ *
+ * gcc xxterm.c -o xxterm -lX11
+ * User notes:
+ * This is only of use to people running UNIX boxes on a LAN.
+ *
+ * History:
+ *
+ * Rev Date Author Comments.
+ * --- ---- ------ ---------
+ * 1.0 30-May-95 MJL Inital Release.
+ */
+/****************** Includes ********************************************/
+ /* These are in /usr/X386 */
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+
+#include <stdio.h>
+#include <unistd.h> /* setuid */
+
+/****************** Defines *********************************************/
+
+#define BUTTONS 7 /* <<<<<--- number of machines. */
+
+ /* VVVVV--- Location of the xterm comnd */
+#define XTERM "/usr/X11R5/bin/xterm -sb -e rlogin"
+
+ /* window background colour */
+#define BACKGROUND_COLOUR "light grey"
+#define BUTTON_COLOUR "blue"
+
+#define DOWN "down"
+#define ACTIVE "active"
+
+/****************** Global Variables ************************************/
+
+Display *display;
+int screen;
+Colormap colormap;
+ /* <<<<<---- Machines you want to access */
+char * machines[] = {
+ "marin",
+ "xarque",
+ "dragon",
+ "saturn",
+ "sentinel",
+ "silver",
+ "sirius"
+ };
+
+/****************** Structures ******************************************/
+ /* Hold the co-ordinates of the buttons */
+struct {
+ XPoint topleft;
+ XPoint topright;
+ XPoint botleft;
+ XPoint botright;
+ } buttons[BUTTONS+1];
+
+
+struct window_info
+ {
+ Window win;
+ GC gc;
+ };
+
+/****************** Functions *******************************************/
+
+void init_buttons(char *button_caps[]);
+
+void draw_image (Window, GC *, char *button_caps[]);
+
+int draw_button
+ (Window,
+ GC *gc,
+ char *text, /* Text to put on screen button cap */
+ int x, int y, /* Position of button in window */
+ int width, int height,
+ int,
+ char button_caps[]);
+ /* Change the colour in the graphics
+ * context.
+ */
+void set_colour (GC *gc, char *, Colormap);
+
+int where_am_i (Window, GC *gc);
+
+ /* Take an action based on the
+ * button ID.
+ */
+int process_button
+ (Window win,
+ GC *gc,
+ char *button_caps[],
+ int button); /* Button ID. */
+
+void press_button
+ (Window,
+ GC *gc,
+ char *button_caps[],
+ char *text );
+
+struct window_info create_window
+ (int x, /* Window size */
+ int y);
+
+ /* Execute system commands */
+void execute_command
+ (int root, /* 1 == must be run by root
+ * 0 == Can be run by anyone */
+ char *command, /* Command */
+ char *machine);
+
+/************************************************************************/
+
+main()
+ {
+ unsigned int width, height; /* Size of the window. */
+ int x=0, y=0; /* x is across, y is down! */
+ unsigned int border_width=4; /* Window border. */
+
+ /* Array of pointers, one for each screen
+ * button, they point to a string constant
+ * describing their status, active, down,
+ * inactive
+ */
+ char *button_caps[BUTTONS+1];
+
+ struct window_info window;
+
+ Window win;
+ GC gc;
+ XEvent report;
+ XFontStruct *font_info;
+ XColor colour;
+
+ char * display_name=NULL;
+
+ /*********************************************************************
+ *
+ * Setup the window environment
+ *
+ *********************************************************************/
+
+ /* Connect to X display server. */
+ display=XOpenDisplay(display_name);
+
+ /* Get screen ID */
+ screen=DefaultScreen(display);
+
+ /* Load the default colour map */
+ colormap = DefaultColormap(display, screen);
+
+ /* Create the new window with the same
+ attributes as the parent. */
+ /* Put the info window on the screen */
+ width = 90; height = (BUTTONS+1)* 30 +15+5;
+ window=create_window(width, height);
+ win = window.win;
+ gc = window.gc;
+
+/************************************************************************
+ *
+ * Window environment has been setup.
+ *
+ * We must now define the attributes required by the graphics that
+ * will be placed inside the window.
+ *
+ ************************************************************************/
+
+ {
+ int exit_prog=1;
+
+ /* Initalize the screen buttons */
+ init_buttons(button_caps);
+
+ /* Will stop looping when the 'exit' button
+ * is pressed.
+ */
+ while (exit_prog)
+ {
+ /* Wait for an event....
+ These are documented in Xlib Programming
+ Manual Volume 1 P.223 */
+ XNextEvent(display, &report);
+
+ switch (report.type)
+ {
+ /* drawing can only be done on an 'Expose'
+ event */
+
+ case Expose: /* Event No. ? */
+ {
+ /* Redraw the whole screen. */
+ draw_image(win, &gc, button_caps);
+ break;
+ }
+ case ButtonPress: /* Event No. 4 */
+ {
+ int button;
+ /* Act on a mouse button press. If the 'exit'
+ * screen button has been pressed, 'exit_prog'
+ * will be set to 0.
+ */
+ button=where_am_i(win, &gc);
+ process_button(win, &gc, button_caps, button);
+
+ /* Test for exit. */
+
+ if ( button == BUTTONS) exit_prog=0;
+
+ break;
+ }
+ case KeyPress: /* Event No. 2 */
+ {
+ break; /* Not realy interested.... */
+ }
+ case 22: /* Event No. 22 */
+ {
+ break; /* Window moved, i think... */
+ }
+ default:
+ {
+ printf ("Unexpected Event occoured in xxterm window. Event No. is %i\n",
+ report.type);
+ break;
+ }
+ }
+ }
+ }
+ }
+/************************************************************************
+ *
+ * root == 1 Command can only be executed by root
+ * root >= 0 Command can be executed by anyone.
+ *
+ ************************************************************************/
+void execute_command(int root, char *command, char *machine)
+ {
+ char full_cmd[100];
+ /* Q. Does this command 'root' authority*/
+ if (root)
+ {
+ if (getuid())
+ {
+ printf("You are not authorised to execute this command\n");
+ return;
+ }
+ }
+ strcpy( full_cmd, command);
+ strcat( full_cmd, " ");
+ strcat( full_cmd, machine);
+ strcat( full_cmd, " &");
+ system(full_cmd);
+ }
+/************************************************************************
+ *
+ *
+ *
+ *
+ *
+ ************************************************************************/
+
+int process_button (Window win, GC *gc, char *button_caps[], int button)
+ {
+
+ /* locate the button the pointer is in */
+ if (button >= 0 && button < BUTTONS)
+ {
+
+ button_caps[button] = DOWN;
+ press_button(win, gc, button_caps, " " );
+
+ execute_command(0, XTERM, machines[button]);
+
+ sleep(1);
+
+ button_caps[button] = ACTIVE;
+ press_button(win, gc, button_caps, " " );
+
+ }
+
+ /* Check for exit */
+ if ( button == BUTTONS)
+ {
+ button_caps[button] = DOWN;
+ press_button(win, gc, button_caps, " " );
+
+ sleep(1);
+
+ button_caps[button] = ACTIVE;
+ press_button(win, gc, button_caps, " " );
+
+ }
+ return (1);
+ }
+
+/****************** Build an image onto the window **********************/
+
+void draw_image (Window win, GC *gc, char *button_caps[])
+ {
+ int i, x;
+ /* Build the screen buttons
+ */
+
+ /* Button states are:
+ * active (up)
+ * down
+ * inactive
+ */
+ for (i=0, x=15; i< BUTTONS; i++, x+=30)
+ {
+ /* Draw_box parms are:
+ * Graphic Context
+ * | Text on the button
+ * | | x indent from left side
+ * | | | y indent from top
+ * | | | | width
+ * | | | | | height
+ * V V V V V V
+ */
+ draw_button(win, gc, machines[i], 15, x, 60, 20, i, button_caps[i]) ;
+ }
+ draw_button(win, gc, "Exit" , 15, x, 60, 20, i, button_caps[i]) ;
+
+ }
+/****************** Draw button with text in it *************************
+ *
+ * Draw a button with texted on its cap.
+ *
+ * win Window ID
+ * gc Graphics context.
+ * text text to put in the box.
+ * x,y top left hand corner of the box. x is across the screen
+ * width
+ * height
+ * box identifing number.
+ * button_state state of screen button, active, inactive or down
+ *
+ ************************************************************************/
+
+draw_button(Window win, GC *gc, char *text, int x, int y,
+ int width, int height, int box,
+ char button_cap[])
+ {
+
+ /* variables to hold the colour names.
+ ****************************************/
+ char top_left_col[80]; /* button shading */
+ char bottom_right_col[80]; /* more button shading. */
+ char text_col[80]; /* Text on button. */
+
+ int yfudge=height-5; /* Text location */
+ int xfudge=x+6;
+
+struct {
+ XPoint p;
+ } points[6];
+
+ int thickness=2; /* Thickness of the button edge. */
+
+ /* Co-ordinates for the inner box. */
+ int xinner=x+thickness;
+ int yinner=y+thickness;
+ int hinner=height-(thickness*2);
+ int winner=width-(thickness*2);
+
+ /* Set colours for an "active" button */
+ if (!strcmp(button_cap, ACTIVE))
+ {
+ strcpy(top_left_col, "white");
+ strcpy(bottom_right_col, "slategrey");
+ }
+
+ /* Set colours for a "down" button
+ * the button has been pressed.
+ */
+ if (!strcmp(button_cap, DOWN))
+ {
+ strcpy(top_left_col, "slategrey");
+ strcpy(bottom_right_col, "white");
+ }
+
+
+ /* set the border colour. */
+
+ set_colour(gc, top_left_col, colormap);
+
+ /* Top Left border */
+
+ points[0].p.x=x; points[0].p.y=y;
+ points[1].p.x=x+width; points[1].p.y=y;
+ points[2].p.x=xinner+winner; points[2].p.y=yinner;
+ points[3].p.x=xinner; points[3].p.y=yinner;
+ points[4].p.x=xinner; points[4].p.y=yinner+hinner;
+ points[5].p.x=x; points[5].p.y=y+height;
+
+ XFillPolygon(
+ display,
+ win,
+ *gc,
+ points,
+ 6,
+ Nonconvex,
+ CoordModeOrigin);
+
+ /* set the border colour. */
+ set_colour(gc, bottom_right_col, colormap);
+
+ /* Bottom right */
+ points[0].p.x=x; points[0].p.y=y+height;
+ points[1].p.x=xinner; points[1].p.y=yinner+hinner;
+ points[2].p.x=xinner+winner; points[2].p.y=yinner+hinner;
+ points[3].p.x=xinner+winner; points[3].p.y=yinner;
+ points[4].p.x=x+width; points[4].p.y=y;
+ points[5].p.x=x+width; points[5].p.y=y+height;
+
+ XFillPolygon(
+ display,
+ win,
+ *gc,
+ points,
+ 6,
+ Nonconvex,
+ CoordModeOrigin);
+
+ /* set the text colour. */
+
+ set_colour(gc, BUTTON_COLOUR, colormap);
+
+ /* draw the text that will be on the screen
+ * button cap.
+ */
+
+ XDrawString (display, win, *gc,
+ xfudge, y+yfudge, /* Bottom left of text */
+ text,
+ strlen(text));
+
+ /* Store the button location */
+
+ buttons[box].topleft.x=x; buttons[box].topleft.y=y;
+ buttons[box].topright.x=x+width; buttons[box].topright.y=y;
+ buttons[box].botright.x=x+width; buttons[box].botright.y=y+height;
+ buttons[box].botleft.x=x; buttons[box].botleft.y=y+height;
+
+ }
+
+/************************************************************************
+ *
+ * Returns
+ * -1 == Not on a screen button or the screen button is not active
+ * ge 0 == Button number.
+ *
+ ************************************************************************/
+int where_am_i(Window win, GC *gc)
+ {
+
+ Window root, child;
+ int root_x, root_y; /* Cursor location on the screen. */
+ int win_x, win_y; /* Cursor location in the window. */
+ int mask;
+ int inc;
+ int button;
+
+ /* Get pointer location on the screen
+ * and within the window from the top left
+ * corner.
+ * x left to right.
+ * y top to bottom.
+ */
+ XQueryPointer( display, win,
+ &root, &child,
+ &root_x, &root_y,
+ &win_x, &win_y,
+ &mask);
+
+ /* win_x and win_y give the usefull position
+ * within the window.
+ */
+
+ /* Scan through each of the button positions
+ * and see if the pointer is in one of them
+ */
+ button=-1;
+ for (inc = 0 ; inc <= BUTTONS && button == -1; inc++)
+ {
+ if ( win_x > buttons[inc].topleft.x && win_x < buttons[inc].topright.x
+ && win_y > buttons[inc].topleft.y && win_y < buttons[inc].botleft.y)
+ {
+ button = inc; /* Store the button ID. */
+ }
+ }
+
+ return(button);
+ }
+
+/************************************************************************
+ *
+ * press - status of button then we start the routine.
+ * release - Status of button when we exit the routine (active/inactive)
+ *
+ ************************************************************************/
+void press_button(Window win, GC *gc, char *button_caps[], char *text )
+ {
+
+ draw_image(win, gc, button_caps); /* redraw all the buttons */
+ }
+/************************************************************************
+ *
+ * Change the colour of any graphics that are drawn after this
+ * function has been called.
+ *
+ * colour - Name of the colour to change to.
+ *
+ * For a list of valid colour names:
+ * Use the Unix command 'showrgb'
+ * or look in /usr/lib/X11/rgb
+ * or on Suns you can try the unix command 'xco'.
+ *
+ ************************************************************************/
+void set_colour (GC *gc, char * colour, Colormap colormap)
+ {
+ XColor xcolour;
+ /* Convert the Colour name into RGB values.
+ */
+ XParseColor(display, colormap, colour, &xcolour);
+ /* Convert the RGB values into a pixel value.
+ */
+ XAllocColor(display, colormap, &xcolour);
+ /* Use the pixel value to set the foreground
+ * colour.
+ */
+ XSetForeground(display, *gc, xcolour.pixel);
+ }
+
+/************************************************************************
+ *
+ * Initalise the screen buttons.
+ *
+ ************************************************************************/
+void init_buttons(char *button_caps[])
+ {
+ int i;
+
+ for (i=0; i <= BUTTONS; i++) button_caps[i] = ACTIVE;
+
+ }
+/************************************************************************
+ *
+ * Put a window on the screen.
+ *
+ * x & y are the size of the window.
+ *
+ ************************************************************************/
+struct window_info create_window(int x, int y)
+ {
+ struct window_info window;
+ XColor colour;
+
+
+ /* Build background colour
+ * XParseColor gets rgb values for the named
+ * colour, then XAllocColor gets the pixel
+ * value from the rgb values.
+ */
+ XParseColor(display, colormap, BACKGROUND_COLOUR, &colour);
+ XAllocColor(display, colormap, &colour);
+
+ /* Create the new window with the same
+ attributes as the parent. */
+ window.win = XCreateSimpleWindow(display,
+ RootWindow(display, screen),
+ 0, 0, /* Position */
+ x, y, /* Size */
+ 4,
+ WhitePixel(display, screen), /* Window Border color */
+ colour.pixel); /* Window Background color */
+
+ /* Select the event types we want the
+ * window to respond to.
+ * XSelectInput(display,
+ */
+ XSelectInput(display,
+ window.win,
+ ExposureMask |
+ KeyPressMask |
+ ButtonPressMask |
+ StructureNotifyMask );
+
+
+ /* Make window visable - this does not
+ actually make the window visable
+ until we start looking for 'events' */
+ XMapWindow (display, window.win);
+
+ /* Create a 'Graphics Context' used to
+ hold common attributes requires by
+ graphic images, for example colour and
+ line thickness. */
+ window.gc = XCreateGC(display,
+ RootWindow(display, screen),
+ 0,
+ NULL);
+
+ return window;
+ }