xdesktopwaves-1.3/0040755000076400001440000000000010160742174012623 5ustar ohusersxdesktopwaves-1.3/README0100644000076400001440000001366410160742174013512 0ustar ohusers xdesktopwaves 1.3 Simulation of water waves on the X Windows desktop Copyright (C) 2004 Oliver Hamann For license please refer to the file COPYING xdesktopwaves is a cellular automata setting the background of your X Windows desktop under water. Windows and mouse are like ships on the sea. Each movement of these ends up in moving water waves. You can even have rain and/or storm stirring up the water. If you want to read more about xdesktopwaves before installation, type: man -l xdesktopwaves.1 or go to the homepage: http://xdesktopwaves.sourceforge.net/ INSTALLATION ============ In seldom cases you may have to edit the Makefile. An example would be to compile with another compiler than gcc, or to change the include, library and install directories. Or maybe you want to add a compiler flag like -mcpu=athlon-xp or -mcpu=pentium4. For compiling xdesktopwaves simply type: make If you get errors from the assembler, try the following command. It disables SSE2 assembly: make XDW_MAX_OPTIMIZATION=1 If you get errors from the assembler again, you will probably even have to disable MMX: make XDW_MAX_OPTIMIZATION=0 Hint: There is no need to disable optimization for lack of support by the CPU. That is checked by the program at run-time. After compilation was successful, be root and install xdesktopwaves with: make install Now read the manual: man xdesktopwaves You don't like to read the manual? Okay, try some of these commands: xdesktopwaves xdesktopwaves -colortheme 9 -verbose xdesktopwaves -quality 3 -colortheme 1 -root -stippled xdesktopwaves -quality 6 -colortheme 5 -window -opaque -rain 7 xdesktopwaves -quality 4 -colortheme 3 -storm 8 If you want to create menu entries in your desktop environment, window manager or wherever: For starting, create an entry containing a command like the examples above. For stopping, create an entry containing this command: xdesktopwaves -end CHANGES ======= Version 1.3 * Added dealing with non-rectangular shape of client windows. * Added a criterion for the idle mode: obscurity of output window. * Added xdwapi. Version 1.2 * Added an option for improving the trails of mouse and windows: -eventsperframe . Because this even has influence on CPU load, it got member of the set of options adjusted through the -quality option. * Added options for configuring lighting: -skyintensity <1-10>, -lightintensity <1-10>, -lightaltitude , -lightazimuth . In order to solve that, the formulas for calculating the reflections have been redesigned. It is theoretically a little bit more realistic now, but it makes no appreciable difference in the look. * The option -highlightcolor has been renamed to -lightcolor. * Added an option for another method of transparency (still highly experimental): -wmopacity <0-100>. Version 1.1 * The intensity of rain and storm is configurable now. New options: -rain <0-10> and -storm <0-10> (the old yes-or-no variants are deprecated). * The viscosity of the fluid is no longer a constant (without any speed loss). New option: -viscosity <1-5> * The rain feature no longer prevents from the idle mode: just obscure by other windows, but don't give -nww. * Bugfix: On 64-bit x86, xdesktopwaves now even compiles with gcc 3.4. * Bugfix: Fixed arithmetic exception on systems with a small RAND_MAX. * Bugfix: If -stippled, clear window at initialization. * Optimization/Bugfix: The color palette is reduced to have only different colors. This can spare about 10% of the rectangles sent to the server, if the display depth is 16-bit. * Optimization: Treatment of minimum range of out-of-date canvas rows. This spares up to 50% client CPU cycles when there are just very few waves (shortly before entering idle mode). BUGS & FANTASIES ================ - If running with -wmbackdrop, mouse clicks mostly are not forwarded to the desktop (possibly just at every second scan-line in shaped mode). I'm afraid that the only solution would be to extend the standard of "Extended Window Manager Hints", so that an application can tell the window manager not to interpret any input on the window. - There is some flicker when client windows are moved. Depending on the X Server, it can be conspicuous with shaped windows. This could be reduced by disabling the "clear-on-exposure" behavior and by immediate repainting on exposure events (if double-buffered). - Screen saver mode is still missing. - In high quality mode, and if client and server are on the same machine, it could make sense to paint with XShmPutImage instead of XFillRectangles. - Add special support for enlightenment 0.17. - The API should have functions for modifying all the other settings. - A graphical user interface for modifying the settings is more and more desirable. - Maybe it is possible to add options for the behavior at the edges of the windows: positive reflection of waves; weaker reflection of waves; deletion of waves; let the waves come back from the opposite edges of the output window. - The cellular automata could possibly be improved by making the cells hexagonal. - There could be an option for setting a background pixmap (stipple mode only). - Another idea is to have an option for setting a bitmap which defines a land/water mask. Would be nice in combination with an appropriate background pixmap. - Finally xdesktopwaves may be developed towards a real-time ray tracer: Reflect an environment pixmap (trees, clouds...). Illuminate a sea bottom pixmap by refraction of sunbeams. Refract rays from eye to sea bottom. Do the same with animated animal pixmaps in one or more layers. Unfortunately these things probably would not look good with the interlaced shaping of the output window. But maybe there could be a shore area, in which the desktop icons are still visible. xdesktopwaves-1.3/Makefile0100644000076400001440000000267710160742174014274 0ustar ohusers# Makefile for xdesktopwaves #===================== Configuration for inline assembler ====================== # This should be adapted if you get errors from the assembler: Which level of # instruction set is supported by the x86 assembler behind gcc? 2 means MMX and # SSE2, 1 means just MMX and no SSE2, and 0 means no MMX and no SSE2. (support # by the CPU is checked at run-time) XDW_MAX_OPTIMIZATION=2 #=========================== C compiler configuration ========================== CC = gcc CFLAGS = -I/usr/X11R6/include -O2 #============================= Linker configuration ============================ LINK = gcc LFLAGS = -L/usr/X11R6/lib LIBS = -lm -lX11 -lXext #============================ Installer configuration ========================== BINDIR = /usr/X11R6/bin MAN1DIR = /usr/X11R6/man/man1 INSTALL = install RM = rm -f -v #=============================================================================== all: xdesktopwaves xdesktopwaves.o: xdesktopwaves.c $(CC) $(CFLAGS) -DXDW_MAX_OPTIMIZATION=$(XDW_MAX_OPTIMIZATION) -c xdesktopwaves.c -o xdesktopwaves.o xdesktopwaves: xdesktopwaves.o $(LINK) $(LFLAGS) xdesktopwaves.o $(LIBS) -o xdesktopwaves clean: $(RM) xdesktopwaves.o install: xdesktopwaves xdesktopwaves.1 $(INSTALL) -c -m 0755 -s xdesktopwaves $(BINDIR)/xdesktopwaves $(INSTALL) -c -m 0444 xdesktopwaves.1 $(MAN1DIR)/xdesktopwaves.1 uninstall: $(RM) $(BINDIR)/xdesktopwaves $(RM) $(MAN1DIR)/xdesktopwaves.1 xdesktopwaves-1.3/xdesktopwaves.c0100644000076400001440000037043510160742174015707 0ustar ohusersconst char * const xdwCopyright= /*===========================================================================*/ " xdesktopwaves 1.3 - simulation of water waves on the X Windows desktop \n" " \n" " Copyright (C) 2004 Oliver Hamann (olha@users.sourceforge.net) \n" " \n" " This program is free software; you can redistribute it and/or modify \n" " it under the terms of the GNU General Public License as published by \n" " the Free Software Foundation; either version 2 of the License, or \n" " (at your option) any later version. \n" " \n" " This program is distributed in the hope that it will be useful, \n" " but WITHOUT ANY WARRANTY; without even the implied warranty of \n" " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \n" " GNU General Public License for more details. \n" " \n" " You should have received a copy of the GNU General Public License \n" " along with this program; if not, write to the Free Software \n" " Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA \n"; /*===========================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #include #include /*============================================================================*/ /*================================= Options ==================================*/ /*============================================================================*/ typedef enum { XDW_USE_ROOT, XDW_BACKDROP, XDW_WMBACKDROP, XDW_WINDOW } xdwWindowCreationType; typedef enum { XDW_OPAQUE, XDW_STIPPLED, XDW_SHAPED, XDW_WMOPACITY } xdwTransparencyType; /* Path/name of executable */ const char * xdwArg0="xdesktopwaves"; /* Option variables. */ int xdwOptVerb; const char * xdwOptDisplay; Bool xdwOptEnd; xdwWindowCreationType xdwOptWindowCreation; xdwTransparencyType xdwOptTransparency; int xdwOptTranspaParam; int xdwOptFrameRate; int xdwOptSimsPerFrame; int xdwOptEventsPerFrame; int xdwOptResDivX; int xdwOptResDivY; int xdwOptCellW; int xdwOptCellH; int xdwOptMaxColors; Bool xdwOptDoubleBuffer; int xdwOptNice; Bool xdwOptIdle; int xdwOptMaxOptimization; const char * xdwOptWaterColor; const char * xdwOptSkyColor; const char * xdwOptLightColor; Bool xdwOptWavesByMouse; Bool xdwOptWavesByWindows; int xdwOptRain; int xdwOptStorm; int xdwOptViscosity; int xdwOptSkyIntensity; int xdwOptLightIntensity; int xdwOptLightAltitude; int xdwOptLightAzimuth; /* Parameters for the quality option. */ const struct { int frameRate; int simsPerFrame; int eventsPerFrame; int resDivX; int resDivY; int cellWidth; int cellHeight; int maxColors; } xdwQualityParams[10]={ { 12, 2, 1, 6, 6, 3, 3, 8 }, { 14, 3, 1, 5, 5, 3, 3, 12 }, { 16, 4, 1, 4, 4, 3, 3, 16 }, { 18, 5, 1, 3, 3, 3, 3, 22 }, { 20, 5, 1, 2, 2, 3, 3, 32 }, { 20, 6, 1, 2, 2, 2, 2, 48 }, { 25, 5, 2, 1, 2, 4, 2, 64 }, { 20, 9, 2, 2, 2, 1, 1, 64 }, { 25, 8, 3, 1, 2, 2, 1, 96 }, { 25,12, 4, 1, 1, 1, 1, 128 } }; /* Color themes. */ const char * const xdwColorThemes[10][3] = { { "#406080", "#9696C0", "#FFFFFF" }, { "#1020C0", "#8080D0", "#FFFFFF" }, { "#000C18", "#122E20", "#FFFF80" }, { "#384840", "#90A0B0", "#FFFFE8" }, { "#808060", "#C0C080", "#FFF0F0" }, { "#000000", "#004030", "#FFFFFF" }, { "#78A020", "#80E098", "#F0FFF0" }, { "#504030", "#807050", "#FFFFE0" }, { "#800000", "#FF3060", "#C0FFFF" }, { "#F0F8FF", "#807050", "#586040" } }; static void xdwSetDefaultOptions(void) { /* Set default values for all the options. */ xdwOptVerb =0; xdwOptDisplay =NULL; xdwOptEnd =False; xdwOptWindowCreation =XDW_BACKDROP; xdwOptTransparency =XDW_SHAPED; xdwOptTranspaParam =0; xdwOptFrameRate =xdwQualityParams[5].frameRate; xdwOptSimsPerFrame =xdwQualityParams[5].simsPerFrame; xdwOptEventsPerFrame =xdwQualityParams[5].eventsPerFrame; xdwOptResDivX =xdwQualityParams[5].resDivX; xdwOptResDivY =xdwQualityParams[5].resDivY; xdwOptCellW =xdwQualityParams[5].cellWidth; xdwOptCellH =xdwQualityParams[5].cellHeight; xdwOptMaxColors =xdwQualityParams[5].maxColors; xdwOptDoubleBuffer =True; xdwOptNice =0; xdwOptIdle =True; xdwOptMaxOptimization=2; xdwOptWaterColor =xdwColorThemes[0][0]; xdwOptSkyColor =xdwColorThemes[0][1]; xdwOptLightColor =xdwColorThemes[0][2]; xdwOptWavesByMouse =True; xdwOptWavesByWindows =True; xdwOptRain =0; xdwOptStorm =0; xdwOptViscosity =3; xdwOptSkyIntensity =5; xdwOptLightIntensity =5; xdwOptLightAltitude =30; xdwOptLightAzimuth =-35; } static Bool xdwParseInt(const char * str, int minVal, int maxVal, int * pVal) { int sign, digit, val; /* Parse a decimal integer without allowing unexpected characters, and check range. */ if (*str=='-') { sign=-1; str++; } else if (*str=='+') { sign=1; str++; } else sign=1; if (!*str) return False; for (val=0; ; str++) { digit=*str; if (!digit) break; digit-='0'; if (digit<0 || digit>9) return False; val=val*10+digit; } val*=sign; if (valmaxVal) return False; *pVal=val; return True; } static void xdwParseOptions(int argc, char * argv[]) { const char * opt, * nm; char transpaStr[256]; int i, j; /* Keep name of executable. */ xdwArg0=argv[0]; /* Parse options. */ for (i=1; i]...\n" "Options:\n" " -h|-help -db|-doublebuffer\n" " -V|-version -ndb|-nodoublebuffer\n" " -v|-verbose -n|-nice \n" " -vv|-veryverbose -i|-idle\n" " -d|-display -ni|-noidle\n" " -e|-end -mo|-maxoptimization \n" " -r|-root -c|-colortheme <0-9>\n" " -b|-backdrop -wc|-watercolor \n" " -wmb|-wmbackdrop -sc|-skycolor \n" " -w|-window -lc|-lightcolor \n" " -o|-opaque -wm|-wavesbymouse\n" " -t|-stippled -nwm|-nowavesbymouse\n" " -s|-shaped -ww|-wavesbywindows\n" " -wmo|-wmopacity <0-100> -nww|-nowavesbywindows\n" " -q|-quality <0-9> -rn|-rain <0-10>\n" " -fr|-framerate -st|-storm <0-10>\n" " -sf|-simsperframe -vs|-viscosity <1-5>\n" " -ef|-eventsperframe -si|-skyintensity <1-10>\n" " -rd|-resdivision -li|-lightintensity <1-10>\n" " -cs|-cellsize -lal|-lightaltitude \n" " -mc|-maxcolors <2-128> -laz|-lightazimuth \n" "For details please refer to the manual page: xdesktopwaves(1)\n", xdwArg0 ); exit(0); } else if (!strcmp(nm,"V") || !strcmp(nm,"version")) { printf("\n%s\n",xdwCopyright); exit(0); } else if (!strcmp(nm,"v") || !strcmp(nm,"verbose")) { xdwOptVerb=1; } else if (!strcmp(nm,"vv") || !strcmp(nm,"veryverbose")) { xdwOptVerb=2; } else if (!strcmp(nm,"d") || !strcmp(nm,"display")) { if (i>=argc) goto L_MISSING_OPT_ARG; xdwOptDisplay=argv[i++]; } else if (!strcmp(nm,"e") || !strcmp(nm,"end")) { xdwOptEnd=True; } else if (!strcmp(nm,"r") || !strcmp(nm,"root")) { xdwOptWindowCreation=XDW_USE_ROOT; } else if (!strcmp(nm,"b") || !strcmp(nm,"backdrop")) { xdwOptWindowCreation=XDW_BACKDROP; } else if (!strcmp(nm,"wmb") || !strcmp(nm,"wmbackdrop")) { xdwOptWindowCreation=XDW_WMBACKDROP; } else if (!strcmp(nm,"w") || !strcmp(nm,"window")) { xdwOptWindowCreation=XDW_WINDOW; } else if (!strcmp(nm,"o") || !strcmp(nm,"opaque")) { xdwOptTransparency=XDW_OPAQUE; } else if (!strcmp(nm,"t") || !strcmp(nm,"stippled")) { xdwOptTransparency=XDW_STIPPLED; } else if (!strcmp(nm,"s") || !strcmp(nm,"shaped")) { xdwOptTransparency=XDW_SHAPED; } else if (!strcmp(nm,"wmo") || !strcmp(nm,"wmopacity")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,100,&j)) goto L_BAD_OPT_ARG; xdwOptTransparency=XDW_WMOPACITY; xdwOptTranspaParam=j; } else if (!strcmp(nm,"q") || !strcmp(nm,"quality")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,9,&j)) goto L_BAD_OPT_ARG; xdwOptFrameRate =xdwQualityParams[j].frameRate; xdwOptSimsPerFrame =xdwQualityParams[j].simsPerFrame; xdwOptEventsPerFrame=xdwQualityParams[j].eventsPerFrame; xdwOptResDivX =xdwQualityParams[j].resDivX; xdwOptResDivY =xdwQualityParams[j].resDivY; xdwOptCellW =xdwQualityParams[j].cellWidth; xdwOptCellH =xdwQualityParams[j].cellHeight; xdwOptMaxColors =xdwQualityParams[j].maxColors; } else if (!strcmp(nm,"fr") || !strcmp(nm,"framerate")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,1000,&j)) goto L_BAD_OPT_ARG; xdwOptFrameRate=j; } else if (!strcmp(nm,"sf") || !strcmp(nm,"simsperframe")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,1000,&j)) goto L_BAD_OPT_ARG; xdwOptSimsPerFrame=j; } else if (!strcmp(nm,"ef") || !strcmp(nm,"eventsperframe")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,1000,&j)) goto L_BAD_OPT_ARG; xdwOptEventsPerFrame=j; } else if (!strcmp(nm,"rd") || !strcmp(nm,"resdivision")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,256,&j)) goto L_BAD_OPT_ARG; xdwOptResDivX=j; if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,256,&j)) goto L_BAD_OPT_ARG; xdwOptResDivY=j; } else if (!strcmp(nm,"cs") || !strcmp(nm,"cellsize")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,256,&j)) goto L_BAD_OPT_ARG; xdwOptCellW=j; if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,256,&j)) goto L_BAD_OPT_ARG; xdwOptCellH=j; } else if (!strcmp(nm,"mc") || !strcmp(nm,"maxcolors")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],2,128,&j)) goto L_BAD_OPT_ARG; xdwOptMaxColors=j; } else if (!strcmp(nm,"db") || !strcmp(nm,"doublebuffer")) { xdwOptDoubleBuffer=True; } else if (!strcmp(nm,"ndb") || !strcmp(nm,"nodoublebuffer")) { xdwOptDoubleBuffer=False; } else if (!strcmp(nm,"n") || !strcmp(nm,"nice")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],-100,100,&j)) goto L_BAD_OPT_ARG; xdwOptNice=j; } else if (!strcmp(nm,"i") || !strcmp(nm,"idle")) { xdwOptIdle=True; } else if (!strcmp(nm,"ni") || !strcmp(nm,"noidle")) { xdwOptIdle=False; } else if (!strcmp(nm,"mo") || !strcmp(nm,"maxoptimization")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,100,&j)) goto L_BAD_OPT_ARG; xdwOptMaxOptimization=j; } else if (!strcmp(nm,"c") || !strcmp(nm,"colortheme")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,9,&j)) goto L_BAD_OPT_ARG; xdwOptWaterColor=xdwColorThemes[j][0]; xdwOptSkyColor =xdwColorThemes[j][1]; xdwOptLightColor=xdwColorThemes[j][2]; } else if (!strcmp(nm,"wc") || !strcmp(nm,"watercolor")) { if (i>=argc) goto L_MISSING_OPT_ARG; xdwOptWaterColor=argv[i++]; } else if (!strcmp(nm,"sc") || !strcmp(nm,"skycolor")) { if (i>=argc) goto L_MISSING_OPT_ARG; xdwOptSkyColor=argv[i++]; } else if (!strcmp(nm,"lc") || !strcmp(nm,"lightcolor")) { if (i>=argc) goto L_MISSING_OPT_ARG; xdwOptLightColor=argv[i++]; } else if (!strcmp(nm,"wm") || !strcmp(nm,"wavesbymouse")) { xdwOptWavesByMouse=True; } else if (!strcmp(nm,"nwm") || !strcmp(nm,"nowavesbymouse")) { xdwOptWavesByMouse=False; } else if (!strcmp(nm,"ww") || !strcmp(nm,"wavesbywindows")) { xdwOptWavesByWindows=True; } else if (!strcmp(nm,"nww") || !strcmp(nm,"nowavesbywindows")) { xdwOptWavesByWindows=False; } else if (!strcmp(nm,"rn") || !strcmp(nm,"rain")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,10,&j)) goto L_BAD_OPT_ARG; xdwOptRain=j; } else if (!strcmp(nm,"st") || !strcmp(nm,"storm")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,10,&j)) goto L_BAD_OPT_ARG; xdwOptStorm=j; } else if (!strcmp(nm,"vs") || !strcmp(nm,"viscosity")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,5,&j)) goto L_BAD_OPT_ARG; xdwOptViscosity=j; } else if (!strcmp(nm,"si") || !strcmp(nm,"skyintensity")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,10,&j)) goto L_BAD_OPT_ARG; xdwOptSkyIntensity=j; } else if (!strcmp(nm,"li") || !strcmp(nm,"lightintensity")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],1,10,&j)) goto L_BAD_OPT_ARG; xdwOptLightIntensity=j; } else if (!strcmp(nm,"lal") || !strcmp(nm,"lightaltitude")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],0,90,&j)) goto L_BAD_OPT_ARG; xdwOptLightAltitude=j; } else if (!strcmp(nm,"laz") || !strcmp(nm,"lightazimuth")) { if (i>=argc) goto L_MISSING_OPT_ARG; if (!xdwParseInt(argv[i++],-360,360,&j)) goto L_BAD_OPT_ARG; xdwOptLightAzimuth=j; } /* --- deprecated options --- */ else if (!strcmp(nm,"hc") || !strcmp(nm,"highlightcolor")) { fprintf(stderr,"%s: option %s is deprecated and should not be used any longer.\n",xdwArg0,opt); if (i>=argc) goto L_MISSING_OPT_ARG; xdwOptLightColor=argv[i++]; } else if (!strcmp(nm,"wr") || !strcmp(nm,"wavesbyrain")) { fprintf(stderr,"%s: option %s is deprecated and should not be used any longer.\n",xdwArg0,opt); if (!xdwOptRain) xdwOptRain=9; } else if (!strcmp(nm,"nwr") || !strcmp(nm,"nowavesbyrain")) { fprintf(stderr,"%s: option %s is deprecated and should not be used any longer.\n",xdwArg0,opt); xdwOptRain=0; } else if (!strcmp(nm,"ws") || !strcmp(nm,"wavesbystorm")) { fprintf(stderr,"%s: option %s is deprecated and should not be used any longer.\n",xdwArg0,opt); if (!xdwOptStorm) xdwOptStorm=9; } else if (!strcmp(nm,"nws") || !strcmp(nm,"nowavesbystorm")) { fprintf(stderr,"%s: option %s is deprecated and should not be used any longer.\n",xdwArg0,opt); xdwOptStorm=0; } /* --------------------------- */ else { fprintf(stderr,"%s: illegal option: %s\n",xdwArg0,opt); exit(1); } } /* Apply some rules on the options. */ if (xdwOptWindowCreation==XDW_USE_ROOT && xdwOptTransparency!=XDW_OPAQUE && xdwOptTransparency!=XDW_STIPPLED) { if (xdwOptVerb) printf("Forcing stippled mode for drawing to root window.\n"); xdwOptTransparency=XDW_STIPPLED; } if (xdwOptTransparency==XDW_SHAPED && !xdwOptDoubleBuffer) { if (xdwOptVerb) printf("Forcing double buffering for shaped mode.\n"); xdwOptDoubleBuffer=True; } if (xdwOptTransparency==XDW_STIPPLED && xdwOptDoubleBuffer) { if (xdwOptVerb) printf("Forcing single buffering for stippled mode.\n"); xdwOptDoubleBuffer=False; } /* Possibly report the resulting settings. */ if (xdwOptVerb>=1) printf( "Applied settings:\n" " display : %-16s max optimization: %d\n" " end : %-16s water color : \"%s\"\n" " window mode : %-16s sky color : \"%s\"\n" " transparency : %-16s light color : \"%s\"\n" " max frame rate : %-16d waves by mouse : %s\n" " sims per frame : %-16d waves by windows: %s\n" " events per frame: %-16d rain : %d\n" " resolution div : %-2d %-13d storm : %d\n" " cell size : %-2d %-13d viscosity : %d\n" " max color count : %-16d sky intensity : %d\n" " double buffering: %-16s light intensity : %d\n" " nice : %-16d light altitude : %d\n" " allow idle mode : %-16s light azimuth : %d\n", xdwOptDisplay ? xdwOptDisplay : "", xdwOptMaxOptimization, xdwOptEnd ? "yes" : "no", xdwOptWaterColor, xdwOptWindowCreation==XDW_USE_ROOT ? "root" : xdwOptWindowCreation==XDW_BACKDROP ? "backdrop" : xdwOptWindowCreation==XDW_WMBACKDROP ? "wm-backdrop" : "normal window", xdwOptSkyColor, xdwOptTransparency==XDW_OPAQUE ? "opaque" : xdwOptTransparency==XDW_STIPPLED ? "stippled" : xdwOptTransparency==XDW_SHAPED ? "shaped" : (sprintf(transpaStr,"opacity %d",xdwOptTranspaParam), transpaStr), xdwOptLightColor, xdwOptFrameRate, xdwOptWavesByMouse ? "yes" : "no", xdwOptSimsPerFrame, xdwOptWavesByWindows ? "yes" : "no", xdwOptEventsPerFrame, xdwOptRain, xdwOptResDivX, xdwOptResDivY, xdwOptStorm, xdwOptCellW, xdwOptCellH, xdwOptViscosity, xdwOptMaxColors, xdwOptSkyIntensity, xdwOptDoubleBuffer ? "yes" : "no", xdwOptLightIntensity, xdwOptNice, xdwOptLightAltitude, xdwOptIdle ? "yes" : "no", xdwOptLightAzimuth ); /* Ready. */ return; /* Error handling. */ L_MISSING_OPT_ARG: fprintf(stderr,"%s: missing argument for option %s\n",xdwArg0,opt); exit(1); L_BAD_OPT_ARG: fprintf(stderr,"%s: illegal argument for option %s\n",xdwArg0,opt); exit(1); } /*============================================================================*/ /*====================== Mathematical Helper Functions =======================*/ /*============================================================================*/ static int xdwSqrt32(unsigned x) { unsigned a, b, c; int i; /* Calculate the square root of x. */ a=0x8000; b=0x4000; c=0x40000000; for (i=14; x!=c && i>=0; i--, b>>=1) { if (xx1 < s->x2 && (!s->next || s->x2 < s->next->x1). */ } xdwRegion; xdwRegScan * xdwGarbageRegScans; /* List of garbage scan line segments for quick re-allocation. */ static xdwRegScan * xdwAllocRegScan() { xdwRegScan * s; if (xdwGarbageRegScans) { s=xdwGarbageRegScans; xdwGarbageRegScans=s->next; } else { s=(xdwRegScan*)malloc(sizeof(xdwRegScan)); } return s; } static void xdwFreeRegScanList(xdwRegScan * first) { xdwRegScan * last; if (first) { for (last=first; last->next; last=last->next); last->next=xdwGarbageRegScans; xdwGarbageRegScans=first; } } static void xdwInitRegion(xdwRegion * reg) { reg->y1=0; reg->y2=0; reg->rows=NULL; } static void xdwEmptyRegion(xdwRegion * reg) { xdwRegScan * * r, * * re; if (reg->rows) { r=reg->rows; re=r+(reg->y2-reg->y1); do { if (*r) xdwFreeRegScanList(*r); r++; } while (rrows); reg->rows=NULL; } reg->y1=0; reg->y2=0; } static int xdwCountRegionPixels(const xdwRegion * reg) { xdwRegScan * * r, * * re; xdwRegScan * s; int pixels; pixels=0; if (reg->rows) { r=reg->rows; re=r+(reg->y2-reg->y1); do { s=*r; if (s) { do { pixels+=s->x2-s->x1; s=s->next; } while (s); } r++; } while (r=x2 || y1>=y2) return; reg->y1=y1; reg->y2=y2; reg->rows=(xdwRegScan**)malloc((y2-y1)*sizeof(xdwRegScan*)); r=reg->rows; re=r+(y2-y1); do { s=xdwAllocRegScan(); s->next=NULL; s->x1=x1; s->x2=x2; *r=s; r++; } while (rrows) return; if (y1y1) y1=reg->y1; if (y2>reg->y2) y2=reg->y2; if (y1>=y2 || x1>=x2) { xdwEmptyRegion(reg); return; } r=reg->rows; if (y1>reg->y1) { re=r+(y1-reg->y1); do { if (*r) { xdwFreeRegScanList(*r); *r=NULL; } r++; } while (rx2>x1) { if (s->x1x1=x1; do { if (s->x2>x2) { if (s->x1x2=x2; ps=&s->next; s=*ps; if (!s) break; } do { *ps=s->next; s->next=xdwGarbageRegScans; xdwGarbageRegScans=s; s=*ps; } while (s); break; } ps=&s->next; s=*ps; } while (s); break; } *ps=s->next; s->next=xdwGarbageRegScans; xdwGarbageRegScans=s; s=*ps; } while (s); } r++; } while (ry2>y2) { re=r+(reg->y2-y2); do { if (*r) { xdwFreeRegScanList(*r); *r=NULL; } r++; } while (rrows) return; if (y1y1) y1=reg->y1; if (y2>reg->y2) y2=reg->y2; if (y1>=y2 || x1>=x2) return; r=reg->rows+(y1-reg->y1); re=r+(y2-y1); do { s=*r; if (s) { ps=r; do { if (s->x2>x1) { if (s->x1x2>x2) { s2=xdwAllocRegScan(); s2->next=s->next; s->next=s2; s2->x1=x2; s2->x2=s->x2; s->x2=x1; break; } s->x2=x1; ps=&s->next; s=*ps; if (!s) break; } do { if (s->x2>x2) { if (s->x1>=x2) break; s->x1=x2; break; } *ps=s->next; s->next=xdwGarbageRegScans; xdwGarbageRegScans=s; s=*ps; } while (s); break; } ps=&s->next; s=*ps; } while (s); } r++; } while (rrows || !reg2->rows) return; y1=reg2->y1; if (y1y1) y1=reg->y1; y2=reg2->y2; if (y2>reg->y2) y2=reg->y2; if (y1>=y2) return; r=reg->rows+(y1-reg->y1); re=r+(y2-y1); q=reg2->rows+(y1-reg2->y1); do { if ((s=*r)!=NULL && (t=*q)!=NULL) { for (ps=r;;) { if (s->x2<=t->x1) { ps=&s->next; s=*ps; if (s) continue; } else if (s->x1>=t->x2) { t=t->next; if (t) continue; } else if (s->x2<=t->x2) { if (s->x1>=t->x1) { *ps=s->next; s->next=xdwGarbageRegScans; xdwGarbageRegScans=s; s=*ps; if (s) continue; } else { s->x2=t->x1; ps=&s->next; s=*ps; if (s) continue; } } else if (s->x1>=t->x1) { s->x1=t->x2; t=t->next; if (t) continue; } else { s2=xdwAllocRegScan(); s2->next=s->next; s->next=s2; s2->x1=t->x2; s2->x2=s->x2; s->x2=t->x1; ps=&s->next; s=s2; t=t->next; if (t) continue; } break; } } r++; q++; } while (r=2) { if (xdwCPUHasCPUID ) printf("CPUID detected\n"); if (xdwCPUIsGenuineIntel) printf("Genuine Intel detected\n"); if (xdwCPUIsAuthenticAMD) printf("Authentic AMD detected\n"); if (xdwCPUHasMMX ) printf("MMX detected\n"); if (xdwCPUHasFXSR ) printf("FXSR detected\n"); if (xdwCPUHasSSE ) printf("SSE detected\n"); if (xdwCPUHasSSE2 ) printf("SSE2 detected\n"); } } /*============================================================================*/ /*========================== The Cellular Automata ===========================*/ /*============================================================================*/ int xdwCellCols, xdwCellRows; /* Number of columns and rows in the grid of cells. */ int xdwCellMemCols; /* Number of columns in memory. This can be a little bit greater than xdwCellCols. The additional cells are not used. Goal is to have the same 16-byte alignment for each row. */ short * xdwCells; /* The grid of cells. This data structure is a little bit awkward, for a better performance of the MMX and SSE2 variants of the algorithm. Each cell (c,r) with c = 0 to xdwCellCols-1 and r = 0 to xdwCellRows-1 has four states: level = xdwCells[(r*3+0)*xdwCellMemCols+c] velocity = xdwCells[(r*3+1)*xdwCellMemCols+c] covered = xdwCells[(r*3+2)*xdwCellMemCols+c]&1023 fading = xdwCells[(r*3+2)*xdwCellMemCols+c]>>10 "level" is the level of water or you can say the vertical position of the mass. "velocity" is the vertical velocity of the water (or mass). "covered" is the number of boats (windows and mouse) stacked on the cell. "fading" is a trick variable for fading from covered=0 to covered!=0 and back. It steps from 25 (got covered) down to 0 (ready with covering) and from -25 (got uncovered) up to 0 (ready with uncovering). The first column, the last column, the first row and the last two rows are making up the borders (the algorithms are easier with the additional border row at the end). They are always covered and should have level=0 and velocity=0. The lower-right corner of the upper-left cell lies in the center of the upper-left pixel of the canvas. And the upper-left corner of the right cell of the second-last row lies in the center of the lower-right pixel of the canvas. The second cell of each row is 16-byte aligned, more precise: each pointer (char*)&xdwCells[n*xdwCellMemCols+1] is a multiple of 16. */ short * xdwCellsMem; /* Pointer to the memory allocated for the cells. This may not be aligned correctly. */ const int xdwCellFadingTable[64]={ /* Table for the trick of fading from covered to uncovered and back. The values are added to the level of a faded cell on each time slice. The index is 32 plus the fading value which ranges from -25 to 25 (see description of xdwCells). */ 0, 0, 0, 0, 0, 0, 0, -36, -72, -108, -143, -178, -212, -246, -278, -310, -340, -369, -397, -424, -448, -472, -493, -513, -531, -546, -560, -572, -582, -590, -595, -598, 0, -450, -471, -485, -489, -484, -470, -445, -411, -367, -314, -253, -183, -107, -24, 61, 151, 243, 335, 425, 512, 594, 669, 737, 795, 843, 0, 0, 0, 0, 0, 0 }; static void xdwInitCells(int windowWidth, int windowHeight) { int col, row; /* Calculate number of columns and rows. */ xdwCellCols=((windowWidth-1)/xdwOptResDivX-1)/xdwOptCellW+3; xdwCellRows=((windowHeight-1)/xdwOptResDivY-1)/xdwOptCellH+4; /* Calculate number of columns in memory (=>alignment). */ xdwCellMemCols=(xdwCellCols+7)&~7; /* Allocate and clear memory for the cells. */ xdwCellsMem=malloc((xdwCellMemCols*xdwCellRows*3+7)*2); memset(xdwCellsMem,0,(xdwCellMemCols*xdwCellRows*3+7)*2); /* Have a pointer for the grid of cells (=>alignment). */ xdwCells=xdwCellsMem+((((short*)0)-xdwCellsMem-1)&7); /* Cover the borders. */ for (row=0; rowxdwCellCols-1) x2=xdwCellCols-1; if (x1>=x2) return False; y1=(2*y1-xdwOptResDivY)/(2*xdwOptCellH*xdwOptResDivY)+1; y2=(2*y2-xdwOptResDivY-1)/(2*xdwOptCellH*xdwOptResDivY)+2; if (y1<1) y1=1; if (y2>xdwCellRows-2) y2=xdwCellRows-2; if (y1>=y2) return False; do { p=xdwCells+(y1*3+2)*xdwCellMemCols+x1; pe=p+(x2-x1); do { c=*p; if ((c&0x3ff)==0) c+=25<<10; c+=deltaCovering; if ((c&0x3ff)==0) c-=25<<10; *p=c; p++; } while (p100) volume=100; x1=cx-5; y1=cy-5; x2=cx+6; y2=cy+6; if (x1<1) x1=1; if (y1<1) y1=1; if (x2>xdwCellCols-1) x2=xdwCellCols-1; if (y2>xdwCellRows-2) y2=xdwCellRows-2; changed=False; for (y=y1; y8 || (pc[x]&1023)!=0) continue; changed=True; v=pv[x]+drop[r]*volume; if (v<-0x8000) v=-0x8000; else if (v>0x7fff) v=0x7fff; pv[x]=(short)v; } } return changed; } static Bool xdwPutRaindrop(int x, int y, int volume) { return xdwPutRaindropOnCell( x/(xdwOptCellW*xdwOptResDivX)+1, y/(xdwOptCellH*xdwOptResDivY)+1, volume ); } static Bool xdwUpdateRain(int timeSlices) { static int rem=0; Bool changed; /* Create a number of raindrops per cell and time slice. A raindrop is just a modification of the velocity of some cells. */ if (xdwOptRain<=0) return False; rem+=xdwCellRows*xdwCellCols*timeSlices/100* xdwOptRain*xdwOptRain/100+10*xdwOptRain; changed=False; while (rem>0) { rem-=xdwRandom(2000,6000); changed|=xdwPutRaindropOnCell( xdwRandom(1,xdwCellCols-2), xdwRandom(1,xdwCellRows-3), xdwRandom(25,100) ); } return changed; } static void xdwUpdateStromRow(int row) { short * p, * pe; int v, n, m, k; /* For one row, perform one time slice of the storm simulation. The basic idea was to calculate the pressure (=acceleration of cells) from the product of airflow vector and water surface vector. With some pressure smoothing and "airflow-tear-offs", it's what this algorithm is nearly doing... */ if (xdwOptStorm<=0) return; p=xdwCells+row*3*xdwCellMemCols; pe=p+xdwCellCols-2; n=0; k=57+xdwOptStorm*xdwOptStorm*35/10; do { v=k; if (!p[2*xdwCellMemCols]) v=p[0]; p++; v-=p[0]; if ((unsigned)v>k) v=0; m=(n+7)>>3; n+=v; n-=m; v-=m; v+=p[xdwCellMemCols]; if (v<-0x8000) v=-0x8000; else if (v>0x7fff) v=0x7fff; p[xdwCellMemCols]=(short)v; } while (p>C2; \ v+=l1; \ l1=l2; \ l2<<=2; \ v-=l2; \ l3=p[0]; \ v+=l3; \ l3+=p[cols]>>2; \ v+=p[2*cols3]; \ c=p[2*cols]; \ if (c) { \ if ((c&0xfc00)!=0) { \ l3+=xdwCellFadingTable[(c>>10)+32]; \ if (c>0) { \ c-=1<<10; \ p[cols]=0; \ } \ else { \ c+=1<<10; \ } \ p[2*cols]=c; \ } \ else { \ l3=0; \ p[cols]=0; \ } \ } \ if (l3>0x7fff) l3=0x7fff; else if (l3<-0x8000) l3=-0x8000; \ p[0]=(short)l3; \ l2=p[cols3+1]; \ v+=l2; \ if (v>0x7fff) v=0x7fff; else if (v<-0x8000) v=-0x8000; \ p[4*cols]=(short)v; \ p++; \ } while(p=1) printf("Using MMX instruction set of 32-bit x86 CPU\n"); reported=True; } i=(((short*)0)-cells)&3; if (i) { xdwOperateCellsOpt0(cells,i); cells+=i; count-=i; } # define XDWOCO1(L,C1,C2) \ asm volatile ( \ " pushl %%ebp \n" \ " pushl %%edx \n" \ " pushl %%edi \n" \ " subl $200,%%esp \n" \ " fnsave (%%esp) \n" \ " movl %%edx,%%ebp \n" \ " pcmpeqw %%mm7,%%mm7 \n" \ " psrlw $" #C1 ",%%mm7 \n" \ " movq (%%edi,%%ecx),%%mm6 \n" \ " movzwl -2(%%edi,%%ecx),%%eax \n" \ " movd %%eax,%%mm5 \n" \ " movq %%mm6,%%mm0 \n" \ " psllq $16,%%mm0 \n" \ " paddsw %%mm0,%%mm5 \n" \ " psubsw %%mm6,%%mm5 \n" \ " jmp " #L "3 \n" \ " .balign 16 \n" \ #L "1: \n" \ " pxor %%mm4,%%mm4 \n" \ " movq %%mm4,(%%edi,%%ebx) \n" \ #L "2: \n" \ " psubsw %%mm2,%%mm3 \n" \ " movq %%mm4,(%%edi) \n" \ " movq %%mm3,(%%edi,%%ebx,4) \n" \ " addl $8,%%edi \n" \ #L "3: \n" \ " cmpl %%esi,%%edi \n" \ " jnc " #L "9 \n" \ " movq (%%edi,%%ebx,4),%%mm3 \n" \ " pxor %%mm2,%%mm2 \n" \ " pcmpeqb (%%edi,%%ebx,2),%%mm2 \n" \ " movq %%mm3,%%mm1 \n" \ " paddsw %%mm5,%%mm3 \n" \ " paddsw %%mm7,%%mm1 \n" \ " movq (%%edi),%%mm4 \n" \ " psrlq $16,%%mm5 \n" \ " psllw $1,%%mm2 \n" \ " psubsw %%mm5,%%mm3 \n" \ " packsswb %%mm2,%%mm2 \n" \ " movq (%%edi,%%ecx,2),%%mm0 \n" \ " psraw $" #C2 ",%%mm1 \n" \ " movq %%mm6,%%mm5 \n" \ " movd %%mm2,%%eax \n" \ " psubsw %%mm1,%%mm3 \n" \ " psubsw %%mm4,%%mm6 \n" \ " movq (%%edi,%%ebx),%%mm1 \n" \ " psubsw %%mm6,%%mm3 \n" \ " psubsw %%mm5,%%mm0 \n" \ " movq 8(%%edi,%%ecx),%%mm6 \n" \ " paddsw %%mm0,%%mm3 \n" \ " psrlq $48,%%mm5 \n" \ " movq %%mm6,%%mm0 \n" \ " psraw $2,%%mm1 \n" \ " psllq $16,%%mm0 \n" \ " psubsw %%mm6,%%mm5 \n" \ " paddsw %%mm1,%%mm4 \n" \ " movq %%mm5,%%mm2 \n" \ " cmpl $0xfefefefe,%%eax \n" \ " psllq $48,%%mm2 \n" \ " paddsw %%mm0,%%mm5 \n" \ " je " #L "2 \n" \ " cmpl $0x80808080,%%eax \n" \ " je " #L "1 \n" \ " pcmpeqd %%mm1,%%mm1 \n" \ " psrlq $48,%%mm1 \n" \ " movl $4,%%edx \n" \ #L "4: \n" \ " movzwl (%%edi,%%ebx,2),%%eax \n" \ " testl %%eax,%%eax \n" \ " je " #L "8 \n" \ " testl $0x0000fc00,%%eax \n" \ " je " #L "6 \n" \ " shrl $10,%%eax \n" \ " addl $32,%%eax \n" \ " andl $63,%%eax \n" \ " movd (%%ebp,%%eax,4),%%mm0 \n" \ " punpcklwd %%mm0,%%mm0 \n" \ " punpckldq %%mm0,%%mm0 \n" \ " pand %%mm1,%%mm0 \n" \ " paddsw %%mm0,%%mm4 \n" \ " testl $32,%%eax \n" \ " jne " #L "5 \n" \ " addw $0x0400,(%%edi,%%ebx,2) \n" \ " jmp " #L "8 \n" \ #L "5: \n" \ " subw $0x0400,(%%edi,%%ebx,2) \n" \ " jmp " #L "7 \n" \ #L "6: \n" \ " movq %%mm1,%%mm0 \n" \ " pandn %%mm4,%%mm0 \n" \ " movq %%mm0,%%mm4 \n" \ #L "7: \n" \ " movw $0,(%%edi,%%ebx) \n" \ #L "8: \n" \ " psllq $16,%%mm1 \n" \ " addl $2,%%edi \n" \ " decl %%edx \n" \ " jnz " #L "4 \n" \ " subl $8,%%edi \n" \ " jmp " #L "2 \n" \ #L "9: \n" \ " frstor (%%esp) \n" \ " addl $200,%%esp \n" \ " popl %%edi \n" \ " popl %%edx \n" \ " popl %%ebp \n" \ : \ : "D"(cells),"S"(cells+(count&~3)),"b"(2*xdwCellMemCols), \ "c"(3*2*xdwCellMemCols),"d"(xdwCellFadingTable) \ : "eax","memory","cc" \ ) switch(xdwOptViscosity) { case 1: XDWOCO1(XDWOCO1_1_, 7,10); break; case 2: XDWOCO1(XDWOCO1_2_, 8, 9); break; case 3: XDWOCO1(XDWOCO1_3_, 9, 8); break; case 4: XDWOCO1(XDWOCO1_4_,10, 7); break; case 5: XDWOCO1(XDWOCO1_5_,11, 6); break; } i=count&3; if (i) xdwOperateCellsOpt0(cells+count-i,i); return True; } #elif defined(__GNUC__) && defined(__x86_64__) /* Same as above, but for 64-bit x86 CPU. (Are there any 64-bit CPU's or assemblers supporting MMX but not SSE2? Probably no, but to be complete...) */ static Bool reported=False; int i; if (xdwCPUHasMMX) { if (!reported) { if (xdwOptVerb>=1) printf("Using MMX instruction set of 64-bit x86 CPU\n"); reported=True; } i=(((short*)0)-cells)&3; if (i) { xdwOperateCellsOpt0(cells,i); cells+=i; count-=i; } # define XDWOCO1(L,C1,C2) \ asm volatile ( \ " pushq %%rdi \n" \ " subq $200,%%rsp \n" \ " fnsave (%%rsp) \n" \ " pcmpeqw %%mm7,%%mm7 \n" \ " psrlw $" #C1 ",%%mm7 \n" \ " movq (%%rdi,%%rcx),%%mm6 \n" \ " movzwl -2(%%rdi,%%rcx),%%eax \n" \ " movd %%eax,%%mm5 \n" \ " movq %%mm6,%%mm0 \n" \ " psllq $16,%%mm0 \n" \ " paddsw %%mm0,%%mm5 \n" \ " psubsw %%mm6,%%mm5 \n" \ " jmp " #L "3 \n" \ " .balign 16 \n" \ #L "1: \n" \ " pxor %%mm4,%%mm4 \n" \ " movq %%mm4,(%%rdi,%%rbx) \n" \ #L "2: \n" \ " psubsw %%mm2,%%mm3 \n" \ " movq %%mm4,(%%rdi) \n" \ " movq %%mm3,(%%rdi,%%rbx,4) \n" \ " addq $8,%%rdi \n" \ #L "3: \n" \ " cmpq %%rsi,%%rdi \n" \ " jnc " #L "9 \n" \ " movq (%%rdi,%%rbx,4),%%mm3 \n" \ " pxor %%mm2,%%mm2 \n" \ " pcmpeqb (%%rdi,%%rbx,2),%%mm2 \n" \ " movq %%mm3,%%mm1 \n" \ " paddsw %%mm5,%%mm3 \n" \ " paddsw %%mm7,%%mm1 \n" \ " movq (%%rdi),%%mm4 \n" \ " psrlq $16,%%mm5 \n" \ " psllw $1,%%mm2 \n" \ " psubsw %%mm5,%%mm3 \n" \ " packsswb %%mm2,%%mm2 \n" \ " movq (%%rdi,%%rcx,2),%%mm0 \n" \ " psraw $" #C2 ",%%mm1 \n" \ " movq %%mm6,%%mm5 \n" \ " movd %%mm2,%%eax \n" \ " psubsw %%mm1,%%mm3 \n" \ " psubsw %%mm4,%%mm6 \n" \ " movq (%%rdi,%%rbx),%%mm1 \n" \ " psubsw %%mm6,%%mm3 \n" \ " psubsw %%mm5,%%mm0 \n" \ " movq 8(%%rdi,%%rcx),%%mm6 \n" \ " paddsw %%mm0,%%mm3 \n" \ " psrlq $48,%%mm5 \n" \ " movq %%mm6,%%mm0 \n" \ " psraw $2,%%mm1 \n" \ " psllq $16,%%mm0 \n" \ " psubsw %%mm6,%%mm5 \n" \ " paddsw %%mm1,%%mm4 \n" \ " movq %%mm5,%%mm2 \n" \ " cmpl $0xfefefefe,%%eax \n" \ " psllq $48,%%mm2 \n" \ " paddsw %%mm0,%%mm5 \n" \ " je " #L "2 \n" \ " cmpl $0x80808080,%%eax \n" \ " je " #L "1 \n" \ " pcmpeqd %%mm1,%%mm1 \n" \ " psrlq $48,%%mm1 \n" \ " movl $4,%%r8d \n" \ #L "4: \n" \ " movzwl (%%rdi,%%rbx,2),%%eax \n" \ " testl %%eax,%%eax \n" \ " je " #L "8 \n" \ " testl $0x0000fc00,%%eax \n" \ " je " #L "6 \n" \ " shrl $10,%%eax \n" \ " addl $32,%%eax \n" \ " andq $63,%%rax \n" \ " movd (%%rdx,%%rax,4),%%mm0 \n" \ " punpcklwd %%mm0,%%mm0 \n" \ " punpckldq %%mm0,%%mm0 \n" \ " pand %%mm1,%%mm0 \n" \ " paddsw %%mm0,%%mm4 \n" \ " testl $32,%%eax \n" \ " jne " #L "5 \n" \ " addw $0x0400,(%%rdi,%%rbx,2) \n" \ " jmp " #L "8 \n" \ #L "5: \n" \ " subw $0x0400,(%%rdi,%%rbx,2) \n" \ " jmp " #L "7 \n" \ #L "6: \n" \ " movq %%mm1,%%mm0 \n" \ " pandn %%mm4,%%mm0 \n" \ " movq %%mm0,%%mm4 \n" \ #L "7: \n" \ " movw $0,(%%rdi,%%rbx) \n" \ #L "8: \n" \ " psllq $16,%%mm1 \n" \ " addq $2,%%rdi \n" \ " decl %%r8d \n" \ " jnz " #L "4 \n" \ " subq $8,%%rdi \n" \ " jmp " #L "2 \n" \ #L "9: \n" \ " frstor (%%rsp) \n" \ " addq $200,%%rsp \n" \ " popq %%rdi \n" \ : \ : "D"(cells),"S"(cells+(count&~3)),"b"((long)2*xdwCellMemCols), \ "c"((long)3*2*xdwCellMemCols),"d"(xdwCellFadingTable) \ : "rax","r8","memory","cc" \ ) switch(xdwOptViscosity) { case 1: XDWOCO1(XDWOCO1_1_, 7,10); break; case 2: XDWOCO1(XDWOCO1_2_, 8, 9); break; case 3: XDWOCO1(XDWOCO1_3_, 9, 8); break; case 4: XDWOCO1(XDWOCO1_4_,10, 7); break; case 5: XDWOCO1(XDWOCO1_5_,11, 6); break; } i=count&3; if (i) xdwOperateCellsOpt0(cells+count-i,i); return True; } #endif return False; } static Bool xdwOperateCellsOpt2(short * cells, int count) { #if defined(XDW_MAX_OPTIMIZATION) && XDW_MAX_OPTIMIZATION < 2 return False; #elif defined(__GNUC__) && defined(__i386__) /* Optimization level 2 of the cellular automata using the SSE2 instruction set of a 32-bit x86 CPU, implemented as GNU-C inline assembler. It is assumed that the covering of a cell is not greater than 255 (it can be up to 1023 per definition). If it's greater, the algorithm is still correct but takes some extra time. */ static Bool reported=False; int i; if (xdwCPUHasFXSR && xdwCPUHasSSE2) { if (!reported) { if (xdwOptVerb>=1) printf("Using SSE2 instruction set of 32-bit x86 CPU\n"); reported=True; } i=(((short*)0)-cells)&7; if (i) { xdwOperateCellsOpt0(cells,i); cells+=i; count-=i; } # define XDWOCO2(L,C1,C2) \ asm volatile ( \ " pushl %%ebp \n" \ " pushl %%edx \n" \ " pushl %%edi \n" \ " movl %%esp,%%eax \n" \ " subl $512,%%esp \n" \ " andl $0xfffffff0,%%esp \n" \ " fxsave (%%esp) \n" \ " push %%eax \n" \ " movl %%edx,%%ebp \n" \ " pcmpeqw %%xmm7,%%xmm7 \n" \ " psrlw $" #C1 ",%%xmm7 \n" \ " movdqa (%%edi,%%ecx),%%xmm6 \n" \ " movzwl -2(%%edi,%%ecx),%%eax \n" \ " movd %%eax,%%xmm5 \n" \ " movdqa %%xmm6,%%xmm0 \n" \ " pslldq $16/8,%%xmm0 \n" \ " paddsw %%xmm0,%%xmm5 \n" \ " psubsw %%xmm6,%%xmm5 \n" \ " jmp " #L "3 \n" \ " .balign 16 \n" \ #L "1: \n" \ " pxor %%xmm4,%%xmm4 \n" \ " movdqa %%xmm4,(%%edi,%%ebx) \n" \ #L "2: \n" \ " psubsw %%xmm2,%%xmm3 \n" \ " movdqa %%xmm4,(%%edi) \n" \ " movdqa %%xmm3,(%%edi,%%ebx,4) \n" \ " addl $16,%%edi \n" \ #L "3: \n" \ " cmpl %%esi,%%edi \n" \ " jnc " #L "9 \n" \ " movdqa (%%edi,%%ebx,4),%%xmm3 \n" \ " pxor %%xmm2,%%xmm2 \n" \ " movdqa %%xmm3,%%xmm1 \n" \ " pcmpeqb (%%edi,%%ebx,2),%%xmm2 \n" \ " paddsw %%xmm5,%%xmm3 \n" \ " paddsw %%xmm7,%%xmm1 \n" \ " movdqa (%%edi),%%xmm4 \n" \ " psrldq $16/8,%%xmm5 \n" \ " movdqa (%%edi,%%ecx,2),%%xmm0 \n" \ " psubsw %%xmm5,%%xmm3 \n" \ " psraw $" #C2 ",%%xmm1 \n" \ " movdqa %%xmm6,%%xmm5 \n" \ " psubsw %%xmm1,%%xmm3 \n" \ " psubsw %%xmm4,%%xmm6 \n" \ " movdqa (%%edi,%%ebx),%%xmm1 \n" \ " psubsw %%xmm6,%%xmm3 \n" \ " pmovmskb %%xmm2,%%eax \n" \ " psubsw %%xmm5,%%xmm0 \n" \ " movdqa 16(%%edi,%%ecx),%%xmm6 \n" \ " paddsw %%xmm0,%%xmm3 \n" \ " psrldq $112/8,%%xmm5 \n" \ " movdqa %%xmm6,%%xmm0 \n" \ " psraw $2,%%xmm1 \n" \ " pslldq $16/8,%%xmm0 \n" \ " psubsw %%xmm6,%%xmm5 \n" \ " paddsw %%xmm1,%%xmm4 \n" \ " movdqa %%xmm5,%%xmm2 \n" \ " cmpl $0x0000ffff,%%eax \n" \ " pslldq $112/8,%%xmm2 \n" \ " paddsw %%xmm0,%%xmm5 \n" \ " je " #L "2 \n" \ " cmpl $0x0000aaaa,%%eax \n" \ " je " #L "1 \n" \ " pcmpeqd %%xmm1,%%xmm1 \n" \ " psrldq $112/8,%%xmm1 \n" \ " movl $8,%%edx \n" \ #L "4: \n" \ " movzwl (%%edi,%%ebx,2),%%eax \n" \ " testl %%eax,%%eax \n" \ " je " #L "8 \n" \ " testl $0x0000fc00,%%eax \n" \ " je " #L "6 \n" \ " shrl $10,%%eax \n" \ " addl $32,%%eax \n" \ " andl $63,%%eax \n" \ " movd (%%ebp,%%eax,4),%%xmm0 \n" \ " pshuflw $0,%%xmm0,%%xmm0 \n" \ " pshufd $0,%%xmm0,%%xmm0 \n" \ " pand %%xmm1,%%xmm0 \n" \ " paddsw %%xmm0,%%xmm4 \n" \ " testl $32,%%eax \n" \ " jne " #L "5 \n" \ " addw $0x0400,(%%edi,%%ebx,2) \n" \ " jmp " #L "8 \n" \ #L "5: \n" \ " subw $0x0400,(%%edi,%%ebx,2) \n" \ " jmp " #L "7 \n" \ #L "6: \n" \ " movdqa %%xmm1,%%xmm0 \n" \ " pandn %%xmm4,%%xmm0 \n" \ " movdqa %%xmm0,%%xmm4 \n" \ #L "7: \n" \ " movw $0,(%%edi,%%ebx) \n" \ #L "8: \n" \ " pslldq $16/8,%%xmm1 \n" \ " addl $2,%%edi \n" \ " decl %%edx \n" \ " jnz " #L "4 \n" \ " subl $16,%%edi \n" \ " jmp " #L "2 \n" \ #L "9: \n" \ " popl %%eax \n" \ " fxrstor (%%esp) \n" \ " movl %%eax,%%esp \n" \ " popl %%edi \n" \ " popl %%edx \n" \ " popl %%ebp \n" \ : \ : "D"(cells),"S"(cells+(count&~7)),"b"(2*xdwCellMemCols), \ "c"(3*2*xdwCellMemCols),"d"(xdwCellFadingTable) \ : "eax","memory","cc" \ ) switch(xdwOptViscosity) { case 1: XDWOCO2(XDWOCO2_1_, 7,10); break; case 2: XDWOCO2(XDWOCO2_2_, 8, 9); break; case 3: XDWOCO2(XDWOCO2_3_, 9, 8); break; case 4: XDWOCO2(XDWOCO2_4_,10, 7); break; case 5: XDWOCO2(XDWOCO2_5_,11, 6); break; } i=count&7; if (i) xdwOperateCellsOpt0(cells+count-i,i); return True; } #elif defined(__GNUC__) && defined(__x86_64__) /* Same as above, but for 64-bit x86 CPU. TODO: This is still just a slightly modified "copy" of the 32-bit mode implementation. Surely it could be improved a little bit, by making use of the additional registers xmm8-xmm15. */ static Bool reported=False; int i; if (xdwCPUHasFXSR && xdwCPUHasSSE2) { if (!reported) { if (xdwOptVerb>=1) printf("Using SSE2 instruction set of 64-bit x86 CPU\n"); reported=True; } i=(((short*)0)-cells)&7; if (i) { xdwOperateCellsOpt0(cells,i); cells+=i; count-=i; } # define XDWOCO2(L,C1,C2) \ asm volatile ( \ " pushq %%rdi \n" \ " movq %%rsp,%%rax \n" \ " subq $512,%%rsp \n" \ " andq $-16,%%rsp \n" \ " fxsave (%%rsp) \n" \ " pushq %%rax \n" \ " pcmpeqw %%xmm7,%%xmm7 \n" \ " psrlw $" #C1 ",%%xmm7 \n" \ " movdqa (%%rdi,%%rcx),%%xmm6 \n" \ " movzwl -2(%%rdi,%%rcx),%%eax \n" \ " movd %%eax,%%xmm5 \n" \ " movdqa %%xmm6,%%xmm0 \n" \ " pslldq $16/8,%%xmm0 \n" \ " paddsw %%xmm0,%%xmm5 \n" \ " psubsw %%xmm6,%%xmm5 \n" \ " jmp " #L "3 \n" \ " .balign 16 \n" \ #L "1: \n" \ " pxor %%xmm4,%%xmm4 \n" \ " movdqa %%xmm4,(%%rdi,%%rbx) \n" \ #L "2: \n" \ " psubsw %%xmm2,%%xmm3 \n" \ " movdqa %%xmm4,(%%rdi) \n" \ " movdqa %%xmm3,(%%rdi,%%rbx,4) \n" \ " addq $16,%%rdi \n" \ #L "3: \n" \ " cmpq %%rsi,%%rdi \n" \ " jnc " #L "9 \n" \ " movdqa (%%rdi,%%rbx,4),%%xmm3 \n" \ " pxor %%xmm2,%%xmm2 \n" \ " movdqa %%xmm3,%%xmm1 \n" \ " pcmpeqb (%%rdi,%%rbx,2),%%xmm2 \n" \ " paddsw %%xmm5,%%xmm3 \n" \ " paddsw %%xmm7,%%xmm1 \n" \ " movdqa (%%rdi),%%xmm4 \n" \ " psrldq $16/8,%%xmm5 \n" \ " movdqa (%%rdi,%%rcx,2),%%xmm0 \n" \ " psubsw %%xmm5,%%xmm3 \n" \ " psraw $" #C2 ",%%xmm1 \n" \ " movdqa %%xmm6,%%xmm5 \n" \ " psubsw %%xmm1,%%xmm3 \n" \ " psubsw %%xmm4,%%xmm6 \n" \ " movdqa (%%rdi,%%rbx),%%xmm1 \n" \ " psubsw %%xmm6,%%xmm3 \n" \ " pmovmskb %%xmm2,%%eax \n" \ " psubsw %%xmm5,%%xmm0 \n" \ " movdqa 16(%%rdi,%%rcx),%%xmm6 \n" \ " paddsw %%xmm0,%%xmm3 \n" \ " psrldq $112/8,%%xmm5 \n" \ " movdqa %%xmm6,%%xmm0 \n" \ " psraw $2,%%xmm1 \n" \ " pslldq $16/8,%%xmm0 \n" \ " psubsw %%xmm6,%%xmm5 \n" \ " paddsw %%xmm1,%%xmm4 \n" \ " movdqa %%xmm5,%%xmm2 \n" \ " cmpl $0x0000ffff,%%eax \n" \ " pslldq $112/8,%%xmm2 \n" \ " paddsw %%xmm0,%%xmm5 \n" \ " je " #L "2 \n" \ " cmpl $0x0000aaaa,%%eax \n" \ " je " #L "1 \n" \ " pcmpeqd %%xmm1,%%xmm1 \n" \ " psrldq $112/8,%%xmm1 \n" \ " movl $8,%%r8d \n" \ #L "4: \n" \ " movzwl (%%rdi,%%rbx,2),%%eax \n" \ " testl %%eax,%%eax \n" \ " je " #L "8 \n" \ " testl $0x0000fc00,%%eax \n" \ " je " #L "6 \n" \ " shrl $10,%%eax \n" \ " addl $32,%%eax \n" \ " andq $63,%%rax \n" \ " movd (%%rdx,%%rax,4),%%xmm0 \n" \ " pshuflw $0,%%xmm0,%%xmm0 \n" \ " pshufd $0,%%xmm0,%%xmm0 \n" \ " pand %%xmm1,%%xmm0 \n" \ " paddsw %%xmm0,%%xmm4 \n" \ " testl $32,%%eax \n" \ " jne " #L "5 \n" \ " addw $0x0400,(%%rdi,%%rbx,2) \n" \ " jmp " #L "8 \n" \ #L "5: \n" \ " subw $0x0400,(%%rdi,%%rbx,2) \n" \ " jmp " #L "7 \n" \ #L "6: \n" \ " movdqa %%xmm1,%%xmm0 \n" \ " pandn %%xmm4,%%xmm0 \n" \ " movdqa %%xmm0,%%xmm4 \n" \ #L "7: \n" \ " movw $0,(%%rdi,%%rbx) \n" \ #L "8: \n" \ " pslldq $16/8,%%xmm1 \n" \ " addq $2,%%rdi \n" \ " decl %%r8d \n" \ " jnz " #L "4 \n" \ " subq $16,%%rdi \n" \ " jmp " #L "2 \n" \ #L "9: \n" \ " popq %%rax \n" \ " fxrstor (%%rsp) \n" \ " movq %%rax,%%rsp \n" \ " popq %%rdi \n" \ : \ : "D"(cells),"S"(cells+(count&~7)),"b"((long)2*xdwCellMemCols), \ "c"((long)3*2*xdwCellMemCols),"d"(xdwCellFadingTable) \ : "rax","r8","memory","cc" \ ) switch(xdwOptViscosity) { case 1: XDWOCO2(XDWOCO2_1_, 7,10); break; case 2: XDWOCO2(XDWOCO2_2_, 8, 9); break; case 3: XDWOCO2(XDWOCO2_3_, 9, 8); break; case 4: XDWOCO2(XDWOCO2_4_,10, 7); break; case 5: XDWOCO2(XDWOCO2_5_,11, 6); break; } i=count&7; if (i) xdwOperateCellsOpt0(cells+count-i,i); return True; } #endif return False; } static void xdwUpdateCells(int timeSlices) { short * p; int i, n, t, r, c; /* For all time slices of one frame, push forward the cellular automata at all cells. Don't forget storm. After a row r has been operated for one time slice, row r-2 can be operated for the next time slice. That's good for cache utilization. */ n=xdwCellRows-2+(timeSlices-1)*2; for (i=0; i=0 && r0) xdwUpdateStromRow(r); } } } } /*============================================================================*/ /*================ Visualization (Canvas, Palette & Lighting =================*/ /*============================================================================*/ /* The "canvas" holds the resulting image of the water and it knows where the output window (or back buffer) is up-to-date. One pixel of the canvas is a rectangle of xdwOptResDivX * xdwOptResDivY pixels on the output window. The upper-left corner of the upper-left pixel of the canvas lies in the upper-left corner of the upper-left pixel of the output window. */ int xdwCanvasWidth, xdwCanvasHeight; /* Width and height of the canvas. xdwCanvasWidth must be n*xdwOptCellW+1 with an integral n, xdwCanvasHeight must be appropriate. */ int xdwCanvasVisibleW, xdwCanvasVisibleH; /* Size of the visible part of the canvas. This may be a little smaller than the canvas size.*/ signed char * xdwCanvas; /* The canvas (array of pixels). Bits 0 to 6 are the color as a palette index. Bit 7 means: output window (or back buffer) is not up-to-date here. */ int xdwTouchedCvRow1, xdwTouchedCvRow2; /* Minimum range of canvas rows, where something is not up-to-date. If everything is up-to-date, xdwTouchedCvRow1 must be >=xdwCanvasHeight, and xdwTouchedCvRow2 must be <=0. TODO: Even try to develop this kind of optimization for columns. */ typedef struct { int count; XRectangle rects[256]; } xdwRectSet; xdwRectSet * * xdwRectSets; /* This array reserves some memory for using XFillRectangles. xdwRectSets[i] is a set of rectangles to be drawn with color xdwPalette[i]. */ int xdwSkyColorIndex; /* Index of sky color. */ int xdwColorCount; /* Number of colors in the palette. */ unsigned long * xdwPalette; /* The color palette. The entries are X pixel values. Water color is at index 0, sky color is at index xdwSkyColorIndex, and light color is at index xdwColorCount-1. Other entries are fadings between those base colors. */ signed char * xdwLightingTable; /* Table for speeding up lighting. */ static void xdwInitPalette(Display * display) { Colormap cmap; XColor ec[3]; XColor c; int i, a, b, q, n; /* Allocate and fill the palette. */ xdwColorCount=xdwOptMaxColors; xdwPalette=malloc(sizeof(unsigned long)*xdwColorCount); xdwSkyColorIndex=xdwColorCount*3/4; cmap=DefaultColormap(display,DefaultScreen(display)); if (!XLookupColor(display,cmap,xdwOptWaterColor,&ec[0],&c)) { fprintf(stderr,"%s: no such color: %s\n",xdwArg0,xdwOptWaterColor); exit(1); } if (!XLookupColor(display,cmap,xdwOptSkyColor,&ec[1],&c)) { fprintf(stderr,"%s: no such color: %s\n",xdwArg0,xdwOptSkyColor); exit(1); } if (!XLookupColor(display,cmap,xdwOptLightColor,&ec[2],&c)) { fprintf(stderr,"%s: no such color: %s\n",xdwArg0,xdwOptLightColor); exit(1); } for (i=0; i=1) { printf("Palette has %d different colors (from %d)\n", xdwColorCount,xdwOptMaxColors); } } static void xdwInitLighting(void) { double lx, ly, lz, nx, ny, nz, r, c, k; int i, j, d1, d2; /* Direction where the light is. */ r=cos(xdwOptLightAltitude*(M_PI/180.0)); lx=r*sin(xdwOptLightAzimuth*(M_PI/180.0)); ly=-r*cos(xdwOptLightAzimuth*(M_PI/180.0)); lz=sin(xdwOptLightAltitude*(M_PI/180.0)); /* Prepare a table for that xdwUpdateCanvas(..) can perform faster. */ xdwLightingTable=malloc(sizeof(signed char)*0x40000); for (i=0; i<0x40000; i++) { /* Calculate norm vector of the water surface. */ d1=i>>9; if (d1&0x100) d1|=~0xff; d2=i&0x1ff; if (d2&0x100) d2|=~0xff; nx=d1-d2; ny=d1+d2; nz=128.0; r=sqrt(nx*nx+ny*ny+nz*nz); nx/=r; ny/=r; nz/=r; /* Reflection of the sky. */ k=xdwOptSkyIntensity*xdwOptSkyIntensity*(0.99-nz*nz)*0.2; if (k>1.0) k=1.0; if (k<0.0) k=0.0; c=k*xdwSkyColorIndex; /* Reflection of light source. */ k=(nx*lx+ny*ly+nz*lz)*nz*2.0-lz; if (k>0.0) { k=(0.51+xdwOptLightIntensity*0.043-sqrt(1.0001-k*k))/0.47; if (k>0.0) { if (k>1.0) k=1.0; c+=k*k*(xdwColorCount-1); } } /* Saturate and set table entry. */ j=(int)(c+0.5); if (j<0) j=0; else if (j>=xdwColorCount) j=xdwColorCount-1; xdwLightingTable[i]=j; } } static void xdwInitCanvas(int windowWidth, int windowHeight) { int i; /* Calculate sizes. */ xdwCanvasVisibleW=(windowWidth-1)/xdwOptResDivX+1; xdwCanvasVisibleH=(windowHeight-1)/xdwOptResDivY+1; xdwCanvasWidth=((xdwCanvasVisibleW-2)/xdwOptCellW+1)*xdwOptCellW+1; xdwCanvasHeight=((xdwCanvasVisibleH-2)/xdwOptCellH+1)*xdwOptCellH+1; /* Allocate the array of pixels, and mark all pixels as out-of-date. */ xdwCanvas=malloc(sizeof(signed char)*xdwCanvasWidth*xdwCanvasHeight); memset(xdwCanvas,0x80,xdwCanvasWidth*xdwCanvasHeight); /* Allocate and initialize memory for sets of rectangles. */ xdwRectSets=malloc(sizeof(xdwRectSet)*xdwColorCount); for (i=0; icount=0; } /* Nothing is up-to-date. */ xdwTouchedCvRow1=0; xdwTouchedCvRow2=xdwCanvasHeight; } static Bool xdwTouchCanvas(int x1, int y1, int x2, int y2) { signed char * p, * pe; /* Mark a rectangular region as out-of-date. The given coordinates are in window pixels. */ x1/=xdwOptResDivX; x2=(x2+xdwOptResDivX-1)/xdwOptResDivX; if (x1<0) x1=0; if (x2>xdwCanvasVisibleW) x2=xdwCanvasVisibleW; if (x1>=x2) return False; y1/=xdwOptResDivY; y2=(y2+xdwOptResDivY-1)/xdwOptResDivY; if (y1<0) y1=0; if (y2>xdwCanvasVisibleH) y2=xdwCanvasVisibleH; if (y1>=y2) return False; if (xdwTouchedCvRow1>y1) xdwTouchedCvRow1=y1; if (xdwTouchedCvRow2>5) ]; p++; if (*q!=c) break; q+=xdwOptCellW; } while(q=qe) return False; *q=c|0x80; q+=xdwOptCellW; if (q>=qe) return True; do { c=xdwLightingTable[ (((p[0]-p[cols3+1])&0x3fe0)<<4)+ (((p[1]-p[cols3])&0x3fe0)>>5) ]; p++; if (*q!=c) *q=c|0x80; q+=xdwOptCellW; } while(q>1; if (q[xdwCanvasWidth]!=c) q[xdwCanvasWidth]=c|0x80; q+=xdwOptCellW; } while(q>1; if (q[2*xdwCanvasWidth]!=c) q[2*xdwCanvasWidth]=c|0x80; c1=(c1+c+1)>>1; if (q[xdwCanvasWidth]!=c1) q[xdwCanvasWidth]=c1|0x80; c2=(c2+c+1)>>1; if (q[3*xdwCanvasWidth]!=c2) q[3*xdwCanvasWidth]=c2|0x80; q+=xdwOptCellW; } while(q>1); t=q+xdwCanvasWidth; for (i=1; i>1; if (*q!=c) *q=c|0x80; q+=2; } while(q>1; c1=(c1+c+1)>>1; if (*q!=c1) *q=c1|0x80; if (q[1]!=c) q[1]=c|0x80; c=c+c-c1; if (q[2]!=c) q[2]=c|0x80; q+=4; } while(q>1); for (i=1; i=0; y1-=xdwOptCellH) { prvChanged=curChanged; curChanged=xdwCvDoLighting(y1); if (!prvChanged && !curChanged) continue; if (xdwTouchedCvRow1>y1) xdwTouchedCvRow1=y1; if (xdwTouchedCvRow2=pxe) break; c=*px; c7=c&0x7f; rs=xdwRectSets[c7]; if (rs->count>=256) { (*pXFRCalls)++; (*pRects)+=rs->count; XSetForeground(display,gc,xdwPalette[c7]); XFillRectangles(display,drawable,gc,rs->rects,rs->count); rs->count=0; } r=rs->rects+rs->count; rs->count++; r->x=sx; r->y=sy; r->width=xdwOptResDivX; r->height=xdwOptResDivY; *px=c7; py=px+xdwCanvasWidth; px++; sx+=xdwOptResDivX; if (pxwidth+=xdwOptResDivX; sx+=xdwOptResDivX; px++; if (pyheight+=xdwOptResDivY; py+=xdwCanvasWidth; pxy=py+2; for (;;) { p=px; if (pheight+=xdwOptResDivY; } break; } p=px; do { *p=c7; p+=xdwCanvasWidth; } while (pwidth+=xdwOptResDivX; sx+=xdwOptResDivX; p=py; if (pwidth+=xdwOptResDivX; sx+=xdwOptResDivX; } break; } p=py; do { *p=c7; p++; } while (pheight+=xdwOptResDivY; } } else if (pxwidth+=xdwOptResDivX; } while (pxheight+=xdwOptResDivY; } while (py=0; c--) if ((rs=xdwRectSets[c])->count) { (*pXFRCalls)++; (*pRects)+=rs->count; XSetForeground(display,gc,xdwPalette[c]); XFillRectangles(display,drawable,gc,rs->rects,rs->count); rs->count=0; } xdwTouchedCvRow1=xdwCanvasHeight; xdwTouchedCvRow2=0; } /*============================================================================*/ /*================================== Times ===================================*/ /*============================================================================*/ unsigned xdwAbsTimeMS=0; /* Time in milliseconds (starts somewhere an may overflow). */ unsigned xdwProcTimeMS=0; /* Process busy time in milliseconds (starts somewhere an may overflow). */ static void xdwUpdateTimes(void) { static long tps=-1; static clock_t atcks=0, ptcks=0; clock_t d; struct tms tb; if (tps<=0) { tps=sysconf(_SC_CLK_TCK); if (tps<=0) { fprintf(stderr,"%s: sysconf(_SC_CLK_TCK) failed\n",xdwArg0); exit(1); } } d=times(&tb)-atcks; if (d) { atcks+=d; xdwAbsTimeMS+=(unsigned)( ((unsigned long)d)/((unsigned long)tps)*1000+ ((unsigned long)d)%((unsigned long)tps)*1000/(unsigned long)tps ); } d=tb.tms_utime+tb.tms_stime-ptcks; if (d) { ptcks+=d; xdwProcTimeMS+=(unsigned)( ((unsigned long)d)/((unsigned long)tps)*1000+ ((unsigned long)d)%((unsigned long)tps)*1000/(unsigned long)tps ); } } /*============================================================================*/ /*============================= Signal Handling ==============================*/ /*============================================================================*/ Bool xdwTerminationRequested=False; /* True if the program should terminate. */ Bool xdwFreeze=False; /* True if the program should freeze (just for making screenshots). Toggled by SIGUSR1. */ static void xdwSignalHandler(int signum) { /* Handle a signal... */ if (signum==SIGUSR1) xdwFreeze=!xdwFreeze; else xdwTerminationRequested=True; } static void xdwInitSignalHandling(void) { /* Install the signal handler. */ signal(SIGHUP ,xdwSignalHandler); signal(SIGINT ,xdwSignalHandler); signal(SIGQUIT,xdwSignalHandler); signal(SIGABRT,xdwSignalHandler); signal(SIGTERM,xdwSignalHandler); signal(SIGUSR1,xdwSignalHandler); } /*============================================================================*/ /*============================= X Error Handling =============================*/ /*============================================================================*/ int xdwXErrorAcceptance=0; /* Non-zero if X errors should be accepted/ignored, instead of terminating the program. */ int (*xdwOriginalXErrorHandler)(Display *, XErrorEvent *); /* Original X error handler. */ static int xdwXErrorHandler(Display * display, XErrorEvent * errorEvent) { char msg[256]; /* Own X error handler: fall back to the original handler, or accept the error. */ if (!xdwXErrorAcceptance) { return (*xdwOriginalXErrorHandler)(display,errorEvent); } if (xdwOptVerb>=2) { XGetErrorText(display,errorEvent->error_code,msg,sizeof(msg)); printf("XError accepted: %s\n",msg); } return 0; } static void xdwInitXErrorHandling(void) { /* Install X error handler. */ xdwOriginalXErrorHandler=XSetErrorHandler(xdwXErrorHandler); } static void xdwBeginAcceptXErrors(void) { /* Increase nesting of accepting X errors. */ xdwXErrorAcceptance++; } static void xdwEndAcceptXErrors(void) { /* Decrease nesting of accepting X errors. */ xdwXErrorAcceptance--; } /*============================================================================*/ /*==================== Detection of Virtual Root Window ======================*/ /*============================================================================*/ static Window xdwDetectVirtualRoot(Display * display, Window * pAboveWin, Bool * pIsNautilus) { XWindowAttributes attr; Window rwin, win, win2, win3, win4, win5; Window * cwins, * cwins2, * cwins3; Atom atom,type; int i, j, k, l, m, n, r, rwidth, rheight, frmt; unsigned long len, rem; unsigned char * data; char * str; /* This code tries to find a virtual root window created by the window manager. It's a horrible topic. I stole some ideas from Andreas Stolcke's vroot.h, and some from Robin Hogan's toon_root.c (xpenguins). */ /* Prepare some variables. */ *pAboveWin=None; *pIsNautilus=False; rwin=DefaultRootWindow(display); rwidth=DisplayWidth(display,DefaultScreen(display)); rheight=DisplayHeight(display,DefaultScreen(display)); /* The good(?) old standard(?): Maybe there is a child-of-root window which has a property named __SWM_VROOT, pointing to the virtual root window. This even works with KDE if "Allow Programs in Desktop Window" has been enabled in the desktop configuration. */ atom=XInternAtom(display,"__SWM_VROOT",False); XQueryTree(display,rwin,&win,&win2,&cwins,(unsigned*)&n); for (win=None, i=0; i=1) printf("Virtual Root detected: 0x%lX\n",win); return win; } /* Nautilus has a root window property pointing to the desktop window. But we have to go deeper within that desktop window... */ atom=XInternAtom(display,"NAUTILUS_DESKTOP_WINDOW_ID",False); r=XGetWindowProperty(display,rwin,atom,0,1,False,XA_WINDOW, &type,&frmt,&len,&rem,&data); win=(r==Success && type==XA_WINDOW && data) ? *(Window*)data : None; if (data) XFree(data); if (win) { for (win2=win;;) { XQueryTree(display,win2,&win4,&win5,&cwins,(unsigned*)&n); for (win3=None, i=n-1; i>=0; i--) { XGetWindowAttributes(display,cwins[i],&attr); if (attr.x==0 && attr.y==0 && attr.width==rwidth && attr.height==rheight && attr.map_state==IsViewable && attr.override_redirect==False) { win3=cwins[i]; break; } } if (cwins) XFree(cwins); if (win3==None) break; win2=win3; } if (xdwOptVerb>=1) { printf("Nautilus Desktop detected: 0x%lX, using 0x%lX\n",win,win2); } *pIsNautilus=True; return win2; } /* For old version of KDE, or if "Allow Programs in Desktop Window" has not been enabled in the KDE Desktop Configuration: There is a child-of-child-of-child-of-root window named "KDE Desktop". All windows in that path are full-size. But we have to go deeper within the desktop window, with large-size instead of full-size... */ XQueryTree(display,rwin,&win,&win2,&cwins,(unsigned*)&n); for (win=None, i=n-1; win==None && i>=0; i--) { XGetWindowAttributes(display,cwins[i],&attr); if (attr.x!=0 || attr.y!=0 || attr.width!=rwidth || attr.height!=rheight || attr.map_state!=IsViewable) continue; XQueryTree(display,cwins[i],&win2,&win3,&cwins2,(unsigned*)&m); for (j=m-1; win==None && j>=0; j--) { XGetWindowAttributes(display,cwins2[j],&attr); if (attr.x!=0 || attr.y!=0 || attr.width!=rwidth || attr.height!=rheight || attr.map_state!=IsViewable || attr.override_redirect!=False) continue; XQueryTree(display,cwins2[j],&win2,&win3,&cwins3,(unsigned*)&l); for (k=l-1; win==None && k>=0; k--) { XGetWindowAttributes(display,cwins3[k],&attr); if (attr.x!=0 || attr.y!=0 || attr.width!=rwidth || attr.height!=rheight || attr.map_state!=IsViewable || attr.override_redirect!=False) continue; if (XFetchName(display,cwins3[k],&str)) { if (strcmp(str,"KDE Desktop")==0) win=cwins3[k]; XFree(str); } } if (cwins3) XFree(cwins3); } if (cwins2) XFree(cwins2); } if (cwins) XFree(cwins); if (win) { for (win2=win;;) { XQueryTree(display,win2,&win4,&win5,&cwins,(unsigned*)&n); for (win3=None, i=n-1; i>=0; i--) { XGetWindowAttributes(display,cwins[i],&attr); if (attr.x>=0 && attr.y>=0 && attr.x+attr.width<=rwidth && attr.y+attr.height<=rheight && attr.width>=rwidth*3/4 && attr.height>=rheight*3/4 && attr.map_state==IsViewable && attr.override_redirect==False) { win3=cwins[i]; break; } } if (cwins) XFree(cwins); if (win3==None) break; win2=win3; } if (xdwOptVerb>=1) { printf("KDE Desktop detected: 0x%lX, using 0x%lX\n",win,win2); } return win2; } /* For CDE and possibly others: Try to detect another backdrop window on the real root and prepare for stacking our backdrop above the other backdrop. This should be safe, because it is checked that the other backdrop has no children, no button input and no other window behind. */ XQueryTree(display,rwin,&win2,&win3,&cwins,(unsigned*)&n); win=(n>=1?cwins[0]:None); if (cwins) XFree(cwins); if (win!=None && XFetchName(display,win,&str) && str) { if (strcmp(str,"xdesktopwaves")==0) win=None; XFree(str); } if (win!=None) { XGetWindowAttributes(display,win,&attr); if (attr.x==0 && attr.y==0 && attr.width==rwidth && attr.height==rheight && attr.border_width==0 && attr.map_state==IsViewable && attr.override_redirect==True && attr.class==InputOutput && !(attr.all_event_masks&ButtonPressMask)) { XQueryTree(display,win,&win2,&win3,&cwins,(unsigned*)&n); if (cwins) XFree(cwins); if (n==0) { if (xdwOptVerb>=1) printf("Other backdrop detected (CDE?)\n"); *pAboveWin=win; return rwin; } } } /* No special window found. Just return the real root window. */ return rwin; } /*============================================================================*/ /*============================== Mouse on Water ==============================*/ /*============================================================================*/ int xdwMouseX=-1, xdwMouseY=-1; /* Position of the mouse pointer, or -1 if the mouse does not cover the water. */ static Bool xdwChangeMouse(int mx, int my) { Bool b; /* Change the mouse position and adapt the covering. */ b=False; if (xdwOptWavesByMouse && (mx!=xdwMouseX || my!=xdwMouseY)) { if (xdwMouseX>=0) b|=xdwCoverCircle(xdwMouseX,xdwMouseY,6,-1); xdwMouseX=mx; xdwMouseY=my; if (xdwMouseX>=0) b|=xdwCoverCircle(xdwMouseX,xdwMouseY,6,1); } return b; } /*============================================================================*/ /*======== Windows on Water, Visibility, Event Selection, Backdropping =======*/ /*============================================================================*/ /* This ugly part has four jobs: - Interaction of windows and water. - Determine whether the output window is fully obscured by other windows. - Select events. - Update backdropping of the output window. To solve these, we are tracking a tree of windows. Our anchor to the tree is not the root window, but the output window (variable xdwWinPath). The windows w1=xdwWinPath, w2=w1->parent, w3=w2->parent... are making up the path from the output window up to the root window (possibly it's just one window). For each window in that path, we are tracking all their direct children. Several events have to be selected for keeping the tree up-to-date. And because XSelectInput has no and/or/xor option, the events from the other program parts are even selected here (e.g. mouse movements on the output window). Unfortunately the XVisibilityEvent would be useless here, because it does not respect child windows. Instead, the visibility is calculated from the mentioned windows, using xdwRegion. Finally, because we know the window lists in this program part, it is even a good place for updating the backdropping. */ typedef struct xdwWinNodeStruct { /* Data type for an element in the tree of windows. */ struct xdwWinNodeStruct * sister; /* Next element in the parent's list of children. */ struct xdwWinNodeStruct * parent; /* The parent (next element in path). */ struct xdwWinNodeStruct * childInPath; /* The child where the output window is (previous element in path). */ struct xdwWinNodeStruct * firstChild; /* List of all children. */ Window window; /* Id of the window. */ long eventMask, shapeEventMask; /* Selected events on the window. */ XWindowAttributes attr; /* Attributes of the window. */ XRectangle * shapeRects; int shapeRectCount; /* Array of rectangles, if it is a shaped window. */ unsigned isInPath : 1; /* Whether this window is member of the path. */ unsigned interaction : 1; /* Whether this window should interact with the water. */ unsigned attrUpToDate : 1; /* Whether the attributes are up-to-date. */ unsigned linkageUpToDate : 1; /* Whether the relationships to other windows are up-to-date. */ unsigned shapeUpToDate : 1; /* Whether the shape information is up-to-date. */ unsigned interactionUpToDate : 1; /* Whether the interaction information is up-to-date. */ } xdwWinNode; xdwWinNode * xdwWinPath; /* (refer to the description above) */ int xdwWinPathX,xdwWinPathY; /* Position of the output window relative to the root window. */ int xdwShapeEventBase, xdwShapeErrorBase; /* General information about the XShape extension. */ Atom XDESKTOPWAVES_WINDOW_INTERACTION; /* Property of client windows. It overrides the waves-by-windows option. */ xdwRegion xdwWindowShips; /* This region summarizes all windows which interact with the water. */ int xdwVisiblePixels; /* Number of visible pixels in the output window. */ Bool xdwWindowTrackingUpToDate; /* Whether everything here is up-to-date. */ static xdwWinNode * xdwCreateWinNode(Window window) { xdwWinNode * n; /* Create a new window node. */ n=malloc(sizeof(xdwWinNode)); memset(n,0,sizeof(xdwWinNode)); n->window=window; return n; } static void xdwDestroyWinTree(Display * display, xdwWinNode * tree) { xdwWinNode * n; /* Destroy a node and all its descendants */ if (tree) { while ((n=tree->firstChild)!=NULL) { tree->firstChild=n->sister; xdwDestroyWinTree(display,n); } if (tree->eventMask || tree->shapeEventMask) { xdwBeginAcceptXErrors(); if (tree->eventMask) { XSelectInput(display,tree->window,0); } if (tree->shapeEventMask) { XShapeSelectInput(display,tree->window,0); } XSync(display,False); xdwEndAcceptXErrors(); } if (tree->shapeRects) { XFree(tree->shapeRects); } free(tree); } } static void xdwDestroyWinAncestors(Display * display, xdwWinNode * node) { xdwWinNode * n, * parent; xdwWinNode * * pn; /* Destroy all nodes but the given node and its descendants */ if (node && node->parent) { parent=node->parent; node->parent=NULL; for (pn=&parent->firstChild, n=*pn; n; pn=&n->sister, n=*pn) { if (n==node) { *pn=n->sister; n->sister=NULL; break; } } while (parent->parent) parent=parent->parent; xdwDestroyWinTree(display,parent); } } static void xdwInitWindowTracking(Display * display, Window drawWin) { /* Query Shape extension. */ if (!XShapeQueryExtension(display,&xdwShapeEventBase,&xdwShapeErrorBase)) { fprintf(stderr,"%s: XShape extension not available\n",xdwArg0); exit(1); } /* Have an atom for the window interaction property. */ XDESKTOPWAVES_WINDOW_INTERACTION=XInternAtom( display,"XDESKTOPWAVES_WINDOW_INTERACTION",False ); /* Create a node for the output window. */ xdwWinPath=xdwCreateWinNode(drawWin); xdwWinPath->isInPath=1; /* Prepare some other variables. */ xdwWinPathX=0; xdwWinPathY=0; xdwInitRegion(&xdwWindowShips); xdwVisiblePixels=0; /* Not up-to-date. */ xdwWindowTrackingUpToDate=False; } static xdwWinNode * xdwSearchWinNode(Window window) { xdwWinNode * n; /* Search for a node by a given window id. */ n=xdwWinPath; while (n->parent) n=n->parent; while (n->window!=window) { if (n->firstChild) n=n->firstChild; else if (n->sister) n=n->sister; else { do { n=n->parent; } while (n && !n->sister); if (!n) break; n=n->sister; } } return n; } static void xdwOnSubstructureChanged(Window window) { xdwWinNode * n; /* Got a substructure notify event... */ n=xdwSearchWinNode(window); if (n) { n->linkageUpToDate=0; for (n=n->firstChild; n; n=n->sister) { n->attrUpToDate=0; /* We will not get any shape notify events, if the window is not shaped. Therefore: */ if (n->shapeRects && n->shapeRectCount<=1) n->shapeUpToDate=0; } xdwWindowTrackingUpToDate=False; } } static void xdwOnInteractionPropertyChanged(Window window) { xdwWinNode * n; /* Got a change event for the interaction property... */ n=xdwSearchWinNode(window); if (n) { n->interactionUpToDate=0; xdwWindowTrackingUpToDate=False; } } static void xdwOnShapeChanged(Window window) { xdwWinNode * n; /* Got a shape notify event... */ n=xdwSearchWinNode(window); if (n) { n->shapeUpToDate=0; xdwWindowTrackingUpToDate=False; } } static Bool xdwUpdateWinNode(Display * display, xdwWinNode * node) { xdwWinNode * n, * oldList; xdwWinNode * * pn, * * pn2; long eventMask, shapeEventMask; unsigned long len, rem; unsigned char * data; Window rwin, pwin; Window * cwins; Atom type; int i, ordering, r, frmt, cnt; /* Which events should be selected on the window? */ if (node->isInPath) { eventMask=SubstructureNotifyMask; shapeEventMask=0; if (!node->parent) eventMask|=PropertyChangeMask; if (!node->childInPath) { eventMask|=ExposureMask|PointerMotionMask|EnterWindowMask|LeaveWindowMask; } else if (!node->childInPath->childInPath && xdwOptTransparency==XDW_SHAPED) { eventMask|=PointerMotionMask|EnterWindowMask|LeaveWindowMask; } } else { eventMask=PropertyChangeMask; shapeEventMask=ShapeNotifyMask; } /* Update event selection. */ if (node->eventMask!=eventMask || node->shapeEventMask!=shapeEventMask) { xdwBeginAcceptXErrors(); if (node->eventMask!=eventMask) { XSelectInput(display,node->window,eventMask); node->eventMask=eventMask; } if (node->shapeEventMask!=shapeEventMask) { XShapeSelectInput(display,node->window,shapeEventMask); node->shapeEventMask=shapeEventMask; } XSync(display,False); xdwEndAcceptXErrors(); } /* Update attributes. */ if (!node->attrUpToDate) { xdwBeginAcceptXErrors(); r=XGetWindowAttributes(display,node->window,&node->attr); if (!r) memset(&node->attr,0,sizeof(node->attr)); node->attrUpToDate=1; xdwEndAcceptXErrors(); } /* Update shape information. */ if (!node->shapeUpToDate) { if (node->shapeRects) { XFree(node->shapeRects); node->shapeRects=NULL; node->shapeRectCount=0; } if (!node->isInPath) { xdwBeginAcceptXErrors(); node->shapeRects=XShapeGetRectangles( display,node->window,ShapeBounding,&node->shapeRectCount, &ordering ); xdwEndAcceptXErrors(); } node->shapeUpToDate=1; } /* Update interaction bit. */ if (!node->interactionUpToDate) { if (node->isInPath) { node->interaction=1; } else { xdwBeginAcceptXErrors(); data=NULL; r=XGetWindowProperty( display,node->window,XDESKTOPWAVES_WINDOW_INTERACTION, 0,1,False,XA_CARDINAL,&type,&frmt,&len,&rem,&data ); if (r==Success && type==XA_CARDINAL && data) { node->interaction = (*(unsigned*)data) ? 1 : 0; } else { node->interaction = xdwOptWavesByWindows ? 1 : 0; } if (data) XFree(data); xdwEndAcceptXErrors(); } node->interactionUpToDate=1; } /* Update relationships. */ if (!node->linkageUpToDate) { /* Query tree... */ xdwBeginAcceptXErrors(); r=XQueryTree(display,node->window,&rwin,&pwin,&cwins,(unsigned*)&cnt); if (!r) { rwin=None; pwin=None; cwins=NULL; cnt=0; } xdwEndAcceptXErrors(); /* Do not have any children if this is a window "out-of-path". */ if (!node->isInPath && cwins) { XFree(cwins); cwins=NULL; cnt=0; } /* Check parent relation. */ if ( (!node->parent && pwin!=None) || (node->parent && node->parent->window!=pwin) ) { if (node->isInPath) { if (node->parent) { xdwDestroyWinAncestors(display,node); node->parent=NULL; } if (pwin!=None) { node->parent=xdwCreateWinNode(pwin); node->parent->isInPath=1; node->parent->firstChild=node; node->parent->childInPath=node; node->sister=NULL; } } else { node->parent->linkageUpToDate=0; if (cwins) XFree(cwins); return False; } } /* Check child-in-path relation. */ if (node->childInPath) { for (i=0; ichildInPath->window; i++); if (i>=cnt) { node->childInPath->linkageUpToDate=0; if (cwins) XFree(cwins); return False; } } /* Update the list of children. */ oldList=node->firstChild; node->firstChild=NULL; pn=&node->firstChild; for (i=0; isister, n=*pn2) { if (n->window==cwins[i]) break; } if (n) { *pn2=n->sister; n->sister=NULL; } else { n=xdwCreateWinNode(cwins[i]); n->parent=node; n->linkageUpToDate=1; } *pn=n; pn=&n->sister; } while ((n=oldList)!=NULL) { oldList=n->sister; xdwDestroyWinTree(display,n); } if (cwins) XFree(cwins); node->linkageUpToDate=1; } return True; } static Bool xdwUpdateWindowTracking(Display * display) { xdwWinNode * pathElement, * child; xdwWinNode * node, * n; xdwRegion oldShips, noShips, visibility; xdwRegScan * s, * t; Bool coveringChanged; Window swins[2]; int x0, y0, y, y2, i; /* Be quick if everything is up-to-date here. */ if (xdwWindowTrackingUpToDate) return False; /* Update the tree... */ for (pathElement=xdwWinPath; pathElement;) { if (!xdwUpdateWinNode(display,pathElement)) { pathElement=xdwWinPath; } else { for (child=pathElement->firstChild; ; child=child->sister) { if (!child) { pathElement=pathElement->parent; break; } if (!xdwUpdateWinNode(display,child)) { pathElement=xdwWinPath; break; } } } } /* Calculate region of visible areas (visibility), calculate region of interacting windows (xdwWindowShips, but keep old variant in oldShips), and calculate the relative position of the output window (xdwWinPathX, xdwWinPathY). */ memcpy(&oldShips,&xdwWindowShips,sizeof(xdwRegion)); xdwInitRegion(&xdwWindowShips); xdwInitRegion(&visibility); xdwInitRegion(&noShips); xdwSetRegionRect( &noShips,0,0,xdwWinPath->attr.width,xdwWinPath->attr.height ); if (xdwWinPath->attr.map_state==IsViewable) { xdwSetRegionRect( &visibility,0,0,xdwWinPath->attr.width,xdwWinPath->attr.height ); } for (x0=0, y0=0, node=xdwWinPath; node; node=node->parent) { if (node->childInPath) { n=node->childInPath; x0-=n->attr.x; y0-=n->attr.y; n=n->sister; xdwRegAndRect( &visibility, x0, y0, x0+node->attr.width, y0+node->attr.height ); } else { n=node->firstChild; } for (; n; n=n->sister) { if (n->attr.map_state==IsViewable && n->attr.class!=InputOnly) { if (n->shapeRects) { for (i=0; ishapeRectCount; i++) { xdwRegAndNotRect( n->interaction ? &noShips : &visibility, x0+n->attr.x+n->shapeRects[i].x, y0+n->attr.y+n->shapeRects[i].y, x0+n->attr.x+n->shapeRects[i].x+n->shapeRects[i].width, y0+n->attr.y+n->shapeRects[i].y+n->shapeRects[i].height ); } } else { xdwRegAndNotRect( n->interaction ? &noShips : &visibility, x0+n->attr.x-n->attr.border_width, y0+n->attr.y-n->attr.border_width, x0+n->attr.x+n->attr.width+n->attr.border_width, y0+n->attr.y+n->attr.height+n->attr.border_width ); } } } } xdwSetRegionRect( &xdwWindowShips,0,0,xdwWinPath->attr.width,xdwWinPath->attr.height ); xdwRegAndNotReg(&xdwWindowShips,&noShips); xdwRegAndNotReg(&visibility,&xdwWindowShips); xdwWinPathX = -x0; xdwWinPathY = -y0; /* How many visible pixels do we have in the output window? */ xdwVisiblePixels=xdwCountRegionPixels(&visibility); /* Update covering by windows. */ coveringChanged=False; y=xdwWindowShips.y1; if (y>oldShips.y1) y=oldShips.y1; y2=xdwWindowShips.y2; if (y2=oldShips.y1 && y=xdwWindowShips.y1 && yx1x1)) { coveringChanged|=xdwCoverRect(s->x1,y,s->x2,y+1,-1); s=s->next; } else if (!s || s->x1!=t->x1 || s->x2!=t->x2) { coveringChanged|=xdwCoverRect(t->x1,y,t->x2,y+1,1); t=t->next; } else { s=s->next; t=t->next; } } } /* Get rid of temporary regions. */ xdwEmptyRegion(&visibility); xdwEmptyRegion(&noShips); xdwEmptyRegion(&oldShips); /* Backdropping: If there is a non-override-redirect window somewhere behind our backdrop window, bring our window behind it. */ if (xdwOptWindowCreation==XDW_BACKDROP && xdwWinPath->parent) { n=xdwWinPath->parent->firstChild; while (n!=xdwWinPath) { if (!n->attr.override_redirect) { swins[0]=n->window; swins[1]=xdwWinPath->window; xdwBeginAcceptXErrors(); XRestackWindows(display,swins,2); XSync(display,False); xdwEndAcceptXErrors(); break; } n=n->sister; } } /* Ready. */ xdwWindowTrackingUpToDate=True; return coveringChanged; } /*============================================================================*/ /*======================= Inter client communications ========================*/ /*============================================================================*/ Window xdwWindow; /* A created window for receiving client messages. */ Atom XDESKTOPWAVES_WINDOW_ID; /* A root window property for the window id. */ Atom XDESKTOPWAVES_COMMAND_MESSAGE; /* Client message type for receiving commands. */ Atom xdw_WM_PROTOCOLS; Atom xdw_WM_DELETE_WINDOW; /* Atoms for receiving deletion requests from the window manager. */ typedef struct xdwGhostStruct { /* Data type for a "ghost" on the water, generated by a client. */ struct xdwGhostStruct * next; /* Next elements in the list. */ int ghostId; /* Identification number of the ghost. */ int milliSecs; /* Remaining lifetime in milliseconds. */ Bool isCircle; /* Whether it's a circle or a rectangle. */ int x, y, width, height, radius; /* Coordinates... */ } xdwGhost; xdwGhost * xdwGhostList; /* List of ghosts. */ static void xdwInitCommunications(Display * display, Window ownWin) { /* Keep id of created window. */ xdwWindow=ownWin; /* Have some atoms. */ XDESKTOPWAVES_WINDOW_ID=XInternAtom( display,"XDESKTOPWAVES_WINDOW_ID",False ); XDESKTOPWAVES_COMMAND_MESSAGE=XInternAtom( display,"XDESKTOPWAVES_COMMAND_MESSAGE",False ); xdw_WM_PROTOCOLS=XInternAtom( display,"WM_PROTOCOLS",False ); xdw_WM_DELETE_WINDOW=XInternAtom( display,"WM_DELETE_WINDOW",False ); /* Set the window id property. Other instances will terminate after recognizing the change. */ XChangeProperty(display,DefaultRootWindow(display),XDESKTOPWAVES_WINDOW_ID, XA_WINDOW,32,PropModeReplace,(unsigned char*)&xdwWindow,1); /* Just for terminating old versions of xdesktopwaves. */ XDeleteProperty(display,DefaultRootWindow(display), XInternAtom(display,"XDESKTOPWAVES_INSTANCE_ID",False)); /* Finalize the property changes. */ XSync(display,False); } static void xdwCheckInstance(Display * display) { unsigned char * data; unsigned long len, bytesAfter; int format, ret; Atom type; /* See if there is a newer instance. If so, prepare for termination. */ data=NULL; ret=XGetWindowProperty( display,DefaultRootWindow(display),XDESKTOPWAVES_WINDOW_ID,0,1,False, XA_WINDOW,&type,&format,&len,&bytesAfter,&data ); if ( ret!=Success || type!=XA_WINDOW || format!=32 || bytesAfter!=0 || len!=1 || (*(Window*)data)!=xdwWindow ) { xdwTerminationRequested=True; } if (data) XFree(data); } static Bool xdwCoverByGhost(xdwGhost * g, int deltaCovering) { if (g->isCircle) { return xdwCoverCircle(g->x,g->y,g->radius,deltaCovering); } else { return xdwCoverRect(g->x,g->y,g->x+g->width,g->y+g->height,deltaCovering); } } static Bool xdwOnClientMessage(XClientMessageEvent * msg) { xdwGhost * g; Bool changed; int removeId,intensity; changed=False; if (msg->message_type==xdw_WM_PROTOCOLS) { if (msg->data.l[0]==xdw_WM_DELETE_WINDOW) { if (xdwOptVerb>=2) printf("got WM_DELETE_WINDOW\n"); xdwTerminationRequested=True; } } else if (msg->message_type==XDESKTOPWAVES_COMMAND_MESSAGE) { if (xdwOptVerb>=2) printf( "got command: %d %d %d %d %d %d %d %d %d %d\n", msg->data.s[0],msg->data.s[1],msg->data.s[2],msg->data.s[3], msg->data.s[4],msg->data.s[5],msg->data.s[6],msg->data.s[7], msg->data.s[8],msg->data.s[9] ); switch (msg->data.s[0]) { case 0: /* Ping */ break; case 1: /* Clear */ xdwClearCells(); changed=True; break; case 2: /* SetRain */ intensity=msg->data.s[1]; if (intensity<0) intensity=0; else if (intensity>10) intensity=10; xdwOptRain=intensity; break; case 3: /* SetStorm */ intensity=msg->data.s[1]; if (intensity<0) intensity=0; else if (intensity>10) intensity=10; xdwOptStorm=intensity; changed=True; /* (to get out of idle mode) */ break; case 4: /* PutRaindrop */ changed=xdwPutRaindrop( msg->data.s[1]-xdwWinPathX, msg->data.s[2]-xdwWinPathY, msg->data.s[3] ); break; case 5: /* PutGhostRect */ case 6: /* PutGhostCircle */ removeId=(((int)msg->data.s[3])<<16)|(unsigned short)msg->data.s[4]; g=NULL; if (removeId) { for (g=xdwGhostList; g; g=g->next) { if (g->ghostId==removeId) break; } } if (g) { changed|=xdwCoverByGhost(g,-1); } else { g=(xdwGhost*)malloc(sizeof(xdwGhost)); g->next=xdwGhostList; xdwGhostList=g; } g->ghostId=(((int)msg->data.s[1])<<16)|(unsigned short)msg->data.s[2]; g->milliSecs=msg->data.s[5]; g->x=msg->data.s[6]-xdwWinPathX; g->y=msg->data.s[7]-xdwWinPathY; if (msg->data.s[0]==5) { g->isCircle=False; g->width=msg->data.s[8]; g->height=msg->data.s[9]; } else { g->isCircle=True; g->radius=msg->data.s[8]; } changed|=xdwCoverByGhost(g,1); break; } } return changed; } static Bool xdwUpdateGhosts(int milliSecsGone) { xdwGhost * * ps; xdwGhost * s; Bool changed; if (milliSecsGone<0) milliSecsGone=0; changed=False; for (ps=&xdwGhostList, s=*ps; s; ) { s->milliSecs-=milliSecsGone; if (s->milliSecs<=0) { changed|=xdwCoverByGhost(s,-1); *ps=s->next; free(s); } else { ps=&s->next; } s=*ps; } return changed; } /*============================================================================*/ /*============================== Event Handling ==============================*/ /*============================================================================*/ static Bool xdwHandleEvent(Display * display, XEvent * event) { Bool coveringChanged; coveringChanged=False; switch (event->type) { case ClientMessage: coveringChanged=xdwOnClientMessage(&event->xclient); break; case PropertyNotify: if (event->xproperty.atom==XDESKTOPWAVES_WINDOW_ID) { if (xdwOptVerb>=2) printf( "PropertyNotify: window=0x%lX atom=XDESKTOPWAVES_WINDOW_ID\n", event->xproperty.window ); xdwCheckInstance(display); } else if (event->xproperty.atom==XDESKTOPWAVES_WINDOW_INTERACTION) { if (xdwOptVerb>=2) printf( "PropertyNotify: window=0x%lX atom=XDESKTOPWAVES_WINDOW_INTERACTION\n", event->xproperty.window ); xdwOnInteractionPropertyChanged(event->xproperty.window); } break; case Expose: if (xdwOptVerb>=2) printf( "Expose: x=%d y=%d w=%d h=%d\n", event->xexpose.x, event->xexpose.y, event->xexpose.width, event->xexpose.height ); /* TODO: If in double buffering mode, the exposed area should be copied from the back buffer to the window, instead of touching the canvas. (=> less flicker and less overhead) */ xdwTouchCanvas( event->xexpose.x, event->xexpose.y, event->xexpose.x+event->xexpose.width, event->xexpose.y+event->xexpose.height ); break; case MotionNotify: if (xdwOptVerb>=2) printf( "MotionNotify: x=%d y=%d\n", event->xmotion.x, event->xmotion.y ); coveringChanged=xdwChangeMouse(event->xmotion.x,event->xmotion.y); break; case EnterNotify: if (xdwOptVerb>=2) printf( "EnterNotify: x=%d y=%d\n", event->xcrossing.x, event->xcrossing.y ); coveringChanged=xdwChangeMouse(event->xcrossing.x,event->xcrossing.y); break; case LeaveNotify: if (xdwOptVerb>=2) printf("LeaveNotify\n"); coveringChanged=xdwChangeMouse(-1,-1); break; case CreateNotify: if (xdwOptVerb>=2) printf( "CreateNotify parent=0x%lX window=0x%lX\n", event->xcreatewindow.parent, event->xcreatewindow.window ); xdwOnSubstructureChanged(event->xcreatewindow.parent); break; case DestroyNotify: if (xdwOptVerb>=2) printf( "DestroyNotify window=0x%lX\n", event->xdestroywindow.window ); if (event->xdestroywindow.window==xdwWinPath->window) { xdwTerminationRequested=True; break; } xdwOnSubstructureChanged(event->xdestroywindow.event); break; case MapNotify: if (xdwOptVerb>=2) printf( "MapNotify window=0x%lX\n", event->xmap.window ); xdwOnSubstructureChanged(event->xmap.event); break; case UnmapNotify: if (xdwOptVerb>=2) printf( "UmapNotify window=0x%lX\n", event->xunmap.window ); xdwOnSubstructureChanged(event->xunmap.event); break; case ConfigureNotify: if (xdwOptVerb>=2) printf( "ConfigureNotify window=0x%lX\n", event->xconfigure.window ); xdwOnSubstructureChanged(event->xconfigure.event); break; case CirculateNotify: if (xdwOptVerb>=2) printf( "CirculateNotify window=0x%lX\n", event->xcirculate.window ); xdwOnSubstructureChanged(event->xcirculate.event); break; case ReparentNotify: if (xdwOptVerb>=2) printf( "ReparentNotify event=0x%lX window=0x%lX parent=0x%lX\n", event->xreparent.event, event->xreparent.window, event->xreparent.parent ); xdwOnSubstructureChanged(event->xreparent.event); break; default: if (event->type==xdwShapeEventBase+ShapeNotify) { if (xdwOptVerb>=2) printf( "ShapeNotify window=0x%lX\n", ((XShapeEvent*)event)->window ); xdwOnShapeChanged(((XShapeEvent*)event)->window); } break; } return coveringChanged; } /*============================================================================*/ /*=================================== main ===================================*/ /*============================================================================*/ int main(int argc, char * argv[]) { Display * display; Window rootWin, ownWin, drawWin, aboveWin; Pixmap pm, pm2, bufferPM; GC gc, drawGC, bufferGC; XGCValues gcv; XSetWindowAttributes xswa; XWindowAttributes xwa; XWindowChanges xwc; XSizeHints xsh; Bool isNautilus, idleByWaves, idleByVisibility, wasIdle; Atom atoms[8]; XEvent event; int width, height, calls, rects, loopRate, tsRem, frRem, timeSlices; int skippedTimeSlices, totalCalls, totalRects, sleepMS, reportMS; int totalFrames; unsigned card, prevAbsTimeMS, reportAbsTimeMS, reportProcTimeMS, t; /* Initialize handling of X errors. */ xdwInitXErrorHandling(); /* Prepare options. */ xdwSetDefaultOptions(); xdwParseOptions(argc,argv); /* Have a display. */ if (!(display=XOpenDisplay(xdwOptDisplay))) { fprintf(stderr,"%s: failed to open display %s\n",xdwArg0, XDisplayName(xdwOptDisplay)); exit(1); } /* Set process priority. */ if (xdwOptNice) { if (nice(xdwOptNice)==-1) { fprintf(stderr,"%s: nice(%d) failed: %s\n", xdwArg0,xdwOptNice,strerror(errno)); exit(1); } } /* Look for CPU features. */ xdwDetectCPUFeatures(); /* Which root window and size should be used? */ if (xdwOptWindowCreation==XDW_USE_ROOT || xdwOptWindowCreation==XDW_BACKDROP) { rootWin=xdwDetectVirtualRoot(display,&aboveWin,&isNautilus); XGetWindowAttributes(display,rootWin,&xwa); width=xwa.width; height=xwa.height; /* Nautilus: Make the backdrop window a little smaller. Otherwise xpenguins 2.2 (and maybe others) would take it as the virtual root! */ if (isNautilus && xdwOptWindowCreation==XDW_BACKDROP) height--; } else { rootWin=DefaultRootWindow(display); aboveWin=None; XGetWindowAttributes(display,rootWin,&xwa); width=xwa.width; height=xwa.height; } /* Initialize several data structures. */ xdwInitCells(width,height); xdwInitPalette(display); xdwInitLighting(); xdwInitCanvas(width,height); /* Have a window for drawing and an own window for receiving client messages (maybe it's just one window). */ if (xdwOptWindowCreation==XDW_USE_ROOT) { drawWin=rootWin; memset(&xswa,0,sizeof(xswa)); xswa.override_redirect=True; ownWin=XCreateWindow( display,DefaultRootWindow(display),-100,-100,1,1,0,CopyFromParent, InputOnly,CopyFromParent,CWOverrideRedirect,&xswa ); XStoreName(display,ownWin,"xdesktopwaves"); } else { memset(&xswa,0,sizeof(xswa)); if (xdwOptWindowCreation==XDW_BACKDROP) xswa.override_redirect=True; memset(&xsh,0,sizeof(xsh)); if (xdwOptWindowCreation==XDW_WINDOW) { xsh.flags =PMinSize|PMaxSize; xsh.x =width/16; xsh.y =height/16; xsh.width =width*7/8; xsh.height =height*7/8; xsh.min_width =width/16; xsh.min_height=height/16; xsh.max_width =width; xsh.max_height=height; } else { xsh.flags =PPosition|PSize|USPosition|USSize|PMinSize|PMaxSize; xsh.x =0; xsh.y =0; xsh.width =width; xsh.height =height; xsh.min_width =width; xsh.min_height=height; xsh.max_width =width; xsh.max_height=height; } drawWin=XCreateWindow( display,rootWin,xsh.x,xsh.y,xsh.width,xsh.height,0,CopyFromParent, InputOutput,CopyFromParent,CWOverrideRedirect,&xswa ); XSetWMProperties(display,drawWin,NULL,NULL,0,0,&xsh,0,NULL); XStoreName(display,drawWin,"xdesktopwaves"); atoms[0]=XInternAtom(display,"WM_DELETE_WINDOW",False); XChangeProperty( display,drawWin,XInternAtom(display,"WM_PROTOCOLS",False),XA_ATOM,32, PropModeReplace,(const unsigned char*)atoms,1 ); if (xdwOptWindowCreation==XDW_WMBACKDROP) { atoms[0]=XInternAtom(display,"_NET_WM_STATE_BELOW",False); atoms[1]=XInternAtom(display,"_NET_WM_STATE_FULLSCREEN",False); atoms[2]=XInternAtom(display,"_NET_WM_STATE_STICKY",False); atoms[3]=XInternAtom(display,"_NET_WM_STATE_SKIP_TASKBAR",False); atoms[4]=XInternAtom(display,"_NET_WM_STATE_SKIP_PAGER",False); XChangeProperty( display,drawWin,XInternAtom(display,"_NET_WM_STATE",False),XA_ATOM, 32,PropModeReplace,(const unsigned char*)atoms,5 ); card=-1; XChangeProperty( display,drawWin,XInternAtom(display,"_NET_WM_DESKTOP",False), XA_CARDINAL,32,PropModeReplace,(const unsigned char*)&card,1 ); } XMapWindow(display,drawWin); if (xdwOptWindowCreation==XDW_BACKDROP) { XLowerWindow(display,drawWin); if (aboveWin!=None) { memset(&xwc,0,sizeof(xwc)); xwc.sibling=aboveWin; xwc.stack_mode=Above; XConfigureWindow(display,drawWin,CWSibling|CWStackMode,&xwc); } } ownWin=drawWin; } /* Have a GC for the window. */ drawGC=XCreateGC(display,drawWin,0,&gcv); /* Possibly have Pixmap and GC for double buffering. */ if (xdwOptDoubleBuffer) { XGetWindowAttributes(display,drawWin,&xwa); bufferPM=XCreatePixmap(display,drawWin,width,height,xwa.depth); bufferGC=XCreateGC(display,bufferPM,0,&gcv); } else { bufferPM=None; bufferGC=None; } /* Prepare for transparency. */ switch (xdwOptTransparency) { case XDW_OPAQUE: if (xdwOptWindowCreation!=XDW_USE_ROOT) { XSetWindowBackground(display,drawWin,xdwPalette[0]); } break; case XDW_STIPPLED: pm=XCreateBitmapFromData(display,drawWin,"\252\125",2,2); XSetStipple(display,drawGC,pm); XSetFillStyle(display,drawGC,FillStippled); if (xdwOptWindowCreation!=XDW_USE_ROOT) { XSetWindowBackgroundPixmap(display,drawWin,ParentRelative); XClearWindow(display,drawWin); } break; case XDW_SHAPED: /* Very slow in drawing with large number of operations => double buffering recommended. Even, if the mask is not horizontal striped (e.g. checkered) everything is extremely slow. */ pm=XCreateBitmapFromData(display,drawWin,"\0\377",2,2); pm2=XCreatePixmap(display,drawWin,width,height,1); gcv.foreground = 1; gcv.background = 0; gc=XCreateGC(display,pm2,(GCForeground|GCBackground),&gcv); XSetStipple(display,gc,pm); XSetFillStyle(display,gc,FillOpaqueStippled); XFillRectangle(display,pm2,gc,0,0,width,height); XFreeGC(display,gc); XShapeCombineMask(display,drawWin,ShapeBounding,0,0,pm2,ShapeSet); XSetWindowBackground(display,drawWin,xdwPalette[0]); break; case XDW_WMOPACITY: if (xdwOptTranspaParam<100 && xdwOptWindowCreation!=XDW_USE_ROOT) { card=((unsigned)xdwOptTranspaParam)*42949672U; XChangeProperty( display,drawWin,XInternAtom(display,"_NET_WM_WINDOW_OPACITY",False), XA_CARDINAL,32,PropModeReplace,(unsigned char *)&card,1 ); } break; } /* Prepare for signals. */ xdwInitSignalHandling(); /* Prepare for tracking other windows covering our window. */ xdwInitWindowTracking(display,drawWin); /* Prepare communications: Be the only instance on the display - other instances will terminate. And maybe that's the only job we have to do... */ xdwInitCommunications(display,ownWin); if (xdwOptEnd) goto THE_END; /* Calculate rate of processing events. */ if (xdwOptEventsPerFrame=xdwOptSimsPerFrame) { frRem-=xdwOptSimsPerFrame; if (frRem>=xdwOptSimsPerFrame) frRem=0; totalFrames++; /* Update canvas. */ if (!idleByWaves && !idleByVisibility) xdwUpdateCanvas(); /* Are there any changes to be drawn? */ if (xdwTouchedCvRow1=1 && !wasIdle && !xdwFreeze) { printf("Frames/s=0 CPU=0%% MBit/s=0.0 (IDLE MODE)\n"); } t=1000000/xdwOptFrameRate; if (t<200000) t=200000; usleep(t); skippedTimeSlices= (xdwOptFrameRate*xdwOptSimsPerFrame*(t/1000-1000/loopRate)+500) /1000 ; if (skippedTimeSlices<0) skippedTimeSlices=0; } else { /* Non-idle mode: sleep for the best known delay (synchronization). */ if (sleepMS>0) usleep(sleepMS*1000); skippedTimeSlices=0; } /* Update times. */ prevAbsTimeMS=xdwAbsTimeMS; xdwUpdateTimes(); /* Synchronize on desired frame rate and report statistics. */ if (!idleByWaves && !idleByVisibility) { if (wasIdle) { reportAbsTimeMS=xdwAbsTimeMS; reportProcTimeMS=xdwProcTimeMS; totalFrames=0; totalCalls=0; totalRects=0; reportMS=250; } else { sleepMS+=(1000/loopRate-(int)(xdwAbsTimeMS-prevAbsTimeMS))/2; if (sleepMS<-100) sleepMS=-100; else if (sleepMS>1000) sleepMS=1000; t=xdwAbsTimeMS-reportAbsTimeMS; if (t>reportMS && totalFrames>0) { if (xdwOptVerb>=1) { printf( "Frames/s=%d CPU=%d%% MBit/s=%.1f XFillRectangles's/Frm=%d Rects/Frm=%d\n", (int)(totalFrames*1000.0/t+0.5), (int)((xdwProcTimeMS-reportProcTimeMS)*100.0/t+0.5), totalRects*0.069/t, totalCalls/totalFrames, totalRects/totalFrames ); } reportAbsTimeMS=xdwAbsTimeMS; reportProcTimeMS=xdwProcTimeMS; totalFrames=0; totalCalls=0; totalRects=0; reportMS=1000; } } } } THE_END: /* Termination: possibly redraw root window. */ if (xdwOptWindowCreation==XDW_USE_ROOT) { XClearArea(display,rootWin,0,0,width,height,True); } XCloseDisplay(display); if (xdwOptVerb>=1) printf("Exiting proper.\n"); return 0; } xdesktopwaves-1.3/xdwapi/0040755000076400001440000000000010160742174014117 5ustar ohusersxdesktopwaves-1.3/xdwapi/Makefile0100644000076400001440000000074310160742174015560 0ustar ohusers# Makefile for the xdesktopwaves API and its demo program CC = gcc CFLAGS = -I/usr/X11R6/include -O2 LINK = gcc LFLAGS = -L/usr/X11R6/lib LIBS = -lm -lX11 all: xdwapidemo xdwapi.o: xdwapi.c xdwapi.h $(CC) $(CFLAGS) -c xdwapi.c -o xdwapi.o xdwapidemo.o: xdwapidemo.c xdwapi.h $(CC) $(CFLAGS) -c xdwapidemo.c -o xdwapidemo.o xdwapidemo: xdwapidemo.o xdwapi.o $(LINK) $(LFLAGS) xdwapidemo.o xdwapi.o $(LIBS) -o xdwapidemo clean: $(RM) xdwapidemo xdwapidemo.o xdwapi.o xdesktopwaves-1.3/xdwapi/xdwapi.h0100644000076400001440000001224510160742174015565 0ustar ohusers/***************************************************************************** xdwapi.h - header file of the xdesktopwaves API Copyright (C) 2004 Oliver Hamann (olha@users.sourceforge.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ #ifndef XDWAPI_H #define XDWAPI_H #ifdef __cplusplus extern "C" { #endif #ifndef _XLIB_H_ #include #endif typedef void * xdwApiContext; xdwApiContext xdwApiOpen(Display * display); /* Open the API for a given display. * Parameters: * display - The X display. * Return value: * A context for the API. It is required for the other functions. */ void xdwApiClose(xdwApiContext context); /* Close the API. * Parameters: * context - The API context. */ Bool xdwApiPing(xdwApiContext context); /* This sends a command which performs nothing, just for testing the * command sending. * Parameters: * context - The API context. * Return value: * True on success, False on error (xdesktopwaves probably not * running). */ Bool xdwApiClear(xdwApiContext context); /* Clear the water from all waves. * Parameters: * context - The API context. * Return value: * True on success, False on error (xdesktopwaves probably not * running). */ Bool xdwApiSetRain(xdwApiContext context, int intensity); /* Set intensity of the rain feature. * Parameters: * context - The API context. * intensity - Intensity of the rain. Valid range: 0 to 10 * Return value: * True on success, False on error (xdesktopwaves probably not * running). */ Bool xdwApiSetStorm(xdwApiContext context, int intensity); /* Set intensity of the storm feature. * Parameters: * context - The API context. * intensity - Intensity of the storm. Valid range: 0 to 10 * Return value: * True on success, False on error (xdesktopwaves probably not * running). */ Bool xdwApiPutRaindrop(xdwApiContext context, int x, int y, int volume); /* Put one raindrop. * Parameters: * context - The API context. * x,y - X- and Y-coordinates of the raindrop, in pixel units * relative to the root window origin. * volume - Volume of the raindrop. Valid range: 0 to 100 * Return value: * True on success, False on error (xdesktopwaves probably not * running). */ int xdwApiPutGhostRect(xdwApiContext context, int milliSecs, int removeId, int x, int y, int width, int height); int xdwApiPutGhostCircle(xdwApiContext context, int milliSecs, int removeId, int x, int y, int radius); /* Put a temporary custom rectangular or circular "ghost" onto the * water. It generates waves like a window (ship or shore), but it is * not drawn. The ghost is automatically removed after a given lifetime. * Additionally, putting a ghost can remove another ghost. This way a * ghost can be animated by substituting it again and again. * Parameters: * context - The API context. * milliSecs - Lifetime of the ghost in milliseconds. The ghost is * removed automatically after this time has passed. * Valid range: 0 to 32767 * removeId - Identification of another ghost to be removed, or 0 for * not removing any ghost. * x,y - Coordinates in pixel units relative to the root window * origin. It is the upper-left corner of the rectangle * respectively the center of the circle. * width - Width of the rectangle in pixel units. * height - Height of the rectangle in pixel units. * radius - Radius of the circle in pixel units. * Return value: * The identification for the new ghost, or 0 on error. The * identification comes from a pseudo random number generator. Most * likely it is unique, but there is no guarantee. */ void xdwApiSetWavesByWindow(xdwApiContext context, Window window, Bool wavesByWindow); /* Override the waves-by-windows option for a given window. * Parameters: * context - The API context. * window - The window. * wavesByWindow - True if waves are to be generated by the window, * False if not. */ void xdwApiDefaultWavesByWindow(xdwApiContext context, Window window); /* Remove the overriding of the waves-by-windows option for a given * window. * Parameters: * context - The API context. * window - The window. */ #ifdef __cplusplus } #endif #endif xdesktopwaves-1.3/xdwapi/xdwapi.c0100644000076400001440000001321010160742174015551 0ustar ohusers/***************************************************************************** xdwapi.c - implementation of the xdesktopwaves API Copyright (C) 2004 Oliver Hamann (olha@users.sourceforge.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ #include #include #include #include #include #include #include #include "xdwapi.h" typedef struct { Display * display; Window root; Atom XDESKTOPWAVES_WINDOW_ID; Atom XDESKTOPWAVES_COMMAND_MESSAGE; Atom XDESKTOPWAVES_WINDOW_INTERACTION; } xdwApiContextImp; xdwApiContext xdwApiOpen(Display * display) { xdwApiContextImp * imp; imp=(xdwApiContextImp*)malloc(sizeof(xdwApiContextImp)); imp->display=display; imp->root=DefaultRootWindow(display); imp->XDESKTOPWAVES_WINDOW_ID=XInternAtom( display,"XDESKTOPWAVES_WINDOW_ID",False ); imp->XDESKTOPWAVES_COMMAND_MESSAGE=XInternAtom( display,"XDESKTOPWAVES_COMMAND_MESSAGE",False ); imp->XDESKTOPWAVES_WINDOW_INTERACTION=XInternAtom( display,"XDESKTOPWAVES_WINDOW_INTERACTION",False ); return (xdwApiContext)imp; } void xdwApiClose(xdwApiContext context) { free((xdwApiContextImp*)context); } volatile Bool xdwApiGotXError; static int xdwApiTmpXErrHandler(Display * display, XErrorEvent * errorEvent) { xdwApiGotXError=True; return 0; } static Bool xdwApiSendCommand(xdwApiContext context, int argCount, ...) { xdwApiContextImp * imp; int (*originalXErrorHandler)(Display *, XErrorEvent *); Atom type; Status st; Window win; XEvent event; va_list ap; unsigned char * data; char * name; unsigned long len, rem; int i, frmt, ret; /* Get window id of xdesktopwaves. */ imp=(xdwApiContextImp*)context; data=NULL; ret=XGetWindowProperty( imp->display,imp->root,imp->XDESKTOPWAVES_WINDOW_ID,0,1,False, XA_WINDOW,&type,&frmt,&len,&rem,&data ); if (ret!=Success || type!=XA_WINDOW || frmt!=32 || len!=1 || rem!=0) { if (data) XFree(data); return False; } win=*(Window*)data; if (data) XFree(data); if (win==None) return False; /* Prepare client message to be sent. */ memset(&event,0,sizeof(event)); event.xclient.type=ClientMessage; event.xclient.display=imp->display; event.xclient.window=win; event.xclient.message_type=imp->XDESKTOPWAVES_COMMAND_MESSAGE; event.xclient.format=16; va_start(ap,argCount); for (i=0; idisplay,False); xdwApiGotXError=False; originalXErrorHandler=XSetErrorHandler(xdwApiTmpXErrHandler); name=NULL; st=XFetchName(imp->display,win,&name); if (st && (!name || strcmp(name,"xdesktopwaves")!=0)) st=0; if (name) XFree(name); if (st) st=XSendEvent(imp->display,win,False,0,&event); XSync(imp->display,False); XSetErrorHandler(originalXErrorHandler); if (xdwApiGotXError) st=0; return st ? True : False; } Bool xdwApiPing(xdwApiContext context) { return xdwApiSendCommand(context,1,0); } Bool xdwApiClear(xdwApiContext context) { return xdwApiSendCommand(context,1,1); } Bool xdwApiSetRain(xdwApiContext context, int intensity) { return xdwApiSendCommand(context,2,2,intensity); } Bool xdwApiSetStorm(xdwApiContext context, int intensity) { return xdwApiSendCommand(context,2,3,intensity); } Bool xdwApiPutRaindrop(xdwApiContext context, int x, int y, int volume) { return xdwApiSendCommand(context,4,4,x,y,volume); } static int xdwApiGenGhostId() { static int seed=0; int id; seed=seed*1375117+3370481; id=(getpid()*2873451)^(time(NULL)*11876973)^seed; if (!id) id=1; return id; } int xdwApiPutGhostRect(xdwApiContext context, int milliSecs, int removeId, int x, int y, int width, int height) { int ghostId; Bool success; ghostId=xdwApiGenGhostId(); success=xdwApiSendCommand( context, 10, 5, ghostId>>16, ghostId&0xffff, removeId>>16, removeId&0xffff, milliSecs, x, y, width, height ); return success ? ghostId : 0; } int xdwApiPutGhostCircle(xdwApiContext context, int milliSecs, int removeId, int x, int y, int radius) { int ghostId; Bool success; ghostId=xdwApiGenGhostId(); success=xdwApiSendCommand( context, 9, 6, ghostId>>16, ghostId&0xffff, removeId>>16, removeId&0xffff, milliSecs, x, y, radius ); return success ? ghostId : 0; } void xdwApiSetWavesByWindow(xdwApiContext context, Window window, Bool wavesByWindow) { xdwApiContextImp * imp; unsigned card32; imp=(xdwApiContextImp*)context; card32=wavesByWindow ? 1 : 0; XChangeProperty( imp->display, window, imp->XDESKTOPWAVES_WINDOW_INTERACTION, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&card32, 1 ); } void xdwApiDefaultWavesByWindow(xdwApiContext context, Window window) { xdwApiContextImp * imp; imp=(xdwApiContextImp*)context; XDeleteProperty( imp->display, window, imp->XDESKTOPWAVES_WINDOW_INTERACTION ); } xdesktopwaves-1.3/xdwapi/README.xdwapi0100644000076400001440000000124310160742174016267 0ustar ohusersWhat is xdwapi? =============== Beginning with version 1.3, xdesktopwaves has an application programming interface for creating wave effects. If you want to make use of it, just compile and link "xdwapi.c" with your program, include "xdwapi.h" and call the API functions. API Demo ======== "xdwapidemo.c" is an example program of creating wave effects. How to get it running: 1.) Compile the demo by typing "make". 2.) Start xdesktopwaves as usual (best with -ef 2 or 3). 3.) Keep the desktop mostly clean from other windows. 4.) Start the demo by typing "./xdwapidemo". API Documentation ================= Please refer to the comments in the header file "xdwapi.h". xdesktopwaves-1.3/xdwapi/xdwapidemo.c0100644000076400001440000001035210160742174016422 0ustar ohusers/***************************************************************************** xdwapidemo.h - demo program on the xdesktopwaves API Copyright (C) 2004 Oliver Hamann (olha@users.sourceforge.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *****************************************************************************/ #include #include #include #include #include #include "xdwapi.h" int main(int argc, char * argv[]) { Display * display; xdwApiContext context; int i, width, height, ghostId1, ghostId2, ghostId3, d; /* This is an example of using the xdesktopwaves API functions. Even throw an eye on the comments in the header file "xdwapi.h". */ printf("XOpenDisplay...\n"); display=XOpenDisplay(NULL); if (!display) { fprintf(stderr,"%s: cannot open display %s\n",argv[0],XDisplayName(NULL)); exit(1); } width=WidthOfScreen(DefaultScreenOfDisplay(display)); height=HeightOfScreen(DefaultScreenOfDisplay(display)); printf("xdwApiOpen...\n"); context=xdwApiOpen(display); printf("xdwApiPing...\n"); if (xdwApiPing(context)==False) { printf("=> warning: xdesktopwaves probably not running\n"); } printf("xdwApiSetRain...\n"); for (i=0; i<=10; i++) { xdwApiSetRain(context,i); usleep(700000); } xdwApiSetRain(context,0); printf("xdwApiSetStorm...\n"); for (i=0; i<=10; i++) { xdwApiSetStorm(context,i); usleep(700000); } xdwApiSetStorm(context,0); printf("xdwApiClear...\n"); xdwApiClear(context); usleep(1000000); printf("xdwApiPutRaindrop...\n"); xdwApiPutRaindrop(context,width/4,height/4,50); usleep(500000); xdwApiPutRaindrop(context,width*3/4,height/4,50); usleep(500000); xdwApiPutRaindrop(context,width/4,height*3/4,50); usleep(500000); xdwApiPutRaindrop(context,width*3/4,height*3/4,50); usleep(1000000); xdwApiPutRaindrop(context,width/2,height/2,100); usleep(1000000); printf("xdwApiPutGhostCircle...\n"); for (i=0; i<320; i++) { xdwApiPutGhostCircle( context, 300, 0, width/2+sin(i*0.04)*width/3, height/2-cos(i*0.04)*height/3, 10 ); usleep(20000); } printf("xdwApiPutGhostCircle (with substitution)...\n"); ghostId1=0; for (i=0; i<320; i++) { ghostId1=xdwApiPutGhostCircle( context, 300, ghostId1, width/2-sin(i*0.04)*width/3, height/2-cos(i*0.04)*height/3, 10 ); usleep(20000); } printf("xdwApiPutGhostCircle (with substitution, three ghosts)...\n"); ghostId1=0; ghostId2=0; ghostId3=0; for (i=0; i<480; i++) { ghostId1=xdwApiPutGhostCircle( context, 300, ghostId1, width/2-sin(i*0.04)*width/3, height/2-cos(i*0.04)*height/3, 8+i*i/2000 ); ghostId2=xdwApiPutGhostCircle( context, 300, ghostId2, width/2-sin(i*0.065)*(width/3+sin(i*0.1)*width/7), height/2-cos(i*0.065)*(height/3+sin(i*0.1)*height/7), 8+i*i/2000 ); ghostId3=xdwApiPutGhostCircle( context, 300, ghostId3, width/2-sin(i*0.015)*sin(i*0.02)*sin(i*0.025)*width/2, height/2-cos(i*0.015)*cos(i*0.02)*cos(i*0.025)*height/2, 8+i*i/2000 ); usleep(20000); } printf("xdwApiPutGhostRect...\n"); for (i=0; i<200; i++) { xdwApiPutGhostRect( context, 300, 0, i*width/200, height/4, 40, height/2 ); usleep(20000); } printf("xdwApiPutGhostRect (with substitution)...\n"); ghostId1=0; for (i=0; i<480; i++) { d=sin(i*(0.1+i/200))*2000/(i+20); ghostId1=xdwApiPutGhostRect( context, 300, ghostId1, width/2-60-d, height/2-60-d, 120+d*2, 120+d*2 ); usleep(20000); } printf("xdwApiClose...\n"); xdwApiClose(context); printf("XCloseDisplay...\n"); XCloseDisplay(display); return 0; } xdesktopwaves-1.3/COPYING0100644000076400001440000004313110160742174013655 0ustar ohusers GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. xdesktopwaves-1.3/xdesktopwaves.10100644000076400001440000003071710160742174015621 0ustar ohusers.TH xdesktopwaves 1 "18 December 2004" "xdesktopwaves 1.3" .SH NAME xdesktopwaves \- simulation of water waves on the X Windows desktop .SH SYNOPSIS \fBxdesktopwaves\fR [\fIoption\fR]... .SH DESCRIPTION xdesktopwaves is a cellular automata setting the background of your X Windows desktop under water. Windows and mouse are like ships on the sea. Each movement of these ends up in moving water waves. You can even have rain and/or storm stirring up the water (\fB\-rain\fR \fI0\-10\fR, \fB\-storm\fR \fI0\-10\fR). .PP In shaped mode, which is enabled by default, xdesktopwaves usually works good together with other desktop background programs like \fBxfishtank\fR, \fBxpenguins\fR, \fBxsnow\fR and \fBxearth\fR. They are all under water. .PP xdesktopwaves has many options. The most important ones are \fB\-quality\fR \fI0\-9\fR and \fB\-colortheme\fR \fI0\-9\fR. The first one is for adjusting the balance between display quality and system load. And the other option is for selecting a set of colors for visualization. Choose a color theme suitable for your background picture. There are even options for fine-tuning. .PP \fBWindow Managers\fR .PP If you are using the \fBKDE\fR window manager, please enable "Allow programs in desktop window" in the KDE desktop configuration (right-click on the desktop and choose "Configure Desktop"). Otherwise xdesktopwaves may not be visible. If you are using \fBEnlightenment 0.16\fR with "Multiple Desktops" instead of "Virtual Desktops", xdesktopwaves appears always on the first desktop. A solution is \fB\-wmbackdrop\fR, but read the comments on that option. With most other window managers xdesktopwaves should work without difficulties. If not, try \fB\-root\fR, \fB\-wmbackdrop\fR or \fB\-window\fR, and/or \fB\-opaque\fR. .PP If supported by the window manager, you should decide to enable opaque moving and resizing of windows ("display content in moving windows" or something like that), instead of displaying just a frame. This may result in very dynamic wave effects - try to pile up a big wave by moving a window slowly. But: unfortunately some window managers seem to be very CPU-intensive while moving a window opaque. In that case xdesktopwaves does not perform very smooth. .PP \fBStarting and stopping\fR .PP For a first try, open a shell and type \fBxdesktopwaves\fR followed by desired options. Example: .RS .PP \fBxdesktopwaves \-quality 4 \-colortheme 3\fR .RE .PP Just press CTRL\-C for stopping. .PP Now, if you want to create menu entries in your desktop environment, window manager or wherever: For starting, create an entry containing a command like the example above. And for stopping, create an entry containing this command: .RS .PP \fBxdesktopwaves \-end\fR .RE .PP Hint: Whenever xdesktopwaves is starting, it automatically tells other instances of xdesktopwaves to terminate. So there cannot be more than one instance. .PP \fBxdesktopwaves every day?\fR .PP Depending on the quality settings, xdesktopwaves can be very CPU-intensive. To get along with this, the program goes into an \fBidle mode\fR if there are no waves on the water or if the output window is obscured. The cellular automata stops computing in that mode. Additionally, you can give a lower priority to the xdesktopwaves process (see \fB\-nice\fR). .PP If you want to have xdesktopwaves automatically started when starting X Windows, insert the start command in the file \fB$HOME/.xinitrc\fR (see \fBstartx\fR(1)). But don't forget to append \fB&\fR to the command. This way, xdesktopwaves is started before the window manager (may or may not work, depending on the type of window manager). .SH GENERAL OPTIONS .TP \fB\-h\fR or \fB\-help\fR Print a short help and exit. .TP \fB\-V\fR or \fB\-version\fR Print version and exit. .TP \fB\-v\fR or \fB\-verbose\fR Print some information about what's going on. .TP \fB\-vv\fR or \fB\-veryverbose\fR Print much information (for debugging). .TP \fB\-d\fR \fIname\fR or \fB\-display\fR \fIname\fR Connect to the display named \fIname\fR. .TP \fB\-e\fR or \fB\-end\fR Exit after terminating a possibly already existing instance of xdesktopwaves. .SH WINDOW CREATION OPTIONS .TP \fB\-r\fR or \fB\-root\fR Do not create any window, draw the waves to the (virtual) root window. This option implies \fB\-stippled\fR if not \fB\-opaque\fR. .TP \fB\-b\fR or \fB\-backdrop\fR (default) Create an override-redirect backdrop window on the (virtual) root window. .TP \fB\-wmb\fR or \fB\-wmbackdrop\fR Create a backdrop window using the extended window manager hints. This is not supported by every window manager. And if it is, there's still the problem that it may not be possible to activate icons or menus on the desktop background (possibly just at every second scan-line in shaped mode). .TP \fB\-w\fR or \fB\-window\fR Create an ordinary normal window. For some window managers you'll even have to give \fB\-opaque\fR. .SH TRANSPARENCY OPTIONS .TP \fB\-o\fR or \fB\-opaque\fR Have no transparency at all. .TP \fB\-t\fR or \fB\-stippled\fR Have faked transparency. This lets the desktop background picture shine through. Other desktop background programs and desktop icons may not be visible. The window of xdesktopwaves inherits the background from the root window, and the waves are drawn in stippled mode. This option implies \fB\-nodoublebuffer\fR. .TP \fB\-s\fR or \fB\-shaped\fR (default) Have better transparency. Everything behind xdesktopwaves shines through. The window of xdesktopwaves is shaped by every second scan-line, using the XShape extension. This option is ignored if \fB\-root\fR, otherwise this option implies \fB\-doublebuffer\fR. .TP \fB\-wmo\fR \fIpercent\fR or \fB\-wmopacity\fR \fIpercent\fR Have best transparency. \fBThis is still highly experimental!\fR It sets the window property _NET_WM_WINDOW_OPACITY, which is a hint for the window manager respectively composite manager to render the window with alpha blending. This option is ignored if \fB\-root\fR. .SH PERFORMANCE OPTIONS .TP \fB\-q\fR \fInumber\fR or \fB\-quality\fR \fInumber\fR (default: \fB5\fR) Set overall quality of the waves. \fInumber\fR can be \fB0\fR to \fB9\fR. The higher the quality, the higher the CPU/network load. This option is a comfortable alternative for \fB\-framerate\fR, \fB\-simsperframe\fR, \fB\-eventsperframe\fR, \fB\-resdivision\fR, \fB\-cellsize\fR and \fB\-maxcolors\fR. .TP \fB\-fr\fR \fIrate\fR or \fB\-framerate\fR \fIrate\fR Set maximum frame rate in hertz. This option is overridden by \fB\-quality\fR. .TP \fB\-sf\fR \fIcount\fR or \fB\-simsperframe\fR \fIcount\fR Set number of simulation steps per frame. Hereby you can adapt the speed of the waves. This option is overridden by \fB\-quality\fR. .TP \fB\-ef\fR \fIcount\fR or \fB\-eventsperframe\fR \fIcount\fR Set number of event processings per frame. This can improve the trails of fast moving objects (mouse and windows), but it can even incur a sensible higher CPU load, because of a worse cache utilization. Maximum is the number of simulation steps per frame. This option is overridden by \fB\-quality\fR. .TP \fB\-rd\fR \fIrdx\fR \fIrdy\fR or \fB\-resdivision\fR \fIrdx\fR \fIrdy\fR Set overall division of resolution in x and y direction. These values have dramatic influence on the CPU usage on both sides, the client and the server. This option is overridden by \fB\-quality\fR. .TP \fB\-cs\fR \fIcw\fR \fIch\fR or \fB\-cellsize\fR \fIcw\fR \fIch\fR Set width and height of the cells of water. These values have dramatic influence on the CPU usage on the client side. The water surface is made of rectangular cells. This is a kind of an image, where each pixel is a cell. For each frame, that image is scaled up to the screen size in two steps. In the first step it is scaled by (\fIcw\fR, \fIch\fR) with bi-linear interpolation, and in the second step it is scaled by (\fIrdx\fR, \fIrdy\fR) without interpolation. This option is overridden by \fB\-quality\fR. .TP \fB\-mc\fR \fIcount\fR or \fB\-maxcolors\fR \fIcount\fR Set maximum number of colors for drawing the waves. The higher the color count, the more rectangles may be sent to the X server. \fIcount\fR can be \fB2\fR to \fB128\fR. This option is overridden by \fB\-quality\fR. .TP \fB\-db\fR or \fB\-doublebuffer\fR (default) Draw with double buffering. This option is ignored if \fB\-stippled\fR. .TP \fB\-ndb\fR or \fB\-nodoublebuffer\fR Draw without double buffering. This option is ignored if \fB\-shaped\fR. .TP \fB\-n\fR \fIincrement\fR or \fB\-nice\fR \fIincrement\fR (default: \fB0\fR) Increment nice value of the xdesktopwaves process. The higher the nice value, the lower the process priority. A typical value for \fIincrement\fR is \fB10\fR. .TP \fB\-i\fR or \fB\-idle\fR (default) Go idle if there are no waves or if the output window is obscured. This can spare CPU cycles. .TP \fB\-ni\fR or \fB\-noidle\fR Never go idle. .TP \fB\-mo\fR \fInumber\fR or \fB\-maxoptimization\fR \fInumber\fR (default: \fB2\fR) Set maximum optimization by CPU instruction set. If compiled with GCC for x86 (32 or 64-bit), \fB1\fR means MMX and \fB2\fR means SSE2. \fB0\fR means to have no special optimization. .SH COLOR OPTIONS .TP \fB\-c\fR \fInumber\fR or \fB\-colortheme\fR \fInumber\fR (default: \fB0\fR) Select a color theme. \fInumber\fR can be \fB0\fR to \fB9\fR. Just try them through. This option is a comfortable alternative for \fB\-watercolor\fR, \fB\-skycolor\fR and \fB\-lightcolor\fR. .TP \fB\-wc\fR \fIcolor\fR or \fB\-watercolor\fR \fIcolor\fR Set color of water. This option is overridden by \fB\-colortheme\fR. .TP \fB\-sc\fR \fIcolor\fR or \fB\-skycolor\fR \fIcolor\fR Set color of sky reflections. This option is overridden by \fB\-colortheme\fR. .TP \fB\-lc\fR \fIcolor\fR or \fB\-lightcolor\fR \fIcolor\fR Set color of light reflections. This option is overridden by \fB\-colortheme\fR. .SH PHYSICS OPTIONS .TP \fB\-wm\fR or \fB\-wavesbymouse\fR (default) Produce waves by mouse pointer movements. .TP \fB\-nwm\fR or \fB\-nowavesbymouse\fR Ignore the mouse. .TP \fB\-ww\fR or \fB\-wavesbywindows\fR (default) Produce waves by client windows. .TP \fB\-nww\fR or \fB\-nowavesbywindows\fR Ignore client windows. .TP \fB\-rn\fR \fIintensity\fR or \fB\-rain\fR \fIintensity\fR (default: \fB0\fR) Simulate raindrops falling on the water. \fIintensity\fR can be \fB0\fR (no rain) to \fB10\fR (cloudburst). .TP \fB\-st\fR \fIintensity\fR or \fB\-storm\fR \fIintensity\fR (default: \fB0\fR) Simulate a storm blowing on the water. \fIintensity\fR can be \fB0\fR (no wind) to \fB10\fR (strong storm). .TP \fB\-vs\fR \fIvalue\fR or \fB\-viscosity\fR \fIvalue\fR (default: \fB3\fR) Set viscosity of the fluid. \fIvalue\fR can be \fB1\fR to \fB5\fR. The higher the viscosity, the shorter the lifetime of waves. .TP \fB\-si\fR \fIintensity\fR or \fB\-skyintensity\fR \fIintensity\fR (default: \fB5\fR) Set intensity of sky reflections. \fIintensity\fR can be \fB1\fR to \fB10\fR. .TP \fB\-li\fR \fIintensity\fR or \fB\-lightintensity\fR \fIintensity\fR (default: \fB5\fR) Set intensity of light reflections. \fIintensity\fR can be \fB1\fR to \fB10\fR. .TP \fB\-lal\fR \fIdegrees\fR or \fB\-lightaltitude\fR \fIdegrees\fR (default: \fB30\fR) Set altitude of the source of light. \fIdegrees\fR can be \fB0\fR to \fB90\fR. .TP \fB\-laz\fR \fIdegrees\fR or \fB\-lightazimuth\fR \fIdegrees\fR (default: \fB\-35\fR) Set azimuth of the source of light. \fIdegrees\fR can be \fB\-360\fR to \fB360\fR. .SH EXAMPLES .TP \fBxdesktopwaves \-quality 6 \-colortheme 1 \-verbose\fR Increased quality. Blue color theme. Print information about settings and performance. .TP \fBxdesktopwaves \-q 6 \-c 1 \-v\fR Short cut of the previous example. .TP \fBxdesktopwaves \-c 2 \-rn 8 \-r \-o\fR Dark night with flashy lights. It's raining. Draw to the root window without any transparency. .SH SEE ALSO xfishtank, xpenguins(1), xearth(1), xsnow(1), xlife(1x), xsetroot(1), startx(1) .SH HOMEPAGE http://xdesktopwaves.sourceforge.net/ .SH AUTHOR Oliver Hamann (olha@users.sourceforge.net) .SH COPYRIGHT xdesktopwaves is copyrighted (C) 2004 by Oliver Hamann .PP This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. .PP This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. .PP You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA xdesktopwaves-1.3/xdesktopwaves.xpm0100644000076400001440000000745010160742174016263 0ustar ohusers/* XPM */ static char * xdesktopwaves_xpm[] = { "48 48 88 1", " c #020202", "1 c #04273F", "2 c #081926", "3 c #093049", "4 c #0C364F", "5 c #0F0F10", "6 c #103B56", "7 c #154663", "8 c #1C506D", "9 c #211E23", "A c #225A79", "B c #263040", "C c #286484", "D c #2B4551", "E c #2C5B73", "F c #2D6C8C", "G c #2E2024", "H c #303E54", "I c #31516A", "J c #347495", "K c #35657A", "L c #38465A", "M c #397D9F", "N c #3B5874", "O c #3F8DB2", "P c #4086A9", "Q c #447E99", "R c #45758B", "S c #486A85", "T c #498FAF", "U c #4B96BA", "V c #505969", "W c #52AAD3", "X c #52B6E4", "Y c #539AB9", "Z c #55A0C1", "0 c #5691AA", "a c #577C98", "b c #5F3E40", "c c #60ABC9", "d c #61B7DF", "e c #678FA3", "f c #68B4C9", "g c #68C2EA", "h c #6A9EB1", "i c #6ECAF5", "j c #71C0D6", "k c #71D1F9", "l c #73ABC3", "m c #747484", "n c #75B8CF", "o c #78C6E0", "p c #7ED4EF", "q c #7F5253", "r c #82B8CC", "s c #82E0FD", "t c #84BEFC", "u c #84C6DA", "v c #88D5F0", "w c #8EA6B8", "x c #8EE4FA", "y c #968EA4", "z c #97CCE5", "! c #99F2FE", "# c #9BD8E6", "$ c #9D717A", "% c #9DE5F7", "& c #A1BBC7", "' c #A6F9FE", "( c #ADD0F4", ") c #ADE4F1", "* c #AEEEF6", "+ c #B5FCFE", ", c #BA7778", "- c #BEB6C6", ". c #BEBAD8", "/ c #C2A2B2", ": c #C5FDFD", "; c #D8FCFB", "< c #DED2D6", "= c #E2919B", "> c #E5F3F5", "? c #EBA1AC", "@ c #F4F4F2", "[ c #F5B4C1", "] c #F5BACB", "^ c #FDA5AA", "_ c #FEAEB3", "Qh(#djdcQaECFFMPPJMJJPOPUZgppWMOUZTMFA8FZp*#rPAJ", "+'x%urh00MYcogWOF888777778ACMTYUTPMUOPTMFEF0#*#h", "+'zhelroiidZQJF77478AEFFJJMPQTjukZMMPTZnfZQCFRl)", "zhwz%xspnQKIJMMTZWOJMMJCAC88FOPMMYOJCCPclZnl0MRQ", "j*+!x%lh00QYfpkkWOJFAAFFJJMPTOPMA77CJTMFM0cjujeQ", "+x!*zeerodkkgZTQRK8A8ACCJJMFPpsujTJA66FZ0JJThz+z", "'+)u&#vkigWTQalUPFAA8776667ECCQcjcZ0TTA48YhTTPh)", "*Tj+!ddkvnhcYTJE776677AACA8843637AMTMF0cK48hhljR", "Kz:oWg%wernTF468FFJMJT0QPO0ywZMF7137JTMC0cK1KhY!", ":'WW**rlzdC37JPlnhRKFECAa/[^mdscPMA417RTPTYe86ee", "sgk:uj)!T38Zcn&rPCFYjx!!]^^?DOFQP0UPJ6480hnfea2e", "gx:h0:sC6YvnuzJCYvx!ocYU^^^,F'xZJFOCQh844K0ooel2", "!:;):k8Cs%eufCa-[?y8JOO0^^[qAMZ!+jKMJAZR31E0c*a&", ":::+i7J'#Quc7L=??==/ZOMy^^_BspTFZ'+RK0RYQ43Ieh#h", "*:+k8J'%E*c4F6 ,[^==,lk[^^^ 3fcPJJf+CE0uh033Erlf", "%+sCA!;#+kCA7T5 q_??==.?^_, BUMRP8Q'8KZ'ae11R&T", "+!U6k+:;*778c%8 G??===?^_q KYP608AF2ehurS31ww", "'k8W!+!:U34F+QhL2 ,^==^__9 fYQCh4OY6wTRz346>", "!ZCs+*+!833x:f&HLB b==?^^,X3 VuejjKJ'7he6)S31e", "kOW!+:'k63J'o%uBNNL52q=?^^_[f5 phzhlAiUI>)@w137", "gkg+'++d74W+%!%NRILNcy^?^^_^_m cw>u>7si7<;><463", "gkg:x!:d74c+::+0SSHhO=^^^^^^^_, A0;:@841", "Xig;'::dZWW:+!:dSVNQf_?_=b?_^^_?Sj+:nCig8z@@