diff -Naur pwm-1.0/Makefile pwm-1.0-tn/Makefile --- pwm-1.0/Makefile Sat Jul 1 17:48:50 2000 +++ pwm-1.0-tn/Makefile Mon Jul 8 18:08:57 2002 @@ -16,7 +16,7 @@ OBJS= main.o draw.o font.o frame.o event.o clientwin.o thing.o \ property.o pointer.o key.o moveres.o cursor.o function.o \ - exec.o focus.o workspace.o winobj.o screen.o menu.o \ + exec.o focus.o workspace.o winobj.o screen.o sound.o menu.o \ readconfig.o menudata.o dock.o frameid.o placement.o \ binding.o winlist.o mwmhints.o signal.o winprops.o diff -Naur pwm-1.0/clientwin.c pwm-1.0-tn/clientwin.c --- pwm-1.0/clientwin.c Fri Aug 2 16:32:43 2002 +++ pwm-1.0-tn/clientwin.c Sat Aug 3 01:27:46 2002 @@ -21,6 +21,7 @@ #include "winlist.h" #include "mwmhints.h" #include "winprops.h" +#include "sound.h" static void set_clientwin_state(WClientWin *cwin, int state); @@ -31,6 +32,53 @@ /* */ +WClientDesc *get_client_desc(Window window) +{ + WClientDesc *wcd; + + if (window == None) + return NULL; + if (XFindContext(wglobal.dpy, window, wglobal.app_context, (XPointer*)&wcd)!=XCSUCCESS){ + /*fprintf(stderr, "Error getting app_context.\n");*/ + return NULL; + } + return wcd; +} + + +void set_appdesc(Window window) +{ + WClientDesc *wcd=get_client_desc(window); + /* I don't know why, but dialog windows can't find previous context :-( */ + if(wcd==NULL){ + wcd=malloc(sizeof(WClientDesc)); + if(wcd==NULL) return; + wcd->refcount=1; + XSaveContext(wglobal.dpy, window, wglobal.app_context, (XPointer)wcd); + play_sound(SND_APPSTART); + }else{ + wcd->refcount++; + } +} + + +void remove_appdesc(Window window) +{ + WClientDesc *wcd=get_client_desc(window); + if(wcd!=NULL){ + wcd->refcount--; + if(wcd->refcount==0){ + XDeleteContext(wglobal.dpy, window, wglobal.app_context); + free(wcd); + play_sound(SND_APPEXIT); + } + } +} + + +/* */ + + void get_clientwin_size_hints(WClientWin *cwin) { XSizeHints *hints; @@ -230,7 +278,7 @@ cwin->state=initial_state; cwin->name=get_string_property(cwin->client_win, XA_WM_NAME, NULL); cwin->icon_name=get_string_property(cwin->client_win, - XA_WM_ICON_NAME, NULL); + XA_WM_ICON_NAME, NULL); cwin->label=NULL; cwin->label_width=0; cwin->event_mask=CLIENT_MASK; @@ -431,8 +479,10 @@ /* Check that the window exists. The previous check does not seem * to catch all cases of window destroyal. */ - if(XGetWindowAttributes(wglobal.dpy, win, &attr)) + if(XGetWindowAttributes(wglobal.dpy, win, &attr)){ + if(!dock) set_appdesc(win); return cwin; + } warn("Window disappeared"); @@ -496,7 +546,9 @@ configure_cwin_bw(cwin->client_win, cwin->orig_bw); update_winlist(); - + if(!WTHING_IS(cwin->t_parent, WTHING_DOCK)) + remove_appdesc(cwin->client_win); + free_thing((WThing*)cwin); } diff -Naur pwm-1.0/clientwin.h pwm-1.0-tn/clientwin.h --- pwm-1.0/clientwin.h Thu Jun 15 20:55:57 2000 +++ pwm-1.0-tn/clientwin.h Fri Aug 2 23:21:16 2002 @@ -51,6 +51,11 @@ } WClientWin; +typedef struct _WClientDesc{ + int refcount; +} WClientDesc; + + #define CWIN_FRAME(CWIN) ((WFrame*)((CWIN)->t_parent)) #define CWIN_HAS_FRAME(CWIN) clientwin_has_frame(CWIN) diff -Naur pwm-1.0/config.h pwm-1.0-tn/config.h --- pwm-1.0/config.h Sun Jun 4 00:12:54 2000 +++ pwm-1.0-tn/config.h Sun Jul 7 19:12:29 2002 @@ -71,6 +71,7 @@ #define GRDATA (&(wglobal.grdata)) #define SCREEN (&(wglobal.screen)) +#define SNDDATA (&(wglobal.sound)) #define CF_FONT (GRDATA->font) #define CF_MENU_FONT (GRDATA->menu_font) diff -Naur pwm-1.0/event.c pwm-1.0-tn/event.c --- pwm-1.0/event.c Sat Jul 1 14:37:50 2000 +++ pwm-1.0-tn/event.c Sat Jul 20 10:22:41 2002 @@ -542,8 +542,11 @@ if(cwin->name!=NULL) XFree((void*)cwin->name); cwin->name=get_string_property(cwin->client_win, XA_WM_NAME, NULL); + if (frame) need_recalc=TRUE; + /* if(frame && frame->cwin_count==1) need_recalc=TRUE; + */ break; case XA_WM_ICON_NAME: diff -Naur pwm-1.0/exec.c pwm-1.0-tn/exec.c --- pwm-1.0/exec.c Wed Jun 28 15:47:22 2000 +++ pwm-1.0-tn/exec.c Tue Jul 9 11:45:45 2002 @@ -19,7 +19,7 @@ #include "menu.h" #include "property.h" #include "signal.h" - +#include "sound.h" #define SHELL_PATH "/bin/sh" #define SHELL_NAME "sh" @@ -150,7 +150,7 @@ void wm_exitret(int retval) -{ +{ if(wglobal.parent!=0) kill(wglobal.parent, SIGTERM); else diff -Naur pwm-1.0/frame.c pwm-1.0-tn/frame.c --- pwm-1.0/frame.c Wed Jun 28 19:56:24 2000 +++ pwm-1.0-tn/frame.c Tue Jul 9 16:30:50 2002 @@ -21,6 +21,7 @@ #include "moveres.h" #include "placement.h" #include "winlist.h" +#include "sound.h" #define IS_CURRENT_FRAME(FRAME) ((WWinObj*)(FRAME)==wglobal.current_winobj) @@ -738,6 +739,7 @@ set_frame_size(frame, w, h); frame->flags=flags; + play_sound(SND_MAXIMIZE); } @@ -770,6 +772,7 @@ set_frame_pos(frame, x, y); frame->flags=flags; + play_sound(SND_UNMAXIMIZE); } @@ -906,6 +909,7 @@ set_frame_pos(frame, x, y); set_frame_state(frame, 0); } + play_sound(SND_ATTACH); } @@ -1015,6 +1019,10 @@ void frame_toggle_shade(WFrame *frame) { set_frame_state(frame, frame->flags^WFRAME_SHADE); + if(frame->flags&WFRAME_SHADE) + play_sound(SND_SHADE); + else + play_sound(SND_UNSHADE); } @@ -1022,8 +1030,12 @@ { int ws=WORKSPACE_STICKY; - if(WWINOBJ_IS_STICKY(frame)) + if(WWINOBJ_IS_STICKY(frame)){ ws=WORKSPACE_CURRENT; + play_sound(SND_UNSTICK); + }else{ + play_sound(SND_STICK); + } move_to_workspace((WWinObj*)frame, ws); diff -Naur pwm-1.0/global.h pwm-1.0-tn/global.h --- pwm-1.0/global.h Mon Jun 12 18:05:15 2000 +++ pwm-1.0-tn/global.h Fri Aug 2 22:51:34 2002 @@ -17,6 +17,7 @@ #include "winobj.h" #include "menu.h" #include "draw.h" +#include "sound.h" #define MAX_SCREENS 1 @@ -41,8 +42,10 @@ WScreen screen; WGRData grdata; + WSounds sound; XContext win_context; + XContext app_context; Atom atom_wm_state; Atom atom_wm_change_state; Atom atom_wm_protocols; diff -Naur pwm-1.0/main.c pwm-1.0-tn/main.c --- pwm-1.0/main.c Wed Jun 28 15:47:22 2000 +++ pwm-1.0-tn/main.c Fri Aug 2 22:54:43 2002 @@ -25,6 +25,7 @@ #include "binding.h" #include "readconfig.h" #include "winlist.h" +#include "sound.h" static bool initialize(const char *display, const char *cfgfile, @@ -90,6 +91,7 @@ wglobal.dblclick_delay=CF_DBLCLICK_DELAY; wglobal.parent=0; wglobal.n_children=0; + sound_init(); /* The rest don't need to be initialized here */ optparser_init(argc, argv, OPTP_MIDLONG, opts, &wm_cinfo); @@ -126,6 +128,7 @@ return EXIT_FAILURE; } + play_sound(SND_START); mainloop(); /* The code should never return here */ @@ -189,6 +192,7 @@ wglobal.conn=ConnectionNumber(dpy); wglobal.win_context=XUniqueContext(); + wglobal.app_context=XUniqueContext(); wglobal.atom_wm_state=XInternAtom(dpy, "WM_STATE", False); wglobal.atom_wm_change_state=XInternAtom(dpy, "WM_CHANGE_STATE", False); @@ -257,4 +261,6 @@ wglobal.dpy=NULL; XCloseDisplay(dpy); + play_sound(SND_FINISH); + sound_deinit(); } diff -Naur pwm-1.0/readconfig.c pwm-1.0-tn/readconfig.c --- pwm-1.0/readconfig.c Mon Jun 26 21:23:46 2000 +++ pwm-1.0-tn/readconfig.c Fri Aug 2 23:27:40 2002 @@ -732,7 +732,40 @@ return TRUE; } - + +static bool do_soundgroup (Token *toks, char **sound) +{ + if(*sound!=NULL){ + free(*sound); + *sound=NULL; + } + *sound = strdup(TOK_STRING_VAL(&(toks[1]))); + return TRUE; +} + +#define SNDHAND(SD) \ + static bool opt_sound_##SD(Tokenizer *tokz, int n, Token *toks) \ + { \ + return do_soundgroup(toks, &(SNDDATA->SD)); \ + } + +SNDHAND(player) +SNDHAND(start) +SNDHAND(finish) +SNDHAND(appstart) +SNDHAND(appexit) +SNDHAND(shade) +SNDHAND(unshade) +SNDHAND(maximize) +SNDHAND(unmaximize) +SNDHAND(stick) +SNDHAND(unstick) +SNDHAND(attach) +SNDHAND(detach) + +#undef SNDHAND + + static bool begin_screen(Tokenizer *tokz, int n, Token *toks) { int i; @@ -939,6 +972,20 @@ {"workspaces", "l?l", opt_screen_workspaces, NULL}, {"opaque_move", "l", opt_screen_opaque_move, NULL}, {"dock", "sl", opt_screen_dock, NULL}, + + {"sound_player", "s", opt_sound_player, NULL}, + {"start_sound", "s", opt_sound_start, NULL}, + {"finish_sound", "s", opt_sound_finish, NULL}, + {"appstart_sound", "s", opt_sound_appstart, NULL}, + {"appexit_sound", "s", opt_sound_appexit, NULL}, + {"shade_sound", "s", opt_sound_shade, NULL}, + {"unshade_sound", "s", opt_sound_unshade, NULL}, + {"maximize_sound", "s", opt_sound_maximize, NULL}, + {"unmaximize_sound", "s", opt_sound_unmaximize, NULL}, + {"stick_sound", "s", opt_sound_stick, NULL}, + {"unstick_sound", "s", opt_sound_unstick, NULL}, + {"attach_sound", "s", opt_sound_attach, NULL}, + {"detach_sound", "s", opt_sound_detach, NULL}, {"#end", NULL, end_screen, NULL}, {"#cancel", NULL, end_screen, NULL}, diff -Naur pwm-1.0/sound.c pwm-1.0-tn/sound.c --- pwm-1.0/sound.c Thu Jan 1 01:00:00 1970 +++ pwm-1.0-tn/sound.c Sat Aug 3 01:13:31 2002 @@ -0,0 +1,120 @@ +/* + * pwm/sound.c + * + * Copyright (c) Thomas Nemeth 2002. + * See the included file LICENSE for details. + */ + +#include "X11/Xlib.h" +#include "sound.h" +#include "global.h" +#include "config.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/* ====== FONCTIONS ======================================================= */ + +extern char **environ; + +int sound_system(const char *command, const char *options) { + int pid, status; + + if (command == 0) + return 1; + pid = fork (); + if (pid == -1) + return -1; + if (pid == 0) { + char *cmd; + char *argv[4]; + cmd = malloc(strlen(command) + strlen (options) + 5); + if (cmd!=NULL) { + strcpy(cmd, command); + strcat(cmd, " "); + strcat(cmd, options); + strcat(cmd, " &"); + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = cmd; + argv[3] = 0; + execve("/bin/sh", argv, environ); + free(cmd); + } + exit(127); + } + do { + if (waitpid (pid, &status, 0) == -1) { + if (errno != EINTR) + return -1; + } else + return status; + } while (1); +} + + +void sound_init() { + SNDDATA->player = NULL; + SNDDATA->start = NULL; + SNDDATA->finish = NULL; + SNDDATA->appstart = NULL; + SNDDATA->appexit = NULL; + SNDDATA->shade = NULL; + SNDDATA->unshade = NULL; + SNDDATA->maximize = NULL; + SNDDATA->unmaximize = NULL; + SNDDATA->stick = NULL; + SNDDATA->unstick = NULL; + SNDDATA->attach = NULL; + SNDDATA->detach = NULL; +} + + +void sound_deinit() { +#define FREESNDSTR(S) if(S!=NULL){free(S);S=NULL;} + FREESNDSTR(SNDDATA->player); + FREESNDSTR(SNDDATA->start); + FREESNDSTR(SNDDATA->finish); + FREESNDSTR(SNDDATA->appstart); + FREESNDSTR(SNDDATA->appexit); + FREESNDSTR(SNDDATA->shade); + FREESNDSTR(SNDDATA->unshade); + FREESNDSTR(SNDDATA->maximize); + FREESNDSTR(SNDDATA->unmaximize); + FREESNDSTR(SNDDATA->stick); + FREESNDSTR(SNDDATA->unstick); + FREESNDSTR(SNDDATA->attach); + FREESNDSTR(SNDDATA->detach); +#undef FREESNDSTR +} + + +void play_sound(SoundType sound) { + char *filename = NULL; + + switch (sound) { + case SND_START: filename = SNDDATA->start; break; + case SND_FINISH: filename = SNDDATA->finish; break; + case SND_APPSTART: filename = SNDDATA->appstart; break; + case SND_APPEXIT: filename = SNDDATA->appexit; break; + case SND_SHADE: filename = SNDDATA->shade; break; + case SND_UNSHADE: filename = SNDDATA->unshade; break; + case SND_MAXIMIZE: filename = SNDDATA->maximize; break; + case SND_UNMAXIMIZE: filename = SNDDATA->unmaximize; break; + case SND_STICK: filename = SNDDATA->stick; break; + case SND_UNSTICK: filename = SNDDATA->unstick; break; + case SND_ATTACH: filename = SNDDATA->attach; break; + case SND_DETACH: filename = SNDDATA->detach; break; + default: filename = NULL; + } + if ((SNDDATA->player != NULL) && (filename != NULL)) + sound_system (SNDDATA->player, filename); +} + diff -Naur pwm-1.0/sound.h pwm-1.0-tn/sound.h --- pwm-1.0/sound.h Thu Jan 1 01:00:00 1970 +++ pwm-1.0-tn/sound.h Fri Aug 2 23:24:18 2002 @@ -0,0 +1,48 @@ +/* + * pwm/sound.h + * + * Copyright (c) Thomas Nemeth 2002. + * See the included file LICENSE for details. + */ + +#ifndef INCLUDED_SOUND_H +#define INCLUDED_SOUND_H + +typedef enum{ + NO_SOUND, + SND_START, + SND_FINISH, + SND_APPSTART, + SND_APPEXIT, + SND_SHADE, + SND_UNSHADE, + SND_MAXIMIZE, + SND_UNMAXIMIZE, + SND_STICK, + SND_UNSTICK, + SND_ATTACH, + SND_DETACH +} SoundType; + +typedef struct _WSounds{ + char *player; + char *start; + char *finish; + char *appstart; + char *appexit; + char *shade; + char *unshade; + char *maximize; + char *unmaximize; + char *stick; + char *unstick; + char *attach; + char *detach; +} WSounds; + + +void sound_init(); +void sound_deinit(); +void play_sound(SoundType sound); + +#endif /* INCLUDED_SOUND_H */ diff -Naur pwm-1.0/winlist.c pwm-1.0-tn/winlist.c --- pwm-1.0/winlist.c Sat Jul 1 17:48:20 2000 +++ pwm-1.0-tn/winlist.c Tue Jul 9 15:55:10 2002 @@ -15,6 +15,7 @@ #include "focus.h" #include "winobj.h" #include "frameid.h" +#include "sound.h" static bool winlist_menudata_init(WMenuData *data, WThing *context); @@ -243,6 +244,7 @@ attachdetach_clientwin((WFrame*)obj, entry->u.winlist.clientwin, FALSE, 0, 0); + play_sound(SND_ATTACH); } @@ -256,6 +258,7 @@ attachdetach_clientwin(NULL, cwin, FALSE, 0, 0); goto_clientwin(cwin); + play_sound(SND_DETACH); }