Files
mcde/programs/dtwm/WmMcdePanel.c
T
lotherkandClaude Opus 5.5 9fd4818051 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 <noreply@anthropic.com>
2026-11-13 06:41:53 +00:00

785 lines
22 KiB
C

/*
* WmMcdePanel.c -- MCDE: the programs left of the trash in the front panel
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*
* The front panel stays CDE's: its controls, subpanels and workspace
* switch. Left of the trash it gets one more part, made here:
*
* - the programs kept in the panel (~/.dt/panel-apps, one a line:
* CLASS <tab> COMMAND); a click starts one, or brings it forward when
* it runs; the right button offers "Remove from Panel";
* - then the programs running that have no place in the panel -- not
* kept, and no main panel control names them (CLIENT_NAME, or a
* PUSH_ACTION that begins with the program's class); a click brings
* the window forward (on its workspace); the right button offers
* "Keep in Panel", and so does dragging it to the left with the button
* held.
*
* Keeping a program needs the command that starts it: the client's
* WM_COMMAND, else the command line of its process (_NET_WM_PID,
* mcde_sys_process_command), else its class in lower case.
*
* The part is a form in the main panel's control row, between the control
* before the trash and the trash; above it, in the row of the subpanel
* arrows, a blank of the same width keeps every arrow over its control
* (UI.c, ArrowCreate). An unmanaged form passes its attachment on, so the
* trash moves back when the part is empty. The buttons are CDE's own
* panel controls (_DtCreateControl) with the class's icon. The part is
* redrawn after dtwm manages or unmanages a window (WmManage.c).
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <ctype.h>
#include <sys/types.h>
#include "WmGlobal.h"
#include "WmFunction.h"
#include "WmWrkspace.h"
#include "DataBaseLoad.h"
#include "UI.h"
#include "WmMcdePanel.h"
#include "WmMcdeDisplays.h"
#include <X11/Xatom.h>
#include <Dt/WsmP.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Separator.h>
#include <Dt/DtStrDefs.h>
#include <Dt/Icon.h>
#include <Dt/Control.h>
#include <Dt/IconFile.h>
#include <Mcde/McdeSys.h>
#define MAX_APPS 48
typedef struct {
char cls[64]; /* WM_CLASS class */
char cmd[1024]; /* what starts it */
} Kept;
static Kept kept[MAX_APPS];
static int nkept;
static Widget area, spacer, menu, menuItem;
static ControlData *trash;
static XtIntervalId pending;
/* the buttons now: class, kept (an index into kept[]) or running only */
static struct {
Widget w;
char cls[64];
int keptIndex; /* -1: running, not kept */
} buttons[MAX_APPS];
static int nbuttons, menuFor = -1, pressX;
/* ---- the kept programs -------------------------------------------------- */
static void
KeptFile(char *buf, size_t len)
{
const char *home = getenv("HOME");
snprintf(buf, len, "%s/.dt/panel-apps", home != NULL ? home : ".");
}
static void
ReadKept(void)
{
char path[1100], line[1200], *tab;
FILE *fp;
nkept = 0;
KeptFile(path, sizeof path);
if ((fp = fopen(path, "r")) == NULL)
return;
while (nkept < MAX_APPS && fgets(line, sizeof line, fp) != NULL) {
line[strcspn(line, "\r\n")] = '\0';
if (line[0] == '#' || (tab = strchr(line, '\t')) == NULL)
continue;
*tab = '\0';
snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s", line);
snprintf(kept[nkept].cmd, sizeof kept[nkept].cmd, "%s", tab + 1);
nkept++;
}
fclose(fp);
}
static void
WriteKept(void)
{
char path[1100], tmp[1200];
FILE *fp;
int i;
KeptFile(path, sizeof path);
snprintf(tmp, sizeof tmp, "%s.new", path);
if ((fp = fopen(tmp, "w")) == NULL)
return;
fprintf(fp, "# the programs kept in the front panel: CLASS <tab> "
"COMMAND (MCDE dtwm)\n");
for (i = 0; i < nkept; i++)
fprintf(fp, "%s\t%s\n", kept[i].cls, kept[i].cmd);
if (fclose(fp) == 0)
(void) rename(tmp, path);
}
static int
KeptIndex(const char *cls)
{
int i;
for (i = 0; i < nkept; i++)
if (strcasecmp(kept[i].cls, cls) == 0)
return i;
return -1;
}
/* ---- the windows -------------------------------------------------------- */
/* a program's window of its own: not a transient, not dtwm's panels */
static Boolean
IsProgram(ClientData *pCD)
{
return pCD != NULL && pCD->clientClass != NULL &&
pCD->transientLeader == NULL &&
!(pCD->dtwmBehaviors & (DtWM_BEHAVIOR_PANEL |
DtWM_BEHAVIOR_SUBPANEL)) &&
pCD->clientState != WITHDRAWN_STATE &&
strcasecmp(pCD->clientClass, "Dtwm") != 0;
}
/* the first window of class CLS, or NULL */
static ClientData *
WindowOf(const char *cls)
{
WmScreenData *pSD = ACTIVE_PSD;
ClientListEntry *e;
for (e = pSD->clientList; e != NULL; e = e->nextSibling)
if (e->pCD != NULL && e == &e->pCD->clientEntry &&
IsProgram(e->pCD) &&
strcasecmp(e->pCD->clientClass, cls) == 0)
return e->pCD;
return NULL;
}
/* does control C stand for class CLS (its CLIENT_NAME, or a PUSH_ACTION
* beginning with the class) */
static Boolean
Names(ControlData *c, const char *cls)
{
size_t n = strlen(cls);
ElementValue *v = c->element_values;
const char *client = (const char *) v[CONTROL_CLIENT_NAME].parsed_value;
const char *action = (const char *) v[CONTROL_PUSH_ACTION].parsed_value;
return (client != NULL && strcasecmp(client, cls) == 0) ||
(action != NULL && strncasecmp(action, cls, n) == 0);
}
/* does a control of the panel, in the main row or in a drawer, stand for
* class CLS: such a program is in the dock and not shown again on the right */
static Boolean
InPanel(const char *cls)
{
int i, j, k;
for (i = 0; i < panel.box_data_count; i++) {
BoxData *b = panel.box_data[i];
for (j = 0; j < b->control_data_count; j++) {
ControlData *c = b->control_data[j];
SubpanelData *sp = c->subpanel_data;
if (Names(c, cls))
return True;
if (sp != NULL)
for (k = 0; k < sp->control_data_count; k++)
if (Names(sp->control_data[k], cls))
return True;
}
}
return False;
}
/* bring PCD forward, on its workspace */
static void
Raise(ClientData *pCD)
{
WmScreenData *pSD = PSD_FOR_CLIENT(pCD);
if (!ClientInWorkspace(pSD->pActiveWS, pCD) && pCD->numInhabited > 0) {
WmWorkspaceData *pWS = GetWorkspaceData(pSD,
pCD->pWsList[0].wsID);
if (pWS != NULL)
ChangeToWorkspace(pWS);
}
(void) F_Normalize_And_Raise(NULL, pCD, NULL);
}
/* the command that starts PCD's program again */
static void
CommandOf(ClientData *pCD, char *buf, size_t len)
{
char **argv = NULL;
int argc = 0, i;
size_t n = 0;
buf[0] = '\0';
if (XGetCommand(DISPLAY, pCD->client, &argv, &argc) && argc > 0) {
for (i = 0; i < argc && n + 4 < len; i++)
n += (size_t) snprintf(buf + n, len - n, "%s'%s'",
i > 0 ? " " : "", argv[i]);
XFreeStringList(argv);
if (strchr(buf, '\n') == NULL)
return;
}
{
Atom a = XInternAtom(DISPLAY, "_NET_WM_PID", False), type;
int format;
unsigned long items, after;
unsigned char *data = NULL;
if (XGetWindowProperty(DISPLAY, pCD->client, a, 0, 1, False,
XA_CARDINAL, &type, &format, &items, &after, &data) ==
Success && data != NULL && items == 1 &&
mcde_sys_process_command((pid_t) *(long *) data, buf,
len) == MCDE_SYS_OK && strchr(buf, '\n') == NULL) {
XFree(data);
return;
}
if (data != NULL)
XFree(data);
}
/* the class, in lower case: dtterm, xclock */
for (i = 0; pCD->clientClass[i] != '\0' && (size_t) i + 1 < len; i++)
buf[i] = (char) tolower((unsigned char) pCD->clientClass[i]);
buf[i] = '\0';
}
/* ---- the part ----------------------------------------------------------- */
static void Update(void);
static void CenterLater(void);
static void
DebugGeometry(XtPointer data, XtIntervalId *id)
{
Widget p = XtParent(area), t = trash->icon;
(void) data;
(void) id;
fprintf(stderr, "dtwm panel: area %dx%d+%d managed %d; parent %dx%d; "
"trash +%d; shell %dx%d\n", XtWidth(area), XtHeight(area),
XtX(area), XtIsManaged(area), XtWidth(p), XtHeight(p), XtX(t),
XtWidth(panel.shell), XtHeight(panel.shell));
}
static void
Later(XtPointer data, XtIntervalId *id)
{
(void) data;
(void) id;
pending = 0;
Update();
}
void
McdePanelChanged(void)
{
if (area == NULL || pending != 0)
return;
pending = XtAppAddTimeOut(wmGD.mwmAppContext, 200, Later, NULL);
}
static void
Keep(int b)
{
ClientData *pCD = WindowOf(buttons[b].cls);
if (pCD == NULL || nkept >= MAX_APPS || KeptIndex(buttons[b].cls) >= 0)
return;
snprintf(kept[nkept].cls, sizeof kept[nkept].cls, "%s",
pCD->clientClass);
CommandOf(pCD, kept[nkept].cmd, sizeof kept[nkept].cmd);
nkept++;
WriteKept();
McdePanelChanged();
}
static void
Unkeep(int b)
{
int k = buttons[b].keptIndex;
if (k < 0)
return;
memmove(kept + k, kept + k + 1, (size_t) (nkept - k - 1) * sizeof kept[0]);
nkept--;
WriteKept();
McdePanelChanged();
}
static void
MenuChosen(Widget w, XtPointer data, XtPointer call)
{
(void) w;
(void) data;
(void) call;
if (menuFor < 0 || menuFor >= nbuttons)
return;
if (buttons[menuFor].keptIndex >= 0)
Unkeep(menuFor);
else
Keep(menuFor);
}
static void
Clicked(Widget w, XtPointer data, XtPointer call)
{
int b = (int) (intptr_t) data;
ClientData *pCD;
(void) w;
(void) call;
if (b < 0 || b >= nbuttons)
return;
if ((pCD = WindowOf(buttons[b].cls)) != NULL)
Raise(pCD);
else if (buttons[b].keptIndex >= 0)
(void) F_Exec(kept[buttons[b].keptIndex].cmd, NULL, NULL);
}
static void
PostMenu(int b, XButtonEvent *ev)
{
XmString s;
menuFor = b;
s = XmStringCreateLocalized(buttons[b].keptIndex >= 0 ?
"Remove from Panel" : "Keep in Panel");
XtVaSetValues(menuItem, XmNlabelString, s, NULL);
XmStringFree(s);
XmMenuPosition(menu, ev);
XtManageChild(menu);
}
Boolean
McdePanelPost(Widget form, XButtonEvent *ev)
{
Position ax, ay;
Widget g;
int b;
if (area == NULL || !XtIsManaged(area) || XtParent(area) != form)
return False;
ax = XtX(area);
ay = XtY(area);
if (ev->x < ax || ev->y < ay || ev->x >= ax + (int) XtWidth(area) ||
ev->y >= ay + (int) XtHeight(area))
return False;
g = XmObjectAtPoint(area, (Position) (ev->x - ax),
(Position) (ev->y - ay));
for (b = 0; b < nbuttons; b++)
if (buttons[b].w == g) {
PostMenu(b, ev);
return True;
}
return True; /* the part, between buttons: no menu of CDE's */
}
/* the right button: the menu; the left one dragged out to the left: keep.
* The buttons are gadgets (_DtCreateControl): their events come to the
* part, which finds the button under the pointer (XmObjectAtPoint). */
static int pressedButton = -1;
static void
Pressed(Widget w, XtPointer data, XEvent *ev, Boolean *cont)
{
int b;
Widget g;
(void) cont;
(void) data;
if (getenv("MCDE_PANEL_DEBUG"))
fprintf(stderr, "dtwm panel: %s button %u at %d,%d\n",
ev->type == ButtonPress ? "press" : "release",
ev->xbutton.button, ev->xbutton.x, ev->xbutton.y);
if (ev->type == ButtonRelease && ev->xbutton.button == Button1)
b = pressedButton;
else {
g = XmObjectAtPoint(w, (Position) ev->xbutton.x,
(Position) ev->xbutton.y);
for (b = 0; b < nbuttons; b++)
if (buttons[b].w == g)
break;
if (b == nbuttons)
return;
}
if (b < 0 || b >= nbuttons)
return;
if (ev->type == ButtonPress && ev->xbutton.button == Button1)
pressedButton = b;
if (ev->type == ButtonPress && ev->xbutton.button == Button1) {
pressX = ev->xbutton.x_root;
return;
}
if (ev->type == ButtonRelease && ev->xbutton.button == Button1) {
Position ax = 0, ay = 0;
XtTranslateCoords(area, 0, 0, &ax, &ay);
/* let go left of the part, having moved there */
if (buttons[b].keptIndex < 0 && ev->xbutton.x_root < ax &&
pressX - ev->xbutton.x_root > 8)
Keep(b);
return;
}
if (ev->type != ButtonPress || ev->xbutton.button != Button3)
return;
PostMenu(b, &ev->xbutton);
}
static void
AddButton(const char *cls, int keptIndex)
{
Widget w;
Arg al[16];
int ac = 0;
String icon;
char lower[64];
size_t i;
if (nbuttons >= MAX_APPS)
return;
/* the class's icon, as CDE names them (Dtterm, Dtcalc), else in
* lower case, else the icon of an action */
icon = _DtGetIconFileName(XtScreen(area), (String) cls, NULL, NULL,
panel.main_icon_size);
if (icon == NULL) {
for (i = 0; cls[i] != '\0' && i + 1 < sizeof lower; i++)
lower[i] = (char) tolower((unsigned char) cls[i]);
lower[i] = '\0';
icon = _DtGetIconFileName(XtScreen(area), lower, NULL, NULL,
panel.main_icon_size);
}
if (icon == NULL)
icon = GetIconName("Dtactn", panel.main_icon_size);
XtSetArg(al[ac], XmNbackground, panel.primary_pixel_set->bg); ac++;
XtSetArg(al[ac], XmNforeground, panel.primary_pixel_set->fg); ac++;
XtSetArg(al[ac], XmNarmColor, panel.primary_pixel_set->sc); ac++;
XtSetArg(al[ac], XmNpixmapBackground, panel.primary_pixel_set->bg); ac++;
XtSetArg(al[ac], XmNpixmapForeground, panel.primary_pixel_set->fg); ac++;
XtSetArg(al[ac], XmNpixmapPosition, XmPIXMAP_TOP); ac++;
XtSetArg(al[ac], XmNimageName, icon); ac++;
XtSetArg(al[ac], XmNstring, NULL); ac++;
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
if (nbuttons == 0) {
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
} else {
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_WIDGET); ac++;
XtSetArg(al[ac], XmNleftWidget, buttons[nbuttons - 1].w); ac++;
}
w = _DtCreateControl(area, "mcdeApp", al, ac);
XtFree(icon);
XtManageChild(w);
XtAddCallback(w, XmNcallback, Clicked, (XtPointer) (intptr_t) nbuttons);
buttons[nbuttons].w = w;
snprintf(buttons[nbuttons].cls, sizeof buttons[nbuttons].cls, "%s", cls);
buttons[nbuttons].keptIndex = keptIndex;
nbuttons++;
}
/* the panel grows by what the part did not get: with a session's
* geometry the panel's shell did not grow by itself, and the form squeezed
* the part to a pixel (measured in a dtsession); shrinking likewise */
static Dimension shown;
static void
Grow(XtPointer data, XtIntervalId *id)
{
Dimension want = (Dimension) (intptr_t) data, have = XtWidth(area);
int delta = (int) want - (int) have;
(void) id;
if (delta == 0 || !XtIsManaged(area))
return;
XtVaSetValues(panel.shell, XmNwidth,
(Dimension) ((int) XtWidth(panel.shell) + delta), NULL);
/* the form squeezed the part while there was no room; now there is */
XtVaSetValues(area, XmNwidth, want, NULL);
XtVaSetValues(spacer, XmNwidth, want, NULL);
CenterLater();
}
/*
* The workspace switch stays in the middle of the screen: the panel's left
* part (Files ... Desktop) has a fixed width, the right part (the running
* programs and the trash) grows and shrinks, so the shell is moved after
* every change by as much as the switch's centre is off the screen's.
* Konrad: "die 4 workspace knoepfe im dock ... sind immer center auf dem
* screen".
*/
static int centerTries, realizeTries;
/* the window manager puts the shell this far from where it was asked to
* (its frame); learnt from the first move */
static int centerAsked = -1, centerOffset;
static void
Center(XtPointer data, XtIntervalId *id)
{
Widget sw = NULL;
Position sx, sy;
int i, x, want, screenW, shellW, mx, my, mw, mh;
(void) data;
(void) id;
for (i = 0; i < panel.box_data_count && sw == NULL; i++)
if (panel.box_data[i]->switch_form != NULL)
sw = panel.box_data[i]->switch_form;
if (sw == NULL || panel.shell == NULL)
return;
/* at the start the panel is made before it is shown */
if (!XtIsRealized(panel.shell) || !XtIsRealized(sw)) {
if (++realizeTries < 40)
XtAppAddTimeOut(XtWidgetToApplicationContext(panel.shell),
250, Center, NULL);
return;
}
XtTranslateCoords(sw, (Position) (XtWidth(sw) / 2), 0, &sx, &sy);
screenW = WidthOfScreen(XtScreen(panel.shell));
shellW = (int) XtWidth(panel.shell);
/* 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;
if (getenv("MCDE_PANEL_DEBUG"))
fprintf(stderr, "dtwm panel: switch centre %d of %d, shell %d -> %d\n",
(int) sx, screenW, (int) XtX(panel.shell), want);
if (want != (int) XtX(panel.shell)) {
centerAsked = want - centerOffset;
XtVaSetValues(panel.shell, XmNx, (Position) centerAsked, NULL);
/* once more, to learn the offset if the shell is not there */
if (++centerTries < 3)
XtAppAddTimeOut(XtWidgetToApplicationContext(panel.shell),
300, Center, NULL);
} else
centerTries = 0;
}
/* after the panel's geometry settled (the shell's resize is a round trip
* to the window manager, which is this program) */
static void
CenterLater(void)
{
if (panel.shell != NULL)
XtAppAddTimeOut(XtWidgetToApplicationContext(panel.shell), 150,
Center, NULL);
}
/* the monitors changed (WmMcdeDisplays.c): the panel to the main display */
void
McdePanelMonitorsChanged(void)
{
centerTries = 0;
CenterLater();
}
static void
Update(void)
{
WmScreenData *pSD = ACTIVE_PSD;
ClientListEntry *e;
Dimension width = 0;
int i, j;
if (area == NULL)
return;
for (i = 0; i < nbuttons; i++)
XtDestroyWidget(buttons[i].w);
nbuttons = 0;
for (i = 0; i < nkept; i++)
AddButton(kept[i].cls, i);
for (e = pSD->clientList; e != NULL; e = e->nextSibling) {
ClientData *pCD = e->pCD;
if (pCD == NULL || e != &pCD->clientEntry || !IsProgram(pCD) ||
KeptIndex(pCD->clientClass) >= 0 ||
InPanel(pCD->clientClass))
continue;
for (j = 0; j < nbuttons; j++)
if (strcasecmp(buttons[j].cls, pCD->clientClass) == 0)
break;
if (j == nbuttons)
AddButton(pCD->clientClass, -1);
}
if (getenv("MCDE_PANEL_DEBUG"))
fprintf(stderr, "dtwm panel: %d buttons (%d kept)\n", nbuttons,
nkept);
if (nbuttons == 0) {
if (XtIsManaged(area) && shown > 1)
XtVaSetValues(panel.shell, XmNwidth, (Dimension)
((int) XtWidth(panel.shell) - (int) shown), NULL);
shown = 0;
XtUnmanageChild(area);
XtUnmanageChild(spacer);
CenterLater();
return;
}
for (i = 0; i < nbuttons; i++) {
XtWidgetGeometry pref;
if (XtQueryGeometry(buttons[i].w, NULL, &pref) != XtGeometryNo &&
(pref.request_mode & CWWidth))
width += pref.width;
else
width += XtWidth(buttons[i].w);
}
/* the panel gives back what the part had: Grow asks only for the
* difference */
if (XtIsManaged(area) && shown > 1 && shown != width)
XtVaSetValues(panel.shell, XmNwidth, (Dimension)
((int) XtWidth(panel.shell) + (int) width - (int) shown),
NULL);
shown = width;
XtVaSetValues(area, XmNwidth, width, NULL);
XtVaSetValues(spacer, XmNwidth, width, NULL);
XtManageChild(area);
XtManageChild(spacer);
XtAppAddTimeOut(wmGD.mwmAppContext, 0, Grow, (XtPointer) (intptr_t) width);
CenterLater();
if (getenv("MCDE_PANEL_DEBUG"))
XtAppAddTimeOut(wmGD.mwmAppContext, 500, DebugGeometry, NULL);
}
/* after the main panel's controls are made (UI.c, MainControlCreate) */
void
McdePanelCreate(void)
{
int i, j;
unsigned char att = XmATTACH_FORM;
Widget left = NULL;
Arg al[12];
int ac;
trash = NULL;
for (i = 0; i < panel.box_data_count && trash == NULL; i++)
for (j = 0; j < panel.box_data[i]->control_data_count; j++) {
ControlData *c = panel.box_data[i]->control_data[j];
const char *name =
(const char *) c->element_values[CONTROL_NAME].parsed_value;
if (name != NULL && strcmp(name, "Trash") == 0 &&
c->icon != NULL && c->arrow != NULL) {
trash = c;
break;
}
}
if (getenv("MCDE_PANEL_DEBUG"))
fprintf(stderr, "dtwm panel: create, trash %s\n",
trash != NULL ? "found" : "not found");
if (trash == NULL)
return;
ReadKept();
/* the part, in the control row before the trash */
XtVaGetValues(trash->icon, XmNleftAttachment, &att, XmNleftWidget,
&left, NULL);
/* the background of the row it sits in: a colour, or a pattern
* (UI.c gives the control forms a pixmap in some colour modes) */
{
Pixel bg;
Pixmap pm = XmUNSPECIFIED_PIXMAP;
XtVaGetValues(XtParent(trash->icon), XmNbackground, &bg,
XmNbackgroundPixmap, &pm, NULL);
ac = 0;
XtSetArg(al[ac], XmNbackground, bg); ac++;
if (pm != XmUNSPECIFIED_PIXMAP && pm != None) {
XtSetArg(al[ac], XmNbackgroundPixmap, pm); ac++;
}
}
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNtopOffset, 1); ac++;
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNbottomOffset, 1); ac++;
XtSetArg(al[ac], XmNleftAttachment, att); ac++;
if (att == XmATTACH_WIDGET) {
XtSetArg(al[ac], XmNleftWidget, left); ac++;
}
XtSetArg(al[ac], XmNresizePolicy, XmRESIZE_NONE); ac++;
XtSetArg(al[ac], XmNwidth, 1); ac++;
area = XmCreateForm(XtParent(trash->icon), "mcdeRunning", al, ac);
XtVaSetValues(trash->icon, XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, area, NULL);
/* its blank in the arrow row, before the trash's arrow */
att = XmATTACH_FORM;
left = NULL;
XtVaGetValues(trash->arrow, XmNleftAttachment, &att, XmNleftWidget,
&left, NULL);
{
Pixel bg;
Pixmap pm = XmUNSPECIFIED_PIXMAP;
XtVaGetValues(trash->arrow, XmNbackground, &bg, NULL);
XtVaGetValues(XtParent(trash->arrow), XmNbackgroundPixmap, &pm,
NULL);
ac = 0;
XtSetArg(al[ac], XmNbackground, bg); ac++;
if (pm != XmUNSPECIFIED_PIXMAP && pm != None) {
XtSetArg(al[ac], XmNbackgroundPixmap, pm); ac++;
}
}
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNleftAttachment, att); ac++;
if (att == XmATTACH_WIDGET) {
XtSetArg(al[ac], XmNleftWidget, left); ac++;
}
XtSetArg(al[ac], XmNrecomputeSize, False); ac++;
XtSetArg(al[ac], XmNwidth, 1); ac++;
{
XmString empty = XmStringCreateLocalized("");
XtSetArg(al[ac], XmNlabelString, empty); ac++;
spacer = XmCreateLabel(XtParent(trash->arrow),
"mcdeRunningArrows", al, ac);
XmStringFree(empty);
}
XtVaSetValues(trash->arrow, XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, spacer, NULL);
XtAddEventHandler(area, ButtonPressMask | ButtonReleaseMask, False,
Pressed, NULL);
/* the menu of the right button */
menu = XmCreatePopupMenu(area, "mcdeRunningMenu", NULL, 0);
menuItem = XmCreatePushButton(menu, "keep", NULL, 0);
XtAddCallback(menuItem, XmNactivateCallback, MenuChosen, NULL);
XtManageChild(menuItem);
Update();
}