diff options
author | Keith Packard <keithp@keithp.com> | 2004-04-28 07:20:50 +0000 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2004-04-28 07:20:50 +0000 |
commit | fe9660749e5c69ea3822ff9a8b6639fc99f12c21 (patch) | |
tree | d48bde0ab9a872be79254f85619cbb447da0e83c |
Initial revision
-rw-r--r-- | AUTHORS | 0 | ||||
-rw-r--r-- | COPYING | 19 | ||||
-rw-r--r-- | ChangeLog | 0 | ||||
-rw-r--r-- | INSTALL | 229 | ||||
-rw-r--r-- | Makefile.am | 57 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | README | 0 | ||||
-rwxr-xr-x | autogen.sh | 3 | ||||
-rw-r--r-- | configure.ac | 51 | ||||
-rw-r--r-- | lightpipe.1 | 34 | ||||
-rw-r--r-- | lightpipe.c | 113 | ||||
-rw-r--r-- | lightpipe.h | 86 | ||||
-rw-r--r-- | lightpipe.pc.in | 10 | ||||
-rw-r--r-- | lpapi.c | 125 | ||||
-rw-r--r-- | lpdamage.c | 126 | ||||
-rw-r--r-- | lpdisplay.c | 68 | ||||
-rw-r--r-- | lpevent.c | 114 | ||||
-rw-r--r-- | lpimage.c | 112 | ||||
-rw-r--r-- | lpinit.c | 83 | ||||
-rw-r--r-- | lpint.h | 127 | ||||
-rw-r--r-- | lptable.c | 81 |
21 files changed, 1438 insertions, 0 deletions
@@ -0,0 +1,19 @@ +$Id$ + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation, and that the name of the authors not be used in +advertising or publicity pertaining to distribution of the software without +specific, written prior permission. The authors make no +representations about the suitability of this software for any purpose. It +is provided "as is" without express or implied warranty. + +THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,229 @@ +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software +Foundation, Inc. + + This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + + These are generic installation instructions. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. (Caching is +disabled by default to prevent problems with accidental use of stale +cache files.) + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You only need +`configure.ac' if you want to change it or regenerate `configure' using +a newer version of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. If you're + using `csh' on an old version of System V, you might need to type + `sh ./configure' instead to prevent `csh' from trying to execute + `configure' itself. + + Running `configure' takes awhile. While running, it prints some + messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + +Compilers and Options +===================== + + Some systems require unusual options for compilation or linking that +the `configure' script does not know about. Run `./configure --help' +for details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + + You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you must use a version of `make' that +supports the `VPATH' variable, such as GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + If you have to use a `make' that does not support the `VPATH' +variable, you have to compile the package for one architecture at a +time in the source code directory. After you have installed the +package for one architecture, use `make distclean' before reconfiguring +for another architecture. + +Installation Names +================== + + By default, `make install' will install the package's files in +`/usr/local/bin', `/usr/local/man', etc. You can specify an +installation prefix other than `/usr/local' by giving `configure' the +option `--prefix=PATH'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +give `configure' the option `--exec-prefix=PATH', the package will use +PATH as the prefix for installing programs and libraries. +Documentation and other data files will still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=PATH' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + + Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + + There may be some features `configure' cannot figure out +automatically, but needs to determine by the type of machine the package +will run on. Usually, assuming the package is built to be run on the +_same_ architectures, `configure' can figure that out, but if it prints +a message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the `--target=TYPE' option to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + + If you want to set default values for `configure' scripts to share, +you can create a site shell script called `config.site' that gives +default values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + + Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +will cause the specified gcc to be used as the C compiler (unless it is +overridden in the site shell script). + +`configure' Invocation +====================== + + `configure' recognizes the following options to control how it +operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..8b34de1 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,57 @@ +# +# $Id$ +# +# Copyright © 2004 @AUTHORS@ +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of the authors not be used in +# advertising or publicity pertaining to distribution of the software without +# specific, written prior permission. The authors make no +# representations about the suitability of this software for any purpose. It +# is provided "as is" without express or implied warranty. +# +# THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +# EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. +# + +PROGRAM=lightpipe + +man_MANS=lightpipe.1 + +LOCAL_DOCS=$(man_MANS) + +AM_CFLAGS = $(LIGHTPIPE_CFLAGS) $(WARN_CFLAGS) + +bin_PROGRAMS = lightpipe + +lib_LTLIBRARIES = liblightpipe.la + +liblightpipe_la_SOURCES = \ + lpapi.c \ + lpdamage.c \ + lpdisplay.c \ + lpevent.c \ + lpimage.c \ + lpinit.c \ + lpint.h \ + lptable.c + +liblightpipeincludedir = $(includedir)/X11/extensions +liblightpipeinclude_HEADERS = lightpipe.h + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = lightpipe.pc + +EXTRA_DIST=$(LOCAL_DOCS) lightpipe.pc.in autogen.sh + +lightpipe_SOURCES = lightpipe.c + +lightpipe_LDADD = $(LIGHTPIPE_LIBS) liblightpipe.la diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..b1376df --- /dev/null +++ b/autogen.sh @@ -0,0 +1,3 @@ +#! /bin/sh +autoreconf -v --install || exit 1 +./configure --enable-maintainer-mode "$@" diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..97f8d9c --- /dev/null +++ b/configure.ac @@ -0,0 +1,51 @@ +dnl +dnl $Id$ +dnl +dnl Copyright © 2004 Keith Packard +dnl +dnl Permission to use, copy, modify, distribute, and sell this software and its +dnl documentation for any purpose is hereby granted without fee, provided that +dnl the above copyright notice appear in all copies and that both that +dnl copyright notice and this permission notice appear in supporting +dnl documentation, and that the name of the authors not be used in +dnl advertising or publicity pertaining to distribution of the software without +dnl specific, written prior permission. The authors make no +dnl representations about the suitability of this software for any purpose. It +dnl is provided "as is" without express or implied warranty. +dnl +dnl THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +dnl INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +dnl EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR +dnl CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +dnl DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +dnl TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +dnl PERFORMANCE OF THIS SOFTWARE. +dnl + +AC_PREREQ(2.57) +AC_INIT([lightpipe],0.0.0,[keithp@freedesktop.org],lightpipe) +AC_CONFIG_SRCDIR([Makefile.am]) +AM_INIT_AUTOMAKE([dist-bzip2]) +AM_MAINTAINER_MODE +AM_CONFIG_HEADER(config.h) + +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LN_S +AC_LIBTOOL_WIN32_DLL +AM_PROG_LIBTOOL +AC_PROG_MAKE_SET + +PKG_CHECK_MODULES(LIGHTPIPE, xdamage xcomposite xext x11) + +WARN_CFLAGS="" + +if test "x$GCC" = "xyes"; then + WARN_CFLAGS="-Wall -Wpointer-arith -Wstrict-prototypes \ + -Wmissing-prototypes -Wmissing-declarations \ + -Wnested-externs -fno-strict-aliasing" +fi +AC_SUBST(WARN_CFLAGS) + +AC_OUTPUT([Makefile + lightpipe.pc]) diff --git a/lightpipe.1 b/lightpipe.1 new file mode 100644 index 0000000..5649cc6 --- /dev/null +++ b/lightpipe.1 @@ -0,0 +1,34 @@ +.\" +.\" Copyright 2001 Keith Packard, member of The XFree86 Project, Inc..\" +.\" Permission to use, copy, modify, distribute, and sell this software and its +.\" documentation for any purpose is hereby granted without fee, provided that +.\" the above copyright notice appear in all copies and that both that +.\" copyright notice and this permission notice appear in supporting +.\" documentation, and that the name of Keith Packard not be used in +.\" advertising or publicity pertaining to distribution of the software without +.\" specific, written prior permission. Keith Packard makes no +.\" representations about the suitability of this software for any purpose. It +.\" is provided "as is" without express or implied warranty. +.\" +.\" KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +.\" EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR +.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +.\" DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +.\" PERFORMANCE OF THIS SOFTWARE. +.\" +.\" +.\" $XFree86: xc/programs/xrandr/xrandr.man,v 1.6 2003/06/12 14:12:39 eich Exp $ +.\" +.TH LIGHTPIPE 1 "Version 1.0" "X.Org" +.SH NAME +lightpipe \- pump X windows from one display to another +.SH SYNOPSIS +.B "lightpipe" +.SH DESCRIPTION +.SH "SEE ALSO" +Xdamage(3) +.SH AUTHORS +Keith Packard, +Cambridge Research Laboratory, HP Labs, HP. diff --git a/lightpipe.c b/lightpipe.c new file mode 100644 index 0000000..1c6deae --- /dev/null +++ b/lightpipe.c @@ -0,0 +1,113 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lightpipe.h" +#include <stdlib.h> +#include <stdio.h> +#include <X11/Xlib.h> +#include <X11/Xatom.h> +#include <X11/Xutil.h> + +int +main (int argc, char **argv) +{ + Display *display; + Display *new_display; + Window window; + Window new = 0; + int new_width, new_height; + XLightPipeWindow *lpw; + GC gc; + + if (argc != 4) + { + fprintf (stderr, "usage: %s <src-dpy> <window-id> <dst-dpy>\n", + argv[0]); + exit (1); + } + + display = XOpenDisplay (argv[1]); + window = strtol (argv[2], 0, 0); + new_display = XOpenDisplay (argv[3]); + XLightPipeInit (); + XLightPipeAttendWindow (display, window); + gc = XCreateGC (new_display, RootWindow (new_display, DefaultScreen (new_display)), 0, 0); + for (;;) + { + lpw = XLightPipeCheckWindow (display, window, True); + if (!new) + { + XWMHints *wmhints; + XSizeHints *normalhints; + XClassHint *classhint; + char *name = "lightpipe"; + new = XCreateSimpleWindow (new_display, RootWindow (new_display, + DefaultScreen (new_display)), + 0, 0, lpw->geometry.width, + lpw->geometry.height, + 0, 0, 0); + normalhints = XAllocSizeHints (); + normalhints->flags = 0; + normalhints->x = 0; + normalhints->y = 0; + normalhints->width = lpw->geometry.width; + normalhints->height = lpw->geometry.height; + + classhint = XAllocClassHint (); + classhint->res_name = "lightpipe"; + classhint->res_class = "Lightpipe"; + + wmhints = XAllocWMHints (); + wmhints->flags = InputHint; + wmhints->input = False; + + Xutf8SetWMProperties (new_display, new, name, name, 0, 0, + normalhints, wmhints, classhint); + XFree (wmhints); + XFree (classhint); + XFree (normalhints); + + XMapWindow (new_display, new); + new_width = lpw->geometry.width; + new_height = lpw->geometry.height; + } + if (new_width != lpw->geometry.width || + new_height != lpw->geometry.height) + { + new_width = lpw->geometry.width; + new_height = lpw->geometry.height; + XResizeWindow (new_display, new, new_width, new_height); + } + printf ("%dx%d+%d+%d\n", + lpw->damage.width, lpw->damage.height, lpw->damage.x, lpw->damage.y); + XPutImage (new_display, new, gc, lpw->image, + lpw->damage.x, lpw->damage.y, + lpw->damage.x, lpw->damage.y, + lpw->damage.width, + lpw->damage.height); + XFlush (new_display); + XLightPipeRelease (display, lpw); + } + return 0; +} diff --git a/lightpipe.h b/lightpipe.h new file mode 100644 index 0000000..de12b42 --- /dev/null +++ b/lightpipe.h @@ -0,0 +1,86 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include <X11/Xlib.h> + +typedef struct { + XRectangle geometry; /* in screen space, read-only */ + int border_width; /* read-only */ + XRectangle damage; /* in window space, client may modify */ + XImage *image; /* read-only */ +} XLightPipeWindow; + +/* + * Initialize library. Must be called before first XOpenDisplay call + */ + +void +XLightPipeInit (void); + +/* + * Start monitoring window, returns success boolean + */ + +Bool +XLightPipeAttendWindow (Display *display, Window window); + +/* + * Start monitoring all sub windows; create/destroy handled + * automagically + */ + +Bool +XLightPipeAttendSubwindows (Display *display, Window window); + +/* + * Stop monitoring window. Note that monitoring is automatically + * disabled if the window is destroyed + */ + +void +XLightPipeIgnoreWindow (Display *display, Window window); + +/* + * Returns XLightPipeWindow structure if there is any damage, + * else 0. The XLightPipeWindow structure is 'locked' on return + * and must be 'released' before any other calls to the library + * including XLightPipeIgnoreWindow. + */ + +XLightPipeWindow * +XLightPipeCheckWindow (Display *display, Window window, Bool block); + +/* + * Returns a random window containing damage, 0 if none + */ +XLightPipeWindow * +XLightPipeCheckAny (Display *display, Bool block); + +/* + * Release the XLightPipeWindow structure so that + * additional damage can be added. + */ + +void +XLightPipeRelease (Display *display, XLightPipeWindow *lpw); diff --git a/lightpipe.pc.in b/lightpipe.pc.in new file mode 100644 index 0000000..879b051 --- /dev/null +++ b/lightpipe.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: lightpipe +Description: Light Pipe Library +Version: @PACKAGE_VERSION@ +Cflags: -I${includedir} @LIGHTPIPE_CFLAGS@ +Libs: -L${libdir} -llightpipe @LIGHTPIPE_LIBS@ @X_LIBS@ @@ -0,0 +1,125 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +/* + * Initialize library. Must be called before first XOpenDisplay call + */ + +void +XLightPipeInit (void) +{ +} + +/* + * Start monitoring window, returns success boolean + */ + +Bool +XLightPipeAttendWindow (Display *display, Window window) +{ + return add_window (display, window) ? True : False; +} + +/* + * Start monitoring all sub windows; create/destroy handled + * automagically + */ + +Bool +XLightPipeAttendSubwindows (Display *display, Window window) +{ + return False; +} + +/* + * Stop monitoring window. Note that monitoring is automatically + * disabled if the window is destroyed + */ + +void +XLightPipeIgnoreWindow (Display *display, Window window) +{ + remove_window (display, window); +} + +/* + * Returns XLightPipeWindow structure if there is any damage, + * else 0. The XLightPipeWindow structure is 'locked' on return + * and must be 'released' before any other calls to the library + * including XLightPipeIgnoreWindow. + */ + +XLightPipeWindow * +XLightPipeCheckWindow (Display *display, Window window, Bool block) +{ + light_pipe_window *lpw; + + do { + process_events (display); + for (lpw = find_damaged (display); lpw; lpw = lpw->next_damaged) + { + if (lpw->window == window) + { + update_window (lpw); + return &lpw->public; + } + } + } while (!block || await_event (display)); + return 0; +} + +/* + * Returns a random window containing damage, 0 if none + */ +XLightPipeWindow * +XLightPipeCheckAny (Display *display, Bool block) +{ + light_pipe_window *lpw; + + do { + process_events (display); + lpw = find_damaged (display); + if (lpw) + { + update_window (lpw); + return &lpw->public; + } + } while (!block || await_event (display)); + return 0; +} + +/* + * Release the XLightPipeWindow structure so that + * additional damage can be added. + */ + +void +XLightPipeRelease (Display *display, XLightPipeWindow *xlpw) +{ + light_pipe_window *lpw = (light_pipe_window *) xlpw; + + undamage_window (lpw); +} diff --git a/lpdamage.c b/lpdamage.c new file mode 100644 index 0000000..d87c66a --- /dev/null +++ b/lpdamage.c @@ -0,0 +1,126 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +static void +add_damage (light_pipe_window *lpw) +{ + light_pipe_display *lpd = find_display (lpw->display); + light_pipe_window **prev; + + if (!lpd) + return; + for (prev = &lpd->damaged; *prev; prev = &(*prev)->next_damaged) + if ((*prev) == lpw) + return; + lpw->next_damaged = *prev; + *prev = lpw; +} + +static void +remove_damage (light_pipe_window *lpw) +{ + light_pipe_display *lpd = find_display (lpw->display); + light_pipe_window **prev; + + if (!lpd) + return; + for (prev = &lpd->damaged; *prev; prev = &(*prev)->next_damaged) + if ((*prev) == lpw) + { + *prev = lpw->next_damaged; + break; + } +} + +void +damage_window (light_pipe_window *lpw, int x, int y, int width, int height) +{ + add_damage (lpw); + if (lpw->public.damage.width == 0) + { + lpw->public.damage.x = x; + lpw->public.damage.y = y; + lpw->public.damage.width = width; + lpw->public.damage.height = height; + } + else + { + int old_x2 = lpw->public.damage.x + lpw->public.damage.width; + int old_y2 = lpw->public.damage.y + lpw->public.damage.height; + int new_x2 = x + width; + int new_y2 = y + height; + + if (x < lpw->public.damage.x) + lpw->public.damage.x = x; + if (new_x2 > old_x2) + old_x2 = new_x2; + lpw->public.damage.width = old_x2 - lpw->public.damage.x; + if (y < lpw->public.damage.y) + lpw->public.damage.y = y; + if (new_y2 > old_y2) + old_y2 = new_y2; + lpw->public.damage.height = old_y2 - lpw->public.damage.y; + } +} + +void +update_window (light_pipe_window *lpw) +{ + if (lpw->public.damage.width && lpw->public.damage.height) + { + XFixesSetRegion (lpw->display, + lpw->repair, + &lpw->public.damage, + 1); + XDamageSubtract (lpw->display, + lpw->damage, + lpw->repair, + None); + update_region (lpw, + lpw->public.damage.x, + lpw->public.damage.y, + lpw->public.damage.width, + lpw->public.damage.height); + XSync (lpw->display, False); + } +} + +void +undamage_window (light_pipe_window *lpw) +{ + remove_damage (lpw); + lpw->public.damage.x = lpw->public.damage.y = 0; + lpw->public.damage.width = lpw->public.damage.height = 0; +} + +light_pipe_window * +find_damaged (Display *display) +{ + light_pipe_display *lpd; + + lpd = find_display (display); + return lpd->damaged; +} diff --git a/lpdisplay.c b/lpdisplay.c new file mode 100644 index 0000000..cd666ec --- /dev/null +++ b/lpdisplay.c @@ -0,0 +1,68 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +static Bool +init_display (light_pipe_display *lpd) +{ + if (!XFixesQueryExtension (lpd->display, + &lpd->xfixes.event_base, + &lpd->xfixes.error_base)) + return False; + if (!XDamageQueryExtension (lpd->display, + &lpd->damage.event_base, + &lpd->damage.error_base)) + return False; + if (!XCompositeQueryExtension (lpd->display, + &lpd->composite.event_base, + &lpd->composite.error_base)) + return False; + return True; +} + +light_pipe_display * +find_display (Display *display) +{ + light_pipe_display *lpd; + + if (XFindContext (display, 0, lp_context (), (XPointer *) &lpd) == 0) + return lpd; + lpd = malloc (sizeof (light_pipe_display)); + if (!lpd) + return 0; + lpd->display = display; + lpd->damaged = 0; + if (!init_display (lpd)) + { + free (lpd); + return 0; + } + if (XSaveContext (display, 0, lp_context (), (char *) lpd) != 0) + { + free (lpd); + return 0; + } + return lpd; +} diff --git a/lpevent.c b/lpevent.c new file mode 100644 index 0000000..334fe98 --- /dev/null +++ b/lpevent.c @@ -0,0 +1,114 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +static void +process_destroy_notify (XDestroyWindowEvent *event) +{ + remove_window (event->display, event->window); +} + +static void +process_configure_notify (XConfigureEvent *event) +{ + light_pipe_window *lpw = find_window (event->display, event->window); + + if (!lpw) + return; + if (event->width != lpw->public.geometry.width || + event->height != lpw->public.geometry.height) + { + lpw->public.geometry.width = event->width; + lpw->public.geometry.height = event->height; + destroy_window_image (lpw); + create_window_image (lpw); + damage_window (lpw, 0, 0, event->width, event->height); + } + lpw->public.geometry.x = event->x; + lpw->public.geometry.y = event->y; + lpw->public.border_width = event->border_width; +} + +static void +process_damage_notify (XDamageNotifyEvent *event) +{ + light_pipe_window *lpw = find_window (event->display, event->drawable); + + if (!lpw) + return; + damage_window (lpw, + event->area.x, + event->area.y, + event->area.width, + event->area.height); +} + +static void +process_event (XEvent *event) +{ + Display *display = event->xany.display; + light_pipe_display *lpd = find_display (display); + + if (!lpd) + return; + switch (event->type) { + case DestroyNotify: + process_destroy_notify ((XDestroyWindowEvent *) event); + return; + case ConfigureNotify: + process_configure_notify ((XConfigureEvent *) event); + return; + default: + break; + } + switch (event->type - lpd->damage.event_base) { + case XDamageNotify: + process_damage_notify ((XDamageNotifyEvent *) event); + return; + default: + break; + } +} + +Bool +await_event (Display *display) +{ + XEvent event; + + XPeekEvent (display, &event); + return True; +} + +void +process_events (Display *display) +{ + while (XPending (display)) + { + XEvent event; + + XNextEvent (display, &event); + process_event (&event); + } +} diff --git a/lpimage.c b/lpimage.c new file mode 100644 index 0000000..f797b6c --- /dev/null +++ b/lpimage.c @@ -0,0 +1,112 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +Bool +create_window_image (light_pipe_window *lpw) +{ + int image_size; + XGCValues gcv; + + lpw->public.image = XCreateImage (lpw->display, + lpw->visual, + lpw->depth, + ZPixmap, + 0, + 0, + lpw->public.geometry.width, + lpw->public.geometry.height, + 32, + 0); + if (!lpw->public.image) + return False; + image_size = (lpw->public.image->bytes_per_line * + lpw->public.geometry.height); + if (!image_size) + { + XDestroyImage (lpw->public.image); + return False; + } + lpw->shm_info.shmid = shmget (IPC_PRIVATE, image_size, IPC_CREAT|0600); + if (lpw->shm_info.shmid < 0) + { + XDestroyImage (lpw->public.image); + lpw->public.image = 0; + return False; + } + lpw->shm_info.shmaddr = (char *) shmat (lpw->shm_info.shmid, 0, 0); + if (lpw->shm_info.shmaddr == ((char *) -1)) + { + XDestroyImage (lpw->public.image); + lpw->public.image = 0; + shmctl (lpw->shm_info.shmid, IPC_RMID, 0); + return False; + } + XShmAttach (lpw->display, &lpw->shm_info); + lpw->public.image->data = lpw->shm_info.shmaddr; + lpw->public.image->obdata = (char *) &lpw->shm_info; + lpw->shm_pixmap = XShmCreatePixmap (lpw->display, + lpw->window, + lpw->public.image->data, + &lpw->shm_info, + lpw->public.geometry.width, + lpw->public.geometry.height, + lpw->depth); + gcv.graphics_exposures = False; + gcv.subwindow_mode = IncludeInferiors; + lpw->shm_gc = XCreateGC (lpw->display, + lpw->window, + GCGraphicsExposures|GCSubwindowMode, + &gcv); + return True; +} + +void +destroy_window_image (light_pipe_window *lpw) +{ + if (lpw->public.image) + { + XShmDetach (lpw->display, &lpw->shm_info); + XSync (lpw->display, False); + (void) shmdt (&lpw->shm_info.shmaddr); + (void) shmctl (lpw->shm_info.shmid, IPC_RMID, 0); + lpw->public.image->data = 0; + lpw->public.image->obdata = 0; + XDestroyImage (lpw->public.image); + XFreePixmap (lpw->display, lpw->shm_pixmap); + XFreeGC (lpw->display, lpw->shm_gc); + lpw->public.image = 0; + } +} + +void +update_region (light_pipe_window *lpw, int x, int y, int width, int height) +{ + XCopyArea (lpw->display, + lpw->window, + lpw->shm_pixmap, + lpw->shm_gc, + x, y, width, height, x, y); +} diff --git a/lpinit.c b/lpinit.c new file mode 100644 index 0000000..4c3aa87 --- /dev/null +++ b/lpinit.c @@ -0,0 +1,83 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +Bool +init_window (Display *display, Window window, light_pipe_window *lpw) +{ + XWindowAttributes attr; + + lpw->display = display; + lpw->window = window; + XSelectInput (display, window, LP_WINDOW_EVENT_MASK); + if (!XGetWindowAttributes (display, window, &attr)) + return False; + + lpw->public.geometry.x = attr.x; + lpw->public.geometry.y = attr.y; + lpw->public.geometry.width = attr.width; + lpw->public.geometry.height = attr.height; + lpw->public.border_width = attr.border_width; + + lpw->public.damage.x = 0; + lpw->public.damage.y = 0; + lpw->public.damage.width = 0; + lpw->public.damage.height = 0; + + lpw->public.image = 0; + + lpw->display = display; + lpw->window = window; + lpw->visual = attr.visual; + lpw->depth = attr.depth; + + lpw->damage = XDamageCreate (display, window, XDamageReportBoundingBox); + + lpw->repair = XFixesCreateRegion (display, 0, 0); + + XCompositeRedirectWindow (display, window, CompositeRedirectAutomatic); + + lpw->next_damaged = 0; + + if (!create_window_image (lpw)) + { + XSelectInput (display, window, 0); + return False; + } + + if (attr.map_state == IsViewable) + damage_window (lpw, 0, 0, attr.width, attr.height); + return True; +} + +void +fini_window (Display *display, Window window, light_pipe_window *lpw) +{ + XSelectInput (display, window, 0); + undamage_window (lpw); + XCompositeUnredirectWindow (display, window, CompositeRedirectAutomatic); + XDamageDestroy (display, lpw->damage); + destroy_window_image (lpw); +} @@ -0,0 +1,127 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lightpipe.h" +#include <X11/extensions/Xdamage.h> +#include <X11/extensions/Xcomposite.h> +#include <X11/extensions/XShm.h> +#include <X11/Xresource.h> +#include <X11/Xutil.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <stdlib.h> + +#define LP_WINDOW_EVENT_MASK (StructureNotifyMask) + +typedef struct _light_pipe_window { + XLightPipeWindow public; + Display *display; + Window window; + Visual *visual; + int depth; + XShmSegmentInfo shm_info; + Pixmap shm_pixmap; + GC shm_gc; + Damage damage; + XserverRegion repair; + struct _light_pipe_window *next_damaged; +} light_pipe_window; + +typedef struct _light_pipe_extension { + int event_base; + int error_base; +} light_pipe_extension; + +typedef struct _light_pipe_display { + Display *display; + light_pipe_window *damaged; + light_pipe_extension xfixes; + light_pipe_extension damage; + light_pipe_extension composite; +} light_pipe_display; + +/* lpdamage.c */ + +/* mark area as damaged */ +void +damage_window (light_pipe_window *lpw, int x, int y, int width, int height); + +/* synchronize local copy of window with remote */ +void +update_window (light_pipe_window *lpw); + +/* mark window as entirely undamaged */ +void +undamage_window (light_pipe_window *lpw); + +light_pipe_window * +find_damaged (Display *display); + +/* lpdisplay.c */ + +light_pipe_display * +find_display (Display *display); + +/* lpevent.c */ + +Bool +await_event (Display *display); + +void +process_events (Display *display); + +/* lptable.c */ + +int +lp_context (void); + +light_pipe_window * +find_window (Display *display, Window window); + +light_pipe_window * +add_window (Display *display, Window window); + +void +remove_window (Display *display, Window window); + +/* lpimage.c */ + +Bool +create_window_image (light_pipe_window *lpw); + +void +destroy_window_image (light_pipe_window *lpw); + +void +update_region (light_pipe_window *lpw, int x, int y, int width, int height); + +/* lpinit.c */ + +Bool +init_window (Display *display, Window window, light_pipe_window *lpw); + +void +fini_window (Display *display, Window window, light_pipe_window *lpw); + diff --git a/lptable.c b/lptable.c new file mode 100644 index 0000000..12aad9b --- /dev/null +++ b/lptable.c @@ -0,0 +1,81 @@ +/* + * $Id$ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +#include "lpint.h" + +int +lp_context (void) +{ + static int context; + + while (!context) + context = XUniqueContext (); + return context; +} + +light_pipe_window * +find_window (Display *display, Window window) +{ + light_pipe_window *lpw; + + if (XFindContext (display, window, lp_context (), (XPointer *) &lpw) != 0) + return 0; + return lpw; +} + +light_pipe_window * +add_window (Display *display, Window window) +{ + light_pipe_window *lpw; + + if (XFindContext (display, window, lp_context (), (XPointer *) &lpw) == 0) + return 0; + lpw = malloc (sizeof (light_pipe_window)); + if (!lpw) + return 0; + if (XSaveContext (display, window, lp_context (), (char *) lpw) != 0) + { + free (lpw); + return 0; + } + if (!init_window (display, window, lpw)) + { + XDeleteContext (display, window, lp_context()); + free (lpw); + return 0; + } + return lpw; +} + +void +remove_window (Display *display, Window window) +{ + light_pipe_window *lpw; + + if (!XFindContext (display, window, lp_context (), (XPointer *) &lpw)) + return; + (void) XDeleteContext (display, window, lp_context ()); + fini_window (display, window, lpw); + free (lpw); +} |