--- icewm-1.0.6-pristine/Makefile.in Sun Jan 14 22:49:38 2001 +++ icewm-1.0.6/Makefile.in Mon Jan 15 19:53:35 2001 @@ -11,7 +11,7 @@ SPEC = icewm.spec LSM = icewm.lsm -GUIEVENTSFILES = src/icesound +GUIEVENTSFILES = src/icesound src/icecursor GNOMEFILES = lib/IceWM.desktop WMPROPDIR = $(shell gnome-config --datadir)/gnome/wm-properties/ @@ -30,6 +30,7 @@ guievents: cd src ; $(MAKE) icesound + cd src ; $(MAKE) icecursor gnome: --- icewm-1.0.6-pristine/README.icefx Mon Jan 15 20:00:41 2001 +++ icewm-1.0.6/README.icefx Mon Jan 15 20:25:54 2001 @@ -0,0 +1,30 @@ +IceFX +===== + +Get icewm-1.0.6.src.tar.bz2 +and http://triq.net/icewm/icewm-1.0.6-fx.patch + +Unpack IceWM + tar xvIf icewm-1.0.6.src.tar.bz2 +Apply Patch + cd icewm-1.0.6 + patch -p1 <../icewm-1.0.6-fx.patch + +(If you don't patch a pristine source or this is the developer patch + regenerate configure scripts and headers with autoconf and autoheader ) + +Configure. And enable GUI Events. ESounD will be enabled if detected. + ./configure --enable-guievents + +Build icewm + make +or just the eytra binaries + make guievents + +copy some sound and cursors to ~/.icewm/sounds/ and ~/.icewm/cursors/ + +enjoy ./src/icesound and ./src/icecursor + + +Author : Christian W. Zuckschwerdt +Latest patch and Sound/Cursor-Themes : http://triq.net/icewm/ --- icewm-1.0.6-pristine/configure.in Sun Jan 14 22:49:39 2001 +++ icewm-1.0.6/configure.in Mon Jan 15 19:57:38 2001 @@ -101,12 +101,21 @@ fi ]) AC_ARG_ENABLE(guievents, - [ --enable-guievents Enable GUI events for icesound (experimental)], + [ --enable-guievents Enable GUI events for icesound and icecursor], [ if test "$enable_guievents" != "no"; then AC_DEFINE(CONFIG_GUIEVENTS, 1, [Define to enable GUI events support. ]) TARGETS=$TARGETS' guievents' fi ]) +AC_ARG_ENABLE(esd, + [ --disable-esd Don't compile ESounD support(NEW)]) + if test "$enable_esd" != "no"; then + AC_CHECK_LIB(esd, esd_open_sound, + [ LIBS="$LIBS -lesd" + AC_DEFINE(ESD, 1, [Define to compile ESD support]) ], + [ AC_MSG_WARN([Unable to locate ESD]) ]) + fi + dnl All further test will use X libraries/headers no_x_CXXFLAGS=$CXXFLAGS no_x_LIBS=$LIBS @@ -131,6 +140,15 @@ [ LIBS="$LIBS -lXext" AC_DEFINE(SHAPE, 1, [Define to enable X shape extension]) ], [ AC_MSG_WARN([Unable to use X shape extension]) ]) + fi + +AC_ARG_ENABLE(xmu, + [ --disable-xmu Don't use X misc util extension(NEW)]) + if test "$enable_xmu" != "no"; then + AC_CHECK_LIB(Xmu, XmuCursorNameToIndex, + [ LIBS="$LIBS -lXmu" + AC_DEFINE(XMU, 1, [Define to enable X misc util extension]) ], + [ AC_MSG_WARN([Unable to use X misc util extension]) ]) fi AC_ARG_ENABLE(prefs, --- icewm-1.0.6-pristine/src/Makefile Sun Jan 14 22:49:39 2001 +++ icewm-1.0.6/src/Makefile Mon Jan 15 19:59:32 2001 @@ -44,7 +44,9 @@ ICEWMBGOBJS = icewmbg.o -ICESOUNDOBJS = icesound.o misc.o +ICESOUNDOBJS = icesound.o misc.o + +ICECURSOROBJS = icecursor.o misc.o ICECLOCKOBJS = $(COREOBJS) \ iceclock.o aclock.o @@ -109,7 +111,11 @@ icesound$(EXEEXT): $(ICESOUNDOBJS) -@rm -f $@ - $(LD) -o $@ $(LFLAGS) $(ICESOUNDOBJS) $(LIBS) -lesd + $(LD) -o $@ $(LFLAGS) $(ICESOUNDOBJS) $(LIBS) + +icecursor$(EXEEXT): $(ICECURSOROBJS) + -@rm -f $@ + $(LD) -o $@ $(LFLAGS) $(ICECURSOROBJS) $(LIBS) iceclock$(EXEEXT): $(ICECLOCKOBJS) -@rm -f $@ --- icewm-1.0.6-pristine/src/icecursor.cc Mon Jan 15 20:01:12 2001 +++ icewm-1.0.6/src/icecursor.cc Mon Jan 15 20:01:55 2001 @@ -0,0 +1,470 @@ +/* + * IceWM - IceCursor + * + * Copyright (C) 2000 Christian W. Zuckschwerdt + * + * animate the X cursor each time a specific GUI event occures + * (see guievent.h) + * for now cursors and masks need to be in LIBDIR/cursors + * + * 2000-10-01: Christian W. Zuckschwerdt + */ + +/* Config: */ +/* event: cursor fgcol bgcol delay + cursor fgcol bgcol delay + ... + event: ... + */ + +#include + +/* Short-cut if GUIEVENTS isn't requested */ +#ifndef CONFIG_GUIEVENTS +int +main(int argc, char *argv[]) { + printf("%s not supported. Configure with '--enable-guievents'.\n", argv[0]); +} +#else /* CONFIG_GUIEVENTS */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define GUI_EVENT_NAMES +#include "guievent.h" +#include "base.h" +#define NUM_OF_GUIEVENTS (sizeof(gui_events)/sizeof(gui_events[0])) +#define NUM_OF_FRAMES 8 + +/* needed in FixupState */ +#define Dynamic 1 + +#ifdef XMU +/* int XmuCursorNameToIndex (char *name); */ +#include +#endif + +static char *program_name = NULL; + +char *displayName = 0; +Display *display = 0; +Window root = 0; + +Atom _GUI_EVENT;; + +char default_cursor_name[] = "left_ptr"; /* see also: cursorfont.h */ +Cursor cursors [NUM_OF_GUIEVENTS][NUM_OF_FRAMES]; + +Display *dpy; +int screen; +Window root1; +char *fore_color = NULL; +char *back_color = NULL; +int reverse = 0; +int save_colors = 0; +int unsave_past = 0; +Pixmap save_pixmap = (Pixmap)None; + +void read_cursors(); +int set_cursor(Cursor cursor); +int file_pointer(char *cursor_file, char *cursor_mask); +int normal_pointer(const char *cursor_name); +void FixupState(); +Cursor CreateCursorFromFiles(const char *cursor_file, const char *mask_file); +Cursor CreateCursorFromName (const char *name); +XColor NameToXColor(const char *name, unsigned long pixel); +Pixmap ReadBitmapFile(const char *filename, unsigned int *width, unsigned int *height, int *x_hot, int *y_hot); + + +int main(int argc, char *argv[]) +{ + + program_name = strrchr(argv[0], '/'); + if (program_name) program_name++; else program_name = argv[0]; + + if (!(display = XOpenDisplay(displayName))) + { + fprintf(stderr, "can't open display: %s", displayName); + exit(1); + } + + root = RootWindow(display, DefaultScreen(display)); + + screen = DefaultScreen(display); + dpy = display; + read_cursors(); + + _GUI_EVENT = XInternAtom(display, XA_GUI_EVENT_NAME, False); + + XSelectInput(display, root, PropertyChangeMask); + + while (1) + { + XEvent xev; + time_t last, now; + + XNextEvent(display, &xev); + + switch (xev.type) { + case PropertyNotify: + if (xev.xproperty.atom == _GUI_EVENT) + { + + /* act at most every other second */ + /*last = now; + now = time(NULL); + if (last+1 < now)*/ + + if (xev.xproperty.state == PropertyNewValue) + { + Atom type; + int format; + unsigned long nitems, lbytes; + unsigned char *propdata; + int d = -1; + + if (XGetWindowProperty(display, root, + _GUI_EVENT, 0, 3, + False, _GUI_EVENT, + &type, &format, + &nitems, &lbytes, + &propdata) == Success) + if (propdata) + { + d = *(char *)propdata; + XFree(propdata); + } + for (unsigned int i = 0; i < sizeof(gui_events)/sizeof(gui_events[0]); i++) + { + if (gui_events[i].type == d) + { + puts(gui_events[i].name); + /* + if (geLaunchApp == i) + { + / * Restore normal pointer * / + fore_color = NULL; + normal_pointer("watch"); + } + else + { + / * Restore normal pointer * / + fore_color = NULL; + normal_pointer(default_cursor_name); + } + */ + + if (1) // cursors[i][0]) + { + /* Animate cursor */ + for (int n = 0; n < NUM_OF_FRAMES; n++) + { + // !!! TODO: which colors? + fore_color = "gold"; + set_cursor(cursors[i][n]); + usleep(100000); + } + /* Restore normal pointer */ + fore_color = NULL; + normal_pointer(default_cursor_name); + } + break; + } + } + } + } + break; + } + } +} + +void read_cursors() +{ + const char *homeDir = getenv("HOME"); + char *path, *libpath; + path = strJoin(homeDir, "/.icewm/cursors/", NULL); + libpath = strJoin(LIBDIR, "/cursors/", NULL); + + char cursor[1024], mask[1024]; + char *cursor_path, *mask_path; + int i, n; + + for (i=0; i < (int)NUM_OF_GUIEVENTS; i++) + { + for (n=0; n < NUM_OF_FRAMES; n++) + { + sprintf(cursor, "%s_cursor_%d.xbm", gui_events[i].name, n+1); + sprintf(mask, "%s_mask_%d.xbm", gui_events[i].name, n+1); + cursor_path = strJoin(path, cursor, NULL); + mask_path = strJoin(path, mask, NULL); + if ((access(cursor_path, R_OK) == 0) && + (access(mask_path, R_OK) == 0)) + { +printf("found %s\n", cursor_path); + // !!! TODO: set colors? + fore_color = "gold"; + cursors[i][n] = CreateCursorFromFiles(cursor_path, mask_path); + } + } + } +} + +int file_pointer(char *cursor_file, char *cursor_mask) +{ + /* Variables */ + Cursor cursor; + + /* Init display */ + dpy = XOpenDisplay(NULL); + if (!dpy) + { + fprintf(stderr, "%s: unable to open display '%s'\n", + program_name, XDisplayName (NULL)); + exit (2); + } + screen = DefaultScreen(dpy); + root1 = RootWindow(dpy, screen); + + /* Set busy-cursor */ + cursor = CreateCursorFromFiles(cursor_file, cursor_mask); + XDefineCursor(dpy, root1, cursor); + XFreeCursor(dpy, cursor); + + FixupState(); + XCloseDisplay(dpy); + return (0); +} + +int set_cursor(Cursor cursor) +{ + /* Init display */ + dpy = XOpenDisplay(NULL); + if (!dpy) + { + fprintf(stderr, "%s: unable to open display '%s'\n", + program_name, XDisplayName (NULL)); + exit (2); + } + screen = DefaultScreen(dpy); + root1 = RootWindow(dpy, screen); + + /* Set -cursor */ + XDefineCursor(dpy, root1, cursor); + + FixupState(); + XCloseDisplay(dpy); + return (0); +} + +int normal_pointer(const char *cursor_name) +{ + /* Variables */ + Cursor cursor; + + /* Init display */ + dpy = XOpenDisplay(NULL); + if (!dpy) + { + fprintf(stderr, "%s: unable to open display '%s'\n", + program_name, XDisplayName (NULL)); + exit (2); + } + screen = DefaultScreen(dpy); + root1 = RootWindow(dpy, screen); + + /* Restore normal pointer */ + cursor = CreateCursorFromName (cursor_name); + if (cursor) + { + XDefineCursor (dpy, root1, cursor); + XFreeCursor (dpy, cursor); + } + + FixupState(); + XCloseDisplay(dpy); + return (0); +} + + +/* Free past incarnation if needed, and retain state if needed. */ +void FixupState() +{ + Atom prop, type; + int format; + unsigned long length, after; + unsigned char *data; + /* + if (!(DefaultVisual(dpy, screen)->class & Dynamic)) + unsave_past = 0;*/ + if (!unsave_past && !save_colors) + return; + prop = XInternAtom(dpy, "_XSETROOT_ID", False); + if (unsave_past) + { + (void)XGetWindowProperty(dpy, root1, prop, 0L, 1L, True, + AnyPropertyType, + &type, &format, &length, &after, &data); + if ((type == XA_PIXMAP) && (format == 32) && + (length == 1) && (after == 0)) + XKillClient(dpy, *((Pixmap *)data)); + else if (type != None) + fprintf(stderr, "%s: warning: _XSETROOT_ID property is garbage\n", + program_name); + } + if (save_colors) + { + if (!save_pixmap) + save_pixmap = XCreatePixmap(dpy, root1, 1, 1, 1); + XChangeProperty(dpy, root1, prop, XA_PIXMAP, 32, PropModeReplace, + (unsigned char *) &save_pixmap, 1); + XSetCloseDownMode(dpy, RetainPermanent); + } +} + + +/* + * CreateCursorFromFiles: make a cursor of the right colors from two bitmap + * files. + */ +#define BITMAP_HOT_DEFAULT 8 + +Cursor CreateCursorFromFiles(const char *cursor_file, const char *mask_file) +{ + Pixmap cursor_bitmap, mask_bitmap; + unsigned int width, height, ww, hh; + int x_hot, y_hot; + Cursor cursor; + XColor fg, bg, temp; + + fg = NameToXColor(fore_color, BlackPixel(dpy, screen)); + bg = NameToXColor(back_color, WhitePixel(dpy, screen)); + if (reverse) + { + temp = fg; fg = bg; bg = temp; + } + + cursor_bitmap = ReadBitmapFile(cursor_file, &width, &height, &x_hot, &y_hot); + mask_bitmap = ReadBitmapFile(mask_file, &ww, &hh, (int *)NULL, (int *)NULL); + + if (width != ww || height != hh) + { + fprintf(stderr, +"%s: dimensions of cursor bitmap and cursor mask bitmap are different\n", + program_name); + exit(1); + /*NOTREACHED*/ + } + + if ((x_hot == -1) && (y_hot == -1)) + { + x_hot = BITMAP_HOT_DEFAULT; + y_hot = BITMAP_HOT_DEFAULT; + } + if ((x_hot < 0) || (x_hot >= (int)width) || + (y_hot < 0) || (y_hot >= (int)height)) + { + fprintf(stderr, "%s: hotspot is outside cursor bounds\n", program_name); + exit(1); + /*NOTREACHED*/ + } + + cursor = XCreatePixmapCursor(dpy, cursor_bitmap, mask_bitmap, &fg, &bg, + (unsigned int)x_hot, (unsigned int)y_hot); + XFreePixmap(dpy, cursor_bitmap); + XFreePixmap(dpy, mask_bitmap); + + return(cursor); +} + +/* + * CreateCursorFromName: Return cursor with given name + * global variables: + * dpy, screen, fore_color, back_color, reverse + */ +Cursor CreateCursorFromName (const char *name) +{ + XColor fg, bg, temp; + int i; + Font fid; + + fg = NameToXColor(fore_color, BlackPixel(dpy, screen)); + bg = NameToXColor(back_color, WhitePixel(dpy, screen)); + if (reverse) + { + temp = fg; fg = bg; bg = temp; + } +#ifdef XMU + i = XmuCursorNameToIndex (name); + if (i == -1) +#endif + return (Cursor) NULL; + fid = XLoadFont (dpy, "cursor"); + if (!fid) + return (Cursor) NULL; + return XCreateGlyphCursor (dpy, fid, fid, + i, i+1, &fg, &bg); +} + + +/* + * NameToXColor: Convert the name of a color to its Xcolor value. + */ +XColor NameToXColor(const char *name, unsigned long pixel) +{ + XColor c; + + if (!name || !*name) + { + c.pixel = pixel; + XQueryColor(dpy, DefaultColormap(dpy, screen), &c); + } + else if (!XParseColor(dpy, DefaultColormap(dpy, screen), name, &c)) + { + fprintf(stderr, "%s: unknown color or bad color format: %s\n", + program_name, name); + exit(1); + /*NOTREACHED*/ + } + return(c); +} + + +Pixmap ReadBitmapFile(const char *filename, unsigned int *width, unsigned int *height, int *x_hot, int *y_hot) +{ + Pixmap bitmap; + int status; + + status = XReadBitmapFile(dpy, root, filename, width, + height, &bitmap, x_hot, y_hot); + if (status == BitmapSuccess) + return(bitmap); + else if (status == BitmapOpenFailed) + fprintf(stderr, "%s: can't open file: %s\n", program_name, filename); + else if (status == BitmapFileInvalid) + fprintf(stderr, "%s: bad bitmap format file: %s\n", + program_name, filename); + else + fprintf(stderr, "%s: insufficient memory for bitmap: %s", + program_name, filename); + exit(1); + /*NOTREACHED*/ +} + +#endif /* CONFIG_GUIEVENTS */ --- icewm-1.0.6-pristine/src/icesound.cc Sun Jan 14 22:49:40 2001 +++ icewm-1.0.6/src/icesound.cc Mon Jan 15 20:09:55 2001 @@ -1,22 +1,48 @@ /* - * IceWM + * IceWM - IceSound * - * Copyright (C) 1997-2001 Marko Macek - * EsounD Hack by CW Zuckschwerdt + * Based on IceWM code Copyright (C) 1997-2001 Marko Macek + * 2000-02-13: Christian W. Zuckschwerdt + * 2000-08-08: Playback throttling. E.g. switch though + * multiple workspaces and get a single sound + * 2000-10-02: Support for (pre-loaded) server samples (ESounD only) + * Removed forking of esd calls + * 2000-12-11: merged patch by Marius Gedminas + * 2000-12-16: merged patch by maxim@macomnet.ru + * - portable way to rip the children + * 2001-01-15: merged with IceWM release 1.0.6 + * + * for now get latest patches as well as sound and cursor themes at + * http://triq.net/icewm/ + * + * Throttling is max. one sample every 500ms. Comments? + * + * Output options and notes: + * /dev/dsp : default. Sound playback will queue. If your /dev/dsp + * is capable of mixing sound streams you can use forking. + * ESounD : recommended. Sampels are cached in the ESD server. + * Is anyone interested in ALSA, ...etc? Nag me about your fav. */ #include "config.h" -#include "intl.h" -#define ESD +#include + +/* Short-cut if either GUIEVENTS or ICESOUND are not requested */ +#ifndef CONFIG_GUIEVENTS +int +main(int argc, char *argv[]) { + printf("%s not supported. Configure with '--enable-guievents'.\n", argv[0]); +} +#else /* CONFIG_GUIEVENTS */ #include -#include #include #include #include #include #include +#include #include #include #include @@ -24,39 +50,246 @@ #include #include #include -#include -#include -#include -#include #include -#include -#include -#define GUI_EVENT_NAMES +#define GUI_EVENT_NAMES #include "guievent.h" +#define GUIEVENTS (sizeof(gui_events)/sizeof(gui_events[0])) + +#include "base.h" /* strJoin */ + +static char *program_name = NULL; + +/* Prefered sound path can be given on commandline. */ +/* Fallback to $HOME/.icewm/sounds then LIBDIR/sounds */ +static char *preferedPath = NULL; + +#ifdef ESD +/* #include */ /* just let ESD do it */ +#include + +char *esd_server = NULL; /* we should read it as an option */ +int esd = -1; /* socket */ +int sample[GUIEVENTS]; /* cache sample id index */ + +/* cache a sample in the server returns sample id, < 0 = error */ +int +cache_sound(char *path, int sound) +{ + int ok; + ok = esd_file_cache( esd, program_name, path ); + if (ok < 0) + { + printf( "%s: Error <%d> uploading. Name = %s:%s\n", + program_name, ok, program_name, path ); + return ok; + } + sample[sound] = ok; + printf( "%s: Sample <%d> uploaded. Name = %s:%s\n", + program_name, ok, program_name, path ); + return ok; +} + +/* uncache all samples from the server */ +int +uncache() +{ + int cnt = 0; + for (int i = 0; i < (int)GUIEVENTS; i++) + if (sample[i] > 0) { + esd_sample_free(esd, sample[i]); + cnt++; + } + return cnt; +} -static char *program_name = NULL; -static char *soundPath = NULL; +/* + * cache the sounds into the EsounD sever + * returns: number of loaded samples + */ +int +cache() +{ + const char *homeDir = getenv("HOME"); + char *path, *libpath; + path = strJoin(homeDir, "/.icewm/sounds/", NULL); + libpath = strJoin(LIBDIR, "/sounds/", NULL); + int cnt = 0; + + char sound_file[1024]; + char *sound_path; + + for (int i = 0; i < (int)GUIEVENTS; i++) + { + sprintf(sound_file, "%s.wav", gui_events[i].name); + if (preferedPath != NULL) { + sound_path = strJoin(preferedPath, sound_file, NULL); + if (access(sound_path, R_OK) == 0) + { + cache_sound(sound_path, i); + cnt++; + continue; + } + } + sound_path = strJoin(path, sound_file, NULL); + if (access(sound_path, R_OK) == 0) + { + cache_sound(sound_path, i); + cnt++; + } + else + { + sound_path = strJoin(libpath, sound_file, NULL); + if (access(sound_path, R_OK) == 0) + { + cache_sound(sound_path, i); + cnt++; + } + } + } + return cnt; +} -char *displayName = 0; -Display *display = 0; -Window root = 0; -int counter = 0; - -Atom _GUI_EVENT;; - -int main(int argc, char *argv[]) { - program_name = argv [0]; - if(argc == 2){ - soundPath = argv[1]; +/* play a cached sound sample using ESounD */ +void +esd_sound_play(int sound) +{ +#ifdef DEBUG + printf ("esd sample play: #%d\n", sound); +#endif + if (sample[ sound ] > 0 ) + esd_sample_play(esd, sample[ sound ]); +} + +#endif /* ESD */ + +/* play a sound sample to /dev/dsp */ +void +dsp_sound_play(int sound) +{ + for (unsigned int i = 0; i < sizeof(gui_events)/sizeof(gui_events[0]); i++) + { + if (gui_events[i].type == sound) { + char s[1024]; + if(preferedPath != NULL){ + sprintf(s, "%s/sounds/%s.wav", preferedPath, gui_events[i].name); + } else { + // !!! TODO: search in ($HOME/.icewm/) + sprintf(s, "%s/sounds/%s.wav", LIBDIR, gui_events[i].name); + } + + + if (access(s, R_OK) == 0) { + int ifd = open(s, O_RDONLY); + if (ifd == -1) + return; + int ofd = open("/dev/dsp", O_WRONLY); + if (ofd == -1) + return; +#ifdef DEBUG + printf ("copying sound %s to /dev/dsp\n", s); +#endif + int n; + while ((n = read(ifd, s, sizeof(s))) > 0) + write(ofd, s, n); + } + break; + } + } +} + +/* fork and play a sound sample */ +void +fork_sound_play(int sound) +{ + int pid = -1; + + if (sound != -1 && (pid = fork()) == 0) { +#ifdef DEBUG + printf ("fork for sound: #%d\n", sound); +#endif + exit(0); } +} + + +char *displayName = 0; +Display *display = 0; +Window root = 0; +struct timeval last; +Atom _GUI_EVENT; + +/* SIGNAL HANDLER */ + +volatile int terminate = 0; + +void +clean_exit(int sig) { + signal(sig, SIG_DFL); + fprintf( stderr, "%s: received signal %d: terminating...\n", + program_name, sig ); + terminate = 1; + return; +} + +/* + * Catch a restart signal and reload + */ +void +sig_hup(int sig) +{ +#ifdef DEBUG + printf("%s: signal %d", program_name, sig); +#endif +#ifdef ESD + uncache(); + cache(); +#endif +} + +void +sig_chld(int sig){ + pid_t pid; + int stat; + while ((pid = waitpid(-1, &stat, WNOHANG)) > 0) + +#ifdef DEBUG + printf("child %d terminated\n", pid); +#else + ; +#endif + + return; +} + +/* MAIN */ + +int +main(int argc, char *argv[]) { + + program_name = strrchr(argv[0], '/'); + if (program_name) program_name++; else program_name = argv[0]; + + /* if we see any of these, terminate */ + signal( SIGINT, clean_exit ); + signal( SIGKILL, clean_exit ); + signal( SIGPIPE, clean_exit ); + + if(argc == 2) preferedPath = argv[1]; + +#ifdef ESD + for (int i = 0; i < (int)GUIEVENTS; i++) + sample[i] = -1; + + esd = esd_open_sound( esd_server ); + if ( esd <= 0 ) exit(1); + cache(); +#endif if (!(display = XOpenDisplay(displayName))) { fprintf(stderr, - _("Can't open display: %s. " - "X must be running and $DISPLAY set."), - displayName ? displayName : _("")); - fputc('\n', stderr); + "Can't open display: %s. X must be running and $DISPLAY set.\n", + displayName ? displayName : ""); exit(1); } @@ -66,13 +299,20 @@ XSelectInput(display, root, PropertyChangeMask); - signal(SIGCHLD, SIG_IGN); + signal(SIGCHLD, sig_chld); + signal(SIGHUP, sig_hup); - for (;;) { + gettimeofday(&last, NULL); + while (!terminate) { XEvent xev; + struct timeval now; - XNextEvent(display, &xev); - + XNextEvent(display, &xev); /* blocking -- damn.*/ + /* perhaps we'll use this next time? + while (!XCheckMaskEvent(display, PropertyChangeMask, &xev)) { + usleep(10000); + } + */ switch (xev.type) { case PropertyNotify: if (xev.xproperty.atom == _GUI_EVENT) { @@ -84,7 +324,7 @@ int d = -1; if (XGetWindowProperty(display, root, - _GUI_EVENT, 0, 3, True, _GUI_EVENT, + _GUI_EVENT, 0, 3, False, _GUI_EVENT, &type, &format, &nitems, &lbytes, &propdata) == Success) if (propdata) { @@ -92,48 +332,48 @@ XFree(propdata); } - int pid = -1; - if (pid > 0) - kill(pid, SIGKILL); - - if (d != -1 && (pid = fork()) == 0) { - for (unsigned int i = 0; i < sizeof(gui_events)/sizeof(gui_events[0]); i++) { + if (geRestart == d) { +#ifdef DEBUG + printf("%s: recieved restart event.\n", + program_name); +#endif +#ifdef ESD + uncache(); + cache(); +#endif + } + + gettimeofday(&now, NULL); + + if ((now.tv_sec - last.tv_sec >= 2) || + ((now.tv_sec-last.tv_sec)*1000000 + + now.tv_usec - last.tv_usec > 500000)) { + last.tv_sec = now.tv_sec; + last.tv_usec = now.tv_usec; +#ifdef DEBUG + for (unsigned int i = 0; + i < sizeof(gui_events)/sizeof(gui_events[0]); + i++) { if (gui_events[i].type == d) { - char s[1024]; - if(soundPath != NULL){ - sprintf(s, "%s/sounds/%s.wav", soundPath, gui_events[i].name); - } else { - sprintf(s, "%s/sounds/%s.wav", LIBDIR, gui_events[i].name); - } - - if (access(s, R_OK) == 0) { -#ifdef ESD - char prg[1024]; - sprintf(prg,"%s-%i",program_name,counter); - counter++; - if(counter >= 32767) counter = 0; - esd_play_file(program_name, s, 1); -#else - int ifd = open(s, O_RDONLY); - if (ifd == -1) - exit(0); - int ofd = open("/dev/dsp", O_WRONLY); - if (ofd == -1) - exit(0); - - int n; - while ((n = read(ifd, s, sizeof(s))) > 0) - write(ofd, s, n); -#endif - } - break; - } + puts(gui_events[i].name); + } } - exit(0); +#endif /* DEBUG */ +#ifdef ESD + esd_sound_play( d ); +#else + dsp_sound_play( d ); + // or fork_sound_play( d ); +#endif } } } break; } } +#ifdef ESD + uncache(); +#endif /* ESD */ } + +#endif /* CONFIG_GUIEVENTS */