From 9fd48180518860c5545e91fd6d951e06f2d083dc Mon Sep 17 00:00:00 2001 From: lotherk Date: Fri, 13 Nov 2026 06:41:53 +0000 Subject: [PATCH] MCDE: the review's open points -- sound through McdeSys, dtwm plug and play, the rest 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 --- AGENTS.md | 48 +++- configure.ac | 7 +- include/Makefile.am | 1 + include/Mcde/McdeSys.h | 3 + lib/McdeSound/Makefile.am | 1 + lib/McdeSound/Sound.c | 89 ++----- lib/McdeSys/linux.c | 10 + lib/McdeSys/netbsd.c | 9 + lib/McdeSys/private.h | 3 + lib/McdeSys/sound.c | 43 ++- pkgsrc/PLIST | 1 + programs/dtfile/Main.c | 4 - programs/dtfile/Makefile.am | 2 +- programs/dtpaint/dtpaint.c | 2 +- programs/dtphoto/dtphoto.c | 2 - programs/dtsystemsettings/Makefile.am | 2 +- programs/dtterm/Makefile.am | 2 +- programs/dttoolbox/dttoolbox.c | 15 +- programs/dtwm/Makefile.am | 3 +- programs/dtwm/WmGlobal.h | 4 + programs/dtwm/WmInitWs.c | 4 + programs/dtwm/WmMain.c | 4 + programs/dtwm/WmMcdeDisplays.c | 369 ++++++++++++++++++++++++++ programs/dtwm/WmMcdeDisplays.h | 17 ++ programs/dtwm/WmMcdePanel.c | 30 ++- programs/dtwm/WmMcdePanel.h | 2 + programs/dtwm/WmMultiHead.c | 13 + programs/dtwm/WmMultiHead.h | 2 + programs/mcdesoundd/Makefile.am | 2 +- programs/mcdesoundd/mcdesoundd.c | 12 +- 30 files changed, 607 insertions(+), 99 deletions(-) create mode 100644 programs/dtwm/WmMcdeDisplays.c create mode 100644 programs/dtwm/WmMcdeDisplays.h diff --git a/AGENTS.md b/AGENTS.md index bbb72c93..244633b0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -265,9 +265,20 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`. Tested on Xorg with the dummy driver (one output, DUMMY0): -apply-displays 2048x1536 -> 1280x1024, an unknown mode and all-off refused; in the pane 1024x768 applied and back after 16 s without an answer, kept with Keep - and written. Next (Konrad): plug and play in dtwm -- a monitor plugged in - is switched on and used, unplugged its windows gather on the main display, - plugged in again the desktop (windows, widgets, icons) is as before. + and written. Plug and play in dtwm (`programs/dtwm/WmMcdeDisplays.c`, + Konrad): dtwm selects RandR's output and screen changes. A monitor + plugged in is switched on as ~/.dt/displays remembers it, else right of + the others in its preferred mode (one switched off in System Settings + stays off); one unplugged is switched off. On a screen change every + window keeps its monitor's id and its place on it (ClientData.mcdeMonitor, + mcdeMonX/Y); a window whose monitor is gone waits on the main display + (mcdeRescued) and goes back when the monitor returns. Xinerama's heads + are read anew (McdeHeadsChanged) and the front panel centres on the main + display (McdePanelMonitorsChanged). Tested: dtwm starts with it on + Xvfb, the check at login changes nothing when nothing was plugged, and it + keeps running; plugging itself was not measured -- Xvfb cannot change + its outputs and Xorg's dummy driver needs a console user. Widgets and + icons are not yet moved back. - Focus: Dtwm*keyboardFocusPolicy: pointer and Dtwm*focusAutoRaise: False in sys.resources (MCDE's default, Konrad); the Style Manager's Window settings change them as in CDE, and so do System Settings: Mouse, @@ -450,6 +461,37 @@ place of CDE; pkgsrc builds it on any platform from `pkgsrc/`. its command `DtNsubprocessArgv`. Window > New Tab / New Tab with Profile come from a hook in `TermViewMenu.c` (`_DtTermViewMenuSetNewTab`); `dtterm -profile NAME`; the profile "Default" is the starting one. +- The desktop's sounds (docs/MCDE-PROGRAMS.md A1-A4): `lib/McdeSound` + (`include/Mcde/Sound.h`) reads a theme -- an X resource file, + `*Launch.soundfile: launch.wav`, the files beside it -- and sends an + event as a ClientMessage `_MCDE_SOUND_EVENT` to the owner of the + selection `_MCDE_SOUND_SERVER`; `programs/mcdesoundd` owns it (one per + display), drops a repeat within 50 ms and plays through McdeSys + (`mcde_sys_sound_play`: paplay where a PulseAudio server answers, else + audioplay(1) on NetBSD and aplay(1) on Linux, started in a grandchild so + the daemon never waits), the X bell when there is no player. Started by + `sessionetc.d/0075.mcdesoundd`. dtfile plays OpenFolder (FileMgr.c, + once per folder), dtterm's bell TerminalBell (libDtTerm, which links + libMcdeSound), dtwm DeskSwitch; System Settings, Sound lists and plays + the events and switches the theme. Themes: Camouflage and Base in + `programs/mcdesoundd/themes`, 16-bit mono 44.1 kHz WAV tones made for + MCDE on 2026-11-12 (no file from elsewhere); the program that made them + was not kept -- a new sound comes with what makes it. +- `programs/dtphoto` -- the raster editor (docs/MCDE-PROGRAMS.md C1): menu + bar, toolbox and status line with a 2.5 / 3.0 switch; BMP open and save, + one-step undo, four zoom steps, marquee, fill, crop and the painting + tools. The menus are data, `share/dtphoto/dtphoto.menu` (a line ending + in "@2.5" or "@3.0" is read only there; "sub NAME" ... "endsub"). +- `programs/dtpaint` -- the simple paint program (C4): toolbox, colour box, + canvas; pencil, brush, eraser, fill, pick colour, line, rectangle, + ellipse, rounded rectangle, undo, invert, flip, BMP. Select, text, + curve, polygon, airbrush and zoom are drawn but do nothing yet. +- `programs/dttoolbox` -- the toolchest (B1-B5): a window of menus from a + chestrc (`$DTTB_CHESTRC`, `~/.chestrc`, else `share/toolchest/ + system.chestrc`): "Menu NAME [dynamic] {", f.menu, f.exec, + f.checkexec.sh, f.separator; include lines are skipped. Dynamic menus + come from a property `_SGI_MENU_` on the window the root's + `_SGI__MENU_WINDOW` names, read when it changes and every 500 ms. ## Building it diff --git a/configure.ac b/configure.ac index 5b53427b..94167d05 100644 --- a/configure.ac +++ b/configure.ac @@ -209,7 +209,12 @@ dnl not here. AC_SUBST(LIBTT, '$(top_builddir)/lib/tt/lib/libtt.la') AC_SUBST(LIBXIN, '$(top_builddir)/lib/DtXinerama/libDtXinerama.la') AC_SUBST(LIBWIDGET, '$(top_builddir)/lib/DtWidget/libDtWidget.la') -AC_SUBST(LIBTERM, '$(top_builddir)/lib/DtTerm/libDtTerm.la') +dnl MCDE: libDtTerm and libMcdeSound need the libraries below them named +dnl to every program that links them: a libtool that does not hand on +dnl indirect libraries (Debian's) let the linker take an older installed +dnl libMcdeSys through the RUNPATH (dtterm, 2026-11-13) +AC_SUBST(LIBTERM, '$(top_builddir)/lib/DtTerm/libDtTerm.la $(LIBMCDESOUND)') +AC_SUBST(LIBMCDESOUND, '$(top_builddir)/lib/McdeSound/libMcdeSound.la $(LIBMCDESYS)') AC_SUBST(LIBSVC, '$(top_builddir)/lib/DtSvc/libDtSvc.la') AC_SUBST(LIBMCDESYS, '$(top_builddir)/lib/McdeSys/libMcdeSys.la') AC_SUBST(LIBSEARCH, '$(top_builddir)/lib/DtSearch/libDtSearch.la') diff --git a/include/Makefile.am b/include/Makefile.am index 0b6f967b..b11bd5b1 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -6,6 +6,7 @@ nobase_include_HEADERS = Mcde/GlobalMenu.h \ Mcde/Displays.h \ Mcde/Image.h \ Mcde/McdeSys.h \ + Mcde/Sound.h \ Dt/Editor.h \ Dt/TermPrim.h \ Dt/Term.h \ diff --git a/include/Mcde/McdeSys.h b/include/Mcde/McdeSys.h index b8b7c98c..272af798 100644 --- a/include/Mcde/McdeSys.h +++ b/include/Mcde/McdeSys.h @@ -184,6 +184,9 @@ int mcde_sys_power(McdeSysPower what); int mcde_sys_volume_get(int *percent, int *muted); /* 0..100 */ int mcde_sys_volume_set(int percent); int mcde_sys_volume_mute(int muted); +/* play a sound file (WAV) on the default output and return at once, the + * player left running on its own; MCDE_SYS_ENOTSUP when there is none */ +int mcde_sys_sound_play(const char *file); /* * Bluetooth: the first controller diff --git a/lib/McdeSound/Makefile.am b/lib/McdeSound/Makefile.am index 702a8c2d..97c1128f 100644 --- a/lib/McdeSound/Makefile.am +++ b/lib/McdeSound/Makefile.am @@ -7,4 +7,5 @@ lib_LTLIBRARIES = libMcdeSound.la libMcdeSound_la_CPPFLAGS = -I$(top_srcdir)/include \ -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" libMcdeSound_la_SOURCES = Sound.c +libMcdeSound_la_LIBADD = $(LIBMCDESYS) libMcdeSound_la_LDFLAGS = -version-info 1:0:0 diff --git a/lib/McdeSound/Sound.c b/lib/McdeSound/Sound.c index 906843e7..2b0140a9 100644 --- a/lib/McdeSound/Sound.c +++ b/lib/McdeSound/Sound.c @@ -8,7 +8,8 @@ * * 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. + * 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. */ @@ -18,13 +19,11 @@ #include #include #include -#include -#include -#include #include #include +#include #include #define MAXEVENTS 128 @@ -132,49 +131,36 @@ McdeSoundInit(void) snprintf(themeDir, sizeof themeDir, CDE_INSTALLATION_TOP "/share/sounds/themes/Camouflage"); snprintf(path, sizeof path, "%s/theme.ss", themeDir); - if (ReadTheme(path) == 0) - return 0; - snprintf(themeDir, sizeof themeDir, - "/usr/pkg/dt/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++) { - char a[64], b[64], *q; - size_t n = 0; - const char *p; - - snprintf(a, sizeof a, "%s", event); - for (p = a; *p != '\0' && n < sizeof a - 1; p++) - if (*p != '_') - a[n++] = *p; - a[n] = '\0'; - snprintf(b, sizeof b, "%s", evName[i]); - for (q = b; *q != '\0'; q++) - if (*q == '_') - *q = '\0'; - /* compare without underscores on both sides */ - { - char c[64]; - size_t m = 0; - - for (q = evName[i]; *q != '\0' && m < sizeof c - 1; q++) - if (*q != '_') - c[m++] = *q; - c[m] = '\0'; - if (strcmp(a, c) == 0) - return evFile[i]; - } + Bare(evName[i], have, sizeof have); + if (strcmp(want, have) == 0) + return evFile[i]; } return NULL; } @@ -228,34 +214,9 @@ McdeSoundEvent(Display *dpy, const char *event) int McdeSoundPlay(Display *dpy, const char *path) { - static const char *const players[] = { - "/usr/bin/paplay", "/usr/pkg/bin/paplay", - "/usr/bin/aplay", "/usr/pkg/bin/audioplay", - "/usr/bin/ffplay", NULL - }; - const char *p = NULL; - int i; - pid_t pid; - - for (i = 0; players[i] != NULL; i++) - if (access(players[i], X_OK) == 0) { - p = players[i]; - break; - } - if (p == NULL) { - XBell(dpy, 0); - XFlush(dpy); - return 1; /* no player: the bell answered */ - } - if ((pid = fork()) == 0) { - setsid(); - execl(p, p, path, (char *) NULL); - _exit(127); - } - if (pid > 0) { - int status; - - waitpid(pid, &status, 0); - } - return 0; + if (mcde_sys_sound_play(path) == MCDE_SYS_OK) + return 0; + XBell(dpy, 0); + XFlush(dpy); + return 1; /* no player: the bell answered */ } diff --git a/lib/McdeSys/linux.c b/lib/McdeSys/linux.c index da7beccf..99c24811 100644 --- a/lib/McdeSys/linux.c +++ b/lib/McdeSys/linux.c @@ -139,6 +139,16 @@ mcde_sys_if_kind(const char *name, char *ssid, size_t len) /* ---- sound without a sound server: ALSA's amixer(1), control Master */ static const char *const amixerPaths[] = { "/usr/bin/amixer", NULL }; +/* ALSA's player when no sound server runs */ +const char * +mcde_sys_player(void) +{ + static const char *const paths[] = { "/usr/bin/aplay", "/bin/aplay", + NULL }; + + return mcde_sys_which(paths); +} + int mcde_sys_mixer_get(int *percent, int *muted) { diff --git a/lib/McdeSys/netbsd.c b/lib/McdeSys/netbsd.c index 48a1ab30..86458415 100644 --- a/lib/McdeSys/netbsd.c +++ b/lib/McdeSys/netbsd.c @@ -148,6 +148,15 @@ mcde_sys_if_kind(const char *name, char *ssid, size_t len) /* ---- sound without a sound server: mixerctl(1), outputs.master (0..255) */ static char mixerctl[] = "/usr/bin/mixerctl"; +/* the base system's player for the audio(4) device: audioplay(1) */ +const char * +mcde_sys_player(void) +{ + static const char *const paths[] = { "/usr/bin/audioplay", NULL }; + + return mcde_sys_which(paths); +} + int mcde_sys_mixer_get(int *percent, int *muted) { diff --git a/lib/McdeSys/private.h b/lib/McdeSys/private.h index c2a8b914..22555a59 100644 --- a/lib/McdeSys/private.h +++ b/lib/McdeSys/private.h @@ -71,5 +71,8 @@ int mcde_sys_net_add(McdeSysNetHost *hosts, int n, size_t max, int mcde_sys_mixer_get(int *percent, int *muted); int mcde_sys_mixer_set(int percent); int mcde_sys_mixer_mute(int muted); +/* the backend: the player of the system's own sound device, for a WAV file + * when no sound server runs (audioplay(1) on NetBSD), or NULL */ +const char *mcde_sys_player(void); #endif /* _McdeSys_private_h */ diff --git a/lib/McdeSys/sound.c b/lib/McdeSys/sound.c index 99cbf7da..0d85d323 100644 --- a/lib/McdeSys/sound.c +++ b/lib/McdeSys/sound.c @@ -6,7 +6,9 @@ * Where a PulseAudio server runs, its default sink is the output: pactl(1) * gets and sets it, the same on every system (pkgsrc has audio/pulseaudio). * Without one, the backend asks the system's mixer (mcde_sys_mixer_*: - * mixerctl(1) on NetBSD). C99 and POSIX only. + * mixerctl(1) on NetBSD). A sound is played the same way: paplay(1) + * where the server runs, else the system's player (mcde_sys_player: + * audioplay(1) on NetBSD, aplay(1) on Linux). C99 and POSIX only. */ #define _POSIX_C_SOURCE 200809L @@ -14,6 +16,9 @@ #include #include #include +#include +#include +#include #include @@ -96,3 +101,39 @@ mcde_sys_volume_mute(int muted) argv[3] = muted ? "1" : "0"; return mcde_sys_run(argv); } + +static const char *const paplayPaths[] = { + "/usr/bin/paplay", "/usr/pkg/bin/paplay", "/usr/local/bin/paplay", NULL +}; + +/* the player started in a grandchild: the caller (mcdesoundd's event loop) + * neither waits while the sound plays nor leaves a zombie */ +int +mcde_sys_sound_play(const char *file) +{ + const char *player = Pactl() != NULL ? mcde_sys_which(paplayPaths) : + NULL; + pid_t pid; + int status; + + if (file == NULL || access(file, R_OK) != 0) + return mcde_sys_fail(MCDE_SYS_ENOENT, "There is no sound file " + "\"%s\".", file != NULL ? file : ""); + if (player == NULL) + player = mcde_sys_player(); + if (player == NULL) + return mcde_sys_fail(MCDE_SYS_ENOTSUP, "No player for sounds is " + "installed."); + if ((pid = fork()) < 0) + return mcde_sys_fail(MCDE_SYS_EFAIL, "Cannot start %s.", player); + if (pid == 0) { + if (fork() == 0) { + (void) setsid(); + execl(player, player, file, (char *) NULL); + _exit(127); + } + _exit(0); + } + (void) waitpid(pid, &status, 0); + return MCDE_SYS_OK; +} diff --git a/pkgsrc/PLIST b/pkgsrc/PLIST index 5453cda8..cdf175fc 100644 --- a/pkgsrc/PLIST +++ b/pkgsrc/PLIST @@ -2689,6 +2689,7 @@ dt/include/Mcde/Displays.h dt/include/Mcde/GlobalMenu.h dt/include/Mcde/Image.h dt/include/Mcde/McdeSys.h +dt/include/Mcde/Sound.h dt/include/Tt/tt_c.h dt/include/Tt/tttk.h dt/include/csa/csa.h diff --git a/programs/dtfile/Main.c b/programs/dtfile/Main.c index 434969d5..3945795c 100644 --- a/programs/dtfile/Main.c +++ b/programs/dtfile/Main.c @@ -178,7 +178,6 @@ #include "Desktop.h" #include "Main.h" -#include #include "ChangeDir.h" #include "Prefs.h" #include "Common.h" @@ -3579,9 +3578,6 @@ GetNewView( return(NULL); } - /* MCDE: a folder opens -- the desktop's OpenFolder event */ - (void) McdeSoundEvent(XtDisplay(toplevel), "OpenFolder"); - /* * Special case: When opening any of the special desktop directory * icons (Home, Remote Systems, etc), we want to display the correct diff --git a/programs/dtfile/Makefile.am b/programs/dtfile/Makefile.am index 3f47301f..9847b337 100644 --- a/programs/dtfile/Makefile.am +++ b/programs/dtfile/Makefile.am @@ -15,7 +15,7 @@ dtfile_CPPFLAGS = -I./dtcopy -DSHAPE -D_ILS_MACROS -DSUN_PERF \ -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" \ -DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\" -dtfile_LDADD = $(top_builddir)/lib/McdeSound/libMcdeSound.la \ +dtfile_LDADD = $(LIBMCDESOUND) \ dtcopy/sharedFuncs.o \ dtcopy/fsrtns.o \ $(LIBMCDESYS) $(DTCLIENTLIBS) $(TIRPCLIB) $(XTOOLLIB) diff --git a/programs/dtpaint/dtpaint.c b/programs/dtpaint/dtpaint.c index d943be54..a099ae33 100644 --- a/programs/dtpaint/dtpaint.c +++ b/programs/dtpaint/dtpaint.c @@ -432,7 +432,7 @@ CanvasExpose(Widget w, XtPointer cd, XtPointer call) static void CanvasInput(Widget w, XtPointer cd, XEvent *ev, Boolean *keep) { - int color, radius, x, y; + int color, x, y; (void) w; (void) cd; (void) keep; switch (ev->type) { diff --git a/programs/dtphoto/dtphoto.c b/programs/dtphoto/dtphoto.c index 68928be8..35ef629e 100644 --- a/programs/dtphoto/dtphoto.c +++ b/programs/dtphoto/dtphoto.c @@ -1119,8 +1119,6 @@ main(int argc, char **argv) XGetDefault(dpy, "dtphoto", "version")); ReadMenus(CDE_INSTALLATION_TOP "/share/dtphoto/dtphoto.menu"); - if (nmenus == 0) - ReadMenus("/usr/pkg/dt/share/dtphoto/dtphoto.menu"); if (nmenus == 0) ReadMenus("dtphoto.menu"); diff --git a/programs/dtsystemsettings/Makefile.am b/programs/dtsystemsettings/Makefile.am index ca76a059..4f869662 100644 --- a/programs/dtsystemsettings/Makefile.am +++ b/programs/dtsystemsettings/Makefile.am @@ -14,7 +14,7 @@ dtsystemsettings_CPPFLAGS = -I$(top_srcdir)/include $(DT_INCDIR) \ -DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\" # Xft and fontconfig: the font families (appearance.c) # Xrandr: the monitors (libDtSvc's McdeDisplays.c), when configure found it -dtsystemsettings_LDADD = $(top_builddir)/lib/McdeSound/libMcdeSound.la \ +dtsystemsettings_LDADD = $(LIBMCDESOUND) \ $(LIBMCDESYS) $(DTCLIENTLIBS) $(XRANDRLIB) \ $(XTOOLLIB) $(XFTLIB) diff --git a/programs/dtterm/Makefile.am b/programs/dtterm/Makefile.am index fa11e478..8a915073 100644 --- a/programs/dtterm/Makefile.am +++ b/programs/dtterm/Makefile.am @@ -5,7 +5,7 @@ bin_PROGRAMS = dtterm # MCDE: the front panel's Remote Login (action McdeRemoteLogin) dist_bin_SCRIPTS = dtremotelogin -dtterm_LDADD = $(LIBTERM) $(top_builddir)/lib/McdeSound/libMcdeSound.la \ +dtterm_LDADD = $(LIBTERM) $(LIBMCDESOUND) \ $(DTCLIENTLIBS) $(XTOOLLIB) if BSD diff --git a/programs/dttoolbox/dttoolbox.c b/programs/dttoolbox/dttoolbox.c index 20eaf38e..66d32e29 100644 --- a/programs/dttoolbox/dttoolbox.c +++ b/programs/dttoolbox/dttoolbox.c @@ -315,21 +315,20 @@ BuildMenuWidget(Widget shell, const char *name, int depth) AddWidgets(shell, m, depth); } +/* the children are not waited for: SIGCHLD is ignored from the start + * (main), so none stays a zombie -- set after the first fork it missed + * the first child */ static void RunCommand(char *cmd) { - pid_t pid; - if (cmd == NULL || *cmd == '\0') return; fprintf(stderr, "dttoolbox: %s\n", cmd); - if ((pid = fork()) == 0) { + if (fork() == 0) { setsid(); execl("/bin/sh", "sh", "-c", cmd, (char *) NULL); _exit(127); } - if (pid > 0) - signal(SIGCHLD, SIG_IGN); } /* --------------------------------------------------- dynamic menus (poll) */ @@ -525,7 +524,7 @@ RootEvent(Widget w, XtPointer data, XEvent *ev, Boolean *keep) { (void) w; (void) data; (void) keep; if (ev->type == PropertyNotify) { - const char *name = XGetAtomName(dpy, ev->xproperty.atom); + char *name = XGetAtomName(dpy, ev->xproperty.atom); if (name != NULL && strncmp(name, "_SGI_MENU_", 10) == 0) @@ -555,6 +554,7 @@ main(int argc, char **argv) Window root; const char *home; + signal(SIGCHLD, SIG_IGN); top = XtVaAppInitialize(&app, "Dttoolbox", NULL, 0, &argc, argv, NULL, NULL); dpy = XtDisplay(top); @@ -562,8 +562,7 @@ main(int argc, char **argv) if ((home = getenv("DTTB_CHESTRC")) != NULL) { snprintf(chestFile, sizeof chestFile, "%s", home); - } else if ((home = getenv("HOME")) != NULL && - access("/tmp/dttoolbox-no-home", F_OK) != 0) { + } else if ((home = getenv("HOME")) != NULL) { char p[512]; snprintf(p, sizeof p, "%s/.chestrc", home); diff --git a/programs/dtwm/Makefile.am b/programs/dtwm/Makefile.am index 37a2c282..98a345ff 100644 --- a/programs/dtwm/Makefile.am +++ b/programs/dtwm/Makefile.am @@ -13,7 +13,7 @@ AM_CPPFLAGS = -DLARGECURSORS -DR2_COMPAT -DOPAQUE -DSHAPE -DUNMAP_ON_RESTART \ -DCDE_CONFIGURATION_TOP=\"$(CDE_CONFIGURATION_TOP)\" # Xrandr: monitors plugged in and out (WmMcdeDisplays.c) -dtwm_LDADD = $(LIBMCDESYS) $(top_builddir)/lib/McdeSound/libMcdeSound.la \ +dtwm_LDADD = $(LIBMCDESYS) $(LIBMCDESOUND) \ $(DTCLIENTLIBS) $(XRANDRLIB) $(XTOOLLIB) dtfplist_LDADD = $(DTCLIENTLIBS) $(TIRPCLIB) $(XTOOLLIB) @@ -37,6 +37,7 @@ dtwm_SOURCES = WmCDInfo.c WmCDecor.c WmCEvent.c \ Parse.c PopupMenu.c Session.c \ UI.c WmBackdrop.c WmFP.c \ WmSlideshow.c WmMcdePanel.c WmMcdeSnap.c \ + WmMcdeDisplays.c \ WmHelp.c WmIPC.c WmInstantTitle.c \ WmOL.c WmParse.c WmParseP.c \ WmPresence.c WmWrkspace.c WmXSMP.c diff --git a/programs/dtwm/WmGlobal.h b/programs/dtwm/WmGlobal.h index 64d61c31..e8f7dfb1 100644 --- a/programs/dtwm/WmGlobal.h +++ b/programs/dtwm/WmGlobal.h @@ -1600,6 +1600,10 @@ typedef struct _ClientData int primaryStackPosition; /* stack pos'n of primary */ Boolean secondariesOnTop; /* resource */ Boolean mcdeAbove; /* MCDE: Always on Top */ + char mcdeMonitor[48]; /* MCDE: its monitor's id and */ + int mcdeMonX, mcdeMonY; /* place on it; True while it */ + Boolean mcdeRescued; /* waits on the main display + * for it (WmMcdeDisplays.c) */ Boolean mcdeSnapped; /* MCDE: in a zone (WmMcdeSnap.c) */ int mcdeSnapWidth, mcdeSnapHeight; /* its client size before */ int primaryModalCount; /* primary modal win count */ diff --git a/programs/dtwm/WmInitWs.c b/programs/dtwm/WmInitWs.c index 86eea8ae..fec283fc 100644 --- a/programs/dtwm/WmInitWs.c +++ b/programs/dtwm/WmInitWs.c @@ -116,6 +116,7 @@ typedef struct #include "WmInitWs.h" #include "WmSlideshow.h" +#include "WmMcdeDisplays.h" static void InsureDefaultBackdropDir(char **ppchBackdropDirs); void InitWmDisplayEnv (void); @@ -1006,6 +1007,9 @@ void InitWmGlobal (int argc, char *argv [], char *environ []) /* setup EWMH handling */ SetupWmEwmh (); + /* MCDE: monitors plugged in and out (WmMcdeDisplays.c) */ + McdeDisplaysInit (); + /* * Use the WM_SAVE_YOURSELF protocol * for notification of when to save ourself diff --git a/programs/dtwm/WmMain.c b/programs/dtwm/WmMain.c index bf23693e..4e5a8a12 100644 --- a/programs/dtwm/WmMain.c +++ b/programs/dtwm/WmMain.c @@ -48,6 +48,7 @@ #include "WmInitWs.h" #include "WmError.h" #include "WmIPC.h" +#include "WmMcdeDisplays.h" #include "WmBackdrop.h" @@ -171,6 +172,9 @@ main (int argc, char *argv [], char *environ []) wmGD.bReplayedButton = False; } } + /* MCDE: RandR's events (monitors plugged in and out) */ + if (McdeDisplaysEvent (&event)) + continue; dispatchEvent = True; if (wmGD.menuActive) { diff --git a/programs/dtwm/WmMcdeDisplays.c b/programs/dtwm/WmMcdeDisplays.c new file mode 100644 index 00000000..7281954e --- /dev/null +++ b/programs/dtwm/WmMcdeDisplays.c @@ -0,0 +1,369 @@ +/* + * WmMcdeDisplays.c -- MCDE: monitors plugged in and out (plug and play) + * + * Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE. + * + * Konrad, 2026-11-11: "wenn display an, direkt anschalten und benutzen. + * wenn display ab alle fenster auf main sammeln. wenn display wieder + * dran, desktop wie vorher wiederherstellen." + * + * dtwm listens for RandR's output and screen changes on the root windows. + * + * An output change (a monitor plugged in or out; gathered for half a + * second, a plug bounces): a monitor that is connected and off is switched + * on -- as ~/.dt/displays remembers it (include/Mcde/Displays.h: the + * monitor by its EDID id, whatever socket it is in), else right of the + * others in the mode it prefers; one the user switched off in System + * Settings stays off. An output that is on with nothing plugged in is + * switched off. McdeDispApply sets it as xrandr(1) would. + * + * A screen change (that, or System Settings > Displays): before, every + * window was on a monitor at a place; each window keeps that monitor's id + * and its place on it. A window whose monitor is gone goes to the main + * display at the same place (clamped into it) and stays marked; when its + * monitor comes back it goes back there. Maximized and full-screen + * windows are made so again on the monitor they are on now. The front + * panel follows the main display (WmMcdePanel.c, Center); the top bar + * (dtbar) moves itself. + * + * Nothing runs while nothing is plugged: no polling, events only. + */ + +#include + +#include +#include + +#include "WmGlobal.h" +#include "WmCDInfo.h" +#include "WmEvent.h" +#include "WmFunction.h" +#include "WmMultiHead.h" +#include "WmWinConf.h" +#include "WmWinState.h" +#include "WmMcdeDisplays.h" +#include "WmMcdePanel.h" +#include "WmMcdeSnap.h" + +#include + +#ifdef HAVE_XRANDR +#include + +#define HOTPLUG_DELAY 500 /* ms: a plug bounces */ +#define REARRANGE_DELAY 200 /* ms: one screen change brings several */ + +typedef struct { + char id[48]; + int x, y, w, h; +} McdeMon; + +static McdeMon mons[MCDE_DISP_MAX]; +static int nmons, mainMon = -1; +static int rrEventBase = -1; +static XtIntervalId hotplugTimer, rearrangeTimer; +static McdeDispSet live, file; /* large: not on the stack */ + +/* the monitors that are on now, and which is the main one */ +static void +Snapshot(void) +{ + int i, p; + + nmons = 0; + mainMon = -1; + if (McdeDispLoad(DISPLAY, &live) != 0) + return; + p = McdeDispPrimary(&live); + for (i = 0; i < live.n && nmons < MCDE_DISP_MAX; i++) { + McdeDisp *d = &live.d[i]; + + if (!d->on) + continue; + if (i == p) + mainMon = nmons; + snprintf(mons[nmons].id, sizeof mons[nmons].id, "%s", d->id); + mons[nmons].x = d->x; + mons[nmons].y = d->y; + McdeDispSize(d, &mons[nmons].w, &mons[nmons].h); + nmons++; + } + if (mainMon < 0 && nmons > 0) + mainMon = 0; +} + +Boolean +McdeMainMonitor(int *x, int *y, int *w, int *h) +{ + if (mainMon < 0) + return False; + *x = mons[mainMon].x; + *y = mons[mainMon].y; + *w = mons[mainMon].w; + *h = mons[mainMon].h; + return True; +} + +/* ---- plugged in or out: switch it on or off ---- */ + +static const McdeDisp * +Remembered(const char *id) +{ + int i; + + for (i = 0; i < file.n; i++) + if (strcmp(file.d[i].id, id) == 0) + return &file.d[i]; + return NULL; +} + +static void +Hotplug(XtPointer data, XtIntervalId *id) +{ + FILE *f; + int i, j, changed = 0, bw, bh; + + (void) data; + (void) id; + hotplugTimer = 0; + if (McdeDispLoad(DISPLAY, &live) != 0) + return; + memset(&file, 0, sizeof file); + if ((f = fopen(McdeDispConfigPath(), "r")) != NULL) { + McdeDispRead(f, &file); + fclose(f); + } + /* unplugged first: they leave room */ + for (i = 0; i < live.n; i++) + if (!live.d[i].connected && live.d[i].on) { + live.d[i].on = 0; + live.d[i].primary = 0; + changed = 1; + } + for (i = 0; i < live.n; i++) { + McdeDisp *d = &live.d[i]; + const McdeDisp *r; + int m = -1; + + if (!d->connected || d->on || d->nmodes == 0) + continue; + r = Remembered(d->id); + if (r != NULL && !r->on) + continue; /* switched off on purpose */ + if (r != NULL) + m = McdeDispFindMode(d, r->w, r->h, r->rate); + if (m < 0) + m = 0; /* the one the monitor prefers */ + d->w = d->modes[m].w; + d->h = d->modes[m].h; + d->rate = d->modes[m].rate; + d->on = 1; + if (r != NULL && McdeDispFindMode(d, r->w, r->h, r->rate) >= 0) { + d->x = r->x; + d->y = r->y; + d->rot = r->rot; + if (r->primary) { + for (j = 0; j < live.n; j++) + live.d[j].primary = 0; + d->primary = 1; + } + } else { + /* new: right of the others, docked */ + d->on = 0; + McdeDispBounds(&live, &bw, &bh); + d->on = 1; + d->x = bw; + d->y = 0; + d->rot = MCDE_ROT_NORMAL; + } + McdeDispDock(&live, i); + changed = 1; + } + if (!changed) + return; + j = McdeDispPrimary(&live); + for (i = 0; i < live.n; i++) + live.d[i].primary = i == j; + McdeDispNormalize(&live); + (void) McdeDispApply(DISPLAY, &live); +} + +/* ---- the screen changed: windows to their monitors ---- */ + +static int +FindMonitor(const McdeMon *list, int n, const char *id) +{ + int i; + + for (i = 0; i < n; i++) + if (strcmp(list[i].id, id) == 0) + return i; + return -1; +} + +static int +MonitorAt(const McdeMon *list, int n, int x, int y) +{ + int i; + + for (i = 0; i < n; i++) + if (x >= list[i].x && y >= list[i].y && + x < list[i].x + list[i].w && y < list[i].y + list[i].h) + return i; + return -1; +} + +static int +Clamp(int v, int lo, int hi) +{ + return hi < lo ? lo : v < lo ? lo : v > hi ? hi : v; +} + +static void +MoveClient(ClientData *pCD, int fx, int fy) +{ + int state = pCD->clientState; + Boolean full = pCD->fullscreen; + + if (full) + McdeToggleFullscreen(pCD); + if (state == MAXIMIZED_STATE) + SetClientState(pCD, NORMAL_STATE, GetTimestamp()); + ProcessNewConfiguration(pCD, fx, fy, (unsigned int) pCD->clientWidth, + (unsigned int) pCD->clientHeight, False); + /* made so again on the monitor it is on now (GetHeadInfo) */ + if (state == MAXIMIZED_STATE) + SetClientState(pCD, MAXIMIZED_STATE, GetTimestamp()); + if (full) + McdeToggleFullscreen(pCD); +} + +static void +Rearrange(XtPointer data, XtIntervalId *id) +{ + McdeMon old[MCDE_DISP_MAX]; + int oldN = nmons, oldMain = mainMon, s; + + (void) data; + (void) id; + rearrangeTimer = 0; + memcpy(old, mons, sizeof old); + Snapshot(); + McdeHeadsChanged(); + if (nmons == 0) + return; + for (s = 0; s < wmGD.numScreens; s++) { + WmScreenData *pSD = &wmGD.Screens[s]; + ClientListEntry *e; + + if (!pSD->managed) + continue; + for (e = pSD->clientList; e != NULL; e = e->nextSibling) { + ClientData *pCD = e->pCD; + int fx, fy, fw, fh, m, nx, ny; + + if (e->type != NORMAL_STATE || pCD == NULL || + (pCD->dtwmBehaviors & (DtWM_BEHAVIOR_PANEL | + DtWM_BEHAVIOR_SUBPANEL)) || + pCD->clientState == WITHDRAWN_STATE) + continue; + fx = pCD->clientX - pCD->clientOffset.x; + fy = pCD->clientY - pCD->clientOffset.y; + fw = pCD->clientWidth + 2 * pCD->clientOffset.x; + fh = pCD->clientHeight + pCD->clientOffset.y + + pCD->clientOffset.x; + /* where it was, unless it waits for its monitor */ + if (!pCD->mcdeRescued) { + m = MonitorAt(old, oldN, fx + fw / 2, fy + fh / 2); + if (m < 0) + m = MonitorAt(old, oldN, fx, fy); + if (m < 0) + m = oldMain; + if (m < 0) + continue; + snprintf(pCD->mcdeMonitor, sizeof pCD->mcdeMonitor, + "%s", old[m].id); + pCD->mcdeMonX = fx - old[m].x; + pCD->mcdeMonY = fy - old[m].y; + } + m = FindMonitor(mons, nmons, pCD->mcdeMonitor); + pCD->mcdeRescued = m < 0; + if (m < 0) + m = mainMon; + nx = mons[m].x + Clamp(pCD->mcdeMonX, 0, mons[m].w - fw); + ny = mons[m].y + Clamp(pCD->mcdeMonY, 0, mons[m].h - fh); + if (nx != fx || ny != fy) + MoveClient(pCD, nx, ny); + } + } + McdePanelMonitorsChanged(); +} + +void +McdeDisplaysInit(void) +{ + int ev, err, s; + + if (!XRRQueryExtension(DISPLAY, &ev, &err)) + return; + rrEventBase = ev; + for (s = 0; s < wmGD.numScreens; s++) + if (wmGD.Screens[s].managed) + XRRSelectInput(DISPLAY, wmGD.Screens[s].rootWindow, + RRScreenChangeNotifyMask | RROutputChangeNotifyMask); + Snapshot(); + /* what was plugged in while nobody listened (before the login) */ + hotplugTimer = XtAppAddTimeOut(wmGD.mwmAppContext, HOTPLUG_DELAY, + Hotplug, NULL); +} + +Boolean +McdeDisplaysEvent(XEvent *event) +{ + if (rrEventBase < 0) + return False; + if (event->type == rrEventBase + RRScreenChangeNotify) { + XRRUpdateConfiguration(event); + if (rearrangeTimer != 0) + XtRemoveTimeOut(rearrangeTimer); + rearrangeTimer = XtAppAddTimeOut(wmGD.mwmAppContext, + REARRANGE_DELAY, Rearrange, NULL); + return True; + } + if (event->type == rrEventBase + RRNotify) { + if (((XRRNotifyEvent *) event)->subtype == RRNotify_OutputChange) { + if (hotplugTimer != 0) + XtRemoveTimeOut(hotplugTimer); + hotplugTimer = XtAppAddTimeOut(wmGD.mwmAppContext, + HOTPLUG_DELAY, Hotplug, NULL); + } + return True; + } + return False; +} + +#else /* !HAVE_XRANDR */ + +void +McdeDisplaysInit(void) +{ +} + +Boolean +McdeDisplaysEvent(XEvent *event) +{ + (void) event; + return False; +} + +Boolean +McdeMainMonitor(int *x, int *y, int *w, int *h) +{ + (void) x; + (void) y; + (void) w; + (void) h; + return False; +} + +#endif /* HAVE_XRANDR */ diff --git a/programs/dtwm/WmMcdeDisplays.h b/programs/dtwm/WmMcdeDisplays.h new file mode 100644 index 00000000..db516727 --- /dev/null +++ b/programs/dtwm/WmMcdeDisplays.h @@ -0,0 +1,17 @@ +/* + * WmMcdeDisplays.h -- MCDE: monitors plugged in and out (WmMcdeDisplays.c) + * + * Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE. + */ + +#ifndef _WmMcdeDisplays_h +#define _WmMcdeDisplays_h + +/* listen to RandR on the managed screens (after they are set up) */ +extern void McdeDisplaysInit(void); +/* an event of RandR: handled (True), or not one (False) */ +extern Boolean McdeDisplaysEvent(XEvent *event); +/* the main display's rectangle; False if RandR does not say */ +extern Boolean McdeMainMonitor(int *x, int *y, int *w, int *h); + +#endif /* _WmMcdeDisplays_h */ diff --git a/programs/dtwm/WmMcdePanel.c b/programs/dtwm/WmMcdePanel.c index fbfa4360..17a3f318 100644 --- a/programs/dtwm/WmMcdePanel.c +++ b/programs/dtwm/WmMcdePanel.c @@ -42,6 +42,7 @@ #include "DataBaseLoad.h" #include "UI.h" #include "WmMcdePanel.h" +#include "WmMcdeDisplays.h" #include #include
@@ -538,7 +539,7 @@ Center(XtPointer data, XtIntervalId *id) { Widget sw = NULL; Position sx, sy; - int i, x, want, screenW, shellW; + int i, x, want, screenW, shellW, mx, my, mw, mh; (void) data; (void) id; @@ -557,12 +558,19 @@ Center(XtPointer data, XtIntervalId *id) XtTranslateCoords(sw, (Position) (XtWidth(sw) / 2), 0, &sx, &sy); screenW = WidthOfScreen(XtScreen(panel.shell)); shellW = (int) XtWidth(panel.shell); - x = (int) XtX(panel.shell) + screenW / 2 - (int) sx; - /* never off the screen: then the switch is as near the middle as fits */ - if (x + shellW > screenW) - x = screenW - shellW; - if (x < 0) - x = 0; + /* the middle of the main display (WmMcdeDisplays.c), else of the + * screen */ + if (!McdeMainMonitor(&mx, &my, &mw, &mh)) { + mx = 0; + mw = screenW; + } + x = (int) XtX(panel.shell) + mx + mw / 2 - (int) sx; + /* never off the display: then the switch is as near the middle as + * fits */ + if (x + shellW > mx + mw) + x = mx + mw - shellW; + if (x < mx) + x = mx; if (centerAsked >= 0 && (int) XtX(panel.shell) != centerAsked + centerOffset) centerOffset = (int) XtX(panel.shell) - centerAsked; want = x; @@ -590,6 +598,14 @@ CenterLater(void) Center, NULL); } +/* the monitors changed (WmMcdeDisplays.c): the panel to the main display */ +void +McdePanelMonitorsChanged(void) +{ + centerTries = 0; + CenterLater(); +} + static void Update(void) { diff --git a/programs/dtwm/WmMcdePanel.h b/programs/dtwm/WmMcdePanel.h index 5187774a..052cd742 100644 --- a/programs/dtwm/WmMcdePanel.h +++ b/programs/dtwm/WmMcdePanel.h @@ -17,5 +17,7 @@ extern void McdePanelCreate(void); extern Boolean McdePanelPost(Widget form, XButtonEvent *ev); /* a window came or went (WmManage.c): the part is redrawn soon */ extern void McdePanelChanged(void); +/* the monitors changed: the panel to the main display (WmMcdeDisplays.c) */ +extern void McdePanelMonitorsChanged(void); #endif /* _WmMcdePanel_h */ diff --git a/programs/dtwm/WmMultiHead.c b/programs/dtwm/WmMultiHead.c index ad1be515..bd610fdb 100644 --- a/programs/dtwm/WmMultiHead.c +++ b/programs/dtwm/WmMultiHead.c @@ -171,6 +171,19 @@ WmHeadInfo_t *GetHeadInfoById(int id) { } +/* MCDE: the monitors changed (WmMcdeDisplays.c): Xinerama's list, kept + * "for life of X server" above, is read anew at the next question */ +void +McdeHeadsChanged(void) +{ + if (DtXI) { + if (DtXI->ScreenInfo) + XFree(DtXI->ScreenInfo); /* XineramaQueryScreens' */ + free(DtXI); + DtXI = NULL; + } +} + /* MCDE: the area below the top bar (WmMultiHead.h) */ void McdeExcludeBar(int screen, int *px, int *py, int *pwidth, int *pheight) diff --git a/programs/dtwm/WmMultiHead.h b/programs/dtwm/WmMultiHead.h index 40833ec1..b86a8fd3 100644 --- a/programs/dtwm/WmMultiHead.h +++ b/programs/dtwm/WmMultiHead.h @@ -42,5 +42,7 @@ WmHeadInfo_t *GetHeadInfoById(int id); * that windows are placed and maximized below it. */ void McdeExcludeBar(int screen, int *px, int *py, int *pwidth, int *pheight); +/* MCDE: the monitors changed, read them anew (WmMcdeDisplays.c) */ +void McdeHeadsChanged(void); #endif /* _WmMultiHead_h */ diff --git a/programs/mcdesoundd/Makefile.am b/programs/mcdesoundd/Makefile.am index 78ec5f70..374320c8 100644 --- a/programs/mcdesoundd/Makefile.am +++ b/programs/mcdesoundd/Makefile.am @@ -5,7 +5,7 @@ bin_PROGRAMS = mcdesoundd mcdesoundd_CPPFLAGS = -I$(top_srcdir)/include \ -DCDE_INSTALLATION_TOP=\"$(CDE_INSTALLATION_TOP)\" -mcdesoundd_LDADD = $(top_builddir)/lib/McdeSound/libMcdeSound.la \ +mcdesoundd_LDADD = $(LIBMCDESOUND) \ $(DTCLIENTLIBS) $(XTOOLLIB) if SOLARIS diff --git a/programs/mcdesoundd/mcdesoundd.c b/programs/mcdesoundd/mcdesoundd.c index fd19beb3..c18ecce3 100644 --- a/programs/mcdesoundd/mcdesoundd.c +++ b/programs/mcdesoundd/mcdesoundd.c @@ -105,9 +105,15 @@ Message(Widget w, XtPointer data, XEvent *ev, Boolean *keep) 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_EVENT", False)) { + /* the 20 bytes of the message, ended here whatever the + * sender put into them */ + char name[sizeof ev->xclient.data.b + 1]; + + memcpy(name, ev->xclient.data.b, sizeof ev->xclient.data.b); + name[sizeof name - 1] = '\0'; + PlayEvent(name); + } else if (ev->xclient.message_type == XInternAtom(dpy, "_MCDE_SOUND_RELOAD", False)) ReloadTheme(); }