From the review of 2026-11-12's commits (the points left open in 1b524eb94): Sound behind McdeSys (ext/src/mcde/AGENTS.md, philosophy 3): libMcdeSound named /usr/bin/paplay, aplay, /usr/pkg/bin/audioplay and ffplay itself and waited for the player, so mcdesoundd heard nothing while a sound played. mcde_sys_sound_play (sound.c) takes paplay where a PulseAudio server answers, else the backend's player (mcde_sys_player: audioplay(1) on NetBSD, aplay(1) on Linux), started in a grandchild: no wait, no zombie. Measured against a private PulseAudio with a null sink: OpenFolder and TerminalBell sent back to back play at the same time (pactl list short sink-inputs: two streams), mcdesoundd -selftest PASS, a second mcdesoundd says "a server runs already". The /usr/pkg/dt fallbacks of Sound.c and dtphoto.c are gone (CDE_INSTALLATION_TOP is the prefix); McdeSoundFile's dead buffer is gone; mcdesoundd ends the 20 bytes of a message itself; Sound.h is installed (include/Makefile.am, PLIST). Linking: LIBMCDESOUND and LIBTERM carry the libraries below them (configure.ac). Debian's libtool hands no indirect library to the linker, which then took the installed, older libMcdeSys through libMcdeSound's RUNPATH and failed (dtterm: undefined mcde_sys_sound_play). dtwm plug and play (WmMcdeDisplays.c, written 2026-11-11, uncommitted and not compiling): the ClientData fields it uses, McdeHeadsChanged (Xinerama's list read anew, its XineramaQueryScreens memory given back with XFree), McdePanelMonitorsChanged (the panel centres on the main display), the RandR events taken in WmMain.c's loop, McdeDisplaysInit after the EWMH setup, the file in Makefile.am. Measured on Xvfb: dtwm starts with it, the check at login leaves the outputs as they were (xrandr before and after: screen connected 1024x700+0+0), dtwm runs on. Plugging itself was not measured: Xvfb cannot change its outputs, and Xorg's dummy driver refuses a user who is not at the console. Smaller: dttoolbox ignores SIGCHLD from the start (set after the first fork it missed the first child) and lost its test hook /tmp/dttoolbox-no-home; dtfile plays OpenFolder once per folder (FileMgr.c), not twice; dtpaint's unused variable; dttoolbox frees XGetAtomName's string without a cast-away const. AGENTS.md describes McdeSound, mcdesoundd, dtphoto, dtpaint, dttoolbox and the plug and play; the WAV tones' maker was not kept, which it says. The two stale citations (53b852bb2, 945da0f4c) are corrected in git notes. Built with make mcde-host, exit 0 (build/logs/mcde-host-2026-11-13q.log). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
223 lines
4.7 KiB
C
223 lines
4.7 KiB
C
/*
|
|
* Sound.c -- MCDE: the theme, the client call, the player (Mcde/Sound.h)
|
|
*
|
|
* The theme is the reference's format, an X-Resource file:
|
|
*
|
|
* *Launch.soundfile: launch.wav
|
|
* *OpenFolder.soundfile: open_folder.wav
|
|
*
|
|
* so an IRIX defaultScheme.ss loads as a test case; the files are looked up
|
|
* next to the theme. The client sends a ClientMessage to the selection owner
|
|
* of _MCDE_SOUND_SERVER; the daemon (programs/mcdesoundd) plays, through
|
|
* McdeSys (mcde_sys_sound_play: the system's player, ext/src/mcde/AGENTS.md).
|
|
*
|
|
* C99 and POSIX, Xlib only.
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <X11/Xlib.h>
|
|
#include <X11/Xatom.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
#include <Mcde/Sound.h>
|
|
|
|
#define MAXEVENTS 128
|
|
|
|
static char themeDir[512];
|
|
static char evName[MAXEVENTS][64];
|
|
static char evFile[MAXEVENTS][128];
|
|
static int nev;
|
|
|
|
static void
|
|
Trim(char *p)
|
|
{
|
|
size_t n = strlen(p);
|
|
|
|
while (n > 0 && (p[n - 1] == '\n' || p[n - 1] == '\r' ||
|
|
p[n - 1] == ' ' || p[n - 1] == '\t'))
|
|
p[--n] = '\0';
|
|
}
|
|
|
|
static int
|
|
ReadTheme(const char *path)
|
|
{
|
|
FILE *f;
|
|
char line[512];
|
|
|
|
if ((f = fopen(path, "r")) == NULL)
|
|
return -1;
|
|
while (fgets(line, sizeof line, f) != NULL) {
|
|
char *p = line, *dot, *colon, *val;
|
|
size_t n;
|
|
|
|
while (*p == ' ' || *p == '\t')
|
|
p++;
|
|
Trim(p);
|
|
if (*p != '*')
|
|
continue;
|
|
dot = strstr(p, ".soundfile");
|
|
if (dot == NULL)
|
|
continue;
|
|
colon = strchr(dot, ':');
|
|
if (colon == NULL)
|
|
continue;
|
|
n = (size_t) (dot - (p + 1));
|
|
if (n == 0 || n >= sizeof evName[0] || nev >= MAXEVENTS)
|
|
continue;
|
|
memcpy(evName[nev], p + 1, n);
|
|
evName[nev][n] = '\0';
|
|
val = colon + 1;
|
|
while (*val == ' ' || *val == '\t')
|
|
val++;
|
|
Trim(val);
|
|
snprintf(evFile[nev], sizeof evFile[nev], "%s", val);
|
|
nev++;
|
|
}
|
|
fclose(f);
|
|
return nev > 0 ? 0 : -1;
|
|
}
|
|
|
|
int
|
|
McdeSoundLoadTheme(const char *dir)
|
|
{
|
|
char path[768];
|
|
|
|
if (dir == NULL || dir[0] == '\0')
|
|
return -1;
|
|
snprintf(themeDir, sizeof themeDir, "%s", dir);
|
|
snprintf(path, sizeof path, "%s/theme.ss", themeDir);
|
|
nev = 0;
|
|
return ReadTheme(path);
|
|
}
|
|
|
|
int
|
|
McdeSoundSetTheme(Display *dpy, const char *dir)
|
|
{
|
|
Atom sel = XInternAtom(dpy, "_MCDE_SOUND_SERVER", False);
|
|
Atom prop = XInternAtom(dpy, "_MCDE_SOUND_THEME", False);
|
|
Atom msg = XInternAtom(dpy, "_MCDE_SOUND_RELOAD", False);
|
|
Window owner = XGetSelectionOwner(dpy, sel);
|
|
XEvent ev;
|
|
|
|
if (owner == None)
|
|
return 1;
|
|
XChangeProperty(dpy, owner, prop, XA_STRING, 8, PropModeReplace,
|
|
(const unsigned char *) dir, (int) strlen(dir));
|
|
memset(&ev, 0, sizeof ev);
|
|
ev.xclient.type = ClientMessage;
|
|
ev.xclient.window = owner;
|
|
ev.xclient.message_type = msg;
|
|
ev.xclient.format = 8;
|
|
XSendEvent(dpy, owner, False, NoEventMask, &ev);
|
|
XFlush(dpy);
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
McdeSoundInit(void)
|
|
{
|
|
const char *env = getenv("MCDE_SOUND_THEME");
|
|
char path[768];
|
|
|
|
nev = 0;
|
|
if (env != NULL && env[0] != '\0')
|
|
snprintf(themeDir, sizeof themeDir, "%s", env);
|
|
else
|
|
snprintf(themeDir, sizeof themeDir,
|
|
CDE_INSTALLATION_TOP "/share/sounds/themes/Camouflage");
|
|
snprintf(path, sizeof path, "%s/theme.ss", themeDir);
|
|
return ReadTheme(path);
|
|
}
|
|
|
|
/* NAME without its underscores into BUF */
|
|
static void
|
|
Bare(const char *name, char *buf, size_t len)
|
|
{
|
|
size_t n = 0;
|
|
|
|
for (; *name != '\0' && n + 1 < len; name++)
|
|
if (*name != '_')
|
|
buf[n++] = *name;
|
|
buf[n] = '\0';
|
|
}
|
|
|
|
const char *
|
|
McdeSoundFile(const char *event)
|
|
{
|
|
char want[64], have[64];
|
|
int i;
|
|
|
|
for (i = 0; i < nev; i++)
|
|
if (strcmp(evName[i], event) == 0)
|
|
return evFile[i];
|
|
/* the reference wrote names with underscores; accept both */
|
|
Bare(event, want, sizeof want);
|
|
for (i = 0; i < nev; i++) {
|
|
Bare(evName[i], have, sizeof have);
|
|
if (strcmp(want, have) == 0)
|
|
return evFile[i];
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
const char *
|
|
McdeSoundThemeDir(void)
|
|
{
|
|
return themeDir;
|
|
}
|
|
|
|
int
|
|
McdeSoundCount(void)
|
|
{
|
|
return nev;
|
|
}
|
|
|
|
const char *
|
|
McdeSoundEventName(int i)
|
|
{
|
|
if (i < 0 || i >= nev)
|
|
return NULL;
|
|
return evName[i];
|
|
}
|
|
|
|
int
|
|
McdeSoundEvent(Display *dpy, const char *event)
|
|
{
|
|
if (nev == 0)
|
|
(void) McdeSoundInit();
|
|
Atom sel = XInternAtom(dpy, "_MCDE_SOUND_SERVER", False);
|
|
Atom msg = XInternAtom(dpy, "_MCDE_SOUND_EVENT", False);
|
|
Window owner = XGetSelectionOwner(dpy, sel);
|
|
XEvent ev;
|
|
int i;
|
|
|
|
if (owner == None)
|
|
return 1;
|
|
memset(&ev, 0, sizeof ev);
|
|
ev.xclient.type = ClientMessage;
|
|
ev.xclient.window = owner;
|
|
ev.xclient.message_type = msg;
|
|
ev.xclient.format = 8;
|
|
for (i = 0; i < 19 && event[i] != '\0'; i++)
|
|
ev.xclient.data.b[i] = event[i];
|
|
ev.xclient.data.b[i] = '\0';
|
|
XSendEvent(dpy, owner, False, NoEventMask, &ev);
|
|
XFlush(dpy);
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
McdeSoundPlay(Display *dpy, const char *path)
|
|
{
|
|
if (mcde_sys_sound_play(path) == MCDE_SYS_OK)
|
|
return 0;
|
|
XBell(dpy, 0);
|
|
XFlush(dpy);
|
|
return 1; /* no player: the bell answered */
|
|
}
|