MCDE S4 in part: a second theme, listed and switched at runtime

The theme directory is the unit: a second theme Base (the lower voice of
Camouflage) sits beside it.  The Sound pane lists the directories found
next to the current theme; a click sends McdeSoundSetTheme, which writes
the path into _MCDE_SOUND_THEME and sends _MCDE_SOUND_RELOAD; the server
reads the property and reloads (McdeSoundLoadTheme).

Measured: click on Base -> daemon log 'theme now .../Base', the next
Launch plays .../Base/launch.wav; screenshot settings-sound3.png.
This commit is contained in:
lotherk committed 2026-11-12 12:42:42 +00:00
1 parent 6834760edb
commit 9b57d2a773
26 files changed
+199 -4

No files matched your search

+6
View File
@@ -21,6 +21,12 @@ const char * McdeSoundFile(const char *event);
/* the theme directory (for the daemon's relative file names) */
const char * McdeSoundThemeDir(void);
/* load another theme directory (the server's side of a theme change) */
int McdeSoundLoadTheme(const char *dir);
/* ask the running server to load DIR; returns 0 when it took it */
int McdeSoundSetTheme(Display *dpy, const char *dir);
/* how many events the theme names, and their names (for a settings list) */
int McdeSoundCount(void);
const char * McdeSoundEventName(int i);
+36
View File
@@ -83,6 +83,42 @@ ReadTheme(const char *path)
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)
{
+50
View File
@@ -40,6 +40,9 @@
#include <Dt/Dt.h>
#include <Mcde/McdeSys.h>
#include <dirent.h>
#include <sys/stat.h>
#include <Mcde/Sound.h>
#include "panes.h"
@@ -257,6 +260,52 @@ SoundPreview(Widget w, XtPointer data, XtPointer call)
(void) McdeSoundEvent(XtDisplay(w), (const char *) data);
}
static void
SoundTheme(Widget w, XtPointer data, XtPointer call)
{
(void) call;
(void) McdeSoundSetTheme(XtDisplay(w), (const char *) data);
}
/* the themes are directories next to the current one */
static void
MakeThemes(Widget box)
{
char root[512], path[768], *slash;
DIR *d;
struct dirent *e;
Widget row;
(void) McdeSoundInit();
snprintf(root, sizeof root, "%s", McdeSoundThemeDir());
if ((slash = strrchr(root, '/')) == NULL)
return;
*slash = '\0';
if ((d = opendir(root)) == NULL)
return;
XtVaCreateManagedWidget("themeLabel", xmLabelWidgetClass, box,
XmNlabelString, XmStringCreateLocalized("Sound theme:"), NULL);
row = XtVaCreateManagedWidget("themes", xmRowColumnWidgetClass, box,
XmNorientation, XmHORIZONTAL, XmNspacing, 4, NULL);
while ((e = readdir(d)) != NULL) {
struct stat st;
Widget b;
char *dir;
if (e->d_name[0] == '.')
continue;
snprintf(path, sizeof path, "%s/%s", root, e->d_name);
if (stat(path, &st) != 0 || !S_ISDIR(st.st_mode))
continue;
b = XtVaCreateManagedWidget(e->d_name, xmPushButtonWidgetClass,
row, NULL);
dir = strdup(path);
XtAddCallback(b, XmNactivateCallback, SoundTheme,
(XtPointer) dir);
}
closedir(d);
}
static Widget
MakeSound(Widget parent)
{
@@ -294,6 +343,7 @@ MakeSound(Widget parent)
(XtPointer) ev[i]);
}
}
MakeThemes(box);
SoundRead();
return box;
}
+24
View File
@@ -24,3 +24,27 @@ sounds_DATA = theme.ss \
sounds/iconify.wav sounds/deiconify.wav sounds/new_mail.wav \
sounds/print_files.wav sounds/search_hit.wav sounds/search_miss.wav \
sounds/clock_chime_hour.wav
# the second theme, for the theme choice in the settings
basedir = $(CDE_INSTALLATION_TOP)/share/sounds/themes/Base
base_DATA = themes/Base/theme.ss \
themes/Base/launch.wav \
themes/Base/start.wav \
themes/Base/end.wav \
themes/Base/error.wav \
themes/Base/warning.wav \
themes/Base/beep.wav \
themes/Base/open_folder.wav \
themes/Base/drop_move.wav \
themes/Base/drop_copy.wav \
themes/Base/remove.wav \
themes/Base/remove_to_dumpster.wav \
themes/Base/desk_switch.wav \
themes/Base/iconify.wav \
themes/Base/deiconify.wav \
themes/Base/new_mail.wav \
themes/Base/print_files.wav \
themes/Base/search_hit.wav \
themes/Base/search_miss.wav \
themes/Base/clock_chime_hour.wav \
themes/Base/terminal_bell.wav
+41 -4
View File
@@ -76,15 +76,40 @@ PlayEvent(const char *event)
McdeSoundPlay(dpy, path) == 0 ? "player" : "bell");
}
static void
ReloadTheme(void)
{
Atom prop = XInternAtom(dpy, "_MCDE_SOUND_THEME", False);
Atom type;
int format;
unsigned long n, after;
unsigned char *data = NULL;
if (XGetWindowProperty(dpy, service, prop, 0, 1024, False,
AnyPropertyType, &type, &format, &n, &after, &data) == Success &&
data != NULL && n > 0) {
if (McdeSoundLoadTheme((char *) data) == 0)
fprintf(stderr, "mcdesoundd: theme now %s\n",
McdeSoundThemeDir());
else
fprintf(stderr, "mcdesoundd: cannot read theme %s\n",
(char *) data);
XFree(data);
}
}
static void
Message(Widget w, XtPointer data, XEvent *ev, Boolean *keep)
{
(void) w; (void) data; (void) keep;
if (ev->type == ClientMessage &&
ev->xclient.message_type ==
XInternAtom(dpy, "_MCDE_SOUND_EVENT", False) &&
ev->xclient.format == 8)
if (ev->type != ClientMessage || ev->xclient.format != 8)
return;
if (ev->xclient.message_type ==
XInternAtom(dpy, "_MCDE_SOUND_EVENT", False))
PlayEvent(ev->xclient.data.b);
else if (ev->xclient.message_type ==
XInternAtom(dpy, "_MCDE_SOUND_RELOAD", False))
ReloadTheme();
}
int
@@ -130,6 +155,18 @@ main(int argc, char **argv)
ok ? "PASS" : "FAIL", McdeSoundThemeDir());
return ok ? 0 : 1;
}
if (strcmp(argv[i], "-set-theme") == 0 && i + 1 < argc) {
if ((dpy = XOpenDisplay(NULL)) == NULL)
return 2;
if (McdeSoundSetTheme(dpy, argv[i + 1]) != 0) {
fprintf(stderr,
"mcdesoundd: no server for the theme\n");
return 1;
}
fprintf(stderr, "mcdesoundd: theme %s sent\n",
argv[i + 1]);
return 0;
}
if (strcmp(argv[i], "-event") == 0 && i + 1 < argc) {
if ((dpy = XOpenDisplay(NULL)) == NULL)
return 2;
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+42
View File
@@ -0,0 +1,42 @@
! MCDE sound theme Base -- the lower voice of Camouflage
*Launch.soundfile: launch.wav
*Launch.label: Launch
*Start.soundfile: start.wav
*Start.label: Start
*End.soundfile: end.wav
*End.label: End
*Error.soundfile: error.wav
*Error.label: Error
*Warning.soundfile: warning.wav
*Warning.label: Warning
*Beep.soundfile: beep.wav
*Beep.label: Beep
*OpenFolder.soundfile: open_folder.wav
*OpenFolder.label: OpenFolder
*DropMove.soundfile: drop_move.wav
*DropMove.label: DropMove
*DropCopy.soundfile: drop_copy.wav
*DropCopy.label: DropCopy
*Remove.soundfile: remove.wav
*Remove.label: Remove
*RemoveToDumpster.soundfile: remove_to_dumpster.wav
*RemoveToDumpster.label: RemoveToDumpster
*DeskSwitch.soundfile: desk_switch.wav
*DeskSwitch.label: DeskSwitch
*Iconify.soundfile: iconify.wav
*Iconify.label: Iconify
*Deiconify.soundfile: deiconify.wav
*Deiconify.label: Deiconify
*NewMail.soundfile: new_mail.wav
*NewMail.label: NewMail
*PrintFiles.soundfile: print_files.wav
*PrintFiles.label: PrintFiles
*SearchHit.soundfile: search_hit.wav
*SearchHit.label: SearchHit
*SearchMiss.soundfile: search_miss.wav
*SearchMiss.label: SearchMiss
*ClockChimeHour.soundfile: clock_chime_hour.wav
*ClockChimeHour.label: ClockChimeHour
*TerminalBell.soundfile: terminal_bell.wav
*TerminalBell.label: TerminalBell
Binary file not shown.